@utoo/pack 1.0.0-alpha.0 → 1.0.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 +0 -14
- package/cjs/binding.js +1 -7
- package/cjs/build.js +0 -1
- package/cjs/project.js +0 -40
- package/esm/binding.d.ts +0 -14
- package/esm/binding.js +1 -7
- package/esm/build.js +0 -1
- package/esm/project.js +0 -40
- package/package.json +8 -8
package/cjs/binding.d.ts
CHANGED
|
@@ -9,20 +9,6 @@ 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>
|
|
26
12
|
export interface NapiEndpointConfig {
|
|
27
13
|
|
|
28
14
|
}
|
package/cjs/binding.js
CHANGED
|
@@ -319,13 +319,7 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
322
|
-
const {
|
|
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;
|
|
322
|
+
const { endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
329
323
|
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
330
324
|
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
331
325
|
module.exports.endpointClientChangedSubscribe = endpointClientChangedSubscribe;
|
package/cjs/build.js
CHANGED
|
@@ -56,7 +56,6 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
56
56
|
await analyzeBundle(((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
|
|
57
57
|
}
|
|
58
58
|
await project.shutdown();
|
|
59
|
-
process.exit(0);
|
|
60
59
|
// TODO: Maybe run tasks in worker is a better way, see
|
|
61
60
|
// https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
|
|
62
61
|
}
|
package/cjs/project.js
CHANGED
|
@@ -36,7 +36,6 @@ 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"));
|
|
41
40
|
const util_2 = require("./util");
|
|
42
41
|
class TurbopackInternalError extends Error {
|
|
@@ -201,48 +200,9 @@ function projectFactory() {
|
|
|
201
200
|
};
|
|
202
201
|
return iterator;
|
|
203
202
|
}
|
|
204
|
-
const loaderWorkers = {};
|
|
205
|
-
const createOrScalePool = async () => {
|
|
206
|
-
let poolOptions = await binding.recvPoolRequest();
|
|
207
|
-
const { filename, maxConcurrency } = poolOptions;
|
|
208
|
-
const workers = loaderWorkers[filename] || (loaderWorkers[filename] = []);
|
|
209
|
-
if (workers.length < maxConcurrency) {
|
|
210
|
-
for (let i = workers.length; i < maxConcurrency; i++) {
|
|
211
|
-
const worker = new worker_threads_1.Worker(filename, {
|
|
212
|
-
workerData: {
|
|
213
|
-
poolId: filename,
|
|
214
|
-
bindingPath: require.resolve("./binding.js"),
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
worker.unref();
|
|
218
|
-
workers.push(worker);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
else if (workers.length > maxConcurrency) {
|
|
222
|
-
const workersToStop = workers.splice(0, workers.length - maxConcurrency);
|
|
223
|
-
workersToStop.forEach((worker) => worker.terminate());
|
|
224
|
-
}
|
|
225
|
-
createOrScalePool();
|
|
226
|
-
};
|
|
227
|
-
const waitingForWorkerTermination = async () => {
|
|
228
|
-
const { filename, workerId } = await binding.recvWorkerTermination();
|
|
229
|
-
const workers = loaderWorkers[filename];
|
|
230
|
-
const workerIdx = workers.findIndex((worker) => worker.threadId === workerId);
|
|
231
|
-
if (workerIdx > -1) {
|
|
232
|
-
const worker = workers.splice(workerIdx, 1);
|
|
233
|
-
worker[0].terminate();
|
|
234
|
-
}
|
|
235
|
-
waitingForWorkerTermination();
|
|
236
|
-
};
|
|
237
203
|
class ProjectImpl {
|
|
238
204
|
constructor(nativeProject) {
|
|
239
205
|
this._nativeProject = nativeProject;
|
|
240
|
-
if (typeof binding.recvPoolRequest === "function") {
|
|
241
|
-
createOrScalePool();
|
|
242
|
-
}
|
|
243
|
-
if (typeof binding.recvWorkerTermination === "function") {
|
|
244
|
-
waitingForWorkerTermination();
|
|
245
|
-
}
|
|
246
206
|
}
|
|
247
207
|
async update(options) {
|
|
248
208
|
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
|
package/esm/binding.d.ts
CHANGED
|
@@ -9,20 +9,6 @@ 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>
|
|
26
12
|
export interface NapiEndpointConfig {
|
|
27
13
|
|
|
28
14
|
}
|
package/esm/binding.js
CHANGED
|
@@ -319,13 +319,7 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
322
|
-
const {
|
|
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;
|
|
322
|
+
const { endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
329
323
|
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
330
324
|
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
331
325
|
module.exports.endpointClientChangedSubscribe = endpointClientChangedSubscribe;
|
package/esm/build.js
CHANGED
|
@@ -53,7 +53,6 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
53
53
|
await analyzeBundle(((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
|
|
54
54
|
}
|
|
55
55
|
await project.shutdown();
|
|
56
|
-
process.exit(0);
|
|
57
56
|
// TODO: Maybe run tasks in worker is a better way, see
|
|
58
57
|
// https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
|
|
59
58
|
}
|
package/esm/project.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "util";
|
|
2
|
-
import { Worker } from "worker_threads";
|
|
3
2
|
import * as binding from "./binding";
|
|
4
3
|
import { rustifyEnv } from "./util";
|
|
5
4
|
export class TurbopackInternalError extends Error {
|
|
@@ -163,48 +162,9 @@ export function projectFactory() {
|
|
|
163
162
|
};
|
|
164
163
|
return iterator;
|
|
165
164
|
}
|
|
166
|
-
const loaderWorkers = {};
|
|
167
|
-
const createOrScalePool = async () => {
|
|
168
|
-
let poolOptions = await binding.recvPoolRequest();
|
|
169
|
-
const { filename, maxConcurrency } = poolOptions;
|
|
170
|
-
const workers = loaderWorkers[filename] || (loaderWorkers[filename] = []);
|
|
171
|
-
if (workers.length < maxConcurrency) {
|
|
172
|
-
for (let i = workers.length; i < maxConcurrency; i++) {
|
|
173
|
-
const worker = new Worker(filename, {
|
|
174
|
-
workerData: {
|
|
175
|
-
poolId: filename,
|
|
176
|
-
bindingPath: require.resolve("./binding.js"),
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
worker.unref();
|
|
180
|
-
workers.push(worker);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else if (workers.length > maxConcurrency) {
|
|
184
|
-
const workersToStop = workers.splice(0, workers.length - maxConcurrency);
|
|
185
|
-
workersToStop.forEach((worker) => worker.terminate());
|
|
186
|
-
}
|
|
187
|
-
createOrScalePool();
|
|
188
|
-
};
|
|
189
|
-
const waitingForWorkerTermination = async () => {
|
|
190
|
-
const { filename, workerId } = await binding.recvWorkerTermination();
|
|
191
|
-
const workers = loaderWorkers[filename];
|
|
192
|
-
const workerIdx = workers.findIndex((worker) => worker.threadId === workerId);
|
|
193
|
-
if (workerIdx > -1) {
|
|
194
|
-
const worker = workers.splice(workerIdx, 1);
|
|
195
|
-
worker[0].terminate();
|
|
196
|
-
}
|
|
197
|
-
waitingForWorkerTermination();
|
|
198
|
-
};
|
|
199
165
|
class ProjectImpl {
|
|
200
166
|
constructor(nativeProject) {
|
|
201
167
|
this._nativeProject = nativeProject;
|
|
202
|
-
if (typeof binding.recvPoolRequest === "function") {
|
|
203
|
-
createOrScalePool();
|
|
204
|
-
}
|
|
205
|
-
if (typeof binding.recvWorkerTermination === "function") {
|
|
206
|
-
waitingForWorkerTermination();
|
|
207
|
-
}
|
|
208
168
|
}
|
|
209
169
|
async update(options) {
|
|
210
170
|
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.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.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"
|
|
95
95
|
}
|
|
96
96
|
}
|