vite-node 5.0.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 -19
- package/dist/cli.js +0 -156
- 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
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { t as C } from "./dist-B2ebky9O.mjs";
|
|
2
|
+
import { f as normalizeRequestId } from "./utils-ExLpYVUV.mjs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { createDebug } from "obug";
|
|
5
|
+
import { EventEmitter } from "node:events";
|
|
6
6
|
|
|
7
|
+
//#region src/hmr/emitter.ts
|
|
7
8
|
function createHmrEmitter() {
|
|
8
9
|
return new EventEmitter();
|
|
9
10
|
}
|
|
@@ -12,7 +13,6 @@ function viteNodeHmrPlugin() {
|
|
|
12
13
|
return {
|
|
13
14
|
name: "vite-node:hmr",
|
|
14
15
|
config() {
|
|
15
|
-
// chokidar fsevents is unstable on macos when emitting "ready" event
|
|
16
16
|
if (process.platform === "darwin" && process.env.VITE_TEST_WATCHER_DEBUG) return { server: { watch: {
|
|
17
17
|
useFsEvents: false,
|
|
18
18
|
usePolling: false
|
|
@@ -25,8 +25,6 @@ function viteNodeHmrPlugin() {
|
|
|
25
25
|
_send(payload);
|
|
26
26
|
emitter.emit("message", payload);
|
|
27
27
|
};
|
|
28
|
-
// eslint-disable-next-line ts/ban-ts-comment
|
|
29
|
-
// @ts-ignore Vite 6 compat
|
|
30
28
|
const environments = server.environments;
|
|
31
29
|
if (environments) environments.ssr.hot.send = function(payload) {
|
|
32
30
|
_send(payload);
|
|
@@ -36,6 +34,8 @@ function viteNodeHmrPlugin() {
|
|
|
36
34
|
};
|
|
37
35
|
}
|
|
38
36
|
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/hmr/hmr.ts
|
|
39
39
|
const debugHmr = createDebug("vite-node:hmr");
|
|
40
40
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
41
41
|
function getCache(runner) {
|
|
@@ -59,7 +59,6 @@ function sendMessageBuffer(runner, emitter) {
|
|
|
59
59
|
maps.messageBuffer.length = 0;
|
|
60
60
|
}
|
|
61
61
|
async function reload(runner, files) {
|
|
62
|
-
// invalidate module cache but not node_modules
|
|
63
62
|
Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
|
|
64
63
|
if (!fsPath.includes("node_modules")) runner.moduleCache.delete(fsPath);
|
|
65
64
|
});
|
|
@@ -86,14 +85,9 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
|
|
|
86
85
|
acceptedPath = normalizeRequestId(acceptedPath);
|
|
87
86
|
const maps = getCache(runner);
|
|
88
87
|
const mod = maps.hotModulesMap.get(path);
|
|
89
|
-
if (!mod)
|
|
90
|
-
// In a code-splitting project,
|
|
91
|
-
// it is common that the hot-updating module is not loaded yet.
|
|
92
|
-
// https://github.com/vitejs/vite/issues/721
|
|
93
|
-
return;
|
|
88
|
+
if (!mod) return;
|
|
94
89
|
const isSelfUpdate = path === acceptedPath;
|
|
95
90
|
let fetchedModule;
|
|
96
|
-
// determine the qualified callbacks before we re-import the modules
|
|
97
91
|
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
|
98
92
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
|
99
93
|
const disposer = maps.disposeMap.get(acceptedPath);
|
|
@@ -124,7 +118,6 @@ async function handleMessage(runner, emitter, files, payload) {
|
|
|
124
118
|
await notifyListeners(runner, "vite:beforeUpdate", payload);
|
|
125
119
|
await Promise.all(payload.updates.map((update) => {
|
|
126
120
|
if (update.type === "js-update") return queueUpdate(runner, fetchUpdate(runner, update));
|
|
127
|
-
// css-update
|
|
128
121
|
console.error(`${C.cyan("[vite-node]")} no support css hmr.}`);
|
|
129
122
|
return null;
|
|
130
123
|
}));
|
|
@@ -157,37 +150,31 @@ function createHotContext(runner, emitter, files, ownerPath) {
|
|
|
157
150
|
debugHmr("createHotContext", ownerPath);
|
|
158
151
|
const maps = getCache(runner);
|
|
159
152
|
if (!maps.dataMap.has(ownerPath)) maps.dataMap.set(ownerPath, {});
|
|
160
|
-
// when a file is hot updated, a new context is created
|
|
161
|
-
// clear its stale callbacks
|
|
162
153
|
const mod = maps.hotModulesMap.get(ownerPath);
|
|
163
154
|
if (mod) mod.callbacks = [];
|
|
164
155
|
const newListeners = /* @__PURE__ */ new Map();
|
|
165
156
|
maps.ctxToListenersMap.set(ownerPath, newListeners);
|
|
166
157
|
function acceptDeps(deps, callback = () => {}) {
|
|
167
|
-
const mod = maps.hotModulesMap.get(ownerPath) || {
|
|
158
|
+
const mod$1 = maps.hotModulesMap.get(ownerPath) || {
|
|
168
159
|
id: ownerPath,
|
|
169
160
|
callbacks: []
|
|
170
161
|
};
|
|
171
|
-
mod.callbacks.push({
|
|
162
|
+
mod$1.callbacks.push({
|
|
172
163
|
deps,
|
|
173
164
|
fn: callback
|
|
174
165
|
});
|
|
175
|
-
maps.hotModulesMap.set(ownerPath, mod);
|
|
166
|
+
maps.hotModulesMap.set(ownerPath, mod$1);
|
|
176
167
|
}
|
|
177
168
|
return {
|
|
178
169
|
get data() {
|
|
179
170
|
return maps.dataMap.get(ownerPath);
|
|
180
171
|
},
|
|
181
172
|
acceptExports(_, callback) {
|
|
182
|
-
acceptDeps([ownerPath], callback && (([mod]) => callback(mod)));
|
|
173
|
+
acceptDeps([ownerPath], callback && (([mod$1]) => callback(mod$1)));
|
|
183
174
|
},
|
|
184
175
|
accept(deps, callback) {
|
|
185
|
-
if (typeof deps === "function" || !deps)
|
|
186
|
-
|
|
187
|
-
acceptDeps([ownerPath], ([mod]) => deps && deps(mod));
|
|
188
|
-
else if (typeof deps === "string")
|
|
189
|
-
// explicit deps
|
|
190
|
-
acceptDeps([deps], ([mod]) => callback && callback(mod));
|
|
176
|
+
if (typeof deps === "function" || !deps) acceptDeps([ownerPath], ([mod$1]) => deps && deps(mod$1));
|
|
177
|
+
else if (typeof deps === "string") acceptDeps([deps], ([mod$1]) => callback && callback(mod$1));
|
|
191
178
|
else if (Array.isArray(deps)) acceptDeps(deps, callback);
|
|
192
179
|
else throw new TypeError("invalid hot.accept() usage.");
|
|
193
180
|
},
|
|
@@ -239,4 +226,5 @@ function createHotContext(runner, emitter, files, ownerPath) {
|
|
|
239
226
|
};
|
|
240
227
|
}
|
|
241
228
|
|
|
242
|
-
|
|
229
|
+
//#endregion
|
|
230
|
+
export { sendMessageBuffer as a, reload as i, getCache as n, createHmrEmitter as o, handleMessage as r, viteNodeHmrPlugin as s, createHotContext as t };
|
package/dist/hmr.d.mts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { T as ViteNodeRunner, u as HotContext } from "./types-Dtew7m7O.mjs";
|
|
2
|
+
import { HMRPayload, Plugin } from "vite";
|
|
3
|
+
import { EventEmitter } from "node:events";
|
|
4
|
+
import { CustomEventMap } from "vite/types/customEvent.js";
|
|
5
|
+
import { HMRPayload as HMRPayload$1 } from "vite/types/hmrPayload.js";
|
|
6
|
+
|
|
7
|
+
//#region src/hmr/emitter.d.ts
|
|
8
|
+
type EventType = string | symbol;
|
|
9
|
+
type Handler<T = unknown> = (event: T) => void;
|
|
10
|
+
interface Emitter<Events extends Record<EventType, unknown>> {
|
|
11
|
+
on: <Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>) => void;
|
|
12
|
+
off: <Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>) => void;
|
|
13
|
+
emit: (<Key extends keyof Events>(type: Key, event: Events[Key]) => void) & (<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never) => void);
|
|
14
|
+
}
|
|
15
|
+
type HMREmitter = Emitter<{
|
|
16
|
+
message: HMRPayload;
|
|
17
|
+
}> & EventEmitter;
|
|
18
|
+
declare module "vite" {
|
|
19
|
+
interface ViteDevServer {
|
|
20
|
+
emitter: HMREmitter;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
declare function createHmrEmitter(): HMREmitter;
|
|
24
|
+
declare function viteNodeHmrPlugin(): Plugin;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/hmr/hmr.d.ts
|
|
27
|
+
type ModuleNamespace = Record<string, any> & {
|
|
28
|
+
[Symbol.toStringTag]: "Module";
|
|
29
|
+
};
|
|
30
|
+
type InferCustomEventPayload<T extends string> = T extends keyof CustomEventMap ? CustomEventMap[T] : any;
|
|
31
|
+
interface HotModule {
|
|
32
|
+
id: string;
|
|
33
|
+
callbacks: HotCallback[];
|
|
34
|
+
}
|
|
35
|
+
interface HotCallback {
|
|
36
|
+
deps: string[];
|
|
37
|
+
fn: (modules: (ModuleNamespace | undefined)[]) => void;
|
|
38
|
+
}
|
|
39
|
+
interface CacheData {
|
|
40
|
+
hotModulesMap: Map<string, HotModule>;
|
|
41
|
+
dataMap: Map<string, any>;
|
|
42
|
+
disposeMap: Map<string, (data: any) => void | Promise<void>>;
|
|
43
|
+
pruneMap: Map<string, (data: any) => void | Promise<void>>;
|
|
44
|
+
customListenersMap: Map<string, ((data: any) => void)[]>;
|
|
45
|
+
ctxToListenersMap: Map<string, Map<string, ((data: any) => void)[]>>;
|
|
46
|
+
messageBuffer: string[];
|
|
47
|
+
isFirstUpdate: boolean;
|
|
48
|
+
pending: boolean;
|
|
49
|
+
queued: Promise<(() => void) | undefined>[];
|
|
50
|
+
}
|
|
51
|
+
declare function getCache(runner: ViteNodeRunner): CacheData;
|
|
52
|
+
declare function sendMessageBuffer(runner: ViteNodeRunner, emitter: HMREmitter): void;
|
|
53
|
+
declare function reload(runner: ViteNodeRunner, files: string[]): Promise<any[]>;
|
|
54
|
+
declare function handleMessage(runner: ViteNodeRunner, emitter: HMREmitter, files: string[], payload: HMRPayload$1): Promise<void>;
|
|
55
|
+
declare function createHotContext(runner: ViteNodeRunner, emitter: HMREmitter, files: string[], ownerPath: string): HotContext;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Emitter, EventType, HMREmitter, Handler, HotCallback, HotModule, InferCustomEventPayload, ModuleNamespace, createHmrEmitter, createHotContext, getCache, handleMessage, reload, sendMessageBuffer, viteNodeHmrPlugin };
|
package/dist/hmr.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "./dist-B2ebky9O.mjs";
|
|
2
|
+
import "./utils-ExLpYVUV.mjs";
|
|
3
|
+
import { a as sendMessageBuffer, i as reload, n as getCache, o as createHmrEmitter, r as handleMessage, s as viteNodeHmrPlugin, t as createHotContext } from "./hmr-qEG3qSgW.mjs";
|
|
4
|
+
|
|
5
|
+
export { createHmrEmitter, createHotContext, getCache, handleMessage, reload, sendMessageBuffer, viteNodeHmrPlugin };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as ModuleExecutionInfo, S as ModuleCacheMap, _ as ViteNodeResolveId, a as DecodedSourceMap, b as ViteNodeServerOptions, c as FetchFunction, d as ModuleCache, f as Nullable, g as StartOfSourceMap, h as SourceMapInput, i as DebuggerOptions, l as FetchResult, m as ResolveIdFunction, n as Awaitable, o as DepsHandlingOptions, p as RawSourceMap, r as CreateHotContextFunction, s as EncodedSourceMap, t as Arrayable, u as HotContext, v as ViteNodeResolveModule, y as ViteNodeRunnerOptions } from "./types-Dtew7m7O.mjs";
|
|
2
|
+
export { Arrayable, Awaitable, CreateHotContextFunction, DebuggerOptions, DecodedSourceMap, DepsHandlingOptions, EncodedSourceMap, FetchFunction, FetchResult, HotContext, ModuleCache, ModuleCacheMap, ModuleExecutionInfo, Nullable, RawSourceMap, ResolveIdFunction, SourceMapInput, StartOfSourceMap, ViteNodeResolveId, ViteNodeResolveModule, ViteNodeRunnerOptions, ViteNodeServerOptions };
|
package/dist/index.mjs
ADDED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import 'node:module';
|
|
15
|
-
import 'node:buffer';
|
|
16
|
-
import 'node:path';
|
|
1
|
+
import { t as C } from "./dist-B2ebky9O.mjs";
|
|
2
|
+
import { n as KNOWN_ASSET_RE } from "./constants-DRkacFwN.mjs";
|
|
3
|
+
import { _ as withTrailingSlash, c as isNodeBuiltin, d as normalizeModuleId, g as toFilePath, h as toArray, i as findNearestPackageData, m as slash } from "./utils-ExLpYVUV.mjs";
|
|
4
|
+
import { r as withInlineSourcemap } from "./source-map-DQLD3K8K.mjs";
|
|
5
|
+
import assert from "node:assert";
|
|
6
|
+
import { existsSync, promises } from "node:fs";
|
|
7
|
+
import { performance } from "node:perf_hooks";
|
|
8
|
+
import process from "node:process";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { createDebug } from "obug";
|
|
11
|
+
import { dirname, extname, join, normalize, relative, resolve } from "pathe";
|
|
12
|
+
import { version } from "vite";
|
|
13
|
+
import * as esModuleLexer from "es-module-lexer";
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
//#region src/debug.ts
|
|
19
16
|
function hashCode(s) {
|
|
20
17
|
return s.split("").reduce((a, b) => {
|
|
21
18
|
a = (a << 5) - a + b.charCodeAt(0);
|
|
22
19
|
return a & a;
|
|
23
20
|
}, 0);
|
|
24
21
|
}
|
|
25
|
-
|
|
22
|
+
var Debugger = class {
|
|
26
23
|
dumpDir;
|
|
27
24
|
initPromise;
|
|
28
25
|
externalizeMap = /* @__PURE__ */ new Map();
|
|
@@ -74,8 +71,10 @@ class Debugger {
|
|
|
74
71
|
}, null, 2);
|
|
75
72
|
return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
|
|
76
73
|
}
|
|
77
|
-
}
|
|
74
|
+
};
|
|
78
75
|
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/externalize.ts
|
|
79
78
|
const BUILTIN_EXTENSIONS = new Set([
|
|
80
79
|
".mjs",
|
|
81
80
|
".cjs",
|
|
@@ -109,7 +108,6 @@ function guessCJSversion(id) {
|
|
|
109
108
|
]) if (existsSync(i)) return i;
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
// The code from https://github.com/unjs/mlly/blob/c5bcca0cda175921344fd6de1bc0c499e73e5dac/src/syntax.ts#L51-L98
|
|
113
111
|
async function isValidNodeImport(id) {
|
|
114
112
|
const extension = extname(id);
|
|
115
113
|
if (BUILTIN_EXTENSIONS.has(extension)) return true;
|
|
@@ -133,20 +131,15 @@ async function shouldExternalize(id, options, cache = _defaultExternalizeCache)
|
|
|
133
131
|
}
|
|
134
132
|
async function _shouldExternalize(id, options) {
|
|
135
133
|
if (isNodeBuiltin(id)) return id;
|
|
136
|
-
// data: should be processed by native import,
|
|
137
|
-
// since it is a feature of ESM.
|
|
138
|
-
// also externalize network imports since nodejs allows it when --experimental-network-imports
|
|
139
134
|
if (id.startsWith("data:") || /^(?:https?:)?\/\//.test(id)) return id;
|
|
140
135
|
id = patchWindowsImportPath(id);
|
|
141
|
-
const moduleDirectories =
|
|
142
|
-
if (matchExternalizePattern(id, moduleDirectories, options
|
|
143
|
-
if (
|
|
144
|
-
if (matchExternalizePattern(id, moduleDirectories, options
|
|
145
|
-
|
|
146
|
-
// They are too big to inline by default.
|
|
147
|
-
if ((options === null || options === void 0 ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) return id;
|
|
136
|
+
const moduleDirectories = options?.moduleDirectories || ["/node_modules/"];
|
|
137
|
+
if (matchExternalizePattern(id, moduleDirectories, options?.inline)) return false;
|
|
138
|
+
if (options?.inlineFiles && options?.inlineFiles.includes(id)) return false;
|
|
139
|
+
if (matchExternalizePattern(id, moduleDirectories, options?.external)) return id;
|
|
140
|
+
if (options?.cacheDir && id.includes(options.cacheDir)) return id;
|
|
148
141
|
const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
|
|
149
|
-
id = isLibraryModule &&
|
|
142
|
+
id = isLibraryModule && options?.fallbackCJS ? guessCJSversion(id) || id : id;
|
|
150
143
|
if (matchExternalizePattern(id, moduleDirectories, defaultInline)) return false;
|
|
151
144
|
if (matchExternalizePattern(id, moduleDirectories, depsExternal)) return id;
|
|
152
145
|
if (isLibraryModule && await isValidNodeImport(id)) return id;
|
|
@@ -166,8 +159,10 @@ function patchWindowsImportPath(path) {
|
|
|
166
159
|
else return path;
|
|
167
160
|
}
|
|
168
161
|
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/server.ts
|
|
169
164
|
const debugRequest = createDebug("vite-node:server:request");
|
|
170
|
-
|
|
165
|
+
var ViteNodeServer = class {
|
|
171
166
|
fetchPromiseMap = {
|
|
172
167
|
ssr: /* @__PURE__ */ new Map(),
|
|
173
168
|
web: /* @__PURE__ */ new Map()
|
|
@@ -189,24 +184,15 @@ class ViteNodeServer {
|
|
|
189
184
|
externalizeCache = /* @__PURE__ */ new Map();
|
|
190
185
|
debugger;
|
|
191
186
|
constructor(server, options = {}) {
|
|
192
|
-
var _options$deps3;
|
|
193
187
|
this.server = server;
|
|
194
188
|
this.options = options;
|
|
195
189
|
const ssrOptions = server.config.ssr;
|
|
196
|
-
options.deps
|
|
190
|
+
options.deps ??= {};
|
|
197
191
|
options.deps.cacheDir = relative(server.config.root, options.deps.cacheDir || server.config.cacheDir);
|
|
198
192
|
if (ssrOptions) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
// options.deps.external.push(...ssrOptions.external)
|
|
203
|
-
// }
|
|
204
|
-
if (ssrOptions.noExternal === true) {
|
|
205
|
-
var _options$deps;
|
|
206
|
-
(_options$deps = options.deps).inline ?? (_options$deps.inline = true);
|
|
207
|
-
} else if (options.deps.inline !== true) {
|
|
208
|
-
var _options$deps2;
|
|
209
|
-
(_options$deps2 = options.deps).inline ?? (_options$deps2.inline = []);
|
|
193
|
+
if (ssrOptions.noExternal === true) options.deps.inline ??= true;
|
|
194
|
+
else if (options.deps.inline !== true) {
|
|
195
|
+
options.deps.inline ??= [];
|
|
210
196
|
const inline = options.deps.inline;
|
|
211
197
|
options.deps.inline.push(...toArray(ssrOptions.noExternal).filter((dep) => !inline.includes(dep)));
|
|
212
198
|
}
|
|
@@ -221,16 +207,14 @@ class ViteNodeServer {
|
|
|
221
207
|
const resolvedId = resolve(file);
|
|
222
208
|
return [resolvedId, pathToFileURL(resolvedId).href];
|
|
223
209
|
});
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
const customModuleDirectories = envValue === null || envValue === void 0 ? void 0 : envValue.split(",");
|
|
210
|
+
options.deps.moduleDirectories ??= [];
|
|
211
|
+
const customModuleDirectories = (process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES)?.split(",");
|
|
227
212
|
if (customModuleDirectories) options.deps.moduleDirectories.push(...customModuleDirectories);
|
|
228
213
|
options.deps.moduleDirectories = options.deps.moduleDirectories.map((dir) => {
|
|
229
214
|
if (!dir.startsWith("/")) dir = `/${dir}`;
|
|
230
215
|
if (!dir.endsWith("/")) dir += "/";
|
|
231
216
|
return normalize(dir);
|
|
232
217
|
});
|
|
233
|
-
// always add node_modules as a module directory
|
|
234
218
|
if (!options.deps.moduleDirectories.includes("/node_modules/")) options.deps.moduleDirectories.push("/node_modules/");
|
|
235
219
|
}
|
|
236
220
|
shouldExternalize(id) {
|
|
@@ -247,10 +231,10 @@ class ViteNodeServer {
|
|
|
247
231
|
this.existingOptimizedDeps.add(id);
|
|
248
232
|
return true;
|
|
249
233
|
}
|
|
250
|
-
return new Promise((resolve) => {
|
|
234
|
+
return new Promise((resolve$1) => {
|
|
251
235
|
setTimeout(() => {
|
|
252
236
|
this.ensureExists(id).then(() => {
|
|
253
|
-
resolve(true);
|
|
237
|
+
resolve$1(true);
|
|
254
238
|
});
|
|
255
239
|
});
|
|
256
240
|
});
|
|
@@ -261,12 +245,10 @@ class ViteNodeServer {
|
|
|
261
245
|
return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
|
|
262
246
|
}
|
|
263
247
|
getSourceMap(source) {
|
|
264
|
-
var _this$fetchCache$get, _this$server$moduleGr;
|
|
265
248
|
source = normalizeModuleId(source);
|
|
266
|
-
const fetchResult =
|
|
267
|
-
if (fetchResult
|
|
268
|
-
|
|
269
|
-
return (ssrTransformResult === null || ssrTransformResult === void 0 ? void 0 : ssrTransformResult.map) || null;
|
|
249
|
+
const fetchResult = this.fetchCache.get(source)?.result;
|
|
250
|
+
if (fetchResult?.map) return fetchResult.map;
|
|
251
|
+
return (this.server.moduleGraph.getModuleById(source)?.ssrTransformResult)?.map || null;
|
|
270
252
|
}
|
|
271
253
|
assertMode(mode) {
|
|
272
254
|
assert(mode === "web" || mode === "ssr", `"transformMode" can only be "web" or "ssr", received "${mode}".`);
|
|
@@ -284,7 +266,6 @@ class ViteNodeServer {
|
|
|
284
266
|
const moduleId = normalizeModuleId(id);
|
|
285
267
|
this.assertMode(mode);
|
|
286
268
|
const promiseMap = this.fetchPromiseMap[mode];
|
|
287
|
-
// reuse transform for concurrent requests
|
|
288
269
|
if (!promiseMap.has(moduleId)) promiseMap.set(moduleId, this._fetchModule(moduleId, mode).finally(() => {
|
|
289
270
|
promiseMap.delete(moduleId);
|
|
290
271
|
}));
|
|
@@ -294,7 +275,6 @@ class ViteNodeServer {
|
|
|
294
275
|
const mode = transformMode || this.getTransformMode(id);
|
|
295
276
|
this.assertMode(mode);
|
|
296
277
|
const promiseMap = this.transformPromiseMap[mode];
|
|
297
|
-
// reuse transform for concurrent requests
|
|
298
278
|
if (!promiseMap.has(id)) promiseMap.set(id, this._transformRequest(id, filepath, mode).finally(() => {
|
|
299
279
|
promiseMap.delete(id);
|
|
300
280
|
}));
|
|
@@ -303,15 +283,12 @@ class ViteNodeServer {
|
|
|
303
283
|
async transformModule(id, transformMode) {
|
|
304
284
|
if (transformMode !== "web") throw new Error("`transformModule` only supports `transformMode: \"web\"`.");
|
|
305
285
|
const normalizedId = normalizeModuleId(id);
|
|
306
|
-
|
|
307
|
-
const result = (mod === null || mod === void 0 ? void 0 : mod.transformResult) || await this.server.transformRequest(normalizedId);
|
|
308
|
-
return { code: result === null || result === void 0 ? void 0 : result.code };
|
|
286
|
+
return { code: (this.server.moduleGraph.getModuleById(normalizedId)?.transformResult || await this.server.transformRequest(normalizedId))?.code };
|
|
309
287
|
}
|
|
310
288
|
getTransformMode(id) {
|
|
311
|
-
var _this$options$transfo, _this$options$transfo2;
|
|
312
289
|
const withoutQuery = id.split("?")[0];
|
|
313
|
-
if (
|
|
314
|
-
if (
|
|
290
|
+
if (this.options.transformMode?.web?.some((r) => withoutQuery.match(r))) return "web";
|
|
291
|
+
if (this.options.transformMode?.ssr?.some((r) => withoutQuery.match(r))) return "ssr";
|
|
315
292
|
if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/)) return "ssr";
|
|
316
293
|
return "web";
|
|
317
294
|
}
|
|
@@ -332,9 +309,8 @@ class ViteNodeServer {
|
|
|
332
309
|
return mod;
|
|
333
310
|
}
|
|
334
311
|
async _fetchModule(id, transformMode) {
|
|
335
|
-
var _this$options$deps;
|
|
336
312
|
let result;
|
|
337
|
-
const cacheDir =
|
|
313
|
+
const cacheDir = this.options.deps?.cacheDir;
|
|
338
314
|
if (cacheDir && id.includes(cacheDir)) {
|
|
339
315
|
if (!id.startsWith(withTrailingSlash(this.server.config.root))) id = join(this.server.config.root, id);
|
|
340
316
|
const timeout = setTimeout(() => {
|
|
@@ -346,25 +322,21 @@ class ViteNodeServer {
|
|
|
346
322
|
const { path: filePath } = toFilePath(id, this.server.config.root);
|
|
347
323
|
const moduleNode = this.getChangedModule(id, filePath);
|
|
348
324
|
const cache = this.fetchCaches[transformMode].get(filePath);
|
|
349
|
-
// lastUpdateTimestamp is the timestamp that marks the last time the module was changed
|
|
350
|
-
// if lastUpdateTimestamp is 0, then the module was not changed since the server started
|
|
351
|
-
// we test "timestamp === 0" for expressiveness, but it's not necessary
|
|
352
325
|
const timestamp = moduleNode ? Math.max(moduleNode.lastHMRTimestamp, moduleNode.lastInvalidationTimestamp) : 0;
|
|
353
326
|
if (cache && (timestamp === 0 || cache.timestamp >= timestamp)) return cache.result;
|
|
354
327
|
const time = Date.now();
|
|
355
328
|
const externalize = await this.shouldExternalize(filePath);
|
|
356
329
|
let duration;
|
|
357
330
|
if (externalize) {
|
|
358
|
-
var _this$debugger;
|
|
359
331
|
result = { externalize };
|
|
360
|
-
|
|
332
|
+
this.debugger?.recordExternalize(id, externalize);
|
|
361
333
|
} else {
|
|
362
334
|
const start = performance.now();
|
|
363
335
|
const r = await this._transformRequest(id, filePath, transformMode);
|
|
364
336
|
duration = performance.now() - start;
|
|
365
337
|
result = {
|
|
366
|
-
code: r
|
|
367
|
-
map: r
|
|
338
|
+
code: r?.code,
|
|
339
|
+
map: r?.map
|
|
368
340
|
};
|
|
369
341
|
}
|
|
370
342
|
const cacheEntry = {
|
|
@@ -379,35 +351,28 @@ class ViteNodeServer {
|
|
|
379
351
|
return result;
|
|
380
352
|
}
|
|
381
353
|
async processTransformResult(filepath, result) {
|
|
382
|
-
const mod = this.server.moduleGraph.getModuleById(filepath);
|
|
383
354
|
return withInlineSourcemap(result, {
|
|
384
|
-
filepath: (
|
|
355
|
+
filepath: this.server.moduleGraph.getModuleById(filepath)?.file || filepath,
|
|
385
356
|
root: this.server.config.root,
|
|
386
357
|
noFirstLineMapping: Number(version.split(".")[0]) >= 6
|
|
387
358
|
});
|
|
388
359
|
}
|
|
389
360
|
async _transformRequest(id, filepath, transformMode) {
|
|
390
|
-
var _this$options$debug, _this$options$debug2;
|
|
391
361
|
debugRequest(id);
|
|
392
362
|
let result = null;
|
|
393
|
-
if (
|
|
394
|
-
|
|
395
|
-
result = await ((_this$debugger2 = this.debugger) === null || _this$debugger2 === void 0 ? void 0 : _this$debugger2.loadDump(id)) ?? null;
|
|
363
|
+
if (this.options.debug?.loadDumppedModules) {
|
|
364
|
+
result = await this.debugger?.loadDump(id) ?? null;
|
|
396
365
|
if (result) return result;
|
|
397
366
|
}
|
|
398
367
|
if (transformMode === "web") {
|
|
399
|
-
// for components like Vue, we want to use the client side
|
|
400
|
-
// plugins but then convert the code to be consumed by the server
|
|
401
368
|
result = await this.server.transformRequest(id);
|
|
402
369
|
if (result) result = await this.server.ssrTransform(result.code, result.map, id);
|
|
403
370
|
} else result = await this.server.transformRequest(id, { ssr: true });
|
|
404
371
|
if ((this.options.sourcemap ?? "inline") === "inline" && result) result = await this.processTransformResult(filepath, result);
|
|
405
|
-
if (
|
|
406
|
-
var _this$debugger3;
|
|
407
|
-
await ((_this$debugger3 = this.debugger) === null || _this$debugger3 === void 0 ? void 0 : _this$debugger3.dumpFile(id, result));
|
|
408
|
-
}
|
|
372
|
+
if (this.options.debug?.dumpModules) await this.debugger?.dumpFile(id, result);
|
|
409
373
|
return result;
|
|
410
374
|
}
|
|
411
|
-
}
|
|
375
|
+
};
|
|
412
376
|
|
|
413
|
-
|
|
377
|
+
//#endregion
|
|
378
|
+
export { guessCJSversion as n, shouldExternalize as r, ViteNodeServer as t };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { _ as ViteNodeResolveId, b as ViteNodeServerOptions, i as DebuggerOptions, l as FetchResult, o as DepsHandlingOptions, s as EncodedSourceMap } from "./types-Dtew7m7O.mjs";
|
|
2
|
+
import { TransformResult, ViteDevServer } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/debug.d.ts
|
|
5
|
+
declare class Debugger {
|
|
6
|
+
options: DebuggerOptions;
|
|
7
|
+
dumpDir: string | undefined;
|
|
8
|
+
initPromise: Promise<void> | undefined;
|
|
9
|
+
externalizeMap: Map<string, string>;
|
|
10
|
+
constructor(root: string, options: DebuggerOptions);
|
|
11
|
+
clearDump(): Promise<void>;
|
|
12
|
+
encodeId(id: string): string;
|
|
13
|
+
recordExternalize(id: string, path: string): Promise<void>;
|
|
14
|
+
dumpFile(id: string, result: TransformResult | null): Promise<void>;
|
|
15
|
+
loadDump(id: string): Promise<TransformResult | null>;
|
|
16
|
+
writeInfo(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/externalize.d.ts
|
|
20
|
+
declare function guessCJSversion(id: string): string | undefined;
|
|
21
|
+
declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/server.d.ts
|
|
24
|
+
interface FetchCache {
|
|
25
|
+
duration?: number;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
result: FetchResult;
|
|
28
|
+
}
|
|
29
|
+
declare class ViteNodeServer {
|
|
30
|
+
server: ViteDevServer;
|
|
31
|
+
options: ViteNodeServerOptions;
|
|
32
|
+
private fetchPromiseMap;
|
|
33
|
+
private transformPromiseMap;
|
|
34
|
+
private durations;
|
|
35
|
+
private existingOptimizedDeps;
|
|
36
|
+
fetchCaches: Record<"ssr" | "web", Map<string, FetchCache>>;
|
|
37
|
+
fetchCache: Map<string, FetchCache>;
|
|
38
|
+
externalizeCache: Map<string, Promise<string | false>>;
|
|
39
|
+
debugger?: Debugger;
|
|
40
|
+
constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
|
|
41
|
+
shouldExternalize(id: string): Promise<string | false>;
|
|
42
|
+
getTotalDuration(): number;
|
|
43
|
+
private ensureExists;
|
|
44
|
+
resolveId(id: string, importer?: string, transformMode?: "web" | "ssr"): Promise<ViteNodeResolveId | null>;
|
|
45
|
+
getSourceMap(source: string): EncodedSourceMap | null;
|
|
46
|
+
private assertMode;
|
|
47
|
+
fetchModule(id: string, transformMode?: "web" | "ssr"): Promise<FetchResult>;
|
|
48
|
+
fetchResult(id: string, mode: "web" | "ssr"): Promise<FetchResult>;
|
|
49
|
+
transformRequest(id: string, filepath?: string, transformMode?: "web" | "ssr"): Promise<TransformResult | null | undefined>;
|
|
50
|
+
transformModule(id: string, transformMode?: "web" | "ssr"): Promise<{
|
|
51
|
+
code: string | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
getTransformMode(id: string): "ssr" | "web";
|
|
54
|
+
private getChangedModule;
|
|
55
|
+
private _fetchModule;
|
|
56
|
+
protected processTransformResult(filepath: string, result: TransformResult): Promise<TransformResult>;
|
|
57
|
+
private _transformRequest;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { ViteNodeServer, guessCJSversion, shouldExternalize };
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./dist-B2ebky9O.mjs";
|
|
2
|
+
import { n as guessCJSversion, r as shouldExternalize, t as ViteNodeServer } from "./server-BWywEVuB.mjs";
|
|
3
|
+
import "./constants-DRkacFwN.mjs";
|
|
4
|
+
import "./utils-ExLpYVUV.mjs";
|
|
5
|
+
import "./source-map-DQLD3K8K.mjs";
|
|
6
|
+
|
|
7
|
+
export { ViteNodeServer, guessCJSversion, shouldExternalize };
|