Skip to content

Commit

Permalink
fix(@angular/build): Exclude known --import from execArgv when spaw…
Browse files Browse the repository at this point in the history
…ning workers

This change prevents Bazel compilation issues in the ADEV build process.

(cherry picked from commit 3371f5b)
  • Loading branch information
alan-agius4 committed Oct 31, 2024
1 parent 1abb384 commit 7502fee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

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

return this.#workerPool;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { join } from 'node:path';
import { pathToFileURL } from 'node:url';

export const IMPORT_EXEC_ARGV =
'--import=' + pathToFileURL(join(__dirname, 'register-hooks.js')).href;
17 changes: 4 additions & 13 deletions packages/angular/build/src/utils/server-rendering/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*/

import { readFile } from 'node:fs/promises';
import { extname, join, posix } from 'node:path';
import { pathToFileURL } from 'node:url';
import { extname, posix } from 'node:path';
import { NormalizedApplicationBuildOptions } from '../../builders/application/options';
import { OutputMode } from '../../builders/application/schema';
import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-context';
import { BuildOutputAsset } from '../../tools/esbuild/bundler-execution-result';
import { assertIsError } from '../error';
import { urlJoin } from '../url';
import { WorkerPool } from '../worker-pool';
import { IMPORT_EXEC_ARGV } from './esm-in-memory-loader/utils';
import {
RouteRenderMode,
RoutersExtractorWorkerResult,
Expand Down Expand Up @@ -194,12 +194,7 @@ async function renderPages(
}> {
const output: PrerenderOutput = {};
const errors: string[] = [];

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

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

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

if (sourcemap) {
workerExecArgv.push('--enable-source-maps');
Expand Down

0 comments on commit 7502fee

Please sign in to comment.