build(@angular/cli): bundle CLI first-party code into ESM chunks with esbuild - #34125
Conversation
b285291 to
43f2d71
Compare
There was a problem hiding this comment.
Code Review
This pull request transitions the Angular CLI package to ES modules, introducing bundling via esbuild, updating TypeScript configurations, and replacing CommonJS-specific globals like __dirname with ESM equivalents. It also optimizes asset loading by importing Markdown files directly as modules and adds a custom ESM loader for testing. Feedback on these changes highlights a critical issue where marking the root package as a module will cause CommonJS binaries in bin/ to crash at runtime, and suggests adding a safety depth limit to the recursive default export unwrapping in lib/init.ts to prevent infinite loops.
43f2d71 to
f3dcb9d
Compare
alan-agius4
left a comment
There was a problem hiding this comment.
Please remove all newly added @ts-ignore strict-deps and eslint-disable-next-line. These should no longer be needed after #34133.
alan-agius4
left a comment
There was a problem hiding this comment.
LGTM, just a couple of NITs
… esbuild Bundle @angular/cli first-party entry points (`lib/cli/index.js` and `lib/init.js`) into ESM chunks using `aspect_rules_esbuild` targeting Node 22 with external packages, code splitting, and bundle sourcemaps disabled. The package `package.json` is now designated as "type": "module", while `bin/package.json` retains CommonJS to allow the `ng` binary bootstrap to validate older Node.js runtimes. A dedicated ES5/CommonJS `bin/version.js` file is stamped by Bazel during release packaging and exposed through a `#version` package subpath import. This enables `bin/ng.js` to perform runtime compatibility checks safely before dynamic ESM import, while allowing bundled chunks to access stamped versions without runtime file I/O. Inlined markdown assets, including MCP resources and command long descriptions, are bundled directly into output chunks via esbuild's text loader, removing the need for runtime filesystem reads and the CommonJS `require.extensions` loader workaround. Ambient `__dirname`, `__filename`, and `createRequire` usages are replaced with `import.meta.dirname` and `import.meta.url`, with `pathToFileURL` used for Windows dynamic imports. A standalone `index.d.ts` declaration file is provided for programmatic package consumers, and unit tests are updated to execute under native Node.js ESM.
f3dcb9d to
0f8d88b
Compare
|
This PR was merged into the repository. The changes were merged into the following branches:
|
Bundle @angular/cli first-party entry points into ESM chunks using aspect_rules_esbuild targeting node22 with external packages. Inlined markdown files are packaged into the output bundle chunks directly using esbuild's text loader, and a lib/package.json marker file is generated to designate the bundled library output as ESM.