fix(tsc-wrapped): use agreed on options names (#14630)

This commit is contained in:
Chuck Jazdzewski 2017-02-22 10:57:01 -08:00 committed by Igor Minar
parent fcc1d17ccb
commit c9bfc59a21
14 changed files with 59 additions and 66 deletions

View File

@ -27,7 +27,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/animation"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/animation"
}
}

View File

@ -26,7 +26,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/common"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/common"
}
}

View File

@ -27,7 +27,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/core"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/core"
}
}

View File

@ -31,7 +31,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/forms"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/forms"
}
}

View File

@ -26,7 +26,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/http"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/http"
}
}

View File

@ -28,7 +28,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/platform-browser"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/platform-browser"
}
}

View File

@ -32,7 +32,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/platform-server"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/platform-server"
}
}

View File

@ -28,7 +28,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/platform-webworker"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/platform-webworker"
}
}

View File

@ -29,7 +29,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/router"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/router"
}
}

View File

@ -30,7 +30,7 @@
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"bundleIndex": "index",
"importAs": "@angular/upgrade"
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/upgrade"
}
}

View File

@ -16,7 +16,7 @@
"../../../node_modules/zone.js/dist/zone.js.d.ts"
],
"angularCompilerOptions": {
"bundleIndex": "static",
"importAs": "@angular/upgrade/static"
"flatModuleOutFile": "static.js",
"flatModuleId": "@angular/upgrade/static"
}
}

View File

@ -109,7 +109,7 @@ export class MetadataWriterHost extends DelegatingHost {
if (sourceFiles.length > 1) {
throw new Error('Bundled emit with --out is not supported');
}
if (!this.ngOptions.skipMetadataEmit && !this.ngOptions.bundleIndex) {
if (!this.ngOptions.skipMetadataEmit && !this.ngOptions.flatModuleOutFile) {
this.writeMetadata(fileName, sourceFiles[0]);
}
}

View File

@ -22,6 +22,7 @@ import {privateEntriesToIndex} from './index_writer';
export {UserError} from './tsc';
const DTS = /\.d\.ts$/;
const JS_EXT = /(\.js|)$/;
export type CodegenExtension =
(ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, host: ts.CompilerHost) =>
@ -59,34 +60,32 @@ export function main(
// todo(misko): remove once facade symlinks are removed
host.realpath = (path) => path;
// If the comilation is a bundle index then produce the bundle index metadata and
// the synthetic bundle index.
if (ngOptions.bundleIndex && !ngOptions.skipMetadataEmit) {
// If the comilation is a flat module index then produce the flat module index
// metadata and the synthetic flat module index.
if (ngOptions.flatModuleOutFile && !ngOptions.skipMetadataEmit) {
const files = parsed.fileNames.filter(f => !DTS.test(f));
if (files.length != 1 && (!ngOptions.libraryIndex || files.length < 1)) {
if (files.length != 1) {
check([{
file: null,
start: null,
length: null,
messageText:
'Angular compiler option "bundleIndex" requires one and only one .ts file in the "files" field or "libraryIndex" to also be specified in order to select which module to use as the library index',
'Angular compiler option "flatModuleIndex" requires one and only one .ts file in the "files" field.',
category: ts.DiagnosticCategory.Error,
code: 0
}]);
}
const file = files[0];
const indexModule = file.replace(/\.ts$/, '');
const libraryIndexModule = ngOptions.libraryIndex ?
MetadataBundler.resolveModule(ngOptions.libraryIndex, indexModule) :
indexModule;
const bundler =
new MetadataBundler(indexModule, ngOptions.importAs, new CompilerHostAdapter(host));
if (diagnostics) console.time('NG bundle index');
new MetadataBundler(indexModule, ngOptions.flatModuleId, new CompilerHostAdapter(host));
if (diagnostics) console.time('NG flat module index');
const metadataBundle = bundler.getMetadataBundle();
if (diagnostics) console.timeEnd('NG bundle index');
if (diagnostics) console.timeEnd('NG flat module index');
const metadata = JSON.stringify(metadataBundle.metadata);
const name = path.join(path.dirname(libraryIndexModule), ngOptions.bundleIndex + '.ts');
const libraryIndex = ngOptions.libraryIndex || `./${path.basename(indexModule)}`;
const name =
path.join(path.dirname(indexModule), ngOptions.flatModuleOutFile.replace(JS_EXT, '.ts'));
const libraryIndex = `./${path.basename(indexModule)}`;
const content = privateEntriesToIndex(libraryIndex, metadataBundle.privates);
host = new SyntheticIndexHost(host, {name, content, metadata});
parsed.fileNames.push(name);

View File

@ -25,40 +25,34 @@ interface Options extends ts.CompilerOptions {
// Don't produce .ngfactory.ts or .ngstyle.ts files
skipTemplateCodegen?: boolean;
// Whether to generate a bundle index of the given name and the corresponding bundled
// metadata. This option is intended to be used when creating library bundles similar
// to how `@angular/core` and `@angular/common` are generated.
// Whether to generate a flat module index of the given name and the corresponding
// flat module metadata. This option is intended to be used when creating flat
// modules similar to how `@angular/core` and `@angular/common` are packaged.
// When this option is used the `package.json` for the library should refered to the
// generated bundle index instead of the library index file. Only the bundle index
// metadata is required as the bundle index contains all metadata visible from the
// bundle index. The bundle index is used to import symbols for generating
// .ngfactory.ts files and includes both the public API from the root .ts file as well
// as shrowded internal symbols.
// The by default the .ts file supplied in the `files` files field is assumed to be
// generated flat module index instead of the library index file. When using this
// option only one .metadata.json file is produced that contains all the metadata
// necessary for symbols exported from the library index.
// In the generated .ngfactory.ts files flat module index is used to import symbols
// includes both the public API from the library index as well as shrowded internal
// symbols.
// By default the .ts file supplied in the `files` files field is assumed to be
// library index. If more than one is specified, uses `libraryIndex` to select the
// file to use. If more than on .ts file is supplied and no `libraryIndex` is supllied
// file to use. If more than on .ts file is supplied and no `libraryIndex` is supplied
// an error is produced.
// A bundle index .d.ts and .js will be created with the given `bundleIndex` name in the
// same location as the library index .d.ts file is emitted.
// For example, if a library uses `index.ts` file as the root file, the `tsconfig.json`
// `files` field would be `["index.ts"]`. The `bundleIndex` options could then be set
// to, for example `"bundle_index"`, which produces a `bundle_index.d.ts` and
// `bundle_index.metadata.json` files. The library's `package.json`'s `module` field
// would be `"bundle_index.js"` and the `typings` field would be `"bundle_index.d.ts"`.
bundleIndex?: string;
// A flat module index .d.ts and .js will be created with the given `flatModuleOutFile`
// name in the same location as the library index .d.ts file is emitted.
// For example, if a library uses `public_api.ts` file as the library index of the
// module the `tsconfig.json` `files` field would be `["public_api.ts"]`. The
// `flatModuleOutFile` options could then be set to, for example `"index.js"`, which
// produces `index.d.ts` and `index.metadata.json` files. The library's
// `package.json`'s `module` field would be `"index.js"` and the `typings` field would
// be `"index.d.ts"`.
flatModuleOutFile?: string;
// Override which module is used as the library index. This is only meaningful if
// `bundleIndex` is also supplied and only necessary if more than one `.ts` file is
// supplied in the `files` field. This must be of the form found in a import
// declaration. For example, if the library index is in `index.ts` then the
// `libraryIndex` field should be `"./index"`.
libraryIndex?: string;
// Preferred module name to use for importing the generated bundle. References
// generated by `ngc` will use this module name when importing symbols from the
// generated bundle. This is only meaningful when `bundleIndex` is also supplied. It is
// otherwise ignored.
importAs?: string;
// Preferred module id to use for importing flat module. References generated by `ngc`
// will use this module name when importing symbols from the flat module. This is only
// meaningful when `flatModuleOutFile` is also supplied. It is otherwise ignored.
flatModuleId?: string;
// Whether to generate code for library code.
// If true, produce .ngfactory.ts and .ngstyle.ts files for .d.ts inputs.