fix(angular): convert-to-rspack should ensure zone.js is not treated as local file (#30966)

## Current Behavior
The `@nx/angular:convert-to-rspack` relies on `require.resolve` to check
if entries listed in the `polyfills` array is an npm package.
However, in some circumstances such as generating a new app, `zone.js`
is not yet installed and therefore require.resolve will not resolve the
package.

## Expected Behavior
Ensure that `zone.js` is special cased as it is a polyfill that is
always needed to be treated as a package.
This is also the only polyfill that is set during generation of an app
and therefore is the only package that should run into this issue.
This commit is contained in:
Colum Ferry 2025-05-01 18:18:32 +01:00 committed by GitHub
parent e239a15052
commit 11ca6fc685
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -15,7 +15,7 @@ exports[`app --minimal should generate a correct setup when --bundler=rspack and
"index": "./src/index.html", "index": "./src/index.html",
"browser": "./src/main.ts", "browser": "./src/main.ts",
"polyfills": [ "polyfills": [
"./zone.js" "zone.js"
], ],
"tsConfig": "./tsconfig.app.json", "tsConfig": "./tsconfig.app.json",
"assets": [ "assets": [
@ -162,7 +162,7 @@ exports[`app --minimal should generate a correct setup when --bundler=rspack inc
"index": "./src/index.html", "index": "./src/index.html",
"browser": "./src/main.ts", "browser": "./src/main.ts",
"polyfills": [ "polyfills": [
"./zone.js" "zone.js"
], ],
"tsConfig": "./tsconfig.app.json", "tsConfig": "./tsconfig.app.json",
"assets": [ "assets": [

View File

@ -111,6 +111,10 @@ const PATH_NORMALIZER = {
polyfills: (tree: Tree, paths: string | string[], root: string) => { polyfills: (tree: Tree, paths: string | string[], root: string) => {
const normalizedPaths: string[] = []; const normalizedPaths: string[] = [];
const normalizeFn = (path: string) => { const normalizeFn = (path: string) => {
if (path.startsWith('zone.js')) {
normalizedPaths.push(path);
return;
}
try { try {
const resolvedPath = require.resolve(path, { const resolvedPath = require.resolve(path, {
paths: [join(workspaceRoot, 'node_modules')], paths: [join(workspaceRoot, 'node_modules')],