Skip to content

Commit 432302f

Browse files
committed
perf(@angular/cli): avoid eager module loading during global bootstrap
Avoid importing `isWarningEnabled` and `colors` statically in `init.ts`. Eagerly importing `config.ts` causes `@angular-devkit/core` and its transitive dependencies (`rxjs`, `ajv`, `jsonc-parser`, and schema registries) to be evaluated synchronously in the global CLI context before resolving the project local CLI. By lazily importing `config.ts` and `color.ts` only when `isGlobalGreater` is true and a version mismatch warning needs to be issued, cold CLI invocations avoid evaluating these packages globally during bootstrap.
1 parent a6ef9cf commit 432302f

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

packages/angular/cli/lib/init.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { readFile } from 'node:fs/promises';
1010
import { createRequire } from 'node:module';
1111
import * as path from 'node:path';
1212
import { SemVer, major } from 'semver';
13-
import { colors } from '../src/utilities/color';
14-
import { isWarningEnabled } from '../src/utilities/config';
1513
import { disableVersionCheck } from '../src/utilities/environment-options';
1614
import { VERSION } from '../src/utilities/version';
1715

@@ -125,15 +123,19 @@ let forceExit = false;
125123
cli.VERSION.major - globalVersion.major <= 1
126124
) {
127125
cli = await import('./cli');
128-
} else if (await isWarningEnabled('versionMismatch')) {
129-
// Otherwise, use local version and warn if global is newer than local
130-
const warning =
131-
`Your global Angular CLI version (${globalVersion}) is greater than your local ` +
132-
`version (${localVersion}). The local Angular CLI version is used.\n\n` +
133-
'To disable this warning use "ng config -g cli.warnings.versionMismatch false".';
134-
135-
// eslint-disable-next-line no-console
136-
console.error(colors.yellow(warning));
126+
} else {
127+
const { isWarningEnabled } = await import('../src/utilities/config');
128+
if (await isWarningEnabled('versionMismatch')) {
129+
// Otherwise, use local version and warn if global is newer than local
130+
const warning =
131+
`Your global Angular CLI version (${globalVersion}) is greater than your local ` +
132+
`version (${localVersion}). The local Angular CLI version is used.\n\n` +
133+
'To disable this warning use "ng config -g cli.warnings.versionMismatch false".';
134+
135+
const { colors } = await import('../src/utilities/color');
136+
// eslint-disable-next-line no-console
137+
console.error(colors.yellow(warning));
138+
}
137139
}
138140
}
139141
} catch {

0 commit comments

Comments
 (0)