Skip to content

Commit 999d84c

Browse files
authored
perf(@angular/build): avoid loading compiler-cli and typescript in js transform worker
Previously, `OxcLinker` imported `ConsoleLogger` and `LogLevel` directly from `@angular/compiler-cli`. Even though `@angular/compiler-cli/linker` is an isolated, lightweight runtime (depending only on `semver` and `convert-source-map`), resolving the main `@angular/compiler-cli` entry point (`bundles/index.js`) eagerly evaluated the full `ngtsc` compiler toolchain and required the 10 MB `typescript.js` bundle at the top level.
1 parent a0a6b42 commit 999d84c

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

‎packages/angular/build/src/tools/angular/linker/oxc-linker.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { ConsoleLogger, LogLevel } from '@angular/compiler-cli';
9+
import type { Logger } from '@angular/compiler-cli';
1010
import { type DeclarationScope, FileLinker, LinkerEnvironment } from '@angular/compiler-cli/linker';
1111
import type {
1212
AbsoluteFsPath,
@@ -45,7 +45,34 @@ const noopFileSystem: ReadonlyFileSystem = {
4545
relative: (_from: string, to: string) => to,
4646
} as unknown as ReadonlyFileSystem;
4747

48-
let SHARED_LOGGER: ConsoleLogger;
48+
const defaultLogger: Logger = {
49+
level: 1, // LogLevel.info
50+
debug(...args: string[]) {
51+
if (this.level <= 0) {
52+
// eslint-disable-next-line no-console
53+
console.debug(...args);
54+
}
55+
},
56+
info(...args: string[]) {
57+
if (this.level <= 1) {
58+
// eslint-disable-next-line no-console
59+
console.info(...args);
60+
}
61+
},
62+
warn(...args: string[]) {
63+
if (this.level <= 2) {
64+
// eslint-disable-next-line no-console
65+
console.warn(...args);
66+
}
67+
},
68+
error(...args: string[]) {
69+
if (this.level <= 3) {
70+
// eslint-disable-next-line no-console
71+
console.error(...args);
72+
}
73+
},
74+
};
75+
4976
let SHARED_AST_HOST: OxcAstHost;
5077
let SHARED_DECLARATION_SCOPE: InlineDeclarationScope;
5178

@@ -56,14 +83,13 @@ export class OxcLinker {
5683
readonly #fileLinker: FileLinker<unknown, string, unknown, string | undefined>;
5784

5885
constructor(filename: string, code: string, jit = false) {
59-
SHARED_LOGGER ??= new ConsoleLogger(LogLevel.info);
6086
SHARED_AST_HOST ??= new OxcAstHost();
6187
SHARED_DECLARATION_SCOPE ??= new InlineDeclarationScope();
6288

6389
const astFactory = new StringAstFactory(code);
6490
const linkerEnvironment = LinkerEnvironment.create(
6591
noopFileSystem,
66-
SHARED_LOGGER,
92+
defaultLogger,
6793
SHARED_AST_HOST,
6894
astFactory,
6995
{ linkerJitMode: jit, sourceMapping: false },

0 commit comments

Comments
 (0)