Skip to content

Commit c35b43c

Browse files
committed
refactor(@angular/build): explicitly target worker script in i18n inliner task execution
Specify the worker target file directly in each task run option via #runWorkerTask rather than hardcoding a default filename during WorkerPool instantiation. To prepare for ESM transition and avoid reliance on ambient require, createRequire is used to resolve the inliner worker script path. Explicitly specifying the worker file per task enables the inliner to run against general-purpose or shared worker pools that do not have a preconfigured default script.
1 parent ed189a2 commit c35b43c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

packages/angular/build/src/tools/esbuild/i18n-inliner.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import type { ɵParsedTranslation } from '@angular/localize';
1010
import assert from 'node:assert';
11+
import { createRequire } from 'node:module';
1112
import { extname, join } from 'node:path';
1213
import { serialize } from 'node:v8';
1314
import { calculateHash, createContentHash, initializeHash } from '../../utils/hash';
@@ -22,6 +23,10 @@ import type {
2223
} from './i18n-inliner-worker';
2324
import { encodeTranslationToBuffer } from './i18n-translation-encoder';
2425

26+
// TODO: Convert to import.meta usage during ESM transition
27+
const localRequire = createRequire(__filename);
28+
const INLINER_WORKER_PATH = localRequire.resolve('./i18n-inliner-worker');
29+
2530
interface WorkerTaskMap {
2631
inlineFileBatch: {
2732
request: InlineFileBatchRequest;
@@ -187,7 +192,6 @@ export class I18nInliner {
187192
maxThreads?: number,
188193
) {
189194
this.#workerPool = new WorkerPool({
190-
filename: require.resolve('./i18n-inliner-worker'),
191195
maxThreads,
192196
});
193197
}
@@ -562,7 +566,10 @@ export class I18nInliner {
562566
name: T,
563567
request: WorkerTaskMap[T]['request'],
564568
): Promise<WorkerTaskMap[T]['result']> {
565-
return this.#workerPool.run(request, { name }) as Promise<WorkerTaskMap[T]['result']>;
569+
return this.#workerPool.run(request, {
570+
filename: INLINER_WORKER_PATH,
571+
name,
572+
}) as Promise<WorkerTaskMap[T]['result']>;
566573
}
567574

568575
/**

0 commit comments

Comments
 (0)