@nasti-toolchain/nasti 2.4.2 → 2.4.4
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/README.md +34 -1
- package/dist/cli.cjs +546 -273
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +533 -260
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +472 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +465 -185
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -10,10 +10,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
10
10
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
12
|
});
|
|
13
|
-
var __glob = (map) => (
|
|
14
|
-
var fn = map[
|
|
13
|
+
var __glob = (map) => (path20) => {
|
|
14
|
+
var fn = map[path20];
|
|
15
15
|
if (fn) return fn();
|
|
16
|
-
throw new Error("Module not found in bundle: " +
|
|
16
|
+
throw new Error("Module not found in bundle: " + path20);
|
|
17
17
|
};
|
|
18
18
|
var __esm = (fn, res) => function __init() {
|
|
19
19
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
@@ -876,27 +876,27 @@ var require_process = __commonJS({
|
|
|
876
876
|
var require_filesystem = __commonJS({
|
|
877
877
|
"node_modules/detect-libc/lib/filesystem.js"(exports, module) {
|
|
878
878
|
"use strict";
|
|
879
|
-
var
|
|
879
|
+
var fs15 = __require("fs");
|
|
880
880
|
var LDD_PATH = "/usr/bin/ldd";
|
|
881
881
|
var SELF_PATH = "/proc/self/exe";
|
|
882
882
|
var MAX_LENGTH = 2048;
|
|
883
|
-
var readFileSync = (
|
|
884
|
-
const fd =
|
|
883
|
+
var readFileSync = (path20) => {
|
|
884
|
+
const fd = fs15.openSync(path20, "r");
|
|
885
885
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
886
|
-
const bytesRead =
|
|
887
|
-
|
|
886
|
+
const bytesRead = fs15.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
887
|
+
fs15.close(fd, () => {
|
|
888
888
|
});
|
|
889
889
|
return buffer.subarray(0, bytesRead);
|
|
890
890
|
};
|
|
891
|
-
var readFile = (
|
|
892
|
-
|
|
891
|
+
var readFile = (path20) => new Promise((resolve, reject) => {
|
|
892
|
+
fs15.open(path20, "r", (err, fd) => {
|
|
893
893
|
if (err) {
|
|
894
894
|
reject(err);
|
|
895
895
|
} else {
|
|
896
896
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
897
|
-
|
|
897
|
+
fs15.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
|
|
898
898
|
resolve(buffer.subarray(0, bytesRead));
|
|
899
|
-
|
|
899
|
+
fs15.close(fd, () => {
|
|
900
900
|
});
|
|
901
901
|
});
|
|
902
902
|
}
|
|
@@ -1008,11 +1008,11 @@ var require_detect_libc = __commonJS({
|
|
|
1008
1008
|
}
|
|
1009
1009
|
return null;
|
|
1010
1010
|
};
|
|
1011
|
-
var familyFromInterpreterPath = (
|
|
1012
|
-
if (
|
|
1013
|
-
if (
|
|
1011
|
+
var familyFromInterpreterPath = (path20) => {
|
|
1012
|
+
if (path20) {
|
|
1013
|
+
if (path20.includes("/ld-musl-")) {
|
|
1014
1014
|
return MUSL;
|
|
1015
|
-
} else if (
|
|
1015
|
+
} else if (path20.includes("/ld-linux-")) {
|
|
1016
1016
|
return GLIBC;
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
@@ -1059,8 +1059,8 @@ var require_detect_libc = __commonJS({
|
|
|
1059
1059
|
cachedFamilyInterpreter = null;
|
|
1060
1060
|
try {
|
|
1061
1061
|
const selfContent = await readFile(SELF_PATH);
|
|
1062
|
-
const
|
|
1063
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1062
|
+
const path20 = interpreterPath(selfContent);
|
|
1063
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path20);
|
|
1064
1064
|
} catch (e) {
|
|
1065
1065
|
}
|
|
1066
1066
|
return cachedFamilyInterpreter;
|
|
@@ -1072,8 +1072,8 @@ var require_detect_libc = __commonJS({
|
|
|
1072
1072
|
cachedFamilyInterpreter = null;
|
|
1073
1073
|
try {
|
|
1074
1074
|
const selfContent = readFileSync(SELF_PATH);
|
|
1075
|
-
const
|
|
1076
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1075
|
+
const path20 = interpreterPath(selfContent);
|
|
1076
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path20);
|
|
1077
1077
|
} catch (e) {
|
|
1078
1078
|
}
|
|
1079
1079
|
return cachedFamilyInterpreter;
|
|
@@ -2226,8 +2226,8 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2226
2226
|
let cached2 = descriptorCache.get(filePath);
|
|
2227
2227
|
if (!cached2) {
|
|
2228
2228
|
try {
|
|
2229
|
-
const
|
|
2230
|
-
const rawSource =
|
|
2229
|
+
const fs15 = await import("fs");
|
|
2230
|
+
const rawSource = fs15.readFileSync(filePath, "utf-8");
|
|
2231
2231
|
const transformedSfc = await applySourceTransform(
|
|
2232
2232
|
vueOptions.transformSfc,
|
|
2233
2233
|
rawSource,
|
|
@@ -2316,8 +2316,10 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2316
2316
|
});
|
|
2317
2317
|
const scopeId = hashId(id);
|
|
2318
2318
|
const wantsSourceMap = !!config.build.sourcemap || transformedSfc.map != null;
|
|
2319
|
+
const vapor = resolveVaporMode(descriptor, vueOptions, sfc, config);
|
|
2319
2320
|
let scriptCode = "";
|
|
2320
2321
|
let scriptMap;
|
|
2322
|
+
let scriptBindings;
|
|
2321
2323
|
if (descriptor.script || descriptor.scriptSetup) {
|
|
2322
2324
|
const inlineTemplate = vueOptions.script?.inlineTemplate !== false;
|
|
2323
2325
|
const compiled = sfc.compileScript(descriptor, {
|
|
@@ -2329,9 +2331,11 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2329
2331
|
// 让 compileScript 产出 `const __sfc__ = ...`(而非默认的 `export default {...}`)。
|
|
2330
2332
|
// 否则下方追加的 `__sfc__.render` / `__sfc__.__scopeId` / HMR 记录会引用一个
|
|
2331
2333
|
// 不存在的 `__sfc__`,并与 compileScript 自带的 `export default` 形成双重默认导出。
|
|
2332
|
-
genDefaultAs: "__sfc__"
|
|
2334
|
+
genDefaultAs: "__sfc__",
|
|
2335
|
+
vapor
|
|
2333
2336
|
});
|
|
2334
2337
|
scriptCode = compiled.content;
|
|
2338
|
+
scriptBindings = compiled.bindings;
|
|
2335
2339
|
scriptMap = composeSourceMapChain(
|
|
2336
2340
|
[compiled.map, transformedSfc.map],
|
|
2337
2341
|
{ filename: id, environmentName, type: "sfc" }
|
|
@@ -2345,7 +2349,9 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2345
2349
|
}
|
|
2346
2350
|
let templateCode = "";
|
|
2347
2351
|
let templateMap;
|
|
2352
|
+
let templateMultiRoot;
|
|
2348
2353
|
const scriptSetupIsInline = !!descriptor.scriptSetup && vueOptions.script?.inlineTemplate !== false;
|
|
2354
|
+
const isTemplateOnlyVapor = vapor && !descriptor.script && !descriptor.scriptSetup;
|
|
2349
2355
|
if (descriptor.template && !scriptSetupIsInline) {
|
|
2350
2356
|
const transformedTemplate = await applySourceTransform(
|
|
2351
2357
|
vueOptions.transformTemplate,
|
|
@@ -2367,12 +2373,16 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2367
2373
|
filename: id,
|
|
2368
2374
|
id: scopeId,
|
|
2369
2375
|
inMap: templateInputMap,
|
|
2376
|
+
vapor,
|
|
2370
2377
|
compilerOptions: {
|
|
2371
2378
|
...customCompilerOptions,
|
|
2379
|
+
// Vapor 在 bindingMetadata 缺失时需要空对象(与 Vite / compiler-sfc 一致)
|
|
2380
|
+
bindingMetadata: customCompilerOptions.bindingMetadata ?? scriptBindings ?? (vapor ? {} : void 0),
|
|
2372
2381
|
scopeId: `data-v-${scopeId}`
|
|
2373
2382
|
}
|
|
2374
2383
|
});
|
|
2375
2384
|
templateCode = compiled.code;
|
|
2385
|
+
templateMultiRoot = compiled.multiRoot;
|
|
2376
2386
|
if (wantsSourceMap || transformedTemplate.map != null) {
|
|
2377
2387
|
templateMap = compiled.map;
|
|
2378
2388
|
}
|
|
@@ -2410,12 +2420,20 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2410
2420
|
outputNode.add(fragment);
|
|
2411
2421
|
}
|
|
2412
2422
|
};
|
|
2413
|
-
append(
|
|
2423
|
+
append(
|
|
2424
|
+
scriptCode || (vapor ? "const __sfc__ = { __vapor: true }" : "const __sfc__ = {}"),
|
|
2425
|
+
scriptMap
|
|
2426
|
+
);
|
|
2414
2427
|
if (templateCode) {
|
|
2415
2428
|
append("\n");
|
|
2416
2429
|
append(templateCode, templateMap);
|
|
2417
2430
|
append("\n");
|
|
2418
2431
|
append("\n__sfc__.render = render\n");
|
|
2432
|
+
if (isTemplateOnlyVapor && templateMultiRoot !== void 0) {
|
|
2433
|
+
append(`
|
|
2434
|
+
__sfc__.__multiRoot = ${JSON.stringify(templateMultiRoot)}
|
|
2435
|
+
`);
|
|
2436
|
+
}
|
|
2419
2437
|
}
|
|
2420
2438
|
if (descriptor.styles.length > 0) {
|
|
2421
2439
|
for (let i = 0; i < descriptor.styles.length; i++) {
|
|
@@ -2424,6 +2442,16 @@ import "${id}?vue&type=style&index=${i}&lang.css"
|
|
|
2424
2442
|
`);
|
|
2425
2443
|
}
|
|
2426
2444
|
}
|
|
2445
|
+
if (vapor) {
|
|
2446
|
+
append(
|
|
2447
|
+
`
|
|
2448
|
+
if (!globalThis.__NASTI_VAPOR_BETA_WARNED__) {
|
|
2449
|
+
globalThis.__NASTI_VAPOR_BETA_WARNED__ = true
|
|
2450
|
+
console.warn(${JSON.stringify(VAPOR_BETA_WARNING)})
|
|
2451
|
+
}
|
|
2452
|
+
`
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2427
2455
|
append(`
|
|
2428
2456
|
__sfc__.__scopeId = "data-v-${scopeId}"
|
|
2429
2457
|
`);
|
|
@@ -2483,6 +2511,32 @@ if (import.meta.hot) {
|
|
|
2483
2511
|
}
|
|
2484
2512
|
};
|
|
2485
2513
|
}
|
|
2514
|
+
function resolveVaporMode(descriptor, vueOptions, sfc, config) {
|
|
2515
|
+
const requested = !!descriptor.vapor || !!vueOptions.features?.vapor && canForceVaporMode(descriptor);
|
|
2516
|
+
if (!requested) return false;
|
|
2517
|
+
if (!supportsVaporCompiler(sfc)) {
|
|
2518
|
+
config.logger.warnOnce(
|
|
2519
|
+
"[nasti:vue] Vapor Mode requires @vue/compiler-sfc >= 3.6. Install it: npm install @vue/compiler-sfc@^3.6.0-0"
|
|
2520
|
+
);
|
|
2521
|
+
return false;
|
|
2522
|
+
}
|
|
2523
|
+
config.logger.warnOnce(VAPOR_BETA_WARNING);
|
|
2524
|
+
return true;
|
|
2525
|
+
}
|
|
2526
|
+
function canForceVaporMode(descriptor) {
|
|
2527
|
+
if (typeof descriptor.filename === "string" && descriptor.filename.endsWith(".vue")) {
|
|
2528
|
+
if (descriptor.script && !descriptor.scriptSetup) return false;
|
|
2529
|
+
return !!(descriptor.scriptSetup || descriptor.template);
|
|
2530
|
+
}
|
|
2531
|
+
return true;
|
|
2532
|
+
}
|
|
2533
|
+
function supportsVaporCompiler(sfc) {
|
|
2534
|
+
const version = sfc.version;
|
|
2535
|
+
if (!version) return false;
|
|
2536
|
+
const [major, minor] = version.split(".").map((part) => Number.parseInt(part, 10));
|
|
2537
|
+
if (!Number.isFinite(major) || !Number.isFinite(minor)) return false;
|
|
2538
|
+
return major > 3 || major === 3 && minor >= 6;
|
|
2539
|
+
}
|
|
2486
2540
|
async function applySourceTransform(transform2, source, context) {
|
|
2487
2541
|
if (!transform2) return { code: source };
|
|
2488
2542
|
const result = await transform2(source, context);
|
|
@@ -2543,7 +2597,7 @@ function warnUnchainableMap(context, reason) {
|
|
|
2543
2597
|
function hashId(filename) {
|
|
2544
2598
|
return crypto2.createHash("sha256").update(filename).digest("hex").slice(0, 8);
|
|
2545
2599
|
}
|
|
2546
|
-
var VUE_FILE_RE, VUE_QUERY_RE, debug2, compiler;
|
|
2600
|
+
var VUE_FILE_RE, VUE_QUERY_RE, debug2, VAPOR_BETA_WARNING, compiler;
|
|
2547
2601
|
var init_vue = __esm({
|
|
2548
2602
|
"src/plugins/vue.ts"() {
|
|
2549
2603
|
"use strict";
|
|
@@ -2552,6 +2606,7 @@ var init_vue = __esm({
|
|
|
2552
2606
|
VUE_FILE_RE = /\.vue$/;
|
|
2553
2607
|
VUE_QUERY_RE = /\.vue\?vue&type=(script|template|style)(&index=\d+)?(&lang[.=]\w+)?/;
|
|
2554
2608
|
debug2 = createDebugger("nasti:vue");
|
|
2609
|
+
VAPOR_BETA_WARNING = "Vapor Mode is a beta feature; Zixiao Labs and the Vue team do not provide guarantees against crashes in production environments, and it is not suitable for server-side rendering environments.";
|
|
2555
2610
|
compiler = null;
|
|
2556
2611
|
}
|
|
2557
2612
|
});
|
|
@@ -2838,6 +2893,24 @@ var init_module_graph = __esm({
|
|
|
2838
2893
|
getModulesByFile(file) {
|
|
2839
2894
|
return this.fileToModulesMap.get(file);
|
|
2840
2895
|
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Modules whose registered entry file lives under `dir` (inclusive).
|
|
2898
|
+
* Used when a non-entry source inside a prebundled workspace package changes:
|
|
2899
|
+
* only the package entry was registered, so getModulesByFile(changedFile)
|
|
2900
|
+
* misses — we invalidate every /@modules entry rooted in that package.
|
|
2901
|
+
*/
|
|
2902
|
+
getModulesWithFileUnder(dir) {
|
|
2903
|
+
const result = /* @__PURE__ */ new Set();
|
|
2904
|
+
const normDir = dir.replace(/\\/g, "/");
|
|
2905
|
+
const normPrefix = normDir.endsWith("/") ? normDir : normDir + "/";
|
|
2906
|
+
for (const [file, mods] of this.fileToModulesMap) {
|
|
2907
|
+
const normFile = file.replace(/\\/g, "/");
|
|
2908
|
+
if (normFile === normDir || normFile.startsWith(normPrefix)) {
|
|
2909
|
+
for (const m of mods) result.add(m);
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
return result;
|
|
2913
|
+
}
|
|
2841
2914
|
async ensureEntryFromUrl(url) {
|
|
2842
2915
|
const normalizedUrl = removeTimestampQuery(url);
|
|
2843
2916
|
let mod = this.urlToModuleMap.get(normalizedUrl);
|
|
@@ -3811,7 +3884,7 @@ async function build(inlineConfig = {}) {
|
|
|
3811
3884
|
const startTime = performance.now();
|
|
3812
3885
|
logger.info(
|
|
3813
3886
|
pc4.cyan(`
|
|
3814
|
-
nasti v${"2.4.
|
|
3887
|
+
nasti v${"2.4.4"} `) + pc4.green(`building for ${config.mode}...`)
|
|
3815
3888
|
);
|
|
3816
3889
|
debug5?.(`root: ${config.root}`);
|
|
3817
3890
|
const buildableNames = Object.keys(config.environments).filter((name) => {
|
|
@@ -4148,10 +4221,124 @@ var init_ws = __esm({
|
|
|
4148
4221
|
}
|
|
4149
4222
|
});
|
|
4150
4223
|
|
|
4151
|
-
// src/server/
|
|
4152
|
-
import path12 from "path";
|
|
4224
|
+
// src/server/fs-allow.ts
|
|
4153
4225
|
import fs9 from "fs";
|
|
4154
|
-
import
|
|
4226
|
+
import path12 from "path";
|
|
4227
|
+
function isUnderRoot(abs, root) {
|
|
4228
|
+
const rel = path12.relative(root, abs);
|
|
4229
|
+
return !!rel && !rel.startsWith("..") && !path12.isAbsolute(rel);
|
|
4230
|
+
}
|
|
4231
|
+
function discoverLinkedPackageRoots(projectRoot, maxDepth = 4) {
|
|
4232
|
+
const results = [];
|
|
4233
|
+
const seenReal = /* @__PURE__ */ new Set();
|
|
4234
|
+
const queued = /* @__PURE__ */ new Set([projectRoot]);
|
|
4235
|
+
const queue = [projectRoot];
|
|
4236
|
+
for (let depth = 0; depth < maxDepth && queue.length > 0; depth++) {
|
|
4237
|
+
const levelCount = queue.length;
|
|
4238
|
+
for (let i = 0; i < levelCount; i++) {
|
|
4239
|
+
const dir = queue.shift();
|
|
4240
|
+
const nm = path12.join(dir, "node_modules");
|
|
4241
|
+
let entries;
|
|
4242
|
+
try {
|
|
4243
|
+
entries = fs9.readdirSync(nm, { withFileTypes: true });
|
|
4244
|
+
} catch {
|
|
4245
|
+
continue;
|
|
4246
|
+
}
|
|
4247
|
+
for (const ent of entries) {
|
|
4248
|
+
if (ent.name.startsWith(".") || ent.name === "node_modules") continue;
|
|
4249
|
+
const pkgNames = ent.name.startsWith("@") ? listScopedPackages(nm, ent.name) : [ent.name];
|
|
4250
|
+
for (const pkgName of pkgNames) {
|
|
4251
|
+
const pkgPath = path12.join(nm, pkgName);
|
|
4252
|
+
let real;
|
|
4253
|
+
try {
|
|
4254
|
+
real = fs9.realpathSync(pkgPath);
|
|
4255
|
+
} catch {
|
|
4256
|
+
continue;
|
|
4257
|
+
}
|
|
4258
|
+
if (seenReal.has(real)) continue;
|
|
4259
|
+
seenReal.add(real);
|
|
4260
|
+
if (!queued.has(real)) {
|
|
4261
|
+
queued.add(real);
|
|
4262
|
+
queue.push(real);
|
|
4263
|
+
}
|
|
4264
|
+
if (real !== projectRoot && !isUnderRoot(real, projectRoot) && !real.includes(NM)) {
|
|
4265
|
+
results.push(real);
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
return results;
|
|
4272
|
+
}
|
|
4273
|
+
function listScopedPackages(nm, scope) {
|
|
4274
|
+
try {
|
|
4275
|
+
return fs9.readdirSync(path12.join(nm, scope)).filter((name) => !name.startsWith(".")).map((name) => path12.join(scope, name));
|
|
4276
|
+
} catch {
|
|
4277
|
+
return [];
|
|
4278
|
+
}
|
|
4279
|
+
}
|
|
4280
|
+
function getLinkedPackageRoots(projectRoot) {
|
|
4281
|
+
let mtimeMs = 0;
|
|
4282
|
+
try {
|
|
4283
|
+
mtimeMs = fs9.statSync(path12.join(projectRoot, "node_modules")).mtimeMs;
|
|
4284
|
+
} catch {
|
|
4285
|
+
mtimeMs = 0;
|
|
4286
|
+
}
|
|
4287
|
+
const cached2 = linkedRootsCache.get(projectRoot);
|
|
4288
|
+
if (cached2 && cached2.mtimeMs === mtimeMs) {
|
|
4289
|
+
return cached2.roots;
|
|
4290
|
+
}
|
|
4291
|
+
const roots = discoverLinkedPackageRoots(projectRoot);
|
|
4292
|
+
linkedRootsCache.set(projectRoot, { roots, mtimeMs });
|
|
4293
|
+
return roots;
|
|
4294
|
+
}
|
|
4295
|
+
function clearLinkedPackageRootsCache() {
|
|
4296
|
+
linkedRootsCache.clear();
|
|
4297
|
+
}
|
|
4298
|
+
function isAllowedDevModulePath(realId, projectRoot) {
|
|
4299
|
+
if (realId === projectRoot || isUnderRoot(realId, projectRoot)) return true;
|
|
4300
|
+
for (const pkgRoot of getLinkedPackageRoots(projectRoot)) {
|
|
4301
|
+
if (realId === pkgRoot || realId.startsWith(pkgRoot + path12.sep)) return true;
|
|
4302
|
+
}
|
|
4303
|
+
let dir = projectRoot;
|
|
4304
|
+
for (; ; ) {
|
|
4305
|
+
const nm = path12.join(dir, "node_modules");
|
|
4306
|
+
if (realId === nm || realId.startsWith(nm + path12.sep)) return true;
|
|
4307
|
+
const parent = path12.dirname(dir);
|
|
4308
|
+
if (parent === dir) break;
|
|
4309
|
+
dir = parent;
|
|
4310
|
+
}
|
|
4311
|
+
return false;
|
|
4312
|
+
}
|
|
4313
|
+
function findNearestPackageRoot(file) {
|
|
4314
|
+
let dir = path12.dirname(file);
|
|
4315
|
+
for (; ; ) {
|
|
4316
|
+
const pkgJson = path12.join(dir, "package.json");
|
|
4317
|
+
if (fs9.existsSync(pkgJson)) {
|
|
4318
|
+
try {
|
|
4319
|
+
const pkg = JSON.parse(fs9.readFileSync(pkgJson, "utf-8"));
|
|
4320
|
+
if (typeof pkg?.name === "string" && pkg.name) return dir;
|
|
4321
|
+
} catch {
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
const parent = path12.dirname(dir);
|
|
4325
|
+
if (parent === dir) return null;
|
|
4326
|
+
dir = parent;
|
|
4327
|
+
}
|
|
4328
|
+
}
|
|
4329
|
+
var NM, linkedRootsCache;
|
|
4330
|
+
var init_fs_allow = __esm({
|
|
4331
|
+
"src/server/fs-allow.ts"() {
|
|
4332
|
+
"use strict";
|
|
4333
|
+
NM = `${path12.sep}node_modules${path12.sep}`;
|
|
4334
|
+
linkedRootsCache = /* @__PURE__ */ new Map();
|
|
4335
|
+
}
|
|
4336
|
+
});
|
|
4337
|
+
|
|
4338
|
+
// src/server/middleware.ts
|
|
4339
|
+
import path13 from "path";
|
|
4340
|
+
import fs10 from "fs";
|
|
4341
|
+
import { createRequire as createRequire4 } from "module";
|
|
4155
4342
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "url";
|
|
4156
4343
|
import pc6 from "picocolors";
|
|
4157
4344
|
function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
|
|
@@ -4161,10 +4348,10 @@ function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
|
|
|
4161
4348
|
let cjsPath;
|
|
4162
4349
|
try {
|
|
4163
4350
|
const pkgPath = __require2.resolve("react-refresh/package.json");
|
|
4164
|
-
cjsPath =
|
|
4351
|
+
cjsPath = path13.join(path13.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
|
|
4165
4352
|
} catch (err) {
|
|
4166
|
-
cjsPath =
|
|
4167
|
-
if (!
|
|
4353
|
+
cjsPath = path13.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
|
|
4354
|
+
if (!fs10.existsSync(cjsPath)) {
|
|
4168
4355
|
const origMsg = err instanceof Error ? err.message : String(err);
|
|
4169
4356
|
throw new Error(
|
|
4170
4357
|
`[nasti] Missing dependency "react-refresh". Install it with: npm install react-refresh
|
|
@@ -4172,7 +4359,7 @@ Original resolve error: ${origMsg}`
|
|
|
4172
4359
|
);
|
|
4173
4360
|
}
|
|
4174
4361
|
}
|
|
4175
|
-
const cjsSource =
|
|
4362
|
+
const cjsSource = fs10.readFileSync(cjsPath, "utf-8");
|
|
4176
4363
|
__refreshRuntimeCache = `// Wrapped react-refresh runtime -> ESM
|
|
4177
4364
|
const exports = {};
|
|
4178
4365
|
const module = { exports };
|
|
@@ -4343,8 +4530,8 @@ async function transformRequest(url, ctx) {
|
|
|
4343
4530
|
let realIdValid = false;
|
|
4344
4531
|
try {
|
|
4345
4532
|
if (idParam) {
|
|
4346
|
-
realId =
|
|
4347
|
-
realIdValid =
|
|
4533
|
+
realId = fs10.realpathSync(idParam);
|
|
4534
|
+
realIdValid = fs10.statSync(realId).isFile() && isAllowedDevModulePath(realId, config.root);
|
|
4348
4535
|
}
|
|
4349
4536
|
} catch {
|
|
4350
4537
|
realId = null;
|
|
@@ -4411,7 +4598,7 @@ async function transformRequest(url, ctx) {
|
|
|
4411
4598
|
}
|
|
4412
4599
|
}
|
|
4413
4600
|
const filePath = resolveUrlToFile(url, config.root);
|
|
4414
|
-
if (!filePath || !
|
|
4601
|
+
if (!filePath || !fs10.existsSync(filePath)) return null;
|
|
4415
4602
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
4416
4603
|
moduleGraph.registerModule(mod, filePath);
|
|
4417
4604
|
const transformVersion = mod.invalidationVersion;
|
|
@@ -4422,7 +4609,7 @@ async function transformRequest(url, ctx) {
|
|
|
4422
4609
|
return transformResult2;
|
|
4423
4610
|
}
|
|
4424
4611
|
const loaded = await pluginContainer.load(filePath);
|
|
4425
|
-
let code = loaded == null ?
|
|
4612
|
+
let code = loaded == null ? fs10.readFileSync(filePath, "utf-8") : typeof loaded === "string" ? loaded : loaded.code;
|
|
4426
4613
|
let map = loaded && typeof loaded !== "string" ? loaded.map : void 0;
|
|
4427
4614
|
const pluginResult = await pluginContainer.transform(code, filePath);
|
|
4428
4615
|
if (pluginResult) {
|
|
@@ -4480,7 +4667,7 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
4480
4667
|
const resolved = await pluginContainer.resolveId(spec);
|
|
4481
4668
|
if (resolved == null) return null;
|
|
4482
4669
|
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
4483
|
-
const looksVirtual = resolvedId.startsWith("\0") || !
|
|
4670
|
+
const looksVirtual = resolvedId.startsWith("\0") || !fs10.existsSync(resolvedId);
|
|
4484
4671
|
if (!looksVirtual) return null;
|
|
4485
4672
|
const loadResult = await pluginContainer.load(resolvedId);
|
|
4486
4673
|
if (loadResult == null) return null;
|
|
@@ -4494,7 +4681,7 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
4494
4681
|
config.mode,
|
|
4495
4682
|
ssrDefineOverrides(ctx.environment?.consumer ?? "client")
|
|
4496
4683
|
));
|
|
4497
|
-
const anchor =
|
|
4684
|
+
const anchor = path13.join(config.root, "__nasti_virtual__.ts");
|
|
4498
4685
|
code = rewriteImports(code, config, anchor);
|
|
4499
4686
|
return { id: resolvedId, result: { code } };
|
|
4500
4687
|
}
|
|
@@ -4520,7 +4707,7 @@ async function doBundlePackage(entryFile, root) {
|
|
|
4520
4707
|
await bundle2.close();
|
|
4521
4708
|
let code = result.output[0].code;
|
|
4522
4709
|
code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
|
|
4523
|
-
const externalBaseDir =
|
|
4710
|
+
const externalBaseDir = path13.dirname(entryFile);
|
|
4524
4711
|
code = code.replace(
|
|
4525
4712
|
/^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
4526
4713
|
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
@@ -4538,16 +4725,16 @@ async function doBundlePackage(entryFile, root) {
|
|
|
4538
4725
|
return code;
|
|
4539
4726
|
}
|
|
4540
4727
|
async function tryGenerateSubpathShim(entryFile, root) {
|
|
4541
|
-
const
|
|
4542
|
-
if (!entryFile.includes(
|
|
4728
|
+
const NM2 = `${path13.sep}node_modules${path13.sep}`;
|
|
4729
|
+
if (!entryFile.includes(NM2)) return null;
|
|
4543
4730
|
let pkgDir = null;
|
|
4544
4731
|
let pkgName = null;
|
|
4545
|
-
let dir =
|
|
4732
|
+
let dir = path13.dirname(entryFile);
|
|
4546
4733
|
while (true) {
|
|
4547
|
-
const pkgJsonPath =
|
|
4548
|
-
if (
|
|
4734
|
+
const pkgJsonPath = path13.join(dir, "package.json");
|
|
4735
|
+
if (fs10.existsSync(pkgJsonPath)) {
|
|
4549
4736
|
try {
|
|
4550
|
-
const pkg = JSON.parse(
|
|
4737
|
+
const pkg = JSON.parse(fs10.readFileSync(pkgJsonPath, "utf-8"));
|
|
4551
4738
|
if (typeof pkg?.name === "string" && pkg.name) {
|
|
4552
4739
|
pkgDir = dir;
|
|
4553
4740
|
pkgName = pkg.name;
|
|
@@ -4556,16 +4743,16 @@ async function tryGenerateSubpathShim(entryFile, root) {
|
|
|
4556
4743
|
} catch {
|
|
4557
4744
|
}
|
|
4558
4745
|
}
|
|
4559
|
-
const parent =
|
|
4746
|
+
const parent = path13.dirname(dir);
|
|
4560
4747
|
if (parent === dir) return null;
|
|
4561
4748
|
dir = parent;
|
|
4562
|
-
if (!dir.includes(
|
|
4749
|
+
if (!dir.includes(NM2)) return null;
|
|
4563
4750
|
}
|
|
4564
4751
|
if (!pkgDir || !pkgName) return null;
|
|
4565
|
-
const entryExt =
|
|
4752
|
+
const entryExt = path13.extname(entryFile);
|
|
4566
4753
|
const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
|
|
4567
4754
|
if (!mainEntry) return null;
|
|
4568
|
-
if (
|
|
4755
|
+
if (path13.resolve(mainEntry) === path13.resolve(entryFile)) return null;
|
|
4569
4756
|
let mainNs;
|
|
4570
4757
|
let subNs;
|
|
4571
4758
|
try {
|
|
@@ -4589,7 +4776,7 @@ async function tryGenerateSubpathShim(entryFile, root) {
|
|
|
4589
4776
|
if (mainNs["default"] !== subNs["default"]) return null;
|
|
4590
4777
|
}
|
|
4591
4778
|
const rootMain = resolveNodeModule(root, pkgName);
|
|
4592
|
-
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir +
|
|
4779
|
+
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + path13.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
|
|
4593
4780
|
const lines = [
|
|
4594
4781
|
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
4595
4782
|
`import * as __pkg from "${mainEntryUrl}";`
|
|
@@ -4603,10 +4790,10 @@ async function tryGenerateSubpathShim(entryFile, root) {
|
|
|
4603
4790
|
return lines.join("\n") + "\n";
|
|
4604
4791
|
}
|
|
4605
4792
|
function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
4606
|
-
const pkgJsonPath =
|
|
4793
|
+
const pkgJsonPath = path13.join(pkgDir, "package.json");
|
|
4607
4794
|
let pkg;
|
|
4608
4795
|
try {
|
|
4609
|
-
pkg = JSON.parse(
|
|
4796
|
+
pkg = JSON.parse(fs10.readFileSync(pkgJsonPath, "utf-8"));
|
|
4610
4797
|
} catch {
|
|
4611
4798
|
return null;
|
|
4612
4799
|
}
|
|
@@ -4625,14 +4812,14 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
4625
4812
|
if (typeof pkg.module === "string") candidates.push(pkg.module);
|
|
4626
4813
|
if (typeof pkg.main === "string") candidates.push(pkg.main);
|
|
4627
4814
|
for (const cand of candidates) {
|
|
4628
|
-
if (
|
|
4629
|
-
const full =
|
|
4630
|
-
if (
|
|
4815
|
+
if (path13.extname(cand) === preferredExt) {
|
|
4816
|
+
const full = path13.resolve(pkgDir, cand);
|
|
4817
|
+
if (fs10.existsSync(full)) return full;
|
|
4631
4818
|
}
|
|
4632
4819
|
}
|
|
4633
4820
|
for (const cand of candidates) {
|
|
4634
|
-
const full =
|
|
4635
|
-
if (
|
|
4821
|
+
const full = path13.resolve(pkgDir, cand);
|
|
4822
|
+
if (fs10.existsSync(full)) return full;
|
|
4636
4823
|
}
|
|
4637
4824
|
return null;
|
|
4638
4825
|
}
|
|
@@ -4657,8 +4844,8 @@ function rewriteExternalRequires(code, baseDir, root) {
|
|
|
4657
4844
|
}
|
|
4658
4845
|
async function injectCjsNamedExports(code, entryFile) {
|
|
4659
4846
|
try {
|
|
4660
|
-
const { createRequire:
|
|
4661
|
-
const req =
|
|
4847
|
+
const { createRequire: createRequire8 } = await import("module");
|
|
4848
|
+
const req = createRequire8(entryFile);
|
|
4662
4849
|
const cjsExports = req(entryFile);
|
|
4663
4850
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
4664
4851
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
@@ -4699,11 +4886,22 @@ function rewriteImports(code, config, filePath, importedUrls, moduleGraph) {
|
|
|
4699
4886
|
}
|
|
4700
4887
|
function createModuleSpecifierResolver(config, filePath) {
|
|
4701
4888
|
const root = config.root;
|
|
4702
|
-
const fileDir =
|
|
4889
|
+
const fileDir = path13.dirname(filePath);
|
|
4703
4890
|
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
4704
4891
|
([a], [b]) => b.length - a.length
|
|
4705
4892
|
);
|
|
4706
|
-
const
|
|
4893
|
+
const toServableUrl = (abs) => {
|
|
4894
|
+
if (isUnderRoot(abs, root)) {
|
|
4895
|
+
return "/" + path13.relative(root, abs).replace(/\\/g, "/");
|
|
4896
|
+
}
|
|
4897
|
+
for (const pkgRoot of getLinkedPackageRoots(root)) {
|
|
4898
|
+
if (abs === pkgRoot || abs.startsWith(pkgRoot + path13.sep)) {
|
|
4899
|
+
const normalized = abs.replace(/\\/g, "/");
|
|
4900
|
+
return "/@fs/" + (normalized.startsWith("/") ? normalized.slice(1) : normalized);
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
return null;
|
|
4904
|
+
};
|
|
4707
4905
|
return (specifier) => {
|
|
4708
4906
|
const suffixMatch = specifier.match(/[?#].*$/);
|
|
4709
4907
|
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
@@ -4712,18 +4910,21 @@ function createModuleSpecifierResolver(config, filePath) {
|
|
|
4712
4910
|
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
4713
4911
|
const aliasBase = resolveAliasTarget2(value, root);
|
|
4714
4912
|
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
4715
|
-
const target = sub ?
|
|
4913
|
+
const target = sub ? path13.join(aliasBase, sub) : aliasBase;
|
|
4716
4914
|
const resolved = tryResolveDiskPath(target);
|
|
4717
|
-
|
|
4915
|
+
const url = resolved ? toServableUrl(resolved) : null;
|
|
4916
|
+
return url ? url + suffix : specifier;
|
|
4718
4917
|
}
|
|
4719
4918
|
}
|
|
4720
4919
|
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
4721
|
-
const resolved = tryResolveDiskPath(
|
|
4722
|
-
|
|
4920
|
+
const resolved = tryResolveDiskPath(path13.resolve(fileDir, baseSpec));
|
|
4921
|
+
const url = resolved ? toServableUrl(resolved) : null;
|
|
4922
|
+
return url ? url + suffix : specifier;
|
|
4723
4923
|
}
|
|
4724
4924
|
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
4725
|
-
const resolved = tryResolveDiskPath(
|
|
4726
|
-
|
|
4925
|
+
const resolved = tryResolveDiskPath(path13.join(root, baseSpec.replace(/^\//, "")));
|
|
4926
|
+
const url = resolved ? toServableUrl(resolved) : null;
|
|
4927
|
+
return url ? url + suffix : specifier;
|
|
4727
4928
|
}
|
|
4728
4929
|
if (baseSpec.startsWith("/")) return specifier;
|
|
4729
4930
|
return `/@modules/${specifier}`;
|
|
@@ -4876,28 +5077,24 @@ function maskStringsAndComments(code) {
|
|
|
4876
5077
|
return masked.join("");
|
|
4877
5078
|
}
|
|
4878
5079
|
function resolveAliasTarget2(value, root) {
|
|
4879
|
-
if (
|
|
4880
|
-
if (value.startsWith("/")) return
|
|
4881
|
-
return
|
|
5080
|
+
if (path13.isAbsolute(value) && fs10.existsSync(value)) return value;
|
|
5081
|
+
if (value.startsWith("/")) return path13.join(root, value.slice(1));
|
|
5082
|
+
return path13.resolve(root, value);
|
|
4882
5083
|
}
|
|
4883
5084
|
function tryResolveDiskPath(target) {
|
|
4884
|
-
if (
|
|
5085
|
+
if (fs10.existsSync(target) && fs10.statSync(target).isFile()) return target;
|
|
4885
5086
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
4886
5087
|
const withExt = target + ext;
|
|
4887
|
-
if (
|
|
5088
|
+
if (fs10.existsSync(withExt) && fs10.statSync(withExt).isFile()) return withExt;
|
|
4888
5089
|
}
|
|
4889
|
-
if (
|
|
5090
|
+
if (fs10.existsSync(target) && fs10.statSync(target).isDirectory()) {
|
|
4890
5091
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
4891
|
-
const idx =
|
|
4892
|
-
if (
|
|
5092
|
+
const idx = path13.join(target, "index" + ext);
|
|
5093
|
+
if (fs10.existsSync(idx) && fs10.statSync(idx).isFile()) return idx;
|
|
4893
5094
|
}
|
|
4894
5095
|
}
|
|
4895
5096
|
return null;
|
|
4896
5097
|
}
|
|
4897
|
-
function isUnderRoot(abs, root) {
|
|
4898
|
-
const rel = path12.relative(root, abs);
|
|
4899
|
-
return !!rel && !rel.startsWith("..") && !path12.isAbsolute(rel);
|
|
4900
|
-
}
|
|
4901
5098
|
function appendTimestampQuery(url, timestamp) {
|
|
4902
5099
|
const hashIndex = url.indexOf("#");
|
|
4903
5100
|
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
@@ -4915,7 +5112,7 @@ function resolveNodeModule(baseDir, moduleName) {
|
|
|
4915
5112
|
const resolved = resolveNodeModuleEntry(baseDir, moduleName);
|
|
4916
5113
|
if (!resolved) return null;
|
|
4917
5114
|
try {
|
|
4918
|
-
return
|
|
5115
|
+
return fs10.realpathSync(resolved);
|
|
4919
5116
|
} catch {
|
|
4920
5117
|
return resolved;
|
|
4921
5118
|
}
|
|
@@ -4935,21 +5132,21 @@ function resolveNodeModuleEntry(root, moduleName) {
|
|
|
4935
5132
|
let pkgDir = null;
|
|
4936
5133
|
let dir = root;
|
|
4937
5134
|
for (; ; ) {
|
|
4938
|
-
const candidate =
|
|
4939
|
-
if (
|
|
5135
|
+
const candidate = path13.join(dir, "node_modules", pkgName);
|
|
5136
|
+
if (fs10.existsSync(candidate)) {
|
|
4940
5137
|
pkgDir = candidate;
|
|
4941
5138
|
break;
|
|
4942
5139
|
}
|
|
4943
|
-
const parent =
|
|
5140
|
+
const parent = path13.dirname(dir);
|
|
4944
5141
|
if (parent === dir) break;
|
|
4945
5142
|
dir = parent;
|
|
4946
5143
|
}
|
|
4947
5144
|
if (!pkgDir) return null;
|
|
4948
|
-
const pkgJsonPath =
|
|
4949
|
-
if (!
|
|
5145
|
+
const pkgJsonPath = path13.join(pkgDir, "package.json");
|
|
5146
|
+
if (!fs10.existsSync(pkgJsonPath)) return null;
|
|
4950
5147
|
let pkg;
|
|
4951
5148
|
try {
|
|
4952
|
-
pkg = JSON.parse(
|
|
5149
|
+
pkg = JSON.parse(fs10.readFileSync(pkgJsonPath, "utf-8"));
|
|
4953
5150
|
} catch {
|
|
4954
5151
|
return null;
|
|
4955
5152
|
}
|
|
@@ -4962,32 +5159,32 @@ function resolveNodeModuleEntry(root, moduleName) {
|
|
|
4962
5159
|
const subDirs = [""];
|
|
4963
5160
|
for (const field of ["module", "main"]) {
|
|
4964
5161
|
if (typeof pkg[field] === "string") {
|
|
4965
|
-
const dir2 =
|
|
5162
|
+
const dir2 = path13.dirname(pkg[field]);
|
|
4966
5163
|
if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
|
|
4967
5164
|
}
|
|
4968
5165
|
}
|
|
4969
5166
|
for (const dir2 of subDirs) {
|
|
4970
|
-
const direct =
|
|
4971
|
-
if (
|
|
5167
|
+
const direct = path13.join(pkgDir, dir2, subpath);
|
|
5168
|
+
if (fs10.existsSync(direct) && fs10.statSync(direct).isFile()) return direct;
|
|
4972
5169
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
4973
|
-
if (
|
|
5170
|
+
if (fs10.existsSync(direct + ext)) return direct + ext;
|
|
4974
5171
|
}
|
|
4975
5172
|
}
|
|
4976
5173
|
return null;
|
|
4977
5174
|
}
|
|
4978
5175
|
for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
|
|
4979
5176
|
if (typeof pkg[field] === "string") {
|
|
4980
|
-
const entry =
|
|
4981
|
-
if (
|
|
5177
|
+
const entry = path13.join(pkgDir, pkg[field]);
|
|
5178
|
+
if (fs10.existsSync(entry)) return entry;
|
|
4982
5179
|
}
|
|
4983
5180
|
}
|
|
4984
|
-
const indexFallback =
|
|
4985
|
-
if (
|
|
5181
|
+
const indexFallback = path13.join(pkgDir, "index.js");
|
|
5182
|
+
if (fs10.existsSync(indexFallback)) return indexFallback;
|
|
4986
5183
|
return null;
|
|
4987
5184
|
}
|
|
4988
5185
|
function resolvePackageExports(exports, key, pkgDir) {
|
|
4989
5186
|
if (typeof exports === "string") {
|
|
4990
|
-
return key === "." ?
|
|
5187
|
+
return key === "." ? path13.join(pkgDir, exports) : null;
|
|
4991
5188
|
}
|
|
4992
5189
|
const entry = exports[key];
|
|
4993
5190
|
if (entry === void 0) {
|
|
@@ -4999,7 +5196,7 @@ function resolvePackageExports(exports, key, pkgDir) {
|
|
|
4999
5196
|
return resolveExportValue(entry, pkgDir);
|
|
5000
5197
|
}
|
|
5001
5198
|
function resolveExportValue(value, pkgDir) {
|
|
5002
|
-
if (typeof value === "string") return
|
|
5199
|
+
if (typeof value === "string") return path13.join(pkgDir, value);
|
|
5003
5200
|
if (Array.isArray(value)) {
|
|
5004
5201
|
for (const item of value) {
|
|
5005
5202
|
const r = resolveExportValue(item, pkgDir);
|
|
@@ -5018,35 +5215,54 @@ function resolveExportValue(value, pkgDir) {
|
|
|
5018
5215
|
return null;
|
|
5019
5216
|
}
|
|
5020
5217
|
function resolveUrlToFile(url, root) {
|
|
5021
|
-
const cleanUrl = url.split(
|
|
5218
|
+
const cleanUrl = url.split(/[?#]/)[0];
|
|
5022
5219
|
if (cleanUrl.startsWith("/@modules/")) {
|
|
5023
5220
|
const moduleName = cleanUrl.slice("/@modules/".length);
|
|
5024
5221
|
return resolveNodeModule(root, moduleName);
|
|
5025
5222
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5223
|
+
if (cleanUrl.startsWith("/@fs/")) {
|
|
5224
|
+
let abs = cleanUrl.slice("/@fs/".length);
|
|
5225
|
+
if (process.platform === "win32") {
|
|
5226
|
+
abs = abs.replace(/\//g, path13.sep);
|
|
5227
|
+
} else if (!abs.startsWith("/")) {
|
|
5228
|
+
abs = "/" + abs;
|
|
5229
|
+
}
|
|
5230
|
+
try {
|
|
5231
|
+
const real = fs10.realpathSync(abs);
|
|
5232
|
+
if (fs10.statSync(real).isFile() && isAllowedDevModulePath(real, root)) return real;
|
|
5233
|
+
} catch {
|
|
5234
|
+
return null;
|
|
5235
|
+
}
|
|
5236
|
+
return null;
|
|
5237
|
+
}
|
|
5238
|
+
const filePath = path13.resolve(root, cleanUrl.replace(/^\//, ""));
|
|
5239
|
+
if (fs10.existsSync(filePath) && fs10.statSync(filePath).isFile()) {
|
|
5028
5240
|
return filePath;
|
|
5029
5241
|
}
|
|
5030
5242
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
5031
5243
|
const withExt = filePath + ext;
|
|
5032
|
-
if (
|
|
5244
|
+
if (fs10.existsSync(withExt)) return withExt;
|
|
5033
5245
|
}
|
|
5034
5246
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
5035
|
-
const indexFile =
|
|
5036
|
-
if (
|
|
5247
|
+
const indexFile = path13.join(filePath, "index" + ext);
|
|
5248
|
+
if (fs10.existsSync(indexFile)) return indexFile;
|
|
5037
5249
|
}
|
|
5038
5250
|
return null;
|
|
5039
5251
|
}
|
|
5040
5252
|
function isModuleRequest(url, destination) {
|
|
5041
|
-
const cleanUrl = url.split(
|
|
5253
|
+
const cleanUrl = url.split(/[?#]/)[0];
|
|
5042
5254
|
if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
|
|
5043
5255
|
if (cleanUrl.startsWith("/@modules/")) return true;
|
|
5256
|
+
if (cleanUrl.startsWith("/@fs/")) return true;
|
|
5044
5257
|
if (isAssetFile(cleanUrl)) {
|
|
5045
|
-
const
|
|
5258
|
+
const qIdx = url.indexOf("?");
|
|
5259
|
+
const hIdx = url.indexOf("#");
|
|
5260
|
+
const queryEnd = hIdx === -1 ? url.length : hIdx;
|
|
5261
|
+
const query = qIdx === -1 || qIdx > queryEnd ? "" : url.slice(qIdx + 1, queryEnd);
|
|
5046
5262
|
const isExplicitAssetModule = /(?:^|&)(?:url|raw)(?:&|$)/.test(query);
|
|
5047
5263
|
return isExplicitAssetModule || destination === "script";
|
|
5048
5264
|
}
|
|
5049
|
-
if (!
|
|
5265
|
+
if (!path13.extname(cleanUrl)) return true;
|
|
5050
5266
|
return false;
|
|
5051
5267
|
}
|
|
5052
5268
|
function getHmrClientCode() {
|
|
@@ -5285,8 +5501,9 @@ var init_middleware = __esm({
|
|
|
5285
5501
|
init_env();
|
|
5286
5502
|
init_url();
|
|
5287
5503
|
init_assets();
|
|
5288
|
-
|
|
5289
|
-
|
|
5504
|
+
init_fs_allow();
|
|
5505
|
+
__dirname_esm = path13.dirname(fileURLToPath(import.meta.url));
|
|
5506
|
+
__require2 = createRequire4(import.meta.url);
|
|
5290
5507
|
__refreshRuntimeCache = null;
|
|
5291
5508
|
REACT_REFRESH_BOUNDARY_HELPERS = `
|
|
5292
5509
|
function __nastiIsPlainObject(obj) {
|
|
@@ -5366,8 +5583,8 @@ window.__vite_plugin_react_preamble_installed__ = true;
|
|
|
5366
5583
|
});
|
|
5367
5584
|
|
|
5368
5585
|
// src/server/hmr.ts
|
|
5369
|
-
import
|
|
5370
|
-
import
|
|
5586
|
+
import path14 from "path";
|
|
5587
|
+
import fs11 from "fs";
|
|
5371
5588
|
import pc7 from "picocolors";
|
|
5372
5589
|
async function handleFileChange(file, server, environmentName = "client", timestamp = Date.now()) {
|
|
5373
5590
|
const { config } = server;
|
|
@@ -5377,9 +5594,26 @@ async function handleFileChange(file, server, environmentName = "client", timest
|
|
|
5377
5594
|
}
|
|
5378
5595
|
const moduleGraph = environment.moduleGraph;
|
|
5379
5596
|
const logger = config.logger;
|
|
5380
|
-
const relativePath = "/" +
|
|
5381
|
-
const shortFile =
|
|
5382
|
-
|
|
5597
|
+
const relativePath = "/" + path14.relative(config.root, file);
|
|
5598
|
+
const shortFile = path14.relative(config.root, file);
|
|
5599
|
+
let mods = moduleGraph.getModulesByFile(file);
|
|
5600
|
+
if (!mods || mods.size === 0) {
|
|
5601
|
+
try {
|
|
5602
|
+
const real = fs11.realpathSync(file);
|
|
5603
|
+
if (real !== file) mods = moduleGraph.getModulesByFile(real);
|
|
5604
|
+
if (mods && mods.size > 0) file = real;
|
|
5605
|
+
} catch {
|
|
5606
|
+
}
|
|
5607
|
+
}
|
|
5608
|
+
if (!mods || mods.size === 0) {
|
|
5609
|
+
const packageRoot = findNearestPackageRoot(file);
|
|
5610
|
+
if (packageRoot && getLinkedPackageRoots(config.root).some(
|
|
5611
|
+
(r) => packageRoot === r || packageRoot.startsWith(r + path14.sep)
|
|
5612
|
+
)) {
|
|
5613
|
+
const under = moduleGraph.getModulesWithFileUnder(packageRoot);
|
|
5614
|
+
if (under.size > 0) mods = under;
|
|
5615
|
+
}
|
|
5616
|
+
}
|
|
5383
5617
|
if (!mods || mods.size === 0) {
|
|
5384
5618
|
return null;
|
|
5385
5619
|
}
|
|
@@ -5394,7 +5628,7 @@ async function handleFileChange(file, server, environmentName = "client", timest
|
|
|
5394
5628
|
file,
|
|
5395
5629
|
timestamp,
|
|
5396
5630
|
modules: [mod],
|
|
5397
|
-
read: () =>
|
|
5631
|
+
read: () => fs11.readFileSync(file, "utf-8"),
|
|
5398
5632
|
server,
|
|
5399
5633
|
environment
|
|
5400
5634
|
};
|
|
@@ -5458,6 +5692,7 @@ async function handleFileChange(file, server, environmentName = "client", timest
|
|
|
5458
5692
|
var init_hmr = __esm({
|
|
5459
5693
|
"src/server/hmr.ts"() {
|
|
5460
5694
|
"use strict";
|
|
5695
|
+
init_fs_allow();
|
|
5461
5696
|
}
|
|
5462
5697
|
});
|
|
5463
5698
|
|
|
@@ -5467,9 +5702,9 @@ __export(runnable_environment_exports, {
|
|
|
5467
5702
|
NastiModuleRunner: () => NastiModuleRunner,
|
|
5468
5703
|
createModuleRunner: () => createModuleRunner
|
|
5469
5704
|
});
|
|
5470
|
-
import
|
|
5471
|
-
import
|
|
5472
|
-
import { builtinModules as builtinModules3, createRequire as
|
|
5705
|
+
import path15 from "path";
|
|
5706
|
+
import fs12 from "fs";
|
|
5707
|
+
import { builtinModules as builtinModules3, createRequire as createRequire5 } from "module";
|
|
5473
5708
|
import { pathToFileURL as pathToFileURL4 } from "url";
|
|
5474
5709
|
function createModuleRunner(environment) {
|
|
5475
5710
|
if (environment.consumer !== "server") {
|
|
@@ -5502,7 +5737,7 @@ var init_runnable_environment = __esm({
|
|
|
5502
5737
|
this.config.mode,
|
|
5503
5738
|
ssrDefineOverrides(environment.consumer)
|
|
5504
5739
|
);
|
|
5505
|
-
this.require =
|
|
5740
|
+
this.require = createRequire5(path15.join(this.config.root, "package.json"));
|
|
5506
5741
|
const handlers = {
|
|
5507
5742
|
fetchModule: async (id, importer) => this.fetchModule(id, importer),
|
|
5508
5743
|
getBuiltins: () => [/^node:/, ...builtinModules3]
|
|
@@ -5526,9 +5761,9 @@ var init_runnable_environment = __esm({
|
|
|
5526
5761
|
this.cache.clear();
|
|
5527
5762
|
}
|
|
5528
5763
|
resolveToId(rawUrl) {
|
|
5529
|
-
if (
|
|
5764
|
+
if (path15.isAbsolute(rawUrl) && fs12.existsSync(rawUrl.split("?")[0])) return rawUrl;
|
|
5530
5765
|
const clean = rawUrl.replace(/^\//, "");
|
|
5531
|
-
return
|
|
5766
|
+
return path15.resolve(this.config.root, clean);
|
|
5532
5767
|
}
|
|
5533
5768
|
/**
|
|
5534
5769
|
* fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
|
|
@@ -5537,14 +5772,14 @@ var init_runnable_environment = __esm({
|
|
|
5537
5772
|
*/
|
|
5538
5773
|
async fetchModule(id, importer) {
|
|
5539
5774
|
if (NODE_BUILTINS3.has(id)) return { externalize: id };
|
|
5540
|
-
if (!id.startsWith(".") && !
|
|
5775
|
+
if (!id.startsWith(".") && !path15.isAbsolute(id) && !id.startsWith("\0")) {
|
|
5541
5776
|
return { externalize: id };
|
|
5542
5777
|
}
|
|
5543
5778
|
const container = this.environment.pluginContainer;
|
|
5544
5779
|
let resolvedId = id;
|
|
5545
5780
|
if (id.startsWith(".") && importer) {
|
|
5546
5781
|
const resolved = await container.resolveId(id, importer);
|
|
5547
|
-
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id :
|
|
5782
|
+
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : path15.resolve(path15.dirname(importer.split("?")[0]), id);
|
|
5548
5783
|
}
|
|
5549
5784
|
resolvedId = this.completeExtension(resolvedId);
|
|
5550
5785
|
const cleanId = resolvedId.split("?")[0];
|
|
@@ -5552,8 +5787,8 @@ var init_runnable_environment = __esm({
|
|
|
5552
5787
|
const loaded = await container.load(resolvedId);
|
|
5553
5788
|
if (loaded != null) {
|
|
5554
5789
|
code = typeof loaded === "string" ? loaded : loaded.code;
|
|
5555
|
-
} else if (
|
|
5556
|
-
code =
|
|
5790
|
+
} else if (fs12.existsSync(cleanId)) {
|
|
5791
|
+
code = fs12.readFileSync(cleanId, "utf-8");
|
|
5557
5792
|
} else {
|
|
5558
5793
|
throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
|
|
5559
5794
|
}
|
|
@@ -5587,19 +5822,19 @@ var init_runnable_environment = __esm({
|
|
|
5587
5822
|
completeExtension(id) {
|
|
5588
5823
|
const clean = id.split("?")[0];
|
|
5589
5824
|
const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
|
|
5590
|
-
if (
|
|
5825
|
+
if (fs12.existsSync(clean) && fs12.statSync(clean).isFile()) return id;
|
|
5591
5826
|
const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
|
|
5592
5827
|
if (jsMatch) {
|
|
5593
5828
|
for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
|
|
5594
|
-
if (
|
|
5829
|
+
if (fs12.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
|
|
5595
5830
|
}
|
|
5596
5831
|
}
|
|
5597
5832
|
for (const ext of this.config.resolve.extensions) {
|
|
5598
|
-
if (
|
|
5833
|
+
if (fs12.existsSync(clean + ext)) return clean + ext + query;
|
|
5599
5834
|
}
|
|
5600
5835
|
for (const ext of this.config.resolve.extensions) {
|
|
5601
|
-
const indexPath =
|
|
5602
|
-
if (
|
|
5836
|
+
const indexPath = path15.join(clean, `index${ext}`);
|
|
5837
|
+
if (fs12.existsSync(indexPath)) return indexPath;
|
|
5603
5838
|
}
|
|
5604
5839
|
return id;
|
|
5605
5840
|
}
|
|
@@ -5626,10 +5861,10 @@ var init_runnable_environment = __esm({
|
|
|
5626
5861
|
return;
|
|
5627
5862
|
}
|
|
5628
5863
|
const ssrImport = async (dep) => {
|
|
5629
|
-
if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !
|
|
5864
|
+
if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !path15.isAbsolute(dep) && !dep.startsWith("\0")) {
|
|
5630
5865
|
return this.importExternal(dep);
|
|
5631
5866
|
}
|
|
5632
|
-
const depId = dep.startsWith(".") ? this.completeExtension(
|
|
5867
|
+
const depId = dep.startsWith(".") ? this.completeExtension(path15.resolve(path15.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
|
|
5633
5868
|
return this.instantiate(depId);
|
|
5634
5869
|
};
|
|
5635
5870
|
const ssrExportAll = (sourceModule) => {
|
|
@@ -5661,7 +5896,7 @@ var init_runnable_environment = __esm({
|
|
|
5661
5896
|
}
|
|
5662
5897
|
async importExternal(spec) {
|
|
5663
5898
|
try {
|
|
5664
|
-
return await (spec.startsWith("node:") || !
|
|
5899
|
+
return await (spec.startsWith("node:") || !path15.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import(pathToFileURL4(spec).href));
|
|
5665
5900
|
} catch (err) {
|
|
5666
5901
|
throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
|
|
5667
5902
|
}
|
|
@@ -5687,7 +5922,7 @@ var dev_engine_exports = {};
|
|
|
5687
5922
|
__export(dev_engine_exports, {
|
|
5688
5923
|
createBundledDevServer: () => createBundledDevServer
|
|
5689
5924
|
});
|
|
5690
|
-
import
|
|
5925
|
+
import path16 from "path";
|
|
5691
5926
|
import crypto3 from "crypto";
|
|
5692
5927
|
import { WebSocketServer as WsServer2 } from "ws";
|
|
5693
5928
|
import pc8 from "picocolors";
|
|
@@ -5772,7 +6007,7 @@ async function createBundledDevServer(opts) {
|
|
|
5772
6007
|
}
|
|
5773
6008
|
const url = `/${patchPath}`;
|
|
5774
6009
|
logger.info(
|
|
5775
|
-
pc8.green("hmr update ") + pc8.dim(changedFiles.map((f) =>
|
|
6010
|
+
pc8.green("hmr update ") + pc8.dim(changedFiles.map((f) => path16.relative(config.root, f)).join(", ")),
|
|
5776
6011
|
{ timestamp: true }
|
|
5777
6012
|
);
|
|
5778
6013
|
sendTo(clientId, { type: "hmr:update", path: url, url });
|
|
@@ -5927,7 +6162,7 @@ async function createBundledDevServer(opts) {
|
|
|
5927
6162
|
return;
|
|
5928
6163
|
}
|
|
5929
6164
|
res.setHeader("ETag", hit.etag);
|
|
5930
|
-
res.setHeader("Content-Type", MIME_TYPES[
|
|
6165
|
+
res.setHeader("Content-Type", MIME_TYPES[path16.extname(fileName)] ?? "application/octet-stream");
|
|
5931
6166
|
res.setHeader("Cache-Control", "no-cache");
|
|
5932
6167
|
res.once("finish", () => {
|
|
5933
6168
|
void engine.notifyPayloadDelivered(fileName).catch(
|
|
@@ -5968,7 +6203,7 @@ function stripCatchAllLoad(plugins) {
|
|
|
5968
6203
|
);
|
|
5969
6204
|
}
|
|
5970
6205
|
function createReactRefreshRuntimePlugin(entryPoints) {
|
|
5971
|
-
const entryIds = new Set(entryPoints.map((p) =>
|
|
6206
|
+
const entryIds = new Set(entryPoints.map((p) => path16.resolve(p)));
|
|
5972
6207
|
return {
|
|
5973
6208
|
name: "nasti:bundled-react-refresh",
|
|
5974
6209
|
resolveId(source) {
|
|
@@ -5986,7 +6221,7 @@ function createReactRefreshRuntimePlugin(entryPoints) {
|
|
|
5986
6221
|
return null;
|
|
5987
6222
|
},
|
|
5988
6223
|
transform(code, id) {
|
|
5989
|
-
if (!entryIds.has(
|
|
6224
|
+
if (!entryIds.has(path16.resolve(id.split("?")[0]))) return null;
|
|
5990
6225
|
return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
|
|
5991
6226
|
${code}`, map: null };
|
|
5992
6227
|
}
|
|
@@ -6157,7 +6392,7 @@ __export(server_exports, {
|
|
|
6157
6392
|
createServer: () => createServer
|
|
6158
6393
|
});
|
|
6159
6394
|
import http from "http";
|
|
6160
|
-
import
|
|
6395
|
+
import path17 from "path";
|
|
6161
6396
|
import os from "os";
|
|
6162
6397
|
import connect from "connect";
|
|
6163
6398
|
import sirv from "sirv";
|
|
@@ -6250,20 +6485,39 @@ async function createServer(inlineConfig = {}) {
|
|
|
6250
6485
|
app.use(bundledServer.middleware);
|
|
6251
6486
|
}
|
|
6252
6487
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
6253
|
-
const outDirAbs =
|
|
6254
|
-
const
|
|
6488
|
+
const outDirAbs = path17.resolve(config.root, config.build.outDir);
|
|
6489
|
+
const linkedPackageRoots = getLinkedPackageRoots(config.root).filter(
|
|
6490
|
+
(r) => r !== config.root && !isUnderRoot(config.root, r)
|
|
6491
|
+
);
|
|
6492
|
+
const watchTargets = [config.root, ...linkedPackageRoots];
|
|
6493
|
+
const watcher = watch(watchTargets, {
|
|
6255
6494
|
ignored: (filePath) => {
|
|
6256
|
-
if (filePath ===
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6495
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path17.sep)) return true;
|
|
6496
|
+
for (const watchRoot of watchTargets) {
|
|
6497
|
+
if (filePath === watchRoot) return false;
|
|
6498
|
+
const rel = path17.relative(watchRoot, filePath);
|
|
6499
|
+
if (!rel || rel.startsWith("..") || path17.isAbsolute(rel)) continue;
|
|
6500
|
+
for (const seg of rel.split(path17.sep)) {
|
|
6501
|
+
if (ignoredSegments.has(seg)) return true;
|
|
6502
|
+
}
|
|
6503
|
+
return false;
|
|
6262
6504
|
}
|
|
6263
6505
|
return false;
|
|
6264
6506
|
},
|
|
6265
6507
|
ignoreInitial: true
|
|
6266
6508
|
});
|
|
6509
|
+
await new Promise((resolve, reject) => {
|
|
6510
|
+
const onReady = () => {
|
|
6511
|
+
watcher.off("error", onError);
|
|
6512
|
+
resolve();
|
|
6513
|
+
};
|
|
6514
|
+
const onError = (err) => {
|
|
6515
|
+
watcher.off("ready", onReady);
|
|
6516
|
+
reject(err);
|
|
6517
|
+
};
|
|
6518
|
+
watcher.once("ready", onReady);
|
|
6519
|
+
watcher.once("error", onError);
|
|
6520
|
+
});
|
|
6267
6521
|
let server;
|
|
6268
6522
|
const environmentServices = {};
|
|
6269
6523
|
let environmentDriversStarted = false;
|
|
@@ -6375,16 +6629,25 @@ async function createServer(inlineConfig = {}) {
|
|
|
6375
6629
|
});
|
|
6376
6630
|
};
|
|
6377
6631
|
watcher.on("change", (file) => {
|
|
6632
|
+
if (file.includes(`${path17.sep}node_modules${path17.sep}`) || file.endsWith(`${path17.sep}node_modules`)) {
|
|
6633
|
+
clearLinkedPackageRootsCache();
|
|
6634
|
+
}
|
|
6378
6635
|
ssrRunner?.invalidateFile(file);
|
|
6379
6636
|
queueClientEnvironmentUpdate(file);
|
|
6380
6637
|
notifyEnvironmentDrivers(file, "change");
|
|
6381
6638
|
});
|
|
6382
6639
|
watcher.on("add", (file) => {
|
|
6640
|
+
if (file.includes(`${path17.sep}node_modules${path17.sep}`) || file.endsWith(`${path17.sep}node_modules`)) {
|
|
6641
|
+
clearLinkedPackageRootsCache();
|
|
6642
|
+
}
|
|
6383
6643
|
ssrRunner?.invalidateFile(file);
|
|
6384
6644
|
queueClientEnvironmentUpdate(file);
|
|
6385
6645
|
notifyEnvironmentDrivers(file, "add");
|
|
6386
6646
|
});
|
|
6387
6647
|
watcher.on("unlink", (file) => {
|
|
6648
|
+
if (file.includes(`${path17.sep}node_modules${path17.sep}`) || file.endsWith(`${path17.sep}node_modules`)) {
|
|
6649
|
+
clearLinkedPackageRootsCache();
|
|
6650
|
+
}
|
|
6388
6651
|
ssrRunner?.invalidateFile(file);
|
|
6389
6652
|
notifyEnvironmentDrivers(file, "unlink");
|
|
6390
6653
|
});
|
|
@@ -6414,7 +6677,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6414
6677
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
6415
6678
|
logger.info(
|
|
6416
6679
|
`
|
|
6417
|
-
${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.4.
|
|
6680
|
+
${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.4.4"}`)} ${pc9.dim("ready in")} ${pc9.bold(readyIn)} ${pc9.dim("ms")}
|
|
6418
6681
|
`
|
|
6419
6682
|
);
|
|
6420
6683
|
printServerUrls(
|
|
@@ -6511,7 +6774,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6511
6774
|
throw error;
|
|
6512
6775
|
}
|
|
6513
6776
|
app.use(transformMiddleware(transformContexts.get("client")));
|
|
6514
|
-
const publicDir =
|
|
6777
|
+
const publicDir = path17.resolve(config.root, "public");
|
|
6515
6778
|
app.use(sirv(publicDir, { dev: true, etag: true }));
|
|
6516
6779
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
6517
6780
|
const postMiddlewares = [];
|
|
@@ -6550,6 +6813,7 @@ var init_server = __esm({
|
|
|
6550
6813
|
init_builtins();
|
|
6551
6814
|
init_plugin_api();
|
|
6552
6815
|
init_env();
|
|
6816
|
+
init_fs_allow();
|
|
6553
6817
|
}
|
|
6554
6818
|
});
|
|
6555
6819
|
|
|
@@ -6562,6 +6826,7 @@ init_config();
|
|
|
6562
6826
|
init_resolve();
|
|
6563
6827
|
import path11 from "path";
|
|
6564
6828
|
import fs8 from "fs";
|
|
6829
|
+
import { createRequire as createRequire3 } from "module";
|
|
6565
6830
|
import { rolldown as rolldown2 } from "rolldown";
|
|
6566
6831
|
import pc5 from "picocolors";
|
|
6567
6832
|
|
|
@@ -6605,7 +6870,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
6605
6870
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
6606
6871
|
const startTime = performance.now();
|
|
6607
6872
|
assertElectronVersion(config);
|
|
6608
|
-
console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.4.
|
|
6873
|
+
console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.4.4"}`));
|
|
6609
6874
|
console.log(pc5.dim(` root: ${config.root}`));
|
|
6610
6875
|
console.log(pc5.dim(` mode: ${config.mode}`));
|
|
6611
6876
|
console.log(pc5.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -6749,13 +7014,21 @@ function assertElectronVersion(config) {
|
|
|
6749
7014
|
}
|
|
6750
7015
|
function detectInstalledElectron(root) {
|
|
6751
7016
|
try {
|
|
6752
|
-
const
|
|
6753
|
-
|
|
7017
|
+
const require2 = createRequire3(path11.resolve(root, "package.json"));
|
|
7018
|
+
const pkgPath = require2.resolve("electron/package.json");
|
|
6754
7019
|
const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf-8"));
|
|
6755
7020
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
6756
7021
|
return Number.isFinite(major) ? major : null;
|
|
6757
7022
|
} catch {
|
|
6758
|
-
|
|
7023
|
+
try {
|
|
7024
|
+
const pkgPath = path11.resolve(root, "node_modules/electron/package.json");
|
|
7025
|
+
if (!fs8.existsSync(pkgPath)) return null;
|
|
7026
|
+
const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf-8"));
|
|
7027
|
+
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
7028
|
+
return Number.isFinite(major) ? major : null;
|
|
7029
|
+
} catch {
|
|
7030
|
+
return null;
|
|
7031
|
+
}
|
|
6759
7032
|
}
|
|
6760
7033
|
}
|
|
6761
7034
|
|
|
@@ -6764,9 +7037,9 @@ init_server();
|
|
|
6764
7037
|
|
|
6765
7038
|
// src/server/electron-dev.ts
|
|
6766
7039
|
init_config();
|
|
6767
|
-
import
|
|
6768
|
-
import
|
|
6769
|
-
import { createRequire as
|
|
7040
|
+
import path18 from "path";
|
|
7041
|
+
import fs13 from "fs";
|
|
7042
|
+
import { createRequire as createRequire6 } from "module";
|
|
6770
7043
|
import { spawn } from "child_process";
|
|
6771
7044
|
import chokidar from "chokidar";
|
|
6772
7045
|
import pc10 from "picocolors";
|
|
@@ -6778,7 +7051,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
6778
7051
|
const { noSpawn, ...rest } = inlineConfig;
|
|
6779
7052
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
6780
7053
|
warnElectronVersion(config);
|
|
6781
|
-
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.4.
|
|
7054
|
+
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.4.4"}`));
|
|
6782
7055
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
6783
7056
|
const server = await createServer2({
|
|
6784
7057
|
...rest,
|
|
@@ -6788,11 +7061,11 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
6788
7061
|
await server.listen();
|
|
6789
7062
|
const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
|
|
6790
7063
|
console.log(pc10.dim(` renderer: ${devUrl}`));
|
|
6791
|
-
const stageDir =
|
|
6792
|
-
|
|
6793
|
-
const mainEntry =
|
|
7064
|
+
const stageDir = path18.resolve(config.root, ".nasti");
|
|
7065
|
+
fs13.mkdirSync(stageDir, { recursive: true });
|
|
7066
|
+
const mainEntry = path18.resolve(config.root, config.electron.main);
|
|
6794
7067
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
6795
|
-
const builtMainFile =
|
|
7068
|
+
const builtMainFile = path18.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
6796
7069
|
const builtPreloadFiles = [];
|
|
6797
7070
|
const compileAll = async () => {
|
|
6798
7071
|
await compileNode(config, mainEntry, {
|
|
@@ -6802,9 +7075,9 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
6802
7075
|
});
|
|
6803
7076
|
builtPreloadFiles.length = 0;
|
|
6804
7077
|
for (const entry of preloadEntries) {
|
|
6805
|
-
if (!
|
|
6806
|
-
const base =
|
|
6807
|
-
const out =
|
|
7078
|
+
if (!fs13.existsSync(entry)) continue;
|
|
7079
|
+
const base = path18.basename(entry).replace(/\.[^.]+$/, "");
|
|
7080
|
+
const out = path18.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
6808
7081
|
await compileNode(config, entry, {
|
|
6809
7082
|
outFile: out,
|
|
6810
7083
|
format: config.electron.preloadFormat,
|
|
@@ -6843,7 +7116,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
6843
7116
|
};
|
|
6844
7117
|
spawnElectron();
|
|
6845
7118
|
if (config.electron.autoRestart) {
|
|
6846
|
-
const watchTargets = [mainEntry, ...preloadEntries].filter(
|
|
7119
|
+
const watchTargets = [mainEntry, ...preloadEntries].filter(fs13.existsSync);
|
|
6847
7120
|
const watcher = chokidar.watch(watchTargets, { ignoreInitial: true });
|
|
6848
7121
|
let restarting = null;
|
|
6849
7122
|
let pending = false;
|
|
@@ -6923,7 +7196,7 @@ async function compileNode(config, entry, opts) {
|
|
|
6923
7196
|
platform: "node",
|
|
6924
7197
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
6925
7198
|
});
|
|
6926
|
-
|
|
7199
|
+
fs13.mkdirSync(path18.dirname(opts.outFile), { recursive: true });
|
|
6927
7200
|
await bundle2.write({
|
|
6928
7201
|
file: opts.outFile,
|
|
6929
7202
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -6936,18 +7209,18 @@ async function compileNode(config, entry, opts) {
|
|
|
6936
7209
|
await bundle2.close();
|
|
6937
7210
|
}
|
|
6938
7211
|
function electronRendererDevPath(renderer) {
|
|
6939
|
-
const normalized = renderer.split(
|
|
7212
|
+
const normalized = renderer.split(path18.sep).join("/").replace(/^\.?\//, "");
|
|
6940
7213
|
return normalized === "index.html" ? "/" : `/${normalized}`;
|
|
6941
7214
|
}
|
|
6942
7215
|
function resolveElectronBinary(config) {
|
|
6943
|
-
if (config.electron.electronPath &&
|
|
7216
|
+
if (config.electron.electronPath && fs13.existsSync(config.electron.electronPath)) {
|
|
6944
7217
|
return config.electron.electronPath;
|
|
6945
7218
|
}
|
|
6946
7219
|
try {
|
|
6947
|
-
const require2 =
|
|
7220
|
+
const require2 = createRequire6(path18.resolve(config.root, "package.json"));
|
|
6948
7221
|
const pathFile = require2.resolve("electron");
|
|
6949
7222
|
const electronModule = require2(pathFile);
|
|
6950
|
-
if (typeof electronModule === "string" &&
|
|
7223
|
+
if (typeof electronModule === "string" && fs13.existsSync(electronModule)) {
|
|
6951
7224
|
return electronModule;
|
|
6952
7225
|
}
|
|
6953
7226
|
} catch {
|
|
@@ -6974,10 +7247,10 @@ function warnElectronVersion(config) {
|
|
|
6974
7247
|
}
|
|
6975
7248
|
|
|
6976
7249
|
// src/plugins/monaco-editor.ts
|
|
6977
|
-
import
|
|
6978
|
-
import
|
|
7250
|
+
import path19 from "path";
|
|
7251
|
+
import fs14 from "fs";
|
|
6979
7252
|
import crypto4 from "crypto";
|
|
6980
|
-
import { createRequire as
|
|
7253
|
+
import { createRequire as createRequire7 } from "module";
|
|
6981
7254
|
var DEFAULT_WORKERS = {
|
|
6982
7255
|
editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
|
|
6983
7256
|
css: "monaco-editor/esm/vs/language/css/css.worker",
|
|
@@ -6996,9 +7269,9 @@ function normalizePublicPath(p) {
|
|
|
6996
7269
|
}
|
|
6997
7270
|
function readMonacoVersion(root) {
|
|
6998
7271
|
try {
|
|
6999
|
-
const require2 =
|
|
7272
|
+
const require2 = createRequire7(path19.resolve(root, "package.json"));
|
|
7000
7273
|
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
7001
|
-
const pkg = JSON.parse(
|
|
7274
|
+
const pkg = JSON.parse(fs14.readFileSync(pkgJsonPath, "utf-8"));
|
|
7002
7275
|
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
7003
7276
|
} catch {
|
|
7004
7277
|
return "unknown";
|
|
@@ -7018,20 +7291,20 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7018
7291
|
let cacheDir = "";
|
|
7019
7292
|
const building = /* @__PURE__ */ new Map();
|
|
7020
7293
|
async function buildWorker(worker) {
|
|
7021
|
-
const cacheFile =
|
|
7022
|
-
if (
|
|
7294
|
+
const cacheFile = path19.join(cacheDir, `${worker.label}.worker.js`);
|
|
7295
|
+
if (fs14.existsSync(cacheFile)) return cacheFile;
|
|
7023
7296
|
const existing = building.get(worker.label);
|
|
7024
7297
|
if (existing) return existing;
|
|
7025
7298
|
const task = (async () => {
|
|
7026
7299
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
7027
|
-
const require2 =
|
|
7300
|
+
const require2 = createRequire7(path19.resolve(resolvedConfig.root, "package.json"));
|
|
7028
7301
|
let entry;
|
|
7029
7302
|
try {
|
|
7030
7303
|
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
7031
7304
|
} catch {
|
|
7032
7305
|
entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
|
|
7033
7306
|
}
|
|
7034
|
-
|
|
7307
|
+
fs14.mkdirSync(cacheDir, { recursive: true });
|
|
7035
7308
|
const bundle2 = await rolldown4({
|
|
7036
7309
|
input: entry,
|
|
7037
7310
|
platform: "browser"
|
|
@@ -7091,16 +7364,23 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7091
7364
|
resolvedConfig = config;
|
|
7092
7365
|
const version = readMonacoVersion(config.root);
|
|
7093
7366
|
const key = crypto4.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
7094
|
-
cacheDir =
|
|
7367
|
+
cacheDir = path19.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
7095
7368
|
},
|
|
7096
7369
|
async configureServer(server) {
|
|
7097
7370
|
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
7098
7371
|
const watcher = server.watcher;
|
|
7099
|
-
const
|
|
7372
|
+
const monacoLogical = path19.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
7373
|
+
const monacoPaths = /* @__PURE__ */ new Set([monacoLogical]);
|
|
7100
7374
|
try {
|
|
7101
|
-
|
|
7375
|
+
monacoPaths.add(fs14.realpathSync(monacoLogical));
|
|
7102
7376
|
} catch {
|
|
7103
7377
|
}
|
|
7378
|
+
for (const monacoDir of monacoPaths) {
|
|
7379
|
+
try {
|
|
7380
|
+
watcher?.unwatch?.(monacoDir);
|
|
7381
|
+
} catch {
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7104
7384
|
if (!shouldBuild) return;
|
|
7105
7385
|
void Promise.all(
|
|
7106
7386
|
workers.map(
|
|
@@ -7126,7 +7406,7 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7126
7406
|
const file = await buildWorker(worker);
|
|
7127
7407
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
7128
7408
|
res.setHeader("Cache-Control", "public, max-age=604800, immutable");
|
|
7129
|
-
|
|
7409
|
+
fs14.createReadStream(file).pipe(res);
|
|
7130
7410
|
} catch (e) {
|
|
7131
7411
|
res.statusCode = 500;
|
|
7132
7412
|
res.end(`Monaco worker build failed: ${e.message}`);
|
|
@@ -7161,16 +7441,16 @@ self.monaco = monaco;`,
|
|
|
7161
7441
|
resolvedConfig.root,
|
|
7162
7442
|
resolvedConfig.build.outDir,
|
|
7163
7443
|
resolvedConfig.base
|
|
7164
|
-
) : isCDN(publicPath) ?
|
|
7444
|
+
) : isCDN(publicPath) ? path19.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : path19.resolve(
|
|
7165
7445
|
resolvedConfig.root,
|
|
7166
7446
|
resolvedConfig.build.outDir,
|
|
7167
7447
|
publicPath.replace(/^\//, "")
|
|
7168
7448
|
);
|
|
7169
|
-
|
|
7449
|
+
fs14.mkdirSync(outDir, { recursive: true });
|
|
7170
7450
|
for (const worker of workers) {
|
|
7171
7451
|
try {
|
|
7172
7452
|
const cacheFile = await buildWorker(worker);
|
|
7173
|
-
|
|
7453
|
+
fs14.copyFileSync(cacheFile, path19.join(outDir, `${worker.label}.worker.js`));
|
|
7174
7454
|
} catch (e) {
|
|
7175
7455
|
throw new Error(
|
|
7176
7456
|
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|