Skip to content
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 @@ -66,28 +66,23 @@ export class ParallelCompilation extends AngularCompilation {
);

this.#webWorkerChannel?.port1.close();
this.#webWorkerChannel = undefined;

let webWorkerSignal: Int32Array | undefined;
if (buildType !== 'library') {
// The web worker processing is a synchronous operation and uses shared memory combined with
// the Atomics API to block execution here until a response is received.
const webWorkerChannel = new MessageChannel();
this.#webWorkerChannel = webWorkerChannel;
const signal = new Int32Array(new SharedArrayBuffer(4));
webWorkerSignal = signal;
webWorkerChannel.port1.on('message', ({ workerFile, containingFile }) => {
try {
const workerCodeFile = hostOptions.processWebWorker(workerFile, containingFile);
webWorkerChannel.port1.postMessage({ workerCodeFile });
} catch (error) {
webWorkerChannel.port1.postMessage({ error });
} finally {
Atomics.store(signal, 0, 1);
Atomics.notify(signal, 0);
}
});
}
// The web worker processing is a synchronous operation and uses shared memory combined with
// the Atomics API to block execution here until a response is received.
const webWorkerChannel = new MessageChannel();
this.#webWorkerChannel = webWorkerChannel;
const webWorkerSignal = new Int32Array(new SharedArrayBuffer(4));
webWorkerChannel.port1.on('message', ({ workerFile, containingFile }) => {
try {
const workerCodeFile = hostOptions.processWebWorker(workerFile, containingFile);
webWorkerChannel.port1.postMessage({ workerCodeFile });
} catch (error) {
webWorkerChannel.port1.postMessage({ error });
} finally {
Atomics.store(webWorkerSignal, 0, 1);
Atomics.notify(webWorkerSignal, 0);
}
});

let success = false;
try {
Expand All @@ -100,14 +95,12 @@ export class ParallelCompilation extends AngularCompilation {
browserOnlyBuild: this.browserOnlyBuild,
compilerOptionOverrides,
stylesheetPort: stylesheetChannel.port2,
webWorkerPort: this.#webWorkerChannel?.port2,
webWorkerPort: webWorkerChannel.port2,
webWorkerSignal,
},
{
name: 'initialize',
transferList: this.#webWorkerChannel
? [stylesheetChannel.port2, this.#webWorkerChannel.port2]
: [stylesheetChannel.port2],
transferList: [stylesheetChannel.port2, webWorkerChannel.port2],
},
);
success = true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type { PartialMessage } from 'esbuild';
import assert from 'node:assert';
import { randomUUID } from 'node:crypto';
Comment thread
alan-agius4 marked this conversation as resolved.
import { type MessagePort, receiveMessageOnPort } from 'node:worker_threads';
import { initializeHash } from '../../../utils/hash';
import { getAndClearCumulativeDurations } from '../../../utils/profiling';
Expand All @@ -27,8 +28,8 @@ export interface InitRequest {
fileReplacements?: Record<string, string>;
compilerOptionOverrides?: CompilerOptionOverrides;
stylesheetPort: MessagePort;
webWorkerPort?: MessagePort;
webWorkerSignal?: Int32Array;
webWorkerPort: MessagePort;
webWorkerSignal: Int32Array;
}

let compilation: AngularCompilation | undefined;
Expand All @@ -50,9 +51,8 @@ export async function initialize(request: InitRequest): Promise<AngularCompilati
? new JitCompilation(request.browserOnlyBuild)
: new AotCompilation(request.browserOnlyBuild);

let nextRequestId = 0;
const stylesheetRequests = new Map<
number,
string,
[(value: string) => void, (reason: Error) => void]
>();
request.stylesheetPort.on('message', ({ requestId, value, error }) => {
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function initialize(request: InitRequest): Promise<AngularCompilati
fileReplacements: request.fileReplacements,
modifiedFiles: currentModifiedFiles,
transformStylesheet(data, containingFile, stylesheetFile, order, className) {
const requestId = ++nextRequestId;
const requestId = randomUUID();
Comment thread
alan-agius4 marked this conversation as resolved.
const resultPromise = new Promise<string>((resolve, reject) =>
stylesheetRequests.set(requestId, [resolve, reject]),
);
Expand All @@ -97,10 +97,6 @@ export async function initialize(request: InitRequest): Promise<AngularCompilati
return resultPromise;
},
processWebWorker(workerFile, containingFile) {
if (!request.webWorkerPort || !request.webWorkerSignal) {
return workerFile;
}

Atomics.store(request.webWorkerSignal, 0, 0);
request.webWorkerPort.postMessage({ workerFile, containingFile });

Expand Down
Loading