build: Bazel builds ngfactories for packages/core (#18289)
PR Close #18289
This commit is contained in:
parent
0317c4c478
commit
6fc5940959
|
@ -0,0 +1,17 @@
|
||||||
|
package(default_visibility=["//visibility:public"])
|
||||||
|
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
|
||||||
|
|
||||||
|
ts_library(
|
||||||
|
name = "compiler-cli",
|
||||||
|
srcs = glob(["**/*.ts"], exclude=[
|
||||||
|
"integrationtest/**",
|
||||||
|
"test/**",
|
||||||
|
]),
|
||||||
|
module_name = "@angular/compiler-cli",
|
||||||
|
deps = [
|
||||||
|
"//packages/compiler",
|
||||||
|
"//packages/core",
|
||||||
|
"//packages/tsc-wrapped",
|
||||||
|
],
|
||||||
|
tsconfig = ":tsconfig-build.json",
|
||||||
|
)
|
|
@ -41,8 +41,8 @@ export class CompilerHost implements AotCompilerHost {
|
||||||
protected program: ts.Program, protected options: AngularCompilerOptions,
|
protected program: ts.Program, protected options: AngularCompilerOptions,
|
||||||
protected context: CompilerHostContext, collectorOptions?: CollectorOptions) {
|
protected context: CompilerHostContext, collectorOptions?: CollectorOptions) {
|
||||||
// normalize the path so that it never ends with '/'.
|
// normalize the path so that it never ends with '/'.
|
||||||
this.basePath = path.normalize(path.join(this.options.basePath, '.')).replace(/\\/g, '/');
|
this.basePath = path.normalize(path.join(this.options.basePath !, '.')).replace(/\\/g, '/');
|
||||||
this.genDir = path.normalize(path.join(this.options.genDir, '.')).replace(/\\/g, '/');
|
this.genDir = path.normalize(path.join(this.options.genDir !, '.')).replace(/\\/g, '/');
|
||||||
|
|
||||||
const genPath: string = path.relative(this.basePath, this.genDir);
|
const genPath: string = path.relative(this.basePath, this.genDir);
|
||||||
this.isGenDirChildOfRootDir = genPath === '' || !genPath.startsWith('..');
|
this.isGenDirChildOfRootDir = genPath === '' || !genPath.startsWith('..');
|
||||||
|
@ -312,7 +312,7 @@ export class CompilerHost implements AotCompilerHost {
|
||||||
relativePath = relativePath.substr(3);
|
relativePath = relativePath.substr(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(this.options.genDir, relativePath);
|
return path.join(this.options.genDir !, relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private hasBundleIndex(filePath: string): boolean {
|
private hasBundleIndex(filePath: string): boolean {
|
||||||
|
|
|
@ -36,7 +36,7 @@ export class Extractor {
|
||||||
return promiseBundle.then(bundle => {
|
return promiseBundle.then(bundle => {
|
||||||
const content = this.serialize(bundle, formatName);
|
const content = this.serialize(bundle, formatName);
|
||||||
const dstFile = outFile || `messages.${ext}`;
|
const dstFile = outFile || `messages.${ext}`;
|
||||||
const dstPath = path.join(this.options.genDir, dstFile);
|
const dstPath = path.join(this.options.genDir !, dstFile);
|
||||||
this.host.writeFile(dstPath, content, false);
|
this.host.writeFile(dstPath, content, false);
|
||||||
return [dstPath];
|
return [dstPath];
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,8 +27,8 @@ class SingleRootDirModuleFilenameResolver implements ModuleFilenameResolver {
|
||||||
|
|
||||||
constructor(private host: ModuleFilenameResolutionHost, private options: CompilerOptions) {
|
constructor(private host: ModuleFilenameResolutionHost, private options: CompilerOptions) {
|
||||||
// normalize the path so that it never ends with '/'.
|
// normalize the path so that it never ends with '/'.
|
||||||
this.basePath = path.normalize(path.join(options.basePath, '.')).replace(/\\/g, '/');
|
this.basePath = path.normalize(path.join(options.basePath !, '.')).replace(/\\/g, '/');
|
||||||
this.genDir = path.normalize(path.join(options.genDir, '.')).replace(/\\/g, '/');
|
this.genDir = path.normalize(path.join(options.genDir !, '.')).replace(/\\/g, '/');
|
||||||
|
|
||||||
const genPath: string = path.relative(this.basePath, this.genDir);
|
const genPath: string = path.relative(this.basePath, this.genDir);
|
||||||
this.isGenDirChildOfRootDir = genPath === '' || !genPath.startsWith('..');
|
this.isGenDirChildOfRootDir = genPath === '' || !genPath.startsWith('..');
|
||||||
|
@ -153,7 +153,7 @@ class MultipleRootDirModuleFilenameResolver implements ModuleFilenameResolver {
|
||||||
|
|
||||||
constructor(private host: ModuleFilenameResolutionHost, private options: CompilerOptions) {
|
constructor(private host: ModuleFilenameResolutionHost, private options: CompilerOptions) {
|
||||||
// normalize the path so that it never ends with '/'.
|
// normalize the path so that it never ends with '/'.
|
||||||
this.basePath = path.normalize(path.join(options.basePath, '.')).replace(/\\/g, '/');
|
this.basePath = path.normalize(path.join(options.basePath !, '.')).replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
getNgCanonicalFileName(fileName: string): string {
|
getNgCanonicalFileName(fileName: string): string {
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package(default_visibility=["//visibility:public"])
|
||||||
|
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
|
||||||
|
|
||||||
|
ts_library(
|
||||||
|
name = "compiler",
|
||||||
|
srcs = glob(["**/*.ts"], exclude=[
|
||||||
|
"test/**",
|
||||||
|
"testing/**",
|
||||||
|
]),
|
||||||
|
module_name = "@angular/compiler",
|
||||||
|
deps = ["//packages/core"],
|
||||||
|
tsconfig = ":tsconfig-build.json",
|
||||||
|
)
|
|
@ -11,3 +11,18 @@ ts_library(
|
||||||
deps = [],
|
deps = [],
|
||||||
tsconfig = ":tsconfig-build.json",
|
tsconfig = ":tsconfig-build.json",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
load("@build_bazel_rules_angular//:defs.bzl", "ng_module")
|
||||||
|
|
||||||
|
ng_module(
|
||||||
|
name = "core_ng_module",
|
||||||
|
srcs = glob(["**/*.ts"], exclude=[
|
||||||
|
"test/**",
|
||||||
|
"testing/**",
|
||||||
|
]),
|
||||||
|
# Needed to allow (ts_library,ng_module) pair
|
||||||
|
write_ng_outputs_only = True,
|
||||||
|
module_name = "@angular/core",
|
||||||
|
tsconfig = ":tsconfig-build.json",
|
||||||
|
compiler = "//tools/ngc-wrapped"
|
||||||
|
)
|
|
@ -0,0 +1,11 @@
|
||||||
|
package(default_visibility=["//visibility:public"])
|
||||||
|
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
|
||||||
|
|
||||||
|
ts_library(
|
||||||
|
name = "tsc-wrapped",
|
||||||
|
srcs = glob(["**/*.ts"], exclude=[
|
||||||
|
"test/**",
|
||||||
|
]),
|
||||||
|
module_name = "@angular/tsc-wrapped",
|
||||||
|
tsconfig = ":tsconfig-build.json",
|
||||||
|
)
|
|
@ -1,6 +1,10 @@
|
||||||
{
|
{
|
||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "../../dist/packages-dist/tsc-wrapped"
|
"outDir": "../../dist/packages-dist/tsc-wrapped",
|
||||||
|
"types": [
|
||||||
|
"node",
|
||||||
|
"jasmine"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "nodejs_binary")
|
||||||
|
|
||||||
|
licenses(["notice"]) # Apache 2.0
|
||||||
|
|
||||||
|
ts_library(
|
||||||
|
name = "ngc_lib",
|
||||||
|
srcs = ["index.ts"],
|
||||||
|
deps = [
|
||||||
|
"//packages/compiler-cli",
|
||||||
|
"@build_bazel_rules_typescript//internal/tsc_wrapped"
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
nodejs_binary(
|
||||||
|
name = "ngc-wrapped",
|
||||||
|
entry_point = "__main__/tools/ngc-wrapped/index.js",
|
||||||
|
data = [":ngc_lib"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,6 @@
|
||||||
|
# ngc-wrapped
|
||||||
|
|
||||||
|
This is a wrapper around @angular/compiler-cli that makes ngc run under Bazel.
|
||||||
|
It should be identical to https://github.com/bazelbuild/rules_angular/tree/master/internal/ngc
|
||||||
|
however that is built against Angular packages from npm, while ngc-wrapped is
|
||||||
|
built using Bazel against Angular at HEAD.
|
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
|
* found in the LICENSE file at https://angular.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TODO(chuckj): Remove the requirment for a fake 'reflect` implementation from
|
||||||
|
// the compiler
|
||||||
|
import 'reflect-metadata';
|
||||||
|
import {ngc} from '@angular/compiler-cli';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
// Note, the tsc_wrapped module comes from rules_typescript, not from @angular/tsc-wrapped
|
||||||
|
import {parseTsconfig} from 'tsc_wrapped';
|
||||||
|
|
||||||
|
function main(args: string[]) {
|
||||||
|
const [{options, bazelOpts, files, config}] = parseTsconfig(args[1]);
|
||||||
|
const ngOptions: {expectedOut: string[]} = (config as any).angularCompilerOptions;
|
||||||
|
|
||||||
|
const result = ngc(args, undefined, files, options, ngOptions);
|
||||||
|
|
||||||
|
if (result === 0) {
|
||||||
|
// Ensure that expected output files exist.
|
||||||
|
if (ngOptions && ngOptions.expectedOut) {
|
||||||
|
for (const out of ngOptions.expectedOut) {
|
||||||
|
fs.appendFileSync(out, '', 'utf-8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
process.exitCode = main(process.argv.slice(2));
|
||||||
|
}
|
|
@ -9,17 +9,20 @@
|
||||||
"outDir": "../dist/tools/",
|
"outDir": "../dist/tools/",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"paths": {
|
"paths": {},
|
||||||
},
|
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"inlineSources": true,
|
"inlineSources": true,
|
||||||
"lib": ["es6", "dom"],
|
"lib": [
|
||||||
|
"es6",
|
||||||
|
"dom"
|
||||||
|
],
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
"ngc-wrapped",
|
||||||
"typings-test",
|
"typings-test",
|
||||||
"public_api_guard",
|
"public_api_guard",
|
||||||
"docs"
|
"docs"
|
||||||
|
|
Loading…
Reference in New Issue