Skip to content

Commit 7502fee

Browse files
committed
fix(@angular/build): Exclude known --import from execArgv when spawning workers
This change prevents Bazel compilation issues in the ADEV build process. (cherry picked from commit 3371f5b)
1 parent 1abb384 commit 7502fee

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

packages/angular/build/src/tools/esbuild/javascript-transformer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { createHash } from 'node:crypto';
1010
import { readFile } from 'node:fs/promises';
11+
import { IMPORT_EXEC_ARGV } from '../../utils/server-rendering/esm-in-memory-loader/utils';
1112
import { WorkerPool } from '../../utils/worker-pool';
1213
import { Cache } from './cache';
1314

@@ -59,7 +60,7 @@ export class JavaScriptTransformer {
5960
filename: require.resolve('./javascript-transformer-worker'),
6061
maxThreads: this.maxThreads,
6162
// Prevent passing `--import` (loader-hooks) from parent to child worker.
62-
execArgv: [],
63+
execArgv: process.execArgv.filter((v) => v !== IMPORT_EXEC_ARGV),
6364
});
6465

6566
return this.#workerPool;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { join } from 'node:path';
10+
import { pathToFileURL } from 'node:url';
11+
12+
export const IMPORT_EXEC_ARGV =
13+
'--import=' + pathToFileURL(join(__dirname, 'register-hooks.js')).href;

packages/angular/build/src/utils/server-rendering/prerender.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*/
88

99
import { readFile } from 'node:fs/promises';
10-
import { extname, join, posix } from 'node:path';
11-
import { pathToFileURL } from 'node:url';
10+
import { extname, posix } from 'node:path';
1211
import { NormalizedApplicationBuildOptions } from '../../builders/application/options';
1312
import { OutputMode } from '../../builders/application/schema';
1413
import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-context';
1514
import { BuildOutputAsset } from '../../tools/esbuild/bundler-execution-result';
1615
import { assertIsError } from '../error';
1716
import { urlJoin } from '../url';
1817
import { WorkerPool } from '../worker-pool';
18+
import { IMPORT_EXEC_ARGV } from './esm-in-memory-loader/utils';
1919
import {
2020
RouteRenderMode,
2121
RoutersExtractorWorkerResult,
@@ -194,12 +194,7 @@ async function renderPages(
194194
}> {
195195
const output: PrerenderOutput = {};
196196
const errors: string[] = [];
197-
198-
const workerExecArgv = [
199-
'--import',
200-
// Loader cannot be an absolute path on Windows.
201-
pathToFileURL(join(__dirname, 'esm-in-memory-loader/register-hooks.js')).href,
202-
];
197+
const workerExecArgv = [IMPORT_EXEC_ARGV];
203198

204199
if (sourcemap) {
205200
workerExecArgv.push('--enable-source-maps');
@@ -301,11 +296,7 @@ async function getAllRoutes(
301296
return { errors: [], serializedRouteTree: routes };
302297
}
303298

304-
const workerExecArgv = [
305-
'--import',
306-
// Loader cannot be an absolute path on Windows.
307-
pathToFileURL(join(__dirname, 'esm-in-memory-loader/register-hooks.js')).href,
308-
];
299+
const workerExecArgv = [IMPORT_EXEC_ARGV];
309300

310301
if (sourcemap) {
311302
workerExecArgv.push('--enable-source-maps');

0 commit comments

Comments
 (0)