vite-node 3.0.9 → 3.1.0-beta.2
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/chunk-hmr.cjs +193 -231
- package/dist/chunk-hmr.mjs +193 -231
- package/dist/cli.cjs +100 -113
- package/dist/cli.mjs +100 -113
- package/dist/client.cjs +387 -468
- package/dist/client.mjs +387 -468
- package/dist/constants.cjs +27 -33
- package/dist/constants.mjs +27 -33
- package/dist/server.cjs +354 -516
- package/dist/server.mjs +354 -516
- package/dist/source-map.cjs +258 -341
- package/dist/source-map.mjs +258 -341
- package/dist/utils.cjs +137 -152
- package/dist/utils.mjs +137 -152
- package/package.json +1 -1
package/dist/client.mjs
CHANGED
|
@@ -12,489 +12,408 @@ const { setTimeout, clearTimeout } = globalThis;
|
|
|
12
12
|
const debugExecute = createDebug("vite-node:client:execute");
|
|
13
13
|
const debugNative = createDebug("vite-node:client:native");
|
|
14
14
|
const clientStub = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
send: () => {
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
updateStyle: () => {
|
|
35
|
-
},
|
|
36
|
-
removeStyle: () => {
|
|
37
|
-
}
|
|
15
|
+
injectQuery: (id) => id,
|
|
16
|
+
createHotContext: () => {
|
|
17
|
+
return {
|
|
18
|
+
accept: () => {},
|
|
19
|
+
prune: () => {},
|
|
20
|
+
dispose: () => {},
|
|
21
|
+
decline: () => {},
|
|
22
|
+
invalidate: () => {},
|
|
23
|
+
on: () => {},
|
|
24
|
+
send: () => {}
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
updateStyle: () => {},
|
|
28
|
+
removeStyle: () => {}
|
|
38
29
|
};
|
|
39
30
|
const env = createImportMetaEnvProxy();
|
|
40
31
|
const DEFAULT_REQUEST_STUBS = {
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
"/@vite/client": clientStub,
|
|
33
|
+
"@vite/client": clientStub
|
|
43
34
|
};
|
|
44
35
|
class ModuleCacheMap extends Map {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return invalidated;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Return parsed source map based on inlined source map of the module
|
|
139
|
-
*/
|
|
140
|
-
getSourceMap(id) {
|
|
141
|
-
const cache = this.get(id);
|
|
142
|
-
if (cache.map) {
|
|
143
|
-
return cache.map;
|
|
144
|
-
}
|
|
145
|
-
const map = cache.code && extractSourceMap(cache.code);
|
|
146
|
-
if (map) {
|
|
147
|
-
cache.map = map;
|
|
148
|
-
return map;
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
36
|
+
normalizePath(fsPath) {
|
|
37
|
+
return normalizeModuleId(fsPath);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Assign partial data to the map
|
|
41
|
+
*/
|
|
42
|
+
update(fsPath, mod) {
|
|
43
|
+
fsPath = this.normalizePath(fsPath);
|
|
44
|
+
if (!super.has(fsPath)) this.setByModuleId(fsPath, mod);
|
|
45
|
+
else Object.assign(super.get(fsPath), mod);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
setByModuleId(modulePath, mod) {
|
|
49
|
+
return super.set(modulePath, mod);
|
|
50
|
+
}
|
|
51
|
+
set(fsPath, mod) {
|
|
52
|
+
return this.setByModuleId(this.normalizePath(fsPath), mod);
|
|
53
|
+
}
|
|
54
|
+
getByModuleId(modulePath) {
|
|
55
|
+
if (!super.has(modulePath)) this.setByModuleId(modulePath, {});
|
|
56
|
+
const mod = super.get(modulePath);
|
|
57
|
+
if (!mod.imports) Object.assign(mod, {
|
|
58
|
+
imports: new Set(),
|
|
59
|
+
importers: new Set()
|
|
60
|
+
});
|
|
61
|
+
return mod;
|
|
62
|
+
}
|
|
63
|
+
get(fsPath) {
|
|
64
|
+
return this.getByModuleId(this.normalizePath(fsPath));
|
|
65
|
+
}
|
|
66
|
+
deleteByModuleId(modulePath) {
|
|
67
|
+
return super.delete(modulePath);
|
|
68
|
+
}
|
|
69
|
+
delete(fsPath) {
|
|
70
|
+
return this.deleteByModuleId(this.normalizePath(fsPath));
|
|
71
|
+
}
|
|
72
|
+
invalidateModule(mod) {
|
|
73
|
+
var _mod$importers, _mod$imports;
|
|
74
|
+
delete mod.evaluated;
|
|
75
|
+
delete mod.resolving;
|
|
76
|
+
delete mod.promise;
|
|
77
|
+
delete mod.exports;
|
|
78
|
+
(_mod$importers = mod.importers) === null || _mod$importers === void 0 || _mod$importers.clear();
|
|
79
|
+
(_mod$imports = mod.imports) === null || _mod$imports === void 0 || _mod$imports.clear();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Invalidate modules that dependent on the given modules, up to the main entry
|
|
84
|
+
*/
|
|
85
|
+
invalidateDepTree(ids, invalidated = new Set()) {
|
|
86
|
+
for (const _id of ids) {
|
|
87
|
+
const id = this.normalizePath(_id);
|
|
88
|
+
if (invalidated.has(id)) continue;
|
|
89
|
+
invalidated.add(id);
|
|
90
|
+
const mod = super.get(id);
|
|
91
|
+
if (mod === null || mod === void 0 ? void 0 : mod.importers) this.invalidateDepTree(mod.importers, invalidated);
|
|
92
|
+
super.delete(id);
|
|
93
|
+
}
|
|
94
|
+
return invalidated;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Invalidate dependency modules of the given modules, down to the bottom-level dependencies
|
|
98
|
+
*/
|
|
99
|
+
invalidateSubDepTree(ids, invalidated = new Set()) {
|
|
100
|
+
for (const _id of ids) {
|
|
101
|
+
const id = this.normalizePath(_id);
|
|
102
|
+
if (invalidated.has(id)) continue;
|
|
103
|
+
invalidated.add(id);
|
|
104
|
+
const subIds = Array.from(super.entries()).filter(([, mod]) => {
|
|
105
|
+
var _mod$importers2;
|
|
106
|
+
return (_mod$importers2 = mod.importers) === null || _mod$importers2 === void 0 ? void 0 : _mod$importers2.has(id);
|
|
107
|
+
}).map(([key]) => key);
|
|
108
|
+
if (subIds.length) this.invalidateSubDepTree(subIds, invalidated);
|
|
109
|
+
super.delete(id);
|
|
110
|
+
}
|
|
111
|
+
return invalidated;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Return parsed source map based on inlined source map of the module
|
|
115
|
+
*/
|
|
116
|
+
getSourceMap(id) {
|
|
117
|
+
const cache = this.get(id);
|
|
118
|
+
if (cache.map) return cache.map;
|
|
119
|
+
const map = cache.code && extractSourceMap(cache.code);
|
|
120
|
+
if (map) {
|
|
121
|
+
cache.map = map;
|
|
122
|
+
return map;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
152
126
|
}
|
|
153
127
|
class ViteNodeRunner {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
shouldResolveId(id, _importee) {
|
|
215
|
-
return !isInternalRequest(id) && !isNodeBuiltin(id) && !id.startsWith("data:");
|
|
216
|
-
}
|
|
217
|
-
async _resolveUrl(id, importer) {
|
|
218
|
-
var _a, _b;
|
|
219
|
-
const dep = normalizeRequestId(id, this.options.base);
|
|
220
|
-
if (!this.shouldResolveId(dep)) {
|
|
221
|
-
return [dep, dep];
|
|
222
|
-
}
|
|
223
|
-
const { path, exists } = toFilePath(dep, this.root);
|
|
224
|
-
if (!this.options.resolveId || exists) {
|
|
225
|
-
return [dep, path];
|
|
226
|
-
}
|
|
227
|
-
const resolved = await this.options.resolveId(dep, importer);
|
|
228
|
-
if ((_b = (_a = resolved == null ? void 0 : resolved.meta) == null ? void 0 : _a["vite:alias"]) == null ? void 0 : _b.noResolved) {
|
|
229
|
-
const error = new Error(
|
|
230
|
-
`Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
|
|
128
|
+
root;
|
|
129
|
+
debug;
|
|
130
|
+
/**
|
|
131
|
+
* Holds the cache of modules
|
|
132
|
+
* Keys of the map are filepaths, or plain package names
|
|
133
|
+
*/
|
|
134
|
+
moduleCache;
|
|
135
|
+
constructor(options) {
|
|
136
|
+
this.options = options;
|
|
137
|
+
this.root = options.root ?? process.cwd();
|
|
138
|
+
this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
|
|
139
|
+
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
|
|
140
|
+
}
|
|
141
|
+
async executeFile(file) {
|
|
142
|
+
const url = `/@fs/${slash(resolve(file))}`;
|
|
143
|
+
return await this.cachedRequest(url, url, []);
|
|
144
|
+
}
|
|
145
|
+
async executeId(rawId) {
|
|
146
|
+
const [id, url] = await this.resolveUrl(rawId);
|
|
147
|
+
return await this.cachedRequest(id, url, []);
|
|
148
|
+
}
|
|
149
|
+
/** @internal */
|
|
150
|
+
async cachedRequest(id, fsPath, callstack) {
|
|
151
|
+
const importee = callstack[callstack.length - 1];
|
|
152
|
+
const mod = this.moduleCache.get(fsPath);
|
|
153
|
+
const { imports, importers } = mod;
|
|
154
|
+
if (importee) importers.add(importee);
|
|
155
|
+
const getStack = () => `stack:\n${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
|
|
156
|
+
if (callstack.includes(fsPath) || Array.from(imports.values()).some((i) => importers.has(i))) {
|
|
157
|
+
if (mod.exports) return mod.exports;
|
|
158
|
+
}
|
|
159
|
+
let debugTimer;
|
|
160
|
+
if (this.debug) debugTimer = setTimeout(() => console.warn(`[vite-node] module ${fsPath} takes over 2s to load.\n${getStack()}`), 2e3);
|
|
161
|
+
try {
|
|
162
|
+
if (mod.promise) return await mod.promise;
|
|
163
|
+
const promise = this.directRequest(id, fsPath, callstack);
|
|
164
|
+
Object.assign(mod, {
|
|
165
|
+
promise,
|
|
166
|
+
evaluated: false
|
|
167
|
+
});
|
|
168
|
+
return await promise;
|
|
169
|
+
} finally {
|
|
170
|
+
mod.evaluated = true;
|
|
171
|
+
if (debugTimer) clearTimeout(debugTimer);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
shouldResolveId(id, _importee) {
|
|
175
|
+
return !isInternalRequest(id) && !isNodeBuiltin(id) && !id.startsWith("data:");
|
|
176
|
+
}
|
|
177
|
+
async _resolveUrl(id, importer) {
|
|
178
|
+
var _resolved$meta;
|
|
179
|
+
const dep = normalizeRequestId(id, this.options.base);
|
|
180
|
+
if (!this.shouldResolveId(dep)) return [dep, dep];
|
|
181
|
+
const { path, exists } = toFilePath(dep, this.root);
|
|
182
|
+
if (!this.options.resolveId || exists) return [dep, path];
|
|
183
|
+
const resolved = await this.options.resolveId(dep, importer);
|
|
184
|
+
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) {
|
|
185
|
+
const error = new Error(`Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
|
|
231
186
|
|
|
232
187
|
- If you rely on tsconfig.json's "paths" to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
|
|
233
|
-
- Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (prop === "default") {
|
|
434
|
-
return defaultExport;
|
|
435
|
-
}
|
|
436
|
-
return mod2[prop] ?? (defaultExport == null ? void 0 : defaultExport[prop]);
|
|
437
|
-
},
|
|
438
|
-
has(mod2, prop) {
|
|
439
|
-
if (prop === "default") {
|
|
440
|
-
return defaultExport !== void 0;
|
|
441
|
-
}
|
|
442
|
-
return prop in mod2 || defaultExport && prop in defaultExport;
|
|
443
|
-
},
|
|
444
|
-
getOwnPropertyDescriptor(mod2, prop) {
|
|
445
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(mod2, prop);
|
|
446
|
-
if (descriptor) {
|
|
447
|
-
return descriptor;
|
|
448
|
-
}
|
|
449
|
-
if (prop === "default" && defaultExport !== void 0) {
|
|
450
|
-
return {
|
|
451
|
-
value: defaultExport,
|
|
452
|
-
enumerable: true,
|
|
453
|
-
configurable: true
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
}
|
|
188
|
+
- Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`);
|
|
189
|
+
Object.defineProperty(error, "code", {
|
|
190
|
+
value: "ERR_MODULE_NOT_FOUND",
|
|
191
|
+
enumerable: true
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), {
|
|
194
|
+
value: {
|
|
195
|
+
id: dep,
|
|
196
|
+
importer
|
|
197
|
+
},
|
|
198
|
+
enumerable: false
|
|
199
|
+
});
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : dep;
|
|
203
|
+
return [resolvedId, resolvedId];
|
|
204
|
+
}
|
|
205
|
+
async resolveUrl(id, importee) {
|
|
206
|
+
const resolveKey = `resolve:${id}`;
|
|
207
|
+
this.moduleCache.setByModuleId(resolveKey, { resolving: true });
|
|
208
|
+
try {
|
|
209
|
+
return await this._resolveUrl(id, importee);
|
|
210
|
+
} finally {
|
|
211
|
+
this.moduleCache.deleteByModuleId(resolveKey);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** @internal */
|
|
215
|
+
async dependencyRequest(id, fsPath, callstack) {
|
|
216
|
+
return await this.cachedRequest(id, fsPath, callstack);
|
|
217
|
+
}
|
|
218
|
+
/** @internal */
|
|
219
|
+
async directRequest(id, fsPath, _callstack) {
|
|
220
|
+
const moduleId = normalizeModuleId(fsPath);
|
|
221
|
+
const callstack = [..._callstack, moduleId];
|
|
222
|
+
const mod = this.moduleCache.getByModuleId(moduleId);
|
|
223
|
+
const request = async (dep) => {
|
|
224
|
+
const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
|
|
225
|
+
const depMod = this.moduleCache.getByModuleId(depFsPath);
|
|
226
|
+
depMod.importers.add(moduleId);
|
|
227
|
+
mod.imports.add(depFsPath);
|
|
228
|
+
return this.dependencyRequest(id, depFsPath, callstack);
|
|
229
|
+
};
|
|
230
|
+
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
231
|
+
if (id in requestStubs) return requestStubs[id];
|
|
232
|
+
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
233
|
+
if (externalize) {
|
|
234
|
+
debugNative(externalize);
|
|
235
|
+
const exports = await this.interopedImport(externalize);
|
|
236
|
+
mod.exports = exports;
|
|
237
|
+
return exports;
|
|
238
|
+
}
|
|
239
|
+
if (transformed == null) throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
|
|
240
|
+
const { Object, Reflect, Symbol } = this.getContextPrimitives();
|
|
241
|
+
const modulePath = cleanUrl(moduleId);
|
|
242
|
+
const href = pathToFileURL(modulePath).href;
|
|
243
|
+
const __filename = fileURLToPath(href);
|
|
244
|
+
const __dirname = dirname(__filename);
|
|
245
|
+
const meta = {
|
|
246
|
+
url: href,
|
|
247
|
+
env,
|
|
248
|
+
filename: __filename,
|
|
249
|
+
dirname: __dirname
|
|
250
|
+
};
|
|
251
|
+
const exports = Object.create(null);
|
|
252
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
253
|
+
value: "Module",
|
|
254
|
+
enumerable: false,
|
|
255
|
+
configurable: false
|
|
256
|
+
});
|
|
257
|
+
const SYMBOL_NOT_DEFINED = Symbol("not defined");
|
|
258
|
+
let moduleExports = SYMBOL_NOT_DEFINED;
|
|
259
|
+
const cjsExports = new Proxy(exports, {
|
|
260
|
+
get: (target, p, receiver) => {
|
|
261
|
+
if (Reflect.has(target, p)) return Reflect.get(target, p, receiver);
|
|
262
|
+
return Reflect.get(Object.prototype, p, receiver);
|
|
263
|
+
},
|
|
264
|
+
getPrototypeOf: () => Object.prototype,
|
|
265
|
+
set: (_, p, value) => {
|
|
266
|
+
if (p === "default" && this.shouldInterop(modulePath, { default: value }) && cjsExports !== value) {
|
|
267
|
+
exportAll(cjsExports, value);
|
|
268
|
+
exports.default = value;
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
if (!Reflect.has(exports, "default")) exports.default = {};
|
|
272
|
+
if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {
|
|
273
|
+
defineExport(exports, p, () => void 0);
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
if (!isPrimitive(exports.default)) exports.default[p] = value;
|
|
277
|
+
if (p !== "default") defineExport(exports, p, () => value);
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
Object.assign(mod, {
|
|
282
|
+
code: transformed,
|
|
283
|
+
exports
|
|
284
|
+
});
|
|
285
|
+
const moduleProxy = {
|
|
286
|
+
set exports(value) {
|
|
287
|
+
exportAll(cjsExports, value);
|
|
288
|
+
exports.default = value;
|
|
289
|
+
moduleExports = value;
|
|
290
|
+
},
|
|
291
|
+
get exports() {
|
|
292
|
+
return cjsExports;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
let hotContext;
|
|
296
|
+
if (this.options.createHotContext) Object.defineProperty(meta, "hot", {
|
|
297
|
+
enumerable: true,
|
|
298
|
+
get: () => {
|
|
299
|
+
var _this$options$createH, _this$options;
|
|
300
|
+
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));
|
|
301
|
+
return hotContext;
|
|
302
|
+
},
|
|
303
|
+
set: (value) => {
|
|
304
|
+
hotContext = value;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
const context = this.prepareContext({
|
|
308
|
+
__vite_ssr_import__: request,
|
|
309
|
+
__vite_ssr_dynamic_import__: request,
|
|
310
|
+
__vite_ssr_exports__: exports,
|
|
311
|
+
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
312
|
+
__vite_ssr_import_meta__: meta,
|
|
313
|
+
require: createRequire(href),
|
|
314
|
+
exports: cjsExports,
|
|
315
|
+
module: moduleProxy,
|
|
316
|
+
__filename,
|
|
317
|
+
__dirname
|
|
318
|
+
});
|
|
319
|
+
debugExecute(__filename);
|
|
320
|
+
if (transformed[0] === "#") transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
|
|
321
|
+
await this.runModule(context, transformed);
|
|
322
|
+
return exports;
|
|
323
|
+
}
|
|
324
|
+
getContextPrimitives() {
|
|
325
|
+
return {
|
|
326
|
+
Object,
|
|
327
|
+
Reflect,
|
|
328
|
+
Symbol
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
async runModule(context, transformed) {
|
|
332
|
+
var _this$options$moduleE;
|
|
333
|
+
const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
|
|
334
|
+
const code = `${codeDefinition}${transformed}\n}}`;
|
|
335
|
+
const options = {
|
|
336
|
+
filename: context.__filename,
|
|
337
|
+
lineOffset: 0,
|
|
338
|
+
columnOffset: -codeDefinition.length
|
|
339
|
+
};
|
|
340
|
+
(_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, { startOffset: codeDefinition.length });
|
|
341
|
+
const fn = vm.runInThisContext(code, options);
|
|
342
|
+
await fn(...Object.values(context));
|
|
343
|
+
}
|
|
344
|
+
prepareContext(context) {
|
|
345
|
+
return context;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Define if a module should be interop-ed
|
|
349
|
+
* This function mostly for the ability to override by subclass
|
|
350
|
+
*/
|
|
351
|
+
shouldInterop(path, mod) {
|
|
352
|
+
if (this.options.interopDefault === false) return false;
|
|
353
|
+
return !path.endsWith(".mjs") && "default" in mod;
|
|
354
|
+
}
|
|
355
|
+
importExternalModule(path) {
|
|
356
|
+
return import(
|
|
357
|
+
/* @vite-ignore */
|
|
358
|
+
path
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Import a module and interop it
|
|
363
|
+
*/
|
|
364
|
+
async interopedImport(path) {
|
|
365
|
+
const importedModule = await this.importExternalModule(path);
|
|
366
|
+
if (!this.shouldInterop(path, importedModule)) return importedModule;
|
|
367
|
+
const { mod, defaultExport } = interopModule(importedModule);
|
|
368
|
+
return new Proxy(mod, {
|
|
369
|
+
get(mod, prop) {
|
|
370
|
+
if (prop === "default") return defaultExport;
|
|
371
|
+
return mod[prop] ?? (defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport[prop]);
|
|
372
|
+
},
|
|
373
|
+
has(mod, prop) {
|
|
374
|
+
if (prop === "default") return defaultExport !== void 0;
|
|
375
|
+
return prop in mod || defaultExport && prop in defaultExport;
|
|
376
|
+
},
|
|
377
|
+
getOwnPropertyDescriptor(mod, prop) {
|
|
378
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
|
|
379
|
+
if (descriptor) return descriptor;
|
|
380
|
+
if (prop === "default" && defaultExport !== void 0) return {
|
|
381
|
+
value: defaultExport,
|
|
382
|
+
enumerable: true,
|
|
383
|
+
configurable: true
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
459
388
|
}
|
|
460
389
|
function interopModule(mod) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
return { mod, defaultExport };
|
|
390
|
+
if (isPrimitive(mod)) return {
|
|
391
|
+
mod: { default: mod },
|
|
392
|
+
defaultExport: mod
|
|
393
|
+
};
|
|
394
|
+
let defaultExport = "default" in mod ? mod.default : mod;
|
|
395
|
+
if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {
|
|
396
|
+
mod = defaultExport;
|
|
397
|
+
if ("default" in defaultExport) defaultExport = defaultExport.default;
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
mod,
|
|
401
|
+
defaultExport
|
|
402
|
+
};
|
|
475
403
|
}
|
|
476
404
|
function defineExport(exports, key, value) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
405
|
+
Object.defineProperty(exports, key, {
|
|
406
|
+
enumerable: true,
|
|
407
|
+
configurable: true,
|
|
408
|
+
get: value
|
|
409
|
+
});
|
|
482
410
|
}
|
|
483
411
|
function exportAll(exports, sourceModule) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
for (const key in sourceModule) {
|
|
491
|
-
if (key !== "default") {
|
|
492
|
-
try {
|
|
493
|
-
defineExport(exports, key, () => sourceModule[key]);
|
|
494
|
-
} catch {
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
412
|
+
if (exports === sourceModule) return;
|
|
413
|
+
if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
|
|
414
|
+
for (const key in sourceModule) if (key !== "default") try {
|
|
415
|
+
defineExport(exports, key, () => sourceModule[key]);
|
|
416
|
+
} catch {}
|
|
498
417
|
}
|
|
499
418
|
|
|
500
419
|
export { DEFAULT_REQUEST_STUBS, ModuleCacheMap, ViteNodeRunner };
|