@windwalker-io/fusion-next 0.1.4 → 0.1.5
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/index.cjs +62 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +63 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -6211,18 +6211,20 @@ class ConfigBuilder {
|
|
|
6211
6211
|
}
|
|
6212
6212
|
const chunkDir = this.getChunkDir();
|
|
6213
6213
|
if (this.env.mode === "production" && this.fusionOptions.chunkNameObfuscation) {
|
|
6214
|
-
return `${chunkDir}${serial}.js`;
|
|
6214
|
+
return `${chunkDir}${serial}-[hash].js`;
|
|
6215
6215
|
}
|
|
6216
6216
|
return `${chunkDir}[name]-[hash].js`;
|
|
6217
6217
|
},
|
|
6218
6218
|
assetFileNames: (assetInfo) => {
|
|
6219
|
+
const chunkDir = this.getChunkDir();
|
|
6219
6220
|
for (const assetFileNamesCallback of this.assetFileNamesCallbacks) {
|
|
6220
6221
|
const name = assetFileNamesCallback(assetInfo);
|
|
6221
6222
|
if (name) {
|
|
6222
6223
|
return name;
|
|
6223
6224
|
}
|
|
6224
6225
|
}
|
|
6225
|
-
|
|
6226
|
+
const dir = this.getAssetDefaultSubdir(assetInfo);
|
|
6227
|
+
return `${chunkDir}${dir}[name]-[hash].[ext]`;
|
|
6226
6228
|
}
|
|
6227
6229
|
};
|
|
6228
6230
|
}
|
|
@@ -6237,6 +6239,19 @@ class ConfigBuilder {
|
|
|
6237
6239
|
}
|
|
6238
6240
|
return chunkDir;
|
|
6239
6241
|
}
|
|
6242
|
+
getAssetDefaultSubdir(assetInfo) {
|
|
6243
|
+
let dir = "";
|
|
6244
|
+
if (assetInfo.name && assetInfo.name.endsWith(".css")) {
|
|
6245
|
+
dir = "css/";
|
|
6246
|
+
}
|
|
6247
|
+
if (assetInfo.name && /\.(woff2?|ttf|otf|eot)$/.test(assetInfo.name)) {
|
|
6248
|
+
dir = "fonts/";
|
|
6249
|
+
}
|
|
6250
|
+
if (assetInfo.name && /\.(png|jpe?g|gif|svg|webp)$/.test(assetInfo.name)) {
|
|
6251
|
+
dir = "images/";
|
|
6252
|
+
}
|
|
6253
|
+
return dir;
|
|
6254
|
+
}
|
|
6240
6255
|
getChunkNameFromTask(chunkInfo) {
|
|
6241
6256
|
if (this.tasks.has(chunkInfo.name)) {
|
|
6242
6257
|
const output = this.tasks.get(chunkInfo.name)?.output;
|
|
@@ -8841,6 +8856,7 @@ async function resolveTaskAsFlat(name, task, cache) {
|
|
|
8841
8856
|
|
|
8842
8857
|
let params = parseArgv(getArgsAfterDoubleDashes(process.argv));
|
|
8843
8858
|
prepareParams(params);
|
|
8859
|
+
let serverRunning = false;
|
|
8844
8860
|
exports.builder = void 0;
|
|
8845
8861
|
const originalTasks = params._;
|
|
8846
8862
|
const extraVitePlugins = [];
|
|
@@ -8932,21 +8948,54 @@ function useFusion(fusionOptions = {}, tasks) {
|
|
|
8932
8948
|
server.httpServer?.once("listening", async () => {
|
|
8933
8949
|
const scheme = server.config.server.https ? "https" : "http";
|
|
8934
8950
|
const address = server.httpServer?.address();
|
|
8935
|
-
|
|
8951
|
+
let host = address && typeof address !== "string" ? address.address : "localhost";
|
|
8936
8952
|
const port = address && typeof address !== "string" ? address.port : 80;
|
|
8953
|
+
if (host === "::1") {
|
|
8954
|
+
host = `[${host}]`;
|
|
8955
|
+
}
|
|
8937
8956
|
const url = `${scheme}://${host}:${port}/`;
|
|
8938
8957
|
const serverFile = node_path.resolve(
|
|
8939
8958
|
server.config.root,
|
|
8940
8959
|
resolvedOptions.cliParams?.serverFile ?? "tmp/vite-server"
|
|
8941
8960
|
);
|
|
8942
8961
|
const serverFileFull = node_path.resolve(server.config.root, serverFile);
|
|
8943
|
-
|
|
8962
|
+
const pidFile = node_path.resolve(
|
|
8963
|
+
server.config.root,
|
|
8964
|
+
resolvedOptions.cliParams?.pidFile ?? "tmp/vite-pid"
|
|
8965
|
+
);
|
|
8966
|
+
const anotherServerRunning = fs$1.existsSync(serverFileFull) || fs$1.existsSync(pidFile);
|
|
8967
|
+
await sleep(500);
|
|
8968
|
+
if (!serverRunning && anotherServerRunning) {
|
|
8944
8969
|
console.log(chalk.yellow(`There may be a dev server running!`));
|
|
8945
|
-
console.log(`The server host file
|
|
8946
|
-
console.log(
|
|
8947
|
-
|
|
8970
|
+
console.log(`The server host file: ${chalk.cyan(serverFile)} or PID file: ${chalk.cyan(pidFile)} exists.`);
|
|
8971
|
+
console.log("Do you want to kill other process and start a new server? [N/y]");
|
|
8972
|
+
const answer = await new Promise((resolve2) => {
|
|
8973
|
+
process.stdin.once("data", (data) => {
|
|
8974
|
+
resolve2(data.toString().trim());
|
|
8975
|
+
});
|
|
8976
|
+
});
|
|
8977
|
+
if (answer.toLowerCase() === "y") {
|
|
8978
|
+
if (fs$1.existsSync(pidFile)) {
|
|
8979
|
+
const pid = fs$1.readFileSync(pidFile, "utf-8");
|
|
8980
|
+
try {
|
|
8981
|
+
process.kill(parseInt(pid), "SIGTERM");
|
|
8982
|
+
console.log(`Killed process with PID: ${chalk.yellow(pid)}`);
|
|
8983
|
+
} catch (err) {
|
|
8984
|
+
console.log(`Failed to kill process with PID: ${chalk.yellow(pid)}. It may have already exited.`);
|
|
8985
|
+
}
|
|
8986
|
+
}
|
|
8987
|
+
fs$1.unlinkSync(serverFileFull);
|
|
8988
|
+
fs$1.unlinkSync(pidFile);
|
|
8989
|
+
console.log(`Start running new server on: ${chalk.green(url)} and PID: ${chalk.green(process.pid)}`);
|
|
8990
|
+
} else {
|
|
8991
|
+
console.log(chalk.yellow("Aborting server start."));
|
|
8992
|
+
process.exit(0);
|
|
8993
|
+
}
|
|
8948
8994
|
}
|
|
8995
|
+
serverRunning = true;
|
|
8996
|
+
await sleep(300);
|
|
8949
8997
|
fs$1.writeFileSync(serverFileFull, url);
|
|
8998
|
+
fs$1.writeFileSync(pidFile, process.pid.toString());
|
|
8950
8999
|
if (!exitHandlersBound) {
|
|
8951
9000
|
process.on("exit", () => {
|
|
8952
9001
|
for (const callback of exports.builder.serverStopCallbacks) {
|
|
@@ -8955,6 +9004,9 @@ function useFusion(fusionOptions = {}, tasks) {
|
|
|
8955
9004
|
if (fs$1.existsSync(serverFile)) {
|
|
8956
9005
|
fs$1.rmSync(serverFile);
|
|
8957
9006
|
}
|
|
9007
|
+
if (fs$1.existsSync(pidFile)) {
|
|
9008
|
+
fs$1.rmSync(pidFile);
|
|
9009
|
+
}
|
|
8958
9010
|
});
|
|
8959
9011
|
process.on("SIGINT", () => process.exit());
|
|
8960
9012
|
process.on("SIGTERM", () => process.exit());
|
|
@@ -9169,6 +9221,9 @@ function fullReloads(...paths) {
|
|
|
9169
9221
|
exports.builder.watches.push(...paths);
|
|
9170
9222
|
exports.builder.watches = uniq(exports.builder.watches);
|
|
9171
9223
|
}
|
|
9224
|
+
function sleep(ms) {
|
|
9225
|
+
return new Promise((resolve2) => setTimeout(() => resolve2(), ms));
|
|
9226
|
+
}
|
|
9172
9227
|
const index = {
|
|
9173
9228
|
...fusion,
|
|
9174
9229
|
useFusion,
|