vite-node 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.mts +21 -0
- package/dist/cli.mjs +145 -0
- package/dist/{client.js → client-CyS7w_FB.mjs} +54 -87
- package/dist/client.d.mts +2 -0
- package/dist/client.mjs +5 -0
- package/dist/{constants.js → constants-DRkacFwN.mjs} +3 -1
- package/dist/{constants.d.ts → constants.d.mts} +3 -2
- package/dist/constants.mjs +3 -0
- package/dist/dist-B2ebky9O.mjs +85 -0
- package/dist/{chunk-hmr.js → hmr-qEG3qSgW.mjs} +17 -29
- package/dist/hmr.d.mts +57 -0
- package/dist/hmr.mjs +5 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/{server.js → server-BWywEVuB.mjs} +52 -87
- package/dist/server.d.mts +60 -0
- package/dist/server.mjs +7 -0
- package/dist/source-map-DQLD3K8K.mjs +737 -0
- package/dist/{source-map.d.ts → source-map.d.mts} +9 -8
- package/dist/source-map.mjs +4 -0
- package/dist/types-55T_-8KG.mjs +1 -0
- package/dist/types-Dtew7m7O.d.mts +212 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/dist/{utils.js → utils-ExLpYVUV.mjs} +10 -18
- package/dist/{utils.d.ts → utils.d.mts} +7 -7
- package/dist/utils.mjs +3 -0
- package/package.json +25 -32
- package/dist/chunk-index.js +0 -82
- package/dist/cli.d.ts +0 -21
- package/dist/cli.js +0 -162
- package/dist/client.d.ts +0 -2
- package/dist/hmr.d.ts +0 -55
- package/dist/hmr.js +0 -10
- package/dist/index.d-D6Pqey3g.d.ts +0 -367
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/server.d.ts +0 -58
- package/dist/source-map.js +0 -919
- package/dist/trace-mapping.d-BWFx6tPc.d.ts +0 -62
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/vite-node.js +0 -2
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { b as ViteNodeServerOptions } from "./types-Dtew7m7O.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli.d.ts
|
|
4
|
+
interface CliOptions {
|
|
5
|
+
"root"?: string;
|
|
6
|
+
"script"?: boolean;
|
|
7
|
+
"config"?: string;
|
|
8
|
+
"mode"?: string;
|
|
9
|
+
"watch"?: boolean;
|
|
10
|
+
"inspect"?: boolean;
|
|
11
|
+
"inspectAddr"?: string;
|
|
12
|
+
"options"?: ViteNodeServerOptionsCLI;
|
|
13
|
+
"version"?: boolean;
|
|
14
|
+
"help"?: boolean;
|
|
15
|
+
"--"?: string[];
|
|
16
|
+
}
|
|
17
|
+
type Optional<T> = T | undefined;
|
|
18
|
+
type ComputeViteNodeServerOptionsCLI<T extends Record<string, any>> = { [K in keyof T]: T[K] extends Optional<RegExp[]> ? string | string[] : T[K] extends Optional<(string | RegExp)[]> ? string | string[] : T[K] extends Optional<(string | RegExp)[] | true> ? string | string[] | true : T[K] extends Optional<Record<string, any>> ? ComputeViteNodeServerOptionsCLI<T[K]> : T[K] };
|
|
19
|
+
type ViteNodeServerOptionsCLI = ComputeViteNodeServerOptionsCLI<ViteNodeServerOptions>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CliOptions, ViteNodeServerOptionsCLI };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as C } from "./dist-B2ebky9O.mjs";
|
|
3
|
+
import { t as ViteNodeServer } from "./server-BWywEVuB.mjs";
|
|
4
|
+
import "./constants-DRkacFwN.mjs";
|
|
5
|
+
import { h as toArray } from "./utils-ExLpYVUV.mjs";
|
|
6
|
+
import { n as installSourcemapsSupport } from "./source-map-DQLD3K8K.mjs";
|
|
7
|
+
import { r as ViteNodeRunner } from "./client-CyS7w_FB.mjs";
|
|
8
|
+
import { r as handleMessage, s as viteNodeHmrPlugin, t as createHotContext } from "./hmr-qEG3qSgW.mjs";
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
import { createServer, loadEnv, version } from "vite";
|
|
11
|
+
import { resolve } from "node:path";
|
|
12
|
+
import cac from "cac";
|
|
13
|
+
|
|
14
|
+
//#region package.json
|
|
15
|
+
var version$1 = "5.2.0";
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/cli.ts
|
|
19
|
+
const cli = cac("vite-node");
|
|
20
|
+
cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", "Restart on file changes, similar to \"nodemon\"").option("--inspect", "Enable Node.js inspector").option("--inspect-addr [host:port]", "Enable Node.js inspector with specified address").option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
|
|
21
|
+
cli.command("[...files]").allowUnknownOptions().action(run);
|
|
22
|
+
cli.parse(process.argv, { run: false });
|
|
23
|
+
if (cli.args.length === 0) cli.runMatchedCommand();
|
|
24
|
+
else {
|
|
25
|
+
const i = cli.rawArgs.indexOf(cli.args[0]) + 1;
|
|
26
|
+
const scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--");
|
|
27
|
+
const executeArgs = [
|
|
28
|
+
...cli.rawArgs.slice(0, i),
|
|
29
|
+
"--",
|
|
30
|
+
...scriptArgs
|
|
31
|
+
];
|
|
32
|
+
cli.parse(executeArgs);
|
|
33
|
+
}
|
|
34
|
+
async function run(files, options = {}) {
|
|
35
|
+
if (options.inspect || options.inspectAddr) {
|
|
36
|
+
const { open } = await import("node:inspector");
|
|
37
|
+
const [host, port] = options.inspectAddr?.split(":") || ["127.0.0.1", "9229"];
|
|
38
|
+
open(Number(port), host, false);
|
|
39
|
+
}
|
|
40
|
+
if (options.script) {
|
|
41
|
+
files = [files[0]];
|
|
42
|
+
options = {};
|
|
43
|
+
process.argv = [
|
|
44
|
+
process.argv[0],
|
|
45
|
+
resolve(files[0]),
|
|
46
|
+
...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
|
|
47
|
+
];
|
|
48
|
+
} else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
|
|
49
|
+
if (options.version) {
|
|
50
|
+
cli.version(version$1);
|
|
51
|
+
cli.outputVersion();
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
if (options.help) {
|
|
55
|
+
cli.version(version$1).outputHelp();
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
if (!files.length) {
|
|
59
|
+
console.error(C.red("No files specified."));
|
|
60
|
+
cli.version(version$1).outputHelp();
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const serverOptions = options.options ? parseServerOptions(options.options) : {};
|
|
64
|
+
const server = await createServer({
|
|
65
|
+
logLevel: "error",
|
|
66
|
+
configFile: options.config,
|
|
67
|
+
root: options.root,
|
|
68
|
+
mode: options.mode,
|
|
69
|
+
server: {
|
|
70
|
+
hmr: !!options.watch,
|
|
71
|
+
watch: options.watch ? void 0 : null
|
|
72
|
+
},
|
|
73
|
+
plugins: [options.watch && viteNodeHmrPlugin()]
|
|
74
|
+
});
|
|
75
|
+
if (Number(version.split(".")[0]) < 6) await server.pluginContainer.buildStart({});
|
|
76
|
+
else await server.environments.client.pluginContainer.buildStart({});
|
|
77
|
+
const env = loadEnv(server.config.mode, server.config.envDir, "");
|
|
78
|
+
for (const key in env) process.env[key] ??= env[key];
|
|
79
|
+
const node = new ViteNodeServer(server, serverOptions);
|
|
80
|
+
installSourcemapsSupport({ getSourceMap: (source) => node.getSourceMap(source) });
|
|
81
|
+
const runner = new ViteNodeRunner({
|
|
82
|
+
root: server.config.root,
|
|
83
|
+
base: server.config.base,
|
|
84
|
+
fetchModule(id) {
|
|
85
|
+
return node.fetchModule(id);
|
|
86
|
+
},
|
|
87
|
+
resolveId(id, importer) {
|
|
88
|
+
return node.resolveId(id, importer);
|
|
89
|
+
},
|
|
90
|
+
createHotContext(runner$1, url) {
|
|
91
|
+
return createHotContext(runner$1, server.emitter, files, url);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
await runner.executeId("/@vite/env");
|
|
95
|
+
for (const file of files) await runner.executeFile(file);
|
|
96
|
+
if (!options.watch) await server.close();
|
|
97
|
+
server.emitter?.on("message", (payload) => {
|
|
98
|
+
handleMessage(runner, server.emitter, files, payload);
|
|
99
|
+
});
|
|
100
|
+
if (options.watch) {
|
|
101
|
+
process.on("uncaughtException", (err) => {
|
|
102
|
+
console.error(C.red("[vite-node] Failed to execute file: \n"), err);
|
|
103
|
+
});
|
|
104
|
+
if (process.env.VITE_TEST_WATCHER_DEBUG) {
|
|
105
|
+
const nodePath = await import("node:path");
|
|
106
|
+
async function waitForWatched(files$1) {
|
|
107
|
+
while (!files$1.every((file) => isWatched(file))) await new Promise((resolve$1) => setTimeout(resolve$1, 20));
|
|
108
|
+
}
|
|
109
|
+
function isWatched(file) {
|
|
110
|
+
const watched = server.watcher.getWatched();
|
|
111
|
+
const resolved = nodePath.resolve(file);
|
|
112
|
+
const dir = nodePath.dirname(resolved);
|
|
113
|
+
const base = nodePath.basename(resolved);
|
|
114
|
+
return watched[dir]?.includes(base);
|
|
115
|
+
}
|
|
116
|
+
await waitForWatched(files);
|
|
117
|
+
console.log("[debug] watcher is ready");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function parseServerOptions(serverOptions) {
|
|
122
|
+
const inlineOptions = serverOptions.deps?.inline === true ? true : toArray(serverOptions.deps?.inline);
|
|
123
|
+
return {
|
|
124
|
+
...serverOptions,
|
|
125
|
+
deps: {
|
|
126
|
+
...serverOptions.deps,
|
|
127
|
+
inlineFiles: toArray(serverOptions.deps?.inlineFiles),
|
|
128
|
+
inline: inlineOptions !== true ? inlineOptions.map((dep) => {
|
|
129
|
+
return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
|
|
130
|
+
}) : true,
|
|
131
|
+
external: toArray(serverOptions.deps?.external).map((dep) => {
|
|
132
|
+
return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
|
|
133
|
+
}),
|
|
134
|
+
moduleDirectories: serverOptions.deps?.moduleDirectories ? toArray(serverOptions.deps?.moduleDirectories) : void 0
|
|
135
|
+
},
|
|
136
|
+
transformMode: {
|
|
137
|
+
...serverOptions.transformMode,
|
|
138
|
+
ssr: toArray(serverOptions.transformMode?.ssr).map((dep) => new RegExp(dep)),
|
|
139
|
+
web: toArray(serverOptions.transformMode?.web).map((dep) => new RegExp(dep))
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
export { };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import createDebug from
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import 'node:buffer';
|
|
10
|
-
import 'pathe';
|
|
11
|
-
import 'node:fs';
|
|
1
|
+
import { c as isNodeBuiltin, d as normalizeModuleId, f as normalizeRequestId, g as toFilePath, l as isPrimitive, m as slash, n as cleanUrl, o as isBareImport, r as createImportMetaEnvProxy, s as isInternalRequest } from "./utils-ExLpYVUV.mjs";
|
|
2
|
+
import { t as extractSourceMap } from "./source-map-DQLD3K8K.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { createDebug } from "obug";
|
|
7
|
+
import { dirname, resolve } from "node:path";
|
|
8
|
+
import vm from "node:vm";
|
|
12
9
|
|
|
10
|
+
//#region src/client.ts
|
|
13
11
|
const { setTimeout, clearTimeout } = globalThis;
|
|
14
12
|
const debugExecute = createDebug("vite-node:client:execute");
|
|
15
13
|
const debugNative = createDebug("vite-node:client:native");
|
|
@@ -34,7 +32,7 @@ const DEFAULT_REQUEST_STUBS = {
|
|
|
34
32
|
"/@vite/client": clientStub,
|
|
35
33
|
"@vite/client": clientStub
|
|
36
34
|
};
|
|
37
|
-
|
|
35
|
+
var ModuleCacheMap = class extends Map {
|
|
38
36
|
normalizePath(fsPath) {
|
|
39
37
|
return normalizeModuleId(fsPath);
|
|
40
38
|
}
|
|
@@ -72,13 +70,12 @@ class ModuleCacheMap extends Map {
|
|
|
72
70
|
return this.deleteByModuleId(this.normalizePath(fsPath));
|
|
73
71
|
}
|
|
74
72
|
invalidateModule(mod) {
|
|
75
|
-
var _mod$importers, _mod$imports;
|
|
76
73
|
delete mod.evaluated;
|
|
77
74
|
delete mod.resolving;
|
|
78
75
|
delete mod.promise;
|
|
79
76
|
delete mod.exports;
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
mod.importers?.clear();
|
|
78
|
+
mod.imports?.clear();
|
|
82
79
|
return true;
|
|
83
80
|
}
|
|
84
81
|
/**
|
|
@@ -90,7 +87,7 @@ class ModuleCacheMap extends Map {
|
|
|
90
87
|
if (invalidated.has(id)) continue;
|
|
91
88
|
invalidated.add(id);
|
|
92
89
|
const mod = super.get(id);
|
|
93
|
-
if (mod
|
|
90
|
+
if (mod?.importers) this.invalidateDepTree(mod.importers, invalidated);
|
|
94
91
|
super.delete(id);
|
|
95
92
|
}
|
|
96
93
|
return invalidated;
|
|
@@ -103,10 +100,7 @@ class ModuleCacheMap extends Map {
|
|
|
103
100
|
const id = this.normalizePath(_id);
|
|
104
101
|
if (invalidated.has(id)) continue;
|
|
105
102
|
invalidated.add(id);
|
|
106
|
-
const subIds = Array.from(super.entries()).filter(([, mod]) =>
|
|
107
|
-
var _mod$importers2;
|
|
108
|
-
return (_mod$importers2 = mod.importers) === null || _mod$importers2 === void 0 ? void 0 : _mod$importers2.has(id);
|
|
109
|
-
}).map(([key]) => key);
|
|
103
|
+
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
|
110
104
|
if (subIds.length) this.invalidateSubDepTree(subIds, invalidated);
|
|
111
105
|
super.delete(id);
|
|
112
106
|
}
|
|
@@ -125,8 +119,8 @@ class ModuleCacheMap extends Map {
|
|
|
125
119
|
}
|
|
126
120
|
return null;
|
|
127
121
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
122
|
+
};
|
|
123
|
+
var ViteNodeRunner = class {
|
|
130
124
|
root;
|
|
131
125
|
debug;
|
|
132
126
|
/**
|
|
@@ -151,7 +145,6 @@ class ViteNodeRunner {
|
|
|
151
145
|
* As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
|
|
152
146
|
*/
|
|
153
147
|
executionStack = [];
|
|
154
|
-
// `performance` can be mocked, so make sure we're using the original function
|
|
155
148
|
performanceNow = performance.now.bind(performance);
|
|
156
149
|
constructor(options) {
|
|
157
150
|
this.options = options;
|
|
@@ -174,14 +167,12 @@ class ViteNodeRunner {
|
|
|
174
167
|
const { imports, importers } = mod;
|
|
175
168
|
if (importee) importers.add(importee);
|
|
176
169
|
const getStack = () => `stack:\n${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
|
|
177
|
-
// check circular dependency
|
|
178
170
|
if (callstack.includes(fsPath) || Array.from(imports.values()).some((i) => importers.has(i))) {
|
|
179
171
|
if (mod.exports) return mod.exports;
|
|
180
172
|
}
|
|
181
173
|
let debugTimer;
|
|
182
174
|
if (this.debug) debugTimer = setTimeout(() => console.warn(`[vite-node] module ${fsPath} takes over 2s to load.\n${getStack()}`), 2e3);
|
|
183
175
|
try {
|
|
184
|
-
// cached module
|
|
185
176
|
if (mod.promise) return await mod.promise;
|
|
186
177
|
const promise = this.directRequest(id, fsPath, callstack);
|
|
187
178
|
Object.assign(mod, {
|
|
@@ -198,14 +189,12 @@ class ViteNodeRunner {
|
|
|
198
189
|
return !isInternalRequest(id) && !isNodeBuiltin(id) && !id.startsWith("data:");
|
|
199
190
|
}
|
|
200
191
|
async _resolveUrl(id, importer) {
|
|
201
|
-
var _resolved$meta;
|
|
202
192
|
const dep = normalizeRequestId(id, this.options.base);
|
|
203
193
|
if (!this.shouldResolveId(dep)) return [dep, dep];
|
|
204
|
-
const { path, exists } = toFilePath(dep, this.root);
|
|
205
|
-
if (!this.options.resolveId || exists) return [dep, path];
|
|
194
|
+
const { path: path$1, exists } = toFilePath(dep, this.root);
|
|
195
|
+
if (!this.options.resolveId || exists) return [dep, path$1];
|
|
206
196
|
const resolved = await this.options.resolveId(dep, importer);
|
|
207
|
-
|
|
208
|
-
if (resolved === null || resolved === void 0 || (_resolved$meta = resolved.meta) === null || _resolved$meta === void 0 || (_resolved$meta = _resolved$meta["vite:alias"]) === null || _resolved$meta === void 0 ? void 0 : _resolved$meta.noResolved) {
|
|
197
|
+
if (resolved?.meta?.["vite:alias"]?.noResolved) {
|
|
209
198
|
const error = /* @__PURE__ */ new Error(`Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
|
|
210
199
|
|
|
211
200
|
- If you rely on tsconfig.json's "paths" to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
|
|
@@ -228,7 +217,6 @@ class ViteNodeRunner {
|
|
|
228
217
|
}
|
|
229
218
|
async resolveUrl(id, importee) {
|
|
230
219
|
const resolveKey = `resolve:${id}`;
|
|
231
|
-
// put info about new import as soon as possible, so we can start tracking it
|
|
232
220
|
this.moduleCache.setByModuleId(resolveKey, { resolving: true });
|
|
233
221
|
try {
|
|
234
222
|
return await this._resolveUrl(id, importee);
|
|
@@ -244,8 +232,7 @@ class ViteNodeRunner {
|
|
|
244
232
|
try {
|
|
245
233
|
return await this.options.fetchModule(id);
|
|
246
234
|
} catch (cause) {
|
|
247
|
-
|
|
248
|
-
if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof (cause === null || cause === void 0 ? void 0 : cause.message) === "string" && cause.message.includes("Failed to load url")) {
|
|
235
|
+
if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url")) {
|
|
249
236
|
const error = new Error(`Cannot find ${isBareImport(id) ? "package" : "module"} '${id}'${importer ? ` imported from '${importer}'` : ""}`, { cause });
|
|
250
237
|
error.code = "ERR_MODULE_NOT_FOUND";
|
|
251
238
|
throw error;
|
|
@@ -259,24 +246,23 @@ class ViteNodeRunner {
|
|
|
259
246
|
const callstack = [..._callstack, moduleId];
|
|
260
247
|
const mod = this.moduleCache.getByModuleId(moduleId);
|
|
261
248
|
const request = async (dep) => {
|
|
262
|
-
const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
|
|
249
|
+
const [id$1, depFsPath] = await this.resolveUrl(String(dep), fsPath);
|
|
263
250
|
this.moduleCache.getByModuleId(depFsPath).importers.add(moduleId);
|
|
264
251
|
mod.imports.add(depFsPath);
|
|
265
|
-
return this.dependencyRequest(id, depFsPath, callstack);
|
|
252
|
+
return this.dependencyRequest(id$1, depFsPath, callstack);
|
|
266
253
|
};
|
|
267
254
|
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
268
255
|
if (id in requestStubs) return requestStubs[id];
|
|
269
256
|
let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
|
|
270
257
|
if (externalize) {
|
|
271
258
|
debugNative(externalize);
|
|
272
|
-
const exports = await this.interopedImport(externalize);
|
|
273
|
-
mod.exports = exports;
|
|
274
|
-
return exports;
|
|
259
|
+
const exports$1 = await this.interopedImport(externalize);
|
|
260
|
+
mod.exports = exports$1;
|
|
261
|
+
return exports$1;
|
|
275
262
|
}
|
|
276
263
|
if (transformed == null) throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
|
|
277
|
-
const { Object, Reflect, Symbol } = this.getContextPrimitives();
|
|
264
|
+
const { Object: Object$1, Reflect: Reflect$1, Symbol: Symbol$1 } = this.getContextPrimitives();
|
|
278
265
|
const modulePath = cleanUrl(moduleId);
|
|
279
|
-
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
|
|
280
266
|
const href = pathToFileURL(modulePath).href;
|
|
281
267
|
const __filename = fileURLToPath(href);
|
|
282
268
|
const __dirname = dirname(__filename);
|
|
@@ -286,33 +272,27 @@ class ViteNodeRunner {
|
|
|
286
272
|
filename: __filename,
|
|
287
273
|
dirname: __dirname
|
|
288
274
|
};
|
|
289
|
-
const exports = Object.create(null);
|
|
290
|
-
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
275
|
+
const exports = Object$1.create(null);
|
|
276
|
+
Object$1.defineProperty(exports, Symbol$1.toStringTag, {
|
|
291
277
|
value: "Module",
|
|
292
278
|
enumerable: false,
|
|
293
279
|
configurable: false
|
|
294
280
|
});
|
|
295
|
-
const SYMBOL_NOT_DEFINED = Symbol("not defined");
|
|
281
|
+
const SYMBOL_NOT_DEFINED = Symbol$1("not defined");
|
|
296
282
|
let moduleExports = SYMBOL_NOT_DEFINED;
|
|
297
|
-
// this proxy is triggered only on exports.{name} and module.exports access
|
|
298
|
-
// inside the module itself. imported module is always "exports"
|
|
299
283
|
const cjsExports = new Proxy(exports, {
|
|
300
284
|
get: (target, p, receiver) => {
|
|
301
|
-
if (Reflect.has(target, p)) return Reflect.get(target, p, receiver);
|
|
302
|
-
return Reflect.get(Object.prototype, p, receiver);
|
|
285
|
+
if (Reflect$1.has(target, p)) return Reflect$1.get(target, p, receiver);
|
|
286
|
+
return Reflect$1.get(Object$1.prototype, p, receiver);
|
|
303
287
|
},
|
|
304
|
-
getPrototypeOf: () => Object.prototype,
|
|
288
|
+
getPrototypeOf: () => Object$1.prototype,
|
|
305
289
|
set: (_, p, value) => {
|
|
306
|
-
// treat "module.exports =" the same as "exports.default =" to not have nested "default.default",
|
|
307
|
-
// so "exports.default" becomes the actual module
|
|
308
290
|
if (p === "default" && this.shouldInterop(modulePath, { default: value }) && cjsExports !== value) {
|
|
309
291
|
exportAll(cjsExports, value);
|
|
310
292
|
exports.default = value;
|
|
311
293
|
return true;
|
|
312
294
|
}
|
|
313
|
-
if (!Reflect.has(exports, "default")) exports.default = {};
|
|
314
|
-
// returns undefined, when accessing named exports, if default is not an object
|
|
315
|
-
// but is still present inside hasOwnKeys, this is Node behaviour for CJS
|
|
295
|
+
if (!Reflect$1.has(exports, "default")) exports.default = {};
|
|
316
296
|
if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {
|
|
317
297
|
defineExport(exports, p, () => void 0);
|
|
318
298
|
return true;
|
|
@@ -322,7 +302,7 @@ class ViteNodeRunner {
|
|
|
322
302
|
return true;
|
|
323
303
|
}
|
|
324
304
|
});
|
|
325
|
-
Object.assign(mod, {
|
|
305
|
+
Object$1.assign(mod, {
|
|
326
306
|
code: transformed,
|
|
327
307
|
exports
|
|
328
308
|
});
|
|
@@ -336,29 +316,23 @@ class ViteNodeRunner {
|
|
|
336
316
|
return cjsExports;
|
|
337
317
|
}
|
|
338
318
|
};
|
|
339
|
-
// Vite hot context
|
|
340
319
|
let hotContext;
|
|
341
|
-
if (this.options.createHotContext) Object.defineProperty(meta, "hot", {
|
|
320
|
+
if (this.options.createHotContext) Object$1.defineProperty(meta, "hot", {
|
|
342
321
|
enumerable: true,
|
|
343
322
|
get: () => {
|
|
344
|
-
|
|
345
|
-
hotContext || (hotContext = (_this$options$createH = (_this$options = this.options).createHotContext) === null || _this$options$createH === void 0 ? void 0 : _this$options$createH.call(_this$options, this, moduleId));
|
|
323
|
+
hotContext ||= this.options.createHotContext?.(this, moduleId);
|
|
346
324
|
return hotContext;
|
|
347
325
|
},
|
|
348
326
|
set: (value) => {
|
|
349
327
|
hotContext = value;
|
|
350
328
|
}
|
|
351
329
|
});
|
|
352
|
-
// Be careful when changing this
|
|
353
|
-
// changing context will change amount of code added on line :114 (vm.runInThisContext)
|
|
354
|
-
// this messes up sourcemaps for coverage
|
|
355
|
-
// adjust `WRAPPER_LENGTH` variable in packages/coverage-v8/src/provider.ts if you do change this
|
|
356
330
|
const context = this.prepareContext({
|
|
357
331
|
__vite_ssr_import__: request,
|
|
358
332
|
__vite_ssr_dynamic_import__: request,
|
|
359
333
|
__vite_ssr_exports__: exports,
|
|
360
334
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
361
|
-
__vite_ssr_exportName__: (name, getter) => Object.defineProperty(exports, name, {
|
|
335
|
+
__vite_ssr_exportName__: (name, getter) => Object$1.defineProperty(exports, name, {
|
|
362
336
|
enumerable: true,
|
|
363
337
|
configurable: true,
|
|
364
338
|
get: getter
|
|
@@ -371,7 +345,6 @@ class ViteNodeRunner {
|
|
|
371
345
|
__dirname
|
|
372
346
|
});
|
|
373
347
|
debugExecute(__filename);
|
|
374
|
-
// remove shebang
|
|
375
348
|
if (transformed[0] === "#") transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
|
|
376
349
|
await this.runModule(context, transformed);
|
|
377
350
|
return exports;
|
|
@@ -384,7 +357,6 @@ class ViteNodeRunner {
|
|
|
384
357
|
};
|
|
385
358
|
}
|
|
386
359
|
async runModule(context, transformed) {
|
|
387
|
-
// add 'use strict' since ESM enables it by default
|
|
388
360
|
const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
|
|
389
361
|
const code = `${codeDefinition}${transformed}\n}}`;
|
|
390
362
|
const options = {
|
|
@@ -396,8 +368,7 @@ class ViteNodeRunner {
|
|
|
396
368
|
try {
|
|
397
369
|
await vm.runInThisContext(code, options)(...Object.values(context));
|
|
398
370
|
} finally {
|
|
399
|
-
|
|
400
|
-
(_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
|
|
371
|
+
this.options.moduleExecutionInfo?.set(options.filename, finishModuleExecutionInfo());
|
|
401
372
|
}
|
|
402
373
|
}
|
|
403
374
|
/**
|
|
@@ -431,36 +402,34 @@ class ViteNodeRunner {
|
|
|
431
402
|
* Define if a module should be interop-ed
|
|
432
403
|
* This function mostly for the ability to override by subclass
|
|
433
404
|
*/
|
|
434
|
-
shouldInterop(path, mod) {
|
|
405
|
+
shouldInterop(path$1, mod) {
|
|
435
406
|
if (this.options.interopDefault === false) return false;
|
|
436
|
-
|
|
437
|
-
// TODO: should also skip for `.js` with `type="module"`
|
|
438
|
-
return !path.endsWith(".mjs") && "default" in mod;
|
|
407
|
+
return !path$1.endsWith(".mjs") && "default" in mod;
|
|
439
408
|
}
|
|
440
|
-
importExternalModule(path) {
|
|
409
|
+
importExternalModule(path$1) {
|
|
441
410
|
return import(
|
|
442
411
|
/* @vite-ignore */
|
|
443
|
-
path
|
|
412
|
+
path$1
|
|
444
413
|
);
|
|
445
414
|
}
|
|
446
415
|
/**
|
|
447
416
|
* Import a module and interop it
|
|
448
417
|
*/
|
|
449
|
-
async interopedImport(path) {
|
|
450
|
-
const importedModule = await this.importExternalModule(path);
|
|
451
|
-
if (!this.shouldInterop(path, importedModule)) return importedModule;
|
|
418
|
+
async interopedImport(path$1) {
|
|
419
|
+
const importedModule = await this.importExternalModule(path$1);
|
|
420
|
+
if (!this.shouldInterop(path$1, importedModule)) return importedModule;
|
|
452
421
|
const { mod, defaultExport } = interopModule(importedModule);
|
|
453
422
|
return new Proxy(mod, {
|
|
454
|
-
get(mod, prop) {
|
|
423
|
+
get(mod$1, prop) {
|
|
455
424
|
if (prop === "default") return defaultExport;
|
|
456
|
-
return mod[prop] ??
|
|
425
|
+
return mod$1[prop] ?? defaultExport?.[prop];
|
|
457
426
|
},
|
|
458
|
-
has(mod, prop) {
|
|
427
|
+
has(mod$1, prop) {
|
|
459
428
|
if (prop === "default") return defaultExport !== void 0;
|
|
460
|
-
return prop in mod || defaultExport && prop in defaultExport;
|
|
429
|
+
return prop in mod$1 || defaultExport && prop in defaultExport;
|
|
461
430
|
},
|
|
462
|
-
getOwnPropertyDescriptor(mod, prop) {
|
|
463
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
|
|
431
|
+
getOwnPropertyDescriptor(mod$1, prop) {
|
|
432
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(mod$1, prop);
|
|
464
433
|
if (descriptor) return descriptor;
|
|
465
434
|
if (prop === "default" && defaultExport !== void 0) return {
|
|
466
435
|
value: defaultExport,
|
|
@@ -470,7 +439,7 @@ class ViteNodeRunner {
|
|
|
470
439
|
}
|
|
471
440
|
});
|
|
472
441
|
}
|
|
473
|
-
}
|
|
442
|
+
};
|
|
474
443
|
function interopModule(mod) {
|
|
475
444
|
if (isPrimitive(mod)) return {
|
|
476
445
|
mod: { default: mod },
|
|
@@ -486,7 +455,6 @@ function interopModule(mod) {
|
|
|
486
455
|
defaultExport
|
|
487
456
|
};
|
|
488
457
|
}
|
|
489
|
-
// keep consistency with Vite on how exports are defined
|
|
490
458
|
function defineExport(exports, key, value) {
|
|
491
459
|
Object.defineProperty(exports, key, {
|
|
492
460
|
enumerable: true,
|
|
@@ -495,8 +463,6 @@ function defineExport(exports, key, value) {
|
|
|
495
463
|
});
|
|
496
464
|
}
|
|
497
465
|
function exportAll(exports, sourceModule) {
|
|
498
|
-
// #1120 when a module exports itself it causes
|
|
499
|
-
// call stack error
|
|
500
466
|
if (exports === sourceModule) return;
|
|
501
467
|
if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
|
|
502
468
|
for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
|
|
@@ -504,4 +470,5 @@ function exportAll(exports, sourceModule) {
|
|
|
504
470
|
} catch {}
|
|
505
471
|
}
|
|
506
472
|
|
|
507
|
-
|
|
473
|
+
//#endregion
|
|
474
|
+
export { ModuleCacheMap as n, ViteNodeRunner as r, DEFAULT_REQUEST_STUBS as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as ModuleExecutionInfo, S as ModuleCacheMap, T as ViteNodeRunner, w as ModuleExecutionInfoEntry, x as DEFAULT_REQUEST_STUBS } from "./types-Dtew7m7O.mjs";
|
|
2
|
+
export { DEFAULT_REQUEST_STUBS, ModuleCacheMap, ModuleExecutionInfo, ModuleExecutionInfoEntry, ViteNodeRunner };
|
package/dist/client.mjs
ADDED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
1
2
|
const KNOWN_ASSET_TYPES = [
|
|
2
3
|
"apng",
|
|
3
4
|
"bmp",
|
|
@@ -29,4 +30,5 @@ const KNOWN_ASSET_TYPES = [
|
|
|
29
30
|
const KNOWN_ASSET_RE = /* @__PURE__ */ new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
|
|
30
31
|
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
export { KNOWN_ASSET_RE as n, KNOWN_ASSET_TYPES as r, CSS_LANGS_RE as t };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
1
2
|
declare const KNOWN_ASSET_TYPES: string[];
|
|
2
3
|
declare const KNOWN_ASSET_RE: RegExp;
|
|
3
4
|
declare const CSS_LANGS_RE: RegExp;
|
|
4
|
-
|
|
5
|
-
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES };
|
|
5
|
+
//#endregion
|
|
6
|
+
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.js
|
|
2
|
+
var d = {
|
|
3
|
+
reset: [0, 0],
|
|
4
|
+
bold: [
|
|
5
|
+
1,
|
|
6
|
+
22,
|
|
7
|
+
"\x1B[22m\x1B[1m"
|
|
8
|
+
],
|
|
9
|
+
dim: [
|
|
10
|
+
2,
|
|
11
|
+
22,
|
|
12
|
+
"\x1B[22m\x1B[2m"
|
|
13
|
+
],
|
|
14
|
+
italic: [3, 23],
|
|
15
|
+
underline: [4, 24],
|
|
16
|
+
inverse: [7, 27],
|
|
17
|
+
hidden: [8, 28],
|
|
18
|
+
strikethrough: [9, 29],
|
|
19
|
+
black: [30, 39],
|
|
20
|
+
red: [31, 39],
|
|
21
|
+
green: [32, 39],
|
|
22
|
+
yellow: [33, 39],
|
|
23
|
+
blue: [34, 39],
|
|
24
|
+
magenta: [35, 39],
|
|
25
|
+
cyan: [36, 39],
|
|
26
|
+
white: [37, 39],
|
|
27
|
+
gray: [90, 39],
|
|
28
|
+
bgBlack: [40, 49],
|
|
29
|
+
bgRed: [41, 49],
|
|
30
|
+
bgGreen: [42, 49],
|
|
31
|
+
bgYellow: [43, 49],
|
|
32
|
+
bgBlue: [44, 49],
|
|
33
|
+
bgMagenta: [45, 49],
|
|
34
|
+
bgCyan: [46, 49],
|
|
35
|
+
bgWhite: [47, 49],
|
|
36
|
+
blackBright: [90, 39],
|
|
37
|
+
redBright: [91, 39],
|
|
38
|
+
greenBright: [92, 39],
|
|
39
|
+
yellowBright: [93, 39],
|
|
40
|
+
blueBright: [94, 39],
|
|
41
|
+
magentaBright: [95, 39],
|
|
42
|
+
cyanBright: [96, 39],
|
|
43
|
+
whiteBright: [97, 39],
|
|
44
|
+
bgBlackBright: [100, 49],
|
|
45
|
+
bgRedBright: [101, 49],
|
|
46
|
+
bgGreenBright: [102, 49],
|
|
47
|
+
bgYellowBright: [103, 49],
|
|
48
|
+
bgBlueBright: [104, 49],
|
|
49
|
+
bgMagentaBright: [105, 49],
|
|
50
|
+
bgCyanBright: [106, 49],
|
|
51
|
+
bgWhiteBright: [107, 49]
|
|
52
|
+
};
|
|
53
|
+
function g(e) {
|
|
54
|
+
return String(e);
|
|
55
|
+
}
|
|
56
|
+
g.open = "";
|
|
57
|
+
g.close = "";
|
|
58
|
+
function h() {
|
|
59
|
+
let e = typeof process != "undefined" ? process : void 0, n = (e == null ? void 0 : e.env) || {}, a = n.FORCE_TTY !== "false", i = (e == null ? void 0 : e.argv) || [];
|
|
60
|
+
return !("NO_COLOR" in n || i.includes("--no-color")) && ("FORCE_COLOR" in n || i.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || a && n.TERM !== "dumb" || "CI" in n) || typeof window != "undefined" && !!window.chrome;
|
|
61
|
+
}
|
|
62
|
+
function f() {
|
|
63
|
+
let e = h(), n = (r, t, u, o) => {
|
|
64
|
+
let l = "", s = 0;
|
|
65
|
+
do
|
|
66
|
+
l += r.substring(s, o) + u, s = o + t.length, o = r.indexOf(t, s);
|
|
67
|
+
while (~o);
|
|
68
|
+
return l + r.substring(s);
|
|
69
|
+
}, a = (r, t, u = r) => {
|
|
70
|
+
let o = (l) => {
|
|
71
|
+
let s = String(l), b = s.indexOf(t, r.length);
|
|
72
|
+
return ~b ? r + n(s, t, u, b) + t : r + s + t;
|
|
73
|
+
};
|
|
74
|
+
return o.open = r, o.close = t, o;
|
|
75
|
+
}, i = { isColorSupported: e }, c = (r) => `\x1B[${r}m`;
|
|
76
|
+
for (let r in d) {
|
|
77
|
+
let t = d[r];
|
|
78
|
+
i[r] = e ? a(c(t[0]), c(t[1]), t[2]) : g;
|
|
79
|
+
}
|
|
80
|
+
return i;
|
|
81
|
+
}
|
|
82
|
+
var C = f();
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
export { C as t };
|