diff --git a/packages/tsc-wrapped/index.ts b/packages/tsc-wrapped/index.ts index f939fbfdcb..0079e4af5b 100644 --- a/packages/tsc-wrapped/index.ts +++ b/packages/tsc-wrapped/index.ts @@ -6,12 +6,5 @@ * found in the LICENSE file at https://angular.io/license */ -export {MetadataWriterHost} from './src/compiler_host'; -export {CodegenExtension, UserError, createBundleIndexHost, main} from './src/main'; - -export {default as AngularCompilerOptions} from './src/options'; -export * from './src/bundler'; -export * from './src/cli_options'; -export * from './src/collector'; -export * from './src/index_writer'; -export * from './src/schema'; +export {main} from './src/main'; +export * from './index_no_tsickle'; diff --git a/packages/tsc-wrapped/index_no_tsickle.ts b/packages/tsc-wrapped/index_no_tsickle.ts new file mode 100644 index 0000000000..845e1e35c1 --- /dev/null +++ b/packages/tsc-wrapped/index_no_tsickle.ts @@ -0,0 +1,19 @@ +/** + * @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 + */ + +// This index allows tsc-wrapped to be used with no dependency on tsickle. +// Short-term workaround until tsc-wrapped is removed entirely. +export {MetadataWriterHost} from './src/compiler_host'; +export {CodegenExtension, UserError, createBundleIndexHost} from './src/main_no_tsickle'; +export {default as AngularCompilerOptions} from './src/options'; + +export * from './src/bundler'; +export * from './src/cli_options'; +export * from './src/collector'; +export * from './src/index_writer'; +export * from './src/schema'; diff --git a/packages/tsc-wrapped/src/main.ts b/packages/tsc-wrapped/src/main.ts index 9c208860b3..977e90dc7b 100644 --- a/packages/tsc-wrapped/src/main.ts +++ b/packages/tsc-wrapped/src/main.ts @@ -11,60 +11,15 @@ import * as path from 'path'; import * as tsickle from 'tsickle'; import * as ts from 'typescript'; -import {CompilerHostAdapter, MetadataBundler} from './bundler'; import {CliOptions} from './cli_options'; -import {MetadataWriterHost, createSyntheticIndexHost} from './compiler_host'; -import {privateEntriesToIndex} from './index_writer'; -import NgOptions from './options'; +import {MetadataWriterHost} from './compiler_host'; + +import {CodegenExtension, createBundleIndexHost} from './main_no_tsickle'; import {check, tsc} from './tsc'; -import {isVinylFile, VinylFile} from './vinyl_file'; +import {VinylFile, isVinylFile} from './vinyl_file'; -export {UserError} from './tsc'; - -const DTS = /\.d\.ts$/; -const JS_EXT = /(\.js|)$/; const TS_EXT = /\.ts$/; -export interface CodegenExtension { - /** - * Returns the generated file names. - */ - (ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, - host: ts.CompilerHost): Promise; -} - -export function createBundleIndexHost( - ngOptions: NgOptions, rootFiles: string[], - host: H): {host: H, indexName?: string, errors?: ts.Diagnostic[]} { - const files = rootFiles.filter(f => !DTS.test(f)); - if (files.length != 1) { - return { - host, - errors: [{ - file: null as any as ts.SourceFile, - start: null as any as number, - length: null as any as number, - messageText: - '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 bundler = - new MetadataBundler(indexModule, ngOptions.flatModuleId, new CompilerHostAdapter(host)); - const metadataBundle = bundler.getMetadataBundle(); - const metadata = JSON.stringify(metadataBundle.metadata); - 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 = createSyntheticIndexHost(host, {name, content, metadata}); - return {host, indexName: name}; -} - export function main( project: string | VinylFile, cliOptions: CliOptions, codegen?: CodegenExtension, options?: ts.CompilerOptions): Promise { diff --git a/packages/tsc-wrapped/src/main_no_tsickle.ts b/packages/tsc-wrapped/src/main_no_tsickle.ts new file mode 100644 index 0000000000..8097b085bc --- /dev/null +++ b/packages/tsc-wrapped/src/main_no_tsickle.ts @@ -0,0 +1,61 @@ +/** + * @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 + */ + +import * as path from 'path'; +import * as ts from 'typescript'; + +import {CompilerHostAdapter, MetadataBundler} from './bundler'; +import {CliOptions} from './cli_options'; +import {createSyntheticIndexHost} from './compiler_host'; +import {privateEntriesToIndex} from './index_writer'; +import NgOptions from './options'; + +export {UserError} from './tsc'; + +export interface CodegenExtension { + /** + * Returns the generated file names. + */ + (ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, + host: ts.CompilerHost): Promise; +} + +const DTS = /\.d\.ts$/; +const JS_EXT = /(\.js|)$/; + +export function createBundleIndexHost( + ngOptions: NgOptions, rootFiles: string[], + host: H): {host: H, indexName?: string, errors?: ts.Diagnostic[]} { + const files = rootFiles.filter(f => !DTS.test(f)); + if (files.length != 1) { + return { + host, + errors: [{ + file: null as any as ts.SourceFile, + start: null as any as number, + length: null as any as number, + messageText: + '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 bundler = + new MetadataBundler(indexModule, ngOptions.flatModuleId, new CompilerHostAdapter(host)); + const metadataBundle = bundler.getMetadataBundle(); + const metadata = JSON.stringify(metadataBundle.metadata); + 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 = createSyntheticIndexHost(host, {name, content, metadata}); + return {host, indexName: name}; +} \ No newline at end of file