vite-node 2.0.0-beta.9 → 2.0.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 +5 -2
- package/dist/chunk-hmr.cjs +35 -18
- package/dist/chunk-hmr.mjs +35 -18
- package/dist/cli.cjs +23 -11
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +24 -12
- package/dist/client.cjs +78 -35
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +78 -35
- package/dist/constants.cjs +4 -1
- package/dist/constants.mjs +4 -1
- package/dist/hmr.d.ts +1 -1
- package/dist/{index-D1EszD4V.d.ts → index-CCsqCcr7.d.ts} +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/server.cjs +186 -104
- package/dist/server.d.ts +1 -7
- package/dist/server.mjs +189 -107
- package/dist/source-map.cjs +66 -31
- package/dist/source-map.mjs +66 -31
- package/dist/types.d.ts +1 -1
- package/dist/utils.cjs +41 -31
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +41 -31
- package/package.json +3 -3
package/dist/server.cjs
CHANGED
|
@@ -23,7 +23,7 @@ const defaultInline = [
|
|
|
23
23
|
// special Vite query strings
|
|
24
24
|
/[?&](init|raw|url|inline)\b/,
|
|
25
25
|
// Vite returns a string for assets imports, even if it's inside "node_modules"
|
|
26
|
-
|
|
26
|
+
constants.KNOWN_ASSET_RE
|
|
27
27
|
];
|
|
28
28
|
const depsExternal = [
|
|
29
29
|
/\/node_modules\/.*\.cjs\.js$/,
|
|
@@ -37,8 +37,9 @@ function guessCJSversion(id) {
|
|
|
37
37
|
id.replace(ESM_EXT_RE, ".cjs.js"),
|
|
38
38
|
id.replace(ESM_EXT_RE, ".js")
|
|
39
39
|
]) {
|
|
40
|
-
if (fs.existsSync(i))
|
|
40
|
+
if (fs.existsSync(i)) {
|
|
41
41
|
return i;
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
if (id.match(ESM_FOLDER_RE)) {
|
|
@@ -48,79 +49,98 @@ function guessCJSversion(id) {
|
|
|
48
49
|
id.replace(ESM_FOLDER_RE, "/lib/$1"),
|
|
49
50
|
id.replace(ESM_FOLDER_RE, "/$1")
|
|
50
51
|
]) {
|
|
51
|
-
if (fs.existsSync(i))
|
|
52
|
+
if (fs.existsSync(i)) {
|
|
52
53
|
return i;
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
async function isValidNodeImport(id) {
|
|
57
59
|
const extension = pathe.extname(id);
|
|
58
|
-
if (BUILTIN_EXTENSIONS.has(extension))
|
|
60
|
+
if (BUILTIN_EXTENSIONS.has(extension)) {
|
|
59
61
|
return true;
|
|
60
|
-
|
|
62
|
+
}
|
|
63
|
+
if (extension !== ".js") {
|
|
61
64
|
return false;
|
|
65
|
+
}
|
|
62
66
|
id = id.replace("file:///", "");
|
|
63
67
|
const package_ = await utils.findNearestPackageData(pathe.dirname(id));
|
|
64
|
-
if (package_.type === "module")
|
|
68
|
+
if (package_.type === "module") {
|
|
65
69
|
return true;
|
|
66
|
-
|
|
70
|
+
}
|
|
71
|
+
if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id)) {
|
|
67
72
|
return false;
|
|
73
|
+
}
|
|
68
74
|
const code = await fs.promises.readFile(id, "utf8").catch(() => "");
|
|
69
75
|
return !ESM_SYNTAX_RE.test(code);
|
|
70
76
|
}
|
|
71
77
|
const _defaultExternalizeCache = /* @__PURE__ */ new Map();
|
|
72
78
|
async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
|
|
73
|
-
if (!cache.has(id))
|
|
79
|
+
if (!cache.has(id)) {
|
|
74
80
|
cache.set(id, _shouldExternalize(id, options));
|
|
81
|
+
}
|
|
75
82
|
return cache.get(id);
|
|
76
83
|
}
|
|
77
84
|
async function _shouldExternalize(id, options) {
|
|
78
|
-
if (utils.isNodeBuiltin(id))
|
|
85
|
+
if (utils.isNodeBuiltin(id)) {
|
|
79
86
|
return id;
|
|
80
|
-
|
|
87
|
+
}
|
|
88
|
+
if (id.startsWith("data:") || /^(?:https?:)?\/\//.test(id)) {
|
|
81
89
|
return id;
|
|
90
|
+
}
|
|
82
91
|
id = patchWindowsImportPath(id);
|
|
83
|
-
if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
|
|
92
|
+
if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) {
|
|
84
93
|
return id;
|
|
94
|
+
}
|
|
85
95
|
const moduleDirectories = (options == null ? void 0 : options.moduleDirectories) || ["/node_modules/"];
|
|
86
|
-
if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline))
|
|
96
|
+
if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline)) {
|
|
87
97
|
return false;
|
|
88
|
-
|
|
98
|
+
}
|
|
99
|
+
if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external)) {
|
|
89
100
|
return id;
|
|
101
|
+
}
|
|
90
102
|
const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
|
|
91
103
|
const guessCJS = isLibraryModule && (options == null ? void 0 : options.fallbackCJS);
|
|
92
104
|
id = guessCJS ? guessCJSversion(id) || id : id;
|
|
93
|
-
if (matchExternalizePattern(id, moduleDirectories, defaultInline))
|
|
105
|
+
if (matchExternalizePattern(id, moduleDirectories, defaultInline)) {
|
|
94
106
|
return false;
|
|
95
|
-
|
|
107
|
+
}
|
|
108
|
+
if (matchExternalizePattern(id, moduleDirectories, depsExternal)) {
|
|
96
109
|
return id;
|
|
97
|
-
|
|
110
|
+
}
|
|
111
|
+
if (isLibraryModule && await isValidNodeImport(id)) {
|
|
98
112
|
return id;
|
|
113
|
+
}
|
|
99
114
|
return false;
|
|
100
115
|
}
|
|
101
116
|
function matchExternalizePattern(id, moduleDirectories, patterns) {
|
|
102
|
-
if (patterns == null)
|
|
117
|
+
if (patterns == null) {
|
|
103
118
|
return false;
|
|
104
|
-
|
|
119
|
+
}
|
|
120
|
+
if (patterns === true) {
|
|
105
121
|
return true;
|
|
122
|
+
}
|
|
106
123
|
for (const ex of patterns) {
|
|
107
124
|
if (typeof ex === "string") {
|
|
108
|
-
if (moduleDirectories.some((dir) => id.includes(pathe.join(dir, ex))))
|
|
125
|
+
if (moduleDirectories.some((dir) => id.includes(pathe.join(dir, ex)))) {
|
|
109
126
|
return true;
|
|
127
|
+
}
|
|
110
128
|
} else {
|
|
111
|
-
if (ex.test(id))
|
|
129
|
+
if (ex.test(id)) {
|
|
112
130
|
return true;
|
|
131
|
+
}
|
|
113
132
|
}
|
|
114
133
|
}
|
|
115
134
|
return false;
|
|
116
135
|
}
|
|
117
136
|
function patchWindowsImportPath(path) {
|
|
118
|
-
if (path.match(/^\w:\\/))
|
|
137
|
+
if (path.match(/^\w:\\/)) {
|
|
119
138
|
return `file:///${utils.slash(path)}`;
|
|
120
|
-
else if (path.match(/^\w:\//))
|
|
139
|
+
} else if (path.match(/^\w:\//)) {
|
|
121
140
|
return `file:///${path}`;
|
|
122
|
-
else
|
|
141
|
+
} else {
|
|
123
142
|
return path;
|
|
143
|
+
}
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
function hashCode(s) {
|
|
@@ -132,13 +152,22 @@ function hashCode(s) {
|
|
|
132
152
|
class Debugger {
|
|
133
153
|
constructor(root, options) {
|
|
134
154
|
this.options = options;
|
|
135
|
-
if (options.dumpModules)
|
|
136
|
-
this.dumpDir = pathe.resolve(
|
|
155
|
+
if (options.dumpModules) {
|
|
156
|
+
this.dumpDir = pathe.resolve(
|
|
157
|
+
root,
|
|
158
|
+
options.dumpModules === true ? ".vite-node/dump" : options.dumpModules
|
|
159
|
+
);
|
|
160
|
+
}
|
|
137
161
|
if (this.dumpDir) {
|
|
138
|
-
if (options.loadDumppedModules)
|
|
139
|
-
console.info(
|
|
140
|
-
|
|
141
|
-
|
|
162
|
+
if (options.loadDumppedModules) {
|
|
163
|
+
console.info(
|
|
164
|
+
c.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`)
|
|
165
|
+
);
|
|
166
|
+
} else {
|
|
167
|
+
console.info(
|
|
168
|
+
c.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
142
171
|
}
|
|
143
172
|
this.initPromise = this.clearDump();
|
|
144
173
|
}
|
|
@@ -146,37 +175,49 @@ class Debugger {
|
|
|
146
175
|
initPromise;
|
|
147
176
|
externalizeMap = /* @__PURE__ */ new Map();
|
|
148
177
|
async clearDump() {
|
|
149
|
-
if (!this.dumpDir)
|
|
178
|
+
if (!this.dumpDir) {
|
|
150
179
|
return;
|
|
151
|
-
|
|
180
|
+
}
|
|
181
|
+
if (!this.options.loadDumppedModules && fs.existsSync(this.dumpDir)) {
|
|
152
182
|
await fs.promises.rm(this.dumpDir, { recursive: true, force: true });
|
|
183
|
+
}
|
|
153
184
|
await fs.promises.mkdir(this.dumpDir, { recursive: true });
|
|
154
185
|
}
|
|
155
186
|
encodeId(id) {
|
|
156
|
-
return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(
|
|
187
|
+
return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(
|
|
188
|
+
id
|
|
189
|
+
)}.js`;
|
|
157
190
|
}
|
|
158
191
|
async recordExternalize(id, path) {
|
|
159
|
-
if (!this.dumpDir)
|
|
192
|
+
if (!this.dumpDir) {
|
|
160
193
|
return;
|
|
194
|
+
}
|
|
161
195
|
this.externalizeMap.set(id, path);
|
|
162
196
|
await this.writeInfo();
|
|
163
197
|
}
|
|
164
198
|
async dumpFile(id, result) {
|
|
165
|
-
if (!result || !this.dumpDir)
|
|
199
|
+
if (!result || !this.dumpDir) {
|
|
166
200
|
return;
|
|
201
|
+
}
|
|
167
202
|
await this.initPromise;
|
|
168
203
|
const name = this.encodeId(id);
|
|
169
|
-
return await fs.promises.writeFile(
|
|
170
|
-
|
|
204
|
+
return await fs.promises.writeFile(
|
|
205
|
+
pathe.join(this.dumpDir, name),
|
|
206
|
+
`// ${id.replace(/\0/g, "\\0")}
|
|
207
|
+
${result.code}`,
|
|
208
|
+
"utf-8"
|
|
209
|
+
);
|
|
171
210
|
}
|
|
172
211
|
async loadDump(id) {
|
|
173
|
-
if (!this.dumpDir)
|
|
212
|
+
if (!this.dumpDir) {
|
|
174
213
|
return null;
|
|
214
|
+
}
|
|
175
215
|
await this.initPromise;
|
|
176
216
|
const name = this.encodeId(id);
|
|
177
217
|
const path = pathe.join(this.dumpDir, name);
|
|
178
|
-
if (!fs.existsSync(path))
|
|
218
|
+
if (!fs.existsSync(path)) {
|
|
179
219
|
return null;
|
|
220
|
+
}
|
|
180
221
|
const code = await fs.promises.readFile(path, "utf-8");
|
|
181
222
|
return {
|
|
182
223
|
code: code.replace(/^\/\/.*\n/, ""),
|
|
@@ -184,12 +225,17 @@ ${result.code}`, "utf-8");
|
|
|
184
225
|
};
|
|
185
226
|
}
|
|
186
227
|
async writeInfo() {
|
|
187
|
-
if (!this.dumpDir)
|
|
228
|
+
if (!this.dumpDir) {
|
|
188
229
|
return;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
230
|
+
}
|
|
231
|
+
const info = JSON.stringify(
|
|
232
|
+
{
|
|
233
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
234
|
+
externalize: Object.fromEntries(this.externalizeMap.entries())
|
|
235
|
+
},
|
|
236
|
+
null,
|
|
237
|
+
2
|
|
238
|
+
);
|
|
193
239
|
return fs.promises.writeFile(pathe.join(this.dumpDir, "info.json"), info, "utf-8");
|
|
194
240
|
}
|
|
195
241
|
}
|
|
@@ -202,38 +248,55 @@ class ViteNodeServer {
|
|
|
202
248
|
var _a, _b, _c;
|
|
203
249
|
const ssrOptions = server.config.ssr;
|
|
204
250
|
options.deps ?? (options.deps = {});
|
|
205
|
-
options.deps.cacheDir = pathe.relative(
|
|
251
|
+
options.deps.cacheDir = pathe.relative(
|
|
252
|
+
server.config.root,
|
|
253
|
+
options.deps.cacheDir || server.config.cacheDir
|
|
254
|
+
);
|
|
206
255
|
if (ssrOptions) {
|
|
207
256
|
if (ssrOptions.noExternal === true) {
|
|
208
257
|
(_a = options.deps).inline ?? (_a.inline = true);
|
|
209
258
|
} else if (options.deps.inline !== true) {
|
|
210
259
|
(_b = options.deps).inline ?? (_b.inline = []);
|
|
211
260
|
const inline = options.deps.inline;
|
|
212
|
-
options.deps.inline.push(
|
|
261
|
+
options.deps.inline.push(
|
|
262
|
+
...utils.toArray(ssrOptions.noExternal).filter(
|
|
263
|
+
(dep) => !inline.includes(dep)
|
|
264
|
+
)
|
|
265
|
+
);
|
|
213
266
|
}
|
|
214
267
|
}
|
|
215
268
|
if (process.env.VITE_NODE_DEBUG_DUMP) {
|
|
216
|
-
options.debug = Object.assign(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
269
|
+
options.debug = Object.assign(
|
|
270
|
+
{
|
|
271
|
+
dumpModules: !!process.env.VITE_NODE_DEBUG_DUMP,
|
|
272
|
+
loadDumppedModules: process.env.VITE_NODE_DEBUG_DUMP === "load"
|
|
273
|
+
},
|
|
274
|
+
options.debug ?? {}
|
|
275
|
+
);
|
|
220
276
|
}
|
|
221
|
-
if (options.debug)
|
|
277
|
+
if (options.debug) {
|
|
222
278
|
this.debugger = new Debugger(server.config.root, options.debug);
|
|
279
|
+
}
|
|
223
280
|
(_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
|
|
224
281
|
const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
|
|
225
282
|
const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
|
|
226
|
-
if (customModuleDirectories)
|
|
283
|
+
if (customModuleDirectories) {
|
|
227
284
|
options.deps.moduleDirectories.push(...customModuleDirectories);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
285
|
+
}
|
|
286
|
+
options.deps.moduleDirectories = options.deps.moduleDirectories.map(
|
|
287
|
+
(dir) => {
|
|
288
|
+
if (!dir.startsWith("/")) {
|
|
289
|
+
dir = `/${dir}`;
|
|
290
|
+
}
|
|
291
|
+
if (!dir.endsWith("/")) {
|
|
292
|
+
dir += "/";
|
|
293
|
+
}
|
|
294
|
+
return pathe.normalize(dir);
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
if (!options.deps.moduleDirectories.includes("/node_modules/")) {
|
|
236
298
|
options.deps.moduleDirectories.push("/node_modules/");
|
|
299
|
+
}
|
|
237
300
|
}
|
|
238
301
|
fetchPromiseMap = {
|
|
239
302
|
ssr: /* @__PURE__ */ new Map(),
|
|
@@ -264,8 +327,9 @@ class ViteNodeServer {
|
|
|
264
327
|
return [...ssrDurations, ...webDurations].reduce((a, b) => a + b, 0);
|
|
265
328
|
}
|
|
266
329
|
async ensureExists(id) {
|
|
267
|
-
if (this.existingOptimizedDeps.has(id))
|
|
330
|
+
if (this.existingOptimizedDeps.has(id)) {
|
|
268
331
|
return true;
|
|
332
|
+
}
|
|
269
333
|
if (fs.existsSync(id)) {
|
|
270
334
|
this.existingOptimizedDeps.add(id);
|
|
271
335
|
return true;
|
|
@@ -279,35 +343,28 @@ class ViteNodeServer {
|
|
|
279
343
|
});
|
|
280
344
|
}
|
|
281
345
|
async resolveId(id, importer, transformMode) {
|
|
282
|
-
if (importer && !importer.startsWith(utils.withTrailingSlash(this.server.config.root)))
|
|
346
|
+
if (importer && !importer.startsWith(utils.withTrailingSlash(this.server.config.root))) {
|
|
283
347
|
importer = pathe.resolve(this.server.config.root, importer);
|
|
348
|
+
}
|
|
284
349
|
const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
|
|
285
|
-
return this.server.pluginContainer.resolveId(id, importer, {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const id = (resolved == null ? void 0 : resolved.id) || rawId;
|
|
289
|
-
const external = !pathe.isAbsolute(id) || this.isModuleDirectory(id) ? rawId : null;
|
|
290
|
-
return {
|
|
291
|
-
id,
|
|
292
|
-
fsPath: utils.cleanUrl(id),
|
|
293
|
-
external
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
isModuleDirectory(path) {
|
|
297
|
-
var _a;
|
|
298
|
-
const moduleDirectories = ((_a = this.options.deps) == null ? void 0 : _a.moduleDirectories) || ["/node_modules/"];
|
|
299
|
-
return moduleDirectories.some((dir) => path.includes(dir));
|
|
350
|
+
return this.server.pluginContainer.resolveId(id, importer, {
|
|
351
|
+
ssr: mode === "ssr"
|
|
352
|
+
});
|
|
300
353
|
}
|
|
301
354
|
getSourceMap(source) {
|
|
302
355
|
var _a, _b;
|
|
303
356
|
const fetchResult = (_a = this.fetchCache.get(source)) == null ? void 0 : _a.result;
|
|
304
|
-
if (fetchResult == null ? void 0 : fetchResult.map)
|
|
357
|
+
if (fetchResult == null ? void 0 : fetchResult.map) {
|
|
305
358
|
return fetchResult.map;
|
|
359
|
+
}
|
|
306
360
|
const ssrTransformResult = (_b = this.server.moduleGraph.getModuleById(source)) == null ? void 0 : _b.ssrTransformResult;
|
|
307
361
|
return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
|
|
308
362
|
}
|
|
309
363
|
assertMode(mode) {
|
|
310
|
-
assert(
|
|
364
|
+
assert(
|
|
365
|
+
mode === "web" || mode === "ssr",
|
|
366
|
+
`"transformMode" can only be "web" or "ssr", received "${mode}".`
|
|
367
|
+
);
|
|
311
368
|
}
|
|
312
369
|
async fetchModule(id, transformMode) {
|
|
313
370
|
const mode = transformMode || this.getTransformMode(id);
|
|
@@ -320,9 +377,12 @@ class ViteNodeServer {
|
|
|
320
377
|
this.assertMode(mode);
|
|
321
378
|
const promiseMap = this.fetchPromiseMap[mode];
|
|
322
379
|
if (!promiseMap.has(moduleId)) {
|
|
323
|
-
promiseMap.set(
|
|
324
|
-
|
|
325
|
-
|
|
380
|
+
promiseMap.set(
|
|
381
|
+
moduleId,
|
|
382
|
+
this._fetchModule(moduleId, mode).finally(() => {
|
|
383
|
+
promiseMap.delete(moduleId);
|
|
384
|
+
})
|
|
385
|
+
);
|
|
326
386
|
}
|
|
327
387
|
return promiseMap.get(moduleId);
|
|
328
388
|
}
|
|
@@ -331,15 +391,21 @@ class ViteNodeServer {
|
|
|
331
391
|
this.assertMode(mode);
|
|
332
392
|
const promiseMap = this.transformPromiseMap[mode];
|
|
333
393
|
if (!promiseMap.has(id)) {
|
|
334
|
-
promiseMap.set(
|
|
335
|
-
|
|
336
|
-
|
|
394
|
+
promiseMap.set(
|
|
395
|
+
id,
|
|
396
|
+
this._transformRequest(id, filepath, mode).finally(() => {
|
|
397
|
+
promiseMap.delete(id);
|
|
398
|
+
})
|
|
399
|
+
);
|
|
337
400
|
}
|
|
338
401
|
return promiseMap.get(id);
|
|
339
402
|
}
|
|
340
403
|
async transformModule(id, transformMode) {
|
|
341
|
-
if (transformMode !== "web")
|
|
342
|
-
throw new Error(
|
|
404
|
+
if (transformMode !== "web") {
|
|
405
|
+
throw new Error(
|
|
406
|
+
'`transformModule` only supports `transformMode: "web"`.'
|
|
407
|
+
);
|
|
408
|
+
}
|
|
343
409
|
const normalizedId = utils.normalizeModuleId(id);
|
|
344
410
|
const mod = this.server.moduleGraph.getModuleById(normalizedId);
|
|
345
411
|
const result = (mod == null ? void 0 : mod.transformResult) || await this.server.transformRequest(normalizedId);
|
|
@@ -350,26 +416,34 @@ class ViteNodeServer {
|
|
|
350
416
|
getTransformMode(id) {
|
|
351
417
|
var _a, _b, _c, _d;
|
|
352
418
|
const withoutQuery = id.split("?")[0];
|
|
353
|
-
if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
|
|
419
|
+
if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r))) {
|
|
354
420
|
return "web";
|
|
355
|
-
|
|
421
|
+
}
|
|
422
|
+
if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r))) {
|
|
356
423
|
return "ssr";
|
|
357
|
-
|
|
424
|
+
}
|
|
425
|
+
if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/)) {
|
|
358
426
|
return "ssr";
|
|
427
|
+
}
|
|
359
428
|
return "web";
|
|
360
429
|
}
|
|
361
430
|
getChangedModule(id, file) {
|
|
362
431
|
const module = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(file);
|
|
363
|
-
if (module)
|
|
432
|
+
if (module) {
|
|
364
433
|
return module;
|
|
434
|
+
}
|
|
365
435
|
const _modules = this.server.moduleGraph.getModulesByFile(file);
|
|
366
|
-
if (!_modules || !_modules.size)
|
|
436
|
+
if (!_modules || !_modules.size) {
|
|
367
437
|
return null;
|
|
438
|
+
}
|
|
368
439
|
const modules = [..._modules];
|
|
369
440
|
let mod = modules[0];
|
|
370
441
|
let latestMax = -1;
|
|
371
442
|
for (const m of _modules) {
|
|
372
|
-
const timestamp = Math.max(
|
|
443
|
+
const timestamp = Math.max(
|
|
444
|
+
m.lastHMRTimestamp,
|
|
445
|
+
m.lastInvalidationTimestamp
|
|
446
|
+
);
|
|
373
447
|
if (timestamp > latestMax) {
|
|
374
448
|
latestMax = timestamp;
|
|
375
449
|
mod = m;
|
|
@@ -382,10 +456,13 @@ class ViteNodeServer {
|
|
|
382
456
|
let result;
|
|
383
457
|
const cacheDir = (_a = this.options.deps) == null ? void 0 : _a.cacheDir;
|
|
384
458
|
if (cacheDir && id.includes(cacheDir)) {
|
|
385
|
-
if (!id.startsWith(utils.withTrailingSlash(this.server.config.root)))
|
|
459
|
+
if (!id.startsWith(utils.withTrailingSlash(this.server.config.root))) {
|
|
386
460
|
id = pathe.join(this.server.config.root, id);
|
|
461
|
+
}
|
|
387
462
|
const timeout = setTimeout(() => {
|
|
388
|
-
throw new Error(
|
|
463
|
+
throw new Error(
|
|
464
|
+
`ViteNodeServer: ${id} not found. This is a bug, please report it.`
|
|
465
|
+
);
|
|
389
466
|
}, 5e3);
|
|
390
467
|
await this.ensureExists(id);
|
|
391
468
|
clearTimeout(timeout);
|
|
@@ -393,9 +470,13 @@ class ViteNodeServer {
|
|
|
393
470
|
const { path: filePath } = utils.toFilePath(id, this.server.config.root);
|
|
394
471
|
const moduleNode = this.getChangedModule(id, filePath);
|
|
395
472
|
const cache = this.fetchCaches[transformMode].get(filePath);
|
|
396
|
-
const timestamp = moduleNode ? Math.max(
|
|
397
|
-
|
|
473
|
+
const timestamp = moduleNode ? Math.max(
|
|
474
|
+
moduleNode.lastHMRTimestamp,
|
|
475
|
+
moduleNode.lastInvalidationTimestamp
|
|
476
|
+
) : 0;
|
|
477
|
+
if (cache && (timestamp === 0 || cache.timestamp >= timestamp)) {
|
|
398
478
|
return cache.result;
|
|
479
|
+
}
|
|
399
480
|
const time = Date.now();
|
|
400
481
|
const externalize = await this.shouldExternalize(filePath);
|
|
401
482
|
let duration;
|
|
@@ -414,10 +495,7 @@ class ViteNodeServer {
|
|
|
414
495
|
result
|
|
415
496
|
};
|
|
416
497
|
const durations = this.durations[transformMode].get(filePath) || [];
|
|
417
|
-
this.durations[transformMode].set(
|
|
418
|
-
filePath,
|
|
419
|
-
[...durations, duration ?? 0]
|
|
420
|
-
);
|
|
498
|
+
this.durations[transformMode].set(filePath, [...durations, duration ?? 0]);
|
|
421
499
|
this.fetchCaches[transformMode].set(filePath, cacheEntry);
|
|
422
500
|
this.fetchCache.set(filePath, cacheEntry);
|
|
423
501
|
return result;
|
|
@@ -435,21 +513,25 @@ class ViteNodeServer {
|
|
|
435
513
|
let result = null;
|
|
436
514
|
if ((_a = this.options.debug) == null ? void 0 : _a.loadDumppedModules) {
|
|
437
515
|
result = await ((_b = this.debugger) == null ? void 0 : _b.loadDump(id)) ?? null;
|
|
438
|
-
if (result)
|
|
516
|
+
if (result) {
|
|
439
517
|
return result;
|
|
518
|
+
}
|
|
440
519
|
}
|
|
441
520
|
if (transformMode === "web") {
|
|
442
521
|
result = await this.server.transformRequest(id);
|
|
443
|
-
if (result)
|
|
522
|
+
if (result) {
|
|
444
523
|
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
524
|
+
}
|
|
445
525
|
} else {
|
|
446
526
|
result = await this.server.transformRequest(id, { ssr: true });
|
|
447
527
|
}
|
|
448
528
|
const sourcemap = this.options.sourcemap ?? "inline";
|
|
449
|
-
if (sourcemap === "inline" && result && !id.includes("node_modules"))
|
|
529
|
+
if (sourcemap === "inline" && result && !id.includes("node_modules")) {
|
|
450
530
|
result = await this.processTransformResult(filepath, result);
|
|
451
|
-
|
|
531
|
+
}
|
|
532
|
+
if ((_c = this.options.debug) == null ? void 0 : _c.dumpModules) {
|
|
452
533
|
await ((_d = this.debugger) == null ? void 0 : _d.dumpFile(id, result));
|
|
534
|
+
}
|
|
453
535
|
return result;
|
|
454
536
|
}
|
|
455
537
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransformResult, ViteDevServer } from 'vite';
|
|
2
|
-
import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-
|
|
2
|
+
import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-CCsqCcr7.js';
|
|
3
3
|
import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
|
|
4
4
|
|
|
5
5
|
declare class Debugger {
|
|
@@ -43,12 +43,6 @@ declare class ViteNodeServer {
|
|
|
43
43
|
getTotalDuration(): number;
|
|
44
44
|
private ensureExists;
|
|
45
45
|
resolveId(id: string, importer?: string, transformMode?: 'web' | 'ssr'): Promise<ViteNodeResolveId | null>;
|
|
46
|
-
resolveModule(rawId: string, resolved: ViteNodeResolveId | null): Promise<{
|
|
47
|
-
id: string;
|
|
48
|
-
fsPath: string;
|
|
49
|
-
external: string | null;
|
|
50
|
-
}>;
|
|
51
|
-
private isModuleDirectory;
|
|
52
46
|
getSourceMap(source: string): EncodedSourceMap | null;
|
|
53
47
|
private assertMode;
|
|
54
48
|
fetchModule(id: string, transformMode?: 'web' | 'ssr'): Promise<FetchResult>;
|