|
9 | 9 | import JestWorker from 'jest-worker';
|
10 | 10 | import * as os from 'os';
|
11 | 11 | import * as path from 'path';
|
12 |
| -import * as v8 from 'v8'; |
| 12 | +import { serialize } from 'v8'; |
13 | 13 | import { BundleActionCache } from './action-cache';
|
14 | 14 | import { I18nOptions } from './i18n-options';
|
15 | 15 | import { InlineOptions, ProcessBundleOptions, ProcessBundleResult } from './process-bundle';
|
16 | 16 | import { maxWorkers } from './workers';
|
17 | 17 |
|
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 |
| - |
33 | 18 | let workerFile = require.resolve('./process-bundle');
|
34 | 19 | workerFile =
|
35 | 20 | path.extname(workerFile) === '.ts'
|
@@ -77,9 +62,9 @@ export class BundleActionExecutor {
|
77 | 62 | // The limited number also prevents a large increase in memory usage for an otherwise short operation
|
78 | 63 | return (this.smallWorker = new JestWorker(workerFile, {
|
79 | 64 | exposedMethods: ['process', 'inlineLocales'],
|
80 |
| - setupArgs: hasThreadSupport ? [this.workerOptions] : [[...serialize(this.workerOptions)]], |
| 65 | + setupArgs: [this.workerOptions], |
81 | 66 | numWorkers: os.cpus().length < 2 ? 1 : 2,
|
82 |
| - enableWorkerThreads: hasThreadSupport, |
| 67 | + enableWorkerThreads: true, |
83 | 68 | }));
|
84 | 69 | }
|
85 | 70 |
|
|
0 commit comments