@parcel/workers 2.0.0-nightly.121 → 2.0.0-nightly.1212
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +22 -0
- package/lib/Handle.js +14 -45
- package/lib/Profiler.js +20 -10
- package/lib/Trace.js +16 -11
- package/lib/Worker.js +97 -26
- package/lib/WorkerFarm.js +237 -101
- package/lib/bus.js +10 -2
- package/lib/child.js +113 -63
- package/lib/childState.js +1 -1
- package/lib/cpuCount.js +28 -7
- package/lib/index.js +26 -10
- package/lib/process/ProcessChild.js +22 -11
- package/lib/process/ProcessWorker.js +30 -19
- package/lib/threads/ThreadsChild.js +32 -14
- package/lib/threads/ThreadsWorker.js +28 -16
- package/package.json +18 -7
- package/src/Handle.js +10 -39
- package/src/Profiler.js +1 -1
- package/src/Trace.js +8 -4
- package/src/Worker.js +75 -11
- package/src/WorkerFarm.js +195 -50
- package/src/bus.js +1 -1
- package/src/child.js +70 -21
- package/src/cpuCount.js +9 -4
- package/src/index.js +1 -1
- package/src/process/ProcessChild.js +2 -1
- package/src/process/ProcessWorker.js +1 -1
- package/src/threads/ThreadsWorker.js +2 -2
- package/test/cpuCount.test.js +1 -1
- package/test/integration/workerfarm/console.js +1 -1
- package/test/integration/workerfarm/logging.js +1 -1
- package/test/integration/workerfarm/reverse-handle.js +2 -2
- package/test/workerfarm.js +5 -5
|
@@ -25,7 +25,7 @@ export default class ProcessChild implements ChildImpl {
|
|
|
25
25
|
process.on('message', data => this.handleMessage(data));
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
handleMessage(data: string) {
|
|
28
|
+
handleMessage(data: string): void {
|
|
29
29
|
if (data === 'die') {
|
|
30
30
|
return this.stop();
|
|
31
31
|
}
|
|
@@ -37,6 +37,7 @@ export default class ProcessChild implements ChildImpl {
|
|
|
37
37
|
let processSend = nullthrows(process.send).bind(process);
|
|
38
38
|
processSend(serialize(data).toString('base64'), err => {
|
|
39
39
|
if (err && err instanceof Error) {
|
|
40
|
+
// $FlowFixMe[prop-missing]
|
|
40
41
|
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
|
41
42
|
// IPC connection closed
|
|
42
43
|
// no need to keep the worker running if it can't send or receive data
|
|
@@ -32,7 +32,7 @@ export default class ThreadsWorker implements WorkerImpl {
|
|
|
32
32
|
this.onExit = onExit;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
start() {
|
|
35
|
+
start(): Promise<void> {
|
|
36
36
|
this.worker = new Worker(WORKER_PATH, {
|
|
37
37
|
execArgv: this.execArgv,
|
|
38
38
|
env: process.env,
|
|
@@ -47,7 +47,7 @@ export default class ThreadsWorker implements WorkerImpl {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
stop() {
|
|
50
|
+
stop(): Promise<void> {
|
|
51
51
|
// In node 12, this returns a promise, but previously it accepted a callback
|
|
52
52
|
// TODO: Pass a callback in earlier versions of Node
|
|
53
53
|
return Promise.resolve(this.worker.terminate());
|
package/test/cpuCount.test.js
CHANGED
|
@@ -3,7 +3,7 @@ import os from 'os';
|
|
|
3
3
|
|
|
4
4
|
import getCores, {detectRealCores} from '../src/cpuCount';
|
|
5
5
|
|
|
6
|
-
describe('cpuCount', function() {
|
|
6
|
+
describe('cpuCount', function () {
|
|
7
7
|
it('Should be able to detect real cpu count', () => {
|
|
8
8
|
// Windows not supported as getting the cpu count takes a couple seconds...
|
|
9
9
|
if (os.platform() === 'win32') return;
|
package/test/workerfarm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Logger from '@parcel/logger';
|
|
2
2
|
import assert from 'assert';
|
|
3
|
-
import WorkerFarm from '../';
|
|
3
|
+
import WorkerFarm from '../src';
|
|
4
4
|
|
|
5
|
-
describe('WorkerFarm', function() {
|
|
5
|
+
describe('WorkerFarm', function () {
|
|
6
6
|
this.timeout(30000);
|
|
7
7
|
|
|
8
8
|
it('Should start up workers', async () => {
|
|
@@ -132,7 +132,7 @@ describe('WorkerFarm', function() {
|
|
|
132
132
|
await workerfarm.end();
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
it('Forwards stdio from the child process and levels event source if
|
|
135
|
+
it('Forwards stdio from the child process and levels event source if shouldPatchConsole is true', async () => {
|
|
136
136
|
let events = [];
|
|
137
137
|
let logDisposable = Logger.onLog(event => events.push(event));
|
|
138
138
|
|
|
@@ -140,7 +140,7 @@ describe('WorkerFarm', function() {
|
|
|
140
140
|
warmWorkers: true,
|
|
141
141
|
useLocalWorker: false,
|
|
142
142
|
workerPath: require.resolve('./integration/workerfarm/console.js'),
|
|
143
|
-
|
|
143
|
+
shouldPatchConsole: true,
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
await workerfarm.run();
|
|
@@ -291,7 +291,7 @@ describe('WorkerFarm', function() {
|
|
|
291
291
|
assert.equal(result, 'Shared reference does not exist');
|
|
292
292
|
});
|
|
293
293
|
|
|
294
|
-
it('
|
|
294
|
+
it('Should resolve shared references in workers', async () => {
|
|
295
295
|
let workerfarm = new WorkerFarm({
|
|
296
296
|
warmWorkers: true,
|
|
297
297
|
useLocalWorker: false,
|