@utoo/pack 1.0.7 → 1.0.8-alpha.1
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/cjs/binding.d.ts +16 -11
- package/cjs/binding.js +4 -6
- package/cjs/loaderWorkerPool.d.ts +1 -0
- package/cjs/loaderWorkerPool.js +30 -0
- package/cjs/project.js +3 -51
- package/cjs/types.d.ts +1 -0
- package/esm/binding.d.ts +16 -11
- package/esm/binding.js +4 -6
- package/esm/loaderWorkerPool.d.ts +1 -0
- package/esm/loaderWorkerPool.js +27 -0
- package/esm/project.js +3 -51
- package/esm/types.d.ts +1 -0
- package/package.json +8 -8
package/cjs/binding.d.ts
CHANGED
|
@@ -9,20 +9,25 @@ export declare class ExternalObject<T> {
|
|
|
9
9
|
[K: symbol]: T
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
|
|
13
|
+
export declare function workerCreated(workerId: number): void
|
|
14
|
+
export interface NapiWorkerCreation {
|
|
15
|
+
options: NapiWorkerOptions
|
|
15
16
|
}
|
|
16
|
-
export interface
|
|
17
|
-
filename:
|
|
17
|
+
export interface NapiWorkerOptions {
|
|
18
|
+
filename: RcStr
|
|
19
|
+
cwd: RcStr
|
|
20
|
+
}
|
|
21
|
+
export interface NapiWorkerTermination {
|
|
22
|
+
options: NapiWorkerOptions
|
|
18
23
|
workerId: number
|
|
19
24
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function sendTaskMessage(
|
|
25
|
+
export interface NapiTaskMessage {
|
|
26
|
+
taskId: number
|
|
27
|
+
data: string
|
|
28
|
+
}
|
|
29
|
+
export declare function recvTaskMessageInWorker(workerId: number): Promise<NapiTaskMessage>
|
|
30
|
+
export declare function sendTaskMessage(message: NapiTaskMessage): Promise<void>
|
|
26
31
|
export interface NapiEndpointConfig {
|
|
27
32
|
|
|
28
33
|
}
|
package/cjs/binding.js
CHANGED
|
@@ -319,12 +319,10 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
322
|
-
const {
|
|
323
|
-
module.exports.
|
|
324
|
-
module.exports.
|
|
325
|
-
module.exports.
|
|
326
|
-
module.exports.recvMessageInWorker = recvMessageInWorker;
|
|
327
|
-
module.exports.notifyWorkerAck = notifyWorkerAck;
|
|
322
|
+
const { registerWorkerScheduler, workerCreated, recvTaskMessageInWorker, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
323
|
+
module.exports.registerWorkerScheduler = registerWorkerScheduler;
|
|
324
|
+
module.exports.workerCreated = workerCreated;
|
|
325
|
+
module.exports.recvTaskMessageInWorker = recvTaskMessageInWorker;
|
|
328
326
|
module.exports.sendTaskMessage = sendTaskMessage;
|
|
329
327
|
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
330
328
|
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runLoaderWorkerPool(binding: typeof import("./binding"), bindingPath: string): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runLoaderWorkerPool = runLoaderWorkerPool;
|
|
4
|
+
const worker_threads_1 = require("worker_threads");
|
|
5
|
+
const loaderWorkers = {};
|
|
6
|
+
function getPoolId(cwd, filename) {
|
|
7
|
+
return `${cwd}:${filename}`;
|
|
8
|
+
}
|
|
9
|
+
async function runLoaderWorkerPool(binding, bindingPath) {
|
|
10
|
+
binding.registerWorkerScheduler((creation) => {
|
|
11
|
+
const { options: { filename, cwd }, } = creation;
|
|
12
|
+
let poolId = getPoolId(cwd, filename);
|
|
13
|
+
const worker = new worker_threads_1.Worker(filename, {
|
|
14
|
+
workerData: {
|
|
15
|
+
bindingPath,
|
|
16
|
+
cwd,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
worker.unref();
|
|
20
|
+
const workers = loaderWorkers[poolId] || (loaderWorkers[poolId] = new Map());
|
|
21
|
+
workers.set(worker.threadId, worker);
|
|
22
|
+
}, (termination) => {
|
|
23
|
+
var _a;
|
|
24
|
+
const { options: { filename, cwd }, workerId, } = termination;
|
|
25
|
+
let poolId = getPoolId(cwd, filename);
|
|
26
|
+
const workers = loaderWorkers[poolId];
|
|
27
|
+
(_a = workers.get(workerId)) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
28
|
+
workers.delete(workerId);
|
|
29
|
+
});
|
|
30
|
+
}
|
package/cjs/project.js
CHANGED
|
@@ -36,8 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.TurbopackInternalError = void 0;
|
|
37
37
|
exports.projectFactory = projectFactory;
|
|
38
38
|
const util_1 = require("util");
|
|
39
|
-
const worker_threads_1 = require("worker_threads");
|
|
40
39
|
const binding = __importStar(require("./binding"));
|
|
40
|
+
const loaderWorkerPool_1 = require("./loaderWorkerPool");
|
|
41
41
|
const util_2 = require("./util");
|
|
42
42
|
class TurbopackInternalError extends Error {
|
|
43
43
|
constructor(cause) {
|
|
@@ -201,59 +201,11 @@ function projectFactory() {
|
|
|
201
201
|
};
|
|
202
202
|
return iterator;
|
|
203
203
|
}
|
|
204
|
-
const loaderWorkers = {};
|
|
205
|
-
const createOrScalePool = async () => {
|
|
206
|
-
while (true) {
|
|
207
|
-
try {
|
|
208
|
-
let poolOptions = await binding.recvPoolRequest();
|
|
209
|
-
const { filename, maxConcurrency } = poolOptions;
|
|
210
|
-
const workers = loaderWorkers[filename] || (loaderWorkers[filename] = []);
|
|
211
|
-
if (workers.length < maxConcurrency) {
|
|
212
|
-
for (let i = workers.length; i < maxConcurrency; i++) {
|
|
213
|
-
const worker = new worker_threads_1.Worker(filename, {
|
|
214
|
-
workerData: {
|
|
215
|
-
poolId: filename,
|
|
216
|
-
bindingPath: require.resolve("./binding.js"),
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
worker.unref();
|
|
220
|
-
workers.push(worker);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else if (workers.length > maxConcurrency) {
|
|
224
|
-
const workersToStop = workers.splice(0, workers.length - maxConcurrency);
|
|
225
|
-
workersToStop.forEach((worker) => worker.terminate());
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch (e) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
const waitingForWorkerTermination = async () => {
|
|
234
|
-
while (true) {
|
|
235
|
-
try {
|
|
236
|
-
const { filename, workerId } = await binding.recvWorkerTermination();
|
|
237
|
-
const workers = loaderWorkers[filename];
|
|
238
|
-
const workerIdx = workers.findIndex((worker) => worker.threadId === workerId);
|
|
239
|
-
if (workerIdx > -1) {
|
|
240
|
-
const worker = workers.splice(workerIdx, 1);
|
|
241
|
-
worker[0].terminate();
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
catch (e) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
204
|
class ProjectImpl {
|
|
250
205
|
constructor(nativeProject) {
|
|
251
206
|
this._nativeProject = nativeProject;
|
|
252
|
-
if (typeof binding.
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
if (typeof binding.recvWorkerTermination === "function") {
|
|
256
|
-
waitingForWorkerTermination();
|
|
207
|
+
if (typeof binding.registerWorkerScheduler === "function") {
|
|
208
|
+
(0, loaderWorkerPool_1.runLoaderWorkerPool)(binding, require.resolve("@utoo/pack/cjs/binding.js"));
|
|
257
209
|
}
|
|
258
210
|
}
|
|
259
211
|
async update(options) {
|
package/cjs/types.d.ts
CHANGED
package/esm/binding.d.ts
CHANGED
|
@@ -9,20 +9,25 @@ export declare class ExternalObject<T> {
|
|
|
9
9
|
[K: symbol]: T
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
|
|
13
|
+
export declare function workerCreated(workerId: number): void
|
|
14
|
+
export interface NapiWorkerCreation {
|
|
15
|
+
options: NapiWorkerOptions
|
|
15
16
|
}
|
|
16
|
-
export interface
|
|
17
|
-
filename:
|
|
17
|
+
export interface NapiWorkerOptions {
|
|
18
|
+
filename: RcStr
|
|
19
|
+
cwd: RcStr
|
|
20
|
+
}
|
|
21
|
+
export interface NapiWorkerTermination {
|
|
22
|
+
options: NapiWorkerOptions
|
|
18
23
|
workerId: number
|
|
19
24
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function sendTaskMessage(
|
|
25
|
+
export interface NapiTaskMessage {
|
|
26
|
+
taskId: number
|
|
27
|
+
data: string
|
|
28
|
+
}
|
|
29
|
+
export declare function recvTaskMessageInWorker(workerId: number): Promise<NapiTaskMessage>
|
|
30
|
+
export declare function sendTaskMessage(message: NapiTaskMessage): Promise<void>
|
|
26
31
|
export interface NapiEndpointConfig {
|
|
27
32
|
|
|
28
33
|
}
|
package/esm/binding.js
CHANGED
|
@@ -319,12 +319,10 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
322
|
-
const {
|
|
323
|
-
module.exports.
|
|
324
|
-
module.exports.
|
|
325
|
-
module.exports.
|
|
326
|
-
module.exports.recvMessageInWorker = recvMessageInWorker;
|
|
327
|
-
module.exports.notifyWorkerAck = notifyWorkerAck;
|
|
322
|
+
const { registerWorkerScheduler, workerCreated, recvTaskMessageInWorker, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
323
|
+
module.exports.registerWorkerScheduler = registerWorkerScheduler;
|
|
324
|
+
module.exports.workerCreated = workerCreated;
|
|
325
|
+
module.exports.recvTaskMessageInWorker = recvTaskMessageInWorker;
|
|
328
326
|
module.exports.sendTaskMessage = sendTaskMessage;
|
|
329
327
|
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
330
328
|
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runLoaderWorkerPool(binding: typeof import("./binding"), bindingPath: string): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Worker } from "worker_threads";
|
|
2
|
+
const loaderWorkers = {};
|
|
3
|
+
function getPoolId(cwd, filename) {
|
|
4
|
+
return `${cwd}:${filename}`;
|
|
5
|
+
}
|
|
6
|
+
export async function runLoaderWorkerPool(binding, bindingPath) {
|
|
7
|
+
binding.registerWorkerScheduler((creation) => {
|
|
8
|
+
const { options: { filename, cwd }, } = creation;
|
|
9
|
+
let poolId = getPoolId(cwd, filename);
|
|
10
|
+
const worker = new Worker(filename, {
|
|
11
|
+
workerData: {
|
|
12
|
+
bindingPath,
|
|
13
|
+
cwd,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
worker.unref();
|
|
17
|
+
const workers = loaderWorkers[poolId] || (loaderWorkers[poolId] = new Map());
|
|
18
|
+
workers.set(worker.threadId, worker);
|
|
19
|
+
}, (termination) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const { options: { filename, cwd }, workerId, } = termination;
|
|
22
|
+
let poolId = getPoolId(cwd, filename);
|
|
23
|
+
const workers = loaderWorkers[poolId];
|
|
24
|
+
(_a = workers.get(workerId)) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
25
|
+
workers.delete(workerId);
|
|
26
|
+
});
|
|
27
|
+
}
|
package/esm/project.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "util";
|
|
2
|
-
import { Worker } from "worker_threads";
|
|
3
2
|
import * as binding from "./binding";
|
|
3
|
+
import { runLoaderWorkerPool } from "./loaderWorkerPool";
|
|
4
4
|
import { rustifyEnv } from "./util";
|
|
5
5
|
export class TurbopackInternalError extends Error {
|
|
6
6
|
constructor(cause) {
|
|
@@ -163,59 +163,11 @@ export function projectFactory() {
|
|
|
163
163
|
};
|
|
164
164
|
return iterator;
|
|
165
165
|
}
|
|
166
|
-
const loaderWorkers = {};
|
|
167
|
-
const createOrScalePool = async () => {
|
|
168
|
-
while (true) {
|
|
169
|
-
try {
|
|
170
|
-
let poolOptions = await binding.recvPoolRequest();
|
|
171
|
-
const { filename, maxConcurrency } = poolOptions;
|
|
172
|
-
const workers = loaderWorkers[filename] || (loaderWorkers[filename] = []);
|
|
173
|
-
if (workers.length < maxConcurrency) {
|
|
174
|
-
for (let i = workers.length; i < maxConcurrency; i++) {
|
|
175
|
-
const worker = new Worker(filename, {
|
|
176
|
-
workerData: {
|
|
177
|
-
poolId: filename,
|
|
178
|
-
bindingPath: require.resolve("./binding.js"),
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
worker.unref();
|
|
182
|
-
workers.push(worker);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
else if (workers.length > maxConcurrency) {
|
|
186
|
-
const workersToStop = workers.splice(0, workers.length - maxConcurrency);
|
|
187
|
-
workersToStop.forEach((worker) => worker.terminate());
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
catch (e) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
const waitingForWorkerTermination = async () => {
|
|
196
|
-
while (true) {
|
|
197
|
-
try {
|
|
198
|
-
const { filename, workerId } = await binding.recvWorkerTermination();
|
|
199
|
-
const workers = loaderWorkers[filename];
|
|
200
|
-
const workerIdx = workers.findIndex((worker) => worker.threadId === workerId);
|
|
201
|
-
if (workerIdx > -1) {
|
|
202
|
-
const worker = workers.splice(workerIdx, 1);
|
|
203
|
-
worker[0].terminate();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
catch (e) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
166
|
class ProjectImpl {
|
|
212
167
|
constructor(nativeProject) {
|
|
213
168
|
this._nativeProject = nativeProject;
|
|
214
|
-
if (typeof binding.
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
if (typeof binding.recvWorkerTermination === "function") {
|
|
218
|
-
waitingForWorkerTermination();
|
|
169
|
+
if (typeof binding.registerWorkerScheduler === "function") {
|
|
170
|
+
runLoaderWorkerPool(binding, require.resolve("@utoo/pack/cjs/binding.js"));
|
|
219
171
|
}
|
|
220
172
|
}
|
|
221
173
|
async update(options) {
|
package/esm/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8-alpha.1",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -85,12 +85,12 @@
|
|
|
85
85
|
},
|
|
86
86
|
"repository": "git@github.com:utooland/utoo.git",
|
|
87
87
|
"optionalDependencies": {
|
|
88
|
-
"@utoo/pack-darwin-arm64": "1.0.
|
|
89
|
-
"@utoo/pack-darwin-x64": "1.0.
|
|
90
|
-
"@utoo/pack-linux-arm64-gnu": "1.0.
|
|
91
|
-
"@utoo/pack-linux-arm64-musl": "1.0.
|
|
92
|
-
"@utoo/pack-linux-x64-gnu": "1.0.
|
|
93
|
-
"@utoo/pack-linux-x64-musl": "1.0.
|
|
94
|
-
"@utoo/pack-win32-x64-msvc": "1.0.
|
|
88
|
+
"@utoo/pack-darwin-arm64": "1.0.8-alpha.1",
|
|
89
|
+
"@utoo/pack-darwin-x64": "1.0.8-alpha.1",
|
|
90
|
+
"@utoo/pack-linux-arm64-gnu": "1.0.8-alpha.1",
|
|
91
|
+
"@utoo/pack-linux-arm64-musl": "1.0.8-alpha.1",
|
|
92
|
+
"@utoo/pack-linux-x64-gnu": "1.0.8-alpha.1",
|
|
93
|
+
"@utoo/pack-linux-x64-musl": "1.0.8-alpha.1",
|
|
94
|
+
"@utoo/pack-win32-x64-msvc": "1.0.8-alpha.1"
|
|
95
95
|
}
|
|
96
96
|
}
|