@nasti-toolchain/nasti 2.4.4 → 2.5.1
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 +76 -0
- package/dist/cli.cjs +1716 -215
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1707 -206
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2160 -318
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -1
- package/dist/index.d.ts +85 -1
- package/dist/index.js +2158 -317
- package/dist/index.js.map +1 -1
- package/package.json +18 -1
package/dist/index.js
CHANGED
|
@@ -10,16 +10,25 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
10
10
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
12
|
});
|
|
13
|
-
var __glob = (map) => (
|
|
14
|
-
var fn = map[
|
|
13
|
+
var __glob = (map) => (path23) => {
|
|
14
|
+
var fn = map[path23];
|
|
15
15
|
if (fn) return fn();
|
|
16
|
-
throw new Error("Module not found in bundle: " +
|
|
16
|
+
throw new Error("Module not found in bundle: " + path23);
|
|
17
17
|
};
|
|
18
|
-
var __esm = (fn, res) => function __init() {
|
|
19
|
-
|
|
18
|
+
var __esm = (fn, res, err) => function __init() {
|
|
19
|
+
if (err) throw err[0];
|
|
20
|
+
try {
|
|
21
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw err = [e], e;
|
|
24
|
+
}
|
|
20
25
|
};
|
|
21
26
|
var __commonJS = (cb, mod) => function __require3() {
|
|
22
|
-
|
|
27
|
+
try {
|
|
28
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw mod = 0, e;
|
|
31
|
+
}
|
|
23
32
|
};
|
|
24
33
|
var __export = (target, all) => {
|
|
25
34
|
for (var name in all)
|
|
@@ -43,7 +52,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
43
52
|
));
|
|
44
53
|
|
|
45
54
|
// src/config/defaults.ts
|
|
46
|
-
var defaultResolve, defaultServer, defaultBuild, defaultElectron, defaultExperimental, defaults;
|
|
55
|
+
var defaultResolve, defaultServer, defaultBuild, defaultElectron, defaultExperimental, defaultReact, defaults;
|
|
47
56
|
var init_defaults = __esm({
|
|
48
57
|
"src/config/defaults.ts"() {
|
|
49
58
|
"use strict";
|
|
@@ -96,12 +105,20 @@ var init_defaults = __esm({
|
|
|
96
105
|
defaultExperimental = {
|
|
97
106
|
bundledDev: false
|
|
98
107
|
};
|
|
108
|
+
defaultReact = {
|
|
109
|
+
include: /\.[tj]sx?$/,
|
|
110
|
+
exclude: /node_modules/,
|
|
111
|
+
jsxImportSource: "react",
|
|
112
|
+
jsxRuntime: "automatic",
|
|
113
|
+
compiler: false
|
|
114
|
+
};
|
|
99
115
|
defaults = {
|
|
100
116
|
root: ".",
|
|
101
117
|
base: "/",
|
|
102
118
|
mode: "development",
|
|
103
119
|
target: "web",
|
|
104
120
|
framework: "auto",
|
|
121
|
+
react: defaultReact,
|
|
105
122
|
resolve: defaultResolve,
|
|
106
123
|
server: defaultServer,
|
|
107
124
|
build: defaultBuild,
|
|
@@ -136,7 +153,7 @@ function createLogger(level = "info", options = {}) {
|
|
|
136
153
|
const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
|
|
137
154
|
const clear = canClearScreen ? clearScreen : () => {
|
|
138
155
|
};
|
|
139
|
-
function
|
|
156
|
+
function format2(type, msg, options2 = {}) {
|
|
140
157
|
if (options2.timestamp) {
|
|
141
158
|
const tag = type === "info" ? pc.cyan(pc.bold(prefix)) : type === "warn" ? pc.yellow(pc.bold(prefix)) : pc.red(pc.bold(prefix));
|
|
142
159
|
return `${pc.dim(timeFormatter.format(/* @__PURE__ */ new Date()))} ${tag} ${msg}`;
|
|
@@ -153,16 +170,16 @@ function createLogger(level = "info", options = {}) {
|
|
|
153
170
|
if (type === lastType && msg === lastMsg) {
|
|
154
171
|
sameCount++;
|
|
155
172
|
clear();
|
|
156
|
-
console_[method](
|
|
173
|
+
console_[method](format2(type, msg, options2), pc.yellow(`(x${sameCount + 1})`));
|
|
157
174
|
} else {
|
|
158
175
|
sameCount = 0;
|
|
159
176
|
lastMsg = msg;
|
|
160
177
|
lastType = type;
|
|
161
178
|
if (options2.clear) clear();
|
|
162
|
-
console_[method](
|
|
179
|
+
console_[method](format2(type, msg, options2));
|
|
163
180
|
}
|
|
164
181
|
} else {
|
|
165
|
-
console_[method](
|
|
182
|
+
console_[method](format2(type, msg, options2));
|
|
166
183
|
}
|
|
167
184
|
}
|
|
168
185
|
const warnedMessages = /* @__PURE__ */ new Set();
|
|
@@ -442,6 +459,13 @@ async function resolveConfig(inlineConfig = {}, command) {
|
|
|
442
459
|
mode,
|
|
443
460
|
target: merged.target ?? defaults.target,
|
|
444
461
|
framework: (merged.framework ?? defaults.framework) === "auto" ? detectFramework(root) : merged.framework,
|
|
462
|
+
react: {
|
|
463
|
+
include: merged.react?.include ?? defaultReact.include,
|
|
464
|
+
exclude: merged.react?.exclude ?? defaultReact.exclude,
|
|
465
|
+
jsxImportSource: merged.react?.jsxImportSource ?? defaultReact.jsxImportSource,
|
|
466
|
+
jsxRuntime: merged.react?.jsxRuntime ?? defaultReact.jsxRuntime,
|
|
467
|
+
compiler: merged.react?.compiler === true ? {} : merged.react?.compiler ?? defaultReact.compiler
|
|
468
|
+
},
|
|
445
469
|
command,
|
|
446
470
|
resolve: {
|
|
447
471
|
// tsconfig paths 优先级最低:tsconfig < defaults < user config
|
|
@@ -876,27 +900,27 @@ var require_process = __commonJS({
|
|
|
876
900
|
var require_filesystem = __commonJS({
|
|
877
901
|
"node_modules/detect-libc/lib/filesystem.js"(exports, module) {
|
|
878
902
|
"use strict";
|
|
879
|
-
var
|
|
903
|
+
var fs17 = __require("fs");
|
|
880
904
|
var LDD_PATH = "/usr/bin/ldd";
|
|
881
905
|
var SELF_PATH = "/proc/self/exe";
|
|
882
906
|
var MAX_LENGTH = 2048;
|
|
883
|
-
var readFileSync = (
|
|
884
|
-
const fd =
|
|
907
|
+
var readFileSync = (path23) => {
|
|
908
|
+
const fd = fs17.openSync(path23, "r");
|
|
885
909
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
886
|
-
const bytesRead =
|
|
887
|
-
|
|
910
|
+
const bytesRead = fs17.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
911
|
+
fs17.close(fd, () => {
|
|
888
912
|
});
|
|
889
913
|
return buffer.subarray(0, bytesRead);
|
|
890
914
|
};
|
|
891
|
-
var readFile = (
|
|
892
|
-
|
|
915
|
+
var readFile = (path23) => new Promise((resolve, reject) => {
|
|
916
|
+
fs17.open(path23, "r", (err, fd) => {
|
|
893
917
|
if (err) {
|
|
894
918
|
reject(err);
|
|
895
919
|
} else {
|
|
896
920
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
897
|
-
|
|
921
|
+
fs17.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
|
|
898
922
|
resolve(buffer.subarray(0, bytesRead));
|
|
899
|
-
|
|
923
|
+
fs17.close(fd, () => {
|
|
900
924
|
});
|
|
901
925
|
});
|
|
902
926
|
}
|
|
@@ -1008,11 +1032,11 @@ var require_detect_libc = __commonJS({
|
|
|
1008
1032
|
}
|
|
1009
1033
|
return null;
|
|
1010
1034
|
};
|
|
1011
|
-
var familyFromInterpreterPath = (
|
|
1012
|
-
if (
|
|
1013
|
-
if (
|
|
1035
|
+
var familyFromInterpreterPath = (path23) => {
|
|
1036
|
+
if (path23) {
|
|
1037
|
+
if (path23.includes("/ld-musl-")) {
|
|
1014
1038
|
return MUSL;
|
|
1015
|
-
} else if (
|
|
1039
|
+
} else if (path23.includes("/ld-linux-")) {
|
|
1016
1040
|
return GLIBC;
|
|
1017
1041
|
}
|
|
1018
1042
|
}
|
|
@@ -1059,8 +1083,8 @@ var require_detect_libc = __commonJS({
|
|
|
1059
1083
|
cachedFamilyInterpreter = null;
|
|
1060
1084
|
try {
|
|
1061
1085
|
const selfContent = await readFile(SELF_PATH);
|
|
1062
|
-
const
|
|
1063
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1086
|
+
const path23 = interpreterPath(selfContent);
|
|
1087
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path23);
|
|
1064
1088
|
} catch (e) {
|
|
1065
1089
|
}
|
|
1066
1090
|
return cachedFamilyInterpreter;
|
|
@@ -1072,8 +1096,8 @@ var require_detect_libc = __commonJS({
|
|
|
1072
1096
|
cachedFamilyInterpreter = null;
|
|
1073
1097
|
try {
|
|
1074
1098
|
const selfContent = readFileSync(SELF_PATH);
|
|
1075
|
-
const
|
|
1076
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1099
|
+
const path23 = interpreterPath(selfContent);
|
|
1100
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path23);
|
|
1077
1101
|
} catch (e) {
|
|
1078
1102
|
}
|
|
1079
1103
|
return cachedFamilyInterpreter;
|
|
@@ -2174,13 +2198,88 @@ ${msg}`);
|
|
|
2174
2198
|
map: result.map ? JSON.stringify(result.map) : null
|
|
2175
2199
|
};
|
|
2176
2200
|
}
|
|
2177
|
-
|
|
2201
|
+
async function transformReactCode(filename, code, options) {
|
|
2202
|
+
if (!matchesReactFilter(filename, options.react.include, options.react.exclude)) {
|
|
2203
|
+
return null;
|
|
2204
|
+
}
|
|
2205
|
+
if (!options.react.compiler) {
|
|
2206
|
+
if (!shouldTransform(filename)) return null;
|
|
2207
|
+
return transformCode(filename, code, {
|
|
2208
|
+
sourcemap: options.sourcemap,
|
|
2209
|
+
jsxRuntime: options.react.jsxRuntime,
|
|
2210
|
+
jsxImportSource: options.react.jsxImportSource,
|
|
2211
|
+
reactRefresh: options.reactRefresh,
|
|
2212
|
+
target: options.target
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
if (!shouldTransform(filename)) return null;
|
|
2216
|
+
const compiler2 = await loadReactCompiler();
|
|
2217
|
+
const compilerOptions = options.react.compiler;
|
|
2218
|
+
const shouldCompile = options.consumer === "client" && (compilerOptions.compilationMode === "annotation" ? /['"]use memo['"]/.test(code) : defaultReactCompilerCodeFilter.test(code));
|
|
2219
|
+
const result = await compiler2.transform(cleanTransformId(filename), code, {
|
|
2220
|
+
jsx: {
|
|
2221
|
+
runtime: options.react.jsxRuntime,
|
|
2222
|
+
development: options.development,
|
|
2223
|
+
importSource: options.react.jsxImportSource,
|
|
2224
|
+
refresh: options.consumer === "client" && !!options.reactRefresh
|
|
2225
|
+
},
|
|
2226
|
+
reactCompiler: shouldCompile ? compilerOptions : false,
|
|
2227
|
+
sourcemap: options.sourcemap ?? true
|
|
2228
|
+
});
|
|
2229
|
+
const diagnostics = result.errors.map(
|
|
2230
|
+
(error) => `${error.message}${error.codeframe ? `
|
|
2231
|
+
${error.codeframe}` : ""}`
|
|
2232
|
+
);
|
|
2233
|
+
if (result.fatal) {
|
|
2234
|
+
throw new Error(
|
|
2235
|
+
diagnostics.join("\n\n") || `React Compiler transform failed for ${filename}`
|
|
2236
|
+
);
|
|
2237
|
+
}
|
|
2238
|
+
for (const diagnostic of diagnostics) options.onWarning?.(diagnostic);
|
|
2239
|
+
return {
|
|
2240
|
+
code: result.code,
|
|
2241
|
+
map: result.map ? JSON.stringify(result.map) : null
|
|
2242
|
+
};
|
|
2243
|
+
}
|
|
2244
|
+
function matchesReactFilter(id, include, exclude) {
|
|
2245
|
+
const cleanId = cleanTransformId(id);
|
|
2246
|
+
return matchesFilter(cleanId, include) && !matchesFilter(cleanId, exclude);
|
|
2247
|
+
}
|
|
2248
|
+
function matchesFilter(id, filter2) {
|
|
2249
|
+
const patterns = Array.isArray(filter2) ? filter2 : [filter2];
|
|
2250
|
+
return patterns.some((pattern) => {
|
|
2251
|
+
if (pattern instanceof RegExp) {
|
|
2252
|
+
pattern.lastIndex = 0;
|
|
2253
|
+
return pattern.test(id);
|
|
2254
|
+
}
|
|
2255
|
+
if (!pattern.includes("*")) return id.includes(pattern);
|
|
2256
|
+
const expression = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\0").replace(/\*/g, "[^/]*").replace(/\0/g, ".*");
|
|
2257
|
+
return new RegExp(`^${expression}$`).test(id);
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
function cleanTransformId(id) {
|
|
2261
|
+
return id.split(/[?#]/, 1)[0];
|
|
2262
|
+
}
|
|
2263
|
+
async function loadReactCompiler() {
|
|
2264
|
+
if (reactCompilerImplementation) return reactCompilerImplementation;
|
|
2265
|
+
try {
|
|
2266
|
+
reactCompilerImplementation = await import("oxc-transform-react");
|
|
2267
|
+
return reactCompilerImplementation;
|
|
2268
|
+
} catch (error) {
|
|
2269
|
+
throw new Error(
|
|
2270
|
+
'[nasti] React Compiler requires the optional "oxc-transform-react" package. Install it before setting react.compiler.' + (error instanceof Error ? `
|
|
2271
|
+
${error.message}` : "")
|
|
2272
|
+
);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
var JS_EXTENSIONS, TS_EXTENSIONS, JSX_EXTENSIONS, defaultReactCompilerCodeFilter, reactCompilerImplementation;
|
|
2178
2276
|
var init_transformer = __esm({
|
|
2179
2277
|
"src/core/transformer.ts"() {
|
|
2180
2278
|
"use strict";
|
|
2181
2279
|
JS_EXTENSIONS = /\.(js|mjs|cjs)$/;
|
|
2182
2280
|
TS_EXTENSIONS = /\.(ts|mts|cts)$/;
|
|
2183
2281
|
JSX_EXTENSIONS = /\.(jsx|tsx)$/;
|
|
2282
|
+
defaultReactCompilerCodeFilter = /forwardRef|memo|\b(?:[A-Z]|use[A-Z0-9])/;
|
|
2184
2283
|
}
|
|
2185
2284
|
});
|
|
2186
2285
|
|
|
@@ -2226,8 +2325,8 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2226
2325
|
let cached2 = descriptorCache.get(filePath);
|
|
2227
2326
|
if (!cached2) {
|
|
2228
2327
|
try {
|
|
2229
|
-
const
|
|
2230
|
-
const rawSource =
|
|
2328
|
+
const fs17 = await import("fs");
|
|
2329
|
+
const rawSource = fs17.readFileSync(filePath, "utf-8");
|
|
2231
2330
|
const transformedSfc = await applySourceTransform(
|
|
2232
2331
|
vueOptions.transformSfc,
|
|
2233
2332
|
rawSource,
|
|
@@ -3281,6 +3380,44 @@ var init_environment = __esm({
|
|
|
3281
3380
|
}
|
|
3282
3381
|
});
|
|
3283
3382
|
|
|
3383
|
+
// src/plugins/react.ts
|
|
3384
|
+
function reactPlugin(config, environment) {
|
|
3385
|
+
return {
|
|
3386
|
+
name: "nasti:oxc-transform",
|
|
3387
|
+
async transform(code, id) {
|
|
3388
|
+
const result = await transformReactCode(id, code, {
|
|
3389
|
+
react: config.react,
|
|
3390
|
+
consumer: environment.consumer,
|
|
3391
|
+
development: config.mode === "development",
|
|
3392
|
+
sourcemap: !!environment.options.build.sourcemap,
|
|
3393
|
+
target: environment.options.build.target,
|
|
3394
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
3395
|
+
});
|
|
3396
|
+
if (!result) return null;
|
|
3397
|
+
return {
|
|
3398
|
+
code: result.code,
|
|
3399
|
+
map: result.map ? JSON.parse(result.map) : void 0
|
|
3400
|
+
};
|
|
3401
|
+
},
|
|
3402
|
+
handleHotUpdate(ctx) {
|
|
3403
|
+
for (const mod of ctx.modules) {
|
|
3404
|
+
if (REACT_FILE_RE.test(mod.url) && matchesReactFilter(mod.url, config.react.include, config.react.exclude)) {
|
|
3405
|
+
mod.isSelfAccepting = true;
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
return ctx.modules;
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
var REACT_FILE_RE;
|
|
3413
|
+
var init_react = __esm({
|
|
3414
|
+
"src/plugins/react.ts"() {
|
|
3415
|
+
"use strict";
|
|
3416
|
+
init_transformer();
|
|
3417
|
+
REACT_FILE_RE = /\.[jt]sx(?:[?#].*)?$/;
|
|
3418
|
+
}
|
|
3419
|
+
});
|
|
3420
|
+
|
|
3284
3421
|
// src/core/env.ts
|
|
3285
3422
|
import path7 from "path";
|
|
3286
3423
|
import fs5 from "fs";
|
|
@@ -3641,7 +3778,7 @@ function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
|
|
|
3641
3778
|
// 相对/绝对/虚拟模块照常打包。需要内联依赖时经 rolldownOptions.external 覆盖。
|
|
3642
3779
|
external: restInputOptions.external ?? ((id) => {
|
|
3643
3780
|
if (NODE_BUILTINS.has(id)) return true;
|
|
3644
|
-
return !id.startsWith(".") && !path10.isAbsolute(id) && !id.startsWith("\0");
|
|
3781
|
+
return !id.startsWith(".") && !path10.isAbsolute(id) && !id.startsWith("\0") && !id.startsWith("virtual:");
|
|
3645
3782
|
})
|
|
3646
3783
|
} : {}
|
|
3647
3784
|
};
|
|
@@ -3864,6 +4001,7 @@ function resolveClientEntries(config, html) {
|
|
|
3864
4001
|
return entryPoints;
|
|
3865
4002
|
}
|
|
3866
4003
|
function createOxcTransformPlugin(config, environment) {
|
|
4004
|
+
if (config.framework === "react") return reactPlugin(config, environment);
|
|
3867
4005
|
return {
|
|
3868
4006
|
name: "nasti:oxc-transform",
|
|
3869
4007
|
transform(code, id) {
|
|
@@ -3884,7 +4022,7 @@ async function build(inlineConfig = {}) {
|
|
|
3884
4022
|
const startTime = performance.now();
|
|
3885
4023
|
logger.info(
|
|
3886
4024
|
pc4.cyan(`
|
|
3887
|
-
nasti v${"2.
|
|
4025
|
+
nasti v${"2.5.1"} `) + pc4.green(`building for ${config.mode}...`)
|
|
3888
4026
|
);
|
|
3889
4027
|
debug5?.(`root: ${config.root}`);
|
|
3890
4028
|
const buildableNames = Object.keys(config.environments).filter((name) => {
|
|
@@ -4166,6 +4304,7 @@ var init_build = __esm({
|
|
|
4166
4304
|
init_environment();
|
|
4167
4305
|
init_css_engine();
|
|
4168
4306
|
init_html();
|
|
4307
|
+
init_react();
|
|
4169
4308
|
init_transformer();
|
|
4170
4309
|
init_env();
|
|
4171
4310
|
init_reporter();
|
|
@@ -4618,22 +4757,35 @@ async function transformRequest(url, ctx) {
|
|
|
4618
4757
|
}
|
|
4619
4758
|
const stableUrl = cleanReqUrl;
|
|
4620
4759
|
let wrappedWithRefresh = false;
|
|
4621
|
-
if (
|
|
4622
|
-
const
|
|
4623
|
-
const useRefresh =
|
|
4760
|
+
if (config.framework === "react") {
|
|
4761
|
+
const refreshEnabled = (ctx.environment?.consumer ?? "client") === "client" && config.server.hmr !== false;
|
|
4762
|
+
const useRefresh = refreshEnabled && (!!config.react.compiler || /\.[jt]sx$/.test(filePath));
|
|
4763
|
+
const result = await transformReactCode(filePath, code, {
|
|
4764
|
+
react: config.react,
|
|
4765
|
+
consumer: ctx.environment?.consumer ?? "client",
|
|
4766
|
+
development: true,
|
|
4767
|
+
reactRefresh: useRefresh,
|
|
4768
|
+
sourcemap: true,
|
|
4769
|
+
target: ctx.environment?.options.build.target ?? config.build.target,
|
|
4770
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
4771
|
+
});
|
|
4772
|
+
if (result) {
|
|
4773
|
+
code = result.code;
|
|
4774
|
+
if (result.map) map = JSON.parse(result.map);
|
|
4775
|
+
if (useRefresh) {
|
|
4776
|
+
code = buildReactRefreshWrapper(stableUrl, code);
|
|
4777
|
+
wrappedWithRefresh = true;
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
} else if (shouldTransform(filePath)) {
|
|
4624
4781
|
const result = transformCode(filePath, code, {
|
|
4625
4782
|
sourcemap: true,
|
|
4626
4783
|
jsxRuntime: "automatic",
|
|
4627
|
-
jsxImportSource:
|
|
4628
|
-
reactRefresh: useRefresh,
|
|
4784
|
+
jsxImportSource: "vue",
|
|
4629
4785
|
target: ctx.environment?.options.build.target ?? config.build.target
|
|
4630
4786
|
});
|
|
4631
4787
|
code = result.code;
|
|
4632
4788
|
if (result.map) map = JSON.parse(result.map);
|
|
4633
|
-
if (useRefresh) {
|
|
4634
|
-
code = buildReactRefreshWrapper(stableUrl, code);
|
|
4635
|
-
wrappedWithRefresh = true;
|
|
4636
|
-
}
|
|
4637
4789
|
}
|
|
4638
4790
|
const hotInfo = rewriteHotAcceptDeps(code, config, filePath);
|
|
4639
4791
|
code = hotInfo.code;
|
|
@@ -4844,8 +4996,8 @@ function rewriteExternalRequires(code, baseDir, root) {
|
|
|
4844
4996
|
}
|
|
4845
4997
|
async function injectCjsNamedExports(code, entryFile) {
|
|
4846
4998
|
try {
|
|
4847
|
-
const { createRequire:
|
|
4848
|
-
const req =
|
|
4999
|
+
const { createRequire: createRequire7 } = await import("module");
|
|
5000
|
+
const req = createRequire7(entryFile);
|
|
4849
5001
|
const cjsExports = req(entryFile);
|
|
4850
5002
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
4851
5003
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
@@ -5696,223 +5848,1555 @@ var init_hmr = __esm({
|
|
|
5696
5848
|
}
|
|
5697
5849
|
});
|
|
5698
5850
|
|
|
5699
|
-
//
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
})
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5851
|
+
// node_modules/import-meta-resolve/lib/errors.js
|
|
5852
|
+
import v8 from "v8";
|
|
5853
|
+
import assert from "assert";
|
|
5854
|
+
import { format, inspect } from "util";
|
|
5855
|
+
function formatList(array, type = "and") {
|
|
5856
|
+
return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array[array.length - 1]}`;
|
|
5857
|
+
}
|
|
5858
|
+
function createError(sym, value, constructor) {
|
|
5859
|
+
messages.set(sym, value);
|
|
5860
|
+
return makeNodeErrorWithCode(constructor, sym);
|
|
5861
|
+
}
|
|
5862
|
+
function makeNodeErrorWithCode(Base, key) {
|
|
5863
|
+
return NodeError;
|
|
5864
|
+
function NodeError(...parameters) {
|
|
5865
|
+
const limit = Error.stackTraceLimit;
|
|
5866
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
5867
|
+
const error = new Base();
|
|
5868
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
5869
|
+
const message = getMessage(key, parameters, error);
|
|
5870
|
+
Object.defineProperties(error, {
|
|
5871
|
+
// Note: no need to implement `kIsNodeError` symbol, would be hard,
|
|
5872
|
+
// probably.
|
|
5873
|
+
message: {
|
|
5874
|
+
value: message,
|
|
5875
|
+
enumerable: false,
|
|
5876
|
+
writable: true,
|
|
5877
|
+
configurable: true
|
|
5878
|
+
},
|
|
5879
|
+
toString: {
|
|
5880
|
+
/** @this {Error} */
|
|
5881
|
+
value() {
|
|
5882
|
+
return `${this.name} [${key}]: ${this.message}`;
|
|
5883
|
+
},
|
|
5884
|
+
enumerable: false,
|
|
5885
|
+
writable: true,
|
|
5886
|
+
configurable: true
|
|
5887
|
+
}
|
|
5888
|
+
});
|
|
5889
|
+
captureLargerStackTrace(error);
|
|
5890
|
+
error.code = key;
|
|
5891
|
+
return error;
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
function isErrorStackTraceLimitWritable() {
|
|
5895
|
+
try {
|
|
5896
|
+
if (v8.startupSnapshot.isBuildingSnapshot()) {
|
|
5897
|
+
return false;
|
|
5898
|
+
}
|
|
5899
|
+
} catch {
|
|
5900
|
+
}
|
|
5901
|
+
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
5902
|
+
if (desc === void 0) {
|
|
5903
|
+
return Object.isExtensible(Error);
|
|
5904
|
+
}
|
|
5905
|
+
return own.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
|
|
5906
|
+
}
|
|
5907
|
+
function hideStackFrames(wrappedFunction) {
|
|
5908
|
+
const hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
5909
|
+
Object.defineProperty(wrappedFunction, "name", { value: hidden });
|
|
5910
|
+
return wrappedFunction;
|
|
5911
|
+
}
|
|
5912
|
+
function getMessage(key, parameters, self) {
|
|
5913
|
+
const message = messages.get(key);
|
|
5914
|
+
assert.ok(message !== void 0, "expected `message` to be found");
|
|
5915
|
+
if (typeof message === "function") {
|
|
5916
|
+
assert.ok(
|
|
5917
|
+
message.length <= parameters.length,
|
|
5918
|
+
// Default options do not count.
|
|
5919
|
+
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
|
|
5713
5920
|
);
|
|
5921
|
+
return Reflect.apply(message, self, parameters);
|
|
5922
|
+
}
|
|
5923
|
+
const regex = /%[dfijoOs]/g;
|
|
5924
|
+
let expectedLength = 0;
|
|
5925
|
+
while (regex.exec(message) !== null) expectedLength++;
|
|
5926
|
+
assert.ok(
|
|
5927
|
+
expectedLength === parameters.length,
|
|
5928
|
+
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
|
|
5929
|
+
);
|
|
5930
|
+
if (parameters.length === 0) return message;
|
|
5931
|
+
parameters.unshift(message);
|
|
5932
|
+
return Reflect.apply(format, null, parameters);
|
|
5933
|
+
}
|
|
5934
|
+
function determineSpecificType(value) {
|
|
5935
|
+
if (value === null || value === void 0) {
|
|
5936
|
+
return String(value);
|
|
5714
5937
|
}
|
|
5715
|
-
|
|
5938
|
+
if (typeof value === "function" && value.name) {
|
|
5939
|
+
return `function ${value.name}`;
|
|
5940
|
+
}
|
|
5941
|
+
if (typeof value === "object") {
|
|
5942
|
+
if (value.constructor && value.constructor.name) {
|
|
5943
|
+
return `an instance of ${value.constructor.name}`;
|
|
5944
|
+
}
|
|
5945
|
+
return `${inspect(value, { depth: -1 })}`;
|
|
5946
|
+
}
|
|
5947
|
+
let inspected = inspect(value, { colors: false });
|
|
5948
|
+
if (inspected.length > 28) {
|
|
5949
|
+
inspected = `${inspected.slice(0, 25)}...`;
|
|
5950
|
+
}
|
|
5951
|
+
return `type ${typeof value} (${inspected})`;
|
|
5716
5952
|
}
|
|
5717
|
-
var
|
|
5718
|
-
var
|
|
5719
|
-
"
|
|
5953
|
+
var own, classRegExp, kTypes, codes, messages, nodeInternalPrefix, userStackTraceLimit, captureLargerStackTrace;
|
|
5954
|
+
var init_errors = __esm({
|
|
5955
|
+
"node_modules/import-meta-resolve/lib/errors.js"() {
|
|
5720
5956
|
"use strict";
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
this.require = createRequire5(path15.join(this.config.root, "package.json"));
|
|
5741
|
-
const handlers = {
|
|
5742
|
-
fetchModule: async (id, importer) => this.fetchModule(id, importer),
|
|
5743
|
-
getBuiltins: () => [/^node:/, ...builtinModules3]
|
|
5744
|
-
};
|
|
5745
|
-
environment.hot.setInvokeHandler?.(handlers);
|
|
5746
|
-
}
|
|
5747
|
-
/** 入口:加载并执行一个模块(url 为根相对或绝对路径) */
|
|
5748
|
-
async import(rawUrl) {
|
|
5749
|
-
const id = this.resolveToId(rawUrl);
|
|
5750
|
-
return this.instantiate(id);
|
|
5751
|
-
}
|
|
5752
|
-
/** 文件变更时按文件失效(含其所属的虚拟子模块) */
|
|
5753
|
-
invalidateFile(file) {
|
|
5754
|
-
for (const key of [...this.cache.keys()]) {
|
|
5755
|
-
if (key === file || key.startsWith(file + "?")) {
|
|
5756
|
-
this.cache.delete(key);
|
|
5757
|
-
}
|
|
5758
|
-
}
|
|
5759
|
-
}
|
|
5760
|
-
invalidateAll() {
|
|
5761
|
-
this.cache.clear();
|
|
5762
|
-
}
|
|
5763
|
-
resolveToId(rawUrl) {
|
|
5764
|
-
if (path15.isAbsolute(rawUrl) && fs12.existsSync(rawUrl.split("?")[0])) return rawUrl;
|
|
5765
|
-
const clean = rawUrl.replace(/^\//, "");
|
|
5766
|
-
return path15.resolve(this.config.root, clean);
|
|
5767
|
-
}
|
|
5957
|
+
own = {}.hasOwnProperty;
|
|
5958
|
+
classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
5959
|
+
kTypes = /* @__PURE__ */ new Set([
|
|
5960
|
+
"string",
|
|
5961
|
+
"function",
|
|
5962
|
+
"number",
|
|
5963
|
+
"object",
|
|
5964
|
+
// Accept 'Function' and 'Object' as alternative to the lower cased version.
|
|
5965
|
+
"Function",
|
|
5966
|
+
"Object",
|
|
5967
|
+
"boolean",
|
|
5968
|
+
"bigint",
|
|
5969
|
+
"symbol"
|
|
5970
|
+
]);
|
|
5971
|
+
codes = {};
|
|
5972
|
+
messages = /* @__PURE__ */ new Map();
|
|
5973
|
+
nodeInternalPrefix = "__node_internal_";
|
|
5974
|
+
codes.ERR_INVALID_ARG_TYPE = createError(
|
|
5975
|
+
"ERR_INVALID_ARG_TYPE",
|
|
5768
5976
|
/**
|
|
5769
|
-
*
|
|
5770
|
-
*
|
|
5771
|
-
*
|
|
5977
|
+
* @param {string} name
|
|
5978
|
+
* @param {Array<string> | string} expected
|
|
5979
|
+
* @param {unknown} actual
|
|
5772
5980
|
*/
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
if (!
|
|
5776
|
-
|
|
5777
|
-
}
|
|
5778
|
-
const container = this.environment.pluginContainer;
|
|
5779
|
-
let resolvedId = id;
|
|
5780
|
-
if (id.startsWith(".") && importer) {
|
|
5781
|
-
const resolved = await container.resolveId(id, importer);
|
|
5782
|
-
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : path15.resolve(path15.dirname(importer.split("?")[0]), id);
|
|
5981
|
+
(name, expected, actual) => {
|
|
5982
|
+
assert.ok(typeof name === "string", "'name' must be a string");
|
|
5983
|
+
if (!Array.isArray(expected)) {
|
|
5984
|
+
expected = [expected];
|
|
5783
5985
|
}
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
const loaded = await container.load(resolvedId);
|
|
5788
|
-
if (loaded != null) {
|
|
5789
|
-
code = typeof loaded === "string" ? loaded : loaded.code;
|
|
5790
|
-
} else if (fs12.existsSync(cleanId)) {
|
|
5791
|
-
code = fs12.readFileSync(cleanId, "utf-8");
|
|
5986
|
+
let message = "The ";
|
|
5987
|
+
if (name.endsWith(" argument")) {
|
|
5988
|
+
message += `${name} `;
|
|
5792
5989
|
} else {
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
const transformed = await container.transform(code, resolvedId);
|
|
5796
|
-
if (transformed != null) {
|
|
5797
|
-
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
5798
|
-
}
|
|
5799
|
-
if (shouldTransform(cleanId)) {
|
|
5800
|
-
const result = transformCode(cleanId, code, {
|
|
5801
|
-
sourcemap: false,
|
|
5802
|
-
target: this.environment.options.build.target,
|
|
5803
|
-
jsxRuntime: "automatic",
|
|
5804
|
-
jsxImportSource: this.config.framework === "vue" ? "vue" : "react"
|
|
5805
|
-
});
|
|
5806
|
-
code = result.code;
|
|
5990
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
5991
|
+
message += `"${name}" ${type} `;
|
|
5807
5992
|
}
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5993
|
+
message += "must be ";
|
|
5994
|
+
const types = [];
|
|
5995
|
+
const instances = [];
|
|
5996
|
+
const other = [];
|
|
5997
|
+
for (const value of expected) {
|
|
5998
|
+
assert.ok(
|
|
5999
|
+
typeof value === "string",
|
|
6000
|
+
"All expected entries have to be of type string"
|
|
5816
6001
|
);
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
if (jsMatch) {
|
|
5828
|
-
for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
|
|
5829
|
-
if (fs12.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
|
|
6002
|
+
if (kTypes.has(value)) {
|
|
6003
|
+
types.push(value.toLowerCase());
|
|
6004
|
+
} else if (classRegExp.exec(value) === null) {
|
|
6005
|
+
assert.ok(
|
|
6006
|
+
value !== "object",
|
|
6007
|
+
'The value "object" should be written as "Object"'
|
|
6008
|
+
);
|
|
6009
|
+
other.push(value);
|
|
6010
|
+
} else {
|
|
6011
|
+
instances.push(value);
|
|
5830
6012
|
}
|
|
5831
6013
|
}
|
|
5832
|
-
|
|
5833
|
-
|
|
6014
|
+
if (instances.length > 0) {
|
|
6015
|
+
const pos = types.indexOf("object");
|
|
6016
|
+
if (pos !== -1) {
|
|
6017
|
+
types.slice(pos, 1);
|
|
6018
|
+
instances.push("Object");
|
|
6019
|
+
}
|
|
5834
6020
|
}
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
6021
|
+
if (types.length > 0) {
|
|
6022
|
+
message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(
|
|
6023
|
+
types,
|
|
6024
|
+
"or"
|
|
6025
|
+
)}`;
|
|
6026
|
+
if (instances.length > 0 || other.length > 0) message += " or ";
|
|
5838
6027
|
}
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
const cached2 = this.cache.get(id);
|
|
5843
|
-
if (cached2) return cached2.promise ?? Promise.resolve(cached2.exports);
|
|
5844
|
-
const entry = { exports: {}, promise: null };
|
|
5845
|
-
this.cache.set(id, entry);
|
|
5846
|
-
entry.promise = this.evaluate(id, entry).then(() => {
|
|
5847
|
-
entry.promise = null;
|
|
5848
|
-
return entry.exports;
|
|
5849
|
-
}).catch((err) => {
|
|
5850
|
-
this.cache.delete(id);
|
|
5851
|
-
throw err;
|
|
5852
|
-
});
|
|
5853
|
-
return entry.promise;
|
|
5854
|
-
}
|
|
5855
|
-
async evaluate(id, entry) {
|
|
5856
|
-
const fetched = await this.fetchModule(id);
|
|
5857
|
-
if ("externalize" in fetched) {
|
|
5858
|
-
const spec = fetched.externalize;
|
|
5859
|
-
const mod = await this.importExternal(spec);
|
|
5860
|
-
entry.exports = mod;
|
|
5861
|
-
return;
|
|
6028
|
+
if (instances.length > 0) {
|
|
6029
|
+
message += `an instance of ${formatList(instances, "or")}`;
|
|
6030
|
+
if (other.length > 0) message += " or ";
|
|
5862
6031
|
}
|
|
5863
|
-
|
|
5864
|
-
if (
|
|
5865
|
-
|
|
5866
|
-
}
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
};
|
|
5870
|
-
const ssrExportAll = (sourceModule) => {
|
|
5871
|
-
for (const key of Object.keys(sourceModule)) {
|
|
5872
|
-
if (key !== "default" && !(key in entry.exports)) {
|
|
5873
|
-
Object.defineProperty(entry.exports, key, {
|
|
5874
|
-
enumerable: true,
|
|
5875
|
-
configurable: true,
|
|
5876
|
-
get: () => sourceModule[key]
|
|
5877
|
-
});
|
|
5878
|
-
}
|
|
6032
|
+
if (other.length > 0) {
|
|
6033
|
+
if (other.length > 1) {
|
|
6034
|
+
message += `one of ${formatList(other, "or")}`;
|
|
6035
|
+
} else {
|
|
6036
|
+
if (other[0].toLowerCase() !== other[0]) message += "an ";
|
|
6037
|
+
message += `${other[0]}`;
|
|
5879
6038
|
}
|
|
5880
|
-
};
|
|
5881
|
-
const importMeta = {
|
|
5882
|
-
url: pathToFileURL4(fetched.id.split("?")[0]).href,
|
|
5883
|
-
env: { SSR: true, MODE: this.config.mode, DEV: this.config.mode !== "production", PROD: this.config.mode === "production" },
|
|
5884
|
-
hot: void 0
|
|
5885
|
-
};
|
|
5886
|
-
const fn = new AsyncFunction(
|
|
5887
|
-
"__vite_ssr_exports__",
|
|
5888
|
-
"__vite_ssr_import__",
|
|
5889
|
-
"__vite_ssr_dynamic_import__",
|
|
5890
|
-
"__vite_ssr_exportAll__",
|
|
5891
|
-
"__vite_ssr_import_meta__",
|
|
5892
|
-
`"use strict";${fetched.code}
|
|
5893
|
-
//# sourceURL=${fetched.id}`
|
|
5894
|
-
);
|
|
5895
|
-
await fn(entry.exports, ssrImport, ssrImport, ssrExportAll, importMeta);
|
|
5896
|
-
}
|
|
5897
|
-
async importExternal(spec) {
|
|
5898
|
-
try {
|
|
5899
|
-
return await (spec.startsWith("node:") || !path15.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import(pathToFileURL4(spec).href));
|
|
5900
|
-
} catch (err) {
|
|
5901
|
-
throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
|
|
5902
|
-
}
|
|
5903
|
-
}
|
|
5904
|
-
/** bare specifier → 项目 node_modules 的绝对 URL(避免相对 Nasti 自身解析) */
|
|
5905
|
-
resolveExternalSpecifier(spec) {
|
|
5906
|
-
if (spec.startsWith("node:")) return spec;
|
|
5907
|
-
if (NODE_BUILTINS3.has(spec)) return `node:${spec}`;
|
|
5908
|
-
try {
|
|
5909
|
-
return pathToFileURL4(this.require.resolve(spec)).href;
|
|
5910
|
-
} catch {
|
|
5911
|
-
return spec;
|
|
5912
6039
|
}
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
6040
|
+
message += `. Received ${determineSpecificType(actual)}`;
|
|
6041
|
+
return message;
|
|
6042
|
+
},
|
|
6043
|
+
TypeError
|
|
6044
|
+
);
|
|
6045
|
+
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
6046
|
+
"ERR_INVALID_MODULE_SPECIFIER",
|
|
6047
|
+
/**
|
|
6048
|
+
* @param {string} request
|
|
6049
|
+
* @param {string} reason
|
|
6050
|
+
* @param {string} [base]
|
|
6051
|
+
*/
|
|
6052
|
+
(request, reason, base = void 0) => {
|
|
6053
|
+
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
|
|
6054
|
+
},
|
|
6055
|
+
TypeError
|
|
6056
|
+
);
|
|
6057
|
+
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
6058
|
+
"ERR_INVALID_PACKAGE_CONFIG",
|
|
6059
|
+
/**
|
|
6060
|
+
* @param {string} path
|
|
6061
|
+
* @param {string} [base]
|
|
6062
|
+
* @param {string} [message]
|
|
6063
|
+
*/
|
|
6064
|
+
(path23, base, message) => {
|
|
6065
|
+
return `Invalid package config ${path23}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
6066
|
+
},
|
|
6067
|
+
Error
|
|
6068
|
+
);
|
|
6069
|
+
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
6070
|
+
"ERR_INVALID_PACKAGE_TARGET",
|
|
6071
|
+
/**
|
|
6072
|
+
* @param {string} packagePath
|
|
6073
|
+
* @param {string} key
|
|
6074
|
+
* @param {unknown} target
|
|
6075
|
+
* @param {boolean} [isImport=false]
|
|
6076
|
+
* @param {string} [base]
|
|
6077
|
+
*/
|
|
6078
|
+
(packagePath, key, target, isImport = false, base = void 0) => {
|
|
6079
|
+
const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
6080
|
+
if (key === ".") {
|
|
6081
|
+
assert.ok(isImport === false);
|
|
6082
|
+
return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
6083
|
+
}
|
|
6084
|
+
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
|
|
6085
|
+
target
|
|
6086
|
+
)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
6087
|
+
},
|
|
6088
|
+
Error
|
|
6089
|
+
);
|
|
6090
|
+
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
6091
|
+
"ERR_MODULE_NOT_FOUND",
|
|
6092
|
+
/**
|
|
6093
|
+
* @param {string} path
|
|
6094
|
+
* @param {string} base
|
|
6095
|
+
* @param {boolean} [exactUrl]
|
|
6096
|
+
*/
|
|
6097
|
+
(path23, base, exactUrl = false) => {
|
|
6098
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path23}' imported from ${base}`;
|
|
6099
|
+
},
|
|
6100
|
+
Error
|
|
6101
|
+
);
|
|
6102
|
+
codes.ERR_NETWORK_IMPORT_DISALLOWED = createError(
|
|
6103
|
+
"ERR_NETWORK_IMPORT_DISALLOWED",
|
|
6104
|
+
"import of '%s' by %s is not supported: %s",
|
|
6105
|
+
Error
|
|
6106
|
+
);
|
|
6107
|
+
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
6108
|
+
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
|
|
6109
|
+
/**
|
|
6110
|
+
* @param {string} specifier
|
|
6111
|
+
* @param {string} packagePath
|
|
6112
|
+
* @param {string} base
|
|
6113
|
+
*/
|
|
6114
|
+
(specifier, packagePath, base) => {
|
|
6115
|
+
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
|
|
6116
|
+
},
|
|
6117
|
+
TypeError
|
|
6118
|
+
);
|
|
6119
|
+
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
6120
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
6121
|
+
/**
|
|
6122
|
+
* @param {string} packagePath
|
|
6123
|
+
* @param {string} subpath
|
|
6124
|
+
* @param {string} [base]
|
|
6125
|
+
*/
|
|
6126
|
+
(packagePath, subpath, base = void 0) => {
|
|
6127
|
+
if (subpath === ".")
|
|
6128
|
+
return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
6129
|
+
return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
6130
|
+
},
|
|
6131
|
+
Error
|
|
6132
|
+
);
|
|
6133
|
+
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
|
|
6134
|
+
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
6135
|
+
"Directory import '%s' is not supported resolving ES modules imported from %s",
|
|
6136
|
+
Error
|
|
6137
|
+
);
|
|
6138
|
+
codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(
|
|
6139
|
+
"ERR_UNSUPPORTED_RESOLVE_REQUEST",
|
|
6140
|
+
'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.',
|
|
6141
|
+
TypeError
|
|
6142
|
+
);
|
|
6143
|
+
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
6144
|
+
"ERR_UNKNOWN_FILE_EXTENSION",
|
|
6145
|
+
/**
|
|
6146
|
+
* @param {string} extension
|
|
6147
|
+
* @param {string} path
|
|
6148
|
+
*/
|
|
6149
|
+
(extension, path23) => {
|
|
6150
|
+
return `Unknown file extension "${extension}" for ${path23}`;
|
|
6151
|
+
},
|
|
6152
|
+
TypeError
|
|
6153
|
+
);
|
|
6154
|
+
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
6155
|
+
"ERR_INVALID_ARG_VALUE",
|
|
6156
|
+
/**
|
|
6157
|
+
* @param {string} name
|
|
6158
|
+
* @param {unknown} value
|
|
6159
|
+
* @param {string} [reason='is invalid']
|
|
6160
|
+
*/
|
|
6161
|
+
(name, value, reason = "is invalid") => {
|
|
6162
|
+
let inspected = inspect(value);
|
|
6163
|
+
if (inspected.length > 128) {
|
|
6164
|
+
inspected = `${inspected.slice(0, 128)}...`;
|
|
6165
|
+
}
|
|
6166
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
6167
|
+
return `The ${type} '${name}' ${reason}. Received ${inspected}`;
|
|
6168
|
+
},
|
|
6169
|
+
TypeError
|
|
6170
|
+
// Note: extra classes have been shaken out.
|
|
6171
|
+
// , RangeError
|
|
6172
|
+
);
|
|
6173
|
+
captureLargerStackTrace = hideStackFrames(
|
|
6174
|
+
/**
|
|
6175
|
+
* @param {Error} error
|
|
6176
|
+
* @returns {Error}
|
|
6177
|
+
*/
|
|
6178
|
+
// @ts-expect-error: fine
|
|
6179
|
+
function(error) {
|
|
6180
|
+
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
6181
|
+
if (stackTraceLimitIsWritable) {
|
|
6182
|
+
userStackTraceLimit = Error.stackTraceLimit;
|
|
6183
|
+
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
6184
|
+
}
|
|
6185
|
+
Error.captureStackTrace(error);
|
|
6186
|
+
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
6187
|
+
return error;
|
|
6188
|
+
}
|
|
6189
|
+
);
|
|
6190
|
+
}
|
|
6191
|
+
});
|
|
6192
|
+
|
|
6193
|
+
// node_modules/import-meta-resolve/lib/package-json-reader.js
|
|
6194
|
+
import fs12 from "fs";
|
|
6195
|
+
import path15 from "path";
|
|
6196
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
6197
|
+
function read(jsonPath, { base, specifier }) {
|
|
6198
|
+
const existing = cache.get(jsonPath);
|
|
6199
|
+
if (existing) {
|
|
6200
|
+
return existing;
|
|
6201
|
+
}
|
|
6202
|
+
let string;
|
|
6203
|
+
try {
|
|
6204
|
+
string = fs12.readFileSync(path15.toNamespacedPath(jsonPath), "utf8");
|
|
6205
|
+
} catch (error) {
|
|
6206
|
+
const exception = (
|
|
6207
|
+
/** @type {ErrnoException} */
|
|
6208
|
+
error
|
|
6209
|
+
);
|
|
6210
|
+
if (exception.code !== "ENOENT") {
|
|
6211
|
+
throw exception;
|
|
6212
|
+
}
|
|
6213
|
+
}
|
|
6214
|
+
const result = {
|
|
6215
|
+
exists: false,
|
|
6216
|
+
pjsonPath: jsonPath,
|
|
6217
|
+
main: void 0,
|
|
6218
|
+
name: void 0,
|
|
6219
|
+
type: "none",
|
|
6220
|
+
// Ignore unknown types for forwards compatibility
|
|
6221
|
+
exports: void 0,
|
|
6222
|
+
imports: void 0
|
|
6223
|
+
};
|
|
6224
|
+
if (string !== void 0) {
|
|
6225
|
+
let parsed;
|
|
6226
|
+
try {
|
|
6227
|
+
parsed = JSON.parse(string);
|
|
6228
|
+
} catch (error_) {
|
|
6229
|
+
const cause = (
|
|
6230
|
+
/** @type {ErrnoException} */
|
|
6231
|
+
error_
|
|
6232
|
+
);
|
|
6233
|
+
const error = new ERR_INVALID_PACKAGE_CONFIG(
|
|
6234
|
+
jsonPath,
|
|
6235
|
+
(base ? `"${specifier}" from ` : "") + fileURLToPath2(base || specifier),
|
|
6236
|
+
cause.message
|
|
6237
|
+
);
|
|
6238
|
+
error.cause = cause;
|
|
6239
|
+
throw error;
|
|
6240
|
+
}
|
|
6241
|
+
result.exists = true;
|
|
6242
|
+
if (hasOwnProperty.call(parsed, "name") && typeof parsed.name === "string") {
|
|
6243
|
+
result.name = parsed.name;
|
|
6244
|
+
}
|
|
6245
|
+
if (hasOwnProperty.call(parsed, "main") && typeof parsed.main === "string") {
|
|
6246
|
+
result.main = parsed.main;
|
|
6247
|
+
}
|
|
6248
|
+
if (hasOwnProperty.call(parsed, "exports")) {
|
|
6249
|
+
result.exports = parsed.exports;
|
|
6250
|
+
}
|
|
6251
|
+
if (hasOwnProperty.call(parsed, "imports")) {
|
|
6252
|
+
result.imports = parsed.imports;
|
|
6253
|
+
}
|
|
6254
|
+
if (hasOwnProperty.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) {
|
|
6255
|
+
result.type = parsed.type;
|
|
6256
|
+
}
|
|
6257
|
+
}
|
|
6258
|
+
cache.set(jsonPath, result);
|
|
6259
|
+
return result;
|
|
6260
|
+
}
|
|
6261
|
+
function getPackageScopeConfig(resolved) {
|
|
6262
|
+
let packageJSONUrl = new URL("package.json", resolved);
|
|
6263
|
+
while (true) {
|
|
6264
|
+
const packageJSONPath2 = packageJSONUrl.pathname;
|
|
6265
|
+
if (packageJSONPath2.endsWith("node_modules/package.json")) {
|
|
6266
|
+
break;
|
|
6267
|
+
}
|
|
6268
|
+
const packageConfig = read(fileURLToPath2(packageJSONUrl), {
|
|
6269
|
+
specifier: resolved
|
|
6270
|
+
});
|
|
6271
|
+
if (packageConfig.exists) {
|
|
6272
|
+
return packageConfig;
|
|
6273
|
+
}
|
|
6274
|
+
const lastPackageJSONUrl = packageJSONUrl;
|
|
6275
|
+
packageJSONUrl = new URL("../package.json", packageJSONUrl);
|
|
6276
|
+
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
|
|
6277
|
+
break;
|
|
6278
|
+
}
|
|
6279
|
+
}
|
|
6280
|
+
const packageJSONPath = fileURLToPath2(packageJSONUrl);
|
|
6281
|
+
return {
|
|
6282
|
+
pjsonPath: packageJSONPath,
|
|
6283
|
+
exists: false,
|
|
6284
|
+
type: "none"
|
|
6285
|
+
};
|
|
6286
|
+
}
|
|
6287
|
+
function getPackageType(url) {
|
|
6288
|
+
return getPackageScopeConfig(url).type;
|
|
6289
|
+
}
|
|
6290
|
+
var hasOwnProperty, ERR_INVALID_PACKAGE_CONFIG, cache;
|
|
6291
|
+
var init_package_json_reader = __esm({
|
|
6292
|
+
"node_modules/import-meta-resolve/lib/package-json-reader.js"() {
|
|
6293
|
+
"use strict";
|
|
6294
|
+
init_errors();
|
|
6295
|
+
hasOwnProperty = {}.hasOwnProperty;
|
|
6296
|
+
({ ERR_INVALID_PACKAGE_CONFIG } = codes);
|
|
6297
|
+
cache = /* @__PURE__ */ new Map();
|
|
6298
|
+
}
|
|
6299
|
+
});
|
|
6300
|
+
|
|
6301
|
+
// node_modules/import-meta-resolve/lib/get-format.js
|
|
6302
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6303
|
+
function mimeToFormat(mime) {
|
|
6304
|
+
if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime))
|
|
6305
|
+
return "module";
|
|
6306
|
+
if (mime === "application/json") return "json";
|
|
6307
|
+
return null;
|
|
6308
|
+
}
|
|
6309
|
+
function getDataProtocolModuleFormat(parsed) {
|
|
6310
|
+
const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
|
|
6311
|
+
parsed.pathname
|
|
6312
|
+
) || [null, null, null];
|
|
6313
|
+
return mimeToFormat(mime);
|
|
6314
|
+
}
|
|
6315
|
+
function extname(url) {
|
|
6316
|
+
const pathname = url.pathname;
|
|
6317
|
+
let index2 = pathname.length;
|
|
6318
|
+
while (index2--) {
|
|
6319
|
+
const code = pathname.codePointAt(index2);
|
|
6320
|
+
if (code === 47) {
|
|
6321
|
+
return "";
|
|
6322
|
+
}
|
|
6323
|
+
if (code === 46) {
|
|
6324
|
+
return pathname.codePointAt(index2 - 1) === 47 ? "" : pathname.slice(index2);
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
return "";
|
|
6328
|
+
}
|
|
6329
|
+
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
6330
|
+
const value = extname(url);
|
|
6331
|
+
if (value === ".js") {
|
|
6332
|
+
const packageType = getPackageType(url);
|
|
6333
|
+
if (packageType !== "none") {
|
|
6334
|
+
return packageType;
|
|
6335
|
+
}
|
|
6336
|
+
return "commonjs";
|
|
6337
|
+
}
|
|
6338
|
+
if (value === "") {
|
|
6339
|
+
const packageType = getPackageType(url);
|
|
6340
|
+
if (packageType === "none" || packageType === "commonjs") {
|
|
6341
|
+
return "commonjs";
|
|
6342
|
+
}
|
|
6343
|
+
return "module";
|
|
6344
|
+
}
|
|
6345
|
+
const format2 = extensionFormatMap[value];
|
|
6346
|
+
if (format2) return format2;
|
|
6347
|
+
if (ignoreErrors) {
|
|
6348
|
+
return void 0;
|
|
6349
|
+
}
|
|
6350
|
+
const filepath = fileURLToPath3(url);
|
|
6351
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath);
|
|
6352
|
+
}
|
|
6353
|
+
function getHttpProtocolModuleFormat() {
|
|
6354
|
+
}
|
|
6355
|
+
function defaultGetFormatWithoutErrors(url, context) {
|
|
6356
|
+
const protocol = url.protocol;
|
|
6357
|
+
if (!hasOwnProperty2.call(protocolHandlers, protocol)) {
|
|
6358
|
+
return null;
|
|
6359
|
+
}
|
|
6360
|
+
return protocolHandlers[protocol](url, context, true) || null;
|
|
6361
|
+
}
|
|
6362
|
+
var ERR_UNKNOWN_FILE_EXTENSION, hasOwnProperty2, extensionFormatMap, protocolHandlers;
|
|
6363
|
+
var init_get_format = __esm({
|
|
6364
|
+
"node_modules/import-meta-resolve/lib/get-format.js"() {
|
|
6365
|
+
"use strict";
|
|
6366
|
+
init_package_json_reader();
|
|
6367
|
+
init_errors();
|
|
6368
|
+
({ ERR_UNKNOWN_FILE_EXTENSION } = codes);
|
|
6369
|
+
hasOwnProperty2 = {}.hasOwnProperty;
|
|
6370
|
+
extensionFormatMap = {
|
|
6371
|
+
// @ts-expect-error: hush.
|
|
6372
|
+
__proto__: null,
|
|
6373
|
+
".cjs": "commonjs",
|
|
6374
|
+
".js": "module",
|
|
6375
|
+
".json": "json",
|
|
6376
|
+
".mjs": "module"
|
|
6377
|
+
};
|
|
6378
|
+
protocolHandlers = {
|
|
6379
|
+
// @ts-expect-error: hush.
|
|
6380
|
+
__proto__: null,
|
|
6381
|
+
"data:": getDataProtocolModuleFormat,
|
|
6382
|
+
"file:": getFileProtocolModuleFormat,
|
|
6383
|
+
"http:": getHttpProtocolModuleFormat,
|
|
6384
|
+
"https:": getHttpProtocolModuleFormat,
|
|
6385
|
+
"node:"() {
|
|
6386
|
+
return "builtin";
|
|
6387
|
+
}
|
|
6388
|
+
};
|
|
6389
|
+
}
|
|
6390
|
+
});
|
|
6391
|
+
|
|
6392
|
+
// node_modules/import-meta-resolve/lib/utils.js
|
|
6393
|
+
function getDefaultConditions() {
|
|
6394
|
+
return DEFAULT_CONDITIONS;
|
|
6395
|
+
}
|
|
6396
|
+
function getDefaultConditionsSet() {
|
|
6397
|
+
return DEFAULT_CONDITIONS_SET;
|
|
6398
|
+
}
|
|
6399
|
+
function getConditionsSet(conditions) {
|
|
6400
|
+
if (conditions !== void 0 && conditions !== getDefaultConditions()) {
|
|
6401
|
+
if (!Array.isArray(conditions)) {
|
|
6402
|
+
throw new ERR_INVALID_ARG_VALUE(
|
|
6403
|
+
"conditions",
|
|
6404
|
+
conditions,
|
|
6405
|
+
"expected an array"
|
|
6406
|
+
);
|
|
6407
|
+
}
|
|
6408
|
+
return new Set(conditions);
|
|
6409
|
+
}
|
|
6410
|
+
return getDefaultConditionsSet();
|
|
6411
|
+
}
|
|
6412
|
+
var ERR_INVALID_ARG_VALUE, DEFAULT_CONDITIONS, DEFAULT_CONDITIONS_SET;
|
|
6413
|
+
var init_utils = __esm({
|
|
6414
|
+
"node_modules/import-meta-resolve/lib/utils.js"() {
|
|
6415
|
+
"use strict";
|
|
6416
|
+
init_errors();
|
|
6417
|
+
({ ERR_INVALID_ARG_VALUE } = codes);
|
|
6418
|
+
DEFAULT_CONDITIONS = Object.freeze(["node", "import"]);
|
|
6419
|
+
DEFAULT_CONDITIONS_SET = new Set(DEFAULT_CONDITIONS);
|
|
6420
|
+
}
|
|
6421
|
+
});
|
|
6422
|
+
|
|
6423
|
+
// node_modules/import-meta-resolve/lib/resolve.js
|
|
6424
|
+
import assert2 from "assert";
|
|
6425
|
+
import { statSync, realpathSync } from "fs";
|
|
6426
|
+
import process2 from "process";
|
|
6427
|
+
import { fileURLToPath as fileURLToPath4, pathToFileURL as pathToFileURL4 } from "url";
|
|
6428
|
+
import path16 from "path";
|
|
6429
|
+
import { builtinModules as builtinModules3 } from "module";
|
|
6430
|
+
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
6431
|
+
if (process2.noDeprecation) {
|
|
6432
|
+
return;
|
|
6433
|
+
}
|
|
6434
|
+
const pjsonPath = fileURLToPath4(packageJsonUrl);
|
|
6435
|
+
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
6436
|
+
process2.emitWarning(
|
|
6437
|
+
`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath4(base)}` : ""}.`,
|
|
6438
|
+
"DeprecationWarning",
|
|
6439
|
+
"DEP0166"
|
|
6440
|
+
);
|
|
6441
|
+
}
|
|
6442
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
6443
|
+
if (process2.noDeprecation) {
|
|
6444
|
+
return;
|
|
6445
|
+
}
|
|
6446
|
+
const format2 = defaultGetFormatWithoutErrors(url, { parentURL: base.href });
|
|
6447
|
+
if (format2 !== "module") return;
|
|
6448
|
+
const urlPath = fileURLToPath4(url.href);
|
|
6449
|
+
const packagePath = fileURLToPath4(new URL(".", packageJsonUrl));
|
|
6450
|
+
const basePath = fileURLToPath4(base);
|
|
6451
|
+
if (!main) {
|
|
6452
|
+
process2.emitWarning(
|
|
6453
|
+
`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(
|
|
6454
|
+
packagePath.length
|
|
6455
|
+
)}", imported from ${basePath}.
|
|
6456
|
+
Default "index" lookups for the main are deprecated for ES modules.`,
|
|
6457
|
+
"DeprecationWarning",
|
|
6458
|
+
"DEP0151"
|
|
6459
|
+
);
|
|
6460
|
+
} else if (path16.resolve(packagePath, main) !== urlPath) {
|
|
6461
|
+
process2.emitWarning(
|
|
6462
|
+
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
6463
|
+
packagePath.length
|
|
6464
|
+
)}", imported from ${basePath}.
|
|
6465
|
+
Automatic extension resolution of the "main" field is deprecated for ES modules.`,
|
|
6466
|
+
"DeprecationWarning",
|
|
6467
|
+
"DEP0151"
|
|
6468
|
+
);
|
|
6469
|
+
}
|
|
6470
|
+
}
|
|
6471
|
+
function tryStatSync(path23) {
|
|
6472
|
+
try {
|
|
6473
|
+
return statSync(path23);
|
|
6474
|
+
} catch {
|
|
6475
|
+
}
|
|
6476
|
+
}
|
|
6477
|
+
function fileExists(url) {
|
|
6478
|
+
const stats = statSync(url, { throwIfNoEntry: false });
|
|
6479
|
+
const isFile = stats ? stats.isFile() : void 0;
|
|
6480
|
+
return isFile === null || isFile === void 0 ? false : isFile;
|
|
6481
|
+
}
|
|
6482
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
6483
|
+
let guess;
|
|
6484
|
+
if (packageConfig.main !== void 0) {
|
|
6485
|
+
guess = new URL(packageConfig.main, packageJsonUrl);
|
|
6486
|
+
if (fileExists(guess)) return guess;
|
|
6487
|
+
const tries2 = [
|
|
6488
|
+
`./${packageConfig.main}.js`,
|
|
6489
|
+
`./${packageConfig.main}.json`,
|
|
6490
|
+
`./${packageConfig.main}.node`,
|
|
6491
|
+
`./${packageConfig.main}/index.js`,
|
|
6492
|
+
`./${packageConfig.main}/index.json`,
|
|
6493
|
+
`./${packageConfig.main}/index.node`
|
|
6494
|
+
];
|
|
6495
|
+
let i2 = -1;
|
|
6496
|
+
while (++i2 < tries2.length) {
|
|
6497
|
+
guess = new URL(tries2[i2], packageJsonUrl);
|
|
6498
|
+
if (fileExists(guess)) break;
|
|
6499
|
+
guess = void 0;
|
|
6500
|
+
}
|
|
6501
|
+
if (guess) {
|
|
6502
|
+
emitLegacyIndexDeprecation(
|
|
6503
|
+
guess,
|
|
6504
|
+
packageJsonUrl,
|
|
6505
|
+
base,
|
|
6506
|
+
packageConfig.main
|
|
6507
|
+
);
|
|
6508
|
+
return guess;
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6511
|
+
const tries = ["./index.js", "./index.json", "./index.node"];
|
|
6512
|
+
let i = -1;
|
|
6513
|
+
while (++i < tries.length) {
|
|
6514
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
6515
|
+
if (fileExists(guess)) break;
|
|
6516
|
+
guess = void 0;
|
|
6517
|
+
}
|
|
6518
|
+
if (guess) {
|
|
6519
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
6520
|
+
return guess;
|
|
6521
|
+
}
|
|
6522
|
+
throw new ERR_MODULE_NOT_FOUND(
|
|
6523
|
+
fileURLToPath4(new URL(".", packageJsonUrl)),
|
|
6524
|
+
fileURLToPath4(base)
|
|
6525
|
+
);
|
|
6526
|
+
}
|
|
6527
|
+
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
6528
|
+
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
|
|
6529
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
6530
|
+
resolved.pathname,
|
|
6531
|
+
'must not include encoded "/" or "\\" characters',
|
|
6532
|
+
fileURLToPath4(base)
|
|
6533
|
+
);
|
|
6534
|
+
}
|
|
6535
|
+
let filePath;
|
|
6536
|
+
try {
|
|
6537
|
+
filePath = fileURLToPath4(resolved);
|
|
6538
|
+
} catch (error) {
|
|
6539
|
+
const cause = (
|
|
6540
|
+
/** @type {ErrnoException} */
|
|
6541
|
+
error
|
|
6542
|
+
);
|
|
6543
|
+
Object.defineProperty(cause, "input", { value: String(resolved) });
|
|
6544
|
+
Object.defineProperty(cause, "module", { value: String(base) });
|
|
6545
|
+
throw cause;
|
|
6546
|
+
}
|
|
6547
|
+
const stats = tryStatSync(
|
|
6548
|
+
filePath.endsWith("/") ? filePath.slice(-1) : filePath
|
|
6549
|
+
);
|
|
6550
|
+
if (stats && stats.isDirectory()) {
|
|
6551
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath4(base));
|
|
6552
|
+
error.url = String(resolved);
|
|
6553
|
+
throw error;
|
|
6554
|
+
}
|
|
6555
|
+
if (!stats || !stats.isFile()) {
|
|
6556
|
+
const error = new ERR_MODULE_NOT_FOUND(
|
|
6557
|
+
filePath || resolved.pathname,
|
|
6558
|
+
base && fileURLToPath4(base),
|
|
6559
|
+
true
|
|
6560
|
+
);
|
|
6561
|
+
error.url = String(resolved);
|
|
6562
|
+
throw error;
|
|
6563
|
+
}
|
|
6564
|
+
if (!preserveSymlinks) {
|
|
6565
|
+
const real = realpathSync(filePath);
|
|
6566
|
+
const { search, hash } = resolved;
|
|
6567
|
+
resolved = pathToFileURL4(real + (filePath.endsWith(path16.sep) ? "/" : ""));
|
|
6568
|
+
resolved.search = search;
|
|
6569
|
+
resolved.hash = hash;
|
|
6570
|
+
}
|
|
6571
|
+
return resolved;
|
|
6572
|
+
}
|
|
6573
|
+
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
6574
|
+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
6575
|
+
specifier,
|
|
6576
|
+
packageJsonUrl && fileURLToPath4(new URL(".", packageJsonUrl)),
|
|
6577
|
+
fileURLToPath4(base)
|
|
6578
|
+
);
|
|
6579
|
+
}
|
|
6580
|
+
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
6581
|
+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
6582
|
+
fileURLToPath4(new URL(".", packageJsonUrl)),
|
|
6583
|
+
subpath,
|
|
6584
|
+
base && fileURLToPath4(base)
|
|
6585
|
+
);
|
|
6586
|
+
}
|
|
6587
|
+
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
6588
|
+
const reason = `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath4(packageJsonUrl)}`;
|
|
6589
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
6590
|
+
request,
|
|
6591
|
+
reason,
|
|
6592
|
+
base && fileURLToPath4(base)
|
|
6593
|
+
);
|
|
6594
|
+
}
|
|
6595
|
+
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
6596
|
+
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
6597
|
+
return new ERR_INVALID_PACKAGE_TARGET(
|
|
6598
|
+
fileURLToPath4(new URL(".", packageJsonUrl)),
|
|
6599
|
+
subpath,
|
|
6600
|
+
target,
|
|
6601
|
+
internal,
|
|
6602
|
+
base && fileURLToPath4(base)
|
|
6603
|
+
);
|
|
6604
|
+
}
|
|
6605
|
+
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
6606
|
+
if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
|
|
6607
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6608
|
+
if (!target.startsWith("./")) {
|
|
6609
|
+
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
6610
|
+
let isURL = false;
|
|
6611
|
+
try {
|
|
6612
|
+
new URL(target);
|
|
6613
|
+
isURL = true;
|
|
6614
|
+
} catch {
|
|
6615
|
+
}
|
|
6616
|
+
if (!isURL) {
|
|
6617
|
+
const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
6618
|
+
patternRegEx,
|
|
6619
|
+
target,
|
|
6620
|
+
() => subpath
|
|
6621
|
+
) : target + subpath;
|
|
6622
|
+
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
6623
|
+
}
|
|
6624
|
+
}
|
|
6625
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6626
|
+
}
|
|
6627
|
+
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
|
|
6628
|
+
if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
6629
|
+
if (!isPathMap) {
|
|
6630
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
6631
|
+
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
6632
|
+
patternRegEx,
|
|
6633
|
+
target,
|
|
6634
|
+
() => subpath
|
|
6635
|
+
) : target;
|
|
6636
|
+
emitInvalidSegmentDeprecation(
|
|
6637
|
+
resolvedTarget,
|
|
6638
|
+
request,
|
|
6639
|
+
match,
|
|
6640
|
+
packageJsonUrl,
|
|
6641
|
+
internal,
|
|
6642
|
+
base,
|
|
6643
|
+
true
|
|
6644
|
+
);
|
|
6645
|
+
}
|
|
6646
|
+
} else {
|
|
6647
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6648
|
+
}
|
|
6649
|
+
}
|
|
6650
|
+
const resolved = new URL(target, packageJsonUrl);
|
|
6651
|
+
const resolvedPath = resolved.pathname;
|
|
6652
|
+
const packagePath = new URL(".", packageJsonUrl).pathname;
|
|
6653
|
+
if (!resolvedPath.startsWith(packagePath))
|
|
6654
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6655
|
+
if (subpath === "") return resolved;
|
|
6656
|
+
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
6657
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
6658
|
+
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
6659
|
+
if (!isPathMap) {
|
|
6660
|
+
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
6661
|
+
patternRegEx,
|
|
6662
|
+
target,
|
|
6663
|
+
() => subpath
|
|
6664
|
+
) : target;
|
|
6665
|
+
emitInvalidSegmentDeprecation(
|
|
6666
|
+
resolvedTarget,
|
|
6667
|
+
request,
|
|
6668
|
+
match,
|
|
6669
|
+
packageJsonUrl,
|
|
6670
|
+
internal,
|
|
6671
|
+
base,
|
|
6672
|
+
false
|
|
6673
|
+
);
|
|
6674
|
+
}
|
|
6675
|
+
} else {
|
|
6676
|
+
throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
6677
|
+
}
|
|
6678
|
+
}
|
|
6679
|
+
if (pattern) {
|
|
6680
|
+
return new URL(
|
|
6681
|
+
RegExpPrototypeSymbolReplace.call(
|
|
6682
|
+
patternRegEx,
|
|
6683
|
+
resolved.href,
|
|
6684
|
+
() => subpath
|
|
6685
|
+
)
|
|
6686
|
+
);
|
|
6687
|
+
}
|
|
6688
|
+
return new URL(subpath, resolved);
|
|
6689
|
+
}
|
|
6690
|
+
function isArrayIndex(key) {
|
|
6691
|
+
const keyNumber = Number(key);
|
|
6692
|
+
if (`${keyNumber}` !== key) return false;
|
|
6693
|
+
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
6694
|
+
}
|
|
6695
|
+
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
6696
|
+
if (typeof target === "string") {
|
|
6697
|
+
return resolvePackageTargetString(
|
|
6698
|
+
target,
|
|
6699
|
+
subpath,
|
|
6700
|
+
packageSubpath,
|
|
6701
|
+
packageJsonUrl,
|
|
6702
|
+
base,
|
|
6703
|
+
pattern,
|
|
6704
|
+
internal,
|
|
6705
|
+
isPathMap,
|
|
6706
|
+
conditions
|
|
6707
|
+
);
|
|
6708
|
+
}
|
|
6709
|
+
if (Array.isArray(target)) {
|
|
6710
|
+
const targetList = target;
|
|
6711
|
+
if (targetList.length === 0) return null;
|
|
6712
|
+
let lastException;
|
|
6713
|
+
let i = -1;
|
|
6714
|
+
while (++i < targetList.length) {
|
|
6715
|
+
const targetItem = targetList[i];
|
|
6716
|
+
let resolveResult;
|
|
6717
|
+
try {
|
|
6718
|
+
resolveResult = resolvePackageTarget(
|
|
6719
|
+
packageJsonUrl,
|
|
6720
|
+
targetItem,
|
|
6721
|
+
subpath,
|
|
6722
|
+
packageSubpath,
|
|
6723
|
+
base,
|
|
6724
|
+
pattern,
|
|
6725
|
+
internal,
|
|
6726
|
+
isPathMap,
|
|
6727
|
+
conditions
|
|
6728
|
+
);
|
|
6729
|
+
} catch (error) {
|
|
6730
|
+
const exception = (
|
|
6731
|
+
/** @type {ErrnoException} */
|
|
6732
|
+
error
|
|
6733
|
+
);
|
|
6734
|
+
lastException = exception;
|
|
6735
|
+
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
6736
|
+
throw error;
|
|
6737
|
+
}
|
|
6738
|
+
if (resolveResult === void 0) continue;
|
|
6739
|
+
if (resolveResult === null) {
|
|
6740
|
+
lastException = null;
|
|
6741
|
+
continue;
|
|
6742
|
+
}
|
|
6743
|
+
return resolveResult;
|
|
6744
|
+
}
|
|
6745
|
+
if (lastException === void 0 || lastException === null) {
|
|
6746
|
+
return null;
|
|
6747
|
+
}
|
|
6748
|
+
throw lastException;
|
|
6749
|
+
}
|
|
6750
|
+
if (typeof target === "object" && target !== null) {
|
|
6751
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
6752
|
+
let i = -1;
|
|
6753
|
+
while (++i < keys.length) {
|
|
6754
|
+
const key = keys[i];
|
|
6755
|
+
if (isArrayIndex(key)) {
|
|
6756
|
+
throw new ERR_INVALID_PACKAGE_CONFIG2(
|
|
6757
|
+
fileURLToPath4(packageJsonUrl),
|
|
6758
|
+
base,
|
|
6759
|
+
'"exports" cannot contain numeric property keys.'
|
|
6760
|
+
);
|
|
6761
|
+
}
|
|
6762
|
+
}
|
|
6763
|
+
i = -1;
|
|
6764
|
+
while (++i < keys.length) {
|
|
6765
|
+
const key = keys[i];
|
|
6766
|
+
if (key === "default" || conditions && conditions.has(key)) {
|
|
6767
|
+
const conditionalTarget = (
|
|
6768
|
+
/** @type {unknown} */
|
|
6769
|
+
target[key]
|
|
6770
|
+
);
|
|
6771
|
+
const resolveResult = resolvePackageTarget(
|
|
6772
|
+
packageJsonUrl,
|
|
6773
|
+
conditionalTarget,
|
|
6774
|
+
subpath,
|
|
6775
|
+
packageSubpath,
|
|
6776
|
+
base,
|
|
6777
|
+
pattern,
|
|
6778
|
+
internal,
|
|
6779
|
+
isPathMap,
|
|
6780
|
+
conditions
|
|
6781
|
+
);
|
|
6782
|
+
if (resolveResult === void 0) continue;
|
|
6783
|
+
return resolveResult;
|
|
6784
|
+
}
|
|
6785
|
+
}
|
|
6786
|
+
return null;
|
|
6787
|
+
}
|
|
6788
|
+
if (target === null) {
|
|
6789
|
+
return null;
|
|
6790
|
+
}
|
|
6791
|
+
throw invalidPackageTarget(
|
|
6792
|
+
packageSubpath,
|
|
6793
|
+
target,
|
|
6794
|
+
packageJsonUrl,
|
|
6795
|
+
internal,
|
|
6796
|
+
base
|
|
6797
|
+
);
|
|
6798
|
+
}
|
|
6799
|
+
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
6800
|
+
if (typeof exports === "string" || Array.isArray(exports)) return true;
|
|
6801
|
+
if (typeof exports !== "object" || exports === null) return false;
|
|
6802
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
6803
|
+
let isConditionalSugar = false;
|
|
6804
|
+
let i = 0;
|
|
6805
|
+
let keyIndex = -1;
|
|
6806
|
+
while (++keyIndex < keys.length) {
|
|
6807
|
+
const key = keys[keyIndex];
|
|
6808
|
+
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
6809
|
+
if (i++ === 0) {
|
|
6810
|
+
isConditionalSugar = currentIsConditionalSugar;
|
|
6811
|
+
} else if (isConditionalSugar !== currentIsConditionalSugar) {
|
|
6812
|
+
throw new ERR_INVALID_PACKAGE_CONFIG2(
|
|
6813
|
+
fileURLToPath4(packageJsonUrl),
|
|
6814
|
+
base,
|
|
6815
|
+
`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`
|
|
6816
|
+
);
|
|
6817
|
+
}
|
|
6818
|
+
}
|
|
6819
|
+
return isConditionalSugar;
|
|
6820
|
+
}
|
|
6821
|
+
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
6822
|
+
if (process2.noDeprecation) {
|
|
6823
|
+
return;
|
|
6824
|
+
}
|
|
6825
|
+
const pjsonPath = fileURLToPath4(pjsonUrl);
|
|
6826
|
+
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
6827
|
+
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
6828
|
+
process2.emitWarning(
|
|
6829
|
+
`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath4(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`,
|
|
6830
|
+
"DeprecationWarning",
|
|
6831
|
+
"DEP0155"
|
|
6832
|
+
);
|
|
6833
|
+
}
|
|
6834
|
+
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
6835
|
+
let exports = packageConfig.exports;
|
|
6836
|
+
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
|
|
6837
|
+
exports = { ".": exports };
|
|
6838
|
+
}
|
|
6839
|
+
if (own2.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
6840
|
+
const target = exports[packageSubpath];
|
|
6841
|
+
const resolveResult = resolvePackageTarget(
|
|
6842
|
+
packageJsonUrl,
|
|
6843
|
+
target,
|
|
6844
|
+
"",
|
|
6845
|
+
packageSubpath,
|
|
6846
|
+
base,
|
|
6847
|
+
false,
|
|
6848
|
+
false,
|
|
6849
|
+
false,
|
|
6850
|
+
conditions
|
|
6851
|
+
);
|
|
6852
|
+
if (resolveResult === null || resolveResult === void 0) {
|
|
6853
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
6854
|
+
}
|
|
6855
|
+
return resolveResult;
|
|
6856
|
+
}
|
|
6857
|
+
let bestMatch = "";
|
|
6858
|
+
let bestMatchSubpath = "";
|
|
6859
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
6860
|
+
let i = -1;
|
|
6861
|
+
while (++i < keys.length) {
|
|
6862
|
+
const key = keys[i];
|
|
6863
|
+
const patternIndex = key.indexOf("*");
|
|
6864
|
+
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
6865
|
+
if (packageSubpath.endsWith("/")) {
|
|
6866
|
+
emitTrailingSlashPatternDeprecation(
|
|
6867
|
+
packageSubpath,
|
|
6868
|
+
packageJsonUrl,
|
|
6869
|
+
base
|
|
6870
|
+
);
|
|
6871
|
+
}
|
|
6872
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
6873
|
+
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
6874
|
+
bestMatch = key;
|
|
6875
|
+
bestMatchSubpath = packageSubpath.slice(
|
|
6876
|
+
patternIndex,
|
|
6877
|
+
packageSubpath.length - patternTrailer.length
|
|
6878
|
+
);
|
|
6879
|
+
}
|
|
6880
|
+
}
|
|
6881
|
+
}
|
|
6882
|
+
if (bestMatch) {
|
|
6883
|
+
const target = (
|
|
6884
|
+
/** @type {unknown} */
|
|
6885
|
+
exports[bestMatch]
|
|
6886
|
+
);
|
|
6887
|
+
const resolveResult = resolvePackageTarget(
|
|
6888
|
+
packageJsonUrl,
|
|
6889
|
+
target,
|
|
6890
|
+
bestMatchSubpath,
|
|
6891
|
+
bestMatch,
|
|
6892
|
+
base,
|
|
6893
|
+
true,
|
|
6894
|
+
false,
|
|
6895
|
+
packageSubpath.endsWith("/"),
|
|
6896
|
+
conditions
|
|
6897
|
+
);
|
|
6898
|
+
if (resolveResult === null || resolveResult === void 0) {
|
|
6899
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
6900
|
+
}
|
|
6901
|
+
return resolveResult;
|
|
6902
|
+
}
|
|
6903
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
6904
|
+
}
|
|
6905
|
+
function patternKeyCompare(a, b) {
|
|
6906
|
+
const aPatternIndex = a.indexOf("*");
|
|
6907
|
+
const bPatternIndex = b.indexOf("*");
|
|
6908
|
+
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
6909
|
+
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
6910
|
+
if (baseLengthA > baseLengthB) return -1;
|
|
6911
|
+
if (baseLengthB > baseLengthA) return 1;
|
|
6912
|
+
if (aPatternIndex === -1) return 1;
|
|
6913
|
+
if (bPatternIndex === -1) return -1;
|
|
6914
|
+
if (a.length > b.length) return -1;
|
|
6915
|
+
if (b.length > a.length) return 1;
|
|
6916
|
+
return 0;
|
|
6917
|
+
}
|
|
6918
|
+
function packageImportsResolve(name, base, conditions) {
|
|
6919
|
+
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) {
|
|
6920
|
+
const reason = "is not a valid internal imports specifier name";
|
|
6921
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath4(base));
|
|
6922
|
+
}
|
|
6923
|
+
let packageJsonUrl;
|
|
6924
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
6925
|
+
if (packageConfig.exists) {
|
|
6926
|
+
packageJsonUrl = pathToFileURL4(packageConfig.pjsonPath);
|
|
6927
|
+
const imports = packageConfig.imports;
|
|
6928
|
+
if (imports) {
|
|
6929
|
+
if (own2.call(imports, name) && !name.includes("*")) {
|
|
6930
|
+
const resolveResult = resolvePackageTarget(
|
|
6931
|
+
packageJsonUrl,
|
|
6932
|
+
imports[name],
|
|
6933
|
+
"",
|
|
6934
|
+
name,
|
|
6935
|
+
base,
|
|
6936
|
+
false,
|
|
6937
|
+
true,
|
|
6938
|
+
false,
|
|
6939
|
+
conditions
|
|
6940
|
+
);
|
|
6941
|
+
if (resolveResult !== null && resolveResult !== void 0) {
|
|
6942
|
+
return resolveResult;
|
|
6943
|
+
}
|
|
6944
|
+
} else {
|
|
6945
|
+
let bestMatch = "";
|
|
6946
|
+
let bestMatchSubpath = "";
|
|
6947
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
6948
|
+
let i = -1;
|
|
6949
|
+
while (++i < keys.length) {
|
|
6950
|
+
const key = keys[i];
|
|
6951
|
+
const patternIndex = key.indexOf("*");
|
|
6952
|
+
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
6953
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
6954
|
+
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
6955
|
+
bestMatch = key;
|
|
6956
|
+
bestMatchSubpath = name.slice(
|
|
6957
|
+
patternIndex,
|
|
6958
|
+
name.length - patternTrailer.length
|
|
6959
|
+
);
|
|
6960
|
+
}
|
|
6961
|
+
}
|
|
6962
|
+
}
|
|
6963
|
+
if (bestMatch) {
|
|
6964
|
+
const target = imports[bestMatch];
|
|
6965
|
+
const resolveResult = resolvePackageTarget(
|
|
6966
|
+
packageJsonUrl,
|
|
6967
|
+
target,
|
|
6968
|
+
bestMatchSubpath,
|
|
6969
|
+
bestMatch,
|
|
6970
|
+
base,
|
|
6971
|
+
true,
|
|
6972
|
+
true,
|
|
6973
|
+
false,
|
|
6974
|
+
conditions
|
|
6975
|
+
);
|
|
6976
|
+
if (resolveResult !== null && resolveResult !== void 0) {
|
|
6977
|
+
return resolveResult;
|
|
6978
|
+
}
|
|
6979
|
+
}
|
|
6980
|
+
}
|
|
6981
|
+
}
|
|
6982
|
+
}
|
|
6983
|
+
throw importNotDefined(name, packageJsonUrl, base);
|
|
6984
|
+
}
|
|
6985
|
+
function parsePackageName(specifier, base) {
|
|
6986
|
+
let separatorIndex = specifier.indexOf("/");
|
|
6987
|
+
let validPackageName = true;
|
|
6988
|
+
let isScoped = false;
|
|
6989
|
+
if (specifier[0] === "@") {
|
|
6990
|
+
isScoped = true;
|
|
6991
|
+
if (separatorIndex === -1 || specifier.length === 0) {
|
|
6992
|
+
validPackageName = false;
|
|
6993
|
+
} else {
|
|
6994
|
+
separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
6995
|
+
}
|
|
6996
|
+
}
|
|
6997
|
+
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
6998
|
+
if (invalidPackageNameRegEx.exec(packageName) !== null) {
|
|
6999
|
+
validPackageName = false;
|
|
7000
|
+
}
|
|
7001
|
+
if (!validPackageName) {
|
|
7002
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
7003
|
+
specifier,
|
|
7004
|
+
"is not a valid package name",
|
|
7005
|
+
fileURLToPath4(base)
|
|
7006
|
+
);
|
|
7007
|
+
}
|
|
7008
|
+
const packageSubpath = "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex));
|
|
7009
|
+
return { packageName, packageSubpath, isScoped };
|
|
7010
|
+
}
|
|
7011
|
+
function packageResolve(specifier, base, conditions) {
|
|
7012
|
+
if (builtinModules3.includes(specifier)) {
|
|
7013
|
+
return new URL("node:" + specifier);
|
|
7014
|
+
}
|
|
7015
|
+
const { packageName, packageSubpath, isScoped } = parsePackageName(
|
|
7016
|
+
specifier,
|
|
7017
|
+
base
|
|
7018
|
+
);
|
|
7019
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
7020
|
+
if (packageConfig.exists) {
|
|
7021
|
+
const packageJsonUrl2 = pathToFileURL4(packageConfig.pjsonPath);
|
|
7022
|
+
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
|
|
7023
|
+
return packageExportsResolve(
|
|
7024
|
+
packageJsonUrl2,
|
|
7025
|
+
packageSubpath,
|
|
7026
|
+
packageConfig,
|
|
7027
|
+
base,
|
|
7028
|
+
conditions
|
|
7029
|
+
);
|
|
7030
|
+
}
|
|
7031
|
+
}
|
|
7032
|
+
let packageJsonUrl = new URL(
|
|
7033
|
+
"./node_modules/" + packageName + "/package.json",
|
|
7034
|
+
base
|
|
7035
|
+
);
|
|
7036
|
+
let packageJsonPath = fileURLToPath4(packageJsonUrl);
|
|
7037
|
+
let lastPath;
|
|
7038
|
+
do {
|
|
7039
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
7040
|
+
if (!stat || !stat.isDirectory()) {
|
|
7041
|
+
lastPath = packageJsonPath;
|
|
7042
|
+
packageJsonUrl = new URL(
|
|
7043
|
+
(isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
|
|
7044
|
+
packageJsonUrl
|
|
7045
|
+
);
|
|
7046
|
+
packageJsonPath = fileURLToPath4(packageJsonUrl);
|
|
7047
|
+
continue;
|
|
7048
|
+
}
|
|
7049
|
+
const packageConfig2 = read(packageJsonPath, { base, specifier });
|
|
7050
|
+
if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
|
|
7051
|
+
return packageExportsResolve(
|
|
7052
|
+
packageJsonUrl,
|
|
7053
|
+
packageSubpath,
|
|
7054
|
+
packageConfig2,
|
|
7055
|
+
base,
|
|
7056
|
+
conditions
|
|
7057
|
+
);
|
|
7058
|
+
}
|
|
7059
|
+
if (packageSubpath === ".") {
|
|
7060
|
+
return legacyMainResolve(packageJsonUrl, packageConfig2, base);
|
|
7061
|
+
}
|
|
7062
|
+
return new URL(packageSubpath, packageJsonUrl);
|
|
7063
|
+
} while (packageJsonPath.length !== lastPath.length);
|
|
7064
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath4(base), false);
|
|
7065
|
+
}
|
|
7066
|
+
function isRelativeSpecifier(specifier) {
|
|
7067
|
+
if (specifier[0] === ".") {
|
|
7068
|
+
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
7069
|
+
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) {
|
|
7070
|
+
return true;
|
|
7071
|
+
}
|
|
7072
|
+
}
|
|
7073
|
+
return false;
|
|
7074
|
+
}
|
|
7075
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
7076
|
+
if (specifier === "") return false;
|
|
7077
|
+
if (specifier[0] === "/") return true;
|
|
7078
|
+
return isRelativeSpecifier(specifier);
|
|
7079
|
+
}
|
|
7080
|
+
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
7081
|
+
if (conditions === void 0) {
|
|
7082
|
+
conditions = getConditionsSet();
|
|
7083
|
+
}
|
|
7084
|
+
const protocol = base.protocol;
|
|
7085
|
+
const isData = protocol === "data:";
|
|
7086
|
+
const isRemote = isData || protocol === "http:" || protocol === "https:";
|
|
7087
|
+
let resolved;
|
|
7088
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
7089
|
+
try {
|
|
7090
|
+
resolved = new URL(specifier, base);
|
|
7091
|
+
} catch (error_) {
|
|
7092
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
7093
|
+
error.cause = error_;
|
|
7094
|
+
throw error;
|
|
7095
|
+
}
|
|
7096
|
+
} else if (protocol === "file:" && specifier[0] === "#") {
|
|
7097
|
+
resolved = packageImportsResolve(specifier, base, conditions);
|
|
7098
|
+
} else {
|
|
7099
|
+
try {
|
|
7100
|
+
resolved = new URL(specifier);
|
|
7101
|
+
} catch (error_) {
|
|
7102
|
+
if (isRemote && !builtinModules3.includes(specifier)) {
|
|
7103
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
7104
|
+
error.cause = error_;
|
|
7105
|
+
throw error;
|
|
7106
|
+
}
|
|
7107
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
7108
|
+
}
|
|
7109
|
+
}
|
|
7110
|
+
assert2.ok(resolved !== void 0, "expected to be defined");
|
|
7111
|
+
if (resolved.protocol !== "file:") {
|
|
7112
|
+
return resolved;
|
|
7113
|
+
}
|
|
7114
|
+
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
7115
|
+
}
|
|
7116
|
+
var RegExpPrototypeSymbolReplace, ERR_NETWORK_IMPORT_DISALLOWED, ERR_INVALID_MODULE_SPECIFIER, ERR_INVALID_PACKAGE_CONFIG2, ERR_INVALID_PACKAGE_TARGET, ERR_MODULE_NOT_FOUND, ERR_PACKAGE_IMPORT_NOT_DEFINED, ERR_PACKAGE_PATH_NOT_EXPORTED, ERR_UNSUPPORTED_DIR_IMPORT, ERR_UNSUPPORTED_RESOLVE_REQUEST, own2, invalidSegmentRegEx, deprecatedInvalidSegmentRegEx, invalidPackageNameRegEx, patternRegEx, encodedSeparatorRegEx, emittedPackageWarnings, doubleSlashRegEx;
|
|
7117
|
+
var init_resolve2 = __esm({
|
|
7118
|
+
"node_modules/import-meta-resolve/lib/resolve.js"() {
|
|
7119
|
+
"use strict";
|
|
7120
|
+
init_get_format();
|
|
7121
|
+
init_errors();
|
|
7122
|
+
init_package_json_reader();
|
|
7123
|
+
init_utils();
|
|
7124
|
+
RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
7125
|
+
({
|
|
7126
|
+
ERR_NETWORK_IMPORT_DISALLOWED,
|
|
7127
|
+
ERR_INVALID_MODULE_SPECIFIER,
|
|
7128
|
+
ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG2,
|
|
7129
|
+
ERR_INVALID_PACKAGE_TARGET,
|
|
7130
|
+
ERR_MODULE_NOT_FOUND,
|
|
7131
|
+
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
7132
|
+
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
7133
|
+
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
7134
|
+
ERR_UNSUPPORTED_RESOLVE_REQUEST
|
|
7135
|
+
} = codes);
|
|
7136
|
+
own2 = {}.hasOwnProperty;
|
|
7137
|
+
invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
7138
|
+
deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
7139
|
+
invalidPackageNameRegEx = /^\.|%|\\/;
|
|
7140
|
+
patternRegEx = /\*/g;
|
|
7141
|
+
encodedSeparatorRegEx = /%2f|%5c/i;
|
|
7142
|
+
emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
7143
|
+
doubleSlashRegEx = /[/\\]{2}/;
|
|
7144
|
+
}
|
|
7145
|
+
});
|
|
7146
|
+
|
|
7147
|
+
// node_modules/import-meta-resolve/index.js
|
|
7148
|
+
var init_import_meta_resolve = __esm({
|
|
7149
|
+
"node_modules/import-meta-resolve/index.js"() {
|
|
7150
|
+
"use strict";
|
|
7151
|
+
init_resolve2();
|
|
7152
|
+
}
|
|
7153
|
+
});
|
|
7154
|
+
|
|
7155
|
+
// src/server/runnable-environment.ts
|
|
7156
|
+
var runnable_environment_exports = {};
|
|
7157
|
+
__export(runnable_environment_exports, {
|
|
7158
|
+
NastiModuleRunner: () => NastiModuleRunner,
|
|
7159
|
+
createModuleRunner: () => createModuleRunner
|
|
7160
|
+
});
|
|
7161
|
+
import path17 from "path";
|
|
7162
|
+
import fs13 from "fs";
|
|
7163
|
+
import { builtinModules as builtinModules4 } from "module";
|
|
7164
|
+
import { pathToFileURL as pathToFileURL5 } from "url";
|
|
7165
|
+
function createModuleRunner(environment) {
|
|
7166
|
+
if (environment.consumer !== "server") {
|
|
7167
|
+
throw new Error(
|
|
7168
|
+
`[nasti] module runner requires a server-consumer environment (got "${environment.name}" / ${environment.consumer})`
|
|
7169
|
+
);
|
|
7170
|
+
}
|
|
7171
|
+
return new NastiModuleRunner(environment);
|
|
7172
|
+
}
|
|
7173
|
+
var debug6, NODE_BUILTINS3, NastiModuleRunner, AsyncFunction;
|
|
7174
|
+
var init_runnable_environment = __esm({
|
|
7175
|
+
"src/server/runnable-environment.ts"() {
|
|
7176
|
+
"use strict";
|
|
7177
|
+
init_import_meta_resolve();
|
|
7178
|
+
init_transformer();
|
|
7179
|
+
init_env();
|
|
7180
|
+
init_debug();
|
|
7181
|
+
debug6 = createDebugger("nasti:ssr");
|
|
7182
|
+
NODE_BUILTINS3 = /* @__PURE__ */ new Set([...builtinModules4, ...builtinModules4.map((m) => `node:${m}`)]);
|
|
7183
|
+
NastiModuleRunner = class {
|
|
7184
|
+
environment;
|
|
7185
|
+
config;
|
|
7186
|
+
cache = /* @__PURE__ */ new Map();
|
|
7187
|
+
envDefine;
|
|
7188
|
+
externalImportParent;
|
|
7189
|
+
externalImportConditions;
|
|
7190
|
+
constructor(environment) {
|
|
7191
|
+
this.environment = environment;
|
|
7192
|
+
this.config = environment.config;
|
|
7193
|
+
this.envDefine = buildEnvDefine(
|
|
7194
|
+
loadEnv(this.config.mode, this.config.root, this.config.envPrefix),
|
|
7195
|
+
this.config.mode,
|
|
7196
|
+
ssrDefineOverrides(environment.consumer)
|
|
7197
|
+
);
|
|
7198
|
+
this.externalImportParent = pathToFileURL5(path17.join(this.config.root, "package.json"));
|
|
7199
|
+
this.externalImportConditions = /* @__PURE__ */ new Set([
|
|
7200
|
+
...environment.options.resolve.conditions.filter((condition) => condition !== "require"),
|
|
7201
|
+
"node",
|
|
7202
|
+
"import"
|
|
7203
|
+
]);
|
|
7204
|
+
const handlers = {
|
|
7205
|
+
fetchModule: async (id, importer) => this.fetchModule(id, importer),
|
|
7206
|
+
getBuiltins: () => [/^node:/, ...builtinModules4]
|
|
7207
|
+
};
|
|
7208
|
+
environment.hot.setInvokeHandler?.(handlers);
|
|
7209
|
+
}
|
|
7210
|
+
/** 入口:加载并执行一个模块(url 为根相对或绝对路径) */
|
|
7211
|
+
async import(rawUrl) {
|
|
7212
|
+
const id = this.resolveToId(rawUrl);
|
|
7213
|
+
return this.instantiate(id);
|
|
7214
|
+
}
|
|
7215
|
+
/** 文件变更时按文件失效(含其所属的虚拟子模块) */
|
|
7216
|
+
invalidateFile(file) {
|
|
7217
|
+
for (const key of [...this.cache.keys()]) {
|
|
7218
|
+
if (key === file || key.startsWith(file + "?")) {
|
|
7219
|
+
this.cache.delete(key);
|
|
7220
|
+
}
|
|
7221
|
+
}
|
|
7222
|
+
}
|
|
7223
|
+
invalidateAll() {
|
|
7224
|
+
this.cache.clear();
|
|
7225
|
+
}
|
|
7226
|
+
resolveToId(rawUrl) {
|
|
7227
|
+
if (path17.isAbsolute(rawUrl) && fs13.existsSync(rawUrl.split("?")[0])) return rawUrl;
|
|
7228
|
+
const clean = rawUrl.replace(/^\//, "");
|
|
7229
|
+
return path17.resolve(this.config.root, clean);
|
|
7230
|
+
}
|
|
7231
|
+
/**
|
|
7232
|
+
* fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
|
|
7233
|
+
* resolve(插件 resolveId → 文件系统)→ load/读盘 → 插件 transform →
|
|
7234
|
+
* oxc(TS/JSX)→ moduleRunnerTransform。
|
|
7235
|
+
*/
|
|
7236
|
+
async fetchModule(id, importer) {
|
|
7237
|
+
if (NODE_BUILTINS3.has(id)) return { externalize: id };
|
|
7238
|
+
if (!id.startsWith(".") && !path17.isAbsolute(id) && !id.startsWith("\0")) {
|
|
7239
|
+
return { externalize: id };
|
|
7240
|
+
}
|
|
7241
|
+
const container = this.environment.pluginContainer;
|
|
7242
|
+
let resolvedId = id;
|
|
7243
|
+
if (id.startsWith(".") && importer) {
|
|
7244
|
+
const resolved = await container.resolveId(id, importer);
|
|
7245
|
+
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : path17.resolve(path17.dirname(importer.split("?")[0]), id);
|
|
7246
|
+
}
|
|
7247
|
+
resolvedId = this.completeExtension(resolvedId);
|
|
7248
|
+
const cleanId = resolvedId.split("?")[0];
|
|
7249
|
+
let code;
|
|
7250
|
+
const loaded = await container.load(resolvedId);
|
|
7251
|
+
if (loaded != null) {
|
|
7252
|
+
code = typeof loaded === "string" ? loaded : loaded.code;
|
|
7253
|
+
} else if (fs13.existsSync(cleanId)) {
|
|
7254
|
+
code = fs13.readFileSync(cleanId, "utf-8");
|
|
7255
|
+
} else {
|
|
7256
|
+
throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
|
|
7257
|
+
}
|
|
7258
|
+
const transformed = await container.transform(code, resolvedId);
|
|
7259
|
+
if (transformed != null) {
|
|
7260
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
7261
|
+
}
|
|
7262
|
+
if (this.config.framework === "react") {
|
|
7263
|
+
const result = await transformReactCode(cleanId, code, {
|
|
7264
|
+
react: this.config.react,
|
|
7265
|
+
consumer: this.environment.consumer,
|
|
7266
|
+
development: true,
|
|
7267
|
+
sourcemap: false,
|
|
7268
|
+
target: this.environment.options.build.target,
|
|
7269
|
+
onWarning: (message) => this.config.logger.warn(`[nasti:react] ${message}`)
|
|
7270
|
+
});
|
|
7271
|
+
if (result) {
|
|
7272
|
+
code = result.code;
|
|
7273
|
+
} else if (shouldTransform(cleanId)) {
|
|
7274
|
+
const fallback = transformCode(cleanId, code, {
|
|
7275
|
+
sourcemap: false,
|
|
7276
|
+
jsxRuntime: this.config.react.jsxRuntime,
|
|
7277
|
+
jsxImportSource: this.config.react.jsxImportSource,
|
|
7278
|
+
target: this.environment.options.build.target
|
|
7279
|
+
});
|
|
7280
|
+
code = fallback.code;
|
|
7281
|
+
}
|
|
7282
|
+
} else if (shouldTransform(cleanId)) {
|
|
7283
|
+
const result = transformCode(cleanId, code, {
|
|
7284
|
+
sourcemap: false,
|
|
7285
|
+
target: this.environment.options.build.target,
|
|
7286
|
+
jsxRuntime: "automatic",
|
|
7287
|
+
jsxImportSource: "vue"
|
|
7288
|
+
});
|
|
7289
|
+
code = result.code;
|
|
7290
|
+
}
|
|
7291
|
+
code = replaceEnvInCode(code, this.envDefine);
|
|
7292
|
+
let moduleRunnerTransform;
|
|
7293
|
+
try {
|
|
7294
|
+
;
|
|
7295
|
+
({ moduleRunnerTransform } = await import("rolldown/experimental"));
|
|
7296
|
+
} catch (err) {
|
|
7297
|
+
throw new Error(
|
|
7298
|
+
`[nasti:ssr] rolldown/experimental moduleRunnerTransform unavailable (installed rolldown incompatible?): ${err.message}`
|
|
7299
|
+
);
|
|
7300
|
+
}
|
|
7301
|
+
const runnerResult = await moduleRunnerTransform(resolvedId, code);
|
|
7302
|
+
debug6?.(`fetchModule ${resolvedId} (${runnerResult.deps?.length ?? 0} deps)`);
|
|
7303
|
+
return { id: resolvedId, code: runnerResult.code };
|
|
7304
|
+
}
|
|
7305
|
+
completeExtension(id) {
|
|
7306
|
+
const clean = id.split("?")[0];
|
|
7307
|
+
const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
|
|
7308
|
+
if (fs13.existsSync(clean) && fs13.statSync(clean).isFile()) return id;
|
|
7309
|
+
const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
|
|
7310
|
+
if (jsMatch) {
|
|
7311
|
+
for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
|
|
7312
|
+
if (fs13.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
|
|
7313
|
+
}
|
|
7314
|
+
}
|
|
7315
|
+
for (const ext of this.config.resolve.extensions) {
|
|
7316
|
+
if (fs13.existsSync(clean + ext)) return clean + ext + query;
|
|
7317
|
+
}
|
|
7318
|
+
for (const ext of this.config.resolve.extensions) {
|
|
7319
|
+
const indexPath = path17.join(clean, `index${ext}`);
|
|
7320
|
+
if (fs13.existsSync(indexPath)) return indexPath;
|
|
7321
|
+
}
|
|
7322
|
+
return id;
|
|
7323
|
+
}
|
|
7324
|
+
async instantiate(id) {
|
|
7325
|
+
const cached2 = this.cache.get(id);
|
|
7326
|
+
if (cached2) return cached2.promise ?? Promise.resolve(cached2.exports);
|
|
7327
|
+
const entry = { exports: {}, promise: null };
|
|
7328
|
+
this.cache.set(id, entry);
|
|
7329
|
+
entry.promise = this.evaluate(id, entry).then(() => {
|
|
7330
|
+
entry.promise = null;
|
|
7331
|
+
return entry.exports;
|
|
7332
|
+
}).catch((err) => {
|
|
7333
|
+
this.cache.delete(id);
|
|
7334
|
+
throw err;
|
|
7335
|
+
});
|
|
7336
|
+
return entry.promise;
|
|
7337
|
+
}
|
|
7338
|
+
async evaluate(id, entry) {
|
|
7339
|
+
const fetched = await this.fetchModule(id);
|
|
7340
|
+
if ("externalize" in fetched) {
|
|
7341
|
+
const spec = fetched.externalize;
|
|
7342
|
+
const mod = await this.importExternal(spec);
|
|
7343
|
+
entry.exports = mod;
|
|
7344
|
+
return;
|
|
7345
|
+
}
|
|
7346
|
+
const ssrImport = async (dep) => {
|
|
7347
|
+
if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !path17.isAbsolute(dep) && !dep.startsWith("\0")) {
|
|
7348
|
+
return this.importExternal(dep);
|
|
7349
|
+
}
|
|
7350
|
+
const depId = dep.startsWith(".") ? this.completeExtension(path17.resolve(path17.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
|
|
7351
|
+
return this.instantiate(depId);
|
|
7352
|
+
};
|
|
7353
|
+
const ssrExportAll = (sourceModule) => {
|
|
7354
|
+
for (const key of Object.keys(sourceModule)) {
|
|
7355
|
+
if (key !== "default" && !(key in entry.exports)) {
|
|
7356
|
+
Object.defineProperty(entry.exports, key, {
|
|
7357
|
+
enumerable: true,
|
|
7358
|
+
configurable: true,
|
|
7359
|
+
get: () => sourceModule[key]
|
|
7360
|
+
});
|
|
7361
|
+
}
|
|
7362
|
+
}
|
|
7363
|
+
};
|
|
7364
|
+
const importMeta = {
|
|
7365
|
+
url: pathToFileURL5(fetched.id.split("?")[0]).href,
|
|
7366
|
+
env: { SSR: true, MODE: this.config.mode, DEV: this.config.mode !== "production", PROD: this.config.mode === "production" },
|
|
7367
|
+
hot: void 0
|
|
7368
|
+
};
|
|
7369
|
+
const fn = new AsyncFunction(
|
|
7370
|
+
"__vite_ssr_exports__",
|
|
7371
|
+
"__vite_ssr_import__",
|
|
7372
|
+
"__vite_ssr_dynamic_import__",
|
|
7373
|
+
"__vite_ssr_exportAll__",
|
|
7374
|
+
"__vite_ssr_import_meta__",
|
|
7375
|
+
`"use strict";${fetched.code}
|
|
7376
|
+
//# sourceURL=${fetched.id}`
|
|
7377
|
+
);
|
|
7378
|
+
await fn(entry.exports, ssrImport, ssrImport, ssrExportAll, importMeta);
|
|
7379
|
+
}
|
|
7380
|
+
async importExternal(spec) {
|
|
7381
|
+
try {
|
|
7382
|
+
return await (spec.startsWith("node:") || !path17.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import(pathToFileURL5(spec).href));
|
|
7383
|
+
} catch (err) {
|
|
7384
|
+
throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
|
|
7385
|
+
}
|
|
7386
|
+
}
|
|
7387
|
+
/** bare specifier → 项目 node_modules 的 ESM URL(避免相对 Nasti 自身解析) */
|
|
7388
|
+
resolveExternalSpecifier(spec) {
|
|
7389
|
+
if (spec.startsWith("node:")) return spec;
|
|
7390
|
+
if (NODE_BUILTINS3.has(spec)) return `node:${spec}`;
|
|
7391
|
+
return moduleResolve(
|
|
7392
|
+
spec,
|
|
7393
|
+
this.externalImportParent,
|
|
7394
|
+
this.externalImportConditions,
|
|
7395
|
+
false
|
|
7396
|
+
).href;
|
|
7397
|
+
}
|
|
7398
|
+
};
|
|
7399
|
+
AsyncFunction = Object.getPrototypeOf(async function() {
|
|
5916
7400
|
}).constructor;
|
|
5917
7401
|
}
|
|
5918
7402
|
});
|
|
@@ -5922,7 +7406,7 @@ var dev_engine_exports = {};
|
|
|
5922
7406
|
__export(dev_engine_exports, {
|
|
5923
7407
|
createBundledDevServer: () => createBundledDevServer
|
|
5924
7408
|
});
|
|
5925
|
-
import
|
|
7409
|
+
import path18 from "path";
|
|
5926
7410
|
import crypto3 from "crypto";
|
|
5927
7411
|
import { WebSocketServer as WsServer2 } from "ws";
|
|
5928
7412
|
import pc8 from "picocolors";
|
|
@@ -5952,11 +7436,11 @@ async function createBundledDevServer(opts) {
|
|
|
5952
7436
|
const patches = new MemoryFiles();
|
|
5953
7437
|
const entryFileNames = /* @__PURE__ */ new Map();
|
|
5954
7438
|
const bundledClients = /* @__PURE__ */ new Map();
|
|
5955
|
-
const useReactRefresh = config.framework
|
|
7439
|
+
const useReactRefresh = config.framework === "react" && config.server.hmr !== false && refreshWrapperFn != null;
|
|
5956
7440
|
const rolldownPlugins = [
|
|
5957
7441
|
...useReactRefresh ? [
|
|
5958
7442
|
createReactRefreshRuntimePlugin(entryPoints),
|
|
5959
|
-
createBundledOxcRefreshPlugin()
|
|
7443
|
+
createBundledOxcRefreshPlugin(config)
|
|
5960
7444
|
] : [],
|
|
5961
7445
|
...stripCatchAllLoad(toRolldownPlugins(clientEnv.plugins, clientEnv)),
|
|
5962
7446
|
...useReactRefresh ? [
|
|
@@ -6007,7 +7491,7 @@ async function createBundledDevServer(opts) {
|
|
|
6007
7491
|
}
|
|
6008
7492
|
const url = `/${patchPath}`;
|
|
6009
7493
|
logger.info(
|
|
6010
|
-
pc8.green("hmr update ") + pc8.dim(changedFiles.map((f) =>
|
|
7494
|
+
pc8.green("hmr update ") + pc8.dim(changedFiles.map((f) => path18.relative(config.root, f)).join(", ")),
|
|
6011
7495
|
{ timestamp: true }
|
|
6012
7496
|
);
|
|
6013
7497
|
sendTo(clientId, { type: "hmr:update", path: url, url });
|
|
@@ -6162,7 +7646,7 @@ async function createBundledDevServer(opts) {
|
|
|
6162
7646
|
return;
|
|
6163
7647
|
}
|
|
6164
7648
|
res.setHeader("ETag", hit.etag);
|
|
6165
|
-
res.setHeader("Content-Type", MIME_TYPES[
|
|
7649
|
+
res.setHeader("Content-Type", MIME_TYPES[path18.extname(fileName)] ?? "application/octet-stream");
|
|
6166
7650
|
res.setHeader("Cache-Control", "no-cache");
|
|
6167
7651
|
res.once("finish", () => {
|
|
6168
7652
|
void engine.notifyPayloadDelivered(fileName).catch(
|
|
@@ -6203,7 +7687,7 @@ function stripCatchAllLoad(plugins) {
|
|
|
6203
7687
|
);
|
|
6204
7688
|
}
|
|
6205
7689
|
function createReactRefreshRuntimePlugin(entryPoints) {
|
|
6206
|
-
const entryIds = new Set(entryPoints.map((p) =>
|
|
7690
|
+
const entryIds = new Set(entryPoints.map((p) => path18.resolve(p)));
|
|
6207
7691
|
return {
|
|
6208
7692
|
name: "nasti:bundled-react-refresh",
|
|
6209
7693
|
resolveId(source) {
|
|
@@ -6221,24 +7705,27 @@ function createReactRefreshRuntimePlugin(entryPoints) {
|
|
|
6221
7705
|
return null;
|
|
6222
7706
|
},
|
|
6223
7707
|
transform(code, id) {
|
|
6224
|
-
if (!entryIds.has(
|
|
7708
|
+
if (!entryIds.has(path18.resolve(id.split("?")[0]))) return null;
|
|
6225
7709
|
return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
|
|
6226
7710
|
${code}`, map: null };
|
|
6227
7711
|
}
|
|
6228
7712
|
};
|
|
6229
7713
|
}
|
|
6230
|
-
function createBundledOxcRefreshPlugin() {
|
|
7714
|
+
function createBundledOxcRefreshPlugin(config) {
|
|
6231
7715
|
return {
|
|
6232
7716
|
name: "nasti:bundled-oxc-refresh",
|
|
6233
|
-
transform(code, id) {
|
|
7717
|
+
async transform(code, id) {
|
|
6234
7718
|
const clean = id.split("?")[0];
|
|
6235
|
-
|
|
6236
|
-
|
|
7719
|
+
const result = await transformReactCode(clean, code, {
|
|
7720
|
+
react: config.react,
|
|
7721
|
+
consumer: "client",
|
|
7722
|
+
development: true,
|
|
7723
|
+
reactRefresh: true,
|
|
6237
7724
|
sourcemap: true,
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
reactRefresh: true
|
|
7725
|
+
target: config.build.target,
|
|
7726
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
6241
7727
|
});
|
|
7728
|
+
if (!result) return null;
|
|
6242
7729
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
6243
7730
|
}
|
|
6244
7731
|
};
|
|
@@ -6392,7 +7879,7 @@ __export(server_exports, {
|
|
|
6392
7879
|
createServer: () => createServer
|
|
6393
7880
|
});
|
|
6394
7881
|
import http from "http";
|
|
6395
|
-
import
|
|
7882
|
+
import path19 from "path";
|
|
6396
7883
|
import os from "os";
|
|
6397
7884
|
import connect from "connect";
|
|
6398
7885
|
import sirv from "sirv";
|
|
@@ -6485,19 +7972,19 @@ async function createServer(inlineConfig = {}) {
|
|
|
6485
7972
|
app.use(bundledServer.middleware);
|
|
6486
7973
|
}
|
|
6487
7974
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
6488
|
-
const outDirAbs =
|
|
7975
|
+
const outDirAbs = path19.resolve(config.root, config.build.outDir);
|
|
6489
7976
|
const linkedPackageRoots = getLinkedPackageRoots(config.root).filter(
|
|
6490
7977
|
(r) => r !== config.root && !isUnderRoot(config.root, r)
|
|
6491
7978
|
);
|
|
6492
7979
|
const watchTargets = [config.root, ...linkedPackageRoots];
|
|
6493
7980
|
const watcher = watch(watchTargets, {
|
|
6494
7981
|
ignored: (filePath) => {
|
|
6495
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
7982
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path19.sep)) return true;
|
|
6496
7983
|
for (const watchRoot of watchTargets) {
|
|
6497
7984
|
if (filePath === watchRoot) return false;
|
|
6498
|
-
const rel =
|
|
6499
|
-
if (!rel || rel.startsWith("..") ||
|
|
6500
|
-
for (const seg of rel.split(
|
|
7985
|
+
const rel = path19.relative(watchRoot, filePath);
|
|
7986
|
+
if (!rel || rel.startsWith("..") || path19.isAbsolute(rel)) continue;
|
|
7987
|
+
for (const seg of rel.split(path19.sep)) {
|
|
6501
7988
|
if (ignoredSegments.has(seg)) return true;
|
|
6502
7989
|
}
|
|
6503
7990
|
return false;
|
|
@@ -6629,7 +8116,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6629
8116
|
});
|
|
6630
8117
|
};
|
|
6631
8118
|
watcher.on("change", (file) => {
|
|
6632
|
-
if (file.includes(`${
|
|
8119
|
+
if (file.includes(`${path19.sep}node_modules${path19.sep}`) || file.endsWith(`${path19.sep}node_modules`)) {
|
|
6633
8120
|
clearLinkedPackageRootsCache();
|
|
6634
8121
|
}
|
|
6635
8122
|
ssrRunner?.invalidateFile(file);
|
|
@@ -6637,7 +8124,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6637
8124
|
notifyEnvironmentDrivers(file, "change");
|
|
6638
8125
|
});
|
|
6639
8126
|
watcher.on("add", (file) => {
|
|
6640
|
-
if (file.includes(`${
|
|
8127
|
+
if (file.includes(`${path19.sep}node_modules${path19.sep}`) || file.endsWith(`${path19.sep}node_modules`)) {
|
|
6641
8128
|
clearLinkedPackageRootsCache();
|
|
6642
8129
|
}
|
|
6643
8130
|
ssrRunner?.invalidateFile(file);
|
|
@@ -6645,7 +8132,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6645
8132
|
notifyEnvironmentDrivers(file, "add");
|
|
6646
8133
|
});
|
|
6647
8134
|
watcher.on("unlink", (file) => {
|
|
6648
|
-
if (file.includes(`${
|
|
8135
|
+
if (file.includes(`${path19.sep}node_modules${path19.sep}`) || file.endsWith(`${path19.sep}node_modules`)) {
|
|
6649
8136
|
clearLinkedPackageRootsCache();
|
|
6650
8137
|
}
|
|
6651
8138
|
ssrRunner?.invalidateFile(file);
|
|
@@ -6677,7 +8164,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6677
8164
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
6678
8165
|
logger.info(
|
|
6679
8166
|
`
|
|
6680
|
-
${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.
|
|
8167
|
+
${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.5.1"}`)} ${pc9.dim("ready in")} ${pc9.bold(readyIn)} ${pc9.dim("ms")}
|
|
6681
8168
|
`
|
|
6682
8169
|
);
|
|
6683
8170
|
printServerUrls(
|
|
@@ -6774,7 +8261,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6774
8261
|
throw error;
|
|
6775
8262
|
}
|
|
6776
8263
|
app.use(transformMiddleware(transformContexts.get("client")));
|
|
6777
|
-
const publicDir =
|
|
8264
|
+
const publicDir = path19.resolve(config.root, "public");
|
|
6778
8265
|
app.use(sirv(publicDir, { dev: true, etag: true }));
|
|
6779
8266
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
6780
8267
|
const postMiddlewares = [];
|
|
@@ -6870,7 +8357,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
6870
8357
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
6871
8358
|
const startTime = performance.now();
|
|
6872
8359
|
assertElectronVersion(config);
|
|
6873
|
-
console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.
|
|
8360
|
+
console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.5.1"}`));
|
|
6874
8361
|
console.log(pc5.dim(` root: ${config.root}`));
|
|
6875
8362
|
console.log(pc5.dim(` mode: ${config.mode}`));
|
|
6876
8363
|
console.log(pc5.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -6936,14 +8423,21 @@ async function bundleNode(config, entry, opts) {
|
|
|
6936
8423
|
};
|
|
6937
8424
|
const oxcTransformPlugin = {
|
|
6938
8425
|
name: "nasti:oxc-transform",
|
|
6939
|
-
transform(code, id) {
|
|
6940
|
-
|
|
6941
|
-
|
|
8426
|
+
async transform(code, id) {
|
|
8427
|
+
const result = config.framework === "react" ? await transformReactCode(id, code, {
|
|
8428
|
+
react: config.react,
|
|
8429
|
+
consumer: "server",
|
|
8430
|
+
development: config.mode === "development",
|
|
8431
|
+
sourcemap: !!config.build.sourcemap,
|
|
8432
|
+
target: config.electron.nodeTarget,
|
|
8433
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
8434
|
+
}) : shouldTransform(id) ? transformCode(id, code, {
|
|
6942
8435
|
sourcemap: !!config.build.sourcemap,
|
|
6943
8436
|
jsxRuntime: "automatic",
|
|
6944
|
-
jsxImportSource:
|
|
8437
|
+
jsxImportSource: "vue",
|
|
6945
8438
|
target: config.electron.nodeTarget
|
|
6946
|
-
});
|
|
8439
|
+
}) : null;
|
|
8440
|
+
if (!result) return null;
|
|
6947
8441
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
6948
8442
|
}
|
|
6949
8443
|
};
|
|
@@ -6993,8 +8487,8 @@ function createElectronRendererConfig(config, inlineConfig = {}, overrides = {})
|
|
|
6993
8487
|
}
|
|
6994
8488
|
};
|
|
6995
8489
|
}
|
|
6996
|
-
function outFileName(outDir, base,
|
|
6997
|
-
const ext =
|
|
8490
|
+
function outFileName(outDir, base, format2) {
|
|
8491
|
+
const ext = format2 === "cjs" ? ".cjs" : ".mjs";
|
|
6998
8492
|
return path11.join(outDir, base + ext);
|
|
6999
8493
|
}
|
|
7000
8494
|
function normalizePreload(preload, root) {
|
|
@@ -7037,9 +8531,9 @@ init_server();
|
|
|
7037
8531
|
|
|
7038
8532
|
// src/server/electron-dev.ts
|
|
7039
8533
|
init_config();
|
|
7040
|
-
import
|
|
7041
|
-
import
|
|
7042
|
-
import { createRequire as
|
|
8534
|
+
import path20 from "path";
|
|
8535
|
+
import fs14 from "fs";
|
|
8536
|
+
import { createRequire as createRequire5 } from "module";
|
|
7043
8537
|
import { spawn } from "child_process";
|
|
7044
8538
|
import chokidar from "chokidar";
|
|
7045
8539
|
import pc10 from "picocolors";
|
|
@@ -7051,7 +8545,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7051
8545
|
const { noSpawn, ...rest } = inlineConfig;
|
|
7052
8546
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
7053
8547
|
warnElectronVersion(config);
|
|
7054
|
-
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.
|
|
8548
|
+
console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.5.1"}`));
|
|
7055
8549
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
7056
8550
|
const server = await createServer2({
|
|
7057
8551
|
...rest,
|
|
@@ -7061,11 +8555,11 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7061
8555
|
await server.listen();
|
|
7062
8556
|
const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
|
|
7063
8557
|
console.log(pc10.dim(` renderer: ${devUrl}`));
|
|
7064
|
-
const stageDir =
|
|
7065
|
-
|
|
7066
|
-
const mainEntry =
|
|
8558
|
+
const stageDir = path20.resolve(config.root, ".nasti");
|
|
8559
|
+
fs14.mkdirSync(stageDir, { recursive: true });
|
|
8560
|
+
const mainEntry = path20.resolve(config.root, config.electron.main);
|
|
7067
8561
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
7068
|
-
const builtMainFile =
|
|
8562
|
+
const builtMainFile = path20.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
7069
8563
|
const builtPreloadFiles = [];
|
|
7070
8564
|
const compileAll = async () => {
|
|
7071
8565
|
await compileNode(config, mainEntry, {
|
|
@@ -7075,9 +8569,9 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7075
8569
|
});
|
|
7076
8570
|
builtPreloadFiles.length = 0;
|
|
7077
8571
|
for (const entry of preloadEntries) {
|
|
7078
|
-
if (!
|
|
7079
|
-
const base =
|
|
7080
|
-
const out =
|
|
8572
|
+
if (!fs14.existsSync(entry)) continue;
|
|
8573
|
+
const base = path20.basename(entry).replace(/\.[^.]+$/, "");
|
|
8574
|
+
const out = path20.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
7081
8575
|
await compileNode(config, entry, {
|
|
7082
8576
|
outFile: out,
|
|
7083
8577
|
format: config.electron.preloadFormat,
|
|
@@ -7116,7 +8610,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7116
8610
|
};
|
|
7117
8611
|
spawnElectron();
|
|
7118
8612
|
if (config.electron.autoRestart) {
|
|
7119
|
-
const watchTargets = [mainEntry, ...preloadEntries].filter(
|
|
8613
|
+
const watchTargets = [mainEntry, ...preloadEntries].filter(fs14.existsSync);
|
|
7120
8614
|
const watcher = chokidar.watch(watchTargets, { ignoreInitial: true });
|
|
7121
8615
|
let restarting = null;
|
|
7122
8616
|
let pending = false;
|
|
@@ -7163,8 +8657,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7163
8657
|
});
|
|
7164
8658
|
}
|
|
7165
8659
|
}
|
|
7166
|
-
function extFor(
|
|
7167
|
-
return
|
|
8660
|
+
function extFor(format2) {
|
|
8661
|
+
return format2 === "cjs" ? ".cjs" : ".mjs";
|
|
7168
8662
|
}
|
|
7169
8663
|
async function compileNode(config, entry, opts) {
|
|
7170
8664
|
const env = loadEnv(config.mode, config.root, config.envPrefix);
|
|
@@ -7176,14 +8670,21 @@ async function compileNode(config, entry, opts) {
|
|
|
7176
8670
|
};
|
|
7177
8671
|
const oxcTransformPlugin = {
|
|
7178
8672
|
name: "nasti:oxc-transform",
|
|
7179
|
-
transform(code, id) {
|
|
7180
|
-
|
|
7181
|
-
|
|
8673
|
+
async transform(code, id) {
|
|
8674
|
+
const result = config.framework === "react" ? await transformReactCode(id, code, {
|
|
8675
|
+
react: config.react,
|
|
8676
|
+
consumer: "server",
|
|
8677
|
+
development: true,
|
|
8678
|
+
sourcemap: true,
|
|
8679
|
+
target: config.electron.nodeTarget,
|
|
8680
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
8681
|
+
}) : shouldTransform(id) ? transformCode(id, code, {
|
|
7182
8682
|
sourcemap: true,
|
|
7183
8683
|
jsxRuntime: "automatic",
|
|
7184
|
-
jsxImportSource:
|
|
8684
|
+
jsxImportSource: "vue",
|
|
7185
8685
|
target: config.electron.nodeTarget
|
|
7186
|
-
});
|
|
8686
|
+
}) : null;
|
|
8687
|
+
if (!result) return null;
|
|
7187
8688
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
7188
8689
|
}
|
|
7189
8690
|
};
|
|
@@ -7196,7 +8697,7 @@ async function compileNode(config, entry, opts) {
|
|
|
7196
8697
|
platform: "node",
|
|
7197
8698
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
7198
8699
|
});
|
|
7199
|
-
|
|
8700
|
+
fs14.mkdirSync(path20.dirname(opts.outFile), { recursive: true });
|
|
7200
8701
|
await bundle2.write({
|
|
7201
8702
|
file: opts.outFile,
|
|
7202
8703
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -7209,18 +8710,18 @@ async function compileNode(config, entry, opts) {
|
|
|
7209
8710
|
await bundle2.close();
|
|
7210
8711
|
}
|
|
7211
8712
|
function electronRendererDevPath(renderer) {
|
|
7212
|
-
const normalized = renderer.split(
|
|
8713
|
+
const normalized = renderer.split(path20.sep).join("/").replace(/^\.?\//, "");
|
|
7213
8714
|
return normalized === "index.html" ? "/" : `/${normalized}`;
|
|
7214
8715
|
}
|
|
7215
8716
|
function resolveElectronBinary(config) {
|
|
7216
|
-
if (config.electron.electronPath &&
|
|
8717
|
+
if (config.electron.electronPath && fs14.existsSync(config.electron.electronPath)) {
|
|
7217
8718
|
return config.electron.electronPath;
|
|
7218
8719
|
}
|
|
7219
8720
|
try {
|
|
7220
|
-
const require2 =
|
|
8721
|
+
const require2 = createRequire5(path20.resolve(config.root, "package.json"));
|
|
7221
8722
|
const pathFile = require2.resolve("electron");
|
|
7222
8723
|
const electronModule = require2(pathFile);
|
|
7223
|
-
if (typeof electronModule === "string" &&
|
|
8724
|
+
if (typeof electronModule === "string" && fs14.existsSync(electronModule)) {
|
|
7224
8725
|
return electronModule;
|
|
7225
8726
|
}
|
|
7226
8727
|
} catch {
|
|
@@ -7247,10 +8748,10 @@ function warnElectronVersion(config) {
|
|
|
7247
8748
|
}
|
|
7248
8749
|
|
|
7249
8750
|
// src/plugins/monaco-editor.ts
|
|
7250
|
-
import
|
|
7251
|
-
import
|
|
8751
|
+
import path21 from "path";
|
|
8752
|
+
import fs15 from "fs";
|
|
7252
8753
|
import crypto4 from "crypto";
|
|
7253
|
-
import { createRequire as
|
|
8754
|
+
import { createRequire as createRequire6 } from "module";
|
|
7254
8755
|
var DEFAULT_WORKERS = {
|
|
7255
8756
|
editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
|
|
7256
8757
|
css: "monaco-editor/esm/vs/language/css/css.worker",
|
|
@@ -7269,9 +8770,9 @@ function normalizePublicPath(p) {
|
|
|
7269
8770
|
}
|
|
7270
8771
|
function readMonacoVersion(root) {
|
|
7271
8772
|
try {
|
|
7272
|
-
const require2 =
|
|
8773
|
+
const require2 = createRequire6(path21.resolve(root, "package.json"));
|
|
7273
8774
|
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
7274
|
-
const pkg = JSON.parse(
|
|
8775
|
+
const pkg = JSON.parse(fs15.readFileSync(pkgJsonPath, "utf-8"));
|
|
7275
8776
|
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
7276
8777
|
} catch {
|
|
7277
8778
|
return "unknown";
|
|
@@ -7291,20 +8792,20 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7291
8792
|
let cacheDir = "";
|
|
7292
8793
|
const building = /* @__PURE__ */ new Map();
|
|
7293
8794
|
async function buildWorker(worker) {
|
|
7294
|
-
const cacheFile =
|
|
7295
|
-
if (
|
|
8795
|
+
const cacheFile = path21.join(cacheDir, `${worker.label}.worker.js`);
|
|
8796
|
+
if (fs15.existsSync(cacheFile)) return cacheFile;
|
|
7296
8797
|
const existing = building.get(worker.label);
|
|
7297
8798
|
if (existing) return existing;
|
|
7298
8799
|
const task = (async () => {
|
|
7299
8800
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
7300
|
-
const require2 =
|
|
8801
|
+
const require2 = createRequire6(path21.resolve(resolvedConfig.root, "package.json"));
|
|
7301
8802
|
let entry;
|
|
7302
8803
|
try {
|
|
7303
8804
|
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
7304
8805
|
} catch {
|
|
7305
8806
|
entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
|
|
7306
8807
|
}
|
|
7307
|
-
|
|
8808
|
+
fs15.mkdirSync(cacheDir, { recursive: true });
|
|
7308
8809
|
const bundle2 = await rolldown4({
|
|
7309
8810
|
input: entry,
|
|
7310
8811
|
platform: "browser"
|
|
@@ -7364,15 +8865,15 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7364
8865
|
resolvedConfig = config;
|
|
7365
8866
|
const version = readMonacoVersion(config.root);
|
|
7366
8867
|
const key = crypto4.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
7367
|
-
cacheDir =
|
|
8868
|
+
cacheDir = path21.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
7368
8869
|
},
|
|
7369
8870
|
async configureServer(server) {
|
|
7370
8871
|
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
7371
8872
|
const watcher = server.watcher;
|
|
7372
|
-
const monacoLogical =
|
|
8873
|
+
const monacoLogical = path21.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
7373
8874
|
const monacoPaths = /* @__PURE__ */ new Set([monacoLogical]);
|
|
7374
8875
|
try {
|
|
7375
|
-
monacoPaths.add(
|
|
8876
|
+
monacoPaths.add(fs15.realpathSync(monacoLogical));
|
|
7376
8877
|
} catch {
|
|
7377
8878
|
}
|
|
7378
8879
|
for (const monacoDir of monacoPaths) {
|
|
@@ -7406,7 +8907,7 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7406
8907
|
const file = await buildWorker(worker);
|
|
7407
8908
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
7408
8909
|
res.setHeader("Cache-Control", "public, max-age=604800, immutable");
|
|
7409
|
-
|
|
8910
|
+
fs15.createReadStream(file).pipe(res);
|
|
7410
8911
|
} catch (e) {
|
|
7411
8912
|
res.statusCode = 500;
|
|
7412
8913
|
res.end(`Monaco worker build failed: ${e.message}`);
|
|
@@ -7441,16 +8942,16 @@ self.monaco = monaco;`,
|
|
|
7441
8942
|
resolvedConfig.root,
|
|
7442
8943
|
resolvedConfig.build.outDir,
|
|
7443
8944
|
resolvedConfig.base
|
|
7444
|
-
) : isCDN(publicPath) ?
|
|
8945
|
+
) : isCDN(publicPath) ? path21.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : path21.resolve(
|
|
7445
8946
|
resolvedConfig.root,
|
|
7446
8947
|
resolvedConfig.build.outDir,
|
|
7447
8948
|
publicPath.replace(/^\//, "")
|
|
7448
8949
|
);
|
|
7449
|
-
|
|
8950
|
+
fs15.mkdirSync(outDir, { recursive: true });
|
|
7450
8951
|
for (const worker of workers) {
|
|
7451
8952
|
try {
|
|
7452
8953
|
const cacheFile = await buildWorker(worker);
|
|
7453
|
-
|
|
8954
|
+
fs15.copyFileSync(cacheFile, path21.join(outDir, `${worker.label}.worker.js`));
|
|
7454
8955
|
} catch (e) {
|
|
7455
8956
|
throw new Error(
|
|
7456
8957
|
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|
|
@@ -7462,6 +8963,345 @@ ${e.stack || ""}`
|
|
|
7462
8963
|
};
|
|
7463
8964
|
}
|
|
7464
8965
|
|
|
8966
|
+
// src/plugins/rsc.ts
|
|
8967
|
+
init_transformer();
|
|
8968
|
+
import fs16 from "fs";
|
|
8969
|
+
import path22 from "path";
|
|
8970
|
+
import { parseSync } from "oxc-parser";
|
|
8971
|
+
var SERVER_RUNTIME_ID = "virtual:nasti-rsc/server-runtime";
|
|
8972
|
+
var CLIENT_RUNTIME_ID = "virtual:nasti-rsc/client-runtime";
|
|
8973
|
+
var RESOLVED_SERVER_RUNTIME_ID = `\0${SERVER_RUNTIME_ID}`;
|
|
8974
|
+
var RESOLVED_CLIENT_RUNTIME_ID = `\0${CLIENT_RUNTIME_ID}`;
|
|
8975
|
+
function rsc(options = {}) {
|
|
8976
|
+
const names = {
|
|
8977
|
+
client: options.environment?.client ?? "client",
|
|
8978
|
+
ssr: options.environment?.ssr ?? "ssr",
|
|
8979
|
+
rsc: options.environment?.rsc ?? "rsc"
|
|
8980
|
+
};
|
|
8981
|
+
const clientReferences = /* @__PURE__ */ new Map();
|
|
8982
|
+
const serverReferences = /* @__PURE__ */ new Map();
|
|
8983
|
+
let resolvedConfig;
|
|
8984
|
+
return {
|
|
8985
|
+
name: "nasti:rsc",
|
|
8986
|
+
enforce: "post",
|
|
8987
|
+
config(config, env) {
|
|
8988
|
+
const root = path22.resolve(config.root ?? ".");
|
|
8989
|
+
const include = options.include ?? config.react?.include ?? /\.[tj]sx?$/;
|
|
8990
|
+
const exclude = options.exclude ?? config.react?.exclude ?? /node_modules/;
|
|
8991
|
+
const discoveredClients = env.command === "build" ? discoverDirectiveModules(root, options.scanDirectories, include, exclude) : [];
|
|
8992
|
+
for (const item of discoveredClients) {
|
|
8993
|
+
if (item.module.useClient) {
|
|
8994
|
+
clientReferences.set(
|
|
8995
|
+
item.id,
|
|
8996
|
+
new Set(item.module.exports.map((entry) => entry.exported))
|
|
8997
|
+
);
|
|
8998
|
+
}
|
|
8999
|
+
if (item.module.useServer) {
|
|
9000
|
+
serverReferences.set(
|
|
9001
|
+
item.id,
|
|
9002
|
+
new Set(item.module.exports.map((entry) => entry.exported))
|
|
9003
|
+
);
|
|
9004
|
+
}
|
|
9005
|
+
}
|
|
9006
|
+
const environments = { ...config.environments ?? {} };
|
|
9007
|
+
if (names.client !== "client") {
|
|
9008
|
+
environments.client = {
|
|
9009
|
+
...environments.client ?? {},
|
|
9010
|
+
buildEnabled: false
|
|
9011
|
+
};
|
|
9012
|
+
}
|
|
9013
|
+
const client = { ...environments[names.client] ?? {} };
|
|
9014
|
+
const clientSeeds = collectClientSeeds(root, config, client, options.entries?.client);
|
|
9015
|
+
const generatedClientEntries = discoveredClients.filter((item) => item.module.useClient).map((item) => item.id);
|
|
9016
|
+
client.consumer = "client";
|
|
9017
|
+
client.entry = uniqueEntries([...clientSeeds, ...generatedClientEntries]);
|
|
9018
|
+
environments[names.client] = client;
|
|
9019
|
+
const rscEnvironment = { ...environments[names.rsc] ?? {} };
|
|
9020
|
+
rscEnvironment.consumer = "server";
|
|
9021
|
+
const rscEntries = normalizeEntries(options.entries?.rsc);
|
|
9022
|
+
if (rscEntries.length > 0) rscEnvironment.entry = rscEntries;
|
|
9023
|
+
environments[names.rsc] = rscEnvironment;
|
|
9024
|
+
const ssrEntries = normalizeEntries(options.entries?.ssr);
|
|
9025
|
+
if (ssrEntries.length > 0 || environments[names.ssr]) {
|
|
9026
|
+
environments[names.ssr] = {
|
|
9027
|
+
...environments[names.ssr] ?? {},
|
|
9028
|
+
consumer: "server",
|
|
9029
|
+
...ssrEntries.length > 0 ? { entry: ssrEntries } : {}
|
|
9030
|
+
};
|
|
9031
|
+
}
|
|
9032
|
+
return { environments };
|
|
9033
|
+
},
|
|
9034
|
+
configEnvironment(name, environment) {
|
|
9035
|
+
if (name !== names.rsc) return;
|
|
9036
|
+
const conditions = environment.resolve?.conditions ?? ["node", "import", "module", "default"];
|
|
9037
|
+
return {
|
|
9038
|
+
consumer: "server",
|
|
9039
|
+
resolve: {
|
|
9040
|
+
...environment.resolve,
|
|
9041
|
+
conditions: ["react-server", ...conditions.filter((item) => item !== "react-server")]
|
|
9042
|
+
}
|
|
9043
|
+
};
|
|
9044
|
+
},
|
|
9045
|
+
configResolved(config) {
|
|
9046
|
+
if (config.framework !== "react") {
|
|
9047
|
+
throw new Error('[nasti:rsc] the RSC generator requires framework: "react"');
|
|
9048
|
+
}
|
|
9049
|
+
resolvedConfig = config;
|
|
9050
|
+
},
|
|
9051
|
+
resolveId(source) {
|
|
9052
|
+
if (source === SERVER_RUNTIME_ID) return RESOLVED_SERVER_RUNTIME_ID;
|
|
9053
|
+
if (source === CLIENT_RUNTIME_ID) return RESOLVED_CLIENT_RUNTIME_ID;
|
|
9054
|
+
return null;
|
|
9055
|
+
},
|
|
9056
|
+
load(id) {
|
|
9057
|
+
if (id === RESOLVED_SERVER_RUNTIME_ID) return createServerRuntimeModule();
|
|
9058
|
+
if (id === RESOLVED_CLIENT_RUNTIME_ID) {
|
|
9059
|
+
const browser = this.environment?.name === names.client;
|
|
9060
|
+
return createClientRuntimeModule(browser);
|
|
9061
|
+
}
|
|
9062
|
+
return null;
|
|
9063
|
+
},
|
|
9064
|
+
transform(code, id) {
|
|
9065
|
+
if (!resolvedConfig || !isSourceModule(id, resolvedConfig, options)) return null;
|
|
9066
|
+
const cleanId = cleanModuleId(id);
|
|
9067
|
+
const module = scanModule(cleanId, code);
|
|
9068
|
+
if (!module) return null;
|
|
9069
|
+
if (module.useClient && module.useServer) {
|
|
9070
|
+
throw new Error(`[nasti:rsc] ${displayId(resolvedConfig.root, cleanId)} cannot contain both "use client" and "use server"`);
|
|
9071
|
+
}
|
|
9072
|
+
const moduleId = referenceModuleId(resolvedConfig.root, cleanId);
|
|
9073
|
+
if (module.useClient) {
|
|
9074
|
+
clientReferences.set(cleanId, new Set(module.exports.map((entry) => entry.exported)));
|
|
9075
|
+
if (this.environment?.name === names.rsc) {
|
|
9076
|
+
return {
|
|
9077
|
+
code: createClientReferenceProxy(moduleId, module.exports),
|
|
9078
|
+
map: { mappings: "" }
|
|
9079
|
+
};
|
|
9080
|
+
}
|
|
9081
|
+
}
|
|
9082
|
+
if (module.useServer) {
|
|
9083
|
+
serverReferences.set(cleanId, new Set(module.exports.map((entry) => entry.exported)));
|
|
9084
|
+
if (this.environment?.name === names.rsc) {
|
|
9085
|
+
return {
|
|
9086
|
+
code: registerServerReferences(code, moduleId, module.exports, cleanId),
|
|
9087
|
+
map: { mappings: "" }
|
|
9088
|
+
};
|
|
9089
|
+
}
|
|
9090
|
+
if (this.environment?.consumer === "client" || this.environment?.name === names.client || this.environment?.name === names.ssr) {
|
|
9091
|
+
return {
|
|
9092
|
+
code: createServerReferenceProxy(moduleId, module.exports),
|
|
9093
|
+
map: { mappings: "" }
|
|
9094
|
+
};
|
|
9095
|
+
}
|
|
9096
|
+
}
|
|
9097
|
+
return null;
|
|
9098
|
+
},
|
|
9099
|
+
afterBuildApp(results, _api, context) {
|
|
9100
|
+
if (options.manifestFile === false) return;
|
|
9101
|
+
const manifest = createManifest(
|
|
9102
|
+
names,
|
|
9103
|
+
resolvedConfig?.root ?? "",
|
|
9104
|
+
results,
|
|
9105
|
+
clientReferences,
|
|
9106
|
+
serverReferences
|
|
9107
|
+
);
|
|
9108
|
+
const output = {
|
|
9109
|
+
type: "asset",
|
|
9110
|
+
fileName: options.manifestFile ?? "rsc-manifest.json",
|
|
9111
|
+
source: JSON.stringify(manifest, null, 2) + "\n"
|
|
9112
|
+
};
|
|
9113
|
+
context.emitFile(output);
|
|
9114
|
+
}
|
|
9115
|
+
};
|
|
9116
|
+
}
|
|
9117
|
+
function scanModule(filename, code) {
|
|
9118
|
+
if (!code.includes("use client") && !code.includes("use server")) return null;
|
|
9119
|
+
const parsed = parseSync(filename, code);
|
|
9120
|
+
if (parsed.errors.length > 0) return null;
|
|
9121
|
+
const directives = new Set(
|
|
9122
|
+
parsed.program.body.filter((node) => node.type === "ExpressionStatement" && typeof node.directive === "string").map((node) => node.directive)
|
|
9123
|
+
);
|
|
9124
|
+
const useClient = directives.has("use client");
|
|
9125
|
+
const useServer = directives.has("use server");
|
|
9126
|
+
if (!useClient && !useServer) return null;
|
|
9127
|
+
const exports = [];
|
|
9128
|
+
for (const statement of parsed.module.staticExports) {
|
|
9129
|
+
for (const entry of statement.entries) {
|
|
9130
|
+
if (entry.isType) continue;
|
|
9131
|
+
const exported = entry.exportName.kind === "Default" ? "default" : entry.exportName.name;
|
|
9132
|
+
if (!exported) {
|
|
9133
|
+
throw new Error(
|
|
9134
|
+
`[nasti:rsc] ${filename} uses export * inside an RSC directive module; replace it with explicit named exports so reference identities are stable`
|
|
9135
|
+
);
|
|
9136
|
+
}
|
|
9137
|
+
exports.push({
|
|
9138
|
+
exported,
|
|
9139
|
+
local: entry.localName.kind === "Name" ? entry.localName.name ?? void 0 : void 0,
|
|
9140
|
+
reexported: entry.moduleRequest !== null
|
|
9141
|
+
});
|
|
9142
|
+
}
|
|
9143
|
+
}
|
|
9144
|
+
return { useClient, useServer, exports: dedupeExports(exports) };
|
|
9145
|
+
}
|
|
9146
|
+
function createClientReferenceProxy(moduleId, exports) {
|
|
9147
|
+
const lines = [
|
|
9148
|
+
`import { registerClientReference as __nasti_register_client__ } from ${JSON.stringify(SERVER_RUNTIME_ID)};`
|
|
9149
|
+
];
|
|
9150
|
+
exports.forEach((entry, index2) => {
|
|
9151
|
+
const local = `__nasti_client_reference_${index2}__`;
|
|
9152
|
+
const message = `Cannot call client export ${moduleId}#${entry.exported} from the RSC server graph.`;
|
|
9153
|
+
lines.push(
|
|
9154
|
+
`const ${local} = __nasti_register_client__(function () { throw new Error(${JSON.stringify(message)}); }, ${JSON.stringify(moduleId)}, ${JSON.stringify(entry.exported)});`,
|
|
9155
|
+
exportLocal(local, entry.exported)
|
|
9156
|
+
);
|
|
9157
|
+
});
|
|
9158
|
+
return lines.join("\n") + "\n";
|
|
9159
|
+
}
|
|
9160
|
+
function registerServerReferences(code, moduleId, exports, filename) {
|
|
9161
|
+
const registrations = [];
|
|
9162
|
+
for (const entry of exports) {
|
|
9163
|
+
if (entry.reexported || !entry.local) {
|
|
9164
|
+
throw new Error(
|
|
9165
|
+
`[nasti:rsc] ${filename} must use named local bindings for "use server" exports; ${entry.exported} cannot be registered safely`
|
|
9166
|
+
);
|
|
9167
|
+
}
|
|
9168
|
+
registrations.push(
|
|
9169
|
+
`__nasti_register_server__(${entry.local}, ${JSON.stringify(moduleId)}, ${JSON.stringify(entry.exported)});`
|
|
9170
|
+
);
|
|
9171
|
+
}
|
|
9172
|
+
return [
|
|
9173
|
+
code,
|
|
9174
|
+
`import { registerServerReference as __nasti_register_server__ } from ${JSON.stringify(SERVER_RUNTIME_ID)};`,
|
|
9175
|
+
...registrations,
|
|
9176
|
+
""
|
|
9177
|
+
].join("\n");
|
|
9178
|
+
}
|
|
9179
|
+
function createServerReferenceProxy(moduleId, exports) {
|
|
9180
|
+
const lines = [
|
|
9181
|
+
`import { createServerReference as __nasti_create_server__ } from ${JSON.stringify(CLIENT_RUNTIME_ID)};`
|
|
9182
|
+
];
|
|
9183
|
+
exports.forEach((entry, index2) => {
|
|
9184
|
+
const local = `__nasti_server_reference_${index2}__`;
|
|
9185
|
+
lines.push(
|
|
9186
|
+
`const ${local} = __nasti_create_server__(${JSON.stringify(moduleId)}, ${JSON.stringify(entry.exported)});`,
|
|
9187
|
+
exportLocal(local, entry.exported)
|
|
9188
|
+
);
|
|
9189
|
+
});
|
|
9190
|
+
return lines.join("\n") + "\n";
|
|
9191
|
+
}
|
|
9192
|
+
function exportLocal(local, exported) {
|
|
9193
|
+
if (exported === "default") return `export default ${local};`;
|
|
9194
|
+
const name = /^[A-Za-z_$][\w$]*$/.test(exported) ? exported : JSON.stringify(exported);
|
|
9195
|
+
return `export { ${local} as ${name} };`;
|
|
9196
|
+
}
|
|
9197
|
+
function createServerRuntimeModule() {
|
|
9198
|
+
return [
|
|
9199
|
+
`export { registerClientReference, registerServerReference } from "react-server-dom-webpack/server.edge";`,
|
|
9200
|
+
""
|
|
9201
|
+
].join("\n");
|
|
9202
|
+
}
|
|
9203
|
+
function createClientRuntimeModule(browser) {
|
|
9204
|
+
const source = browser ? "react-server-dom-webpack/client.browser" : "react-server-dom-webpack/client.edge";
|
|
9205
|
+
return `
|
|
9206
|
+
import { createServerReference as __createServerReference } from ${JSON.stringify(source)};
|
|
9207
|
+
const __callServer = (id, args) => {
|
|
9208
|
+
const handler = globalThis[Symbol.for("nasti.rsc.callServer")];
|
|
9209
|
+
if (typeof handler !== "function") {
|
|
9210
|
+
throw new Error("No RSC callServer handler is installed. Set globalThis[Symbol.for('nasti.rsc.callServer')].");
|
|
9211
|
+
}
|
|
9212
|
+
return handler(id, args);
|
|
9213
|
+
};
|
|
9214
|
+
export function createServerReference(moduleId, name) {
|
|
9215
|
+
return __createServerReference(moduleId + "#" + name, __callServer, undefined, undefined, name);
|
|
9216
|
+
}
|
|
9217
|
+
`.trimStart();
|
|
9218
|
+
}
|
|
9219
|
+
function createManifest(names, root, results, clients, servers) {
|
|
9220
|
+
return {
|
|
9221
|
+
version: 1,
|
|
9222
|
+
environments: names,
|
|
9223
|
+
clientReferences: manifestReferences(root, results[names.client], clients),
|
|
9224
|
+
serverReferences: manifestReferences(root, results[names.rsc], servers)
|
|
9225
|
+
};
|
|
9226
|
+
}
|
|
9227
|
+
function manifestReferences(root, result, references) {
|
|
9228
|
+
const output = {};
|
|
9229
|
+
for (const [id, names] of [...references].sort(([a], [b]) => a.localeCompare(b))) {
|
|
9230
|
+
const chunks = Object.values(result?.chunks ?? {}).filter((chunk) => chunk.moduleIds.some((moduleId) => cleanModuleId(moduleId) === id)).map((chunk) => chunk.fileName).sort();
|
|
9231
|
+
for (const name of [...names].sort()) {
|
|
9232
|
+
const moduleId = referenceModuleId(root, id);
|
|
9233
|
+
output[`${moduleId}#${name}`] = { id: moduleId, name, chunks };
|
|
9234
|
+
}
|
|
9235
|
+
}
|
|
9236
|
+
return output;
|
|
9237
|
+
}
|
|
9238
|
+
function discoverDirectiveModules(root, scanDirectories, include, exclude) {
|
|
9239
|
+
const requested = scanDirectories ?? ["app", "src"];
|
|
9240
|
+
const roots = requested.map((directory) => path22.resolve(root, directory)).filter((directory) => fs16.existsSync(directory));
|
|
9241
|
+
if (roots.length === 0) roots.push(root);
|
|
9242
|
+
const output = [];
|
|
9243
|
+
for (const directory of roots) walk(directory);
|
|
9244
|
+
return output;
|
|
9245
|
+
function walk(directory) {
|
|
9246
|
+
for (const entry of fs16.readdirSync(directory, { withFileTypes: true })) {
|
|
9247
|
+
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".nasti") continue;
|
|
9248
|
+
const id = path22.join(directory, entry.name);
|
|
9249
|
+
if (entry.isDirectory()) {
|
|
9250
|
+
walk(id);
|
|
9251
|
+
continue;
|
|
9252
|
+
}
|
|
9253
|
+
if (!entry.isFile() || !matchesReactFilter(id, include, exclude)) continue;
|
|
9254
|
+
const module = scanModule(id, fs16.readFileSync(id, "utf-8"));
|
|
9255
|
+
if (module) output.push({ id, module });
|
|
9256
|
+
}
|
|
9257
|
+
}
|
|
9258
|
+
}
|
|
9259
|
+
function collectClientSeeds(root, config, client, configured) {
|
|
9260
|
+
const explicit = [
|
|
9261
|
+
...normalizeEntries(client.entry),
|
|
9262
|
+
...normalizeEntries(configured)
|
|
9263
|
+
];
|
|
9264
|
+
if (explicit.length > 0) return explicit;
|
|
9265
|
+
const htmlFile = path22.resolve(root, client.html ?? "index.html");
|
|
9266
|
+
if (fs16.existsSync(htmlFile)) {
|
|
9267
|
+
const html = fs16.readFileSync(htmlFile, "utf-8");
|
|
9268
|
+
const htmlDir = path22.dirname(htmlFile);
|
|
9269
|
+
const entries = [...html.matchAll(/<script[^>]+src=["']([^"']+)["'][^>]*>/gi)].map((match) => match[1]?.split(/[?#]/, 1)[0]).filter((entry) => !!entry && !entry.startsWith("http")).map((entry) => entry.startsWith("/") ? path22.resolve(root, entry.slice(1)) : path22.resolve(htmlDir, entry));
|
|
9270
|
+
if (entries.length > 0) return entries;
|
|
9271
|
+
}
|
|
9272
|
+
for (const entry of ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"]) {
|
|
9273
|
+
if (fs16.existsSync(path22.resolve(root, entry))) return [entry];
|
|
9274
|
+
}
|
|
9275
|
+
return [];
|
|
9276
|
+
}
|
|
9277
|
+
function normalizeEntries(entries) {
|
|
9278
|
+
return entries == null ? [] : Array.isArray(entries) ? entries : [entries];
|
|
9279
|
+
}
|
|
9280
|
+
function uniqueEntries(entries) {
|
|
9281
|
+
return [...new Set(entries)];
|
|
9282
|
+
}
|
|
9283
|
+
function isSourceModule(id, config, options) {
|
|
9284
|
+
const cleanId = cleanModuleId(id);
|
|
9285
|
+
if (cleanId.startsWith("\0")) return false;
|
|
9286
|
+
const include = options.include ?? config.react.include;
|
|
9287
|
+
const exclude = options.exclude ?? config.react.exclude;
|
|
9288
|
+
return matchesReactFilter(cleanId, include, exclude);
|
|
9289
|
+
}
|
|
9290
|
+
function cleanModuleId(id) {
|
|
9291
|
+
return id.split(/[?#]/, 1)[0];
|
|
9292
|
+
}
|
|
9293
|
+
function referenceModuleId(root, id) {
|
|
9294
|
+
if (!root || !path22.isAbsolute(id)) return id.replaceAll(path22.sep, "/");
|
|
9295
|
+
const relative = path22.relative(root, id).replaceAll(path22.sep, "/");
|
|
9296
|
+
return relative.startsWith("../") ? id.replaceAll(path22.sep, "/") : `/${relative}`;
|
|
9297
|
+
}
|
|
9298
|
+
function displayId(root, id) {
|
|
9299
|
+
return referenceModuleId(root, id);
|
|
9300
|
+
}
|
|
9301
|
+
function dedupeExports(exports) {
|
|
9302
|
+
return [...new Map(exports.map((entry) => [entry.exported, entry])).values()];
|
|
9303
|
+
}
|
|
9304
|
+
|
|
7465
9305
|
// src/index.ts
|
|
7466
9306
|
init_environment();
|
|
7467
9307
|
init_hot_channel();
|
|
@@ -7489,6 +9329,7 @@ export {
|
|
|
7489
9329
|
printServerUrls,
|
|
7490
9330
|
resolveConfig,
|
|
7491
9331
|
resolveEnvironmentPlugins,
|
|
9332
|
+
rsc,
|
|
7492
9333
|
ssrDefineOverrides,
|
|
7493
9334
|
startElectronDev
|
|
7494
9335
|
};
|