Repository navigation
perf(@angular/cli): avoid eager module loading during global bootstrap - #33811
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes startup performance in the Angular CLI initialization by refactoring the static imports of colors and isWarningEnabled into dynamic imports that are only loaded when a version mismatch warning is triggered. The review feedback highlights a potential issue where an error during these dynamic imports or the warning check could cause the outer try-catch block to silently fall back to the global CLI instead of using the local CLI. It is recommended to wrap this non-critical warning logic in its own try-catch block to prevent such failures from affecting the CLI execution flow.
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.
432302f to
debafb5
Compare
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Avoid importing
isWarningEnabledandcolorsstatically ininit.ts. Eagerly importingconfig.tscauses@angular-devkit/coreand 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.tsandcolor.tsonly whenisGlobalGreateris true and a version mismatch warning needs to be issued, cold CLI invocations avoid evaluating these packages globally during bootstrap.