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": { "angularCompilerOptions": {
"annotateForClosureCompiler": true, "annotateForClosureCompiler": true,
"strictMetadataEmit": true, "strictMetadataEmit": true,
"bundleIndex": "index", "flatModuleOutFile": "index.js",
"importAs": "@angular/animation" "flatModuleId": "@angular/animation"
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -109,7 +109,7 @@ export class MetadataWriterHost extends DelegatingHost {
if (sourceFiles.length > 1) { if (sourceFiles.length > 1) {
throw new Error('Bundled emit with --out is not supported'); 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]); this.writeMetadata(fileName, sourceFiles[0]);
} }
} }

View File

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

View File

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