From f7cd8a0e45f96c2b65fe10bba791741e1373568b Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 20 Sep 2021 19:30:08 +0200 Subject: [PATCH] refactor(compiler-cli): expose code needed by Angular CLI (#43431) Exposes code needed by the Angular CLI. Previously the CLI used deep imports for most of these things, but now with bundling the CLI, we no longer support deep imports. We will expose the necessary dependencies for the linker as part of the primary entry-point (I think that is more maintable than re-exporting them as part of the linker). We also expose the ngcc entry-point for the CLI with a new constant that will point to the ngcc command line entry-point (which the CLI relies on). PR Close #43431 --- packages/compiler-cli/index.ts | 11 +++++++++-- packages/compiler-cli/ngcc/index.ts | 10 ++++++++++ packages/compiler-cli/package.json | 4 ++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/index.ts b/packages/compiler-cli/index.ts index db4e16f2ce1..6fcdf482cf2 100644 --- a/packages/compiler-cli/index.ts +++ b/packages/compiler-cli/index.ts @@ -21,12 +21,19 @@ export * from './src/perform_compile'; export {CompilerOptions as AngularCompilerOptions} from './src/transformers/api'; export {ngToTsDiagnostic} from './src/transformers/util'; -export {NgTscPlugin} from './src/ngtsc/tsc_plugin'; -export {NgtscProgram} from './src/ngtsc/program'; // Internal exports needed for packages relying on the compiler-cli. // TODO: Consider moving into `@angular/compiler-cli/private`. This would // help with a consistent pattern for cross package imports for Angular. export * from './src/tooling'; +// Exposed as they are needed for relying on the `linker`. +export * from './src/ngtsc/logging'; +export * from './src/ngtsc/file_system'; + +// Exports for dealing with the `ngtsc` program. +export {NgTscPlugin} from './src/ngtsc/tsc_plugin'; +export {NgtscProgram} from './src/ngtsc/program'; +export {OptimizeFor} from './src/ngtsc/typecheck/api'; + setFileSystem(new NodeJSFileSystem()); diff --git a/packages/compiler-cli/ngcc/index.ts b/packages/compiler-cli/ngcc/index.ts index 2dfa3002b97..dc1ea337953 100644 --- a/packages/compiler-cli/ngcc/index.ts +++ b/packages/compiler-cli/ngcc/index.ts @@ -5,6 +5,8 @@ * 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 {join} from 'path'; import {NodeJSFileSystem, setFileSystem} from '../src/ngtsc/file_system'; import {mainNgcc} from './src/main'; @@ -20,3 +22,11 @@ export function process(options: AsyncNgccOptions|SyncNgccOptions): void|Promise setFileSystem(new NodeJSFileSystem()); return mainNgcc(options); } + +/** + * Absolute file path that points to the `ngcc` entry-point. + * + * This can be used by the Angular CLI to spawn a process running ngcc using + * command line options. + */ +export const ngccMainFilePath = join(__dirname, './main-ngcc.js'); diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index 98e05363fa7..c89b4bc3cb2 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -17,6 +17,10 @@ "./package.json": { "default": "./package.json" }, + "./ngcc": { + "types": "./ngcc/index.d.ts", + "default": "./bundles/ngcc/index.js" + }, "./linker": { "types": "./linker/index.d.ts", "default": "./bundles/linker/index.js"