vite-ssg-optimized 0.24.2-optimized.46 → 0.24.2-optimized.48
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/dist/node/cli.cjs +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +1 -1
- package/dist/shared/build.worker.cjs +1 -1
- package/dist/shared/build.worker.mjs +1 -1
- package/dist/shared/{vite-ssg-optimized.41dde896.mjs → vite-ssg-optimized.72fc9757.mjs} +67 -16
- package/dist/shared/{vite-ssg-optimized.5745cadc.cjs → vite-ssg-optimized.bb5ba938.cjs} +69 -18
- package/package.json +1 -1
package/dist/node/cli.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const process = require('node:process');
|
|
|
4
4
|
const kolorist = require('kolorist');
|
|
5
5
|
const yargs = require('yargs');
|
|
6
6
|
const helpers = require('yargs/helpers');
|
|
7
|
-
const node = require('../shared/vite-ssg-optimized.
|
|
7
|
+
const node = require('../shared/vite-ssg-optimized.bb5ba938.cjs');
|
|
8
8
|
require('node:module');
|
|
9
9
|
require('node:path');
|
|
10
10
|
require('@unhead/ssr');
|
package/dist/node/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import process from 'node:process';
|
|
|
2
2
|
import { gray, bold, red, reset, underline } from 'kolorist';
|
|
3
3
|
import yargs from 'yargs';
|
|
4
4
|
import { hideBin } from 'yargs/helpers';
|
|
5
|
-
import { b as build } from '../shared/vite-ssg-optimized.
|
|
5
|
+
import { b as build } from '../shared/vite-ssg-optimized.72fc9757.mjs';
|
|
6
6
|
import 'node:module';
|
|
7
7
|
import 'node:path';
|
|
8
8
|
import '@unhead/ssr';
|
package/dist/node.cjs
CHANGED
package/dist/node.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const node_module = require('node:module');
|
|
4
4
|
const node_worker_threads = require('node:worker_threads');
|
|
5
|
-
const node = require('./vite-ssg-optimized.
|
|
5
|
+
const node = require('./vite-ssg-optimized.bb5ba938.cjs');
|
|
6
6
|
const kolorist = require('kolorist');
|
|
7
7
|
const vite = require('vite');
|
|
8
8
|
require('node:path');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
3
|
-
import { p as plainify, e as executeTaskFn, a as buildClient, c as buildServer } from './vite-ssg-optimized.
|
|
3
|
+
import { p as plainify, e as executeTaskFn, a as buildClient, c as buildServer } from './vite-ssg-optimized.72fc9757.mjs';
|
|
4
4
|
import { red, gray, blue } from 'kolorist';
|
|
5
5
|
import { resolveConfig } from 'vite';
|
|
6
6
|
import 'node:path';
|
|
@@ -1043,6 +1043,9 @@ class BuildWorkerProxy {
|
|
|
1043
1043
|
off(type, listener) {
|
|
1044
1044
|
this.worker.off(type, listener);
|
|
1045
1045
|
}
|
|
1046
|
+
once(type, listener) {
|
|
1047
|
+
this.worker.once(type, listener);
|
|
1048
|
+
}
|
|
1046
1049
|
async send(type, args) {
|
|
1047
1050
|
const id = crypto.randomUUID();
|
|
1048
1051
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -1055,7 +1058,9 @@ class BuildWorkerProxy {
|
|
|
1055
1058
|
return promise;
|
|
1056
1059
|
}
|
|
1057
1060
|
terminate() {
|
|
1058
|
-
return this.worker.terminate()
|
|
1061
|
+
return this.worker.terminate().finally(() => {
|
|
1062
|
+
this.pending.clear();
|
|
1063
|
+
});
|
|
1059
1064
|
}
|
|
1060
1065
|
}
|
|
1061
1066
|
|
|
@@ -1117,11 +1122,11 @@ function createProxy(options) {
|
|
|
1117
1122
|
env: process$1.env,
|
|
1118
1123
|
workerData: options
|
|
1119
1124
|
});
|
|
1120
|
-
process$1.
|
|
1121
|
-
process$1.
|
|
1122
|
-
process$1.
|
|
1123
|
-
process$1.
|
|
1124
|
-
process$1.
|
|
1125
|
+
process$1.once("SIGINT", workerProxy.terminate.bind(workerProxy));
|
|
1126
|
+
process$1.once("SIGTERM", workerProxy.terminate.bind(workerProxy));
|
|
1127
|
+
process$1.once("SIGBREAK", workerProxy.terminate.bind(workerProxy));
|
|
1128
|
+
process$1.once("beforeExit", workerProxy.terminate.bind(workerProxy));
|
|
1129
|
+
process$1.once("exit", workerProxy.terminate.bind(workerProxy));
|
|
1125
1130
|
return workerProxy;
|
|
1126
1131
|
}
|
|
1127
1132
|
async function build(ssgOptions = {}, viteConfig = {}) {
|
|
@@ -1195,15 +1200,24 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1195
1200
|
...createProxyOptions,
|
|
1196
1201
|
workerId: index
|
|
1197
1202
|
}));
|
|
1198
|
-
const
|
|
1203
|
+
const workersInUse = /* @__PURE__ */ new Map();
|
|
1204
|
+
const terminateWorker = async (worker, onFinished2) => {
|
|
1199
1205
|
if (onFinished2) {
|
|
1200
|
-
await
|
|
1206
|
+
await execInWorker(worker, onFinished2);
|
|
1207
|
+
}
|
|
1208
|
+
const foundIndex = workers.indexOf(worker);
|
|
1209
|
+
if (foundIndex > -1) {
|
|
1210
|
+
workers.splice(foundIndex, 1);
|
|
1201
1211
|
}
|
|
1202
|
-
await
|
|
1212
|
+
await worker.terminate().finally(() => {
|
|
1213
|
+
workersInUse.delete(worker);
|
|
1214
|
+
});
|
|
1215
|
+
};
|
|
1216
|
+
const terminateWorkers = async (onFinished2) => {
|
|
1217
|
+
await Promise.all(workers.map((worker) => terminateWorker(worker, onFinished2)));
|
|
1203
1218
|
};
|
|
1204
1219
|
let workerIndex = 0;
|
|
1205
1220
|
const maxTasksPerWorker = Math.ceil(concurrency / numberOfWorkers);
|
|
1206
|
-
const workersInUse = /* @__PURE__ */ new Map();
|
|
1207
1221
|
const workerTasksRunning = (w) => workersInUse.get(w)?.length || 0;
|
|
1208
1222
|
const selectIdleWorker = () => workers.filter((w) => workerTasksRunning(w) < maxTasksPerWorker).sort((a, b) => workerTasksRunning(a) - workerTasksRunning(b))[0];
|
|
1209
1223
|
const selectWorker = async (workerIndex2) => {
|
|
@@ -1216,10 +1230,15 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1216
1230
|
}
|
|
1217
1231
|
const workerPromises = workersInUse.get(worker) || [];
|
|
1218
1232
|
const delayPromise = new Promise((resolve) => setImmediate(resolve));
|
|
1219
|
-
|
|
1233
|
+
workerPromises.push(delayPromise);
|
|
1234
|
+
workersInUse.set(worker, workerPromises);
|
|
1220
1235
|
delayPromise.finally(() => {
|
|
1221
|
-
|
|
1222
|
-
|
|
1236
|
+
const workerPromises2 = workersInUse.get(worker) || [];
|
|
1237
|
+
const foundIndex = workerPromises2.indexOf(delayPromise);
|
|
1238
|
+
if (foundIndex > -1) {
|
|
1239
|
+
workerPromises2.splice(foundIndex, 1);
|
|
1240
|
+
}
|
|
1241
|
+
workersInUse.set(worker, workerPromises2);
|
|
1223
1242
|
});
|
|
1224
1243
|
return worker;
|
|
1225
1244
|
};
|
|
@@ -1245,11 +1264,38 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1245
1264
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
1246
1265
|
const IS_PROD = nodeEnv === "production";
|
|
1247
1266
|
indexHTML = await formatHtml(indexHTML, IS_PROD ? "minify" : formatting, minifyOptions);
|
|
1267
|
+
const workerRunCount = /* @__PURE__ */ new WeakMap();
|
|
1268
|
+
const MAX_RUNS_PER_WORKER = 50;
|
|
1269
|
+
let lastWorkerIndex = workers.length - 1;
|
|
1270
|
+
function replaceWorker(workerProxy) {
|
|
1271
|
+
const index = workers.indexOf(workerProxy);
|
|
1272
|
+
if (index === -1) {
|
|
1273
|
+
return workerProxy;
|
|
1274
|
+
}
|
|
1275
|
+
++lastWorkerIndex;
|
|
1276
|
+
config.logger.info(`${blue("[vite-ssg]")} ${yellow(`Replace worker #${index} => #${lastWorkerIndex}`)}`);
|
|
1277
|
+
const workerPromises = workersInUse.get(workerProxy) || [];
|
|
1278
|
+
const newWorkerProxy = createProxy({
|
|
1279
|
+
...createProxyOptions,
|
|
1280
|
+
workerId: lastWorkerIndex
|
|
1281
|
+
});
|
|
1282
|
+
workers[index] = newWorkerProxy;
|
|
1283
|
+
Promise.allSettled(workerPromises).then(async () => {
|
|
1284
|
+
await terminateWorker(workerProxy, onFinished);
|
|
1285
|
+
});
|
|
1286
|
+
return newWorkerProxy;
|
|
1287
|
+
}
|
|
1248
1288
|
const queue = new PQueue({ concurrency });
|
|
1249
1289
|
for (const route of routesPaths) {
|
|
1250
1290
|
await queue.onSizeLessThan(concurrency);
|
|
1251
1291
|
queue.add(async () => {
|
|
1252
|
-
|
|
1292
|
+
let workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
|
|
1293
|
+
const currentCount = (workerRunCount.get(workerProxy) ?? 0) + 1;
|
|
1294
|
+
workerRunCount.set(workerProxy, currentCount);
|
|
1295
|
+
if (currentCount > MAX_RUNS_PER_WORKER) {
|
|
1296
|
+
workerRunCount.delete(workerProxy);
|
|
1297
|
+
workerProxy = replaceWorker(workerProxy);
|
|
1298
|
+
}
|
|
1253
1299
|
let retryCount = 0;
|
|
1254
1300
|
const maxRetries = 3;
|
|
1255
1301
|
const execOpts = {
|
|
@@ -1266,6 +1312,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1266
1312
|
};
|
|
1267
1313
|
const taskPromise = executeTaskInWorker(workerProxy, execOpts);
|
|
1268
1314
|
const workerPromises = workersInUse.get(workerProxy) || [];
|
|
1315
|
+
workerPromises.push(taskPromise);
|
|
1269
1316
|
workersInUse.set(workerProxy, workerPromises);
|
|
1270
1317
|
const retryFn = async (e) => {
|
|
1271
1318
|
if (retryCount++ < maxRetries) {
|
|
@@ -1275,8 +1322,12 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1275
1322
|
throw e;
|
|
1276
1323
|
};
|
|
1277
1324
|
taskPromise.catch(retryFn).finally(() => {
|
|
1278
|
-
|
|
1279
|
-
|
|
1325
|
+
const workerPromises2 = workersInUse.get(workerProxy) || [];
|
|
1326
|
+
const foundIndex = workerPromises2.indexOf(taskPromise);
|
|
1327
|
+
if (foundIndex > -1) {
|
|
1328
|
+
workerPromises2.splice(foundIndex, 1);
|
|
1329
|
+
}
|
|
1330
|
+
workersInUse.set(workerProxy, workerPromises2);
|
|
1280
1331
|
});
|
|
1281
1332
|
return taskPromise;
|
|
1282
1333
|
});
|
|
@@ -1052,6 +1052,9 @@ class BuildWorkerProxy {
|
|
|
1052
1052
|
off(type, listener) {
|
|
1053
1053
|
this.worker.off(type, listener);
|
|
1054
1054
|
}
|
|
1055
|
+
once(type, listener) {
|
|
1056
|
+
this.worker.once(type, listener);
|
|
1057
|
+
}
|
|
1055
1058
|
async send(type, args) {
|
|
1056
1059
|
const id = crypto.randomUUID();
|
|
1057
1060
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -1064,7 +1067,9 @@ class BuildWorkerProxy {
|
|
|
1064
1067
|
return promise;
|
|
1065
1068
|
}
|
|
1066
1069
|
terminate() {
|
|
1067
|
-
return this.worker.terminate()
|
|
1070
|
+
return this.worker.terminate().finally(() => {
|
|
1071
|
+
this.pending.clear();
|
|
1072
|
+
});
|
|
1068
1073
|
}
|
|
1069
1074
|
}
|
|
1070
1075
|
|
|
@@ -1122,15 +1127,15 @@ async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format, mock
|
|
|
1122
1127
|
}
|
|
1123
1128
|
function createProxy(options) {
|
|
1124
1129
|
const workerExt = options.format === "esm" ? ".mjs" : ".cjs";
|
|
1125
|
-
const workerProxy = new BuildWorkerProxy(new URL(`./build.worker${workerExt}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.
|
|
1130
|
+
const workerProxy = new BuildWorkerProxy(new URL(`./build.worker${workerExt}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.bb5ba938.cjs', document.baseURI).href))), {
|
|
1126
1131
|
env: process__default.env,
|
|
1127
1132
|
workerData: options
|
|
1128
1133
|
});
|
|
1129
|
-
process__default.
|
|
1130
|
-
process__default.
|
|
1131
|
-
process__default.
|
|
1132
|
-
process__default.
|
|
1133
|
-
process__default.
|
|
1134
|
+
process__default.once("SIGINT", workerProxy.terminate.bind(workerProxy));
|
|
1135
|
+
process__default.once("SIGTERM", workerProxy.terminate.bind(workerProxy));
|
|
1136
|
+
process__default.once("SIGBREAK", workerProxy.terminate.bind(workerProxy));
|
|
1137
|
+
process__default.once("beforeExit", workerProxy.terminate.bind(workerProxy));
|
|
1138
|
+
process__default.once("exit", workerProxy.terminate.bind(workerProxy));
|
|
1134
1139
|
return workerProxy;
|
|
1135
1140
|
}
|
|
1136
1141
|
async function build(ssgOptions = {}, viteConfig = {}) {
|
|
@@ -1204,15 +1209,24 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1204
1209
|
...createProxyOptions,
|
|
1205
1210
|
workerId: index
|
|
1206
1211
|
}));
|
|
1207
|
-
const
|
|
1212
|
+
const workersInUse = /* @__PURE__ */ new Map();
|
|
1213
|
+
const terminateWorker = async (worker, onFinished2) => {
|
|
1208
1214
|
if (onFinished2) {
|
|
1209
|
-
await
|
|
1215
|
+
await execInWorker(worker, onFinished2);
|
|
1216
|
+
}
|
|
1217
|
+
const foundIndex = workers.indexOf(worker);
|
|
1218
|
+
if (foundIndex > -1) {
|
|
1219
|
+
workers.splice(foundIndex, 1);
|
|
1210
1220
|
}
|
|
1211
|
-
await
|
|
1221
|
+
await worker.terminate().finally(() => {
|
|
1222
|
+
workersInUse.delete(worker);
|
|
1223
|
+
});
|
|
1224
|
+
};
|
|
1225
|
+
const terminateWorkers = async (onFinished2) => {
|
|
1226
|
+
await Promise.all(workers.map((worker) => terminateWorker(worker, onFinished2)));
|
|
1212
1227
|
};
|
|
1213
1228
|
let workerIndex = 0;
|
|
1214
1229
|
const maxTasksPerWorker = Math.ceil(concurrency / numberOfWorkers);
|
|
1215
|
-
const workersInUse = /* @__PURE__ */ new Map();
|
|
1216
1230
|
const workerTasksRunning = (w) => workersInUse.get(w)?.length || 0;
|
|
1217
1231
|
const selectIdleWorker = () => workers.filter((w) => workerTasksRunning(w) < maxTasksPerWorker).sort((a, b) => workerTasksRunning(a) - workerTasksRunning(b))[0];
|
|
1218
1232
|
const selectWorker = async (workerIndex2) => {
|
|
@@ -1225,15 +1239,20 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1225
1239
|
}
|
|
1226
1240
|
const workerPromises = workersInUse.get(worker) || [];
|
|
1227
1241
|
const delayPromise = new Promise((resolve) => setImmediate(resolve));
|
|
1228
|
-
|
|
1242
|
+
workerPromises.push(delayPromise);
|
|
1243
|
+
workersInUse.set(worker, workerPromises);
|
|
1229
1244
|
delayPromise.finally(() => {
|
|
1230
|
-
|
|
1231
|
-
|
|
1245
|
+
const workerPromises2 = workersInUse.get(worker) || [];
|
|
1246
|
+
const foundIndex = workerPromises2.indexOf(delayPromise);
|
|
1247
|
+
if (foundIndex > -1) {
|
|
1248
|
+
workerPromises2.splice(foundIndex, 1);
|
|
1249
|
+
}
|
|
1250
|
+
workersInUse.set(worker, workerPromises2);
|
|
1232
1251
|
});
|
|
1233
1252
|
return worker;
|
|
1234
1253
|
};
|
|
1235
1254
|
const serverEntry = prefix + node_path.join(ssgOut, node_path.parse(ssrEntry).name + ext).replace(/\\/g, "/");
|
|
1236
|
-
const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.
|
|
1255
|
+
const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.bb5ba938.cjs', document.baseURI).href)));
|
|
1237
1256
|
const { createApp, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
|
|
1238
1257
|
const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes;
|
|
1239
1258
|
const { routes } = await createApp(false);
|
|
@@ -1254,11 +1273,38 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1254
1273
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
1255
1274
|
const IS_PROD = nodeEnv === "production";
|
|
1256
1275
|
indexHTML = await formatHtml(indexHTML, IS_PROD ? "minify" : formatting, minifyOptions);
|
|
1276
|
+
const workerRunCount = /* @__PURE__ */ new WeakMap();
|
|
1277
|
+
const MAX_RUNS_PER_WORKER = 50;
|
|
1278
|
+
let lastWorkerIndex = workers.length - 1;
|
|
1279
|
+
function replaceWorker(workerProxy) {
|
|
1280
|
+
const index = workers.indexOf(workerProxy);
|
|
1281
|
+
if (index === -1) {
|
|
1282
|
+
return workerProxy;
|
|
1283
|
+
}
|
|
1284
|
+
++lastWorkerIndex;
|
|
1285
|
+
config.logger.info(`${kolorist.blue("[vite-ssg]")} ${kolorist.yellow(`Replace worker #${index} => #${lastWorkerIndex}`)}`);
|
|
1286
|
+
const workerPromises = workersInUse.get(workerProxy) || [];
|
|
1287
|
+
const newWorkerProxy = createProxy({
|
|
1288
|
+
...createProxyOptions,
|
|
1289
|
+
workerId: lastWorkerIndex
|
|
1290
|
+
});
|
|
1291
|
+
workers[index] = newWorkerProxy;
|
|
1292
|
+
Promise.allSettled(workerPromises).then(async () => {
|
|
1293
|
+
await terminateWorker(workerProxy, onFinished);
|
|
1294
|
+
});
|
|
1295
|
+
return newWorkerProxy;
|
|
1296
|
+
}
|
|
1257
1297
|
const queue = new PQueue({ concurrency });
|
|
1258
1298
|
for (const route of routesPaths) {
|
|
1259
1299
|
await queue.onSizeLessThan(concurrency);
|
|
1260
1300
|
queue.add(async () => {
|
|
1261
|
-
|
|
1301
|
+
let workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
|
|
1302
|
+
const currentCount = (workerRunCount.get(workerProxy) ?? 0) + 1;
|
|
1303
|
+
workerRunCount.set(workerProxy, currentCount);
|
|
1304
|
+
if (currentCount > MAX_RUNS_PER_WORKER) {
|
|
1305
|
+
workerRunCount.delete(workerProxy);
|
|
1306
|
+
workerProxy = replaceWorker(workerProxy);
|
|
1307
|
+
}
|
|
1262
1308
|
let retryCount = 0;
|
|
1263
1309
|
const maxRetries = 3;
|
|
1264
1310
|
const execOpts = {
|
|
@@ -1275,6 +1321,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1275
1321
|
};
|
|
1276
1322
|
const taskPromise = executeTaskInWorker(workerProxy, execOpts);
|
|
1277
1323
|
const workerPromises = workersInUse.get(workerProxy) || [];
|
|
1324
|
+
workerPromises.push(taskPromise);
|
|
1278
1325
|
workersInUse.set(workerProxy, workerPromises);
|
|
1279
1326
|
const retryFn = async (e) => {
|
|
1280
1327
|
if (retryCount++ < maxRetries) {
|
|
@@ -1284,8 +1331,12 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1284
1331
|
throw e;
|
|
1285
1332
|
};
|
|
1286
1333
|
taskPromise.catch(retryFn).finally(() => {
|
|
1287
|
-
|
|
1288
|
-
|
|
1334
|
+
const workerPromises2 = workersInUse.get(workerProxy) || [];
|
|
1335
|
+
const foundIndex = workerPromises2.indexOf(taskPromise);
|
|
1336
|
+
if (foundIndex > -1) {
|
|
1337
|
+
workerPromises2.splice(foundIndex, 1);
|
|
1338
|
+
}
|
|
1339
|
+
workersInUse.set(workerProxy, workerPromises2);
|
|
1289
1340
|
});
|
|
1290
1341
|
return taskPromise;
|
|
1291
1342
|
});
|