@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.cjs
CHANGED
|
@@ -5,16 +5,25 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __glob = (map) => (
|
|
9
|
-
var fn = map[
|
|
8
|
+
var __glob = (map) => (path23) => {
|
|
9
|
+
var fn = map[path23];
|
|
10
10
|
if (fn) return fn();
|
|
11
|
-
throw new Error("Module not found in bundle: " +
|
|
11
|
+
throw new Error("Module not found in bundle: " + path23);
|
|
12
12
|
};
|
|
13
|
-
var __esm = (fn, res) => function __init() {
|
|
14
|
-
|
|
13
|
+
var __esm = (fn, res, err) => function __init() {
|
|
14
|
+
if (err) throw err[0];
|
|
15
|
+
try {
|
|
16
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
throw err = [e], e;
|
|
19
|
+
}
|
|
15
20
|
};
|
|
16
21
|
var __commonJS = (cb, mod) => function __require2() {
|
|
17
|
-
|
|
22
|
+
try {
|
|
23
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw mod = 0, e;
|
|
26
|
+
}
|
|
18
27
|
};
|
|
19
28
|
var __export = (target, all) => {
|
|
20
29
|
for (var name in all)
|
|
@@ -39,7 +48,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
48
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
49
|
|
|
41
50
|
// src/config/defaults.ts
|
|
42
|
-
var defaultResolve, defaultServer, defaultBuild, defaultElectron, defaultExperimental, defaults;
|
|
51
|
+
var defaultResolve, defaultServer, defaultBuild, defaultElectron, defaultExperimental, defaultReact, defaults;
|
|
43
52
|
var init_defaults = __esm({
|
|
44
53
|
"src/config/defaults.ts"() {
|
|
45
54
|
"use strict";
|
|
@@ -92,12 +101,20 @@ var init_defaults = __esm({
|
|
|
92
101
|
defaultExperimental = {
|
|
93
102
|
bundledDev: false
|
|
94
103
|
};
|
|
104
|
+
defaultReact = {
|
|
105
|
+
include: /\.[tj]sx?$/,
|
|
106
|
+
exclude: /node_modules/,
|
|
107
|
+
jsxImportSource: "react",
|
|
108
|
+
jsxRuntime: "automatic",
|
|
109
|
+
compiler: false
|
|
110
|
+
};
|
|
95
111
|
defaults = {
|
|
96
112
|
root: ".",
|
|
97
113
|
base: "/",
|
|
98
114
|
mode: "development",
|
|
99
115
|
target: "web",
|
|
100
116
|
framework: "auto",
|
|
117
|
+
react: defaultReact,
|
|
101
118
|
resolve: defaultResolve,
|
|
102
119
|
server: defaultServer,
|
|
103
120
|
build: defaultBuild,
|
|
@@ -130,7 +147,7 @@ function createLogger(level = "info", options = {}) {
|
|
|
130
147
|
const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
|
|
131
148
|
const clear = canClearScreen ? clearScreen : () => {
|
|
132
149
|
};
|
|
133
|
-
function
|
|
150
|
+
function format2(type, msg, options2 = {}) {
|
|
134
151
|
if (options2.timestamp) {
|
|
135
152
|
const tag = type === "info" ? import_picocolors.default.cyan(import_picocolors.default.bold(prefix)) : type === "warn" ? import_picocolors.default.yellow(import_picocolors.default.bold(prefix)) : import_picocolors.default.red(import_picocolors.default.bold(prefix));
|
|
136
153
|
return `${import_picocolors.default.dim(timeFormatter.format(/* @__PURE__ */ new Date()))} ${tag} ${msg}`;
|
|
@@ -147,16 +164,16 @@ function createLogger(level = "info", options = {}) {
|
|
|
147
164
|
if (type === lastType && msg === lastMsg) {
|
|
148
165
|
sameCount++;
|
|
149
166
|
clear();
|
|
150
|
-
console_[method](
|
|
167
|
+
console_[method](format2(type, msg, options2), import_picocolors.default.yellow(`(x${sameCount + 1})`));
|
|
151
168
|
} else {
|
|
152
169
|
sameCount = 0;
|
|
153
170
|
lastMsg = msg;
|
|
154
171
|
lastType = type;
|
|
155
172
|
if (options2.clear) clear();
|
|
156
|
-
console_[method](
|
|
173
|
+
console_[method](format2(type, msg, options2));
|
|
157
174
|
}
|
|
158
175
|
} else {
|
|
159
|
-
console_[method](
|
|
176
|
+
console_[method](format2(type, msg, options2));
|
|
160
177
|
}
|
|
161
178
|
}
|
|
162
179
|
const warnedMessages = /* @__PURE__ */ new Set();
|
|
@@ -435,6 +452,13 @@ async function resolveConfig(inlineConfig = {}, command) {
|
|
|
435
452
|
mode,
|
|
436
453
|
target: merged.target ?? defaults.target,
|
|
437
454
|
framework: (merged.framework ?? defaults.framework) === "auto" ? detectFramework(root) : merged.framework,
|
|
455
|
+
react: {
|
|
456
|
+
include: merged.react?.include ?? defaultReact.include,
|
|
457
|
+
exclude: merged.react?.exclude ?? defaultReact.exclude,
|
|
458
|
+
jsxImportSource: merged.react?.jsxImportSource ?? defaultReact.jsxImportSource,
|
|
459
|
+
jsxRuntime: merged.react?.jsxRuntime ?? defaultReact.jsxRuntime,
|
|
460
|
+
compiler: merged.react?.compiler === true ? {} : merged.react?.compiler ?? defaultReact.compiler
|
|
461
|
+
},
|
|
438
462
|
command,
|
|
439
463
|
resolve: {
|
|
440
464
|
// tsconfig paths 优先级最低:tsconfig < defaults < user config
|
|
@@ -873,27 +897,27 @@ var require_process = __commonJS({
|
|
|
873
897
|
var require_filesystem = __commonJS({
|
|
874
898
|
"node_modules/detect-libc/lib/filesystem.js"(exports2, module2) {
|
|
875
899
|
"use strict";
|
|
876
|
-
var
|
|
900
|
+
var fs17 = require("fs");
|
|
877
901
|
var LDD_PATH = "/usr/bin/ldd";
|
|
878
902
|
var SELF_PATH = "/proc/self/exe";
|
|
879
903
|
var MAX_LENGTH = 2048;
|
|
880
|
-
var readFileSync = (
|
|
881
|
-
const fd =
|
|
904
|
+
var readFileSync = (path23) => {
|
|
905
|
+
const fd = fs17.openSync(path23, "r");
|
|
882
906
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
883
|
-
const bytesRead =
|
|
884
|
-
|
|
907
|
+
const bytesRead = fs17.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
908
|
+
fs17.close(fd, () => {
|
|
885
909
|
});
|
|
886
910
|
return buffer.subarray(0, bytesRead);
|
|
887
911
|
};
|
|
888
|
-
var readFile = (
|
|
889
|
-
|
|
912
|
+
var readFile = (path23) => new Promise((resolve, reject) => {
|
|
913
|
+
fs17.open(path23, "r", (err, fd) => {
|
|
890
914
|
if (err) {
|
|
891
915
|
reject(err);
|
|
892
916
|
} else {
|
|
893
917
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
894
|
-
|
|
918
|
+
fs17.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
|
|
895
919
|
resolve(buffer.subarray(0, bytesRead));
|
|
896
|
-
|
|
920
|
+
fs17.close(fd, () => {
|
|
897
921
|
});
|
|
898
922
|
});
|
|
899
923
|
}
|
|
@@ -1005,11 +1029,11 @@ var require_detect_libc = __commonJS({
|
|
|
1005
1029
|
}
|
|
1006
1030
|
return null;
|
|
1007
1031
|
};
|
|
1008
|
-
var familyFromInterpreterPath = (
|
|
1009
|
-
if (
|
|
1010
|
-
if (
|
|
1032
|
+
var familyFromInterpreterPath = (path23) => {
|
|
1033
|
+
if (path23) {
|
|
1034
|
+
if (path23.includes("/ld-musl-")) {
|
|
1011
1035
|
return MUSL;
|
|
1012
|
-
} else if (
|
|
1036
|
+
} else if (path23.includes("/ld-linux-")) {
|
|
1013
1037
|
return GLIBC;
|
|
1014
1038
|
}
|
|
1015
1039
|
}
|
|
@@ -1056,8 +1080,8 @@ var require_detect_libc = __commonJS({
|
|
|
1056
1080
|
cachedFamilyInterpreter = null;
|
|
1057
1081
|
try {
|
|
1058
1082
|
const selfContent = await readFile(SELF_PATH);
|
|
1059
|
-
const
|
|
1060
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1083
|
+
const path23 = interpreterPath(selfContent);
|
|
1084
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path23);
|
|
1061
1085
|
} catch (e) {
|
|
1062
1086
|
}
|
|
1063
1087
|
return cachedFamilyInterpreter;
|
|
@@ -1069,8 +1093,8 @@ var require_detect_libc = __commonJS({
|
|
|
1069
1093
|
cachedFamilyInterpreter = null;
|
|
1070
1094
|
try {
|
|
1071
1095
|
const selfContent = readFileSync(SELF_PATH);
|
|
1072
|
-
const
|
|
1073
|
-
cachedFamilyInterpreter = familyFromInterpreterPath(
|
|
1096
|
+
const path23 = interpreterPath(selfContent);
|
|
1097
|
+
cachedFamilyInterpreter = familyFromInterpreterPath(path23);
|
|
1074
1098
|
} catch (e) {
|
|
1075
1099
|
}
|
|
1076
1100
|
return cachedFamilyInterpreter;
|
|
@@ -2171,7 +2195,81 @@ ${msg}`);
|
|
|
2171
2195
|
map: result.map ? JSON.stringify(result.map) : null
|
|
2172
2196
|
};
|
|
2173
2197
|
}
|
|
2174
|
-
|
|
2198
|
+
async function transformReactCode(filename, code, options) {
|
|
2199
|
+
if (!matchesReactFilter(filename, options.react.include, options.react.exclude)) {
|
|
2200
|
+
return null;
|
|
2201
|
+
}
|
|
2202
|
+
if (!options.react.compiler) {
|
|
2203
|
+
if (!shouldTransform(filename)) return null;
|
|
2204
|
+
return transformCode(filename, code, {
|
|
2205
|
+
sourcemap: options.sourcemap,
|
|
2206
|
+
jsxRuntime: options.react.jsxRuntime,
|
|
2207
|
+
jsxImportSource: options.react.jsxImportSource,
|
|
2208
|
+
reactRefresh: options.reactRefresh,
|
|
2209
|
+
target: options.target
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
if (!shouldTransform(filename)) return null;
|
|
2213
|
+
const compiler2 = await loadReactCompiler();
|
|
2214
|
+
const compilerOptions = options.react.compiler;
|
|
2215
|
+
const shouldCompile = options.consumer === "client" && (compilerOptions.compilationMode === "annotation" ? /['"]use memo['"]/.test(code) : defaultReactCompilerCodeFilter.test(code));
|
|
2216
|
+
const result = await compiler2.transform(cleanTransformId(filename), code, {
|
|
2217
|
+
jsx: {
|
|
2218
|
+
runtime: options.react.jsxRuntime,
|
|
2219
|
+
development: options.development,
|
|
2220
|
+
importSource: options.react.jsxImportSource,
|
|
2221
|
+
refresh: options.consumer === "client" && !!options.reactRefresh
|
|
2222
|
+
},
|
|
2223
|
+
reactCompiler: shouldCompile ? compilerOptions : false,
|
|
2224
|
+
sourcemap: options.sourcemap ?? true
|
|
2225
|
+
});
|
|
2226
|
+
const diagnostics = result.errors.map(
|
|
2227
|
+
(error) => `${error.message}${error.codeframe ? `
|
|
2228
|
+
${error.codeframe}` : ""}`
|
|
2229
|
+
);
|
|
2230
|
+
if (result.fatal) {
|
|
2231
|
+
throw new Error(
|
|
2232
|
+
diagnostics.join("\n\n") || `React Compiler transform failed for ${filename}`
|
|
2233
|
+
);
|
|
2234
|
+
}
|
|
2235
|
+
for (const diagnostic of diagnostics) options.onWarning?.(diagnostic);
|
|
2236
|
+
return {
|
|
2237
|
+
code: result.code,
|
|
2238
|
+
map: result.map ? JSON.stringify(result.map) : null
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
function matchesReactFilter(id, include, exclude) {
|
|
2242
|
+
const cleanId = cleanTransformId(id);
|
|
2243
|
+
return matchesFilter(cleanId, include) && !matchesFilter(cleanId, exclude);
|
|
2244
|
+
}
|
|
2245
|
+
function matchesFilter(id, filter2) {
|
|
2246
|
+
const patterns = Array.isArray(filter2) ? filter2 : [filter2];
|
|
2247
|
+
return patterns.some((pattern) => {
|
|
2248
|
+
if (pattern instanceof RegExp) {
|
|
2249
|
+
pattern.lastIndex = 0;
|
|
2250
|
+
return pattern.test(id);
|
|
2251
|
+
}
|
|
2252
|
+
if (!pattern.includes("*")) return id.includes(pattern);
|
|
2253
|
+
const expression = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\0").replace(/\*/g, "[^/]*").replace(/\0/g, ".*");
|
|
2254
|
+
return new RegExp(`^${expression}$`).test(id);
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
function cleanTransformId(id) {
|
|
2258
|
+
return id.split(/[?#]/, 1)[0];
|
|
2259
|
+
}
|
|
2260
|
+
async function loadReactCompiler() {
|
|
2261
|
+
if (reactCompilerImplementation) return reactCompilerImplementation;
|
|
2262
|
+
try {
|
|
2263
|
+
reactCompilerImplementation = await import("oxc-transform-react");
|
|
2264
|
+
return reactCompilerImplementation;
|
|
2265
|
+
} catch (error) {
|
|
2266
|
+
throw new Error(
|
|
2267
|
+
'[nasti] React Compiler requires the optional "oxc-transform-react" package. Install it before setting react.compiler.' + (error instanceof Error ? `
|
|
2268
|
+
${error.message}` : "")
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
var import_oxc_transform, JS_EXTENSIONS, TS_EXTENSIONS, JSX_EXTENSIONS, defaultReactCompilerCodeFilter, reactCompilerImplementation;
|
|
2175
2273
|
var init_transformer = __esm({
|
|
2176
2274
|
"src/core/transformer.ts"() {
|
|
2177
2275
|
"use strict";
|
|
@@ -2179,6 +2277,7 @@ var init_transformer = __esm({
|
|
|
2179
2277
|
JS_EXTENSIONS = /\.(js|mjs|cjs)$/;
|
|
2180
2278
|
TS_EXTENSIONS = /\.(ts|mts|cts)$/;
|
|
2181
2279
|
JSX_EXTENSIONS = /\.(jsx|tsx)$/;
|
|
2280
|
+
defaultReactCompilerCodeFilter = /forwardRef|memo|\b(?:[A-Z]|use[A-Z0-9])/;
|
|
2182
2281
|
}
|
|
2183
2282
|
});
|
|
2184
2283
|
|
|
@@ -2218,8 +2317,8 @@ function vuePlugin(config, environmentName = "client") {
|
|
|
2218
2317
|
let cached2 = descriptorCache.get(filePath);
|
|
2219
2318
|
if (!cached2) {
|
|
2220
2319
|
try {
|
|
2221
|
-
const
|
|
2222
|
-
const rawSource =
|
|
2320
|
+
const fs17 = await import("fs");
|
|
2321
|
+
const rawSource = fs17.readFileSync(filePath, "utf-8");
|
|
2223
2322
|
const transformedSfc = await applySourceTransform(
|
|
2224
2323
|
vueOptions.transformSfc,
|
|
2225
2324
|
rawSource,
|
|
@@ -3275,6 +3374,44 @@ var init_environment = __esm({
|
|
|
3275
3374
|
}
|
|
3276
3375
|
});
|
|
3277
3376
|
|
|
3377
|
+
// src/plugins/react.ts
|
|
3378
|
+
function reactPlugin(config, environment) {
|
|
3379
|
+
return {
|
|
3380
|
+
name: "nasti:oxc-transform",
|
|
3381
|
+
async transform(code, id) {
|
|
3382
|
+
const result = await transformReactCode(id, code, {
|
|
3383
|
+
react: config.react,
|
|
3384
|
+
consumer: environment.consumer,
|
|
3385
|
+
development: config.mode === "development",
|
|
3386
|
+
sourcemap: !!environment.options.build.sourcemap,
|
|
3387
|
+
target: environment.options.build.target,
|
|
3388
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
3389
|
+
});
|
|
3390
|
+
if (!result) return null;
|
|
3391
|
+
return {
|
|
3392
|
+
code: result.code,
|
|
3393
|
+
map: result.map ? JSON.parse(result.map) : void 0
|
|
3394
|
+
};
|
|
3395
|
+
},
|
|
3396
|
+
handleHotUpdate(ctx) {
|
|
3397
|
+
for (const mod of ctx.modules) {
|
|
3398
|
+
if (REACT_FILE_RE.test(mod.url) && matchesReactFilter(mod.url, config.react.include, config.react.exclude)) {
|
|
3399
|
+
mod.isSelfAccepting = true;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
return ctx.modules;
|
|
3403
|
+
}
|
|
3404
|
+
};
|
|
3405
|
+
}
|
|
3406
|
+
var REACT_FILE_RE;
|
|
3407
|
+
var init_react = __esm({
|
|
3408
|
+
"src/plugins/react.ts"() {
|
|
3409
|
+
"use strict";
|
|
3410
|
+
init_transformer();
|
|
3411
|
+
REACT_FILE_RE = /\.[jt]sx(?:[?#].*)?$/;
|
|
3412
|
+
}
|
|
3413
|
+
});
|
|
3414
|
+
|
|
3278
3415
|
// src/core/env.ts
|
|
3279
3416
|
function loadEnv(mode, root, prefixes) {
|
|
3280
3417
|
const envFiles = [
|
|
@@ -3632,7 +3769,7 @@ function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
|
|
|
3632
3769
|
// 相对/绝对/虚拟模块照常打包。需要内联依赖时经 rolldownOptions.external 覆盖。
|
|
3633
3770
|
external: restInputOptions.external ?? ((id) => {
|
|
3634
3771
|
if (NODE_BUILTINS.has(id)) return true;
|
|
3635
|
-
return !id.startsWith(".") && !import_node_path10.default.isAbsolute(id) && !id.startsWith("\0");
|
|
3772
|
+
return !id.startsWith(".") && !import_node_path10.default.isAbsolute(id) && !id.startsWith("\0") && !id.startsWith("virtual:");
|
|
3636
3773
|
})
|
|
3637
3774
|
} : {}
|
|
3638
3775
|
};
|
|
@@ -3855,6 +3992,7 @@ function resolveClientEntries(config, html) {
|
|
|
3855
3992
|
return entryPoints;
|
|
3856
3993
|
}
|
|
3857
3994
|
function createOxcTransformPlugin(config, environment) {
|
|
3995
|
+
if (config.framework === "react") return reactPlugin(config, environment);
|
|
3858
3996
|
return {
|
|
3859
3997
|
name: "nasti:oxc-transform",
|
|
3860
3998
|
transform(code, id) {
|
|
@@ -3875,7 +4013,7 @@ async function build(inlineConfig = {}) {
|
|
|
3875
4013
|
const startTime = performance.now();
|
|
3876
4014
|
logger.info(
|
|
3877
4015
|
import_picocolors4.default.cyan(`
|
|
3878
|
-
nasti v${"2.
|
|
4016
|
+
nasti v${"2.5.1"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
|
|
3879
4017
|
);
|
|
3880
4018
|
debug5?.(`root: ${config.root}`);
|
|
3881
4019
|
const buildableNames = Object.keys(config.environments).filter((name) => {
|
|
@@ -4161,6 +4299,7 @@ var init_build = __esm({
|
|
|
4161
4299
|
init_environment();
|
|
4162
4300
|
init_css_engine();
|
|
4163
4301
|
init_html();
|
|
4302
|
+
init_react();
|
|
4164
4303
|
init_transformer();
|
|
4165
4304
|
init_env();
|
|
4166
4305
|
init_reporter();
|
|
@@ -4610,22 +4749,35 @@ async function transformRequest(url, ctx) {
|
|
|
4610
4749
|
}
|
|
4611
4750
|
const stableUrl = cleanReqUrl;
|
|
4612
4751
|
let wrappedWithRefresh = false;
|
|
4613
|
-
if (
|
|
4614
|
-
const
|
|
4615
|
-
const useRefresh =
|
|
4752
|
+
if (config.framework === "react") {
|
|
4753
|
+
const refreshEnabled = (ctx.environment?.consumer ?? "client") === "client" && config.server.hmr !== false;
|
|
4754
|
+
const useRefresh = refreshEnabled && (!!config.react.compiler || /\.[jt]sx$/.test(filePath));
|
|
4755
|
+
const result = await transformReactCode(filePath, code, {
|
|
4756
|
+
react: config.react,
|
|
4757
|
+
consumer: ctx.environment?.consumer ?? "client",
|
|
4758
|
+
development: true,
|
|
4759
|
+
reactRefresh: useRefresh,
|
|
4760
|
+
sourcemap: true,
|
|
4761
|
+
target: ctx.environment?.options.build.target ?? config.build.target,
|
|
4762
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
4763
|
+
});
|
|
4764
|
+
if (result) {
|
|
4765
|
+
code = result.code;
|
|
4766
|
+
if (result.map) map = JSON.parse(result.map);
|
|
4767
|
+
if (useRefresh) {
|
|
4768
|
+
code = buildReactRefreshWrapper(stableUrl, code);
|
|
4769
|
+
wrappedWithRefresh = true;
|
|
4770
|
+
}
|
|
4771
|
+
}
|
|
4772
|
+
} else if (shouldTransform(filePath)) {
|
|
4616
4773
|
const result = transformCode(filePath, code, {
|
|
4617
4774
|
sourcemap: true,
|
|
4618
4775
|
jsxRuntime: "automatic",
|
|
4619
|
-
jsxImportSource:
|
|
4620
|
-
reactRefresh: useRefresh,
|
|
4776
|
+
jsxImportSource: "vue",
|
|
4621
4777
|
target: ctx.environment?.options.build.target ?? config.build.target
|
|
4622
4778
|
});
|
|
4623
4779
|
code = result.code;
|
|
4624
4780
|
if (result.map) map = JSON.parse(result.map);
|
|
4625
|
-
if (useRefresh) {
|
|
4626
|
-
code = buildReactRefreshWrapper(stableUrl, code);
|
|
4627
|
-
wrappedWithRefresh = true;
|
|
4628
|
-
}
|
|
4629
4781
|
}
|
|
4630
4782
|
const hotInfo = rewriteHotAcceptDeps(code, config, filePath);
|
|
4631
4783
|
code = hotInfo.code;
|
|
@@ -4836,8 +4988,8 @@ function rewriteExternalRequires(code, baseDir, root) {
|
|
|
4836
4988
|
}
|
|
4837
4989
|
async function injectCjsNamedExports(code, entryFile) {
|
|
4838
4990
|
try {
|
|
4839
|
-
const { createRequire:
|
|
4840
|
-
const req =
|
|
4991
|
+
const { createRequire: createRequire7 } = await import("module");
|
|
4992
|
+
const req = createRequire7(entryFile);
|
|
4841
4993
|
const cjsExports = req(entryFile);
|
|
4842
4994
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
4843
4995
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
@@ -5695,222 +5847,1554 @@ var init_hmr = __esm({
|
|
|
5695
5847
|
}
|
|
5696
5848
|
});
|
|
5697
5849
|
|
|
5698
|
-
//
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5850
|
+
// node_modules/import-meta-resolve/lib/errors.js
|
|
5851
|
+
function formatList(array, type = "and") {
|
|
5852
|
+
return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array[array.length - 1]}`;
|
|
5853
|
+
}
|
|
5854
|
+
function createError(sym, value, constructor) {
|
|
5855
|
+
messages.set(sym, value);
|
|
5856
|
+
return makeNodeErrorWithCode(constructor, sym);
|
|
5857
|
+
}
|
|
5858
|
+
function makeNodeErrorWithCode(Base, key) {
|
|
5859
|
+
return NodeError;
|
|
5860
|
+
function NodeError(...parameters) {
|
|
5861
|
+
const limit = Error.stackTraceLimit;
|
|
5862
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
5863
|
+
const error = new Base();
|
|
5864
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
5865
|
+
const message = getMessage(key, parameters, error);
|
|
5866
|
+
Object.defineProperties(error, {
|
|
5867
|
+
// Note: no need to implement `kIsNodeError` symbol, would be hard,
|
|
5868
|
+
// probably.
|
|
5869
|
+
message: {
|
|
5870
|
+
value: message,
|
|
5871
|
+
enumerable: false,
|
|
5872
|
+
writable: true,
|
|
5873
|
+
configurable: true
|
|
5874
|
+
},
|
|
5875
|
+
toString: {
|
|
5876
|
+
/** @this {Error} */
|
|
5877
|
+
value() {
|
|
5878
|
+
return `${this.name} [${key}]: ${this.message}`;
|
|
5879
|
+
},
|
|
5880
|
+
enumerable: false,
|
|
5881
|
+
writable: true,
|
|
5882
|
+
configurable: true
|
|
5883
|
+
}
|
|
5884
|
+
});
|
|
5885
|
+
captureLargerStackTrace(error);
|
|
5886
|
+
error.code = key;
|
|
5887
|
+
return error;
|
|
5888
|
+
}
|
|
5889
|
+
}
|
|
5890
|
+
function isErrorStackTraceLimitWritable() {
|
|
5891
|
+
try {
|
|
5892
|
+
if (import_node_v8.default.startupSnapshot.isBuildingSnapshot()) {
|
|
5893
|
+
return false;
|
|
5894
|
+
}
|
|
5895
|
+
} catch {
|
|
5896
|
+
}
|
|
5897
|
+
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
5898
|
+
if (desc === void 0) {
|
|
5899
|
+
return Object.isExtensible(Error);
|
|
5900
|
+
}
|
|
5901
|
+
return own.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
|
|
5902
|
+
}
|
|
5903
|
+
function hideStackFrames(wrappedFunction) {
|
|
5904
|
+
const hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
5905
|
+
Object.defineProperty(wrappedFunction, "name", { value: hidden });
|
|
5906
|
+
return wrappedFunction;
|
|
5907
|
+
}
|
|
5908
|
+
function getMessage(key, parameters, self) {
|
|
5909
|
+
const message = messages.get(key);
|
|
5910
|
+
import_node_assert.default.ok(message !== void 0, "expected `message` to be found");
|
|
5911
|
+
if (typeof message === "function") {
|
|
5912
|
+
import_node_assert.default.ok(
|
|
5913
|
+
message.length <= parameters.length,
|
|
5914
|
+
// Default options do not count.
|
|
5915
|
+
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
|
|
5708
5916
|
);
|
|
5917
|
+
return Reflect.apply(message, self, parameters);
|
|
5918
|
+
}
|
|
5919
|
+
const regex = /%[dfijoOs]/g;
|
|
5920
|
+
let expectedLength = 0;
|
|
5921
|
+
while (regex.exec(message) !== null) expectedLength++;
|
|
5922
|
+
import_node_assert.default.ok(
|
|
5923
|
+
expectedLength === parameters.length,
|
|
5924
|
+
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
|
|
5925
|
+
);
|
|
5926
|
+
if (parameters.length === 0) return message;
|
|
5927
|
+
parameters.unshift(message);
|
|
5928
|
+
return Reflect.apply(import_node_util.format, null, parameters);
|
|
5929
|
+
}
|
|
5930
|
+
function determineSpecificType(value) {
|
|
5931
|
+
if (value === null || value === void 0) {
|
|
5932
|
+
return String(value);
|
|
5709
5933
|
}
|
|
5710
|
-
|
|
5934
|
+
if (typeof value === "function" && value.name) {
|
|
5935
|
+
return `function ${value.name}`;
|
|
5936
|
+
}
|
|
5937
|
+
if (typeof value === "object") {
|
|
5938
|
+
if (value.constructor && value.constructor.name) {
|
|
5939
|
+
return `an instance of ${value.constructor.name}`;
|
|
5940
|
+
}
|
|
5941
|
+
return `${(0, import_node_util.inspect)(value, { depth: -1 })}`;
|
|
5942
|
+
}
|
|
5943
|
+
let inspected = (0, import_node_util.inspect)(value, { colors: false });
|
|
5944
|
+
if (inspected.length > 28) {
|
|
5945
|
+
inspected = `${inspected.slice(0, 25)}...`;
|
|
5946
|
+
}
|
|
5947
|
+
return `type ${typeof value} (${inspected})`;
|
|
5711
5948
|
}
|
|
5712
|
-
var
|
|
5713
|
-
var
|
|
5714
|
-
"
|
|
5949
|
+
var import_node_v8, import_node_assert, import_node_util, own, classRegExp, kTypes, codes, messages, nodeInternalPrefix, userStackTraceLimit, captureLargerStackTrace;
|
|
5950
|
+
var init_errors = __esm({
|
|
5951
|
+
"node_modules/import-meta-resolve/lib/errors.js"() {
|
|
5715
5952
|
"use strict";
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
);
|
|
5739
|
-
this.require = (0, import_node_module7.createRequire)(import_node_path15.default.join(this.config.root, "package.json"));
|
|
5740
|
-
const handlers = {
|
|
5741
|
-
fetchModule: async (id, importer) => this.fetchModule(id, importer),
|
|
5742
|
-
getBuiltins: () => [/^node:/, ...import_node_module7.builtinModules]
|
|
5743
|
-
};
|
|
5744
|
-
environment.hot.setInvokeHandler?.(handlers);
|
|
5745
|
-
}
|
|
5746
|
-
/** 入口:加载并执行一个模块(url 为根相对或绝对路径) */
|
|
5747
|
-
async import(rawUrl) {
|
|
5748
|
-
const id = this.resolveToId(rawUrl);
|
|
5749
|
-
return this.instantiate(id);
|
|
5750
|
-
}
|
|
5751
|
-
/** 文件变更时按文件失效(含其所属的虚拟子模块) */
|
|
5752
|
-
invalidateFile(file) {
|
|
5753
|
-
for (const key of [...this.cache.keys()]) {
|
|
5754
|
-
if (key === file || key.startsWith(file + "?")) {
|
|
5755
|
-
this.cache.delete(key);
|
|
5756
|
-
}
|
|
5757
|
-
}
|
|
5758
|
-
}
|
|
5759
|
-
invalidateAll() {
|
|
5760
|
-
this.cache.clear();
|
|
5761
|
-
}
|
|
5762
|
-
resolveToId(rawUrl) {
|
|
5763
|
-
if (import_node_path15.default.isAbsolute(rawUrl) && import_node_fs12.default.existsSync(rawUrl.split("?")[0])) return rawUrl;
|
|
5764
|
-
const clean = rawUrl.replace(/^\//, "");
|
|
5765
|
-
return import_node_path15.default.resolve(this.config.root, clean);
|
|
5766
|
-
}
|
|
5953
|
+
import_node_v8 = __toESM(require("v8"), 1);
|
|
5954
|
+
import_node_assert = __toESM(require("assert"), 1);
|
|
5955
|
+
import_node_util = require("util");
|
|
5956
|
+
own = {}.hasOwnProperty;
|
|
5957
|
+
classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
5958
|
+
kTypes = /* @__PURE__ */ new Set([
|
|
5959
|
+
"string",
|
|
5960
|
+
"function",
|
|
5961
|
+
"number",
|
|
5962
|
+
"object",
|
|
5963
|
+
// Accept 'Function' and 'Object' as alternative to the lower cased version.
|
|
5964
|
+
"Function",
|
|
5965
|
+
"Object",
|
|
5966
|
+
"boolean",
|
|
5967
|
+
"bigint",
|
|
5968
|
+
"symbol"
|
|
5969
|
+
]);
|
|
5970
|
+
codes = {};
|
|
5971
|
+
messages = /* @__PURE__ */ new Map();
|
|
5972
|
+
nodeInternalPrefix = "__node_internal_";
|
|
5973
|
+
codes.ERR_INVALID_ARG_TYPE = createError(
|
|
5974
|
+
"ERR_INVALID_ARG_TYPE",
|
|
5767
5975
|
/**
|
|
5768
|
-
*
|
|
5769
|
-
*
|
|
5770
|
-
*
|
|
5976
|
+
* @param {string} name
|
|
5977
|
+
* @param {Array<string> | string} expected
|
|
5978
|
+
* @param {unknown} actual
|
|
5771
5979
|
*/
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
if (!
|
|
5775
|
-
|
|
5776
|
-
}
|
|
5777
|
-
const container = this.environment.pluginContainer;
|
|
5778
|
-
let resolvedId = id;
|
|
5779
|
-
if (id.startsWith(".") && importer) {
|
|
5780
|
-
const resolved = await container.resolveId(id, importer);
|
|
5781
|
-
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : import_node_path15.default.resolve(import_node_path15.default.dirname(importer.split("?")[0]), id);
|
|
5980
|
+
(name, expected, actual) => {
|
|
5981
|
+
import_node_assert.default.ok(typeof name === "string", "'name' must be a string");
|
|
5982
|
+
if (!Array.isArray(expected)) {
|
|
5983
|
+
expected = [expected];
|
|
5782
5984
|
}
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
const loaded = await container.load(resolvedId);
|
|
5787
|
-
if (loaded != null) {
|
|
5788
|
-
code = typeof loaded === "string" ? loaded : loaded.code;
|
|
5789
|
-
} else if (import_node_fs12.default.existsSync(cleanId)) {
|
|
5790
|
-
code = import_node_fs12.default.readFileSync(cleanId, "utf-8");
|
|
5985
|
+
let message = "The ";
|
|
5986
|
+
if (name.endsWith(" argument")) {
|
|
5987
|
+
message += `${name} `;
|
|
5791
5988
|
} else {
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
const transformed = await container.transform(code, resolvedId);
|
|
5795
|
-
if (transformed != null) {
|
|
5796
|
-
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
5797
|
-
}
|
|
5798
|
-
if (shouldTransform(cleanId)) {
|
|
5799
|
-
const result = transformCode(cleanId, code, {
|
|
5800
|
-
sourcemap: false,
|
|
5801
|
-
target: this.environment.options.build.target,
|
|
5802
|
-
jsxRuntime: "automatic",
|
|
5803
|
-
jsxImportSource: this.config.framework === "vue" ? "vue" : "react"
|
|
5804
|
-
});
|
|
5805
|
-
code = result.code;
|
|
5989
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
5990
|
+
message += `"${name}" ${type} `;
|
|
5806
5991
|
}
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5992
|
+
message += "must be ";
|
|
5993
|
+
const types = [];
|
|
5994
|
+
const instances = [];
|
|
5995
|
+
const other = [];
|
|
5996
|
+
for (const value of expected) {
|
|
5997
|
+
import_node_assert.default.ok(
|
|
5998
|
+
typeof value === "string",
|
|
5999
|
+
"All expected entries have to be of type string"
|
|
5815
6000
|
);
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
if (jsMatch) {
|
|
5827
|
-
for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
|
|
5828
|
-
if (import_node_fs12.default.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
|
|
6001
|
+
if (kTypes.has(value)) {
|
|
6002
|
+
types.push(value.toLowerCase());
|
|
6003
|
+
} else if (classRegExp.exec(value) === null) {
|
|
6004
|
+
import_node_assert.default.ok(
|
|
6005
|
+
value !== "object",
|
|
6006
|
+
'The value "object" should be written as "Object"'
|
|
6007
|
+
);
|
|
6008
|
+
other.push(value);
|
|
6009
|
+
} else {
|
|
6010
|
+
instances.push(value);
|
|
5829
6011
|
}
|
|
5830
6012
|
}
|
|
5831
|
-
|
|
5832
|
-
|
|
6013
|
+
if (instances.length > 0) {
|
|
6014
|
+
const pos = types.indexOf("object");
|
|
6015
|
+
if (pos !== -1) {
|
|
6016
|
+
types.slice(pos, 1);
|
|
6017
|
+
instances.push("Object");
|
|
6018
|
+
}
|
|
5833
6019
|
}
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
6020
|
+
if (types.length > 0) {
|
|
6021
|
+
message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(
|
|
6022
|
+
types,
|
|
6023
|
+
"or"
|
|
6024
|
+
)}`;
|
|
6025
|
+
if (instances.length > 0 || other.length > 0) message += " or ";
|
|
5837
6026
|
}
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
const cached2 = this.cache.get(id);
|
|
5842
|
-
if (cached2) return cached2.promise ?? Promise.resolve(cached2.exports);
|
|
5843
|
-
const entry = { exports: {}, promise: null };
|
|
5844
|
-
this.cache.set(id, entry);
|
|
5845
|
-
entry.promise = this.evaluate(id, entry).then(() => {
|
|
5846
|
-
entry.promise = null;
|
|
5847
|
-
return entry.exports;
|
|
5848
|
-
}).catch((err) => {
|
|
5849
|
-
this.cache.delete(id);
|
|
5850
|
-
throw err;
|
|
5851
|
-
});
|
|
5852
|
-
return entry.promise;
|
|
5853
|
-
}
|
|
5854
|
-
async evaluate(id, entry) {
|
|
5855
|
-
const fetched = await this.fetchModule(id);
|
|
5856
|
-
if ("externalize" in fetched) {
|
|
5857
|
-
const spec = fetched.externalize;
|
|
5858
|
-
const mod = await this.importExternal(spec);
|
|
5859
|
-
entry.exports = mod;
|
|
5860
|
-
return;
|
|
6027
|
+
if (instances.length > 0) {
|
|
6028
|
+
message += `an instance of ${formatList(instances, "or")}`;
|
|
6029
|
+
if (other.length > 0) message += " or ";
|
|
5861
6030
|
}
|
|
5862
|
-
|
|
5863
|
-
if (
|
|
5864
|
-
|
|
5865
|
-
}
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
};
|
|
5869
|
-
const ssrExportAll = (sourceModule) => {
|
|
5870
|
-
for (const key of Object.keys(sourceModule)) {
|
|
5871
|
-
if (key !== "default" && !(key in entry.exports)) {
|
|
5872
|
-
Object.defineProperty(entry.exports, key, {
|
|
5873
|
-
enumerable: true,
|
|
5874
|
-
configurable: true,
|
|
5875
|
-
get: () => sourceModule[key]
|
|
5876
|
-
});
|
|
5877
|
-
}
|
|
6031
|
+
if (other.length > 0) {
|
|
6032
|
+
if (other.length > 1) {
|
|
6033
|
+
message += `one of ${formatList(other, "or")}`;
|
|
6034
|
+
} else {
|
|
6035
|
+
if (other[0].toLowerCase() !== other[0]) message += "an ";
|
|
6036
|
+
message += `${other[0]}`;
|
|
5878
6037
|
}
|
|
5879
|
-
};
|
|
5880
|
-
const importMeta = {
|
|
5881
|
-
url: (0, import_node_url4.pathToFileURL)(fetched.id.split("?")[0]).href,
|
|
5882
|
-
env: { SSR: true, MODE: this.config.mode, DEV: this.config.mode !== "production", PROD: this.config.mode === "production" },
|
|
5883
|
-
hot: void 0
|
|
5884
|
-
};
|
|
5885
|
-
const fn = new AsyncFunction(
|
|
5886
|
-
"__vite_ssr_exports__",
|
|
5887
|
-
"__vite_ssr_import__",
|
|
5888
|
-
"__vite_ssr_dynamic_import__",
|
|
5889
|
-
"__vite_ssr_exportAll__",
|
|
5890
|
-
"__vite_ssr_import_meta__",
|
|
5891
|
-
`"use strict";${fetched.code}
|
|
5892
|
-
//# sourceURL=${fetched.id}`
|
|
5893
|
-
);
|
|
5894
|
-
await fn(entry.exports, ssrImport, ssrImport, ssrExportAll, importMeta);
|
|
5895
|
-
}
|
|
5896
|
-
async importExternal(spec) {
|
|
5897
|
-
try {
|
|
5898
|
-
return await (spec.startsWith("node:") || !import_node_path15.default.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import((0, import_node_url4.pathToFileURL)(spec).href));
|
|
5899
|
-
} catch (err) {
|
|
5900
|
-
throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
|
|
5901
|
-
}
|
|
5902
|
-
}
|
|
5903
|
-
/** bare specifier → 项目 node_modules 的绝对 URL(避免相对 Nasti 自身解析) */
|
|
5904
|
-
resolveExternalSpecifier(spec) {
|
|
5905
|
-
if (spec.startsWith("node:")) return spec;
|
|
5906
|
-
if (NODE_BUILTINS3.has(spec)) return `node:${spec}`;
|
|
5907
|
-
try {
|
|
5908
|
-
return (0, import_node_url4.pathToFileURL)(this.require.resolve(spec)).href;
|
|
5909
|
-
} catch {
|
|
5910
|
-
return spec;
|
|
5911
6038
|
}
|
|
5912
|
-
|
|
5913
|
-
|
|
6039
|
+
message += `. Received ${determineSpecificType(actual)}`;
|
|
6040
|
+
return message;
|
|
6041
|
+
},
|
|
6042
|
+
TypeError
|
|
6043
|
+
);
|
|
6044
|
+
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
6045
|
+
"ERR_INVALID_MODULE_SPECIFIER",
|
|
6046
|
+
/**
|
|
6047
|
+
* @param {string} request
|
|
6048
|
+
* @param {string} reason
|
|
6049
|
+
* @param {string} [base]
|
|
6050
|
+
*/
|
|
6051
|
+
(request, reason, base = void 0) => {
|
|
6052
|
+
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
|
|
6053
|
+
},
|
|
6054
|
+
TypeError
|
|
6055
|
+
);
|
|
6056
|
+
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
6057
|
+
"ERR_INVALID_PACKAGE_CONFIG",
|
|
6058
|
+
/**
|
|
6059
|
+
* @param {string} path
|
|
6060
|
+
* @param {string} [base]
|
|
6061
|
+
* @param {string} [message]
|
|
6062
|
+
*/
|
|
6063
|
+
(path23, base, message) => {
|
|
6064
|
+
return `Invalid package config ${path23}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
6065
|
+
},
|
|
6066
|
+
Error
|
|
6067
|
+
);
|
|
6068
|
+
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
6069
|
+
"ERR_INVALID_PACKAGE_TARGET",
|
|
6070
|
+
/**
|
|
6071
|
+
* @param {string} packagePath
|
|
6072
|
+
* @param {string} key
|
|
6073
|
+
* @param {unknown} target
|
|
6074
|
+
* @param {boolean} [isImport=false]
|
|
6075
|
+
* @param {string} [base]
|
|
6076
|
+
*/
|
|
6077
|
+
(packagePath, key, target, isImport = false, base = void 0) => {
|
|
6078
|
+
const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
6079
|
+
if (key === ".") {
|
|
6080
|
+
import_node_assert.default.ok(isImport === false);
|
|
6081
|
+
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 "./"' : ""}`;
|
|
6082
|
+
}
|
|
6083
|
+
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
|
|
6084
|
+
target
|
|
6085
|
+
)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
6086
|
+
},
|
|
6087
|
+
Error
|
|
6088
|
+
);
|
|
6089
|
+
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
6090
|
+
"ERR_MODULE_NOT_FOUND",
|
|
6091
|
+
/**
|
|
6092
|
+
* @param {string} path
|
|
6093
|
+
* @param {string} base
|
|
6094
|
+
* @param {boolean} [exactUrl]
|
|
6095
|
+
*/
|
|
6096
|
+
(path23, base, exactUrl = false) => {
|
|
6097
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path23}' imported from ${base}`;
|
|
6098
|
+
},
|
|
6099
|
+
Error
|
|
6100
|
+
);
|
|
6101
|
+
codes.ERR_NETWORK_IMPORT_DISALLOWED = createError(
|
|
6102
|
+
"ERR_NETWORK_IMPORT_DISALLOWED",
|
|
6103
|
+
"import of '%s' by %s is not supported: %s",
|
|
6104
|
+
Error
|
|
6105
|
+
);
|
|
6106
|
+
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
6107
|
+
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
|
|
6108
|
+
/**
|
|
6109
|
+
* @param {string} specifier
|
|
6110
|
+
* @param {string} packagePath
|
|
6111
|
+
* @param {string} base
|
|
6112
|
+
*/
|
|
6113
|
+
(specifier, packagePath, base) => {
|
|
6114
|
+
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
|
|
6115
|
+
},
|
|
6116
|
+
TypeError
|
|
6117
|
+
);
|
|
6118
|
+
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
6119
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
6120
|
+
/**
|
|
6121
|
+
* @param {string} packagePath
|
|
6122
|
+
* @param {string} subpath
|
|
6123
|
+
* @param {string} [base]
|
|
6124
|
+
*/
|
|
6125
|
+
(packagePath, subpath, base = void 0) => {
|
|
6126
|
+
if (subpath === ".")
|
|
6127
|
+
return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
6128
|
+
return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
6129
|
+
},
|
|
6130
|
+
Error
|
|
6131
|
+
);
|
|
6132
|
+
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
|
|
6133
|
+
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
6134
|
+
"Directory import '%s' is not supported resolving ES modules imported from %s",
|
|
6135
|
+
Error
|
|
6136
|
+
);
|
|
6137
|
+
codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(
|
|
6138
|
+
"ERR_UNSUPPORTED_RESOLVE_REQUEST",
|
|
6139
|
+
'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.',
|
|
6140
|
+
TypeError
|
|
6141
|
+
);
|
|
6142
|
+
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
6143
|
+
"ERR_UNKNOWN_FILE_EXTENSION",
|
|
6144
|
+
/**
|
|
6145
|
+
* @param {string} extension
|
|
6146
|
+
* @param {string} path
|
|
6147
|
+
*/
|
|
6148
|
+
(extension, path23) => {
|
|
6149
|
+
return `Unknown file extension "${extension}" for ${path23}`;
|
|
6150
|
+
},
|
|
6151
|
+
TypeError
|
|
6152
|
+
);
|
|
6153
|
+
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
6154
|
+
"ERR_INVALID_ARG_VALUE",
|
|
6155
|
+
/**
|
|
6156
|
+
* @param {string} name
|
|
6157
|
+
* @param {unknown} value
|
|
6158
|
+
* @param {string} [reason='is invalid']
|
|
6159
|
+
*/
|
|
6160
|
+
(name, value, reason = "is invalid") => {
|
|
6161
|
+
let inspected = (0, import_node_util.inspect)(value);
|
|
6162
|
+
if (inspected.length > 128) {
|
|
6163
|
+
inspected = `${inspected.slice(0, 128)}...`;
|
|
6164
|
+
}
|
|
6165
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
6166
|
+
return `The ${type} '${name}' ${reason}. Received ${inspected}`;
|
|
6167
|
+
},
|
|
6168
|
+
TypeError
|
|
6169
|
+
// Note: extra classes have been shaken out.
|
|
6170
|
+
// , RangeError
|
|
6171
|
+
);
|
|
6172
|
+
captureLargerStackTrace = hideStackFrames(
|
|
6173
|
+
/**
|
|
6174
|
+
* @param {Error} error
|
|
6175
|
+
* @returns {Error}
|
|
6176
|
+
*/
|
|
6177
|
+
// @ts-expect-error: fine
|
|
6178
|
+
function(error) {
|
|
6179
|
+
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
6180
|
+
if (stackTraceLimitIsWritable) {
|
|
6181
|
+
userStackTraceLimit = Error.stackTraceLimit;
|
|
6182
|
+
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
6183
|
+
}
|
|
6184
|
+
Error.captureStackTrace(error);
|
|
6185
|
+
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
6186
|
+
return error;
|
|
6187
|
+
}
|
|
6188
|
+
);
|
|
6189
|
+
}
|
|
6190
|
+
});
|
|
6191
|
+
|
|
6192
|
+
// node_modules/import-meta-resolve/lib/package-json-reader.js
|
|
6193
|
+
function read(jsonPath, { base, specifier }) {
|
|
6194
|
+
const existing = cache.get(jsonPath);
|
|
6195
|
+
if (existing) {
|
|
6196
|
+
return existing;
|
|
6197
|
+
}
|
|
6198
|
+
let string;
|
|
6199
|
+
try {
|
|
6200
|
+
string = import_node_fs12.default.readFileSync(import_node_path15.default.toNamespacedPath(jsonPath), "utf8");
|
|
6201
|
+
} catch (error) {
|
|
6202
|
+
const exception = (
|
|
6203
|
+
/** @type {ErrnoException} */
|
|
6204
|
+
error
|
|
6205
|
+
);
|
|
6206
|
+
if (exception.code !== "ENOENT") {
|
|
6207
|
+
throw exception;
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
const result = {
|
|
6211
|
+
exists: false,
|
|
6212
|
+
pjsonPath: jsonPath,
|
|
6213
|
+
main: void 0,
|
|
6214
|
+
name: void 0,
|
|
6215
|
+
type: "none",
|
|
6216
|
+
// Ignore unknown types for forwards compatibility
|
|
6217
|
+
exports: void 0,
|
|
6218
|
+
imports: void 0
|
|
6219
|
+
};
|
|
6220
|
+
if (string !== void 0) {
|
|
6221
|
+
let parsed;
|
|
6222
|
+
try {
|
|
6223
|
+
parsed = JSON.parse(string);
|
|
6224
|
+
} catch (error_) {
|
|
6225
|
+
const cause = (
|
|
6226
|
+
/** @type {ErrnoException} */
|
|
6227
|
+
error_
|
|
6228
|
+
);
|
|
6229
|
+
const error = new ERR_INVALID_PACKAGE_CONFIG(
|
|
6230
|
+
jsonPath,
|
|
6231
|
+
(base ? `"${specifier}" from ` : "") + (0, import_node_url4.fileURLToPath)(base || specifier),
|
|
6232
|
+
cause.message
|
|
6233
|
+
);
|
|
6234
|
+
error.cause = cause;
|
|
6235
|
+
throw error;
|
|
6236
|
+
}
|
|
6237
|
+
result.exists = true;
|
|
6238
|
+
if (hasOwnProperty.call(parsed, "name") && typeof parsed.name === "string") {
|
|
6239
|
+
result.name = parsed.name;
|
|
6240
|
+
}
|
|
6241
|
+
if (hasOwnProperty.call(parsed, "main") && typeof parsed.main === "string") {
|
|
6242
|
+
result.main = parsed.main;
|
|
6243
|
+
}
|
|
6244
|
+
if (hasOwnProperty.call(parsed, "exports")) {
|
|
6245
|
+
result.exports = parsed.exports;
|
|
6246
|
+
}
|
|
6247
|
+
if (hasOwnProperty.call(parsed, "imports")) {
|
|
6248
|
+
result.imports = parsed.imports;
|
|
6249
|
+
}
|
|
6250
|
+
if (hasOwnProperty.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) {
|
|
6251
|
+
result.type = parsed.type;
|
|
6252
|
+
}
|
|
6253
|
+
}
|
|
6254
|
+
cache.set(jsonPath, result);
|
|
6255
|
+
return result;
|
|
6256
|
+
}
|
|
6257
|
+
function getPackageScopeConfig(resolved) {
|
|
6258
|
+
let packageJSONUrl = new URL("package.json", resolved);
|
|
6259
|
+
while (true) {
|
|
6260
|
+
const packageJSONPath2 = packageJSONUrl.pathname;
|
|
6261
|
+
if (packageJSONPath2.endsWith("node_modules/package.json")) {
|
|
6262
|
+
break;
|
|
6263
|
+
}
|
|
6264
|
+
const packageConfig = read((0, import_node_url4.fileURLToPath)(packageJSONUrl), {
|
|
6265
|
+
specifier: resolved
|
|
6266
|
+
});
|
|
6267
|
+
if (packageConfig.exists) {
|
|
6268
|
+
return packageConfig;
|
|
6269
|
+
}
|
|
6270
|
+
const lastPackageJSONUrl = packageJSONUrl;
|
|
6271
|
+
packageJSONUrl = new URL("../package.json", packageJSONUrl);
|
|
6272
|
+
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
|
|
6273
|
+
break;
|
|
6274
|
+
}
|
|
6275
|
+
}
|
|
6276
|
+
const packageJSONPath = (0, import_node_url4.fileURLToPath)(packageJSONUrl);
|
|
6277
|
+
return {
|
|
6278
|
+
pjsonPath: packageJSONPath,
|
|
6279
|
+
exists: false,
|
|
6280
|
+
type: "none"
|
|
6281
|
+
};
|
|
6282
|
+
}
|
|
6283
|
+
function getPackageType(url) {
|
|
6284
|
+
return getPackageScopeConfig(url).type;
|
|
6285
|
+
}
|
|
6286
|
+
var import_node_fs12, import_node_path15, import_node_url4, hasOwnProperty, ERR_INVALID_PACKAGE_CONFIG, cache;
|
|
6287
|
+
var init_package_json_reader = __esm({
|
|
6288
|
+
"node_modules/import-meta-resolve/lib/package-json-reader.js"() {
|
|
6289
|
+
"use strict";
|
|
6290
|
+
import_node_fs12 = __toESM(require("fs"), 1);
|
|
6291
|
+
import_node_path15 = __toESM(require("path"), 1);
|
|
6292
|
+
import_node_url4 = require("url");
|
|
6293
|
+
init_errors();
|
|
6294
|
+
hasOwnProperty = {}.hasOwnProperty;
|
|
6295
|
+
({ ERR_INVALID_PACKAGE_CONFIG } = codes);
|
|
6296
|
+
cache = /* @__PURE__ */ new Map();
|
|
6297
|
+
}
|
|
6298
|
+
});
|
|
6299
|
+
|
|
6300
|
+
// node_modules/import-meta-resolve/lib/get-format.js
|
|
6301
|
+
function mimeToFormat(mime) {
|
|
6302
|
+
if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime))
|
|
6303
|
+
return "module";
|
|
6304
|
+
if (mime === "application/json") return "json";
|
|
6305
|
+
return null;
|
|
6306
|
+
}
|
|
6307
|
+
function getDataProtocolModuleFormat(parsed) {
|
|
6308
|
+
const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
|
|
6309
|
+
parsed.pathname
|
|
6310
|
+
) || [null, null, null];
|
|
6311
|
+
return mimeToFormat(mime);
|
|
6312
|
+
}
|
|
6313
|
+
function extname(url) {
|
|
6314
|
+
const pathname = url.pathname;
|
|
6315
|
+
let index2 = pathname.length;
|
|
6316
|
+
while (index2--) {
|
|
6317
|
+
const code = pathname.codePointAt(index2);
|
|
6318
|
+
if (code === 47) {
|
|
6319
|
+
return "";
|
|
6320
|
+
}
|
|
6321
|
+
if (code === 46) {
|
|
6322
|
+
return pathname.codePointAt(index2 - 1) === 47 ? "" : pathname.slice(index2);
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6325
|
+
return "";
|
|
6326
|
+
}
|
|
6327
|
+
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
6328
|
+
const value = extname(url);
|
|
6329
|
+
if (value === ".js") {
|
|
6330
|
+
const packageType = getPackageType(url);
|
|
6331
|
+
if (packageType !== "none") {
|
|
6332
|
+
return packageType;
|
|
6333
|
+
}
|
|
6334
|
+
return "commonjs";
|
|
6335
|
+
}
|
|
6336
|
+
if (value === "") {
|
|
6337
|
+
const packageType = getPackageType(url);
|
|
6338
|
+
if (packageType === "none" || packageType === "commonjs") {
|
|
6339
|
+
return "commonjs";
|
|
6340
|
+
}
|
|
6341
|
+
return "module";
|
|
6342
|
+
}
|
|
6343
|
+
const format2 = extensionFormatMap[value];
|
|
6344
|
+
if (format2) return format2;
|
|
6345
|
+
if (ignoreErrors) {
|
|
6346
|
+
return void 0;
|
|
6347
|
+
}
|
|
6348
|
+
const filepath = (0, import_node_url5.fileURLToPath)(url);
|
|
6349
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath);
|
|
6350
|
+
}
|
|
6351
|
+
function getHttpProtocolModuleFormat() {
|
|
6352
|
+
}
|
|
6353
|
+
function defaultGetFormatWithoutErrors(url, context) {
|
|
6354
|
+
const protocol = url.protocol;
|
|
6355
|
+
if (!hasOwnProperty2.call(protocolHandlers, protocol)) {
|
|
6356
|
+
return null;
|
|
6357
|
+
}
|
|
6358
|
+
return protocolHandlers[protocol](url, context, true) || null;
|
|
6359
|
+
}
|
|
6360
|
+
var import_node_url5, ERR_UNKNOWN_FILE_EXTENSION, hasOwnProperty2, extensionFormatMap, protocolHandlers;
|
|
6361
|
+
var init_get_format = __esm({
|
|
6362
|
+
"node_modules/import-meta-resolve/lib/get-format.js"() {
|
|
6363
|
+
"use strict";
|
|
6364
|
+
import_node_url5 = require("url");
|
|
6365
|
+
init_package_json_reader();
|
|
6366
|
+
init_errors();
|
|
6367
|
+
({ ERR_UNKNOWN_FILE_EXTENSION } = codes);
|
|
6368
|
+
hasOwnProperty2 = {}.hasOwnProperty;
|
|
6369
|
+
extensionFormatMap = {
|
|
6370
|
+
// @ts-expect-error: hush.
|
|
6371
|
+
__proto__: null,
|
|
6372
|
+
".cjs": "commonjs",
|
|
6373
|
+
".js": "module",
|
|
6374
|
+
".json": "json",
|
|
6375
|
+
".mjs": "module"
|
|
6376
|
+
};
|
|
6377
|
+
protocolHandlers = {
|
|
6378
|
+
// @ts-expect-error: hush.
|
|
6379
|
+
__proto__: null,
|
|
6380
|
+
"data:": getDataProtocolModuleFormat,
|
|
6381
|
+
"file:": getFileProtocolModuleFormat,
|
|
6382
|
+
"http:": getHttpProtocolModuleFormat,
|
|
6383
|
+
"https:": getHttpProtocolModuleFormat,
|
|
6384
|
+
"node:"() {
|
|
6385
|
+
return "builtin";
|
|
6386
|
+
}
|
|
6387
|
+
};
|
|
6388
|
+
}
|
|
6389
|
+
});
|
|
6390
|
+
|
|
6391
|
+
// node_modules/import-meta-resolve/lib/utils.js
|
|
6392
|
+
function getDefaultConditions() {
|
|
6393
|
+
return DEFAULT_CONDITIONS;
|
|
6394
|
+
}
|
|
6395
|
+
function getDefaultConditionsSet() {
|
|
6396
|
+
return DEFAULT_CONDITIONS_SET;
|
|
6397
|
+
}
|
|
6398
|
+
function getConditionsSet(conditions) {
|
|
6399
|
+
if (conditions !== void 0 && conditions !== getDefaultConditions()) {
|
|
6400
|
+
if (!Array.isArray(conditions)) {
|
|
6401
|
+
throw new ERR_INVALID_ARG_VALUE(
|
|
6402
|
+
"conditions",
|
|
6403
|
+
conditions,
|
|
6404
|
+
"expected an array"
|
|
6405
|
+
);
|
|
6406
|
+
}
|
|
6407
|
+
return new Set(conditions);
|
|
6408
|
+
}
|
|
6409
|
+
return getDefaultConditionsSet();
|
|
6410
|
+
}
|
|
6411
|
+
var ERR_INVALID_ARG_VALUE, DEFAULT_CONDITIONS, DEFAULT_CONDITIONS_SET;
|
|
6412
|
+
var init_utils = __esm({
|
|
6413
|
+
"node_modules/import-meta-resolve/lib/utils.js"() {
|
|
6414
|
+
"use strict";
|
|
6415
|
+
init_errors();
|
|
6416
|
+
({ ERR_INVALID_ARG_VALUE } = codes);
|
|
6417
|
+
DEFAULT_CONDITIONS = Object.freeze(["node", "import"]);
|
|
6418
|
+
DEFAULT_CONDITIONS_SET = new Set(DEFAULT_CONDITIONS);
|
|
6419
|
+
}
|
|
6420
|
+
});
|
|
6421
|
+
|
|
6422
|
+
// node_modules/import-meta-resolve/lib/resolve.js
|
|
6423
|
+
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
6424
|
+
if (import_node_process.default.noDeprecation) {
|
|
6425
|
+
return;
|
|
6426
|
+
}
|
|
6427
|
+
const pjsonPath = (0, import_node_url6.fileURLToPath)(packageJsonUrl);
|
|
6428
|
+
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
6429
|
+
import_node_process.default.emitWarning(
|
|
6430
|
+
`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 ${(0, import_node_url6.fileURLToPath)(base)}` : ""}.`,
|
|
6431
|
+
"DeprecationWarning",
|
|
6432
|
+
"DEP0166"
|
|
6433
|
+
);
|
|
6434
|
+
}
|
|
6435
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
6436
|
+
if (import_node_process.default.noDeprecation) {
|
|
6437
|
+
return;
|
|
6438
|
+
}
|
|
6439
|
+
const format2 = defaultGetFormatWithoutErrors(url, { parentURL: base.href });
|
|
6440
|
+
if (format2 !== "module") return;
|
|
6441
|
+
const urlPath = (0, import_node_url6.fileURLToPath)(url.href);
|
|
6442
|
+
const packagePath = (0, import_node_url6.fileURLToPath)(new URL(".", packageJsonUrl));
|
|
6443
|
+
const basePath = (0, import_node_url6.fileURLToPath)(base);
|
|
6444
|
+
if (!main) {
|
|
6445
|
+
import_node_process.default.emitWarning(
|
|
6446
|
+
`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(
|
|
6447
|
+
packagePath.length
|
|
6448
|
+
)}", imported from ${basePath}.
|
|
6449
|
+
Default "index" lookups for the main are deprecated for ES modules.`,
|
|
6450
|
+
"DeprecationWarning",
|
|
6451
|
+
"DEP0151"
|
|
6452
|
+
);
|
|
6453
|
+
} else if (import_node_path16.default.resolve(packagePath, main) !== urlPath) {
|
|
6454
|
+
import_node_process.default.emitWarning(
|
|
6455
|
+
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
6456
|
+
packagePath.length
|
|
6457
|
+
)}", imported from ${basePath}.
|
|
6458
|
+
Automatic extension resolution of the "main" field is deprecated for ES modules.`,
|
|
6459
|
+
"DeprecationWarning",
|
|
6460
|
+
"DEP0151"
|
|
6461
|
+
);
|
|
6462
|
+
}
|
|
6463
|
+
}
|
|
6464
|
+
function tryStatSync(path23) {
|
|
6465
|
+
try {
|
|
6466
|
+
return (0, import_node_fs13.statSync)(path23);
|
|
6467
|
+
} catch {
|
|
6468
|
+
}
|
|
6469
|
+
}
|
|
6470
|
+
function fileExists(url) {
|
|
6471
|
+
const stats = (0, import_node_fs13.statSync)(url, { throwIfNoEntry: false });
|
|
6472
|
+
const isFile = stats ? stats.isFile() : void 0;
|
|
6473
|
+
return isFile === null || isFile === void 0 ? false : isFile;
|
|
6474
|
+
}
|
|
6475
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
6476
|
+
let guess;
|
|
6477
|
+
if (packageConfig.main !== void 0) {
|
|
6478
|
+
guess = new URL(packageConfig.main, packageJsonUrl);
|
|
6479
|
+
if (fileExists(guess)) return guess;
|
|
6480
|
+
const tries2 = [
|
|
6481
|
+
`./${packageConfig.main}.js`,
|
|
6482
|
+
`./${packageConfig.main}.json`,
|
|
6483
|
+
`./${packageConfig.main}.node`,
|
|
6484
|
+
`./${packageConfig.main}/index.js`,
|
|
6485
|
+
`./${packageConfig.main}/index.json`,
|
|
6486
|
+
`./${packageConfig.main}/index.node`
|
|
6487
|
+
];
|
|
6488
|
+
let i2 = -1;
|
|
6489
|
+
while (++i2 < tries2.length) {
|
|
6490
|
+
guess = new URL(tries2[i2], packageJsonUrl);
|
|
6491
|
+
if (fileExists(guess)) break;
|
|
6492
|
+
guess = void 0;
|
|
6493
|
+
}
|
|
6494
|
+
if (guess) {
|
|
6495
|
+
emitLegacyIndexDeprecation(
|
|
6496
|
+
guess,
|
|
6497
|
+
packageJsonUrl,
|
|
6498
|
+
base,
|
|
6499
|
+
packageConfig.main
|
|
6500
|
+
);
|
|
6501
|
+
return guess;
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
6504
|
+
const tries = ["./index.js", "./index.json", "./index.node"];
|
|
6505
|
+
let i = -1;
|
|
6506
|
+
while (++i < tries.length) {
|
|
6507
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
6508
|
+
if (fileExists(guess)) break;
|
|
6509
|
+
guess = void 0;
|
|
6510
|
+
}
|
|
6511
|
+
if (guess) {
|
|
6512
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
6513
|
+
return guess;
|
|
6514
|
+
}
|
|
6515
|
+
throw new ERR_MODULE_NOT_FOUND(
|
|
6516
|
+
(0, import_node_url6.fileURLToPath)(new URL(".", packageJsonUrl)),
|
|
6517
|
+
(0, import_node_url6.fileURLToPath)(base)
|
|
6518
|
+
);
|
|
6519
|
+
}
|
|
6520
|
+
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
6521
|
+
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
|
|
6522
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
6523
|
+
resolved.pathname,
|
|
6524
|
+
'must not include encoded "/" or "\\" characters',
|
|
6525
|
+
(0, import_node_url6.fileURLToPath)(base)
|
|
6526
|
+
);
|
|
6527
|
+
}
|
|
6528
|
+
let filePath;
|
|
6529
|
+
try {
|
|
6530
|
+
filePath = (0, import_node_url6.fileURLToPath)(resolved);
|
|
6531
|
+
} catch (error) {
|
|
6532
|
+
const cause = (
|
|
6533
|
+
/** @type {ErrnoException} */
|
|
6534
|
+
error
|
|
6535
|
+
);
|
|
6536
|
+
Object.defineProperty(cause, "input", { value: String(resolved) });
|
|
6537
|
+
Object.defineProperty(cause, "module", { value: String(base) });
|
|
6538
|
+
throw cause;
|
|
6539
|
+
}
|
|
6540
|
+
const stats = tryStatSync(
|
|
6541
|
+
filePath.endsWith("/") ? filePath.slice(-1) : filePath
|
|
6542
|
+
);
|
|
6543
|
+
if (stats && stats.isDirectory()) {
|
|
6544
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, (0, import_node_url6.fileURLToPath)(base));
|
|
6545
|
+
error.url = String(resolved);
|
|
6546
|
+
throw error;
|
|
6547
|
+
}
|
|
6548
|
+
if (!stats || !stats.isFile()) {
|
|
6549
|
+
const error = new ERR_MODULE_NOT_FOUND(
|
|
6550
|
+
filePath || resolved.pathname,
|
|
6551
|
+
base && (0, import_node_url6.fileURLToPath)(base),
|
|
6552
|
+
true
|
|
6553
|
+
);
|
|
6554
|
+
error.url = String(resolved);
|
|
6555
|
+
throw error;
|
|
6556
|
+
}
|
|
6557
|
+
if (!preserveSymlinks) {
|
|
6558
|
+
const real = (0, import_node_fs13.realpathSync)(filePath);
|
|
6559
|
+
const { search, hash } = resolved;
|
|
6560
|
+
resolved = (0, import_node_url6.pathToFileURL)(real + (filePath.endsWith(import_node_path16.default.sep) ? "/" : ""));
|
|
6561
|
+
resolved.search = search;
|
|
6562
|
+
resolved.hash = hash;
|
|
6563
|
+
}
|
|
6564
|
+
return resolved;
|
|
6565
|
+
}
|
|
6566
|
+
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
6567
|
+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
6568
|
+
specifier,
|
|
6569
|
+
packageJsonUrl && (0, import_node_url6.fileURLToPath)(new URL(".", packageJsonUrl)),
|
|
6570
|
+
(0, import_node_url6.fileURLToPath)(base)
|
|
6571
|
+
);
|
|
6572
|
+
}
|
|
6573
|
+
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
6574
|
+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
6575
|
+
(0, import_node_url6.fileURLToPath)(new URL(".", packageJsonUrl)),
|
|
6576
|
+
subpath,
|
|
6577
|
+
base && (0, import_node_url6.fileURLToPath)(base)
|
|
6578
|
+
);
|
|
6579
|
+
}
|
|
6580
|
+
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
6581
|
+
const reason = `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${(0, import_node_url6.fileURLToPath)(packageJsonUrl)}`;
|
|
6582
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
6583
|
+
request,
|
|
6584
|
+
reason,
|
|
6585
|
+
base && (0, import_node_url6.fileURLToPath)(base)
|
|
6586
|
+
);
|
|
6587
|
+
}
|
|
6588
|
+
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
6589
|
+
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
6590
|
+
return new ERR_INVALID_PACKAGE_TARGET(
|
|
6591
|
+
(0, import_node_url6.fileURLToPath)(new URL(".", packageJsonUrl)),
|
|
6592
|
+
subpath,
|
|
6593
|
+
target,
|
|
6594
|
+
internal,
|
|
6595
|
+
base && (0, import_node_url6.fileURLToPath)(base)
|
|
6596
|
+
);
|
|
6597
|
+
}
|
|
6598
|
+
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
6599
|
+
if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
|
|
6600
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6601
|
+
if (!target.startsWith("./")) {
|
|
6602
|
+
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
6603
|
+
let isURL = false;
|
|
6604
|
+
try {
|
|
6605
|
+
new URL(target);
|
|
6606
|
+
isURL = true;
|
|
6607
|
+
} catch {
|
|
6608
|
+
}
|
|
6609
|
+
if (!isURL) {
|
|
6610
|
+
const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
6611
|
+
patternRegEx,
|
|
6612
|
+
target,
|
|
6613
|
+
() => subpath
|
|
6614
|
+
) : target + subpath;
|
|
6615
|
+
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
6616
|
+
}
|
|
6617
|
+
}
|
|
6618
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6619
|
+
}
|
|
6620
|
+
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
|
|
6621
|
+
if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
6622
|
+
if (!isPathMap) {
|
|
6623
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
6624
|
+
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
6625
|
+
patternRegEx,
|
|
6626
|
+
target,
|
|
6627
|
+
() => subpath
|
|
6628
|
+
) : target;
|
|
6629
|
+
emitInvalidSegmentDeprecation(
|
|
6630
|
+
resolvedTarget,
|
|
6631
|
+
request,
|
|
6632
|
+
match,
|
|
6633
|
+
packageJsonUrl,
|
|
6634
|
+
internal,
|
|
6635
|
+
base,
|
|
6636
|
+
true
|
|
6637
|
+
);
|
|
6638
|
+
}
|
|
6639
|
+
} else {
|
|
6640
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6641
|
+
}
|
|
6642
|
+
}
|
|
6643
|
+
const resolved = new URL(target, packageJsonUrl);
|
|
6644
|
+
const resolvedPath = resolved.pathname;
|
|
6645
|
+
const packagePath = new URL(".", packageJsonUrl).pathname;
|
|
6646
|
+
if (!resolvedPath.startsWith(packagePath))
|
|
6647
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
6648
|
+
if (subpath === "") return resolved;
|
|
6649
|
+
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
6650
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
6651
|
+
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
6652
|
+
if (!isPathMap) {
|
|
6653
|
+
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
6654
|
+
patternRegEx,
|
|
6655
|
+
target,
|
|
6656
|
+
() => subpath
|
|
6657
|
+
) : target;
|
|
6658
|
+
emitInvalidSegmentDeprecation(
|
|
6659
|
+
resolvedTarget,
|
|
6660
|
+
request,
|
|
6661
|
+
match,
|
|
6662
|
+
packageJsonUrl,
|
|
6663
|
+
internal,
|
|
6664
|
+
base,
|
|
6665
|
+
false
|
|
6666
|
+
);
|
|
6667
|
+
}
|
|
6668
|
+
} else {
|
|
6669
|
+
throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
if (pattern) {
|
|
6673
|
+
return new URL(
|
|
6674
|
+
RegExpPrototypeSymbolReplace.call(
|
|
6675
|
+
patternRegEx,
|
|
6676
|
+
resolved.href,
|
|
6677
|
+
() => subpath
|
|
6678
|
+
)
|
|
6679
|
+
);
|
|
6680
|
+
}
|
|
6681
|
+
return new URL(subpath, resolved);
|
|
6682
|
+
}
|
|
6683
|
+
function isArrayIndex(key) {
|
|
6684
|
+
const keyNumber = Number(key);
|
|
6685
|
+
if (`${keyNumber}` !== key) return false;
|
|
6686
|
+
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
6687
|
+
}
|
|
6688
|
+
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
6689
|
+
if (typeof target === "string") {
|
|
6690
|
+
return resolvePackageTargetString(
|
|
6691
|
+
target,
|
|
6692
|
+
subpath,
|
|
6693
|
+
packageSubpath,
|
|
6694
|
+
packageJsonUrl,
|
|
6695
|
+
base,
|
|
6696
|
+
pattern,
|
|
6697
|
+
internal,
|
|
6698
|
+
isPathMap,
|
|
6699
|
+
conditions
|
|
6700
|
+
);
|
|
6701
|
+
}
|
|
6702
|
+
if (Array.isArray(target)) {
|
|
6703
|
+
const targetList = target;
|
|
6704
|
+
if (targetList.length === 0) return null;
|
|
6705
|
+
let lastException;
|
|
6706
|
+
let i = -1;
|
|
6707
|
+
while (++i < targetList.length) {
|
|
6708
|
+
const targetItem = targetList[i];
|
|
6709
|
+
let resolveResult;
|
|
6710
|
+
try {
|
|
6711
|
+
resolveResult = resolvePackageTarget(
|
|
6712
|
+
packageJsonUrl,
|
|
6713
|
+
targetItem,
|
|
6714
|
+
subpath,
|
|
6715
|
+
packageSubpath,
|
|
6716
|
+
base,
|
|
6717
|
+
pattern,
|
|
6718
|
+
internal,
|
|
6719
|
+
isPathMap,
|
|
6720
|
+
conditions
|
|
6721
|
+
);
|
|
6722
|
+
} catch (error) {
|
|
6723
|
+
const exception = (
|
|
6724
|
+
/** @type {ErrnoException} */
|
|
6725
|
+
error
|
|
6726
|
+
);
|
|
6727
|
+
lastException = exception;
|
|
6728
|
+
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
6729
|
+
throw error;
|
|
6730
|
+
}
|
|
6731
|
+
if (resolveResult === void 0) continue;
|
|
6732
|
+
if (resolveResult === null) {
|
|
6733
|
+
lastException = null;
|
|
6734
|
+
continue;
|
|
6735
|
+
}
|
|
6736
|
+
return resolveResult;
|
|
6737
|
+
}
|
|
6738
|
+
if (lastException === void 0 || lastException === null) {
|
|
6739
|
+
return null;
|
|
6740
|
+
}
|
|
6741
|
+
throw lastException;
|
|
6742
|
+
}
|
|
6743
|
+
if (typeof target === "object" && target !== null) {
|
|
6744
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
6745
|
+
let i = -1;
|
|
6746
|
+
while (++i < keys.length) {
|
|
6747
|
+
const key = keys[i];
|
|
6748
|
+
if (isArrayIndex(key)) {
|
|
6749
|
+
throw new ERR_INVALID_PACKAGE_CONFIG2(
|
|
6750
|
+
(0, import_node_url6.fileURLToPath)(packageJsonUrl),
|
|
6751
|
+
base,
|
|
6752
|
+
'"exports" cannot contain numeric property keys.'
|
|
6753
|
+
);
|
|
6754
|
+
}
|
|
6755
|
+
}
|
|
6756
|
+
i = -1;
|
|
6757
|
+
while (++i < keys.length) {
|
|
6758
|
+
const key = keys[i];
|
|
6759
|
+
if (key === "default" || conditions && conditions.has(key)) {
|
|
6760
|
+
const conditionalTarget = (
|
|
6761
|
+
/** @type {unknown} */
|
|
6762
|
+
target[key]
|
|
6763
|
+
);
|
|
6764
|
+
const resolveResult = resolvePackageTarget(
|
|
6765
|
+
packageJsonUrl,
|
|
6766
|
+
conditionalTarget,
|
|
6767
|
+
subpath,
|
|
6768
|
+
packageSubpath,
|
|
6769
|
+
base,
|
|
6770
|
+
pattern,
|
|
6771
|
+
internal,
|
|
6772
|
+
isPathMap,
|
|
6773
|
+
conditions
|
|
6774
|
+
);
|
|
6775
|
+
if (resolveResult === void 0) continue;
|
|
6776
|
+
return resolveResult;
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
return null;
|
|
6780
|
+
}
|
|
6781
|
+
if (target === null) {
|
|
6782
|
+
return null;
|
|
6783
|
+
}
|
|
6784
|
+
throw invalidPackageTarget(
|
|
6785
|
+
packageSubpath,
|
|
6786
|
+
target,
|
|
6787
|
+
packageJsonUrl,
|
|
6788
|
+
internal,
|
|
6789
|
+
base
|
|
6790
|
+
);
|
|
6791
|
+
}
|
|
6792
|
+
function isConditionalExportsMainSugar(exports2, packageJsonUrl, base) {
|
|
6793
|
+
if (typeof exports2 === "string" || Array.isArray(exports2)) return true;
|
|
6794
|
+
if (typeof exports2 !== "object" || exports2 === null) return false;
|
|
6795
|
+
const keys = Object.getOwnPropertyNames(exports2);
|
|
6796
|
+
let isConditionalSugar = false;
|
|
6797
|
+
let i = 0;
|
|
6798
|
+
let keyIndex = -1;
|
|
6799
|
+
while (++keyIndex < keys.length) {
|
|
6800
|
+
const key = keys[keyIndex];
|
|
6801
|
+
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
6802
|
+
if (i++ === 0) {
|
|
6803
|
+
isConditionalSugar = currentIsConditionalSugar;
|
|
6804
|
+
} else if (isConditionalSugar !== currentIsConditionalSugar) {
|
|
6805
|
+
throw new ERR_INVALID_PACKAGE_CONFIG2(
|
|
6806
|
+
(0, import_node_url6.fileURLToPath)(packageJsonUrl),
|
|
6807
|
+
base,
|
|
6808
|
+
`"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.`
|
|
6809
|
+
);
|
|
6810
|
+
}
|
|
6811
|
+
}
|
|
6812
|
+
return isConditionalSugar;
|
|
6813
|
+
}
|
|
6814
|
+
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
6815
|
+
if (import_node_process.default.noDeprecation) {
|
|
6816
|
+
return;
|
|
6817
|
+
}
|
|
6818
|
+
const pjsonPath = (0, import_node_url6.fileURLToPath)(pjsonUrl);
|
|
6819
|
+
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
6820
|
+
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
6821
|
+
import_node_process.default.emitWarning(
|
|
6822
|
+
`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${(0, import_node_url6.fileURLToPath)(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`,
|
|
6823
|
+
"DeprecationWarning",
|
|
6824
|
+
"DEP0155"
|
|
6825
|
+
);
|
|
6826
|
+
}
|
|
6827
|
+
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
6828
|
+
let exports2 = packageConfig.exports;
|
|
6829
|
+
if (isConditionalExportsMainSugar(exports2, packageJsonUrl, base)) {
|
|
6830
|
+
exports2 = { ".": exports2 };
|
|
6831
|
+
}
|
|
6832
|
+
if (own2.call(exports2, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
6833
|
+
const target = exports2[packageSubpath];
|
|
6834
|
+
const resolveResult = resolvePackageTarget(
|
|
6835
|
+
packageJsonUrl,
|
|
6836
|
+
target,
|
|
6837
|
+
"",
|
|
6838
|
+
packageSubpath,
|
|
6839
|
+
base,
|
|
6840
|
+
false,
|
|
6841
|
+
false,
|
|
6842
|
+
false,
|
|
6843
|
+
conditions
|
|
6844
|
+
);
|
|
6845
|
+
if (resolveResult === null || resolveResult === void 0) {
|
|
6846
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
6847
|
+
}
|
|
6848
|
+
return resolveResult;
|
|
6849
|
+
}
|
|
6850
|
+
let bestMatch = "";
|
|
6851
|
+
let bestMatchSubpath = "";
|
|
6852
|
+
const keys = Object.getOwnPropertyNames(exports2);
|
|
6853
|
+
let i = -1;
|
|
6854
|
+
while (++i < keys.length) {
|
|
6855
|
+
const key = keys[i];
|
|
6856
|
+
const patternIndex = key.indexOf("*");
|
|
6857
|
+
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
6858
|
+
if (packageSubpath.endsWith("/")) {
|
|
6859
|
+
emitTrailingSlashPatternDeprecation(
|
|
6860
|
+
packageSubpath,
|
|
6861
|
+
packageJsonUrl,
|
|
6862
|
+
base
|
|
6863
|
+
);
|
|
6864
|
+
}
|
|
6865
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
6866
|
+
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
6867
|
+
bestMatch = key;
|
|
6868
|
+
bestMatchSubpath = packageSubpath.slice(
|
|
6869
|
+
patternIndex,
|
|
6870
|
+
packageSubpath.length - patternTrailer.length
|
|
6871
|
+
);
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
}
|
|
6875
|
+
if (bestMatch) {
|
|
6876
|
+
const target = (
|
|
6877
|
+
/** @type {unknown} */
|
|
6878
|
+
exports2[bestMatch]
|
|
6879
|
+
);
|
|
6880
|
+
const resolveResult = resolvePackageTarget(
|
|
6881
|
+
packageJsonUrl,
|
|
6882
|
+
target,
|
|
6883
|
+
bestMatchSubpath,
|
|
6884
|
+
bestMatch,
|
|
6885
|
+
base,
|
|
6886
|
+
true,
|
|
6887
|
+
false,
|
|
6888
|
+
packageSubpath.endsWith("/"),
|
|
6889
|
+
conditions
|
|
6890
|
+
);
|
|
6891
|
+
if (resolveResult === null || resolveResult === void 0) {
|
|
6892
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
6893
|
+
}
|
|
6894
|
+
return resolveResult;
|
|
6895
|
+
}
|
|
6896
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
6897
|
+
}
|
|
6898
|
+
function patternKeyCompare(a, b) {
|
|
6899
|
+
const aPatternIndex = a.indexOf("*");
|
|
6900
|
+
const bPatternIndex = b.indexOf("*");
|
|
6901
|
+
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
6902
|
+
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
6903
|
+
if (baseLengthA > baseLengthB) return -1;
|
|
6904
|
+
if (baseLengthB > baseLengthA) return 1;
|
|
6905
|
+
if (aPatternIndex === -1) return 1;
|
|
6906
|
+
if (bPatternIndex === -1) return -1;
|
|
6907
|
+
if (a.length > b.length) return -1;
|
|
6908
|
+
if (b.length > a.length) return 1;
|
|
6909
|
+
return 0;
|
|
6910
|
+
}
|
|
6911
|
+
function packageImportsResolve(name, base, conditions) {
|
|
6912
|
+
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) {
|
|
6913
|
+
const reason = "is not a valid internal imports specifier name";
|
|
6914
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, (0, import_node_url6.fileURLToPath)(base));
|
|
6915
|
+
}
|
|
6916
|
+
let packageJsonUrl;
|
|
6917
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
6918
|
+
if (packageConfig.exists) {
|
|
6919
|
+
packageJsonUrl = (0, import_node_url6.pathToFileURL)(packageConfig.pjsonPath);
|
|
6920
|
+
const imports = packageConfig.imports;
|
|
6921
|
+
if (imports) {
|
|
6922
|
+
if (own2.call(imports, name) && !name.includes("*")) {
|
|
6923
|
+
const resolveResult = resolvePackageTarget(
|
|
6924
|
+
packageJsonUrl,
|
|
6925
|
+
imports[name],
|
|
6926
|
+
"",
|
|
6927
|
+
name,
|
|
6928
|
+
base,
|
|
6929
|
+
false,
|
|
6930
|
+
true,
|
|
6931
|
+
false,
|
|
6932
|
+
conditions
|
|
6933
|
+
);
|
|
6934
|
+
if (resolveResult !== null && resolveResult !== void 0) {
|
|
6935
|
+
return resolveResult;
|
|
6936
|
+
}
|
|
6937
|
+
} else {
|
|
6938
|
+
let bestMatch = "";
|
|
6939
|
+
let bestMatchSubpath = "";
|
|
6940
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
6941
|
+
let i = -1;
|
|
6942
|
+
while (++i < keys.length) {
|
|
6943
|
+
const key = keys[i];
|
|
6944
|
+
const patternIndex = key.indexOf("*");
|
|
6945
|
+
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
6946
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
6947
|
+
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
6948
|
+
bestMatch = key;
|
|
6949
|
+
bestMatchSubpath = name.slice(
|
|
6950
|
+
patternIndex,
|
|
6951
|
+
name.length - patternTrailer.length
|
|
6952
|
+
);
|
|
6953
|
+
}
|
|
6954
|
+
}
|
|
6955
|
+
}
|
|
6956
|
+
if (bestMatch) {
|
|
6957
|
+
const target = imports[bestMatch];
|
|
6958
|
+
const resolveResult = resolvePackageTarget(
|
|
6959
|
+
packageJsonUrl,
|
|
6960
|
+
target,
|
|
6961
|
+
bestMatchSubpath,
|
|
6962
|
+
bestMatch,
|
|
6963
|
+
base,
|
|
6964
|
+
true,
|
|
6965
|
+
true,
|
|
6966
|
+
false,
|
|
6967
|
+
conditions
|
|
6968
|
+
);
|
|
6969
|
+
if (resolveResult !== null && resolveResult !== void 0) {
|
|
6970
|
+
return resolveResult;
|
|
6971
|
+
}
|
|
6972
|
+
}
|
|
6973
|
+
}
|
|
6974
|
+
}
|
|
6975
|
+
}
|
|
6976
|
+
throw importNotDefined(name, packageJsonUrl, base);
|
|
6977
|
+
}
|
|
6978
|
+
function parsePackageName(specifier, base) {
|
|
6979
|
+
let separatorIndex = specifier.indexOf("/");
|
|
6980
|
+
let validPackageName = true;
|
|
6981
|
+
let isScoped = false;
|
|
6982
|
+
if (specifier[0] === "@") {
|
|
6983
|
+
isScoped = true;
|
|
6984
|
+
if (separatorIndex === -1 || specifier.length === 0) {
|
|
6985
|
+
validPackageName = false;
|
|
6986
|
+
} else {
|
|
6987
|
+
separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
6988
|
+
}
|
|
6989
|
+
}
|
|
6990
|
+
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
6991
|
+
if (invalidPackageNameRegEx.exec(packageName) !== null) {
|
|
6992
|
+
validPackageName = false;
|
|
6993
|
+
}
|
|
6994
|
+
if (!validPackageName) {
|
|
6995
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
6996
|
+
specifier,
|
|
6997
|
+
"is not a valid package name",
|
|
6998
|
+
(0, import_node_url6.fileURLToPath)(base)
|
|
6999
|
+
);
|
|
7000
|
+
}
|
|
7001
|
+
const packageSubpath = "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex));
|
|
7002
|
+
return { packageName, packageSubpath, isScoped };
|
|
7003
|
+
}
|
|
7004
|
+
function packageResolve(specifier, base, conditions) {
|
|
7005
|
+
if (import_node_module7.builtinModules.includes(specifier)) {
|
|
7006
|
+
return new URL("node:" + specifier);
|
|
7007
|
+
}
|
|
7008
|
+
const { packageName, packageSubpath, isScoped } = parsePackageName(
|
|
7009
|
+
specifier,
|
|
7010
|
+
base
|
|
7011
|
+
);
|
|
7012
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
7013
|
+
if (packageConfig.exists) {
|
|
7014
|
+
const packageJsonUrl2 = (0, import_node_url6.pathToFileURL)(packageConfig.pjsonPath);
|
|
7015
|
+
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
|
|
7016
|
+
return packageExportsResolve(
|
|
7017
|
+
packageJsonUrl2,
|
|
7018
|
+
packageSubpath,
|
|
7019
|
+
packageConfig,
|
|
7020
|
+
base,
|
|
7021
|
+
conditions
|
|
7022
|
+
);
|
|
7023
|
+
}
|
|
7024
|
+
}
|
|
7025
|
+
let packageJsonUrl = new URL(
|
|
7026
|
+
"./node_modules/" + packageName + "/package.json",
|
|
7027
|
+
base
|
|
7028
|
+
);
|
|
7029
|
+
let packageJsonPath = (0, import_node_url6.fileURLToPath)(packageJsonUrl);
|
|
7030
|
+
let lastPath;
|
|
7031
|
+
do {
|
|
7032
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
7033
|
+
if (!stat || !stat.isDirectory()) {
|
|
7034
|
+
lastPath = packageJsonPath;
|
|
7035
|
+
packageJsonUrl = new URL(
|
|
7036
|
+
(isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
|
|
7037
|
+
packageJsonUrl
|
|
7038
|
+
);
|
|
7039
|
+
packageJsonPath = (0, import_node_url6.fileURLToPath)(packageJsonUrl);
|
|
7040
|
+
continue;
|
|
7041
|
+
}
|
|
7042
|
+
const packageConfig2 = read(packageJsonPath, { base, specifier });
|
|
7043
|
+
if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
|
|
7044
|
+
return packageExportsResolve(
|
|
7045
|
+
packageJsonUrl,
|
|
7046
|
+
packageSubpath,
|
|
7047
|
+
packageConfig2,
|
|
7048
|
+
base,
|
|
7049
|
+
conditions
|
|
7050
|
+
);
|
|
7051
|
+
}
|
|
7052
|
+
if (packageSubpath === ".") {
|
|
7053
|
+
return legacyMainResolve(packageJsonUrl, packageConfig2, base);
|
|
7054
|
+
}
|
|
7055
|
+
return new URL(packageSubpath, packageJsonUrl);
|
|
7056
|
+
} while (packageJsonPath.length !== lastPath.length);
|
|
7057
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, (0, import_node_url6.fileURLToPath)(base), false);
|
|
7058
|
+
}
|
|
7059
|
+
function isRelativeSpecifier(specifier) {
|
|
7060
|
+
if (specifier[0] === ".") {
|
|
7061
|
+
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
7062
|
+
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) {
|
|
7063
|
+
return true;
|
|
7064
|
+
}
|
|
7065
|
+
}
|
|
7066
|
+
return false;
|
|
7067
|
+
}
|
|
7068
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
7069
|
+
if (specifier === "") return false;
|
|
7070
|
+
if (specifier[0] === "/") return true;
|
|
7071
|
+
return isRelativeSpecifier(specifier);
|
|
7072
|
+
}
|
|
7073
|
+
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
7074
|
+
if (conditions === void 0) {
|
|
7075
|
+
conditions = getConditionsSet();
|
|
7076
|
+
}
|
|
7077
|
+
const protocol = base.protocol;
|
|
7078
|
+
const isData = protocol === "data:";
|
|
7079
|
+
const isRemote = isData || protocol === "http:" || protocol === "https:";
|
|
7080
|
+
let resolved;
|
|
7081
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
7082
|
+
try {
|
|
7083
|
+
resolved = new URL(specifier, base);
|
|
7084
|
+
} catch (error_) {
|
|
7085
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
7086
|
+
error.cause = error_;
|
|
7087
|
+
throw error;
|
|
7088
|
+
}
|
|
7089
|
+
} else if (protocol === "file:" && specifier[0] === "#") {
|
|
7090
|
+
resolved = packageImportsResolve(specifier, base, conditions);
|
|
7091
|
+
} else {
|
|
7092
|
+
try {
|
|
7093
|
+
resolved = new URL(specifier);
|
|
7094
|
+
} catch (error_) {
|
|
7095
|
+
if (isRemote && !import_node_module7.builtinModules.includes(specifier)) {
|
|
7096
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
7097
|
+
error.cause = error_;
|
|
7098
|
+
throw error;
|
|
7099
|
+
}
|
|
7100
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
import_node_assert2.default.ok(resolved !== void 0, "expected to be defined");
|
|
7104
|
+
if (resolved.protocol !== "file:") {
|
|
7105
|
+
return resolved;
|
|
7106
|
+
}
|
|
7107
|
+
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
7108
|
+
}
|
|
7109
|
+
var import_node_assert2, import_node_fs13, import_node_process, import_node_url6, import_node_path16, import_node_module7, 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;
|
|
7110
|
+
var init_resolve2 = __esm({
|
|
7111
|
+
"node_modules/import-meta-resolve/lib/resolve.js"() {
|
|
7112
|
+
"use strict";
|
|
7113
|
+
import_node_assert2 = __toESM(require("assert"), 1);
|
|
7114
|
+
import_node_fs13 = require("fs");
|
|
7115
|
+
import_node_process = __toESM(require("process"), 1);
|
|
7116
|
+
import_node_url6 = require("url");
|
|
7117
|
+
import_node_path16 = __toESM(require("path"), 1);
|
|
7118
|
+
import_node_module7 = require("module");
|
|
7119
|
+
init_get_format();
|
|
7120
|
+
init_errors();
|
|
7121
|
+
init_package_json_reader();
|
|
7122
|
+
init_utils();
|
|
7123
|
+
RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
7124
|
+
({
|
|
7125
|
+
ERR_NETWORK_IMPORT_DISALLOWED,
|
|
7126
|
+
ERR_INVALID_MODULE_SPECIFIER,
|
|
7127
|
+
ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG2,
|
|
7128
|
+
ERR_INVALID_PACKAGE_TARGET,
|
|
7129
|
+
ERR_MODULE_NOT_FOUND,
|
|
7130
|
+
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
7131
|
+
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
7132
|
+
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
7133
|
+
ERR_UNSUPPORTED_RESOLVE_REQUEST
|
|
7134
|
+
} = codes);
|
|
7135
|
+
own2 = {}.hasOwnProperty;
|
|
7136
|
+
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;
|
|
7137
|
+
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;
|
|
7138
|
+
invalidPackageNameRegEx = /^\.|%|\\/;
|
|
7139
|
+
patternRegEx = /\*/g;
|
|
7140
|
+
encodedSeparatorRegEx = /%2f|%5c/i;
|
|
7141
|
+
emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
7142
|
+
doubleSlashRegEx = /[/\\]{2}/;
|
|
7143
|
+
}
|
|
7144
|
+
});
|
|
7145
|
+
|
|
7146
|
+
// node_modules/import-meta-resolve/index.js
|
|
7147
|
+
var init_import_meta_resolve = __esm({
|
|
7148
|
+
"node_modules/import-meta-resolve/index.js"() {
|
|
7149
|
+
"use strict";
|
|
7150
|
+
init_resolve2();
|
|
7151
|
+
}
|
|
7152
|
+
});
|
|
7153
|
+
|
|
7154
|
+
// src/server/runnable-environment.ts
|
|
7155
|
+
var runnable_environment_exports = {};
|
|
7156
|
+
__export(runnable_environment_exports, {
|
|
7157
|
+
NastiModuleRunner: () => NastiModuleRunner,
|
|
7158
|
+
createModuleRunner: () => createModuleRunner
|
|
7159
|
+
});
|
|
7160
|
+
function createModuleRunner(environment) {
|
|
7161
|
+
if (environment.consumer !== "server") {
|
|
7162
|
+
throw new Error(
|
|
7163
|
+
`[nasti] module runner requires a server-consumer environment (got "${environment.name}" / ${environment.consumer})`
|
|
7164
|
+
);
|
|
7165
|
+
}
|
|
7166
|
+
return new NastiModuleRunner(environment);
|
|
7167
|
+
}
|
|
7168
|
+
var import_node_path17, import_node_fs14, import_node_module8, import_node_url7, debug6, NODE_BUILTINS3, NastiModuleRunner, AsyncFunction;
|
|
7169
|
+
var init_runnable_environment = __esm({
|
|
7170
|
+
"src/server/runnable-environment.ts"() {
|
|
7171
|
+
"use strict";
|
|
7172
|
+
import_node_path17 = __toESM(require("path"), 1);
|
|
7173
|
+
import_node_fs14 = __toESM(require("fs"), 1);
|
|
7174
|
+
import_node_module8 = require("module");
|
|
7175
|
+
import_node_url7 = require("url");
|
|
7176
|
+
init_import_meta_resolve();
|
|
7177
|
+
init_transformer();
|
|
7178
|
+
init_env();
|
|
7179
|
+
init_debug();
|
|
7180
|
+
debug6 = createDebugger("nasti:ssr");
|
|
7181
|
+
NODE_BUILTINS3 = /* @__PURE__ */ new Set([...import_node_module8.builtinModules, ...import_node_module8.builtinModules.map((m) => `node:${m}`)]);
|
|
7182
|
+
NastiModuleRunner = class {
|
|
7183
|
+
environment;
|
|
7184
|
+
config;
|
|
7185
|
+
cache = /* @__PURE__ */ new Map();
|
|
7186
|
+
envDefine;
|
|
7187
|
+
externalImportParent;
|
|
7188
|
+
externalImportConditions;
|
|
7189
|
+
constructor(environment) {
|
|
7190
|
+
this.environment = environment;
|
|
7191
|
+
this.config = environment.config;
|
|
7192
|
+
this.envDefine = buildEnvDefine(
|
|
7193
|
+
loadEnv(this.config.mode, this.config.root, this.config.envPrefix),
|
|
7194
|
+
this.config.mode,
|
|
7195
|
+
ssrDefineOverrides(environment.consumer)
|
|
7196
|
+
);
|
|
7197
|
+
this.externalImportParent = (0, import_node_url7.pathToFileURL)(import_node_path17.default.join(this.config.root, "package.json"));
|
|
7198
|
+
this.externalImportConditions = /* @__PURE__ */ new Set([
|
|
7199
|
+
...environment.options.resolve.conditions.filter((condition) => condition !== "require"),
|
|
7200
|
+
"node",
|
|
7201
|
+
"import"
|
|
7202
|
+
]);
|
|
7203
|
+
const handlers = {
|
|
7204
|
+
fetchModule: async (id, importer) => this.fetchModule(id, importer),
|
|
7205
|
+
getBuiltins: () => [/^node:/, ...import_node_module8.builtinModules]
|
|
7206
|
+
};
|
|
7207
|
+
environment.hot.setInvokeHandler?.(handlers);
|
|
7208
|
+
}
|
|
7209
|
+
/** 入口:加载并执行一个模块(url 为根相对或绝对路径) */
|
|
7210
|
+
async import(rawUrl) {
|
|
7211
|
+
const id = this.resolveToId(rawUrl);
|
|
7212
|
+
return this.instantiate(id);
|
|
7213
|
+
}
|
|
7214
|
+
/** 文件变更时按文件失效(含其所属的虚拟子模块) */
|
|
7215
|
+
invalidateFile(file) {
|
|
7216
|
+
for (const key of [...this.cache.keys()]) {
|
|
7217
|
+
if (key === file || key.startsWith(file + "?")) {
|
|
7218
|
+
this.cache.delete(key);
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
}
|
|
7222
|
+
invalidateAll() {
|
|
7223
|
+
this.cache.clear();
|
|
7224
|
+
}
|
|
7225
|
+
resolveToId(rawUrl) {
|
|
7226
|
+
if (import_node_path17.default.isAbsolute(rawUrl) && import_node_fs14.default.existsSync(rawUrl.split("?")[0])) return rawUrl;
|
|
7227
|
+
const clean = rawUrl.replace(/^\//, "");
|
|
7228
|
+
return import_node_path17.default.resolve(this.config.root, clean);
|
|
7229
|
+
}
|
|
7230
|
+
/**
|
|
7231
|
+
* fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
|
|
7232
|
+
* resolve(插件 resolveId → 文件系统)→ load/读盘 → 插件 transform →
|
|
7233
|
+
* oxc(TS/JSX)→ moduleRunnerTransform。
|
|
7234
|
+
*/
|
|
7235
|
+
async fetchModule(id, importer) {
|
|
7236
|
+
if (NODE_BUILTINS3.has(id)) return { externalize: id };
|
|
7237
|
+
if (!id.startsWith(".") && !import_node_path17.default.isAbsolute(id) && !id.startsWith("\0")) {
|
|
7238
|
+
return { externalize: id };
|
|
7239
|
+
}
|
|
7240
|
+
const container = this.environment.pluginContainer;
|
|
7241
|
+
let resolvedId = id;
|
|
7242
|
+
if (id.startsWith(".") && importer) {
|
|
7243
|
+
const resolved = await container.resolveId(id, importer);
|
|
7244
|
+
resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : import_node_path17.default.resolve(import_node_path17.default.dirname(importer.split("?")[0]), id);
|
|
7245
|
+
}
|
|
7246
|
+
resolvedId = this.completeExtension(resolvedId);
|
|
7247
|
+
const cleanId = resolvedId.split("?")[0];
|
|
7248
|
+
let code;
|
|
7249
|
+
const loaded = await container.load(resolvedId);
|
|
7250
|
+
if (loaded != null) {
|
|
7251
|
+
code = typeof loaded === "string" ? loaded : loaded.code;
|
|
7252
|
+
} else if (import_node_fs14.default.existsSync(cleanId)) {
|
|
7253
|
+
code = import_node_fs14.default.readFileSync(cleanId, "utf-8");
|
|
7254
|
+
} else {
|
|
7255
|
+
throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
|
|
7256
|
+
}
|
|
7257
|
+
const transformed = await container.transform(code, resolvedId);
|
|
7258
|
+
if (transformed != null) {
|
|
7259
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
7260
|
+
}
|
|
7261
|
+
if (this.config.framework === "react") {
|
|
7262
|
+
const result = await transformReactCode(cleanId, code, {
|
|
7263
|
+
react: this.config.react,
|
|
7264
|
+
consumer: this.environment.consumer,
|
|
7265
|
+
development: true,
|
|
7266
|
+
sourcemap: false,
|
|
7267
|
+
target: this.environment.options.build.target,
|
|
7268
|
+
onWarning: (message) => this.config.logger.warn(`[nasti:react] ${message}`)
|
|
7269
|
+
});
|
|
7270
|
+
if (result) {
|
|
7271
|
+
code = result.code;
|
|
7272
|
+
} else if (shouldTransform(cleanId)) {
|
|
7273
|
+
const fallback = transformCode(cleanId, code, {
|
|
7274
|
+
sourcemap: false,
|
|
7275
|
+
jsxRuntime: this.config.react.jsxRuntime,
|
|
7276
|
+
jsxImportSource: this.config.react.jsxImportSource,
|
|
7277
|
+
target: this.environment.options.build.target
|
|
7278
|
+
});
|
|
7279
|
+
code = fallback.code;
|
|
7280
|
+
}
|
|
7281
|
+
} else if (shouldTransform(cleanId)) {
|
|
7282
|
+
const result = transformCode(cleanId, code, {
|
|
7283
|
+
sourcemap: false,
|
|
7284
|
+
target: this.environment.options.build.target,
|
|
7285
|
+
jsxRuntime: "automatic",
|
|
7286
|
+
jsxImportSource: "vue"
|
|
7287
|
+
});
|
|
7288
|
+
code = result.code;
|
|
7289
|
+
}
|
|
7290
|
+
code = replaceEnvInCode(code, this.envDefine);
|
|
7291
|
+
let moduleRunnerTransform;
|
|
7292
|
+
try {
|
|
7293
|
+
;
|
|
7294
|
+
({ moduleRunnerTransform } = await import("rolldown/experimental"));
|
|
7295
|
+
} catch (err) {
|
|
7296
|
+
throw new Error(
|
|
7297
|
+
`[nasti:ssr] rolldown/experimental moduleRunnerTransform unavailable (installed rolldown incompatible?): ${err.message}`
|
|
7298
|
+
);
|
|
7299
|
+
}
|
|
7300
|
+
const runnerResult = await moduleRunnerTransform(resolvedId, code);
|
|
7301
|
+
debug6?.(`fetchModule ${resolvedId} (${runnerResult.deps?.length ?? 0} deps)`);
|
|
7302
|
+
return { id: resolvedId, code: runnerResult.code };
|
|
7303
|
+
}
|
|
7304
|
+
completeExtension(id) {
|
|
7305
|
+
const clean = id.split("?")[0];
|
|
7306
|
+
const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
|
|
7307
|
+
if (import_node_fs14.default.existsSync(clean) && import_node_fs14.default.statSync(clean).isFile()) return id;
|
|
7308
|
+
const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
|
|
7309
|
+
if (jsMatch) {
|
|
7310
|
+
for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
|
|
7311
|
+
if (import_node_fs14.default.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
|
|
7312
|
+
}
|
|
7313
|
+
}
|
|
7314
|
+
for (const ext of this.config.resolve.extensions) {
|
|
7315
|
+
if (import_node_fs14.default.existsSync(clean + ext)) return clean + ext + query;
|
|
7316
|
+
}
|
|
7317
|
+
for (const ext of this.config.resolve.extensions) {
|
|
7318
|
+
const indexPath = import_node_path17.default.join(clean, `index${ext}`);
|
|
7319
|
+
if (import_node_fs14.default.existsSync(indexPath)) return indexPath;
|
|
7320
|
+
}
|
|
7321
|
+
return id;
|
|
7322
|
+
}
|
|
7323
|
+
async instantiate(id) {
|
|
7324
|
+
const cached2 = this.cache.get(id);
|
|
7325
|
+
if (cached2) return cached2.promise ?? Promise.resolve(cached2.exports);
|
|
7326
|
+
const entry = { exports: {}, promise: null };
|
|
7327
|
+
this.cache.set(id, entry);
|
|
7328
|
+
entry.promise = this.evaluate(id, entry).then(() => {
|
|
7329
|
+
entry.promise = null;
|
|
7330
|
+
return entry.exports;
|
|
7331
|
+
}).catch((err) => {
|
|
7332
|
+
this.cache.delete(id);
|
|
7333
|
+
throw err;
|
|
7334
|
+
});
|
|
7335
|
+
return entry.promise;
|
|
7336
|
+
}
|
|
7337
|
+
async evaluate(id, entry) {
|
|
7338
|
+
const fetched = await this.fetchModule(id);
|
|
7339
|
+
if ("externalize" in fetched) {
|
|
7340
|
+
const spec = fetched.externalize;
|
|
7341
|
+
const mod = await this.importExternal(spec);
|
|
7342
|
+
entry.exports = mod;
|
|
7343
|
+
return;
|
|
7344
|
+
}
|
|
7345
|
+
const ssrImport = async (dep) => {
|
|
7346
|
+
if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !import_node_path17.default.isAbsolute(dep) && !dep.startsWith("\0")) {
|
|
7347
|
+
return this.importExternal(dep);
|
|
7348
|
+
}
|
|
7349
|
+
const depId = dep.startsWith(".") ? this.completeExtension(import_node_path17.default.resolve(import_node_path17.default.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
|
|
7350
|
+
return this.instantiate(depId);
|
|
7351
|
+
};
|
|
7352
|
+
const ssrExportAll = (sourceModule) => {
|
|
7353
|
+
for (const key of Object.keys(sourceModule)) {
|
|
7354
|
+
if (key !== "default" && !(key in entry.exports)) {
|
|
7355
|
+
Object.defineProperty(entry.exports, key, {
|
|
7356
|
+
enumerable: true,
|
|
7357
|
+
configurable: true,
|
|
7358
|
+
get: () => sourceModule[key]
|
|
7359
|
+
});
|
|
7360
|
+
}
|
|
7361
|
+
}
|
|
7362
|
+
};
|
|
7363
|
+
const importMeta = {
|
|
7364
|
+
url: (0, import_node_url7.pathToFileURL)(fetched.id.split("?")[0]).href,
|
|
7365
|
+
env: { SSR: true, MODE: this.config.mode, DEV: this.config.mode !== "production", PROD: this.config.mode === "production" },
|
|
7366
|
+
hot: void 0
|
|
7367
|
+
};
|
|
7368
|
+
const fn = new AsyncFunction(
|
|
7369
|
+
"__vite_ssr_exports__",
|
|
7370
|
+
"__vite_ssr_import__",
|
|
7371
|
+
"__vite_ssr_dynamic_import__",
|
|
7372
|
+
"__vite_ssr_exportAll__",
|
|
7373
|
+
"__vite_ssr_import_meta__",
|
|
7374
|
+
`"use strict";${fetched.code}
|
|
7375
|
+
//# sourceURL=${fetched.id}`
|
|
7376
|
+
);
|
|
7377
|
+
await fn(entry.exports, ssrImport, ssrImport, ssrExportAll, importMeta);
|
|
7378
|
+
}
|
|
7379
|
+
async importExternal(spec) {
|
|
7380
|
+
try {
|
|
7381
|
+
return await (spec.startsWith("node:") || !import_node_path17.default.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import((0, import_node_url7.pathToFileURL)(spec).href));
|
|
7382
|
+
} catch (err) {
|
|
7383
|
+
throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
|
|
7384
|
+
}
|
|
7385
|
+
}
|
|
7386
|
+
/** bare specifier → 项目 node_modules 的 ESM URL(避免相对 Nasti 自身解析) */
|
|
7387
|
+
resolveExternalSpecifier(spec) {
|
|
7388
|
+
if (spec.startsWith("node:")) return spec;
|
|
7389
|
+
if (NODE_BUILTINS3.has(spec)) return `node:${spec}`;
|
|
7390
|
+
return moduleResolve(
|
|
7391
|
+
spec,
|
|
7392
|
+
this.externalImportParent,
|
|
7393
|
+
this.externalImportConditions,
|
|
7394
|
+
false
|
|
7395
|
+
).href;
|
|
7396
|
+
}
|
|
7397
|
+
};
|
|
5914
7398
|
AsyncFunction = Object.getPrototypeOf(async function() {
|
|
5915
7399
|
}).constructor;
|
|
5916
7400
|
}
|
|
@@ -5947,11 +7431,11 @@ async function createBundledDevServer(opts) {
|
|
|
5947
7431
|
const patches = new MemoryFiles();
|
|
5948
7432
|
const entryFileNames = /* @__PURE__ */ new Map();
|
|
5949
7433
|
const bundledClients = /* @__PURE__ */ new Map();
|
|
5950
|
-
const useReactRefresh = config.framework
|
|
7434
|
+
const useReactRefresh = config.framework === "react" && config.server.hmr !== false && refreshWrapperFn != null;
|
|
5951
7435
|
const rolldownPlugins = [
|
|
5952
7436
|
...useReactRefresh ? [
|
|
5953
7437
|
createReactRefreshRuntimePlugin(entryPoints),
|
|
5954
|
-
createBundledOxcRefreshPlugin()
|
|
7438
|
+
createBundledOxcRefreshPlugin(config)
|
|
5955
7439
|
] : [],
|
|
5956
7440
|
...stripCatchAllLoad(toRolldownPlugins(clientEnv.plugins, clientEnv)),
|
|
5957
7441
|
...useReactRefresh ? [
|
|
@@ -6002,7 +7486,7 @@ async function createBundledDevServer(opts) {
|
|
|
6002
7486
|
}
|
|
6003
7487
|
const url = `/${patchPath}`;
|
|
6004
7488
|
logger.info(
|
|
6005
|
-
import_picocolors8.default.green("hmr update ") + import_picocolors8.default.dim(changedFiles.map((f) =>
|
|
7489
|
+
import_picocolors8.default.green("hmr update ") + import_picocolors8.default.dim(changedFiles.map((f) => import_node_path18.default.relative(config.root, f)).join(", ")),
|
|
6006
7490
|
{ timestamp: true }
|
|
6007
7491
|
);
|
|
6008
7492
|
sendTo(clientId, { type: "hmr:update", path: url, url });
|
|
@@ -6157,7 +7641,7 @@ async function createBundledDevServer(opts) {
|
|
|
6157
7641
|
return;
|
|
6158
7642
|
}
|
|
6159
7643
|
res.setHeader("ETag", hit.etag);
|
|
6160
|
-
res.setHeader("Content-Type", MIME_TYPES[
|
|
7644
|
+
res.setHeader("Content-Type", MIME_TYPES[import_node_path18.default.extname(fileName)] ?? "application/octet-stream");
|
|
6161
7645
|
res.setHeader("Cache-Control", "no-cache");
|
|
6162
7646
|
res.once("finish", () => {
|
|
6163
7647
|
void engine.notifyPayloadDelivered(fileName).catch(
|
|
@@ -6198,7 +7682,7 @@ function stripCatchAllLoad(plugins) {
|
|
|
6198
7682
|
);
|
|
6199
7683
|
}
|
|
6200
7684
|
function createReactRefreshRuntimePlugin(entryPoints) {
|
|
6201
|
-
const entryIds = new Set(entryPoints.map((p) =>
|
|
7685
|
+
const entryIds = new Set(entryPoints.map((p) => import_node_path18.default.resolve(p)));
|
|
6202
7686
|
return {
|
|
6203
7687
|
name: "nasti:bundled-react-refresh",
|
|
6204
7688
|
resolveId(source) {
|
|
@@ -6216,24 +7700,27 @@ function createReactRefreshRuntimePlugin(entryPoints) {
|
|
|
6216
7700
|
return null;
|
|
6217
7701
|
},
|
|
6218
7702
|
transform(code, id) {
|
|
6219
|
-
if (!entryIds.has(
|
|
7703
|
+
if (!entryIds.has(import_node_path18.default.resolve(id.split("?")[0]))) return null;
|
|
6220
7704
|
return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
|
|
6221
7705
|
${code}`, map: null };
|
|
6222
7706
|
}
|
|
6223
7707
|
};
|
|
6224
7708
|
}
|
|
6225
|
-
function createBundledOxcRefreshPlugin() {
|
|
7709
|
+
function createBundledOxcRefreshPlugin(config) {
|
|
6226
7710
|
return {
|
|
6227
7711
|
name: "nasti:bundled-oxc-refresh",
|
|
6228
|
-
transform(code, id) {
|
|
7712
|
+
async transform(code, id) {
|
|
6229
7713
|
const clean = id.split("?")[0];
|
|
6230
|
-
|
|
6231
|
-
|
|
7714
|
+
const result = await transformReactCode(clean, code, {
|
|
7715
|
+
react: config.react,
|
|
7716
|
+
consumer: "client",
|
|
7717
|
+
development: true,
|
|
7718
|
+
reactRefresh: true,
|
|
6232
7719
|
sourcemap: true,
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
reactRefresh: true
|
|
7720
|
+
target: config.build.target,
|
|
7721
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
6236
7722
|
});
|
|
7723
|
+
if (!result) return null;
|
|
6237
7724
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
6238
7725
|
}
|
|
6239
7726
|
};
|
|
@@ -6263,11 +7750,11 @@ async function renderBundledIndexHtml(html, config, entryFileNames) {
|
|
|
6263
7750
|
}
|
|
6264
7751
|
return processed;
|
|
6265
7752
|
}
|
|
6266
|
-
var
|
|
7753
|
+
var import_node_path18, import_node_crypto3, import_ws2, import_picocolors8, debug7, MIME_TYPES, MemoryFiles, PREAMBLE_SPEC, RESOLVED_PREAMBLE_ID, REFRESH_RUNTIME_URL, BUNDLED_PREAMBLE_CODE, WRAPPER_RUNTIME_HELPERS;
|
|
6267
7754
|
var init_dev_engine = __esm({
|
|
6268
7755
|
"src/server/bundled/dev-engine.ts"() {
|
|
6269
7756
|
"use strict";
|
|
6270
|
-
|
|
7757
|
+
import_node_path18 = __toESM(require("path"), 1);
|
|
6271
7758
|
import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
6272
7759
|
import_ws2 = require("ws");
|
|
6273
7760
|
import_picocolors8 = __toESM(require("picocolors"), 1);
|
|
@@ -6477,19 +7964,19 @@ async function createServer(inlineConfig = {}) {
|
|
|
6477
7964
|
app.use(bundledServer.middleware);
|
|
6478
7965
|
}
|
|
6479
7966
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
6480
|
-
const outDirAbs =
|
|
7967
|
+
const outDirAbs = import_node_path19.default.resolve(config.root, config.build.outDir);
|
|
6481
7968
|
const linkedPackageRoots = getLinkedPackageRoots(config.root).filter(
|
|
6482
7969
|
(r) => r !== config.root && !isUnderRoot(config.root, r)
|
|
6483
7970
|
);
|
|
6484
7971
|
const watchTargets = [config.root, ...linkedPackageRoots];
|
|
6485
7972
|
const watcher = (0, import_chokidar.watch)(watchTargets, {
|
|
6486
7973
|
ignored: (filePath) => {
|
|
6487
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
7974
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path19.default.sep)) return true;
|
|
6488
7975
|
for (const watchRoot of watchTargets) {
|
|
6489
7976
|
if (filePath === watchRoot) return false;
|
|
6490
|
-
const rel =
|
|
6491
|
-
if (!rel || rel.startsWith("..") ||
|
|
6492
|
-
for (const seg of rel.split(
|
|
7977
|
+
const rel = import_node_path19.default.relative(watchRoot, filePath);
|
|
7978
|
+
if (!rel || rel.startsWith("..") || import_node_path19.default.isAbsolute(rel)) continue;
|
|
7979
|
+
for (const seg of rel.split(import_node_path19.default.sep)) {
|
|
6493
7980
|
if (ignoredSegments.has(seg)) return true;
|
|
6494
7981
|
}
|
|
6495
7982
|
return false;
|
|
@@ -6621,7 +8108,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6621
8108
|
});
|
|
6622
8109
|
};
|
|
6623
8110
|
watcher.on("change", (file) => {
|
|
6624
|
-
if (file.includes(`${
|
|
8111
|
+
if (file.includes(`${import_node_path19.default.sep}node_modules${import_node_path19.default.sep}`) || file.endsWith(`${import_node_path19.default.sep}node_modules`)) {
|
|
6625
8112
|
clearLinkedPackageRootsCache();
|
|
6626
8113
|
}
|
|
6627
8114
|
ssrRunner?.invalidateFile(file);
|
|
@@ -6629,7 +8116,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6629
8116
|
notifyEnvironmentDrivers(file, "change");
|
|
6630
8117
|
});
|
|
6631
8118
|
watcher.on("add", (file) => {
|
|
6632
|
-
if (file.includes(`${
|
|
8119
|
+
if (file.includes(`${import_node_path19.default.sep}node_modules${import_node_path19.default.sep}`) || file.endsWith(`${import_node_path19.default.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, "add");
|
|
6638
8125
|
});
|
|
6639
8126
|
watcher.on("unlink", (file) => {
|
|
6640
|
-
if (file.includes(`${
|
|
8127
|
+
if (file.includes(`${import_node_path19.default.sep}node_modules${import_node_path19.default.sep}`) || file.endsWith(`${import_node_path19.default.sep}node_modules`)) {
|
|
6641
8128
|
clearLinkedPackageRootsCache();
|
|
6642
8129
|
}
|
|
6643
8130
|
ssrRunner?.invalidateFile(file);
|
|
@@ -6669,7 +8156,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6669
8156
|
const readyIn = Math.ceil(performance.now() - startTime);
|
|
6670
8157
|
logger.info(
|
|
6671
8158
|
`
|
|
6672
|
-
${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.
|
|
8159
|
+
${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.5.1"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
|
|
6673
8160
|
`
|
|
6674
8161
|
);
|
|
6675
8162
|
printServerUrls(
|
|
@@ -6766,7 +8253,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
6766
8253
|
throw error;
|
|
6767
8254
|
}
|
|
6768
8255
|
app.use(transformMiddleware(transformContexts.get("client")));
|
|
6769
|
-
const publicDir =
|
|
8256
|
+
const publicDir = import_node_path19.default.resolve(config.root, "public");
|
|
6770
8257
|
app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
|
|
6771
8258
|
app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
|
|
6772
8259
|
const postMiddlewares = [];
|
|
@@ -6792,12 +8279,12 @@ function getNetworkAddress() {
|
|
|
6792
8279
|
}
|
|
6793
8280
|
return "localhost";
|
|
6794
8281
|
}
|
|
6795
|
-
var import_node_http,
|
|
8282
|
+
var import_node_http, import_node_path19, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors9;
|
|
6796
8283
|
var init_server = __esm({
|
|
6797
8284
|
"src/server/index.ts"() {
|
|
6798
8285
|
"use strict";
|
|
6799
8286
|
import_node_http = __toESM(require("http"), 1);
|
|
6800
|
-
|
|
8287
|
+
import_node_path19 = __toESM(require("path"), 1);
|
|
6801
8288
|
import_node_os = __toESM(require("os"), 1);
|
|
6802
8289
|
import_connect = __toESM(require("connect"), 1);
|
|
6803
8290
|
import_sirv = __toESM(require("sirv"), 1);
|
|
@@ -6840,6 +8327,7 @@ __export(src_exports, {
|
|
|
6840
8327
|
printServerUrls: () => printServerUrls,
|
|
6841
8328
|
resolveConfig: () => resolveConfig,
|
|
6842
8329
|
resolveEnvironmentPlugins: () => resolveEnvironmentPlugins,
|
|
8330
|
+
rsc: () => rsc,
|
|
6843
8331
|
ssrDefineOverrides: () => ssrDefineOverrides,
|
|
6844
8332
|
startElectronDev: () => startElectronDev
|
|
6845
8333
|
});
|
|
@@ -6896,7 +8384,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
6896
8384
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
6897
8385
|
const startTime = performance.now();
|
|
6898
8386
|
assertElectronVersion(config);
|
|
6899
|
-
console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.
|
|
8387
|
+
console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.5.1"}`));
|
|
6900
8388
|
console.log(import_picocolors5.default.dim(` root: ${config.root}`));
|
|
6901
8389
|
console.log(import_picocolors5.default.dim(` mode: ${config.mode}`));
|
|
6902
8390
|
console.log(import_picocolors5.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -6962,14 +8450,21 @@ async function bundleNode(config, entry, opts) {
|
|
|
6962
8450
|
};
|
|
6963
8451
|
const oxcTransformPlugin = {
|
|
6964
8452
|
name: "nasti:oxc-transform",
|
|
6965
|
-
transform(code, id) {
|
|
6966
|
-
|
|
6967
|
-
|
|
8453
|
+
async transform(code, id) {
|
|
8454
|
+
const result = config.framework === "react" ? await transformReactCode(id, code, {
|
|
8455
|
+
react: config.react,
|
|
8456
|
+
consumer: "server",
|
|
8457
|
+
development: config.mode === "development",
|
|
8458
|
+
sourcemap: !!config.build.sourcemap,
|
|
8459
|
+
target: config.electron.nodeTarget,
|
|
8460
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
8461
|
+
}) : shouldTransform(id) ? transformCode(id, code, {
|
|
6968
8462
|
sourcemap: !!config.build.sourcemap,
|
|
6969
8463
|
jsxRuntime: "automatic",
|
|
6970
|
-
jsxImportSource:
|
|
8464
|
+
jsxImportSource: "vue",
|
|
6971
8465
|
target: config.electron.nodeTarget
|
|
6972
|
-
});
|
|
8466
|
+
}) : null;
|
|
8467
|
+
if (!result) return null;
|
|
6973
8468
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
6974
8469
|
}
|
|
6975
8470
|
};
|
|
@@ -7019,8 +8514,8 @@ function createElectronRendererConfig(config, inlineConfig = {}, overrides = {})
|
|
|
7019
8514
|
}
|
|
7020
8515
|
};
|
|
7021
8516
|
}
|
|
7022
|
-
function outFileName(outDir, base,
|
|
7023
|
-
const ext =
|
|
8517
|
+
function outFileName(outDir, base, format2) {
|
|
8518
|
+
const ext = format2 === "cjs" ? ".cjs" : ".mjs";
|
|
7024
8519
|
return import_node_path11.default.join(outDir, base + ext);
|
|
7025
8520
|
}
|
|
7026
8521
|
function normalizePreload(preload, root) {
|
|
@@ -7062,9 +8557,9 @@ function detectInstalledElectron(root) {
|
|
|
7062
8557
|
init_server();
|
|
7063
8558
|
|
|
7064
8559
|
// src/server/electron-dev.ts
|
|
7065
|
-
var
|
|
7066
|
-
var
|
|
7067
|
-
var
|
|
8560
|
+
var import_node_path20 = __toESM(require("path"), 1);
|
|
8561
|
+
var import_node_fs15 = __toESM(require("fs"), 1);
|
|
8562
|
+
var import_node_module9 = require("module");
|
|
7068
8563
|
var import_node_child_process = require("child_process");
|
|
7069
8564
|
var import_chokidar2 = __toESM(require("chokidar"), 1);
|
|
7070
8565
|
var import_picocolors10 = __toESM(require("picocolors"), 1);
|
|
@@ -7077,7 +8572,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7077
8572
|
const { noSpawn, ...rest } = inlineConfig;
|
|
7078
8573
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
7079
8574
|
warnElectronVersion(config);
|
|
7080
|
-
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.
|
|
8575
|
+
console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.5.1"}`));
|
|
7081
8576
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
7082
8577
|
const server = await createServer2({
|
|
7083
8578
|
...rest,
|
|
@@ -7087,11 +8582,11 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7087
8582
|
await server.listen();
|
|
7088
8583
|
const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
|
|
7089
8584
|
console.log(import_picocolors10.default.dim(` renderer: ${devUrl}`));
|
|
7090
|
-
const stageDir =
|
|
7091
|
-
|
|
7092
|
-
const mainEntry =
|
|
8585
|
+
const stageDir = import_node_path20.default.resolve(config.root, ".nasti");
|
|
8586
|
+
import_node_fs15.default.mkdirSync(stageDir, { recursive: true });
|
|
8587
|
+
const mainEntry = import_node_path20.default.resolve(config.root, config.electron.main);
|
|
7093
8588
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
7094
|
-
const builtMainFile =
|
|
8589
|
+
const builtMainFile = import_node_path20.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
7095
8590
|
const builtPreloadFiles = [];
|
|
7096
8591
|
const compileAll = async () => {
|
|
7097
8592
|
await compileNode(config, mainEntry, {
|
|
@@ -7101,9 +8596,9 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7101
8596
|
});
|
|
7102
8597
|
builtPreloadFiles.length = 0;
|
|
7103
8598
|
for (const entry of preloadEntries) {
|
|
7104
|
-
if (!
|
|
7105
|
-
const base =
|
|
7106
|
-
const out =
|
|
8599
|
+
if (!import_node_fs15.default.existsSync(entry)) continue;
|
|
8600
|
+
const base = import_node_path20.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
8601
|
+
const out = import_node_path20.default.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
7107
8602
|
await compileNode(config, entry, {
|
|
7108
8603
|
outFile: out,
|
|
7109
8604
|
format: config.electron.preloadFormat,
|
|
@@ -7142,7 +8637,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7142
8637
|
};
|
|
7143
8638
|
spawnElectron();
|
|
7144
8639
|
if (config.electron.autoRestart) {
|
|
7145
|
-
const watchTargets = [mainEntry, ...preloadEntries].filter(
|
|
8640
|
+
const watchTargets = [mainEntry, ...preloadEntries].filter(import_node_fs15.default.existsSync);
|
|
7146
8641
|
const watcher = import_chokidar2.default.watch(watchTargets, { ignoreInitial: true });
|
|
7147
8642
|
let restarting = null;
|
|
7148
8643
|
let pending = false;
|
|
@@ -7189,8 +8684,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
7189
8684
|
});
|
|
7190
8685
|
}
|
|
7191
8686
|
}
|
|
7192
|
-
function extFor(
|
|
7193
|
-
return
|
|
8687
|
+
function extFor(format2) {
|
|
8688
|
+
return format2 === "cjs" ? ".cjs" : ".mjs";
|
|
7194
8689
|
}
|
|
7195
8690
|
async function compileNode(config, entry, opts) {
|
|
7196
8691
|
const env = loadEnv(config.mode, config.root, config.envPrefix);
|
|
@@ -7202,14 +8697,21 @@ async function compileNode(config, entry, opts) {
|
|
|
7202
8697
|
};
|
|
7203
8698
|
const oxcTransformPlugin = {
|
|
7204
8699
|
name: "nasti:oxc-transform",
|
|
7205
|
-
transform(code, id) {
|
|
7206
|
-
|
|
7207
|
-
|
|
8700
|
+
async transform(code, id) {
|
|
8701
|
+
const result = config.framework === "react" ? await transformReactCode(id, code, {
|
|
8702
|
+
react: config.react,
|
|
8703
|
+
consumer: "server",
|
|
8704
|
+
development: true,
|
|
8705
|
+
sourcemap: true,
|
|
8706
|
+
target: config.electron.nodeTarget,
|
|
8707
|
+
onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
|
|
8708
|
+
}) : shouldTransform(id) ? transformCode(id, code, {
|
|
7208
8709
|
sourcemap: true,
|
|
7209
8710
|
jsxRuntime: "automatic",
|
|
7210
|
-
jsxImportSource:
|
|
8711
|
+
jsxImportSource: "vue",
|
|
7211
8712
|
target: config.electron.nodeTarget
|
|
7212
|
-
});
|
|
8713
|
+
}) : null;
|
|
8714
|
+
if (!result) return null;
|
|
7213
8715
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
7214
8716
|
}
|
|
7215
8717
|
};
|
|
@@ -7222,7 +8724,7 @@ async function compileNode(config, entry, opts) {
|
|
|
7222
8724
|
platform: "node",
|
|
7223
8725
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
7224
8726
|
});
|
|
7225
|
-
|
|
8727
|
+
import_node_fs15.default.mkdirSync(import_node_path20.default.dirname(opts.outFile), { recursive: true });
|
|
7226
8728
|
await bundle2.write({
|
|
7227
8729
|
file: opts.outFile,
|
|
7228
8730
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -7235,18 +8737,18 @@ async function compileNode(config, entry, opts) {
|
|
|
7235
8737
|
await bundle2.close();
|
|
7236
8738
|
}
|
|
7237
8739
|
function electronRendererDevPath(renderer) {
|
|
7238
|
-
const normalized = renderer.split(
|
|
8740
|
+
const normalized = renderer.split(import_node_path20.default.sep).join("/").replace(/^\.?\//, "");
|
|
7239
8741
|
return normalized === "index.html" ? "/" : `/${normalized}`;
|
|
7240
8742
|
}
|
|
7241
8743
|
function resolveElectronBinary(config) {
|
|
7242
|
-
if (config.electron.electronPath &&
|
|
8744
|
+
if (config.electron.electronPath && import_node_fs15.default.existsSync(config.electron.electronPath)) {
|
|
7243
8745
|
return config.electron.electronPath;
|
|
7244
8746
|
}
|
|
7245
8747
|
try {
|
|
7246
|
-
const require2 = (0,
|
|
8748
|
+
const require2 = (0, import_node_module9.createRequire)(import_node_path20.default.resolve(config.root, "package.json"));
|
|
7247
8749
|
const pathFile = require2.resolve("electron");
|
|
7248
8750
|
const electronModule = require2(pathFile);
|
|
7249
|
-
if (typeof electronModule === "string" &&
|
|
8751
|
+
if (typeof electronModule === "string" && import_node_fs15.default.existsSync(electronModule)) {
|
|
7250
8752
|
return electronModule;
|
|
7251
8753
|
}
|
|
7252
8754
|
} catch {
|
|
@@ -7273,10 +8775,10 @@ function warnElectronVersion(config) {
|
|
|
7273
8775
|
}
|
|
7274
8776
|
|
|
7275
8777
|
// src/plugins/monaco-editor.ts
|
|
7276
|
-
var
|
|
7277
|
-
var
|
|
8778
|
+
var import_node_path21 = __toESM(require("path"), 1);
|
|
8779
|
+
var import_node_fs16 = __toESM(require("fs"), 1);
|
|
7278
8780
|
var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
7279
|
-
var
|
|
8781
|
+
var import_node_module10 = require("module");
|
|
7280
8782
|
var DEFAULT_WORKERS = {
|
|
7281
8783
|
editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
|
|
7282
8784
|
css: "monaco-editor/esm/vs/language/css/css.worker",
|
|
@@ -7295,9 +8797,9 @@ function normalizePublicPath(p) {
|
|
|
7295
8797
|
}
|
|
7296
8798
|
function readMonacoVersion(root) {
|
|
7297
8799
|
try {
|
|
7298
|
-
const require2 = (0,
|
|
8800
|
+
const require2 = (0, import_node_module10.createRequire)(import_node_path21.default.resolve(root, "package.json"));
|
|
7299
8801
|
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
7300
|
-
const pkg = JSON.parse(
|
|
8802
|
+
const pkg = JSON.parse(import_node_fs16.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
7301
8803
|
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
7302
8804
|
} catch {
|
|
7303
8805
|
return "unknown";
|
|
@@ -7317,20 +8819,20 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7317
8819
|
let cacheDir = "";
|
|
7318
8820
|
const building = /* @__PURE__ */ new Map();
|
|
7319
8821
|
async function buildWorker(worker) {
|
|
7320
|
-
const cacheFile =
|
|
7321
|
-
if (
|
|
8822
|
+
const cacheFile = import_node_path21.default.join(cacheDir, `${worker.label}.worker.js`);
|
|
8823
|
+
if (import_node_fs16.default.existsSync(cacheFile)) return cacheFile;
|
|
7322
8824
|
const existing = building.get(worker.label);
|
|
7323
8825
|
if (existing) return existing;
|
|
7324
8826
|
const task = (async () => {
|
|
7325
8827
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
7326
|
-
const require2 = (0,
|
|
8828
|
+
const require2 = (0, import_node_module10.createRequire)(import_node_path21.default.resolve(resolvedConfig.root, "package.json"));
|
|
7327
8829
|
let entry;
|
|
7328
8830
|
try {
|
|
7329
8831
|
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
7330
8832
|
} catch {
|
|
7331
8833
|
entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
|
|
7332
8834
|
}
|
|
7333
|
-
|
|
8835
|
+
import_node_fs16.default.mkdirSync(cacheDir, { recursive: true });
|
|
7334
8836
|
const bundle2 = await rolldown4({
|
|
7335
8837
|
input: entry,
|
|
7336
8838
|
platform: "browser"
|
|
@@ -7390,15 +8892,15 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7390
8892
|
resolvedConfig = config;
|
|
7391
8893
|
const version = readMonacoVersion(config.root);
|
|
7392
8894
|
const key = import_node_crypto4.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
7393
|
-
cacheDir =
|
|
8895
|
+
cacheDir = import_node_path21.default.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
7394
8896
|
},
|
|
7395
8897
|
async configureServer(server) {
|
|
7396
8898
|
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
7397
8899
|
const watcher = server.watcher;
|
|
7398
|
-
const monacoLogical =
|
|
8900
|
+
const monacoLogical = import_node_path21.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
7399
8901
|
const monacoPaths = /* @__PURE__ */ new Set([monacoLogical]);
|
|
7400
8902
|
try {
|
|
7401
|
-
monacoPaths.add(
|
|
8903
|
+
monacoPaths.add(import_node_fs16.default.realpathSync(monacoLogical));
|
|
7402
8904
|
} catch {
|
|
7403
8905
|
}
|
|
7404
8906
|
for (const monacoDir of monacoPaths) {
|
|
@@ -7432,7 +8934,7 @@ function monacoEditorPlugin(options = {}) {
|
|
|
7432
8934
|
const file = await buildWorker(worker);
|
|
7433
8935
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
7434
8936
|
res.setHeader("Cache-Control", "public, max-age=604800, immutable");
|
|
7435
|
-
|
|
8937
|
+
import_node_fs16.default.createReadStream(file).pipe(res);
|
|
7436
8938
|
} catch (e) {
|
|
7437
8939
|
res.statusCode = 500;
|
|
7438
8940
|
res.end(`Monaco worker build failed: ${e.message}`);
|
|
@@ -7467,16 +8969,16 @@ self.monaco = monaco;`,
|
|
|
7467
8969
|
resolvedConfig.root,
|
|
7468
8970
|
resolvedConfig.build.outDir,
|
|
7469
8971
|
resolvedConfig.base
|
|
7470
|
-
) : isCDN(publicPath) ?
|
|
8972
|
+
) : isCDN(publicPath) ? import_node_path21.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path21.default.resolve(
|
|
7471
8973
|
resolvedConfig.root,
|
|
7472
8974
|
resolvedConfig.build.outDir,
|
|
7473
8975
|
publicPath.replace(/^\//, "")
|
|
7474
8976
|
);
|
|
7475
|
-
|
|
8977
|
+
import_node_fs16.default.mkdirSync(outDir, { recursive: true });
|
|
7476
8978
|
for (const worker of workers) {
|
|
7477
8979
|
try {
|
|
7478
8980
|
const cacheFile = await buildWorker(worker);
|
|
7479
|
-
|
|
8981
|
+
import_node_fs16.default.copyFileSync(cacheFile, import_node_path21.default.join(outDir, `${worker.label}.worker.js`));
|
|
7480
8982
|
} catch (e) {
|
|
7481
8983
|
throw new Error(
|
|
7482
8984
|
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|
|
@@ -7488,6 +8990,345 @@ ${e.stack || ""}`
|
|
|
7488
8990
|
};
|
|
7489
8991
|
}
|
|
7490
8992
|
|
|
8993
|
+
// src/plugins/rsc.ts
|
|
8994
|
+
var import_node_fs17 = __toESM(require("fs"), 1);
|
|
8995
|
+
var import_node_path22 = __toESM(require("path"), 1);
|
|
8996
|
+
var import_oxc_parser = require("oxc-parser");
|
|
8997
|
+
init_transformer();
|
|
8998
|
+
var SERVER_RUNTIME_ID = "virtual:nasti-rsc/server-runtime";
|
|
8999
|
+
var CLIENT_RUNTIME_ID = "virtual:nasti-rsc/client-runtime";
|
|
9000
|
+
var RESOLVED_SERVER_RUNTIME_ID = `\0${SERVER_RUNTIME_ID}`;
|
|
9001
|
+
var RESOLVED_CLIENT_RUNTIME_ID = `\0${CLIENT_RUNTIME_ID}`;
|
|
9002
|
+
function rsc(options = {}) {
|
|
9003
|
+
const names = {
|
|
9004
|
+
client: options.environment?.client ?? "client",
|
|
9005
|
+
ssr: options.environment?.ssr ?? "ssr",
|
|
9006
|
+
rsc: options.environment?.rsc ?? "rsc"
|
|
9007
|
+
};
|
|
9008
|
+
const clientReferences = /* @__PURE__ */ new Map();
|
|
9009
|
+
const serverReferences = /* @__PURE__ */ new Map();
|
|
9010
|
+
let resolvedConfig;
|
|
9011
|
+
return {
|
|
9012
|
+
name: "nasti:rsc",
|
|
9013
|
+
enforce: "post",
|
|
9014
|
+
config(config, env) {
|
|
9015
|
+
const root = import_node_path22.default.resolve(config.root ?? ".");
|
|
9016
|
+
const include = options.include ?? config.react?.include ?? /\.[tj]sx?$/;
|
|
9017
|
+
const exclude = options.exclude ?? config.react?.exclude ?? /node_modules/;
|
|
9018
|
+
const discoveredClients = env.command === "build" ? discoverDirectiveModules(root, options.scanDirectories, include, exclude) : [];
|
|
9019
|
+
for (const item of discoveredClients) {
|
|
9020
|
+
if (item.module.useClient) {
|
|
9021
|
+
clientReferences.set(
|
|
9022
|
+
item.id,
|
|
9023
|
+
new Set(item.module.exports.map((entry) => entry.exported))
|
|
9024
|
+
);
|
|
9025
|
+
}
|
|
9026
|
+
if (item.module.useServer) {
|
|
9027
|
+
serverReferences.set(
|
|
9028
|
+
item.id,
|
|
9029
|
+
new Set(item.module.exports.map((entry) => entry.exported))
|
|
9030
|
+
);
|
|
9031
|
+
}
|
|
9032
|
+
}
|
|
9033
|
+
const environments = { ...config.environments ?? {} };
|
|
9034
|
+
if (names.client !== "client") {
|
|
9035
|
+
environments.client = {
|
|
9036
|
+
...environments.client ?? {},
|
|
9037
|
+
buildEnabled: false
|
|
9038
|
+
};
|
|
9039
|
+
}
|
|
9040
|
+
const client = { ...environments[names.client] ?? {} };
|
|
9041
|
+
const clientSeeds = collectClientSeeds(root, config, client, options.entries?.client);
|
|
9042
|
+
const generatedClientEntries = discoveredClients.filter((item) => item.module.useClient).map((item) => item.id);
|
|
9043
|
+
client.consumer = "client";
|
|
9044
|
+
client.entry = uniqueEntries([...clientSeeds, ...generatedClientEntries]);
|
|
9045
|
+
environments[names.client] = client;
|
|
9046
|
+
const rscEnvironment = { ...environments[names.rsc] ?? {} };
|
|
9047
|
+
rscEnvironment.consumer = "server";
|
|
9048
|
+
const rscEntries = normalizeEntries(options.entries?.rsc);
|
|
9049
|
+
if (rscEntries.length > 0) rscEnvironment.entry = rscEntries;
|
|
9050
|
+
environments[names.rsc] = rscEnvironment;
|
|
9051
|
+
const ssrEntries = normalizeEntries(options.entries?.ssr);
|
|
9052
|
+
if (ssrEntries.length > 0 || environments[names.ssr]) {
|
|
9053
|
+
environments[names.ssr] = {
|
|
9054
|
+
...environments[names.ssr] ?? {},
|
|
9055
|
+
consumer: "server",
|
|
9056
|
+
...ssrEntries.length > 0 ? { entry: ssrEntries } : {}
|
|
9057
|
+
};
|
|
9058
|
+
}
|
|
9059
|
+
return { environments };
|
|
9060
|
+
},
|
|
9061
|
+
configEnvironment(name, environment) {
|
|
9062
|
+
if (name !== names.rsc) return;
|
|
9063
|
+
const conditions = environment.resolve?.conditions ?? ["node", "import", "module", "default"];
|
|
9064
|
+
return {
|
|
9065
|
+
consumer: "server",
|
|
9066
|
+
resolve: {
|
|
9067
|
+
...environment.resolve,
|
|
9068
|
+
conditions: ["react-server", ...conditions.filter((item) => item !== "react-server")]
|
|
9069
|
+
}
|
|
9070
|
+
};
|
|
9071
|
+
},
|
|
9072
|
+
configResolved(config) {
|
|
9073
|
+
if (config.framework !== "react") {
|
|
9074
|
+
throw new Error('[nasti:rsc] the RSC generator requires framework: "react"');
|
|
9075
|
+
}
|
|
9076
|
+
resolvedConfig = config;
|
|
9077
|
+
},
|
|
9078
|
+
resolveId(source) {
|
|
9079
|
+
if (source === SERVER_RUNTIME_ID) return RESOLVED_SERVER_RUNTIME_ID;
|
|
9080
|
+
if (source === CLIENT_RUNTIME_ID) return RESOLVED_CLIENT_RUNTIME_ID;
|
|
9081
|
+
return null;
|
|
9082
|
+
},
|
|
9083
|
+
load(id) {
|
|
9084
|
+
if (id === RESOLVED_SERVER_RUNTIME_ID) return createServerRuntimeModule();
|
|
9085
|
+
if (id === RESOLVED_CLIENT_RUNTIME_ID) {
|
|
9086
|
+
const browser = this.environment?.name === names.client;
|
|
9087
|
+
return createClientRuntimeModule(browser);
|
|
9088
|
+
}
|
|
9089
|
+
return null;
|
|
9090
|
+
},
|
|
9091
|
+
transform(code, id) {
|
|
9092
|
+
if (!resolvedConfig || !isSourceModule(id, resolvedConfig, options)) return null;
|
|
9093
|
+
const cleanId = cleanModuleId(id);
|
|
9094
|
+
const module2 = scanModule(cleanId, code);
|
|
9095
|
+
if (!module2) return null;
|
|
9096
|
+
if (module2.useClient && module2.useServer) {
|
|
9097
|
+
throw new Error(`[nasti:rsc] ${displayId(resolvedConfig.root, cleanId)} cannot contain both "use client" and "use server"`);
|
|
9098
|
+
}
|
|
9099
|
+
const moduleId = referenceModuleId(resolvedConfig.root, cleanId);
|
|
9100
|
+
if (module2.useClient) {
|
|
9101
|
+
clientReferences.set(cleanId, new Set(module2.exports.map((entry) => entry.exported)));
|
|
9102
|
+
if (this.environment?.name === names.rsc) {
|
|
9103
|
+
return {
|
|
9104
|
+
code: createClientReferenceProxy(moduleId, module2.exports),
|
|
9105
|
+
map: { mappings: "" }
|
|
9106
|
+
};
|
|
9107
|
+
}
|
|
9108
|
+
}
|
|
9109
|
+
if (module2.useServer) {
|
|
9110
|
+
serverReferences.set(cleanId, new Set(module2.exports.map((entry) => entry.exported)));
|
|
9111
|
+
if (this.environment?.name === names.rsc) {
|
|
9112
|
+
return {
|
|
9113
|
+
code: registerServerReferences(code, moduleId, module2.exports, cleanId),
|
|
9114
|
+
map: { mappings: "" }
|
|
9115
|
+
};
|
|
9116
|
+
}
|
|
9117
|
+
if (this.environment?.consumer === "client" || this.environment?.name === names.client || this.environment?.name === names.ssr) {
|
|
9118
|
+
return {
|
|
9119
|
+
code: createServerReferenceProxy(moduleId, module2.exports),
|
|
9120
|
+
map: { mappings: "" }
|
|
9121
|
+
};
|
|
9122
|
+
}
|
|
9123
|
+
}
|
|
9124
|
+
return null;
|
|
9125
|
+
},
|
|
9126
|
+
afterBuildApp(results, _api, context) {
|
|
9127
|
+
if (options.manifestFile === false) return;
|
|
9128
|
+
const manifest = createManifest(
|
|
9129
|
+
names,
|
|
9130
|
+
resolvedConfig?.root ?? "",
|
|
9131
|
+
results,
|
|
9132
|
+
clientReferences,
|
|
9133
|
+
serverReferences
|
|
9134
|
+
);
|
|
9135
|
+
const output = {
|
|
9136
|
+
type: "asset",
|
|
9137
|
+
fileName: options.manifestFile ?? "rsc-manifest.json",
|
|
9138
|
+
source: JSON.stringify(manifest, null, 2) + "\n"
|
|
9139
|
+
};
|
|
9140
|
+
context.emitFile(output);
|
|
9141
|
+
}
|
|
9142
|
+
};
|
|
9143
|
+
}
|
|
9144
|
+
function scanModule(filename, code) {
|
|
9145
|
+
if (!code.includes("use client") && !code.includes("use server")) return null;
|
|
9146
|
+
const parsed = (0, import_oxc_parser.parseSync)(filename, code);
|
|
9147
|
+
if (parsed.errors.length > 0) return null;
|
|
9148
|
+
const directives = new Set(
|
|
9149
|
+
parsed.program.body.filter((node) => node.type === "ExpressionStatement" && typeof node.directive === "string").map((node) => node.directive)
|
|
9150
|
+
);
|
|
9151
|
+
const useClient = directives.has("use client");
|
|
9152
|
+
const useServer = directives.has("use server");
|
|
9153
|
+
if (!useClient && !useServer) return null;
|
|
9154
|
+
const exports2 = [];
|
|
9155
|
+
for (const statement of parsed.module.staticExports) {
|
|
9156
|
+
for (const entry of statement.entries) {
|
|
9157
|
+
if (entry.isType) continue;
|
|
9158
|
+
const exported = entry.exportName.kind === "Default" ? "default" : entry.exportName.name;
|
|
9159
|
+
if (!exported) {
|
|
9160
|
+
throw new Error(
|
|
9161
|
+
`[nasti:rsc] ${filename} uses export * inside an RSC directive module; replace it with explicit named exports so reference identities are stable`
|
|
9162
|
+
);
|
|
9163
|
+
}
|
|
9164
|
+
exports2.push({
|
|
9165
|
+
exported,
|
|
9166
|
+
local: entry.localName.kind === "Name" ? entry.localName.name ?? void 0 : void 0,
|
|
9167
|
+
reexported: entry.moduleRequest !== null
|
|
9168
|
+
});
|
|
9169
|
+
}
|
|
9170
|
+
}
|
|
9171
|
+
return { useClient, useServer, exports: dedupeExports(exports2) };
|
|
9172
|
+
}
|
|
9173
|
+
function createClientReferenceProxy(moduleId, exports2) {
|
|
9174
|
+
const lines = [
|
|
9175
|
+
`import { registerClientReference as __nasti_register_client__ } from ${JSON.stringify(SERVER_RUNTIME_ID)};`
|
|
9176
|
+
];
|
|
9177
|
+
exports2.forEach((entry, index2) => {
|
|
9178
|
+
const local = `__nasti_client_reference_${index2}__`;
|
|
9179
|
+
const message = `Cannot call client export ${moduleId}#${entry.exported} from the RSC server graph.`;
|
|
9180
|
+
lines.push(
|
|
9181
|
+
`const ${local} = __nasti_register_client__(function () { throw new Error(${JSON.stringify(message)}); }, ${JSON.stringify(moduleId)}, ${JSON.stringify(entry.exported)});`,
|
|
9182
|
+
exportLocal(local, entry.exported)
|
|
9183
|
+
);
|
|
9184
|
+
});
|
|
9185
|
+
return lines.join("\n") + "\n";
|
|
9186
|
+
}
|
|
9187
|
+
function registerServerReferences(code, moduleId, exports2, filename) {
|
|
9188
|
+
const registrations = [];
|
|
9189
|
+
for (const entry of exports2) {
|
|
9190
|
+
if (entry.reexported || !entry.local) {
|
|
9191
|
+
throw new Error(
|
|
9192
|
+
`[nasti:rsc] ${filename} must use named local bindings for "use server" exports; ${entry.exported} cannot be registered safely`
|
|
9193
|
+
);
|
|
9194
|
+
}
|
|
9195
|
+
registrations.push(
|
|
9196
|
+
`__nasti_register_server__(${entry.local}, ${JSON.stringify(moduleId)}, ${JSON.stringify(entry.exported)});`
|
|
9197
|
+
);
|
|
9198
|
+
}
|
|
9199
|
+
return [
|
|
9200
|
+
code,
|
|
9201
|
+
`import { registerServerReference as __nasti_register_server__ } from ${JSON.stringify(SERVER_RUNTIME_ID)};`,
|
|
9202
|
+
...registrations,
|
|
9203
|
+
""
|
|
9204
|
+
].join("\n");
|
|
9205
|
+
}
|
|
9206
|
+
function createServerReferenceProxy(moduleId, exports2) {
|
|
9207
|
+
const lines = [
|
|
9208
|
+
`import { createServerReference as __nasti_create_server__ } from ${JSON.stringify(CLIENT_RUNTIME_ID)};`
|
|
9209
|
+
];
|
|
9210
|
+
exports2.forEach((entry, index2) => {
|
|
9211
|
+
const local = `__nasti_server_reference_${index2}__`;
|
|
9212
|
+
lines.push(
|
|
9213
|
+
`const ${local} = __nasti_create_server__(${JSON.stringify(moduleId)}, ${JSON.stringify(entry.exported)});`,
|
|
9214
|
+
exportLocal(local, entry.exported)
|
|
9215
|
+
);
|
|
9216
|
+
});
|
|
9217
|
+
return lines.join("\n") + "\n";
|
|
9218
|
+
}
|
|
9219
|
+
function exportLocal(local, exported) {
|
|
9220
|
+
if (exported === "default") return `export default ${local};`;
|
|
9221
|
+
const name = /^[A-Za-z_$][\w$]*$/.test(exported) ? exported : JSON.stringify(exported);
|
|
9222
|
+
return `export { ${local} as ${name} };`;
|
|
9223
|
+
}
|
|
9224
|
+
function createServerRuntimeModule() {
|
|
9225
|
+
return [
|
|
9226
|
+
`export { registerClientReference, registerServerReference } from "react-server-dom-webpack/server.edge";`,
|
|
9227
|
+
""
|
|
9228
|
+
].join("\n");
|
|
9229
|
+
}
|
|
9230
|
+
function createClientRuntimeModule(browser) {
|
|
9231
|
+
const source = browser ? "react-server-dom-webpack/client.browser" : "react-server-dom-webpack/client.edge";
|
|
9232
|
+
return `
|
|
9233
|
+
import { createServerReference as __createServerReference } from ${JSON.stringify(source)};
|
|
9234
|
+
const __callServer = (id, args) => {
|
|
9235
|
+
const handler = globalThis[Symbol.for("nasti.rsc.callServer")];
|
|
9236
|
+
if (typeof handler !== "function") {
|
|
9237
|
+
throw new Error("No RSC callServer handler is installed. Set globalThis[Symbol.for('nasti.rsc.callServer')].");
|
|
9238
|
+
}
|
|
9239
|
+
return handler(id, args);
|
|
9240
|
+
};
|
|
9241
|
+
export function createServerReference(moduleId, name) {
|
|
9242
|
+
return __createServerReference(moduleId + "#" + name, __callServer, undefined, undefined, name);
|
|
9243
|
+
}
|
|
9244
|
+
`.trimStart();
|
|
9245
|
+
}
|
|
9246
|
+
function createManifest(names, root, results, clients, servers) {
|
|
9247
|
+
return {
|
|
9248
|
+
version: 1,
|
|
9249
|
+
environments: names,
|
|
9250
|
+
clientReferences: manifestReferences(root, results[names.client], clients),
|
|
9251
|
+
serverReferences: manifestReferences(root, results[names.rsc], servers)
|
|
9252
|
+
};
|
|
9253
|
+
}
|
|
9254
|
+
function manifestReferences(root, result, references) {
|
|
9255
|
+
const output = {};
|
|
9256
|
+
for (const [id, names] of [...references].sort(([a], [b]) => a.localeCompare(b))) {
|
|
9257
|
+
const chunks = Object.values(result?.chunks ?? {}).filter((chunk) => chunk.moduleIds.some((moduleId) => cleanModuleId(moduleId) === id)).map((chunk) => chunk.fileName).sort();
|
|
9258
|
+
for (const name of [...names].sort()) {
|
|
9259
|
+
const moduleId = referenceModuleId(root, id);
|
|
9260
|
+
output[`${moduleId}#${name}`] = { id: moduleId, name, chunks };
|
|
9261
|
+
}
|
|
9262
|
+
}
|
|
9263
|
+
return output;
|
|
9264
|
+
}
|
|
9265
|
+
function discoverDirectiveModules(root, scanDirectories, include, exclude) {
|
|
9266
|
+
const requested = scanDirectories ?? ["app", "src"];
|
|
9267
|
+
const roots = requested.map((directory) => import_node_path22.default.resolve(root, directory)).filter((directory) => import_node_fs17.default.existsSync(directory));
|
|
9268
|
+
if (roots.length === 0) roots.push(root);
|
|
9269
|
+
const output = [];
|
|
9270
|
+
for (const directory of roots) walk(directory);
|
|
9271
|
+
return output;
|
|
9272
|
+
function walk(directory) {
|
|
9273
|
+
for (const entry of import_node_fs17.default.readdirSync(directory, { withFileTypes: true })) {
|
|
9274
|
+
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".nasti") continue;
|
|
9275
|
+
const id = import_node_path22.default.join(directory, entry.name);
|
|
9276
|
+
if (entry.isDirectory()) {
|
|
9277
|
+
walk(id);
|
|
9278
|
+
continue;
|
|
9279
|
+
}
|
|
9280
|
+
if (!entry.isFile() || !matchesReactFilter(id, include, exclude)) continue;
|
|
9281
|
+
const module2 = scanModule(id, import_node_fs17.default.readFileSync(id, "utf-8"));
|
|
9282
|
+
if (module2) output.push({ id, module: module2 });
|
|
9283
|
+
}
|
|
9284
|
+
}
|
|
9285
|
+
}
|
|
9286
|
+
function collectClientSeeds(root, config, client, configured) {
|
|
9287
|
+
const explicit = [
|
|
9288
|
+
...normalizeEntries(client.entry),
|
|
9289
|
+
...normalizeEntries(configured)
|
|
9290
|
+
];
|
|
9291
|
+
if (explicit.length > 0) return explicit;
|
|
9292
|
+
const htmlFile = import_node_path22.default.resolve(root, client.html ?? "index.html");
|
|
9293
|
+
if (import_node_fs17.default.existsSync(htmlFile)) {
|
|
9294
|
+
const html = import_node_fs17.default.readFileSync(htmlFile, "utf-8");
|
|
9295
|
+
const htmlDir = import_node_path22.default.dirname(htmlFile);
|
|
9296
|
+
const entries = [...html.matchAll(/<script[^>]+src=["']([^"']+)["'][^>]*>/gi)].map((match) => match[1]?.split(/[?#]/, 1)[0]).filter((entry) => !!entry && !entry.startsWith("http")).map((entry) => entry.startsWith("/") ? import_node_path22.default.resolve(root, entry.slice(1)) : import_node_path22.default.resolve(htmlDir, entry));
|
|
9297
|
+
if (entries.length > 0) return entries;
|
|
9298
|
+
}
|
|
9299
|
+
for (const entry of ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"]) {
|
|
9300
|
+
if (import_node_fs17.default.existsSync(import_node_path22.default.resolve(root, entry))) return [entry];
|
|
9301
|
+
}
|
|
9302
|
+
return [];
|
|
9303
|
+
}
|
|
9304
|
+
function normalizeEntries(entries) {
|
|
9305
|
+
return entries == null ? [] : Array.isArray(entries) ? entries : [entries];
|
|
9306
|
+
}
|
|
9307
|
+
function uniqueEntries(entries) {
|
|
9308
|
+
return [...new Set(entries)];
|
|
9309
|
+
}
|
|
9310
|
+
function isSourceModule(id, config, options) {
|
|
9311
|
+
const cleanId = cleanModuleId(id);
|
|
9312
|
+
if (cleanId.startsWith("\0")) return false;
|
|
9313
|
+
const include = options.include ?? config.react.include;
|
|
9314
|
+
const exclude = options.exclude ?? config.react.exclude;
|
|
9315
|
+
return matchesReactFilter(cleanId, include, exclude);
|
|
9316
|
+
}
|
|
9317
|
+
function cleanModuleId(id) {
|
|
9318
|
+
return id.split(/[?#]/, 1)[0];
|
|
9319
|
+
}
|
|
9320
|
+
function referenceModuleId(root, id) {
|
|
9321
|
+
if (!root || !import_node_path22.default.isAbsolute(id)) return id.replaceAll(import_node_path22.default.sep, "/");
|
|
9322
|
+
const relative = import_node_path22.default.relative(root, id).replaceAll(import_node_path22.default.sep, "/");
|
|
9323
|
+
return relative.startsWith("../") ? id.replaceAll(import_node_path22.default.sep, "/") : `/${relative}`;
|
|
9324
|
+
}
|
|
9325
|
+
function displayId(root, id) {
|
|
9326
|
+
return referenceModuleId(root, id);
|
|
9327
|
+
}
|
|
9328
|
+
function dedupeExports(exports2) {
|
|
9329
|
+
return [...new Map(exports2.map((entry) => [entry.exported, entry])).values()];
|
|
9330
|
+
}
|
|
9331
|
+
|
|
7491
9332
|
// src/index.ts
|
|
7492
9333
|
init_environment();
|
|
7493
9334
|
init_hot_channel();
|
|
@@ -7516,6 +9357,7 @@ init_env();
|
|
|
7516
9357
|
printServerUrls,
|
|
7517
9358
|
resolveConfig,
|
|
7518
9359
|
resolveEnvironmentPlugins,
|
|
9360
|
+
rsc,
|
|
7519
9361
|
ssrDefineOverrides,
|
|
7520
9362
|
startElectronDev
|
|
7521
9363
|
});
|