Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/build): Exclude known --import from execArgv when spawning workers #28758

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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