Skip to content

Commit b6af3f6

Browse files
committed
refactor(@angular-devkit/build-angular): remove old worker_threads detection
We now don't support Node 10 hence `worker_threads` are always available. (cherry picked from commit 9d6c1da)
1 parent 1fe6cb4 commit b6af3f6

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

packages/angular_devkit/build_angular/src/utils/action-executor.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,12 @@
99
import JestWorker from 'jest-worker';
1010
import * as os from 'os';
1111
import * as path from 'path';
12-
import * as v8 from 'v8';
12+
import { serialize } from 'v8';
1313
import { BundleActionCache } from './action-cache';
1414
import { I18nOptions } from './i18n-options';
1515
import { InlineOptions, ProcessBundleOptions, ProcessBundleResult } from './process-bundle';
1616
import { maxWorkers } from './workers';
1717

18-
const hasThreadSupport = (() => {
19-
try {
20-
require('worker_threads');
21-
22-
return true;
23-
} catch {
24-
return false;
25-
}
26-
})();
27-
28-
// This is used to normalize serialization messaging across threads and processes
29-
// Threads use the structured clone algorithm which handles more types
30-
// Processes use JSON which is much more limited
31-
const serialize = ((v8 as unknown) as { serialize(value: unknown): Buffer }).serialize;
32-
3318
let workerFile = require.resolve('./process-bundle');
3419
workerFile =
3520
path.extname(workerFile) === '.ts'
@@ -77,9 +62,9 @@ export class BundleActionExecutor {
7762
// The limited number also prevents a large increase in memory usage for an otherwise short operation
7863
return (this.smallWorker = new JestWorker(workerFile, {
7964
exposedMethods: ['process', 'inlineLocales'],
80-
setupArgs: hasThreadSupport ? [this.workerOptions] : [[...serialize(this.workerOptions)]],
65+
setupArgs: [this.workerOptions],
8166
numWorkers: os.cpus().length < 2 ? 1 : 2,
82-
enableWorkerThreads: hasThreadSupport,
67+
enableWorkerThreads: true,
8368
}));
8469
}
8570

0 commit comments

Comments
 (0)