@utoo/pack 1.0.0 → 1.0.1-alpha.0
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 +14 -0
- package/cjs/binding.js +7 -1
- package/cjs/project.js +52 -0
- package/cjs/types.d.ts +2 -2
- package/esm/binding.d.ts +14 -0
- package/esm/binding.js +7 -1
- package/esm/project.js +52 -0
- package/esm/types.d.ts +2 -2
- package/package.json +8 -8
package/cjs/binding.d.ts
CHANGED
|
@@ -9,6 +9,20 @@ export declare class ExternalObject<T> {
|
|
|
9
9
|
[K: symbol]: T
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
export interface PoolOptions {
|
|
13
|
+
filename: string
|
|
14
|
+
maxConcurrency: number
|
|
15
|
+
}
|
|
16
|
+
export interface WorkerTermination {
|
|
17
|
+
filename: string
|
|
18
|
+
workerId: number
|
|
19
|
+
}
|
|
20
|
+
export declare function recvPoolRequest(): Promise<PoolOptions>
|
|
21
|
+
export declare function recvWorkerTermination(): Promise<WorkerTermination>
|
|
22
|
+
export declare function recvWorkerRequest(filename: string): Promise<number>
|
|
23
|
+
export declare function recvMessageInWorker(workerId: number): Promise<string>
|
|
24
|
+
export declare function notifyWorkerAck(taskId: number, workerId: number): Promise<void>
|
|
25
|
+
export declare function sendTaskMessage(taskId: number, message: string): Promise<void>
|
|
12
26
|
export interface NapiEndpointConfig {
|
|
13
27
|
|
|
14
28
|
}
|
package/cjs/binding.js
CHANGED
|
@@ -319,7 +319,13 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
322
|
-
const { endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
322
|
+
const { recvPoolRequest, recvWorkerTermination, recvWorkerRequest, recvMessageInWorker, notifyWorkerAck, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
323
|
+
module.exports.recvPoolRequest = recvPoolRequest;
|
|
324
|
+
module.exports.recvWorkerTermination = recvWorkerTermination;
|
|
325
|
+
module.exports.recvWorkerRequest = recvWorkerRequest;
|
|
326
|
+
module.exports.recvMessageInWorker = recvMessageInWorker;
|
|
327
|
+
module.exports.notifyWorkerAck = notifyWorkerAck;
|
|
328
|
+
module.exports.sendTaskMessage = sendTaskMessage;
|
|
323
329
|
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
324
330
|
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
325
331
|
module.exports.endpointClientChangedSubscribe = endpointClientChangedSubscribe;
|
package/cjs/project.js
CHANGED
|
@@ -36,6 +36,7 @@ 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");
|
|
39
40
|
const binding = __importStar(require("./binding"));
|
|
40
41
|
const util_2 = require("./util");
|
|
41
42
|
class TurbopackInternalError extends Error {
|
|
@@ -200,9 +201,60 @@ function projectFactory() {
|
|
|
200
201
|
};
|
|
201
202
|
return iterator;
|
|
202
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
|
+
};
|
|
203
249
|
class ProjectImpl {
|
|
204
250
|
constructor(nativeProject) {
|
|
205
251
|
this._nativeProject = nativeProject;
|
|
252
|
+
if (typeof binding.recvPoolRequest === "function") {
|
|
253
|
+
createOrScalePool();
|
|
254
|
+
}
|
|
255
|
+
if (typeof binding.recvWorkerTermination === "function") {
|
|
256
|
+
waitingForWorkerTermination();
|
|
257
|
+
}
|
|
206
258
|
}
|
|
207
259
|
async update(options) {
|
|
208
260
|
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
|
package/cjs/types.d.ts
CHANGED
package/esm/binding.d.ts
CHANGED
|
@@ -9,6 +9,20 @@ export declare class ExternalObject<T> {
|
|
|
9
9
|
[K: symbol]: T
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
export interface PoolOptions {
|
|
13
|
+
filename: string
|
|
14
|
+
maxConcurrency: number
|
|
15
|
+
}
|
|
16
|
+
export interface WorkerTermination {
|
|
17
|
+
filename: string
|
|
18
|
+
workerId: number
|
|
19
|
+
}
|
|
20
|
+
export declare function recvPoolRequest(): Promise<PoolOptions>
|
|
21
|
+
export declare function recvWorkerTermination(): Promise<WorkerTermination>
|
|
22
|
+
export declare function recvWorkerRequest(filename: string): Promise<number>
|
|
23
|
+
export declare function recvMessageInWorker(workerId: number): Promise<string>
|
|
24
|
+
export declare function notifyWorkerAck(taskId: number, workerId: number): Promise<void>
|
|
25
|
+
export declare function sendTaskMessage(taskId: number, message: string): Promise<void>
|
|
12
26
|
export interface NapiEndpointConfig {
|
|
13
27
|
|
|
14
28
|
}
|
package/esm/binding.js
CHANGED
|
@@ -319,7 +319,13 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
322
|
-
const { endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
322
|
+
const { recvPoolRequest, recvWorkerTermination, recvWorkerRequest, recvMessageInWorker, notifyWorkerAck, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
323
|
+
module.exports.recvPoolRequest = recvPoolRequest;
|
|
324
|
+
module.exports.recvWorkerTermination = recvWorkerTermination;
|
|
325
|
+
module.exports.recvWorkerRequest = recvWorkerRequest;
|
|
326
|
+
module.exports.recvMessageInWorker = recvMessageInWorker;
|
|
327
|
+
module.exports.notifyWorkerAck = notifyWorkerAck;
|
|
328
|
+
module.exports.sendTaskMessage = sendTaskMessage;
|
|
323
329
|
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
324
330
|
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
325
331
|
module.exports.endpointClientChangedSubscribe = endpointClientChangedSubscribe;
|
package/esm/project.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "util";
|
|
2
|
+
import { Worker } from "worker_threads";
|
|
2
3
|
import * as binding from "./binding";
|
|
3
4
|
import { rustifyEnv } from "./util";
|
|
4
5
|
export class TurbopackInternalError extends Error {
|
|
@@ -162,9 +163,60 @@ export function projectFactory() {
|
|
|
162
163
|
};
|
|
163
164
|
return iterator;
|
|
164
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
|
+
};
|
|
165
211
|
class ProjectImpl {
|
|
166
212
|
constructor(nativeProject) {
|
|
167
213
|
this._nativeProject = nativeProject;
|
|
214
|
+
if (typeof binding.recvPoolRequest === "function") {
|
|
215
|
+
createOrScalePool();
|
|
216
|
+
}
|
|
217
|
+
if (typeof binding.recvWorkerTermination === "function") {
|
|
218
|
+
waitingForWorkerTermination();
|
|
219
|
+
}
|
|
168
220
|
}
|
|
169
221
|
async update(options) {
|
|
170
222
|
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(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.0",
|
|
3
|
+
"version": "1.0.1-alpha.0",
|
|
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.0",
|
|
89
|
-
"@utoo/pack-darwin-x64": "1.0.0",
|
|
90
|
-
"@utoo/pack-linux-arm64-gnu": "1.0.0",
|
|
91
|
-
"@utoo/pack-linux-arm64-musl": "1.0.0",
|
|
92
|
-
"@utoo/pack-linux-x64-gnu": "1.0.0",
|
|
93
|
-
"@utoo/pack-linux-x64-musl": "1.0.0",
|
|
94
|
-
"@utoo/pack-win32-x64-msvc": "1.0.0"
|
|
88
|
+
"@utoo/pack-darwin-arm64": "1.0.1-alpha.0",
|
|
89
|
+
"@utoo/pack-darwin-x64": "1.0.1-alpha.0",
|
|
90
|
+
"@utoo/pack-linux-arm64-gnu": "1.0.1-alpha.0",
|
|
91
|
+
"@utoo/pack-linux-arm64-musl": "1.0.1-alpha.0",
|
|
92
|
+
"@utoo/pack-linux-x64-gnu": "1.0.1-alpha.0",
|
|
93
|
+
"@utoo/pack-linux-x64-musl": "1.0.1-alpha.0",
|
|
94
|
+
"@utoo/pack-win32-x64-msvc": "1.0.1-alpha.0"
|
|
95
95
|
}
|
|
96
96
|
}
|