@utoo/pack 1.0.0-alpha.1 → 1.0.0-alpha.3
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/build.js +0 -1
- package/cjs/project.js +37 -25
- package/esm/build.js +0 -1
- package/esm/project.js +37 -25
- package/package.json +8 -8
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
|
@@ -203,36 +203,48 @@ function projectFactory() {
|
|
|
203
203
|
}
|
|
204
204
|
const loaderWorkers = {};
|
|
205
205
|
const createOrScalePool = async () => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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;
|
|
219
230
|
}
|
|
220
231
|
}
|
|
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
232
|
};
|
|
227
233
|
const waitingForWorkerTermination = async () => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
+
}
|
|
234
247
|
}
|
|
235
|
-
waitingForWorkerTermination();
|
|
236
248
|
};
|
|
237
249
|
class ProjectImpl {
|
|
238
250
|
constructor(nativeProject) {
|
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
|
@@ -165,36 +165,48 @@ export function projectFactory() {
|
|
|
165
165
|
}
|
|
166
166
|
const loaderWorkers = {};
|
|
167
167
|
const createOrScalePool = async () => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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;
|
|
181
192
|
}
|
|
182
193
|
}
|
|
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
194
|
};
|
|
189
195
|
const waitingForWorkerTermination = async () => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
+
}
|
|
196
209
|
}
|
|
197
|
-
waitingForWorkerTermination();
|
|
198
210
|
};
|
|
199
211
|
class ProjectImpl {
|
|
200
212
|
constructor(nativeProject) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
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-alpha.
|
|
89
|
-
"@utoo/pack-darwin-x64": "1.0.0-alpha.
|
|
90
|
-
"@utoo/pack-linux-arm64-gnu": "1.0.0-alpha.
|
|
91
|
-
"@utoo/pack-linux-arm64-musl": "1.0.0-alpha.
|
|
92
|
-
"@utoo/pack-linux-x64-gnu": "1.0.0-alpha.
|
|
93
|
-
"@utoo/pack-linux-x64-musl": "1.0.0-alpha.
|
|
94
|
-
"@utoo/pack-win32-x64-msvc": "1.0.0-alpha.
|
|
88
|
+
"@utoo/pack-darwin-arm64": "1.0.0-alpha.3",
|
|
89
|
+
"@utoo/pack-darwin-x64": "1.0.0-alpha.3",
|
|
90
|
+
"@utoo/pack-linux-arm64-gnu": "1.0.0-alpha.3",
|
|
91
|
+
"@utoo/pack-linux-arm64-musl": "1.0.0-alpha.3",
|
|
92
|
+
"@utoo/pack-linux-x64-gnu": "1.0.0-alpha.3",
|
|
93
|
+
"@utoo/pack-linux-x64-musl": "1.0.0-alpha.3",
|
|
94
|
+
"@utoo/pack-win32-x64-msvc": "1.0.0-alpha.3"
|
|
95
95
|
}
|
|
96
96
|
}
|