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