Skip to content

build(@angular/cli): bundle CLI first-party code into ESM chunks with esbuild - #34125

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:cli-esbuild-bundle
Open

clydin wants to merge 1 commit into
angular:mainfrom
clydin:cli-esbuild-bundle

Conversation

@clydin

@clydin clydin commented Sep 18, 2026

Copy link
Copy Markdown
Member

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.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Sep 18, 2026
@angular-robot angular-robot Bot added area: build & ci Related the build and CI infrastructure of the project area: @angular/cli labels Sep 18, 2026
@clydin
clydin force-pushed the cli-esbuild-bundle branch 2 times, most recently from b285291 to 43f2d71 Compare September 18, 2026 19:29
@clydin
clydin marked this pull request as ready for review September 18, 2026 20:27

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/angular/cli/package.json
Comment thread packages/angular/cli/lib/init.ts Outdated
… 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.
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 18, 2026
@clydin
clydin requested a review from alan-agius4 September 18, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/cli area: build & ci Related the build and CI infrastructure of the project target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant