@nasti-toolchain/nasti 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -1
- package/bin/nasti.js +0 -0
- package/client/hmr.ts +4 -3
- package/dist/cli.cjs +957 -269
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +951 -264
- package/dist/cli.js.map +1 -1
- package/dist/client/hmr.cjs.map +1 -1
- package/dist/client/hmr.d.cts +4 -3
- package/dist/client/hmr.d.ts +4 -3
- package/dist/index.cjs +1054 -366
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -8
- package/dist/index.d.ts +64 -8
- package/dist/index.js +1048 -361
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,10 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __glob = (map) => (
|
|
9
|
-
var fn = map[
|
|
8
|
+
var __glob = (map) => (path19) => {
|
|
9
|
+
var fn = map[path19];
|
|
10
10
|
if (fn) return fn();
|
|
11
|
-
throw new Error("Module not found in bundle: " +
|
|
11
|
+
throw new Error("Module not found in bundle: " + path19);
|
|
12
12
|
};
|
|
13
13
|
var __esm = (fn, res) => function __init() {
|
|
14
14
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
@@ -474,6 +474,7 @@ async function resolveConfig(inlineConfig = {}, command) {
|
|
|
474
474
|
if (envOptions.build) Object.assign(resolved.build, envOptions.build);
|
|
475
475
|
resolved.environments.client = {
|
|
476
476
|
consumer,
|
|
477
|
+
buildEnabled: envOptions.buildEnabled ?? true,
|
|
477
478
|
entry: normalizeEnvironmentEntries(envOptions.entry, root),
|
|
478
479
|
html: import_node_path.default.resolve(
|
|
479
480
|
root,
|
|
@@ -488,6 +489,7 @@ async function resolveConfig(inlineConfig = {}, command) {
|
|
|
488
489
|
}
|
|
489
490
|
resolved.environments[name] = {
|
|
490
491
|
consumer,
|
|
492
|
+
buildEnabled: envOptions.buildEnabled ?? true,
|
|
491
493
|
entry: normalizeEnvironmentEntries(envOptions.entry, root),
|
|
492
494
|
html: envOptions.consumer === "client" && envOptions.html ? import_node_path.default.resolve(root, envOptions.html) : void 0,
|
|
493
495
|
driver: envOptions.driver,
|
|
@@ -714,6 +716,7 @@ function resolvePlugin(config) {
|
|
|
714
716
|
}
|
|
715
717
|
if (!source.startsWith("/") && !source.startsWith(".")) {
|
|
716
718
|
if (vueRuntimeEntry && source === "vue") return vueRuntimeEntry;
|
|
719
|
+
if (config.command === "build") return null;
|
|
717
720
|
try {
|
|
718
721
|
const resolved = require2.resolve(source, {
|
|
719
722
|
paths: [importer ? import_node_path2.default.dirname(importer) : config.root]
|
|
@@ -849,27 +852,27 @@ var require_process = __commonJS({
|
|
|
849
852
|
var require_filesystem = __commonJS({
|
|
850
853
|
"node_modules/detect-libc/lib/filesystem.js"(exports2, module2) {
|
|
851
854
|
"use strict";
|
|
852
|
-
var
|
|
855
|
+
var fs14 = require("fs");
|
|
853
856
|
var LDD_PATH = "/usr/bin/ldd";
|
|
854
857
|
var SELF_PATH = "/proc/self/exe";
|
|
855
858
|
var MAX_LENGTH = 2048;
|
|
856
|
-
var readFileSync = (
|
|
857
|
-
const fd =
|
|
859
|
+
var readFileSync = (path19) => {
|
|
860
|
+
const fd = fs14.openSync(path19, "r");
|
|
858
861
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
859
|
-
const bytesRead =
|
|
860
|
-
|
|
862
|
+
const bytesRead = fs14.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
863
|
+
fs14.close(fd, () => {
|
|
861
864
|
});
|
|
862
865
|
return buffer.subarray(0, bytesRead);
|
|
863
866
|
};
|
|
864
|
-
var readFile = (
|
|
865
|
-
|
|
867
|
+
var readFile = (path19) => new Promise((resolve, reject) => {
|
|
868
|
+
fs14.open(path19, "r", (err, fd) => {
|
|
866
869
|
if (err) {
|
|
867
870
|
reject(err);
|
|
868
871
|
} else {
|
|
869
872
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
870
|
-
|
|
873
|
+
fs14.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
|
|
871
874
|
resolve(buffer.subarray(0, bytesRead));
|
|
872
|
-
|
|
875
|
+
fs14.close(fd, () => {
|
|
873
876
|
});
|
|
874
877
|
});
|
|
875
878
|
}
|
|
@@ -981,11 +984,11 @@ var require_detect_libc = __commonJS({
|
|
|
981
984
|
}
|
|
982
985
|
return null;
|
|
983
986
|
};
|
|
984
|
-
var familyFromInterpreterPath = (
|
|
985
|
-
if (
|
|
986
|
-
if (
|
|
987
|
+
var familyFromInterpreterPath = (path19) => {
|
|
988
|
+
if (path19) {
|
|
989
|
+
if (path19.includes("/ld-musl-")) {
|
|
987
990
|
return MUSL;
|
|
988
|
-
} else if (
|
|
991
|
+
} else if (path19.includes("/ld-linux-")) {
|
|
989
992
|
return GLIBC;
|
|
990
993
|
}
|
|
991
994
|
}
|
|
@@ -1032,8 +1035,8 @@ var require_detect_libc = __commonJS({
|
|
|
1032
1035
|
cachedFamilyInterpreter = null;
|
|
1033
1036
|
try {
|
|
1034
1037
|
const selfContent = await readFile(SELF_PATH);
|
|
1035
|
-
const
|
|
1036
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1038
|
+
const path19 = interpreterPath(selfContent);
|
|
1039
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path19);
|
|
1037
1040
|
} catch (e) {
|
|
1038
1041
|
}
|
|
1039
1042
|
return cachedFamilyInterpreter;
|
|
@@ -1045,8 +1048,8 @@ var require_detect_libc = __commonJS({
|
|
|
1045
1048
|
cachedFamilyInterpreter = null;
|
|
1046
1049
|
try {
|
|
1047
1050
|
const selfContent = readFileSync(SELF_PATH);
|
|
1048
|
-
const
|
|
1049
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1051
|
+
const path19 = interpreterPath(selfContent);
|
|
1052
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path19);
|
|
1050
1053
|
} catch (e) {
|
|
1051
1054
|
}
|
|
1052
1055
|
return cachedFamilyInterpreter;
|
|
@@ -2110,8 +2113,8 @@ function vuePlugin(config) {
|
|
|
2110
2113
|
let descriptor = descriptorCache.get(filePath);
|
|
2111
2114
|
if (!descriptor) {
|
|
2112
2115
|
try {
|
|
2113
|
-
const
|
|
2114
|
-
const source =
|
|
2116
|
+
const fs14 = await import("fs");
|
|
2117
|
+
const source = fs14.readFileSync(filePath, "utf-8");
|
|
2115
2118
|
const parsed = sfc.parse(source, { filename: filePath });
|
|
2116
2119
|
if (parsed.errors.length) return null;
|
|
2117
2120
|
descriptor = parsed.descriptor;
|
|
@@ -2333,16 +2336,27 @@ window.__vite_plugin_react_preamble_installed__ = true;
|
|
|
2333
2336
|
// src/plugins/builtins.ts
|
|
2334
2337
|
function resolvePluginList(config, userPlugins, opts = {}) {
|
|
2335
2338
|
const isServe = config.command === "serve";
|
|
2339
|
+
let environmentOptions;
|
|
2340
|
+
if (opts.environmentName) {
|
|
2341
|
+
environmentOptions = config.environments[opts.environmentName];
|
|
2342
|
+
if (!environmentOptions) {
|
|
2343
|
+
throw new Error(
|
|
2344
|
+
`[nasti] unknown environment "${opts.environmentName}" \u2014 declare it in config.environments`
|
|
2345
|
+
);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
const pluginConfig = environmentOptions ? { ...config, resolve: environmentOptions.resolve, build: environmentOptions.build } : config;
|
|
2349
|
+
const consumer = opts.consumer ?? environmentOptions?.consumer;
|
|
2336
2350
|
return [
|
|
2337
2351
|
// vuePlugin 排最前(enforce: 'pre' 语义):.vue 先编译成 JS 再走后续管道
|
|
2338
|
-
...config.framework === "vue" ? [vuePlugin(
|
|
2339
|
-
resolvePlugin(
|
|
2340
|
-
cssPlugin(
|
|
2341
|
-
assetsPlugin(
|
|
2342
|
-
...isServe ? [htmlPlugin(
|
|
2352
|
+
...config.framework === "vue" ? [vuePlugin(pluginConfig)] : [],
|
|
2353
|
+
resolvePlugin(pluginConfig),
|
|
2354
|
+
cssPlugin(pluginConfig, opts.cssEngine, consumer),
|
|
2355
|
+
assetsPlugin(pluginConfig),
|
|
2356
|
+
...isServe ? [htmlPlugin(pluginConfig)] : [],
|
|
2343
2357
|
...userPlugins,
|
|
2344
2358
|
// cssPostPlugin 最后(enforce: 'post' 语义):renderChunk 聚合抽取
|
|
2345
|
-
...!isServe && opts.cssEngine ? [cssPostPlugin(
|
|
2359
|
+
...!isServe && opts.cssEngine ? [cssPostPlugin(pluginConfig, opts.cssEngine)] : []
|
|
2346
2360
|
];
|
|
2347
2361
|
}
|
|
2348
2362
|
var init_builtins = __esm({
|
|
@@ -2472,17 +2486,35 @@ var init_plugin_container = __esm({
|
|
|
2472
2486
|
}
|
|
2473
2487
|
});
|
|
2474
2488
|
|
|
2489
|
+
// src/core/url.ts
|
|
2490
|
+
function removeTimestampQuery(url) {
|
|
2491
|
+
const hashIndex = url.indexOf("#");
|
|
2492
|
+
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
2493
|
+
const withoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
2494
|
+
const queryIndex = withoutHash.indexOf("?");
|
|
2495
|
+
if (queryIndex < 0) return url;
|
|
2496
|
+
const pathname = withoutHash.slice(0, queryIndex);
|
|
2497
|
+
const query = withoutHash.slice(queryIndex + 1).split("&").filter((part) => !/^t=\d+$/.test(part)).join("&");
|
|
2498
|
+
return pathname + (query ? `?${query}` : "") + hash;
|
|
2499
|
+
}
|
|
2500
|
+
var init_url = __esm({
|
|
2501
|
+
"src/core/url.ts"() {
|
|
2502
|
+
"use strict";
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
|
|
2475
2506
|
// src/core/module-graph.ts
|
|
2476
2507
|
var ModuleGraph;
|
|
2477
2508
|
var init_module_graph = __esm({
|
|
2478
2509
|
"src/core/module-graph.ts"() {
|
|
2479
2510
|
"use strict";
|
|
2511
|
+
init_url();
|
|
2480
2512
|
ModuleGraph = class {
|
|
2481
2513
|
urlToModuleMap = /* @__PURE__ */ new Map();
|
|
2482
2514
|
idToModuleMap = /* @__PURE__ */ new Map();
|
|
2483
2515
|
fileToModulesMap = /* @__PURE__ */ new Map();
|
|
2484
2516
|
getModuleByUrl(url) {
|
|
2485
|
-
return this.urlToModuleMap.get(url);
|
|
2517
|
+
return this.urlToModuleMap.get(removeTimestampQuery(url));
|
|
2486
2518
|
}
|
|
2487
2519
|
getModuleById(id) {
|
|
2488
2520
|
return this.idToModuleMap.get(id);
|
|
@@ -2491,10 +2523,11 @@ var init_module_graph = __esm({
|
|
|
2491
2523
|
return this.fileToModulesMap.get(file);
|
|
2492
2524
|
}
|
|
2493
2525
|
async ensureEntryFromUrl(url) {
|
|
2494
|
-
|
|
2526
|
+
const normalizedUrl = removeTimestampQuery(url);
|
|
2527
|
+
let mod = this.urlToModuleMap.get(normalizedUrl);
|
|
2495
2528
|
if (mod) return mod;
|
|
2496
|
-
mod = this.createModule(
|
|
2497
|
-
this.urlToModuleMap.set(
|
|
2529
|
+
mod = this.createModule(normalizedUrl);
|
|
2530
|
+
this.urlToModuleMap.set(normalizedUrl, mod);
|
|
2498
2531
|
return mod;
|
|
2499
2532
|
}
|
|
2500
2533
|
createModule(url, id) {
|
|
@@ -2508,6 +2541,7 @@ var init_module_graph = __esm({
|
|
|
2508
2541
|
acceptedHmrDeps: /* @__PURE__ */ new Set(),
|
|
2509
2542
|
transformResult: null,
|
|
2510
2543
|
lastHMRTimestamp: 0,
|
|
2544
|
+
invalidationVersion: 0,
|
|
2511
2545
|
isSelfAccepting: false
|
|
2512
2546
|
};
|
|
2513
2547
|
this.idToModuleMap.set(mod.id, mod);
|
|
@@ -2550,10 +2584,64 @@ var init_module_graph = __esm({
|
|
|
2550
2584
|
}
|
|
2551
2585
|
}
|
|
2552
2586
|
}
|
|
2587
|
+
/**
|
|
2588
|
+
* 用一次转换得到的信息原子更新 import 与 HMR accept 关系。
|
|
2589
|
+
* 依赖节点会在真正被浏览器请求前预先创建,这样入口模块先转换时也能建立完整图。
|
|
2590
|
+
*/
|
|
2591
|
+
async updateModuleInfo(mod, importedUrls, acceptedUrls, isSelfAccepting, expectedInvalidationVersion) {
|
|
2592
|
+
const importedModules = await Promise.all(
|
|
2593
|
+
[...importedUrls].map((url) => this.ensureEntryFromUrl(url))
|
|
2594
|
+
);
|
|
2595
|
+
const acceptedModules = await Promise.all(
|
|
2596
|
+
[...acceptedUrls].map((url) => this.ensureEntryFromUrl(url))
|
|
2597
|
+
);
|
|
2598
|
+
if (expectedInvalidationVersion !== void 0 && mod.invalidationVersion !== expectedInvalidationVersion) {
|
|
2599
|
+
return null;
|
|
2600
|
+
}
|
|
2601
|
+
const previousImports = new Set(mod.importedModules);
|
|
2602
|
+
for (const imported of previousImports) {
|
|
2603
|
+
imported.importers.delete(mod);
|
|
2604
|
+
}
|
|
2605
|
+
mod.importedModules.clear();
|
|
2606
|
+
mod.acceptedHmrDeps.clear();
|
|
2607
|
+
for (const imported of importedModules) {
|
|
2608
|
+
mod.importedModules.add(imported);
|
|
2609
|
+
imported.importers.add(mod);
|
|
2610
|
+
}
|
|
2611
|
+
for (const accepted of acceptedModules) {
|
|
2612
|
+
mod.acceptedHmrDeps.add(accepted);
|
|
2613
|
+
}
|
|
2614
|
+
mod.isSelfAccepting = isSelfAccepting;
|
|
2615
|
+
const pruned = /* @__PURE__ */ new Set();
|
|
2616
|
+
for (const imported of previousImports) {
|
|
2617
|
+
if (!mod.importedModules.has(imported) && imported.importers.size === 0) {
|
|
2618
|
+
pruned.add(imported);
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
return pruned;
|
|
2622
|
+
}
|
|
2553
2623
|
/** 使模块的转换缓存失效 */
|
|
2554
|
-
invalidateModule(mod) {
|
|
2624
|
+
invalidateModule(mod, timestamp = Date.now()) {
|
|
2555
2625
|
mod.transformResult = null;
|
|
2556
|
-
mod.lastHMRTimestamp =
|
|
2626
|
+
mod.lastHMRTimestamp = timestamp;
|
|
2627
|
+
mod.invalidationVersion++;
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* 仅失效到 HMR 边界:显式接受依赖的模块本身不会重执行;自接受模块需要失效,
|
|
2631
|
+
* 但不再继续影响其 importer。这样既能传播依赖时间戳,也不会隐式重复副作用。
|
|
2632
|
+
*/
|
|
2633
|
+
invalidateModuleAndImporters(mod, timestamp = Date.now(), seen = /* @__PURE__ */ new Set()) {
|
|
2634
|
+
if (seen.has(mod)) return;
|
|
2635
|
+
seen.add(mod);
|
|
2636
|
+
this.invalidateModule(mod, timestamp);
|
|
2637
|
+
for (const importer of mod.importers) {
|
|
2638
|
+
if (importer.acceptedHmrDeps.has(mod)) continue;
|
|
2639
|
+
if (importer.isSelfAccepting) {
|
|
2640
|
+
this.invalidateModule(importer, timestamp);
|
|
2641
|
+
continue;
|
|
2642
|
+
}
|
|
2643
|
+
this.invalidateModuleAndImporters(importer, timestamp, seen);
|
|
2644
|
+
}
|
|
2557
2645
|
}
|
|
2558
2646
|
/** 使所有模块缓存失效 */
|
|
2559
2647
|
invalidateAll() {
|
|
@@ -2564,34 +2652,32 @@ var init_module_graph = __esm({
|
|
|
2564
2652
|
/** 获取 HMR 传播边界 - 从变更模块向上遍历找到接受更新的边界 */
|
|
2565
2653
|
getHmrBoundaries(mod) {
|
|
2566
2654
|
const boundaries = [];
|
|
2567
|
-
const
|
|
2568
|
-
const
|
|
2569
|
-
if (
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
boundaries.push({ boundary
|
|
2573
|
-
return true;
|
|
2655
|
+
const traversed = /* @__PURE__ */ new Set();
|
|
2656
|
+
const addBoundary = (boundary, acceptedVia) => {
|
|
2657
|
+
if (!boundaries.some(
|
|
2658
|
+
(item) => item.boundary === boundary && item.acceptedVia === acceptedVia
|
|
2659
|
+
)) {
|
|
2660
|
+
boundaries.push({ boundary, acceptedVia });
|
|
2574
2661
|
}
|
|
2575
|
-
|
|
2576
|
-
|
|
2662
|
+
};
|
|
2663
|
+
const propagate = (node) => {
|
|
2664
|
+
if (traversed.has(node)) return true;
|
|
2665
|
+
traversed.add(node);
|
|
2666
|
+
if (node.isSelfAccepting) {
|
|
2667
|
+
addBoundary(node, node);
|
|
2577
2668
|
return true;
|
|
2578
2669
|
}
|
|
2579
2670
|
if (node.importers.size === 0) return false;
|
|
2580
2671
|
for (const importer of node.importers) {
|
|
2581
|
-
if (
|
|
2672
|
+
if (importer.acceptedHmrDeps.has(node)) {
|
|
2673
|
+
addBoundary(importer, node);
|
|
2674
|
+
continue;
|
|
2675
|
+
}
|
|
2676
|
+
if (!propagate(importer)) return false;
|
|
2582
2677
|
}
|
|
2583
2678
|
return true;
|
|
2584
2679
|
};
|
|
2585
|
-
|
|
2586
|
-
boundaries.push({ boundary: mod, acceptedVia: mod });
|
|
2587
|
-
return boundaries;
|
|
2588
|
-
}
|
|
2589
|
-
for (const importer of mod.importers) {
|
|
2590
|
-
if (!propagate(importer, mod)) {
|
|
2591
|
-
return [];
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
return boundaries;
|
|
2680
|
+
return propagate(mod) ? boundaries : [];
|
|
2595
2681
|
}
|
|
2596
2682
|
};
|
|
2597
2683
|
}
|
|
@@ -2687,6 +2773,7 @@ var init_environment = __esm({
|
|
|
2687
2773
|
moduleGraph;
|
|
2688
2774
|
candidatePlugins;
|
|
2689
2775
|
pluginApi;
|
|
2776
|
+
buildMetadata = {};
|
|
2690
2777
|
initialized = false;
|
|
2691
2778
|
constructor(name, config, init = {}) {
|
|
2692
2779
|
const options = config.environments[name];
|
|
@@ -2743,6 +2830,22 @@ var init_environment = __esm({
|
|
|
2743
2830
|
logger: this.config.logger
|
|
2744
2831
|
};
|
|
2745
2832
|
}
|
|
2833
|
+
setBuildMetadata(metadata) {
|
|
2834
|
+
const { entries: currentEntries, ...currentMetadata } = this.buildMetadata;
|
|
2835
|
+
const { entries, ...nextMetadata } = metadata;
|
|
2836
|
+
this.buildMetadata = {
|
|
2837
|
+
...currentMetadata,
|
|
2838
|
+
...nextMetadata,
|
|
2839
|
+
...currentEntries || entries ? { entries: { ...currentEntries, ...entries } } : {}
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
getBuildMetadata() {
|
|
2843
|
+
const { entries, ...metadata } = this.buildMetadata;
|
|
2844
|
+
return {
|
|
2845
|
+
...metadata,
|
|
2846
|
+
...entries ? { entries: { ...entries } } : {}
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2746
2849
|
async close() {
|
|
2747
2850
|
try {
|
|
2748
2851
|
await this.driver?.close?.(this.getDriverContext());
|
|
@@ -2908,6 +3011,135 @@ var init_reporter = __esm({
|
|
|
2908
3011
|
}
|
|
2909
3012
|
});
|
|
2910
3013
|
|
|
3014
|
+
// src/core/build-app-context.ts
|
|
3015
|
+
function createBuildAppContext(config, results) {
|
|
3016
|
+
const output = [];
|
|
3017
|
+
const emitted = /* @__PURE__ */ new Set();
|
|
3018
|
+
const outDir = import_node_path9.default.resolve(config.root, config.build.outDir);
|
|
3019
|
+
let environmentArtifacts;
|
|
3020
|
+
return {
|
|
3021
|
+
config,
|
|
3022
|
+
results,
|
|
3023
|
+
get output() {
|
|
3024
|
+
return Object.freeze([...output]);
|
|
3025
|
+
},
|
|
3026
|
+
getResult(environmentName) {
|
|
3027
|
+
return results[environmentName];
|
|
3028
|
+
},
|
|
3029
|
+
getArtifact(environmentName, fileName) {
|
|
3030
|
+
const normalized = normalizeEnvironmentFileName(fileName);
|
|
3031
|
+
return results[environmentName]?.output.find(
|
|
3032
|
+
(artifact) => normalizeEnvironmentFileName(artifact.fileName) === normalized
|
|
3033
|
+
);
|
|
3034
|
+
},
|
|
3035
|
+
getEntry(environmentName, entryName) {
|
|
3036
|
+
const result = results[environmentName];
|
|
3037
|
+
const fileName = result?.entries?.[entryName];
|
|
3038
|
+
if (!fileName) return void 0;
|
|
3039
|
+
return result.output.find(
|
|
3040
|
+
(artifact) => normalizeEnvironmentFileName(artifact.fileName) === normalizeEnvironmentFileName(fileName)
|
|
3041
|
+
);
|
|
3042
|
+
},
|
|
3043
|
+
getManifest(environmentName) {
|
|
3044
|
+
return results[environmentName]?.manifest;
|
|
3045
|
+
},
|
|
3046
|
+
emitFile(file) {
|
|
3047
|
+
const fileName = normalizeAppFileName(file.fileName);
|
|
3048
|
+
const collisionKey = artifactCollisionKey(fileName);
|
|
3049
|
+
if (emitted.has(collisionKey)) {
|
|
3050
|
+
throw new Error(`[nasti] app artifact already emitted: ${fileName}`);
|
|
3051
|
+
}
|
|
3052
|
+
environmentArtifacts ??= collectEnvironmentArtifacts(config, results, outDir);
|
|
3053
|
+
if (environmentArtifacts.has(collisionKey)) {
|
|
3054
|
+
throw new Error(`[nasti] app artifact conflicts with environment output: ${fileName}`);
|
|
3055
|
+
}
|
|
3056
|
+
const target = import_node_path9.default.resolve(outDir, ...fileName.split("/"));
|
|
3057
|
+
const relative = import_node_path9.default.relative(outDir, target);
|
|
3058
|
+
if (relative.startsWith("..") || import_node_path9.default.isAbsolute(relative)) {
|
|
3059
|
+
throw new Error(`[nasti] app artifact must stay inside build.outDir: ${file.fileName}`);
|
|
3060
|
+
}
|
|
3061
|
+
assertNoSymlinkComponents(outDir, fileName);
|
|
3062
|
+
import_node_fs6.default.mkdirSync(import_node_path9.default.dirname(target), { recursive: true });
|
|
3063
|
+
import_node_fs6.default.writeFileSync(target, file.source);
|
|
3064
|
+
const artifact = {
|
|
3065
|
+
...file,
|
|
3066
|
+
fileName,
|
|
3067
|
+
type: "asset"
|
|
3068
|
+
};
|
|
3069
|
+
emitted.add(collisionKey);
|
|
3070
|
+
output.push(artifact);
|
|
3071
|
+
return fileName;
|
|
3072
|
+
}
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
function normalizeEnvironmentFileName(fileName) {
|
|
3076
|
+
return import_node_path9.default.posix.normalize(fileName.replace(/\\/g, "/").replace(/^\.\//, ""));
|
|
3077
|
+
}
|
|
3078
|
+
function isInvalidEnvironmentFileName(fileName) {
|
|
3079
|
+
return !fileName || fileName === "." || fileName === ".." || fileName.startsWith("../") || import_node_path9.default.posix.isAbsolute(fileName) || /^[A-Za-z]:\//.test(fileName);
|
|
3080
|
+
}
|
|
3081
|
+
function normalizeAppFileName(fileName) {
|
|
3082
|
+
const normalized = normalizeEnvironmentFileName(fileName);
|
|
3083
|
+
if (isInvalidEnvironmentFileName(normalized)) {
|
|
3084
|
+
throw new Error(`[nasti] invalid app artifact fileName: ${fileName}`);
|
|
3085
|
+
}
|
|
3086
|
+
return normalized;
|
|
3087
|
+
}
|
|
3088
|
+
function artifactCollisionKey(fileName) {
|
|
3089
|
+
return normalizeEnvironmentFileName(fileName).toLowerCase();
|
|
3090
|
+
}
|
|
3091
|
+
function collectEnvironmentArtifacts(config, results, appOutDir) {
|
|
3092
|
+
const occupied = /* @__PURE__ */ new Set();
|
|
3093
|
+
for (const [environmentName, result] of Object.entries(results)) {
|
|
3094
|
+
const environment = config.environments[environmentName];
|
|
3095
|
+
if (!environment) continue;
|
|
3096
|
+
const environmentOutDir = import_node_path9.default.resolve(config.root, environment.build.outDir);
|
|
3097
|
+
for (const artifact of result.output) {
|
|
3098
|
+
const artifactPath = import_node_path9.default.resolve(
|
|
3099
|
+
environmentOutDir,
|
|
3100
|
+
...normalizeEnvironmentFileName(artifact.fileName).split("/")
|
|
3101
|
+
);
|
|
3102
|
+
const relative = import_node_path9.default.relative(appOutDir, artifactPath);
|
|
3103
|
+
if (!relative.startsWith("..") && !import_node_path9.default.isAbsolute(relative)) {
|
|
3104
|
+
occupied.add(artifactCollisionKey(relative));
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
return occupied;
|
|
3109
|
+
}
|
|
3110
|
+
function assertNoSymlinkComponents(outDir, fileName) {
|
|
3111
|
+
let current = outDir;
|
|
3112
|
+
for (const segment of fileName.split("/")) {
|
|
3113
|
+
current = import_node_path9.default.join(current, segment);
|
|
3114
|
+
let stats;
|
|
3115
|
+
try {
|
|
3116
|
+
stats = import_node_fs6.default.lstatSync(current);
|
|
3117
|
+
} catch (error) {
|
|
3118
|
+
if (error.code === "ENOENT") continue;
|
|
3119
|
+
throw error;
|
|
3120
|
+
}
|
|
3121
|
+
if (stats.isSymbolicLink()) {
|
|
3122
|
+
throw new Error(`[nasti] app artifact path cannot traverse a symlink: ${fileName}`);
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
function inferEnvironmentEntries(output) {
|
|
3127
|
+
const entries = {};
|
|
3128
|
+
for (const artifact of output) {
|
|
3129
|
+
if (artifact.type !== "chunk" || !artifact.isEntry || !artifact.name) continue;
|
|
3130
|
+
entries[artifact.name] = normalizeEnvironmentFileName(artifact.fileName);
|
|
3131
|
+
}
|
|
3132
|
+
return Object.keys(entries).length > 0 ? entries : void 0;
|
|
3133
|
+
}
|
|
3134
|
+
var import_node_fs6, import_node_path9;
|
|
3135
|
+
var init_build_app_context = __esm({
|
|
3136
|
+
"src/core/build-app-context.ts"() {
|
|
3137
|
+
"use strict";
|
|
3138
|
+
import_node_fs6 = __toESM(require("fs"), 1);
|
|
3139
|
+
import_node_path9 = __toESM(require("path"), 1);
|
|
3140
|
+
}
|
|
3141
|
+
});
|
|
3142
|
+
|
|
2911
3143
|
// src/build/index.ts
|
|
2912
3144
|
var build_exports = {};
|
|
2913
3145
|
__export(build_exports, {
|
|
@@ -2921,9 +3153,14 @@ function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
|
|
|
2921
3153
|
const config = environment.config;
|
|
2922
3154
|
const envOptions = environment.options;
|
|
2923
3155
|
const isServer = environment.consumer === "server";
|
|
2924
|
-
const outDir =
|
|
3156
|
+
const outDir = import_node_path10.default.resolve(config.root, envOptions.build.outDir);
|
|
2925
3157
|
const assetsDir = envOptions.build.assetsDir;
|
|
2926
|
-
const {
|
|
3158
|
+
const {
|
|
3159
|
+
output: userOutput,
|
|
3160
|
+
transform: userTransform,
|
|
3161
|
+
resolve: userResolve,
|
|
3162
|
+
...restInputOptions
|
|
3163
|
+
} = envOptions.build.rolldownOptions;
|
|
2927
3164
|
const vueDefine = config.framework === "vue" ? {
|
|
2928
3165
|
__VUE_OPTIONS_API__: "true",
|
|
2929
3166
|
__VUE_PROD_DEVTOOLS__: "false",
|
|
@@ -2937,19 +3174,22 @@ function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
|
|
|
2937
3174
|
input: entryPoints,
|
|
2938
3175
|
transform: { ...userTransform, define: mergedDefine },
|
|
2939
3176
|
plugins: rolldownPlugins,
|
|
3177
|
+
// client/server consumer 都必须使用当前环境的 conditions/mainFields;Lynx
|
|
3178
|
+
// BG/MT 通常同为 client consumer,但仍可能声明不同的运行时条件。
|
|
3179
|
+
resolve: {
|
|
3180
|
+
...userResolve ?? {},
|
|
3181
|
+
// Environment API 是条件解析的唯一高层入口,优先于继承来的底层选项。
|
|
3182
|
+
conditionNames: envOptions.resolve.conditions,
|
|
3183
|
+
mainFields: envOptions.resolve.mainFields
|
|
3184
|
+
},
|
|
2940
3185
|
...isServer ? {
|
|
2941
3186
|
platform: restInputOptions.platform ?? "node",
|
|
2942
|
-
resolve: {
|
|
2943
|
-
conditionNames: envOptions.resolve.conditions,
|
|
2944
|
-
mainFields: envOptions.resolve.mainFields,
|
|
2945
|
-
...restInputOptions.resolve
|
|
2946
|
-
},
|
|
2947
3187
|
// server 产物:node 内建恒外部化;bare specifier 默认外部化
|
|
2948
3188
|
//(同 Vite ssr.external 默认 —— 依赖由 node_modules 运行时解析),
|
|
2949
3189
|
// 相对/绝对/虚拟模块照常打包。需要内联依赖时经 rolldownOptions.external 覆盖。
|
|
2950
3190
|
external: restInputOptions.external ?? ((id) => {
|
|
2951
3191
|
if (NODE_BUILTINS.has(id)) return true;
|
|
2952
|
-
return !id.startsWith(".") && !
|
|
3192
|
+
return !id.startsWith(".") && !import_node_path10.default.isAbsolute(id) && !id.startsWith("\0");
|
|
2953
3193
|
})
|
|
2954
3194
|
} : {}
|
|
2955
3195
|
};
|
|
@@ -2976,27 +3216,122 @@ function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
|
|
|
2976
3216
|
};
|
|
2977
3217
|
return { inputOptions, outputOptions, outDir };
|
|
2978
3218
|
}
|
|
2979
|
-
function toRolldownPlugins(plugins) {
|
|
3219
|
+
function toRolldownPlugins(plugins, environment) {
|
|
3220
|
+
const wrap = (hook) => {
|
|
3221
|
+
if (!hook) return hook;
|
|
3222
|
+
return function(...args) {
|
|
3223
|
+
return hook.apply(attachEnvironment(this, environment), args);
|
|
3224
|
+
};
|
|
3225
|
+
};
|
|
2980
3226
|
return plugins.map((p) => ({
|
|
2981
3227
|
name: p.name,
|
|
2982
|
-
resolveId: p.resolveId,
|
|
2983
|
-
load: p.load,
|
|
2984
|
-
transform: p.transform,
|
|
2985
|
-
buildStart: p.buildStart,
|
|
2986
|
-
buildEnd: p.buildEnd,
|
|
3228
|
+
resolveId: wrap(p.resolveId),
|
|
3229
|
+
load: wrap(p.load),
|
|
3230
|
+
transform: wrap(p.transform),
|
|
3231
|
+
buildStart: wrap(p.buildStart),
|
|
3232
|
+
buildEnd: wrap(p.buildEnd),
|
|
2987
3233
|
// closeBundle 在 bundle.close() 时触发 —— PWA manifest/SW 等终态产物依赖
|
|
2988
|
-
closeBundle: p.closeBundle,
|
|
2989
|
-
renderChunk: p.renderChunk,
|
|
2990
|
-
augmentChunkHash: p.augmentChunkHash,
|
|
2991
|
-
generateBundle: p.generateBundle
|
|
3234
|
+
closeBundle: wrap(p.closeBundle),
|
|
3235
|
+
renderChunk: wrap(p.renderChunk),
|
|
3236
|
+
augmentChunkHash: wrap(p.augmentChunkHash),
|
|
3237
|
+
generateBundle: wrap(p.generateBundle)
|
|
2992
3238
|
}));
|
|
2993
3239
|
}
|
|
3240
|
+
function attachEnvironment(context, environment) {
|
|
3241
|
+
if (context?.environment === environment) return context;
|
|
3242
|
+
try {
|
|
3243
|
+
Object.defineProperty(context, "environment", {
|
|
3244
|
+
configurable: true,
|
|
3245
|
+
enumerable: false,
|
|
3246
|
+
writable: false,
|
|
3247
|
+
value: environment
|
|
3248
|
+
});
|
|
3249
|
+
return context;
|
|
3250
|
+
} catch {
|
|
3251
|
+
return new Proxy(context, {
|
|
3252
|
+
get(target, property) {
|
|
3253
|
+
if (property === "environment") return environment;
|
|
3254
|
+
const value = Reflect.get(target, property, target);
|
|
3255
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
3256
|
+
},
|
|
3257
|
+
set(target, property, value) {
|
|
3258
|
+
return Reflect.set(target, property, value, target);
|
|
3259
|
+
}
|
|
3260
|
+
});
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
function finalizeEnvironmentResult(environment, result) {
|
|
3264
|
+
const metadata = environment.getBuildMetadata();
|
|
3265
|
+
const inferredEntries = inferEnvironmentEntries(result.output);
|
|
3266
|
+
const entries = {
|
|
3267
|
+
...inferredEntries,
|
|
3268
|
+
...metadata.entries,
|
|
3269
|
+
...result.entries
|
|
3270
|
+
};
|
|
3271
|
+
const normalizedEntries = Object.fromEntries(
|
|
3272
|
+
Object.entries(entries).map(([name, fileName]) => {
|
|
3273
|
+
const normalized = normalizeEnvironmentFileName(fileName);
|
|
3274
|
+
if (isInvalidEnvironmentFileName(normalized)) {
|
|
3275
|
+
throw new Error(
|
|
3276
|
+
`[nasti] environment "${environment.name}" returned invalid entry "${name}": ${fileName}`
|
|
3277
|
+
);
|
|
3278
|
+
}
|
|
3279
|
+
return [name, normalized];
|
|
3280
|
+
})
|
|
3281
|
+
);
|
|
3282
|
+
return {
|
|
3283
|
+
...metadata,
|
|
3284
|
+
...result,
|
|
3285
|
+
output: result.output,
|
|
3286
|
+
...Object.keys(normalizedEntries).length > 0 ? { entries: normalizedEntries } : {}
|
|
3287
|
+
};
|
|
3288
|
+
}
|
|
3289
|
+
function prepareBuildOutputDirectories(config, buildableNames) {
|
|
3290
|
+
const directories = /* @__PURE__ */ new Set();
|
|
3291
|
+
const protectedPaths = /* @__PURE__ */ new Set();
|
|
3292
|
+
const clientIsBuilt = buildableNames.includes("client");
|
|
3293
|
+
if (!clientIsBuilt && config.build.emptyOutDir) {
|
|
3294
|
+
directories.add(import_node_path10.default.resolve(config.root, config.build.outDir));
|
|
3295
|
+
}
|
|
3296
|
+
for (const name of buildableNames) {
|
|
3297
|
+
const environment = config.environments[name];
|
|
3298
|
+
const outDir = import_node_path10.default.resolve(config.root, environment.build.outDir);
|
|
3299
|
+
if (!environment.build.emptyOutDir) {
|
|
3300
|
+
protectedPaths.add(outDir);
|
|
3301
|
+
continue;
|
|
3302
|
+
}
|
|
3303
|
+
if (!environment.driver) directories.add(outDir);
|
|
3304
|
+
}
|
|
3305
|
+
const containsPath = (parent, child) => {
|
|
3306
|
+
const relative = import_node_path10.default.relative(parent, child);
|
|
3307
|
+
return relative === "" || !relative.startsWith("..") && !import_node_path10.default.isAbsolute(relative);
|
|
3308
|
+
};
|
|
3309
|
+
const roots = [...directories].filter(
|
|
3310
|
+
(directory) => ![...protectedPaths].some((protectedPath) => containsPath(directory, protectedPath))
|
|
3311
|
+
).sort((a, b) => a.length - b.length).filter(
|
|
3312
|
+
(directory, index2, all) => !all.slice(0, index2).some((parent) => containsPath(parent, directory))
|
|
3313
|
+
);
|
|
3314
|
+
for (const directory of roots) {
|
|
3315
|
+
if (import_node_fs7.default.existsSync(directory)) import_node_fs7.default.rmSync(directory, { recursive: true, force: true });
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
function assertDriverBuildResult(environment, result) {
|
|
3319
|
+
const output = result != null && typeof result === "object" ? result.output : void 0;
|
|
3320
|
+
const hasValidOutput = Array.isArray(output) && output.every(
|
|
3321
|
+
(artifact) => artifact != null && typeof artifact === "object" && typeof artifact.fileName === "string" && typeof artifact.type === "string"
|
|
3322
|
+
);
|
|
3323
|
+
if (!hasValidOutput) {
|
|
3324
|
+
throw new Error(
|
|
3325
|
+
`[nasti] environment "${environment.name}" driver "${environment.driver?.name}" returned an invalid build result; expected { output: EnvironmentBuildOutput[] }`
|
|
3326
|
+
);
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
2994
3329
|
function resolveClientEntries(config, html) {
|
|
2995
3330
|
const configuredEntries = config.environments.client?.entry ?? [];
|
|
2996
3331
|
if (configuredEntries.length > 0) return configuredEntries;
|
|
2997
3332
|
const entryPoints = [];
|
|
2998
3333
|
const htmlFile = config.environments.client?.html;
|
|
2999
|
-
const htmlDir = htmlFile ?
|
|
3334
|
+
const htmlDir = htmlFile ? import_node_path10.default.dirname(htmlFile) : config.root;
|
|
3000
3335
|
if (html) {
|
|
3001
3336
|
const scriptMatches = html.matchAll(/<script[^>]+src=["']([^"']+)["'][^>]*>/gi);
|
|
3002
3337
|
for (const match of scriptMatches) {
|
|
@@ -3004,7 +3339,7 @@ function resolveClientEntries(config, html) {
|
|
|
3004
3339
|
if (src && !src.startsWith("http")) {
|
|
3005
3340
|
const cleanSrc = src.split(/[?#]/, 1)[0];
|
|
3006
3341
|
entryPoints.push(
|
|
3007
|
-
cleanSrc.startsWith("/") ?
|
|
3342
|
+
cleanSrc.startsWith("/") ? import_node_path10.default.resolve(config.root, cleanSrc.replace(/^\//, "")) : import_node_path10.default.resolve(htmlDir, cleanSrc)
|
|
3008
3343
|
);
|
|
3009
3344
|
}
|
|
3010
3345
|
}
|
|
@@ -3012,8 +3347,8 @@ function resolveClientEntries(config, html) {
|
|
|
3012
3347
|
if (entryPoints.length === 0) {
|
|
3013
3348
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
3014
3349
|
for (const entry of fallbackEntries) {
|
|
3015
|
-
const fullPath =
|
|
3016
|
-
if (
|
|
3350
|
+
const fullPath = import_node_path10.default.resolve(config.root, entry);
|
|
3351
|
+
if (import_node_fs7.default.existsSync(fullPath)) {
|
|
3017
3352
|
entryPoints.push(fullPath);
|
|
3018
3353
|
break;
|
|
3019
3354
|
}
|
|
@@ -3041,16 +3376,20 @@ async function build(inlineConfig = {}) {
|
|
|
3041
3376
|
const startTime = performance.now();
|
|
3042
3377
|
logger.info(
|
|
3043
3378
|
import_picocolors4.default.cyan(`
|
|
3044
|
-
nasti v${"2.
|
|
3379
|
+
nasti v${"2.4.0"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
|
|
3045
3380
|
);
|
|
3046
3381
|
debug4?.(`root: ${config.root}`);
|
|
3047
|
-
const buildableNames = Object.keys(config.environments).filter(
|
|
3048
|
-
|
|
3049
|
-
|
|
3382
|
+
const buildableNames = Object.keys(config.environments).filter((name) => {
|
|
3383
|
+
const environment = config.environments[name];
|
|
3384
|
+
if (!environment.buildEnabled) return false;
|
|
3385
|
+
return name === "client" || environment.entry.length > 0 || !!environment.driver;
|
|
3386
|
+
});
|
|
3050
3387
|
buildableNames.sort((a, b) => a === "client" ? -1 : b === "client" ? 1 : 0);
|
|
3388
|
+
prepareBuildOutputDirectories(config, buildableNames);
|
|
3051
3389
|
const environments = {};
|
|
3052
3390
|
const environmentResults = {};
|
|
3053
3391
|
const initializedEnvironments = [];
|
|
3392
|
+
const buildAppContext = createBuildAppContext(config, environmentResults);
|
|
3054
3393
|
let clientOutput = [];
|
|
3055
3394
|
let buildFailed = false;
|
|
3056
3395
|
try {
|
|
@@ -3066,7 +3405,7 @@ nasti v${"2.3.1"} `) + import_picocolors4.default.green(`building for ${config.m
|
|
|
3066
3405
|
}
|
|
3067
3406
|
const pluginApi = getPluginApi(config);
|
|
3068
3407
|
for (const plugin of config.plugins) {
|
|
3069
|
-
await plugin.afterBuildApp?.(environmentResults, pluginApi);
|
|
3408
|
+
await plugin.afterBuildApp?.(environmentResults, pluginApi, buildAppContext);
|
|
3070
3409
|
}
|
|
3071
3410
|
} catch (error) {
|
|
3072
3411
|
buildFailed = true;
|
|
@@ -3093,22 +3432,31 @@ nasti v${"2.3.1"} `) + import_picocolors4.default.green(`building for ${config.m
|
|
|
3093
3432
|
}
|
|
3094
3433
|
}
|
|
3095
3434
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
3096
|
-
const
|
|
3435
|
+
const allOutput = [...Object.values(environments).flat(), ...buildAppContext.output];
|
|
3436
|
+
const totalSize = allOutput.reduce((sum, chunk) => {
|
|
3097
3437
|
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
3098
3438
|
if (content == null) return sum;
|
|
3099
3439
|
return sum + (typeof content === "string" ? Buffer.byteLength(content) : content.byteLength);
|
|
3100
3440
|
}, 0);
|
|
3101
|
-
const fileCount =
|
|
3441
|
+
const fileCount = allOutput.length;
|
|
3102
3442
|
const envSuffix = buildableNames.length > 1 ? ` (${buildableNames.join(" + ")})` : "";
|
|
3103
3443
|
logger.info(import_picocolors4.default.green(`\u2713 built in ${elapsed}s`) + import_picocolors4.default.dim(envSuffix));
|
|
3104
3444
|
logger.info(import_picocolors4.default.dim(` ${fileCount} files, ${displaySize(totalSize)} total \u2192 ${config.build.outDir}/`));
|
|
3105
|
-
return {
|
|
3445
|
+
return {
|
|
3446
|
+
output: clientOutput,
|
|
3447
|
+
environments,
|
|
3448
|
+
environmentResults,
|
|
3449
|
+
appOutput: [...buildAppContext.output]
|
|
3450
|
+
};
|
|
3106
3451
|
}
|
|
3107
3452
|
async function buildClientEnvironment(config) {
|
|
3108
3453
|
const logger = config.logger;
|
|
3109
|
-
const outDir =
|
|
3454
|
+
const outDir = import_node_path10.default.resolve(config.root, config.build.outDir);
|
|
3110
3455
|
const cssEngine = createCssEngine();
|
|
3111
|
-
const pluginList = resolvePluginList(config, config.plugins, {
|
|
3456
|
+
const pluginList = resolvePluginList(config, config.plugins, {
|
|
3457
|
+
cssEngine,
|
|
3458
|
+
environmentName: "client"
|
|
3459
|
+
});
|
|
3112
3460
|
const clientEnv = new NastiEnvironment("client", config, {
|
|
3113
3461
|
mode: "build",
|
|
3114
3462
|
plugins: pluginList,
|
|
@@ -3123,13 +3471,11 @@ async function buildClientEnvironment(config) {
|
|
|
3123
3471
|
);
|
|
3124
3472
|
}
|
|
3125
3473
|
const result = await clientEnv.driver.build(clientEnv.getDriverContext());
|
|
3126
|
-
|
|
3474
|
+
assertDriverBuildResult(clientEnv, result);
|
|
3475
|
+
return { environment: clientEnv, result: finalizeEnvironmentResult(clientEnv, result) };
|
|
3127
3476
|
}
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
}
|
|
3131
|
-
import_node_fs6.default.mkdirSync(outDir, { recursive: true });
|
|
3132
|
-
const htmlFile = config.environments.client.html ?? import_node_path9.default.resolve(config.root, "index.html");
|
|
3477
|
+
import_node_fs7.default.mkdirSync(outDir, { recursive: true });
|
|
3478
|
+
const htmlFile = config.environments.client.html ?? import_node_path10.default.resolve(config.root, "index.html");
|
|
3133
3479
|
const html = await readHtmlFile(config.root, htmlFile);
|
|
3134
3480
|
const entryPoints = resolveClientEntries(config, html);
|
|
3135
3481
|
if (entryPoints.length === 0) {
|
|
@@ -3139,7 +3485,7 @@ async function buildClientEnvironment(config) {
|
|
|
3139
3485
|
const nativeReporter = config.logLevel === "silent" ? null : await tryNativeReporterPlugin(config, logger);
|
|
3140
3486
|
const rolldownPlugins = [
|
|
3141
3487
|
createOxcTransformPlugin(config, clientEnv),
|
|
3142
|
-
...toRolldownPlugins(allPlugins),
|
|
3488
|
+
...toRolldownPlugins(allPlugins, clientEnv),
|
|
3143
3489
|
...nativeReporter ? [nativeReporter] : []
|
|
3144
3490
|
];
|
|
3145
3491
|
const { inputOptions, outputOptions } = getRolldownOptions(
|
|
@@ -3176,13 +3522,16 @@ async function buildClientEnvironment(config) {
|
|
|
3176
3522
|
);
|
|
3177
3523
|
}
|
|
3178
3524
|
}
|
|
3179
|
-
|
|
3525
|
+
import_node_fs7.default.writeFileSync(import_node_path10.default.resolve(outDir, "index.html"), processedHtml);
|
|
3180
3526
|
}
|
|
3181
3527
|
if (!nativeReporter && config.logLevel !== "silent") {
|
|
3182
3528
|
reportBuildOutput(output, config, logger);
|
|
3183
3529
|
}
|
|
3184
3530
|
warnLargeChunks(output, config, logger);
|
|
3185
|
-
return {
|
|
3531
|
+
return {
|
|
3532
|
+
environment: clientEnv,
|
|
3533
|
+
result: finalizeEnvironmentResult(clientEnv, { output })
|
|
3534
|
+
};
|
|
3186
3535
|
} catch (error) {
|
|
3187
3536
|
try {
|
|
3188
3537
|
await clientEnv.close();
|
|
@@ -3198,7 +3547,10 @@ async function buildClientEnvironment(config) {
|
|
|
3198
3547
|
async function buildServerEnvironment(config, name) {
|
|
3199
3548
|
const envOptions = config.environments[name];
|
|
3200
3549
|
const logger = config.logger;
|
|
3201
|
-
const pluginList = resolvePluginList(config, config.plugins, {
|
|
3550
|
+
const pluginList = resolvePluginList(config, config.plugins, {
|
|
3551
|
+
consumer: envOptions.consumer,
|
|
3552
|
+
environmentName: name
|
|
3553
|
+
});
|
|
3202
3554
|
const environment = new NastiEnvironment(name, config, {
|
|
3203
3555
|
mode: "build",
|
|
3204
3556
|
plugins: pluginList,
|
|
@@ -3214,38 +3566,39 @@ async function buildServerEnvironment(config, name) {
|
|
|
3214
3566
|
}
|
|
3215
3567
|
try {
|
|
3216
3568
|
const result = await environment.driver.build(environment.getDriverContext());
|
|
3217
|
-
|
|
3569
|
+
assertDriverBuildResult(environment, result);
|
|
3570
|
+
return { environment, result: finalizeEnvironmentResult(environment, result) };
|
|
3218
3571
|
} catch (error) {
|
|
3219
3572
|
await environment.close();
|
|
3220
3573
|
throw error;
|
|
3221
3574
|
}
|
|
3222
3575
|
}
|
|
3223
3576
|
for (const entry of envOptions.entry) {
|
|
3224
|
-
if (!
|
|
3577
|
+
if (!import_node_fs7.default.existsSync(entry)) {
|
|
3225
3578
|
await environment.close();
|
|
3226
3579
|
throw new Error(`[nasti] environment "${name}" entry not found: ${entry}`);
|
|
3227
3580
|
}
|
|
3228
3581
|
}
|
|
3229
3582
|
const rolldownPlugins = [
|
|
3230
3583
|
createOxcTransformPlugin(config, environment),
|
|
3231
|
-
...toRolldownPlugins(environment.plugins)
|
|
3584
|
+
...toRolldownPlugins(environment.plugins, environment)
|
|
3232
3585
|
];
|
|
3233
3586
|
const { inputOptions, outputOptions, outDir } = getRolldownOptions(
|
|
3234
3587
|
environment,
|
|
3235
3588
|
envOptions.entry,
|
|
3236
3589
|
rolldownPlugins
|
|
3237
3590
|
);
|
|
3238
|
-
|
|
3239
|
-
import_node_fs6.default.rmSync(outDir, { recursive: true, force: true });
|
|
3240
|
-
}
|
|
3241
|
-
import_node_fs6.default.mkdirSync(outDir, { recursive: true });
|
|
3591
|
+
import_node_fs7.default.mkdirSync(outDir, { recursive: true });
|
|
3242
3592
|
const bundle2 = await (0, import_rolldown.rolldown)(inputOptions);
|
|
3243
3593
|
const { output } = await bundle2.write(outputOptions);
|
|
3244
3594
|
await bundle2.close();
|
|
3245
3595
|
logger.info(
|
|
3246
|
-
import_picocolors4.default.dim(` [${name}] `) + output.map((o) =>
|
|
3596
|
+
import_picocolors4.default.dim(` [${name}] `) + output.map((o) => import_node_path10.default.join(envOptions.build.outDir, o.fileName)).join(import_picocolors4.default.dim(", "))
|
|
3247
3597
|
);
|
|
3248
|
-
return {
|
|
3598
|
+
return {
|
|
3599
|
+
environment,
|
|
3600
|
+
result: finalizeEnvironmentResult(environment, { output })
|
|
3601
|
+
};
|
|
3249
3602
|
}
|
|
3250
3603
|
function injectCssLinks(html, cssEngine, config) {
|
|
3251
3604
|
const cssLinkTags = [];
|
|
@@ -3272,9 +3625,9 @@ function escapeRegExp(string) {
|
|
|
3272
3625
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3273
3626
|
}
|
|
3274
3627
|
function replaceEntryScript(html, facadeModuleId, fileName, config, htmlFile, urlPrefix) {
|
|
3275
|
-
const rootRelative =
|
|
3276
|
-
const resolvedHtmlFile =
|
|
3277
|
-
const htmlRelative =
|
|
3628
|
+
const rootRelative = import_node_path10.default.relative(config.root, facadeModuleId).split(import_node_path10.default.sep).join("/");
|
|
3629
|
+
const resolvedHtmlFile = import_node_path10.default.resolve(config.root, htmlFile);
|
|
3630
|
+
const htmlRelative = import_node_path10.default.relative(import_node_path10.default.dirname(resolvedHtmlFile), facadeModuleId).split(import_node_path10.default.sep).join("/");
|
|
3278
3631
|
const candidates = /* @__PURE__ */ new Set([
|
|
3279
3632
|
rootRelative,
|
|
3280
3633
|
`/${rootRelative}`,
|
|
@@ -3290,12 +3643,12 @@ function replaceEntryScript(html, facadeModuleId, fileName, config, htmlFile, ur
|
|
|
3290
3643
|
}
|
|
3291
3644
|
return processed;
|
|
3292
3645
|
}
|
|
3293
|
-
var
|
|
3646
|
+
var import_node_path10, import_node_fs7, import_node_module3, import_rolldown, import_picocolors4, debug4, NODE_BUILTINS;
|
|
3294
3647
|
var init_build = __esm({
|
|
3295
3648
|
"src/build/index.ts"() {
|
|
3296
3649
|
"use strict";
|
|
3297
|
-
|
|
3298
|
-
|
|
3650
|
+
import_node_path10 = __toESM(require("path"), 1);
|
|
3651
|
+
import_node_fs7 = __toESM(require("fs"), 1);
|
|
3299
3652
|
import_node_module3 = require("module");
|
|
3300
3653
|
import_rolldown = require("rolldown");
|
|
3301
3654
|
init_config();
|
|
@@ -3308,6 +3661,7 @@ var init_build = __esm({
|
|
|
3308
3661
|
init_reporter();
|
|
3309
3662
|
init_debug();
|
|
3310
3663
|
init_plugin_api();
|
|
3664
|
+
init_build_app_context();
|
|
3311
3665
|
import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
3312
3666
|
debug4 = createDebugger("nasti:build");
|
|
3313
3667
|
NODE_BUILTINS = /* @__PURE__ */ new Set([...import_node_module3.builtinModules, ...import_node_module3.builtinModules.map((m) => `node:${m}`)]);
|
|
@@ -3367,15 +3721,17 @@ __export(middleware_exports, {
|
|
|
3367
3721
|
transformMiddleware: () => transformMiddleware,
|
|
3368
3722
|
transformRequest: () => transformRequest
|
|
3369
3723
|
});
|
|
3370
|
-
function getReactRefreshRuntimeEsm() {
|
|
3371
|
-
if (__refreshRuntimeCache)
|
|
3724
|
+
function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
|
|
3725
|
+
if (__refreshRuntimeCache) {
|
|
3726
|
+
return includeBoundaryHelpers ? __refreshRuntimeCache + REACT_REFRESH_BOUNDARY_HELPERS : __refreshRuntimeCache;
|
|
3727
|
+
}
|
|
3372
3728
|
let cjsPath;
|
|
3373
3729
|
try {
|
|
3374
3730
|
const pkgPath = __require.resolve("react-refresh/package.json");
|
|
3375
|
-
cjsPath =
|
|
3731
|
+
cjsPath = import_node_path12.default.join(import_node_path12.default.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
|
|
3376
3732
|
} catch (err) {
|
|
3377
|
-
cjsPath =
|
|
3378
|
-
if (!
|
|
3733
|
+
cjsPath = import_node_path12.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
|
|
3734
|
+
if (!import_node_fs9.default.existsSync(cjsPath)) {
|
|
3379
3735
|
const origMsg = err instanceof Error ? err.message : String(err);
|
|
3380
3736
|
throw new Error(
|
|
3381
3737
|
`[nasti] Missing dependency "react-refresh". Install it with: npm install react-refresh
|
|
@@ -3383,7 +3739,7 @@ Original resolve error: ${origMsg}`
|
|
|
3383
3739
|
);
|
|
3384
3740
|
}
|
|
3385
3741
|
}
|
|
3386
|
-
const cjsSource =
|
|
3742
|
+
const cjsSource = import_node_fs9.default.readFileSync(cjsPath, "utf-8");
|
|
3387
3743
|
__refreshRuntimeCache = `// Wrapped react-refresh runtime -> ESM
|
|
3388
3744
|
const exports = {};
|
|
3389
3745
|
const module = { exports };
|
|
@@ -3403,7 +3759,7 @@ export const findAffectedHostInstances = __rt.findAffectedHostInstances;
|
|
|
3403
3759
|
export const collectCustomHooksForSignature = __rt.collectCustomHooksForSignature;
|
|
3404
3760
|
export default __rt;
|
|
3405
3761
|
`;
|
|
3406
|
-
return __refreshRuntimeCache;
|
|
3762
|
+
return includeBoundaryHelpers ? __refreshRuntimeCache + REACT_REFRESH_BOUNDARY_HELPERS : __refreshRuntimeCache;
|
|
3407
3763
|
}
|
|
3408
3764
|
function buildReactRefreshWrapper(moduleUrl, transformedCode) {
|
|
3409
3765
|
const urlLit = JSON.stringify(moduleUrl);
|
|
@@ -3429,22 +3785,40 @@ window.$RefreshReg$ = prevRefreshReg;
|
|
|
3429
3785
|
window.$RefreshSig$ = prevRefreshSig;
|
|
3430
3786
|
|
|
3431
3787
|
if (__nasti_hot__) {
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3788
|
+
let __nasti_current_exports__;
|
|
3789
|
+
__nasti_hot__.accept((nextExports) => {
|
|
3790
|
+
if (!nextExports) return;
|
|
3791
|
+
if (!__nasti_current_exports__) {
|
|
3792
|
+
__nasti_hot__.invalidate('Could not Fast Refresh (previous exports unavailable)');
|
|
3793
|
+
return;
|
|
3794
|
+
}
|
|
3795
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(
|
|
3796
|
+
${urlLit},
|
|
3797
|
+
__nasti_current_exports__,
|
|
3798
|
+
nextExports,
|
|
3799
|
+
);
|
|
3800
|
+
if (invalidateMessage) __nasti_hot__.invalidate(invalidateMessage);
|
|
3801
|
+
});
|
|
3802
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
3803
|
+
__nasti_current_exports__ = currentExports;
|
|
3804
|
+
RefreshRuntime.registerExportsForReactRefresh(${urlLit}, currentExports);
|
|
3437
3805
|
});
|
|
3438
3806
|
}
|
|
3439
3807
|
`;
|
|
3440
3808
|
}
|
|
3441
3809
|
function injectImportMetaHot(code, moduleUrl) {
|
|
3442
|
-
|
|
3810
|
+
const hotRE = /\bimport\.meta\.hot\b/g;
|
|
3811
|
+
const matches = [...maskStringsAndComments(code).matchAll(hotRE)];
|
|
3812
|
+
if (matches.length === 0) return code;
|
|
3813
|
+
for (const match of matches.reverse()) {
|
|
3814
|
+
const start = match.index;
|
|
3815
|
+
code = code.slice(0, start) + "__nasti_hot__" + code.slice(start + match[0].length);
|
|
3816
|
+
}
|
|
3443
3817
|
const urlLit = JSON.stringify(moduleUrl);
|
|
3444
3818
|
const header = `import { createHotContext as __nasti_createHotContext__ } from "/@nasti/client";
|
|
3445
3819
|
const __nasti_hot__ = __nasti_createHotContext__(${urlLit});
|
|
3446
3820
|
`;
|
|
3447
|
-
return header + code
|
|
3821
|
+
return header + code;
|
|
3448
3822
|
}
|
|
3449
3823
|
function transformMiddleware(ctx) {
|
|
3450
3824
|
ctx.envDefine = buildEnvDefine(
|
|
@@ -3520,13 +3894,14 @@ function transformMiddleware(ctx) {
|
|
|
3520
3894
|
}
|
|
3521
3895
|
async function transformRequest(url, ctx) {
|
|
3522
3896
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
3897
|
+
url = removeTimestampQuery(url);
|
|
3523
3898
|
const cleanReqUrl = url.split("?")[0];
|
|
3524
3899
|
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
3525
3900
|
if (cached2?.transformResult) {
|
|
3526
3901
|
return cached2.transformResult;
|
|
3527
3902
|
}
|
|
3528
3903
|
if (cleanReqUrl === "/@react-refresh") {
|
|
3529
|
-
return { code: getReactRefreshRuntimeEsm() };
|
|
3904
|
+
return { code: getReactRefreshRuntimeEsm(true) };
|
|
3530
3905
|
}
|
|
3531
3906
|
if (cleanReqUrl.startsWith("/@modules/") && url.includes("?")) {
|
|
3532
3907
|
const idParam = new URLSearchParams(url.slice(url.indexOf("?") + 1)).get("id");
|
|
@@ -3534,8 +3909,8 @@ async function transformRequest(url, ctx) {
|
|
|
3534
3909
|
let realIdValid = false;
|
|
3535
3910
|
try {
|
|
3536
3911
|
if (idParam) {
|
|
3537
|
-
realId =
|
|
3538
|
-
realIdValid =
|
|
3912
|
+
realId = import_node_fs9.default.realpathSync(idParam);
|
|
3913
|
+
realIdValid = import_node_fs9.default.statSync(realId).isFile() && (realId.includes(`${import_node_path12.default.sep}node_modules${import_node_path12.default.sep}`) || isUnderRoot(realId, config.root));
|
|
3539
3914
|
}
|
|
3540
3915
|
} catch {
|
|
3541
3916
|
realId = null;
|
|
@@ -3562,6 +3937,8 @@ async function transformRequest(url, ctx) {
|
|
|
3562
3937
|
}
|
|
3563
3938
|
const rawQuery = url.includes("?") ? url.slice(url.indexOf("?") + 1) : "";
|
|
3564
3939
|
if (rawQuery && !/^t=\d+$/.test(rawQuery)) {
|
|
3940
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
3941
|
+
const transformVersion2 = mod2.invalidationVersion;
|
|
3565
3942
|
const loaded = await pluginContainer.load(url);
|
|
3566
3943
|
if (loaded != null) {
|
|
3567
3944
|
let code2 = typeof loaded === "string" ? loaded : loaded.code;
|
|
@@ -3569,30 +3946,43 @@ async function transformRequest(url, ctx) {
|
|
|
3569
3946
|
if (transformed != null) {
|
|
3570
3947
|
code2 = typeof transformed === "string" ? transformed : transformed.code;
|
|
3571
3948
|
}
|
|
3572
|
-
const
|
|
3573
|
-
moduleGraph.registerModule(mod2,
|
|
3574
|
-
|
|
3949
|
+
const parentFile = resolveUrlToFile(cleanReqUrl, config.root) ?? cleanReqUrl;
|
|
3950
|
+
moduleGraph.registerModule(mod2, parentFile);
|
|
3951
|
+
const hotInfo2 = rewriteHotAcceptDeps(code2, config, parentFile);
|
|
3952
|
+
code2 = injectImportMetaHot(hotInfo2.code, url);
|
|
3575
3953
|
code2 = replaceEnvInCode(code2, ctx.envDefine ?? buildEnvDefine(
|
|
3576
3954
|
loadEnv(config.mode, config.root, config.envPrefix),
|
|
3577
3955
|
config.mode
|
|
3578
3956
|
));
|
|
3579
|
-
|
|
3957
|
+
const importedUrls2 = /* @__PURE__ */ new Set();
|
|
3958
|
+
code2 = rewriteImports(code2, config, parentFile, importedUrls2, moduleGraph);
|
|
3959
|
+
const pruned2 = await moduleGraph.updateModuleInfo(
|
|
3960
|
+
mod2,
|
|
3961
|
+
importedUrls2,
|
|
3962
|
+
hotInfo2.acceptedUrls,
|
|
3963
|
+
hotInfo2.isSelfAccepting,
|
|
3964
|
+
transformVersion2
|
|
3965
|
+
);
|
|
3580
3966
|
const transformResult2 = { code: code2 };
|
|
3581
|
-
|
|
3967
|
+
if (pruned2) {
|
|
3968
|
+
if (pruned2.size > 0) ctx.onPrune?.([...pruned2].map((item) => item.url));
|
|
3969
|
+
mod2.transformResult = transformResult2;
|
|
3970
|
+
}
|
|
3582
3971
|
return transformResult2;
|
|
3583
3972
|
}
|
|
3584
3973
|
}
|
|
3585
3974
|
const filePath = resolveUrlToFile(url, config.root);
|
|
3586
|
-
if (!filePath || !
|
|
3975
|
+
if (!filePath || !import_node_fs9.default.existsSync(filePath)) return null;
|
|
3587
3976
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
3588
3977
|
moduleGraph.registerModule(mod, filePath);
|
|
3978
|
+
const transformVersion = mod.invalidationVersion;
|
|
3589
3979
|
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
3590
3980
|
const code2 = await bundlePackageAsEsm(filePath, config.root);
|
|
3591
3981
|
const transformResult2 = { code: code2 };
|
|
3592
3982
|
mod.transformResult = transformResult2;
|
|
3593
3983
|
return transformResult2;
|
|
3594
3984
|
}
|
|
3595
|
-
let code =
|
|
3985
|
+
let code = import_node_fs9.default.readFileSync(filePath, "utf-8");
|
|
3596
3986
|
const pluginResult = await pluginContainer.transform(code, filePath);
|
|
3597
3987
|
if (pluginResult) {
|
|
3598
3988
|
code = typeof pluginResult === "string" ? pluginResult : pluginResult.code;
|
|
@@ -3612,9 +4002,10 @@ async function transformRequest(url, ctx) {
|
|
|
3612
4002
|
if (useRefresh) {
|
|
3613
4003
|
code = buildReactRefreshWrapper(stableUrl, code);
|
|
3614
4004
|
wrappedWithRefresh = true;
|
|
3615
|
-
mod.isSelfAccepting = true;
|
|
3616
4005
|
}
|
|
3617
4006
|
}
|
|
4007
|
+
const hotInfo = rewriteHotAcceptDeps(code, config, filePath);
|
|
4008
|
+
code = hotInfo.code;
|
|
3618
4009
|
if (!wrappedWithRefresh) {
|
|
3619
4010
|
code = injectImportMetaHot(code, stableUrl);
|
|
3620
4011
|
}
|
|
@@ -3623,9 +4014,20 @@ async function transformRequest(url, ctx) {
|
|
|
3623
4014
|
config.mode
|
|
3624
4015
|
);
|
|
3625
4016
|
code = replaceEnvInCode(code, envDefine);
|
|
3626
|
-
|
|
4017
|
+
const importedUrls = /* @__PURE__ */ new Set();
|
|
4018
|
+
code = rewriteImports(code, config, filePath, importedUrls, moduleGraph);
|
|
4019
|
+
const pruned = await moduleGraph.updateModuleInfo(
|
|
4020
|
+
mod,
|
|
4021
|
+
importedUrls,
|
|
4022
|
+
hotInfo.acceptedUrls,
|
|
4023
|
+
wrappedWithRefresh || hotInfo.isSelfAccepting,
|
|
4024
|
+
transformVersion
|
|
4025
|
+
);
|
|
3627
4026
|
const transformResult = { code };
|
|
3628
|
-
|
|
4027
|
+
if (pruned) {
|
|
4028
|
+
if (pruned.size > 0) ctx.onPrune?.([...pruned].map((item) => item.url));
|
|
4029
|
+
mod.transformResult = transformResult;
|
|
4030
|
+
}
|
|
3629
4031
|
return transformResult;
|
|
3630
4032
|
}
|
|
3631
4033
|
async function loadVirtualModule(spec, ctx) {
|
|
@@ -3633,7 +4035,7 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
3633
4035
|
const resolved = await pluginContainer.resolveId(spec);
|
|
3634
4036
|
if (resolved == null) return null;
|
|
3635
4037
|
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
3636
|
-
const looksVirtual = resolvedId.startsWith("\0") || !
|
|
4038
|
+
const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs9.default.existsSync(resolvedId);
|
|
3637
4039
|
if (!looksVirtual) return null;
|
|
3638
4040
|
const loadResult = await pluginContainer.load(resolvedId);
|
|
3639
4041
|
if (loadResult == null) return null;
|
|
@@ -3646,7 +4048,7 @@ async function loadVirtualModule(spec, ctx) {
|
|
|
3646
4048
|
loadEnv(config.mode, config.root, config.envPrefix),
|
|
3647
4049
|
config.mode
|
|
3648
4050
|
));
|
|
3649
|
-
const anchor =
|
|
4051
|
+
const anchor = import_node_path12.default.join(config.root, "__nasti_virtual__.ts");
|
|
3650
4052
|
code = rewriteImports(code, config, anchor);
|
|
3651
4053
|
return { id: resolvedId, result: { code } };
|
|
3652
4054
|
}
|
|
@@ -3672,7 +4074,7 @@ async function doBundlePackage(entryFile, root) {
|
|
|
3672
4074
|
await bundle2.close();
|
|
3673
4075
|
let code = result.output[0].code;
|
|
3674
4076
|
code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
|
|
3675
|
-
const externalBaseDir =
|
|
4077
|
+
const externalBaseDir = import_node_path12.default.dirname(entryFile);
|
|
3676
4078
|
code = code.replace(
|
|
3677
4079
|
/^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
|
|
3678
4080
|
(_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
|
|
@@ -3690,16 +4092,16 @@ async function doBundlePackage(entryFile, root) {
|
|
|
3690
4092
|
return code;
|
|
3691
4093
|
}
|
|
3692
4094
|
async function tryGenerateSubpathShim(entryFile, root) {
|
|
3693
|
-
const NM = `${
|
|
4095
|
+
const NM = `${import_node_path12.default.sep}node_modules${import_node_path12.default.sep}`;
|
|
3694
4096
|
if (!entryFile.includes(NM)) return null;
|
|
3695
4097
|
let pkgDir = null;
|
|
3696
4098
|
let pkgName = null;
|
|
3697
|
-
let dir =
|
|
4099
|
+
let dir = import_node_path12.default.dirname(entryFile);
|
|
3698
4100
|
while (true) {
|
|
3699
|
-
const pkgJsonPath =
|
|
3700
|
-
if (
|
|
4101
|
+
const pkgJsonPath = import_node_path12.default.join(dir, "package.json");
|
|
4102
|
+
if (import_node_fs9.default.existsSync(pkgJsonPath)) {
|
|
3701
4103
|
try {
|
|
3702
|
-
const pkg = JSON.parse(
|
|
4104
|
+
const pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
3703
4105
|
if (typeof pkg?.name === "string" && pkg.name) {
|
|
3704
4106
|
pkgDir = dir;
|
|
3705
4107
|
pkgName = pkg.name;
|
|
@@ -3708,16 +4110,16 @@ async function tryGenerateSubpathShim(entryFile, root) {
|
|
|
3708
4110
|
} catch {
|
|
3709
4111
|
}
|
|
3710
4112
|
}
|
|
3711
|
-
const parent =
|
|
4113
|
+
const parent = import_node_path12.default.dirname(dir);
|
|
3712
4114
|
if (parent === dir) return null;
|
|
3713
4115
|
dir = parent;
|
|
3714
4116
|
if (!dir.includes(NM)) return null;
|
|
3715
4117
|
}
|
|
3716
4118
|
if (!pkgDir || !pkgName) return null;
|
|
3717
|
-
const entryExt =
|
|
4119
|
+
const entryExt = import_node_path12.default.extname(entryFile);
|
|
3718
4120
|
const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
|
|
3719
4121
|
if (!mainEntry) return null;
|
|
3720
|
-
if (
|
|
4122
|
+
if (import_node_path12.default.resolve(mainEntry) === import_node_path12.default.resolve(entryFile)) return null;
|
|
3721
4123
|
let mainNs;
|
|
3722
4124
|
let subNs;
|
|
3723
4125
|
try {
|
|
@@ -3741,7 +4143,7 @@ async function tryGenerateSubpathShim(entryFile, root) {
|
|
|
3741
4143
|
if (mainNs["default"] !== subNs["default"]) return null;
|
|
3742
4144
|
}
|
|
3743
4145
|
const rootMain = resolveNodeModule(root, pkgName);
|
|
3744
|
-
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir +
|
|
4146
|
+
const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + import_node_path12.default.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
|
|
3745
4147
|
const lines = [
|
|
3746
4148
|
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
3747
4149
|
`import * as __pkg from "${mainEntryUrl}";`
|
|
@@ -3755,10 +4157,10 @@ async function tryGenerateSubpathShim(entryFile, root) {
|
|
|
3755
4157
|
return lines.join("\n") + "\n";
|
|
3756
4158
|
}
|
|
3757
4159
|
function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
3758
|
-
const pkgJsonPath =
|
|
4160
|
+
const pkgJsonPath = import_node_path12.default.join(pkgDir, "package.json");
|
|
3759
4161
|
let pkg;
|
|
3760
4162
|
try {
|
|
3761
|
-
pkg = JSON.parse(
|
|
4163
|
+
pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
3762
4164
|
} catch {
|
|
3763
4165
|
return null;
|
|
3764
4166
|
}
|
|
@@ -3777,14 +4179,14 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
3777
4179
|
if (typeof pkg.module === "string") candidates.push(pkg.module);
|
|
3778
4180
|
if (typeof pkg.main === "string") candidates.push(pkg.main);
|
|
3779
4181
|
for (const cand of candidates) {
|
|
3780
|
-
if (
|
|
3781
|
-
const full =
|
|
3782
|
-
if (
|
|
4182
|
+
if (import_node_path12.default.extname(cand) === preferredExt) {
|
|
4183
|
+
const full = import_node_path12.default.resolve(pkgDir, cand);
|
|
4184
|
+
if (import_node_fs9.default.existsSync(full)) return full;
|
|
3783
4185
|
}
|
|
3784
4186
|
}
|
|
3785
4187
|
for (const cand of candidates) {
|
|
3786
|
-
const full =
|
|
3787
|
-
if (
|
|
4188
|
+
const full = import_node_path12.default.resolve(pkgDir, cand);
|
|
4189
|
+
if (import_node_fs9.default.existsSync(full)) return full;
|
|
3788
4190
|
}
|
|
3789
4191
|
return null;
|
|
3790
4192
|
}
|
|
@@ -3830,72 +4232,231 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
3830
4232
|
return code;
|
|
3831
4233
|
}
|
|
3832
4234
|
}
|
|
3833
|
-
function rewriteImports(code, config, filePath) {
|
|
4235
|
+
function rewriteImports(code, config, filePath, importedUrls, moduleGraph) {
|
|
4236
|
+
const resolveSpec = createModuleSpecifierResolver(config, filePath);
|
|
4237
|
+
const transformSpec = (spec) => {
|
|
4238
|
+
const resolved = removeTimestampQuery(resolveSpec(spec));
|
|
4239
|
+
importedUrls?.add(resolved);
|
|
4240
|
+
const timestamp = moduleGraph?.getModuleByUrl(resolved)?.lastHMRTimestamp ?? 0;
|
|
4241
|
+
return timestamp > 0 ? appendTimestampQuery(resolved, timestamp) : resolved;
|
|
4242
|
+
};
|
|
4243
|
+
return code.replace(
|
|
4244
|
+
/\bfrom\s+(['"])([^'"]+)\1/g,
|
|
4245
|
+
(_m, q, s) => `from ${q}${transformSpec(s)}${q}`
|
|
4246
|
+
).replace(
|
|
4247
|
+
/\bimport\s+(['"])([^'"]+)\1/g,
|
|
4248
|
+
(_m, q, s) => `import ${q}${transformSpec(s)}${q}`
|
|
4249
|
+
).replace(
|
|
4250
|
+
/\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
|
|
4251
|
+
(_m, q, s) => `import(${q}${transformSpec(s)}${q})`
|
|
4252
|
+
);
|
|
4253
|
+
}
|
|
4254
|
+
function createModuleSpecifierResolver(config, filePath) {
|
|
3834
4255
|
const root = config.root;
|
|
3835
|
-
const fileDir =
|
|
4256
|
+
const fileDir = import_node_path12.default.dirname(filePath);
|
|
3836
4257
|
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
3837
4258
|
([a], [b]) => b.length - a.length
|
|
3838
4259
|
);
|
|
3839
|
-
const toRootUrl = (abs) => "/" +
|
|
3840
|
-
|
|
3841
|
-
const suffixMatch =
|
|
4260
|
+
const toRootUrl = (abs) => "/" + import_node_path12.default.relative(root, abs).replace(/\\/g, "/");
|
|
4261
|
+
return (specifier) => {
|
|
4262
|
+
const suffixMatch = specifier.match(/[?#].*$/);
|
|
3842
4263
|
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
3843
|
-
const baseSpec = suffix ?
|
|
4264
|
+
const baseSpec = suffix ? specifier.slice(0, -suffix.length) : specifier;
|
|
3844
4265
|
for (const [key, value] of aliasEntries) {
|
|
3845
4266
|
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
3846
4267
|
const aliasBase = resolveAliasTarget2(value, root);
|
|
3847
4268
|
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
3848
|
-
const target = sub ?
|
|
4269
|
+
const target = sub ? import_node_path12.default.join(aliasBase, sub) : aliasBase;
|
|
3849
4270
|
const resolved = tryResolveDiskPath(target);
|
|
3850
|
-
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix :
|
|
4271
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
|
|
3851
4272
|
}
|
|
3852
4273
|
}
|
|
3853
4274
|
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
3854
|
-
const
|
|
3855
|
-
|
|
3856
|
-
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
4275
|
+
const resolved = tryResolveDiskPath(import_node_path12.default.resolve(fileDir, baseSpec));
|
|
4276
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
|
|
3857
4277
|
}
|
|
3858
4278
|
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
3859
|
-
const
|
|
3860
|
-
|
|
3861
|
-
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
4279
|
+
const resolved = tryResolveDiskPath(import_node_path12.default.join(root, baseSpec.replace(/^\//, "")));
|
|
4280
|
+
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
|
|
3862
4281
|
}
|
|
3863
|
-
if (baseSpec.startsWith("/")) return
|
|
3864
|
-
return `/@modules/${
|
|
4282
|
+
if (baseSpec.startsWith("/")) return specifier;
|
|
4283
|
+
return `/@modules/${specifier}`;
|
|
3865
4284
|
};
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
)
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
)
|
|
4285
|
+
}
|
|
4286
|
+
function rewriteHotAcceptDeps(code, config, filePath) {
|
|
4287
|
+
const acceptedUrls = /* @__PURE__ */ new Set();
|
|
4288
|
+
const edits = [];
|
|
4289
|
+
const resolveSpec = createModuleSpecifierResolver(config, filePath);
|
|
4290
|
+
const acceptRE = /(?:\bimport\.meta\.hot|\b__nasti_hot__)(?:(?:\?\.)|\.)accept\s*\(/g;
|
|
4291
|
+
const searchableCode = maskStringsAndComments(code);
|
|
4292
|
+
let isSelfAccepting = false;
|
|
4293
|
+
let match;
|
|
4294
|
+
while (match = acceptRE.exec(searchableCode)) {
|
|
4295
|
+
let cursor = match.index + match[0].length;
|
|
4296
|
+
const skipTrivia = () => {
|
|
4297
|
+
while (cursor < code.length) {
|
|
4298
|
+
if (/\s/.test(code[cursor])) {
|
|
4299
|
+
cursor++;
|
|
4300
|
+
continue;
|
|
4301
|
+
}
|
|
4302
|
+
if (code[cursor] === "/" && code[cursor + 1] === "/") {
|
|
4303
|
+
cursor += 2;
|
|
4304
|
+
while (cursor < code.length && code[cursor] !== "\n") cursor++;
|
|
4305
|
+
continue;
|
|
4306
|
+
}
|
|
4307
|
+
if (code[cursor] === "/" && code[cursor + 1] === "*") {
|
|
4308
|
+
cursor += 2;
|
|
4309
|
+
while (cursor < code.length && !(code[cursor] === "*" && code[cursor + 1] === "/")) cursor++;
|
|
4310
|
+
cursor += 2;
|
|
4311
|
+
continue;
|
|
4312
|
+
}
|
|
4313
|
+
break;
|
|
4314
|
+
}
|
|
4315
|
+
};
|
|
4316
|
+
skipTrivia();
|
|
4317
|
+
const first = code[cursor];
|
|
4318
|
+
if (!first || first === ")" || first !== "[" && first !== "'" && first !== '"' && first !== "`") {
|
|
4319
|
+
isSelfAccepting = true;
|
|
4320
|
+
continue;
|
|
4321
|
+
}
|
|
4322
|
+
const readLiteral = () => {
|
|
4323
|
+
const quote = code[cursor];
|
|
4324
|
+
if (quote !== "'" && quote !== '"' && quote !== "`") return;
|
|
4325
|
+
const start = cursor;
|
|
4326
|
+
cursor++;
|
|
4327
|
+
let raw = "";
|
|
4328
|
+
while (cursor < code.length) {
|
|
4329
|
+
const char = code[cursor];
|
|
4330
|
+
if (char === "\\") {
|
|
4331
|
+
raw += code[cursor + 1] ?? "";
|
|
4332
|
+
cursor += 2;
|
|
4333
|
+
continue;
|
|
4334
|
+
}
|
|
4335
|
+
if (char === quote) {
|
|
4336
|
+
cursor++;
|
|
4337
|
+
const resolved = removeTimestampQuery(resolveSpec(raw));
|
|
4338
|
+
acceptedUrls.add(resolved);
|
|
4339
|
+
edits.push({ start, end: cursor, value: JSON.stringify(resolved) });
|
|
4340
|
+
return;
|
|
4341
|
+
}
|
|
4342
|
+
if (quote === "`" && char === "$" && code[cursor + 1] === "{") return;
|
|
4343
|
+
raw += char;
|
|
4344
|
+
cursor++;
|
|
4345
|
+
}
|
|
4346
|
+
};
|
|
4347
|
+
if (first === "[") {
|
|
4348
|
+
cursor++;
|
|
4349
|
+
while (cursor < code.length) {
|
|
4350
|
+
skipTrivia();
|
|
4351
|
+
if (code[cursor] === ",") {
|
|
4352
|
+
cursor++;
|
|
4353
|
+
skipTrivia();
|
|
4354
|
+
}
|
|
4355
|
+
if (code[cursor] === "]") break;
|
|
4356
|
+
const before = cursor;
|
|
4357
|
+
readLiteral();
|
|
4358
|
+
if (cursor === before) break;
|
|
4359
|
+
}
|
|
4360
|
+
} else {
|
|
4361
|
+
readLiteral();
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
4365
|
+
code = code.slice(0, edit.start) + edit.value + code.slice(edit.end);
|
|
4366
|
+
}
|
|
4367
|
+
return { code, acceptedUrls, isSelfAccepting };
|
|
4368
|
+
}
|
|
4369
|
+
function maskStringsAndComments(code) {
|
|
4370
|
+
const masked = code.split("");
|
|
4371
|
+
let state = "code";
|
|
4372
|
+
const isRegexStart = (index2) => {
|
|
4373
|
+
let previous = index2 - 1;
|
|
4374
|
+
while (previous >= 0 && /\s/.test(code[previous])) previous--;
|
|
4375
|
+
return previous < 0 || "=(:,!&|?{};[]+-*%^~<>".includes(code[previous]);
|
|
4376
|
+
};
|
|
4377
|
+
for (let i = 0; i < code.length; i++) {
|
|
4378
|
+
const char = code[i];
|
|
4379
|
+
const next = code[i + 1];
|
|
4380
|
+
if (state === "code") {
|
|
4381
|
+
if (char === "'") state = "single";
|
|
4382
|
+
else if (char === '"') state = "double";
|
|
4383
|
+
else if (char === "`") state = "template";
|
|
4384
|
+
else if (char === "/" && next === "/") state = "line-comment";
|
|
4385
|
+
else if (char === "/" && next === "*") state = "block-comment";
|
|
4386
|
+
else if (char === "/" && isRegexStart(i)) state = "regex";
|
|
4387
|
+
else continue;
|
|
4388
|
+
masked[i] = " ";
|
|
4389
|
+
continue;
|
|
4390
|
+
}
|
|
4391
|
+
if (state === "line-comment") {
|
|
4392
|
+
if (char === "\n") {
|
|
4393
|
+
state = "code";
|
|
4394
|
+
} else {
|
|
4395
|
+
masked[i] = " ";
|
|
4396
|
+
}
|
|
4397
|
+
continue;
|
|
4398
|
+
}
|
|
4399
|
+
if (state === "block-comment") {
|
|
4400
|
+
masked[i] = char === "\n" ? "\n" : " ";
|
|
4401
|
+
if (char === "*" && next === "/") {
|
|
4402
|
+
masked[i + 1] = " ";
|
|
4403
|
+
i++;
|
|
4404
|
+
state = "code";
|
|
4405
|
+
}
|
|
4406
|
+
continue;
|
|
4407
|
+
}
|
|
4408
|
+
if (state === "regex" || state === "regex-class") {
|
|
4409
|
+
masked[i] = char === "\n" ? "\n" : " ";
|
|
4410
|
+
if (char === "\\") {
|
|
4411
|
+
if (i + 1 < code.length) masked[++i] = " ";
|
|
4412
|
+
} else if (state === "regex" && char === "[") {
|
|
4413
|
+
state = "regex-class";
|
|
4414
|
+
} else if (state === "regex-class" && char === "]") {
|
|
4415
|
+
state = "regex";
|
|
4416
|
+
} else if (state === "regex" && char === "/") {
|
|
4417
|
+
state = "code";
|
|
4418
|
+
}
|
|
4419
|
+
continue;
|
|
4420
|
+
}
|
|
4421
|
+
masked[i] = char === "\n" ? "\n" : " ";
|
|
4422
|
+
if (char === "\\") {
|
|
4423
|
+
if (i + 1 < code.length) masked[++i] = " ";
|
|
4424
|
+
continue;
|
|
4425
|
+
}
|
|
4426
|
+
if (state === "single" && char === "'" || state === "double" && char === '"' || state === "template" && char === "`") {
|
|
4427
|
+
state = "code";
|
|
4428
|
+
}
|
|
4429
|
+
}
|
|
4430
|
+
return masked.join("");
|
|
3876
4431
|
}
|
|
3877
4432
|
function resolveAliasTarget2(value, root) {
|
|
3878
|
-
if (
|
|
3879
|
-
if (value.startsWith("/")) return
|
|
3880
|
-
return
|
|
4433
|
+
if (import_node_path12.default.isAbsolute(value) && import_node_fs9.default.existsSync(value)) return value;
|
|
4434
|
+
if (value.startsWith("/")) return import_node_path12.default.join(root, value.slice(1));
|
|
4435
|
+
return import_node_path12.default.resolve(root, value);
|
|
3881
4436
|
}
|
|
3882
4437
|
function tryResolveDiskPath(target) {
|
|
3883
|
-
if (
|
|
4438
|
+
if (import_node_fs9.default.existsSync(target) && import_node_fs9.default.statSync(target).isFile()) return target;
|
|
3884
4439
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
3885
4440
|
const withExt = target + ext;
|
|
3886
|
-
if (
|
|
4441
|
+
if (import_node_fs9.default.existsSync(withExt) && import_node_fs9.default.statSync(withExt).isFile()) return withExt;
|
|
3887
4442
|
}
|
|
3888
|
-
if (
|
|
4443
|
+
if (import_node_fs9.default.existsSync(target) && import_node_fs9.default.statSync(target).isDirectory()) {
|
|
3889
4444
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
3890
|
-
const idx =
|
|
3891
|
-
if (
|
|
4445
|
+
const idx = import_node_path12.default.join(target, "index" + ext);
|
|
4446
|
+
if (import_node_fs9.default.existsSync(idx) && import_node_fs9.default.statSync(idx).isFile()) return idx;
|
|
3892
4447
|
}
|
|
3893
4448
|
}
|
|
3894
4449
|
return null;
|
|
3895
4450
|
}
|
|
3896
4451
|
function isUnderRoot(abs, root) {
|
|
3897
|
-
const rel =
|
|
3898
|
-
return !!rel && !rel.startsWith("..") && !
|
|
4452
|
+
const rel = import_node_path12.default.relative(root, abs);
|
|
4453
|
+
return !!rel && !rel.startsWith("..") && !import_node_path12.default.isAbsolute(rel);
|
|
4454
|
+
}
|
|
4455
|
+
function appendTimestampQuery(url, timestamp) {
|
|
4456
|
+
const hashIndex = url.indexOf("#");
|
|
4457
|
+
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
4458
|
+
const withoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
4459
|
+
return `${withoutHash}${withoutHash.includes("?") ? "&" : "?"}t=${timestamp}${hash}`;
|
|
3899
4460
|
}
|
|
3900
4461
|
function externalSpecToModuleUrl(spec, baseDir, root) {
|
|
3901
4462
|
const resolved = resolveNodeModule(baseDir, spec);
|
|
@@ -3908,7 +4469,7 @@ function resolveNodeModule(baseDir, moduleName) {
|
|
|
3908
4469
|
const resolved = resolveNodeModuleEntry(baseDir, moduleName);
|
|
3909
4470
|
if (!resolved) return null;
|
|
3910
4471
|
try {
|
|
3911
|
-
return
|
|
4472
|
+
return import_node_fs9.default.realpathSync(resolved);
|
|
3912
4473
|
} catch {
|
|
3913
4474
|
return resolved;
|
|
3914
4475
|
}
|
|
@@ -3928,21 +4489,21 @@ function resolveNodeModuleEntry(root, moduleName) {
|
|
|
3928
4489
|
let pkgDir = null;
|
|
3929
4490
|
let dir = root;
|
|
3930
4491
|
for (; ; ) {
|
|
3931
|
-
const candidate =
|
|
3932
|
-
if (
|
|
4492
|
+
const candidate = import_node_path12.default.join(dir, "node_modules", pkgName);
|
|
4493
|
+
if (import_node_fs9.default.existsSync(candidate)) {
|
|
3933
4494
|
pkgDir = candidate;
|
|
3934
4495
|
break;
|
|
3935
4496
|
}
|
|
3936
|
-
const parent =
|
|
4497
|
+
const parent = import_node_path12.default.dirname(dir);
|
|
3937
4498
|
if (parent === dir) break;
|
|
3938
4499
|
dir = parent;
|
|
3939
4500
|
}
|
|
3940
4501
|
if (!pkgDir) return null;
|
|
3941
|
-
const pkgJsonPath =
|
|
3942
|
-
if (!
|
|
4502
|
+
const pkgJsonPath = import_node_path12.default.join(pkgDir, "package.json");
|
|
4503
|
+
if (!import_node_fs9.default.existsSync(pkgJsonPath)) return null;
|
|
3943
4504
|
let pkg;
|
|
3944
4505
|
try {
|
|
3945
|
-
pkg = JSON.parse(
|
|
4506
|
+
pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
3946
4507
|
} catch {
|
|
3947
4508
|
return null;
|
|
3948
4509
|
}
|
|
@@ -3955,32 +4516,32 @@ function resolveNodeModuleEntry(root, moduleName) {
|
|
|
3955
4516
|
const subDirs = [""];
|
|
3956
4517
|
for (const field of ["module", "main"]) {
|
|
3957
4518
|
if (typeof pkg[field] === "string") {
|
|
3958
|
-
const dir2 =
|
|
4519
|
+
const dir2 = import_node_path12.default.dirname(pkg[field]);
|
|
3959
4520
|
if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
|
|
3960
4521
|
}
|
|
3961
4522
|
}
|
|
3962
4523
|
for (const dir2 of subDirs) {
|
|
3963
|
-
const direct =
|
|
3964
|
-
if (
|
|
4524
|
+
const direct = import_node_path12.default.join(pkgDir, dir2, subpath);
|
|
4525
|
+
if (import_node_fs9.default.existsSync(direct) && import_node_fs9.default.statSync(direct).isFile()) return direct;
|
|
3965
4526
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
3966
|
-
if (
|
|
4527
|
+
if (import_node_fs9.default.existsSync(direct + ext)) return direct + ext;
|
|
3967
4528
|
}
|
|
3968
4529
|
}
|
|
3969
4530
|
return null;
|
|
3970
4531
|
}
|
|
3971
4532
|
for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
|
|
3972
4533
|
if (typeof pkg[field] === "string") {
|
|
3973
|
-
const entry =
|
|
3974
|
-
if (
|
|
4534
|
+
const entry = import_node_path12.default.join(pkgDir, pkg[field]);
|
|
4535
|
+
if (import_node_fs9.default.existsSync(entry)) return entry;
|
|
3975
4536
|
}
|
|
3976
4537
|
}
|
|
3977
|
-
const indexFallback =
|
|
3978
|
-
if (
|
|
4538
|
+
const indexFallback = import_node_path12.default.join(pkgDir, "index.js");
|
|
4539
|
+
if (import_node_fs9.default.existsSync(indexFallback)) return indexFallback;
|
|
3979
4540
|
return null;
|
|
3980
4541
|
}
|
|
3981
4542
|
function resolvePackageExports(exports2, key, pkgDir) {
|
|
3982
4543
|
if (typeof exports2 === "string") {
|
|
3983
|
-
return key === "." ?
|
|
4544
|
+
return key === "." ? import_node_path12.default.join(pkgDir, exports2) : null;
|
|
3984
4545
|
}
|
|
3985
4546
|
const entry = exports2[key];
|
|
3986
4547
|
if (entry === void 0) {
|
|
@@ -3992,7 +4553,7 @@ function resolvePackageExports(exports2, key, pkgDir) {
|
|
|
3992
4553
|
return resolveExportValue(entry, pkgDir);
|
|
3993
4554
|
}
|
|
3994
4555
|
function resolveExportValue(value, pkgDir) {
|
|
3995
|
-
if (typeof value === "string") return
|
|
4556
|
+
if (typeof value === "string") return import_node_path12.default.join(pkgDir, value);
|
|
3996
4557
|
if (Array.isArray(value)) {
|
|
3997
4558
|
for (const item of value) {
|
|
3998
4559
|
const r = resolveExportValue(item, pkgDir);
|
|
@@ -4016,17 +4577,17 @@ function resolveUrlToFile(url, root) {
|
|
|
4016
4577
|
const moduleName = cleanUrl.slice("/@modules/".length);
|
|
4017
4578
|
return resolveNodeModule(root, moduleName);
|
|
4018
4579
|
}
|
|
4019
|
-
const filePath =
|
|
4020
|
-
if (
|
|
4580
|
+
const filePath = import_node_path12.default.resolve(root, cleanUrl.replace(/^\//, ""));
|
|
4581
|
+
if (import_node_fs9.default.existsSync(filePath) && import_node_fs9.default.statSync(filePath).isFile()) {
|
|
4021
4582
|
return filePath;
|
|
4022
4583
|
}
|
|
4023
4584
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
4024
4585
|
const withExt = filePath + ext;
|
|
4025
|
-
if (
|
|
4586
|
+
if (import_node_fs9.default.existsSync(withExt)) return withExt;
|
|
4026
4587
|
}
|
|
4027
4588
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
4028
|
-
const indexFile =
|
|
4029
|
-
if (
|
|
4589
|
+
const indexFile = import_node_path12.default.join(filePath, "index" + ext);
|
|
4590
|
+
if (import_node_fs9.default.existsSync(indexFile)) return indexFile;
|
|
4030
4591
|
}
|
|
4031
4592
|
return null;
|
|
4032
4593
|
}
|
|
@@ -4034,36 +4595,35 @@ function isModuleRequest(url) {
|
|
|
4034
4595
|
const cleanUrl = url.split("?")[0];
|
|
4035
4596
|
if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
|
|
4036
4597
|
if (cleanUrl.startsWith("/@modules/")) return true;
|
|
4037
|
-
if (!
|
|
4598
|
+
if (!import_node_path12.default.extname(cleanUrl)) return true;
|
|
4038
4599
|
return false;
|
|
4039
4600
|
}
|
|
4040
4601
|
function getHmrClientCode() {
|
|
4041
4602
|
return `
|
|
4042
4603
|
// Nasti HMR Client
|
|
4043
|
-
const
|
|
4604
|
+
const socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
4605
|
+
const socket = new WebSocket(socketProtocol + '://' + location.host, 'nasti-hmr');
|
|
4044
4606
|
const hotModulesMap = new Map();
|
|
4045
4607
|
const disposeMap = new Map();
|
|
4046
4608
|
const pruneMap = new Map();
|
|
4609
|
+
const dataMap = new Map();
|
|
4610
|
+
let updateQueue = [];
|
|
4611
|
+
let pendingUpdateQueue = false;
|
|
4047
4612
|
|
|
4048
4613
|
socket.addEventListener('message', async ({ data }) => {
|
|
4049
4614
|
const payload = JSON.parse(data);
|
|
4050
4615
|
switch (payload.type) {
|
|
4051
4616
|
case 'connected':
|
|
4052
|
-
console.
|
|
4617
|
+
console.debug('[nasti] connected.');
|
|
4053
4618
|
clearErrorOverlay();
|
|
4054
4619
|
break;
|
|
4055
4620
|
case 'update':
|
|
4056
4621
|
try {
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
} else if (update.type === 'css-update') {
|
|
4061
|
-
return updateCss(update.path);
|
|
4062
|
-
}
|
|
4063
|
-
}));
|
|
4622
|
+
// CSS \u5728 unbundled \u6A21\u5F0F\u4E0B\u4E5F\u662F\u4F1A\u6CE8\u5165 <style> \u7684 JS \u6A21\u5757\uFF0C\u548C\u666E\u901A JS
|
|
4623
|
+
// \u4E00\u6837\u91CD\u65B0 import \u624D\u80FD\u6267\u884C dispose/accept \u5E76\u4FDD\u6301\u9875\u9762\u72B6\u6001\u3002
|
|
4624
|
+
await Promise.all(payload.updates.map(queueUpdate));
|
|
4064
4625
|
clearErrorOverlay();
|
|
4065
|
-
console.
|
|
4066
|
-
location.reload();
|
|
4626
|
+
console.debug('[nasti] HMR update complete.');
|
|
4067
4627
|
} catch (err) {
|
|
4068
4628
|
console.error('[nasti] HMR update failed:', err);
|
|
4069
4629
|
showErrorOverlay(err);
|
|
@@ -4074,10 +4634,17 @@ socket.addEventListener('message', async ({ data }) => {
|
|
|
4074
4634
|
location.reload();
|
|
4075
4635
|
break;
|
|
4076
4636
|
case 'prune':
|
|
4077
|
-
payload.paths.
|
|
4078
|
-
const
|
|
4079
|
-
|
|
4080
|
-
|
|
4637
|
+
await Promise.all(payload.paths.map(async (path) => {
|
|
4638
|
+
const data = dataMap.get(path);
|
|
4639
|
+
const dispose = disposeMap.get(path);
|
|
4640
|
+
const prune = pruneMap.get(path);
|
|
4641
|
+
if (dispose) await dispose(data);
|
|
4642
|
+
if (prune) await prune(data);
|
|
4643
|
+
hotModulesMap.delete(path);
|
|
4644
|
+
disposeMap.delete(path);
|
|
4645
|
+
pruneMap.delete(path);
|
|
4646
|
+
dataMap.delete(path);
|
|
4647
|
+
}));
|
|
4081
4648
|
break;
|
|
4082
4649
|
case 'error':
|
|
4083
4650
|
console.error('[nasti] error:', payload.err.message);
|
|
@@ -4086,33 +4653,64 @@ socket.addEventListener('message', async ({ data }) => {
|
|
|
4086
4653
|
}
|
|
4087
4654
|
});
|
|
4088
4655
|
|
|
4089
|
-
// \
|
|
4656
|
+
// \u670D\u52A1\u91CD\u542F\u540E\u65E7\u6A21\u5757\u56FE\u5DF2\u5931\u6548\uFF0C\u91CD\u8FDE\u65F6\u6574\u9875\u5237\u65B0\u662F\u5FC5\u8981\u515C\u5E95\uFF1B\u6B63\u5E38 update \u4E0D\u518D\u5237\u65B0\u3002
|
|
4090
4657
|
let reconnectTimer = 0;
|
|
4091
4658
|
socket.addEventListener('close', () => {
|
|
4092
4659
|
clearTimeout(reconnectTimer);
|
|
4093
4660
|
reconnectTimer = setTimeout(() => location.reload(), 1000);
|
|
4094
4661
|
});
|
|
4095
4662
|
|
|
4663
|
+
/**
|
|
4664
|
+
* \u540C\u4E00\u6279\u66F4\u65B0\u5148\u5168\u90E8\u62C9\u53D6\uFF0C\u518D\u6309\u670D\u52A1\u7AEF\u6D88\u606F\u987A\u5E8F\u6267\u884C accept \u56DE\u8C03\uFF0C\u907F\u514D HTTP \u5F80\u8FD4\u901F\u5EA6
|
|
4665
|
+
* \u6539\u53D8\u6A21\u5757\u5E94\u7528\u987A\u5E8F\u3002\u8FD9\u4E0E Vite HMRClient \u7684 fetch/apply \u4E24\u9636\u6BB5\u4E00\u81F4\u3002
|
|
4666
|
+
*/
|
|
4667
|
+
async function queueUpdate(update) {
|
|
4668
|
+
updateQueue.push(fetchUpdate(update));
|
|
4669
|
+
if (pendingUpdateQueue) return;
|
|
4670
|
+
|
|
4671
|
+
pendingUpdateQueue = true;
|
|
4672
|
+
await Promise.resolve();
|
|
4673
|
+
pendingUpdateQueue = false;
|
|
4674
|
+
const loading = updateQueue;
|
|
4675
|
+
updateQueue = [];
|
|
4676
|
+
const applyUpdates = await Promise.all(loading);
|
|
4677
|
+
for (const apply of applyUpdates) {
|
|
4678
|
+
if (apply) apply();
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
|
|
4096
4682
|
async function fetchUpdate(update) {
|
|
4097
4683
|
const mod = hotModulesMap.get(update.path);
|
|
4098
|
-
// \
|
|
4099
|
-
|
|
4100
|
-
if (dispose) dispose();
|
|
4684
|
+
// \u5C1A\u672A\u5728\u5F53\u524D\u9875\u9762\u52A0\u8F7D\u7684\u52A8\u6001\u6A21\u5757\u4E0D\u9700\u8981\u66F4\u65B0\u3002
|
|
4685
|
+
if (!mod) return;
|
|
4101
4686
|
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4687
|
+
// \u5FC5\u987B\u5728\u91CD\u65B0 import \u524D\u786E\u5B9A\u65E7\u56DE\u8C03\uFF1B\u65B0\u6A21\u5757\u6267\u884C createHotContext \u65F6\u4F1A\u6E05\u7A7A\u5E76\u6CE8\u518C\u65B0\u56DE\u8C03\u3002
|
|
4688
|
+
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) =>
|
|
4689
|
+
deps.includes(update.acceptedPath)
|
|
4690
|
+
);
|
|
4691
|
+
const isSelfUpdate = update.path === update.acceptedPath;
|
|
4692
|
+
if (!isSelfUpdate && qualifiedCallbacks.length === 0) return;
|
|
4693
|
+
|
|
4694
|
+
const dispose = disposeMap.get(update.acceptedPath);
|
|
4695
|
+
if (dispose) await dispose(dataMap.get(update.acceptedPath));
|
|
4696
|
+
const newMod = await import(appendTimestampQuery(update.acceptedPath, update.timestamp));
|
|
4697
|
+
|
|
4698
|
+
return () => {
|
|
4699
|
+
for (const { deps, fn } of qualifiedCallbacks) {
|
|
4700
|
+
fn(deps.map((dep) => dep === update.acceptedPath ? newMod : undefined));
|
|
4701
|
+
}
|
|
4702
|
+
const detail = isSelfUpdate
|
|
4703
|
+
? update.path
|
|
4704
|
+
: update.acceptedPath + ' via ' + update.path;
|
|
4705
|
+
console.debug('[nasti] hot updated:', detail);
|
|
4706
|
+
};
|
|
4107
4707
|
}
|
|
4108
4708
|
|
|
4109
|
-
function
|
|
4110
|
-
const
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
.then(css => { el.textContent = css; });
|
|
4115
|
-
}
|
|
4709
|
+
function appendTimestampQuery(url, timestamp) {
|
|
4710
|
+
const hashIndex = url.indexOf('#');
|
|
4711
|
+
const hash = hashIndex >= 0 ? url.slice(hashIndex) : '';
|
|
4712
|
+
const withoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
4713
|
+
return withoutHash + (withoutHash.includes('?') ? '&' : '?') + 't=' + timestamp + hash;
|
|
4116
4714
|
}
|
|
4117
4715
|
|
|
4118
4716
|
function clearErrorOverlay() {
|
|
@@ -4140,23 +4738,30 @@ function showErrorOverlay(err) {
|
|
|
4140
4738
|
document.body.appendChild(overlay);
|
|
4141
4739
|
}
|
|
4142
4740
|
|
|
4143
|
-
/**
|
|
4144
|
-
* \u751F\u6210 import.meta.hot \u7684 hot context\u3002
|
|
4145
|
-
* \u5173\u952E\u7EA6\u675F\uFF1A\u540C\u4E00 ownerPath \u7684 accept \u56DE\u8C03\u5FC5\u987B\u66FF\u6362\uFF08\u4E0D\u662F append\uFF09\u3002
|
|
4146
|
-
* \u6BCF\u6B21\u6A21\u5757\u91CD\u65B0 import \u90FD\u4F1A\u8C03\u7528 createHotContext\uFF0C\u65E7\u56DE\u8C03\u4F1A\u88AB fetchUpdate \u8C03\u7528\u540E\u7ACB\u5373\u88AB\u65B0 import
|
|
4147
|
-
* \u91CC\u7684 accept \u66FF\u6362\u3002\u4E0D\u66FF\u6362\u7684\u8BDD\u6BCF\u7F16\u8F91\u4E00\u6B21\u5C31\u591A\u4E00\u4E2A\u56DE\u8C03\uFF0C\u8D8A\u8DD1\u8D8A\u6162\u3002
|
|
4148
|
-
*/
|
|
4149
4741
|
export function createHotContext(ownerPath) {
|
|
4742
|
+
if (!dataMap.has(ownerPath)) dataMap.set(ownerPath, {});
|
|
4743
|
+
|
|
4744
|
+
// \u6A21\u5757\u91CD\u65B0\u6267\u884C\u65F6\u4E22\u5F03\u65E7 accept \u56DE\u8C03\uFF0C\u4F46\u4FDD\u7559\u540C\u4E00\u4E2A hot.data \u5BF9\u8C61\u3002
|
|
4745
|
+
const existing = hotModulesMap.get(ownerPath);
|
|
4746
|
+
if (existing) existing.callbacks = [];
|
|
4747
|
+
|
|
4748
|
+
const acceptDeps = (deps, callback = () => {}) => {
|
|
4749
|
+
const mod = hotModulesMap.get(ownerPath) || { id: ownerPath, callbacks: [] };
|
|
4750
|
+
mod.callbacks.push({ deps, fn: callback });
|
|
4751
|
+
hotModulesMap.set(ownerPath, mod);
|
|
4752
|
+
};
|
|
4753
|
+
|
|
4150
4754
|
return {
|
|
4151
4755
|
accept(deps, callback) {
|
|
4152
|
-
// \u81EA\u63A5\u53D7: hot.accept() \u6216 hot.accept(callback)
|
|
4153
4756
|
if (typeof deps === 'function' || deps === undefined) {
|
|
4154
|
-
|
|
4155
|
-
|
|
4757
|
+
acceptDeps([ownerPath], ([mod]) => deps?.(mod));
|
|
4758
|
+
} else if (typeof deps === 'string') {
|
|
4759
|
+
acceptDeps([deps], ([mod]) => callback?.(mod));
|
|
4760
|
+
} else if (Array.isArray(deps)) {
|
|
4761
|
+
acceptDeps(deps, callback);
|
|
4762
|
+
} else {
|
|
4763
|
+
throw new Error('invalid hot.accept() usage');
|
|
4156
4764
|
}
|
|
4157
|
-
// \u4F9D\u8D56\u63A5\u53D7: hot.accept(deps, callback)\uFF0C\u591A\u6B21\u8C03\u7528\u8FFD\u52A0
|
|
4158
|
-
const existing = hotModulesMap.get(ownerPath)?.callbacks ?? [];
|
|
4159
|
-
hotModulesMap.set(ownerPath, { callbacks: [...existing, callback] });
|
|
4160
4765
|
},
|
|
4161
4766
|
prune(callback) {
|
|
4162
4767
|
pruneMap.set(ownerPath, callback);
|
|
@@ -4167,27 +4772,91 @@ export function createHotContext(ownerPath) {
|
|
|
4167
4772
|
invalidate() {
|
|
4168
4773
|
location.reload();
|
|
4169
4774
|
},
|
|
4170
|
-
data:
|
|
4775
|
+
data: dataMap.get(ownerPath),
|
|
4171
4776
|
};
|
|
4172
4777
|
}
|
|
4173
4778
|
`;
|
|
4174
4779
|
}
|
|
4175
|
-
var
|
|
4780
|
+
var import_node_path12, import_node_fs9, import_node_module5, import_node_url3, import_picocolors6, import_meta, __dirname_esm, __require, __refreshRuntimeCache, REACT_REFRESH_BOUNDARY_HELPERS, REACT_REFRESH_GLOBAL_PREAMBLE, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
|
|
4176
4781
|
var init_middleware = __esm({
|
|
4177
4782
|
"src/server/middleware.ts"() {
|
|
4178
4783
|
"use strict";
|
|
4179
|
-
|
|
4180
|
-
|
|
4784
|
+
import_node_path12 = __toESM(require("path"), 1);
|
|
4785
|
+
import_node_fs9 = __toESM(require("fs"), 1);
|
|
4181
4786
|
import_node_module5 = require("module");
|
|
4182
4787
|
import_node_url3 = require("url");
|
|
4183
4788
|
import_picocolors6 = __toESM(require("picocolors"), 1);
|
|
4184
4789
|
init_transformer();
|
|
4185
4790
|
init_html();
|
|
4186
4791
|
init_env();
|
|
4792
|
+
init_url();
|
|
4187
4793
|
import_meta = {};
|
|
4188
|
-
__dirname_esm =
|
|
4794
|
+
__dirname_esm = import_node_path12.default.dirname((0, import_node_url3.fileURLToPath)(import_meta.url));
|
|
4189
4795
|
__require = (0, import_node_module5.createRequire)(import_meta.url);
|
|
4190
4796
|
__refreshRuntimeCache = null;
|
|
4797
|
+
REACT_REFRESH_BOUNDARY_HELPERS = `
|
|
4798
|
+
function __nastiIsPlainObject(obj) {
|
|
4799
|
+
return Object.prototype.toString.call(obj) === '[object Object]' &&
|
|
4800
|
+
(obj.constructor === Object || obj.constructor === undefined);
|
|
4801
|
+
}
|
|
4802
|
+
function __nastiIsCompoundComponent(type) {
|
|
4803
|
+
if (!__nastiIsPlainObject(type)) return false;
|
|
4804
|
+
for (const key in type) {
|
|
4805
|
+
if (!isLikelyComponentType(type[key])) return false;
|
|
4806
|
+
}
|
|
4807
|
+
return true;
|
|
4808
|
+
}
|
|
4809
|
+
export function registerExportsForReactRefresh(filename, moduleExports) {
|
|
4810
|
+
for (const key in moduleExports) {
|
|
4811
|
+
if (key === '__esModule') continue;
|
|
4812
|
+
const value = moduleExports[key];
|
|
4813
|
+
if (isLikelyComponentType(value)) {
|
|
4814
|
+
register(value, filename + ' export ' + key);
|
|
4815
|
+
} else if (__nastiIsCompoundComponent(value)) {
|
|
4816
|
+
for (const subKey in value) {
|
|
4817
|
+
register(value[subKey], filename + ' export ' + key + '-' + subKey);
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
let __nastiRefreshTimer;
|
|
4823
|
+
function __nastiEnqueueRefresh() {
|
|
4824
|
+
clearTimeout(__nastiRefreshTimer);
|
|
4825
|
+
__nastiRefreshTimer = setTimeout(() => performReactRefresh(), 16);
|
|
4826
|
+
}
|
|
4827
|
+
function __nastiCheckExports(ignored, exports, predicate) {
|
|
4828
|
+
for (const key in exports) {
|
|
4829
|
+
if (ignored.includes(key)) continue;
|
|
4830
|
+
if (!predicate(key, exports[key])) return key;
|
|
4831
|
+
}
|
|
4832
|
+
return true;
|
|
4833
|
+
}
|
|
4834
|
+
export function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
|
|
4835
|
+
const ignored = window.__getReactRefreshIgnoredExports?.({ id }) ?? [];
|
|
4836
|
+
if (__nastiCheckExports(ignored, prevExports, (key) => key in nextExports) !== true) {
|
|
4837
|
+
return 'Could not Fast Refresh (export removed)';
|
|
4838
|
+
}
|
|
4839
|
+
if (__nastiCheckExports(ignored, nextExports, (key) => key in prevExports) !== true) {
|
|
4840
|
+
return 'Could not Fast Refresh (new export)';
|
|
4841
|
+
}
|
|
4842
|
+
let hasExports = false;
|
|
4843
|
+
const compatible = __nastiCheckExports(ignored, nextExports, (key, value) => {
|
|
4844
|
+
hasExports = true;
|
|
4845
|
+
return isLikelyComponentType(value) ||
|
|
4846
|
+
__nastiIsCompoundComponent(value) ||
|
|
4847
|
+
prevExports[key] === value;
|
|
4848
|
+
});
|
|
4849
|
+
if (!hasExports) {
|
|
4850
|
+
return 'Could not Fast Refresh (no exports)';
|
|
4851
|
+
}
|
|
4852
|
+
if (compatible === true) {
|
|
4853
|
+
__nastiEnqueueRefresh();
|
|
4854
|
+
return;
|
|
4855
|
+
}
|
|
4856
|
+
return 'Could not Fast Refresh ("' + compatible + '" export is incompatible)';
|
|
4857
|
+
}
|
|
4858
|
+
export const __hmr_import = (module) => import(module);
|
|
4859
|
+
`;
|
|
4191
4860
|
REACT_REFRESH_GLOBAL_PREAMBLE = `
|
|
4192
4861
|
import RefreshRuntime from "/@react-refresh";
|
|
4193
4862
|
RefreshRuntime.injectIntoGlobalHook(window);
|
|
@@ -4206,21 +4875,23 @@ window.__vite_plugin_react_preamble_installed__ = true;
|
|
|
4206
4875
|
async function handleFileChange(file, server) {
|
|
4207
4876
|
const { moduleGraph, ws, config } = server;
|
|
4208
4877
|
const logger = config.logger;
|
|
4209
|
-
const relativePath = "/" +
|
|
4210
|
-
const shortFile =
|
|
4878
|
+
const relativePath = "/" + import_node_path13.default.relative(config.root, file);
|
|
4879
|
+
const shortFile = import_node_path13.default.relative(config.root, file);
|
|
4211
4880
|
const mods = moduleGraph.getModulesByFile(file);
|
|
4212
4881
|
if (!mods || mods.size === 0) {
|
|
4213
4882
|
return;
|
|
4214
4883
|
}
|
|
4215
4884
|
const updates = [];
|
|
4216
4885
|
const timestamp = Date.now();
|
|
4886
|
+
const graph = moduleGraph;
|
|
4887
|
+
const invalidatedModules = /* @__PURE__ */ new Set();
|
|
4217
4888
|
for (const mod of mods) {
|
|
4218
|
-
|
|
4889
|
+
graph.invalidateModuleAndImporters(mod, timestamp, invalidatedModules);
|
|
4219
4890
|
const ctx = {
|
|
4220
4891
|
file,
|
|
4221
4892
|
timestamp,
|
|
4222
4893
|
modules: [mod],
|
|
4223
|
-
read: () =>
|
|
4894
|
+
read: () => import_node_fs10.default.readFileSync(file, "utf-8"),
|
|
4224
4895
|
server
|
|
4225
4896
|
};
|
|
4226
4897
|
let affectedModules = [mod];
|
|
@@ -4233,19 +4904,25 @@ async function handleFileChange(file, server) {
|
|
|
4233
4904
|
}
|
|
4234
4905
|
}
|
|
4235
4906
|
for (const affected of affectedModules) {
|
|
4236
|
-
|
|
4907
|
+
graph.invalidateModuleAndImporters(affected, timestamp, invalidatedModules);
|
|
4908
|
+
const boundaries = graph.getHmrBoundaries(affected);
|
|
4237
4909
|
if (boundaries.length === 0) {
|
|
4238
4910
|
logger.info(import_picocolors7.default.green("page reload ") + import_picocolors7.default.dim(shortFile), { timestamp: true });
|
|
4239
4911
|
ws.send({ type: "full-reload", path: relativePath });
|
|
4240
4912
|
return;
|
|
4241
4913
|
}
|
|
4242
|
-
for (const { boundary } of boundaries) {
|
|
4243
|
-
|
|
4914
|
+
for (const { boundary, acceptedVia } of boundaries) {
|
|
4915
|
+
const update = {
|
|
4244
4916
|
type: boundary.type === "css" ? "css-update" : "js-update",
|
|
4245
4917
|
path: boundary.url,
|
|
4246
|
-
acceptedPath:
|
|
4918
|
+
acceptedPath: acceptedVia.url,
|
|
4247
4919
|
timestamp
|
|
4248
|
-
}
|
|
4920
|
+
};
|
|
4921
|
+
if (!updates.some(
|
|
4922
|
+
(existing) => existing.type === update.type && existing.path === update.path && existing.acceptedPath === update.acceptedPath
|
|
4923
|
+
)) {
|
|
4924
|
+
updates.push(update);
|
|
4925
|
+
}
|
|
4249
4926
|
}
|
|
4250
4927
|
}
|
|
4251
4928
|
}
|
|
@@ -4257,12 +4934,12 @@ async function handleFileChange(file, server) {
|
|
|
4257
4934
|
ws.send({ type: "update", updates });
|
|
4258
4935
|
}
|
|
4259
4936
|
}
|
|
4260
|
-
var
|
|
4937
|
+
var import_node_path13, import_node_fs10, import_picocolors7;
|
|
4261
4938
|
var init_hmr = __esm({
|
|
4262
4939
|
"src/server/hmr.ts"() {
|
|
4263
4940
|
"use strict";
|
|
4264
|
-
|
|
4265
|
-
|
|
4941
|
+
import_node_path13 = __toESM(require("path"), 1);
|
|
4942
|
+
import_node_fs10 = __toESM(require("fs"), 1);
|
|
4266
4943
|
import_picocolors7 = __toESM(require("picocolors"), 1);
|
|
4267
4944
|
}
|
|
4268
4945
|
});
|
|
@@ -4281,12 +4958,12 @@ function createModuleRunner(environment) {
|
|
|
4281
4958
|
}
|
|
4282
4959
|
return new NastiModuleRunner(environment);
|
|
4283
4960
|
}
|
|
4284
|
-
var
|
|
4961
|
+
var import_node_path14, import_node_fs11, import_node_module6, import_node_url4, debug5, NODE_BUILTINS3, NastiModuleRunner, AsyncFunction;
|
|
4285
4962
|
var init_runnable_environment = __esm({
|
|
4286
4963
|
"src/server/runnable-environment.ts"() {
|
|
4287
4964
|
"use strict";
|
|
4288
|
-
|
|
4289
|
-
|
|
4965
|
+
import_node_path14 = __toESM(require("path"), 1);
|
|
4966
|
+
import_node_fs11 = __toESM(require("fs"), 1);
|
|
4290
4967
|
import_node_module6 = require("module");
|
|
4291
4968
|
import_node_url4 = require("url");
|
|
4292
4969
|
init_transformer();
|
|
@@ -4308,7 +4985,7 @@ var init_runnable_environment = __esm({
|
|
|
4308
4985
|
this.config.mode,
|
|
4309
4986
|
ssrDefineOverrides(environment.consumer)
|
|
4310
4987
|
);
|
|
4311
|
-
this.require = (0, import_node_module6.createRequire)(
|
|
4988
|
+
this.require = (0, import_node_module6.createRequire)(import_node_path14.default.join(this.config.root, "package.json"));
|
|
4312
4989
|
const handlers = {
|
|
4313
4990
|
fetchModule: async (id, importer) => this.fetchModule(id, importer),
|
|
4314
4991
|
getBuiltins: () => [/^node:/, ...import_node_module6.builtinModules]
|
|
@@ -4332,9 +5009,9 @@ var init_runnable_environment = __esm({
|
|
|
4332
5009
|
this.cache.clear();
|
|
4333
5010
|
}
|
|
4334
5011
|
resolveToId(rawUrl) {
|
|
4335
|
-
if (
|
|
5012
|
+
if (import_node_path14.default.isAbsolute(rawUrl) && import_node_fs11.default.existsSync(rawUrl.split("?")[0])) return rawUrl;
|
|
4336
5013
|
const clean = rawUrl.replace(/^\//, "");
|
|
4337
|
-
return
|
|
5014
|
+
return import_node_path14.default.resolve(this.config.root, clean);
|
|
4338
5015
|
}
|
|
4339
5016
|
/**
|
|
4340
5017
|
* fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
|
|
@@ -4343,14 +5020,14 @@ var init_runnable_environment = __esm({
|
|
|
4343
5020
|
*/
|
|
4344
5021
|
async fetchModule(id, importer) {
|
|
4345
5022
|
if (NODE_BUILTINS3.has(id)) return { externalize: id };
|
|
4346
|
-
if (!id.startsWith(".") && !
|
|
5023
|
+
if (!id.startsWith(".") && !import_node_path14.default.isAbsolute(id) && !id.startsWith("\0")) {
|
|
4347
5024
|
return { externalize: id };
|
|
4348
5025
|
}
|
|
4349
5026
|
const container = this.environment.pluginContainer;
|
|
4350
5027
|
let resolvedId = id;
|
|
4351
5028
|
if (id.startsWith(".") && importer) {
|
|
4352
5029
|
const resolved = await container.resolveId(id, importer);
|
|
4353
|
-
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id :
|
|
5030
|
+
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : import_node_path14.default.resolve(import_node_path14.default.dirname(importer.split("?")[0]), id);
|
|
4354
5031
|
}
|
|
4355
5032
|
resolvedId = this.completeExtension(resolvedId);
|
|
4356
5033
|
const cleanId = resolvedId.split("?")[0];
|
|
@@ -4358,8 +5035,8 @@ var init_runnable_environment = __esm({
|
|
|
4358
5035
|
const loaded = await container.load(resolvedId);
|
|
4359
5036
|
if (loaded != null) {
|
|
4360
5037
|
code = typeof loaded === "string" ? loaded : loaded.code;
|
|
4361
|
-
} else if (
|
|
4362
|
-
code =
|
|
5038
|
+
} else if (import_node_fs11.default.existsSync(cleanId)) {
|
|
5039
|
+
code = import_node_fs11.default.readFileSync(cleanId, "utf-8");
|
|
4363
5040
|
} else {
|
|
4364
5041
|
throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
|
|
4365
5042
|
}
|
|
@@ -4392,19 +5069,19 @@ var init_runnable_environment = __esm({
|
|
|
4392
5069
|
completeExtension(id) {
|
|
4393
5070
|
const clean = id.split("?")[0];
|
|
4394
5071
|
const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
|
|
4395
|
-
if (
|
|
5072
|
+
if (import_node_fs11.default.existsSync(clean) && import_node_fs11.default.statSync(clean).isFile()) return id;
|
|
4396
5073
|
const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
|
|
4397
5074
|
if (jsMatch) {
|
|
4398
5075
|
for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
|
|
4399
|
-
if (
|
|
5076
|
+
if (import_node_fs11.default.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
|
|
4400
5077
|
}
|
|
4401
5078
|
}
|
|
4402
5079
|
for (const ext of this.config.resolve.extensions) {
|
|
4403
|
-
if (
|
|
5080
|
+
if (import_node_fs11.default.existsSync(clean + ext)) return clean + ext + query;
|
|
4404
5081
|
}
|
|
4405
5082
|
for (const ext of this.config.resolve.extensions) {
|
|
4406
|
-
const indexPath =
|
|
4407
|
-
if (
|
|
5083
|
+
const indexPath = import_node_path14.default.join(clean, `index${ext}`);
|
|
5084
|
+
if (import_node_fs11.default.existsSync(indexPath)) return indexPath;
|
|
4408
5085
|
}
|
|
4409
5086
|
return id;
|
|
4410
5087
|
}
|
|
@@ -4431,10 +5108,10 @@ var init_runnable_environment = __esm({
|
|
|
4431
5108
|
return;
|
|
4432
5109
|
}
|
|
4433
5110
|
const ssrImport = async (dep) => {
|
|
4434
|
-
if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !
|
|
5111
|
+
if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !import_node_path14.default.isAbsolute(dep) && !dep.startsWith("\0")) {
|
|
4435
5112
|
return this.importExternal(dep);
|
|
4436
5113
|
}
|
|
4437
|
-
const depId = dep.startsWith(".") ? this.completeExtension(
|
|
5114
|
+
const depId = dep.startsWith(".") ? this.completeExtension(import_node_path14.default.resolve(import_node_path14.default.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
|
|
4438
5115
|
return this.instantiate(depId);
|
|
4439
5116
|
};
|
|
4440
5117
|
const ssrExportAll = (sourceModule) => {
|
|
@@ -4466,7 +5143,7 @@ var init_runnable_environment = __esm({
|
|
|
4466
5143
|
}
|
|
4467
5144
|
async importExternal(spec) {
|
|
4468
5145
|
try {
|
|
4469
|
-
return await (spec.startsWith("node:") || !
|
|
5146
|
+
return await (spec.startsWith("node:") || !import_node_path14.default.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import((0, import_node_url4.pathToFileURL)(spec).href));
|
|
4470
5147
|
} catch (err) {
|
|
4471
5148
|
throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
|
|
4472
5149
|
}
|
|
@@ -4524,7 +5201,7 @@ async function createBundledDevServer(opts) {
|
|
|
4524
5201
|
createReactRefreshRuntimePlugin(entryPoints),
|
|
4525
5202
|
createBundledOxcRefreshPlugin()
|
|
4526
5203
|
] : [],
|
|
4527
|
-
...stripCatchAllLoad(toRolldownPlugins(clientEnv.plugins)),
|
|
5204
|
+
...stripCatchAllLoad(toRolldownPlugins(clientEnv.plugins, clientEnv)),
|
|
4528
5205
|
...useReactRefresh ? [
|
|
4529
5206
|
refreshWrapperFn({
|
|
4530
5207
|
cwd: config.root,
|
|
@@ -4573,7 +5250,7 @@ async function createBundledDevServer(opts) {
|
|
|
4573
5250
|
}
|
|
4574
5251
|
const url = `/${patchPath}`;
|
|
4575
5252
|
logger.info(
|
|
4576
|
-
import_picocolors8.default.green("hmr update ") + import_picocolors8.default.dim(changedFiles.map((f) =>
|
|
5253
|
+
import_picocolors8.default.green("hmr update ") + import_picocolors8.default.dim(changedFiles.map((f) => import_node_path15.default.relative(config.root, f)).join(", ")),
|
|
4577
5254
|
{ timestamp: true }
|
|
4578
5255
|
);
|
|
4579
5256
|
sendTo(clientId, { type: "hmr:update", path: url, url });
|
|
@@ -4709,7 +5386,7 @@ async function createBundledDevServer(opts) {
|
|
|
4709
5386
|
return;
|
|
4710
5387
|
}
|
|
4711
5388
|
res.setHeader("ETag", hit.etag);
|
|
4712
|
-
res.setHeader("Content-Type", MIME_TYPES[
|
|
5389
|
+
res.setHeader("Content-Type", MIME_TYPES[import_node_path15.default.extname(fileName)] ?? "application/octet-stream");
|
|
4713
5390
|
res.setHeader("Cache-Control", "no-cache");
|
|
4714
5391
|
res.end(hit.content);
|
|
4715
5392
|
return;
|
|
@@ -4745,7 +5422,7 @@ function stripCatchAllLoad(plugins) {
|
|
|
4745
5422
|
);
|
|
4746
5423
|
}
|
|
4747
5424
|
function createReactRefreshRuntimePlugin(entryPoints) {
|
|
4748
|
-
const entryIds = new Set(entryPoints.map((p) =>
|
|
5425
|
+
const entryIds = new Set(entryPoints.map((p) => import_node_path15.default.resolve(p)));
|
|
4749
5426
|
return {
|
|
4750
5427
|
name: "nasti:bundled-react-refresh",
|
|
4751
5428
|
resolveId(source) {
|
|
@@ -4763,7 +5440,7 @@ function createReactRefreshRuntimePlugin(entryPoints) {
|
|
|
4763
5440
|
return null;
|
|
4764
5441
|
},
|
|
4765
5442
|
transform(code, id) {
|
|
4766
|
-
if (!entryIds.has(
|
|
5443
|
+
if (!entryIds.has(import_node_path15.default.resolve(id.split("?")[0]))) return null;
|
|
4767
5444
|
return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
|
|
4768
5445
|
${code}`, map: null };
|
|
4769
5446
|
}
|
|
@@ -4810,11 +5487,11 @@ async function renderBundledIndexHtml(html, config, entryFileNames) {
|
|
|
4810
5487
|
}
|
|
4811
5488
|
return processed;
|
|
4812
5489
|
}
|
|
4813
|
-
var
|
|
5490
|
+
var import_node_path15, import_node_crypto3, import_ws2, import_picocolors8, debug6, MIME_TYPES, MemoryFiles, PREAMBLE_SPEC, RESOLVED_PREAMBLE_ID, REFRESH_RUNTIME_URL, BUNDLED_PREAMBLE_CODE, WRAPPER_RUNTIME_HELPERS;
|
|
4814
5491
|
var init_dev_engine = __esm({
|
|
4815
5492
|
"src/server/bundled/dev-engine.ts"() {
|
|
4816
5493
|
"use strict";
|
|
4817
|
-
|
|
5494
|
+
import_node_path15 = __toESM(require("path"), 1);
|
|
4818
5495
|
import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
4819
5496
|
import_ws2 = require("ws");
|
|
4820
5497
|
import_picocolors8 = __toESM(require("picocolors"), 1);
|
|
@@ -4941,7 +5618,9 @@ async function createServer(inlineConfig = {}) {
|
|
|
4941
5618
|
const startTime = performance.now();
|
|
4942
5619
|
const config = await resolveConfig(inlineConfig, "serve");
|
|
4943
5620
|
const logger = config.logger;
|
|
4944
|
-
const allPlugins = resolvePluginList(config, config.plugins
|
|
5621
|
+
const allPlugins = resolvePluginList(config, config.plugins, {
|
|
5622
|
+
environmentName: "client"
|
|
5623
|
+
});
|
|
4945
5624
|
const configWithPlugins = { ...config, plugins: allPlugins };
|
|
4946
5625
|
const app = (0, import_connect.default)();
|
|
4947
5626
|
const httpServer = import_node_http.default.createServer(app);
|
|
@@ -4958,7 +5637,10 @@ async function createServer(inlineConfig = {}) {
|
|
|
4958
5637
|
for (const name of Object.keys(config.environments)) {
|
|
4959
5638
|
if (name === "client") continue;
|
|
4960
5639
|
const consumer = config.environments[name].consumer;
|
|
4961
|
-
const envPlugins = resolvePluginList(config, config.plugins, {
|
|
5640
|
+
const envPlugins = resolvePluginList(config, config.plugins, {
|
|
5641
|
+
consumer,
|
|
5642
|
+
environmentName: name
|
|
5643
|
+
});
|
|
4962
5644
|
environments[name] = new NastiEnvironment(name, config, {
|
|
4963
5645
|
mode: "dev",
|
|
4964
5646
|
plugins: envPlugins,
|
|
@@ -4993,14 +5675,14 @@ async function createServer(inlineConfig = {}) {
|
|
|
4993
5675
|
app.use(bundledServer.middleware);
|
|
4994
5676
|
}
|
|
4995
5677
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
4996
|
-
const outDirAbs =
|
|
5678
|
+
const outDirAbs = import_node_path16.default.resolve(config.root, config.build.outDir);
|
|
4997
5679
|
const watcher = (0, import_chokidar.watch)(config.root, {
|
|
4998
5680
|
ignored: (filePath) => {
|
|
4999
5681
|
if (filePath === config.root) return false;
|
|
5000
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
5001
|
-
const rel =
|
|
5002
|
-
if (!rel || rel.startsWith("..") ||
|
|
5003
|
-
for (const seg of rel.split(
|
|
5682
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path16.default.sep)) return true;
|
|
5683
|
+
const rel = import_node_path16.default.relative(config.root, filePath);
|
|
5684
|
+
if (!rel || rel.startsWith("..") || import_node_path16.default.isAbsolute(rel)) return false;
|
|
5685
|
+
for (const seg of rel.split(import_node_path16.default.sep)) {
|
|
5004
5686
|
if (ignoredSegments.has(seg)) return true;
|
|
5005
5687
|
}
|
|
5006
5688
|
return false;
|
|
@@ -5101,7 +5783,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
5101
5783
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
5102
5784
|
logger.info(
|
|
5103
5785
|
`
|
|
5104
|
-
${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.
|
|
5786
|
+
${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.4.0"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
|
|
5105
5787
|
`
|
|
5106
5788
|
);
|
|
5107
5789
|
printServerUrls(
|
|
@@ -5129,7 +5811,12 @@ async function createServer(inlineConfig = {}) {
|
|
|
5129
5811
|
},
|
|
5130
5812
|
async transformRequest(url) {
|
|
5131
5813
|
const { transformRequest: transformRequest2 } = await Promise.resolve().then(() => (init_middleware(), middleware_exports));
|
|
5132
|
-
return transformRequest2(url, {
|
|
5814
|
+
return transformRequest2(url, {
|
|
5815
|
+
config: configWithPlugins,
|
|
5816
|
+
pluginContainer,
|
|
5817
|
+
moduleGraph,
|
|
5818
|
+
onPrune: (paths) => ws.send({ type: "prune", paths })
|
|
5819
|
+
});
|
|
5133
5820
|
},
|
|
5134
5821
|
async ssrLoadModule(url) {
|
|
5135
5822
|
const runner = await getSsrRunner();
|
|
@@ -5189,9 +5876,10 @@ async function createServer(inlineConfig = {}) {
|
|
|
5189
5876
|
app.use(transformMiddleware({
|
|
5190
5877
|
config: configWithPlugins,
|
|
5191
5878
|
pluginContainer,
|
|
5192
|
-
moduleGraph
|
|
5879
|
+
moduleGraph,
|
|
5880
|
+
onPrune: (paths) => ws.send({ type: "prune", paths })
|
|
5193
5881
|
}));
|
|
5194
|
-
const publicDir =
|
|
5882
|
+
const publicDir = import_node_path16.default.resolve(config.root, "public");
|
|
5195
5883
|
app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
|
|
5196
5884
|
app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
|
|
5197
5885
|
const postMiddlewares = [];
|
|
@@ -5217,12 +5905,12 @@ function getNetworkAddress() {
|
|
|
5217
5905
|
}
|
|
5218
5906
|
return "localhost";
|
|
5219
5907
|
}
|
|
5220
|
-
var import_node_http,
|
|
5908
|
+
var import_node_http, import_node_path16, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors9;
|
|
5221
5909
|
var init_server = __esm({
|
|
5222
5910
|
"src/server/index.ts"() {
|
|
5223
5911
|
"use strict";
|
|
5224
5912
|
import_node_http = __toESM(require("http"), 1);
|
|
5225
|
-
|
|
5913
|
+
import_node_path16 = __toESM(require("path"), 1);
|
|
5226
5914
|
import_node_os = __toESM(require("os"), 1);
|
|
5227
5915
|
import_connect = __toESM(require("connect"), 1);
|
|
5228
5916
|
import_sirv = __toESM(require("sirv"), 1);
|
|
@@ -5271,8 +5959,8 @@ init_config();
|
|
|
5271
5959
|
init_build();
|
|
5272
5960
|
|
|
5273
5961
|
// src/build/electron.ts
|
|
5274
|
-
var
|
|
5275
|
-
var
|
|
5962
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
5963
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
5276
5964
|
var import_rolldown2 = require("rolldown");
|
|
5277
5965
|
var import_picocolors5 = __toESM(require("picocolors"), 1);
|
|
5278
5966
|
init_config();
|
|
@@ -5318,16 +6006,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
5318
6006
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
5319
6007
|
const startTime = performance.now();
|
|
5320
6008
|
assertElectronVersion(config);
|
|
5321
|
-
console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.
|
|
6009
|
+
console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.4.0"}`));
|
|
5322
6010
|
console.log(import_picocolors5.default.dim(` root: ${config.root}`));
|
|
5323
6011
|
console.log(import_picocolors5.default.dim(` mode: ${config.mode}`));
|
|
5324
6012
|
console.log(import_picocolors5.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
5325
|
-
const outDir =
|
|
5326
|
-
if (config.build.emptyOutDir &&
|
|
5327
|
-
|
|
6013
|
+
const outDir = import_node_path11.default.resolve(config.root, config.build.outDir);
|
|
6014
|
+
if (config.build.emptyOutDir && import_node_fs8.default.existsSync(outDir)) {
|
|
6015
|
+
import_node_fs8.default.rmSync(outDir, { recursive: true, force: true });
|
|
5328
6016
|
}
|
|
5329
|
-
|
|
5330
|
-
const rendererOutDir =
|
|
6017
|
+
import_node_fs8.default.mkdirSync(outDir, { recursive: true });
|
|
6018
|
+
const rendererOutDir = import_node_path11.default.join(outDir, "renderer");
|
|
5331
6019
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
5332
6020
|
await build2(createElectronRendererConfig(config, inlineConfig, {
|
|
5333
6021
|
build: {
|
|
@@ -5336,8 +6024,8 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
5336
6024
|
emptyOutDir: false
|
|
5337
6025
|
}
|
|
5338
6026
|
}));
|
|
5339
|
-
const mainEntry =
|
|
5340
|
-
if (!
|
|
6027
|
+
const mainEntry = import_node_path11.default.resolve(config.root, config.electron.main);
|
|
6028
|
+
if (!import_node_fs8.default.existsSync(mainEntry)) {
|
|
5341
6029
|
throw new Error(
|
|
5342
6030
|
`Electron main entry not found: ${config.electron.main}
|
|
5343
6031
|
\u5728 nasti.config.ts \u7684 electron.main \u6307\u5B9A\u4E3B\u8FDB\u7A0B\u5165\u53E3\u6587\u4EF6\u3002`
|
|
@@ -5351,11 +6039,11 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
5351
6039
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
5352
6040
|
const preloadFiles = [];
|
|
5353
6041
|
for (const entry of preloadEntries) {
|
|
5354
|
-
if (!
|
|
6042
|
+
if (!import_node_fs8.default.existsSync(entry)) {
|
|
5355
6043
|
console.warn(import_picocolors5.default.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
5356
6044
|
continue;
|
|
5357
6045
|
}
|
|
5358
|
-
const base =
|
|
6046
|
+
const base = import_node_path11.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
5359
6047
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
5360
6048
|
await bundleNode(config, entry, {
|
|
5361
6049
|
outFile: out,
|
|
@@ -5367,10 +6055,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
5367
6055
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
5368
6056
|
console.log(import_picocolors5.default.green(`
|
|
5369
6057
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
5370
|
-
console.log(import_picocolors5.default.dim(` renderer: ${
|
|
5371
|
-
console.log(import_picocolors5.default.dim(` main: ${
|
|
6058
|
+
console.log(import_picocolors5.default.dim(` renderer: ${import_node_path11.default.relative(config.root, rendererOutDir)}/`));
|
|
6059
|
+
console.log(import_picocolors5.default.dim(` main: ${import_node_path11.default.relative(config.root, mainFile)}`));
|
|
5372
6060
|
for (const pf of preloadFiles) {
|
|
5373
|
-
console.log(import_picocolors5.default.dim(` preload: ${
|
|
6061
|
+
console.log(import_picocolors5.default.dim(` preload: ${import_node_path11.default.relative(config.root, pf)}`));
|
|
5374
6062
|
}
|
|
5375
6063
|
console.log();
|
|
5376
6064
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -5408,7 +6096,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
5408
6096
|
},
|
|
5409
6097
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
5410
6098
|
});
|
|
5411
|
-
|
|
6099
|
+
import_node_fs8.default.mkdirSync(import_node_path11.default.dirname(opts.outFile), { recursive: true });
|
|
5412
6100
|
await bundle2.write({
|
|
5413
6101
|
sourcemap: !!config.build.sourcemap,
|
|
5414
6102
|
minify: !!config.build.minify,
|
|
@@ -5419,7 +6107,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
5419
6107
|
codeSplitting: false
|
|
5420
6108
|
});
|
|
5421
6109
|
await bundle2.close();
|
|
5422
|
-
console.log(import_picocolors5.default.dim(` \u2713 ${opts.label} \u2192 ${
|
|
6110
|
+
console.log(import_picocolors5.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path11.default.relative(config.root, opts.outFile)}`));
|
|
5423
6111
|
return opts.outFile;
|
|
5424
6112
|
}
|
|
5425
6113
|
function createElectronRendererConfig(config, inlineConfig = {}, overrides = {}) {
|
|
@@ -5443,11 +6131,11 @@ function createElectronRendererConfig(config, inlineConfig = {}, overrides = {})
|
|
|
5443
6131
|
}
|
|
5444
6132
|
function outFileName(outDir, base, format) {
|
|
5445
6133
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
5446
|
-
return
|
|
6134
|
+
return import_node_path11.default.join(outDir, base + ext);
|
|
5447
6135
|
}
|
|
5448
6136
|
function normalizePreload(preload, root) {
|
|
5449
6137
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
5450
|
-
return list.map((p) =>
|
|
6138
|
+
return list.map((p) => import_node_path11.default.resolve(root, p));
|
|
5451
6139
|
}
|
|
5452
6140
|
function assertElectronVersion(config) {
|
|
5453
6141
|
const min = config.electron.minVersion;
|
|
@@ -5462,9 +6150,9 @@ function assertElectronVersion(config) {
|
|
|
5462
6150
|
}
|
|
5463
6151
|
function detectInstalledElectron(root) {
|
|
5464
6152
|
try {
|
|
5465
|
-
const pkgPath =
|
|
5466
|
-
if (!
|
|
5467
|
-
const pkg = JSON.parse(
|
|
6153
|
+
const pkgPath = import_node_path11.default.resolve(root, "node_modules/electron/package.json");
|
|
6154
|
+
if (!import_node_fs8.default.existsSync(pkgPath)) return null;
|
|
6155
|
+
const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgPath, "utf-8"));
|
|
5468
6156
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
5469
6157
|
return Number.isFinite(major) ? major : null;
|
|
5470
6158
|
} catch {
|
|
@@ -5476,8 +6164,8 @@ function detectInstalledElectron(root) {
|
|
|
5476
6164
|
init_server();
|
|
5477
6165
|
|
|
5478
6166
|
// src/server/electron-dev.ts
|
|
5479
|
-
var
|
|
5480
|
-
var
|
|
6167
|
+
var import_node_path17 = __toESM(require("path"), 1);
|
|
6168
|
+
var import_node_fs12 = __toESM(require("fs"), 1);
|
|
5481
6169
|
var import_node_module7 = require("module");
|
|
5482
6170
|
var import_node_child_process = require("child_process");
|
|
5483
6171
|
var import_chokidar2 = __toESM(require("chokidar"), 1);
|
|
@@ -5491,7 +6179,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
5491
6179
|
const { noSpawn, ...rest } = inlineConfig;
|
|
5492
6180
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
5493
6181
|
warnElectronVersion(config);
|
|
5494
|
-
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.
|
|
6182
|
+
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.4.0"}`));
|
|
5495
6183
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
5496
6184
|
const server = await createServer2({
|
|
5497
6185
|
...rest,
|
|
@@ -5501,11 +6189,11 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
5501
6189
|
await server.listen();
|
|
5502
6190
|
const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
|
|
5503
6191
|
console.log(import_picocolors10.default.dim(` renderer: ${devUrl}`));
|
|
5504
|
-
const stageDir =
|
|
5505
|
-
|
|
5506
|
-
const mainEntry =
|
|
6192
|
+
const stageDir = import_node_path17.default.resolve(config.root, ".nasti");
|
|
6193
|
+
import_node_fs12.default.mkdirSync(stageDir, { recursive: true });
|
|
6194
|
+
const mainEntry = import_node_path17.default.resolve(config.root, config.electron.main);
|
|
5507
6195
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
5508
|
-
const builtMainFile =
|
|
6196
|
+
const builtMainFile = import_node_path17.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
5509
6197
|
const builtPreloadFiles = [];
|
|
5510
6198
|
const compileAll = async () => {
|
|
5511
6199
|
await compileNode(config, mainEntry, {
|
|
@@ -5515,9 +6203,9 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
5515
6203
|
});
|
|
5516
6204
|
builtPreloadFiles.length = 0;
|
|
5517
6205
|
for (const entry of preloadEntries) {
|
|
5518
|
-
if (!
|
|
5519
|
-
const base =
|
|
5520
|
-
const out =
|
|
6206
|
+
if (!import_node_fs12.default.existsSync(entry)) continue;
|
|
6207
|
+
const base = import_node_path17.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
6208
|
+
const out = import_node_path17.default.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
5521
6209
|
await compileNode(config, entry, {
|
|
5522
6210
|
outFile: out,
|
|
5523
6211
|
format: config.electron.preloadFormat,
|
|
@@ -5556,7 +6244,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
5556
6244
|
};
|
|
5557
6245
|
spawnElectron();
|
|
5558
6246
|
if (config.electron.autoRestart) {
|
|
5559
|
-
const watchTargets = [mainEntry, ...preloadEntries].filter(
|
|
6247
|
+
const watchTargets = [mainEntry, ...preloadEntries].filter(import_node_fs12.default.existsSync);
|
|
5560
6248
|
const watcher = import_chokidar2.default.watch(watchTargets, { ignoreInitial: true });
|
|
5561
6249
|
let restarting = null;
|
|
5562
6250
|
let pending = false;
|
|
@@ -5636,7 +6324,7 @@ async function compileNode(config, entry, opts) {
|
|
|
5636
6324
|
platform: "node",
|
|
5637
6325
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
5638
6326
|
});
|
|
5639
|
-
|
|
6327
|
+
import_node_fs12.default.mkdirSync(import_node_path17.default.dirname(opts.outFile), { recursive: true });
|
|
5640
6328
|
await bundle2.write({
|
|
5641
6329
|
file: opts.outFile,
|
|
5642
6330
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -5649,18 +6337,18 @@ async function compileNode(config, entry, opts) {
|
|
|
5649
6337
|
await bundle2.close();
|
|
5650
6338
|
}
|
|
5651
6339
|
function electronRendererDevPath(renderer) {
|
|
5652
|
-
const normalized = renderer.split(
|
|
6340
|
+
const normalized = renderer.split(import_node_path17.default.sep).join("/").replace(/^\.?\//, "");
|
|
5653
6341
|
return normalized === "index.html" ? "/" : `/${normalized}`;
|
|
5654
6342
|
}
|
|
5655
6343
|
function resolveElectronBinary(config) {
|
|
5656
|
-
if (config.electron.electronPath &&
|
|
6344
|
+
if (config.electron.electronPath && import_node_fs12.default.existsSync(config.electron.electronPath)) {
|
|
5657
6345
|
return config.electron.electronPath;
|
|
5658
6346
|
}
|
|
5659
6347
|
try {
|
|
5660
|
-
const require2 = (0, import_node_module7.createRequire)(
|
|
6348
|
+
const require2 = (0, import_node_module7.createRequire)(import_node_path17.default.resolve(config.root, "package.json"));
|
|
5661
6349
|
const pathFile = require2.resolve("electron");
|
|
5662
6350
|
const electronModule = require2(pathFile);
|
|
5663
|
-
if (typeof electronModule === "string" &&
|
|
6351
|
+
if (typeof electronModule === "string" && import_node_fs12.default.existsSync(electronModule)) {
|
|
5664
6352
|
return electronModule;
|
|
5665
6353
|
}
|
|
5666
6354
|
} catch {
|
|
@@ -5687,8 +6375,8 @@ function warnElectronVersion(config) {
|
|
|
5687
6375
|
}
|
|
5688
6376
|
|
|
5689
6377
|
// src/plugins/monaco-editor.ts
|
|
5690
|
-
var
|
|
5691
|
-
var
|
|
6378
|
+
var import_node_path18 = __toESM(require("path"), 1);
|
|
6379
|
+
var import_node_fs13 = __toESM(require("fs"), 1);
|
|
5692
6380
|
var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
5693
6381
|
var import_node_module8 = require("module");
|
|
5694
6382
|
var DEFAULT_WORKERS = {
|
|
@@ -5709,9 +6397,9 @@ function normalizePublicPath(p) {
|
|
|
5709
6397
|
}
|
|
5710
6398
|
function readMonacoVersion(root) {
|
|
5711
6399
|
try {
|
|
5712
|
-
const require2 = (0, import_node_module8.createRequire)(
|
|
6400
|
+
const require2 = (0, import_node_module8.createRequire)(import_node_path18.default.resolve(root, "package.json"));
|
|
5713
6401
|
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
5714
|
-
const pkg = JSON.parse(
|
|
6402
|
+
const pkg = JSON.parse(import_node_fs13.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
5715
6403
|
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
5716
6404
|
} catch {
|
|
5717
6405
|
return "unknown";
|
|
@@ -5731,20 +6419,20 @@ function monacoEditorPlugin(options = {}) {
|
|
|
5731
6419
|
let cacheDir = "";
|
|
5732
6420
|
const building = /* @__PURE__ */ new Map();
|
|
5733
6421
|
async function buildWorker(worker) {
|
|
5734
|
-
const cacheFile =
|
|
5735
|
-
if (
|
|
6422
|
+
const cacheFile = import_node_path18.default.join(cacheDir, `${worker.label}.worker.js`);
|
|
6423
|
+
if (import_node_fs13.default.existsSync(cacheFile)) return cacheFile;
|
|
5736
6424
|
const existing = building.get(worker.label);
|
|
5737
6425
|
if (existing) return existing;
|
|
5738
6426
|
const task = (async () => {
|
|
5739
6427
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
5740
|
-
const require2 = (0, import_node_module8.createRequire)(
|
|
6428
|
+
const require2 = (0, import_node_module8.createRequire)(import_node_path18.default.resolve(resolvedConfig.root, "package.json"));
|
|
5741
6429
|
let entry;
|
|
5742
6430
|
try {
|
|
5743
6431
|
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
5744
6432
|
} catch {
|
|
5745
6433
|
entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
|
|
5746
6434
|
}
|
|
5747
|
-
|
|
6435
|
+
import_node_fs13.default.mkdirSync(cacheDir, { recursive: true });
|
|
5748
6436
|
const bundle2 = await rolldown4({
|
|
5749
6437
|
input: entry,
|
|
5750
6438
|
platform: "browser"
|
|
@@ -5804,12 +6492,12 @@ function monacoEditorPlugin(options = {}) {
|
|
|
5804
6492
|
resolvedConfig = config;
|
|
5805
6493
|
const version = readMonacoVersion(config.root);
|
|
5806
6494
|
const key = import_node_crypto4.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
5807
|
-
cacheDir =
|
|
6495
|
+
cacheDir = import_node_path18.default.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
5808
6496
|
},
|
|
5809
6497
|
async configureServer(server) {
|
|
5810
6498
|
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
5811
6499
|
const watcher = server.watcher;
|
|
5812
|
-
const monacoDir =
|
|
6500
|
+
const monacoDir = import_node_path18.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
5813
6501
|
try {
|
|
5814
6502
|
watcher?.unwatch?.(monacoDir);
|
|
5815
6503
|
} catch {
|
|
@@ -5839,7 +6527,7 @@ function monacoEditorPlugin(options = {}) {
|
|
|
5839
6527
|
const file = await buildWorker(worker);
|
|
5840
6528
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
5841
6529
|
res.setHeader("Cache-Control", "public, max-age=604800, immutable");
|
|
5842
|
-
|
|
6530
|
+
import_node_fs13.default.createReadStream(file).pipe(res);
|
|
5843
6531
|
} catch (e) {
|
|
5844
6532
|
res.statusCode = 500;
|
|
5845
6533
|
res.end(`Monaco worker build failed: ${e.message}`);
|
|
@@ -5874,16 +6562,16 @@ self.monaco = monaco;`,
|
|
|
5874
6562
|
resolvedConfig.root,
|
|
5875
6563
|
resolvedConfig.build.outDir,
|
|
5876
6564
|
resolvedConfig.base
|
|
5877
|
-
) : isCDN(publicPath) ?
|
|
6565
|
+
) : isCDN(publicPath) ? import_node_path18.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path18.default.resolve(
|
|
5878
6566
|
resolvedConfig.root,
|
|
5879
6567
|
resolvedConfig.build.outDir,
|
|
5880
6568
|
publicPath.replace(/^\//, "")
|
|
5881
6569
|
);
|
|
5882
|
-
|
|
6570
|
+
import_node_fs13.default.mkdirSync(outDir, { recursive: true });
|
|
5883
6571
|
for (const worker of workers) {
|
|
5884
6572
|
try {
|
|
5885
6573
|
const cacheFile = await buildWorker(worker);
|
|
5886
|
-
|
|
6574
|
+
import_node_fs13.default.copyFileSync(cacheFile, import_node_path18.default.join(outDir, `${worker.label}.worker.js`));
|
|
5887
6575
|
} catch (e) {
|
|
5888
6576
|
throw new Error(
|
|
5889
6577
|
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|