@atlaspack/core 2.12.1-canary.3547 → 2.12.1-canary.3548
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/lib/Atlaspack.js +7 -2
- package/lib/atlaspack-v3/WorkerPool.js +32 -10
- package/package.json +17 -17
- package/src/Atlaspack.js +12 -2
- package/src/atlaspack-v3/WorkerPool.js +37 -10
- package/test/atlaspack-v3/WorkerPool.test.js +5 -1
package/lib/Atlaspack.js
CHANGED
|
@@ -166,10 +166,16 @@ class Atlaspack {
|
|
|
166
166
|
(0, _featureFlags().setFeatureFlags)(featureFlags);
|
|
167
167
|
await _sourceMap().init;
|
|
168
168
|
await (_rust().init === null || _rust().init === void 0 ? void 0 : (0, _rust().init)());
|
|
169
|
+
this.#disposable = new (_events().Disposable)();
|
|
169
170
|
try {
|
|
170
171
|
_rust().initializeMonitoring === null || _rust().initializeMonitoring === void 0 || (0, _rust().initializeMonitoring)();
|
|
171
|
-
|
|
172
|
+
const onExit = () => {
|
|
172
173
|
_rust().closeMonitoring === null || _rust().closeMonitoring === void 0 || (0, _rust().closeMonitoring)();
|
|
174
|
+
};
|
|
175
|
+
process.on('exit', onExit);
|
|
176
|
+
this.#disposable.add(() => {
|
|
177
|
+
process.off('exit', onExit);
|
|
178
|
+
onExit();
|
|
173
179
|
});
|
|
174
180
|
} catch (e) {
|
|
175
181
|
// Fallthrough
|
|
@@ -231,7 +237,6 @@ class Atlaspack {
|
|
|
231
237
|
ref: optionsRef
|
|
232
238
|
} = await this.#farm.createSharedReference(resolvedOptions, false);
|
|
233
239
|
this.#optionsRef = optionsRef;
|
|
234
|
-
this.#disposable = new (_events().Disposable)();
|
|
235
240
|
if (this.#initialOptions.workerFarm) {
|
|
236
241
|
// If we don't own the farm, dispose of only these references when
|
|
237
242
|
// Atlaspack ends.
|
|
@@ -13,6 +13,13 @@ function _path() {
|
|
|
13
13
|
};
|
|
14
14
|
return data;
|
|
15
15
|
}
|
|
16
|
+
function _promises() {
|
|
17
|
+
const data = require("timers/promises");
|
|
18
|
+
_promises = function () {
|
|
19
|
+
return data;
|
|
20
|
+
};
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
16
23
|
function _worker_threads() {
|
|
17
24
|
const data = require("worker_threads");
|
|
18
25
|
_worker_threads = function () {
|
|
@@ -32,8 +39,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
32
39
|
* This "WorkerPool" mitigates this problem by reusing worker threads across
|
|
33
40
|
* builds.
|
|
34
41
|
*/
|
|
42
|
+
// $FlowFixMe Missing types
|
|
35
43
|
const WORKER_PATH = _path().default.join(__dirname, 'worker', 'index.js');
|
|
36
|
-
function waitForMessage(worker, type) {
|
|
44
|
+
function waitForMessage(worker, type, signal) {
|
|
37
45
|
return new Promise(resolve => {
|
|
38
46
|
const onMessage = message => {
|
|
39
47
|
if (message.type === type) {
|
|
@@ -42,6 +50,11 @@ function waitForMessage(worker, type) {
|
|
|
42
50
|
}
|
|
43
51
|
};
|
|
44
52
|
worker.on('message', onMessage);
|
|
53
|
+
const onAbort = () => {
|
|
54
|
+
signal.removeEventListener('abort', onAbort);
|
|
55
|
+
worker.off('message', onMessage);
|
|
56
|
+
};
|
|
57
|
+
signal.addEventListener('abort', onAbort);
|
|
45
58
|
});
|
|
46
59
|
}
|
|
47
60
|
class WorkerPool {
|
|
@@ -117,22 +130,31 @@ class WorkerPool {
|
|
|
117
130
|
return this.#workerPool[workerId];
|
|
118
131
|
}
|
|
119
132
|
async #bootWorker(worker, tx_worker) {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
reject(new Error('Worker failed to register in time'));
|
|
123
|
-
}, 5000);
|
|
124
|
-
});
|
|
133
|
+
const controller = new AbortController();
|
|
134
|
+
const signal = controller.signal;
|
|
125
135
|
const workerError = new Promise((_, reject) => {
|
|
126
|
-
|
|
136
|
+
const onError = err => {
|
|
127
137
|
reject(err);
|
|
128
|
-
}
|
|
138
|
+
};
|
|
139
|
+
worker.once('error', onError);
|
|
140
|
+
const onAbort = () => {
|
|
141
|
+
signal.removeEventListener('abort', onAbort);
|
|
142
|
+
worker.off('error', onError);
|
|
143
|
+
};
|
|
144
|
+
signal.addEventListener('abort', onAbort);
|
|
129
145
|
});
|
|
130
|
-
const workerReady = waitForMessage(worker, 'workerRegistered');
|
|
146
|
+
const workerReady = waitForMessage(worker, 'workerRegistered', signal);
|
|
131
147
|
worker.postMessage({
|
|
132
148
|
type: 'registerWorker',
|
|
133
149
|
tx_worker
|
|
134
150
|
});
|
|
135
|
-
|
|
151
|
+
try {
|
|
152
|
+
await Promise.race([(0, _promises().setTimeout)(5000, {
|
|
153
|
+
signal
|
|
154
|
+
}), workerError, workerReady]);
|
|
155
|
+
} finally {
|
|
156
|
+
controller.abort();
|
|
157
|
+
}
|
|
136
158
|
}
|
|
137
159
|
#createWorker() {
|
|
138
160
|
const worker = new (_worker_threads().Worker)(this.#workerPath, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/core",
|
|
3
|
-
"version": "2.12.1-canary.
|
|
3
|
+
"version": "2.12.1-canary.3548+fbe8fa22b",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,21 +20,21 @@
|
|
|
20
20
|
"check-ts": "tsc --noEmit index.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaspack/build-cache": "2.12.1-canary.
|
|
24
|
-
"@atlaspack/cache": "2.12.1-canary.
|
|
25
|
-
"@atlaspack/diagnostic": "2.12.1-canary.
|
|
26
|
-
"@atlaspack/events": "2.12.1-canary.
|
|
27
|
-
"@atlaspack/feature-flags": "2.12.1-canary.
|
|
28
|
-
"@atlaspack/fs": "2.12.1-canary.
|
|
29
|
-
"@atlaspack/graph": "3.2.1-canary.
|
|
30
|
-
"@atlaspack/logger": "2.12.1-canary.
|
|
31
|
-
"@atlaspack/package-manager": "2.12.1-canary.
|
|
32
|
-
"@atlaspack/plugin": "2.12.1-canary.
|
|
33
|
-
"@atlaspack/profiler": "2.12.1-canary.
|
|
34
|
-
"@atlaspack/rust": "2.12.1-canary.
|
|
35
|
-
"@atlaspack/types": "2.12.1-canary.
|
|
36
|
-
"@atlaspack/utils": "2.12.1-canary.
|
|
37
|
-
"@atlaspack/workers": "2.12.1-canary.
|
|
23
|
+
"@atlaspack/build-cache": "2.12.1-canary.3548+fbe8fa22b",
|
|
24
|
+
"@atlaspack/cache": "2.12.1-canary.3548+fbe8fa22b",
|
|
25
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3548+fbe8fa22b",
|
|
26
|
+
"@atlaspack/events": "2.12.1-canary.3548+fbe8fa22b",
|
|
27
|
+
"@atlaspack/feature-flags": "2.12.1-canary.3548+fbe8fa22b",
|
|
28
|
+
"@atlaspack/fs": "2.12.1-canary.3548+fbe8fa22b",
|
|
29
|
+
"@atlaspack/graph": "3.2.1-canary.3548+fbe8fa22b",
|
|
30
|
+
"@atlaspack/logger": "2.12.1-canary.3548+fbe8fa22b",
|
|
31
|
+
"@atlaspack/package-manager": "2.12.1-canary.3548+fbe8fa22b",
|
|
32
|
+
"@atlaspack/plugin": "2.12.1-canary.3548+fbe8fa22b",
|
|
33
|
+
"@atlaspack/profiler": "2.12.1-canary.3548+fbe8fa22b",
|
|
34
|
+
"@atlaspack/rust": "2.12.1-canary.3548+fbe8fa22b",
|
|
35
|
+
"@atlaspack/types": "2.12.1-canary.3548+fbe8fa22b",
|
|
36
|
+
"@atlaspack/utils": "2.12.1-canary.3548+fbe8fa22b",
|
|
37
|
+
"@atlaspack/workers": "2.12.1-canary.3548+fbe8fa22b",
|
|
38
38
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
39
39
|
"@parcel/source-map": "^2.1.1",
|
|
40
40
|
"base-x": "^3.0.8",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"browser": {
|
|
67
67
|
"./src/serializerCore.js": "./src/serializerCore.browser.js"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "fbe8fa22be490b46c13bf02cb1abe63597b94c03"
|
|
70
70
|
}
|
package/src/Atlaspack.js
CHANGED
|
@@ -118,10 +118,21 @@ export default class Atlaspack {
|
|
|
118
118
|
|
|
119
119
|
await initSourcemaps;
|
|
120
120
|
await initRust?.();
|
|
121
|
+
|
|
122
|
+
this.#disposable = new Disposable();
|
|
123
|
+
|
|
121
124
|
try {
|
|
122
125
|
initializeMonitoring?.();
|
|
123
|
-
|
|
126
|
+
|
|
127
|
+
const onExit = () => {
|
|
124
128
|
closeMonitoring?.();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
process.on('exit', onExit);
|
|
132
|
+
|
|
133
|
+
this.#disposable.add(() => {
|
|
134
|
+
process.off('exit', onExit);
|
|
135
|
+
onExit();
|
|
125
136
|
});
|
|
126
137
|
} catch (e) {
|
|
127
138
|
// Fallthrough
|
|
@@ -188,7 +199,6 @@ export default class Atlaspack {
|
|
|
188
199
|
await this.#farm.createSharedReference(resolvedOptions, false);
|
|
189
200
|
this.#optionsRef = optionsRef;
|
|
190
201
|
|
|
191
|
-
this.#disposable = new Disposable();
|
|
192
202
|
if (this.#initialOptions.workerFarm) {
|
|
193
203
|
// If we don't own the farm, dispose of only these references when
|
|
194
204
|
// Atlaspack ends.
|
|
@@ -13,11 +13,17 @@
|
|
|
13
13
|
* builds.
|
|
14
14
|
*/
|
|
15
15
|
import path from 'path';
|
|
16
|
+
// $FlowFixMe Missing types
|
|
17
|
+
import {setTimeout} from 'timers/promises';
|
|
16
18
|
import {Worker} from 'worker_threads';
|
|
17
19
|
|
|
18
20
|
const WORKER_PATH = path.join(__dirname, 'worker', 'index.js');
|
|
19
21
|
|
|
20
|
-
export function waitForMessage<T>(
|
|
22
|
+
export function waitForMessage<T>(
|
|
23
|
+
worker: Worker,
|
|
24
|
+
type: string,
|
|
25
|
+
signal: AbortSignal,
|
|
26
|
+
): Promise<T> {
|
|
21
27
|
return new Promise((resolve) => {
|
|
22
28
|
const onMessage = (message: T & {|type: string|}) => {
|
|
23
29
|
if (message.type === type) {
|
|
@@ -27,6 +33,13 @@ export function waitForMessage<T>(worker: Worker, type: string): Promise<T> {
|
|
|
27
33
|
};
|
|
28
34
|
|
|
29
35
|
worker.on('message', onMessage);
|
|
36
|
+
|
|
37
|
+
const onAbort = () => {
|
|
38
|
+
signal.removeEventListener('abort', onAbort);
|
|
39
|
+
worker.off('message', onMessage);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
signal.addEventListener('abort', onAbort);
|
|
30
43
|
});
|
|
31
44
|
}
|
|
32
45
|
|
|
@@ -114,23 +127,37 @@ export class WorkerPool {
|
|
|
114
127
|
}
|
|
115
128
|
|
|
116
129
|
async #bootWorker(worker: Worker, tx_worker: number): Promise<void> {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
reject(new Error('Worker failed to register in time'));
|
|
120
|
-
}, 5000);
|
|
121
|
-
});
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
const signal = controller.signal;
|
|
122
132
|
|
|
123
133
|
const workerError = new Promise((_, reject) => {
|
|
124
|
-
|
|
134
|
+
const onError = (err: Error) => {
|
|
125
135
|
reject(err);
|
|
126
|
-
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
worker.once('error', onError);
|
|
139
|
+
|
|
140
|
+
const onAbort = () => {
|
|
141
|
+
signal.removeEventListener('abort', onAbort);
|
|
142
|
+
worker.off('error', onError);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
signal.addEventListener('abort', onAbort);
|
|
127
146
|
});
|
|
128
147
|
|
|
129
|
-
const workerReady = waitForMessage(worker, 'workerRegistered');
|
|
148
|
+
const workerReady = waitForMessage(worker, 'workerRegistered', signal);
|
|
130
149
|
|
|
131
150
|
worker.postMessage({type: 'registerWorker', tx_worker});
|
|
132
151
|
|
|
133
|
-
|
|
152
|
+
try {
|
|
153
|
+
await Promise.race([
|
|
154
|
+
setTimeout(5000, {signal}),
|
|
155
|
+
workerError,
|
|
156
|
+
workerReady,
|
|
157
|
+
]);
|
|
158
|
+
} finally {
|
|
159
|
+
controller.abort();
|
|
160
|
+
}
|
|
134
161
|
}
|
|
135
162
|
|
|
136
163
|
#createWorker(): [number, Worker] {
|
|
@@ -6,7 +6,11 @@ import {WorkerPool, waitForMessage} from '../../src/atlaspack-v3/WorkerPool';
|
|
|
6
6
|
import assert from 'assert';
|
|
7
7
|
|
|
8
8
|
function probeStatus(worker: Worker) {
|
|
9
|
-
const response = waitForMessage(
|
|
9
|
+
const response = waitForMessage(
|
|
10
|
+
worker,
|
|
11
|
+
'status',
|
|
12
|
+
new AbortController().signal,
|
|
13
|
+
);
|
|
10
14
|
worker.postMessage({type: 'probeStatus'});
|
|
11
15
|
return response;
|
|
12
16
|
}
|