vite-node 5.2.0 → 6.0.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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://github.com/antfu/vite-node/blob/main/assets/vite-node.svg?raw=true" height="120">
2
+ <img src="https://raw.githubusercontent.com/antfu-collective/vite-node/refs/heads/main/assets/vite-node.svg" alt="vite-node logo" height="120">
3
3
  </p>
4
4
 
5
5
  <h1 align="center">
@@ -10,7 +10,7 @@ Vite as Node runtime.<br>The engine that powers <a href="https://github.com/nuxt
10
10
 
11
11
  <p>
12
12
  <p align="center">
13
- <a href="https://www.npmjs.com/package/vite-node"><img src="https://img.shields.io/npm/v/vite-node?color=FCC72B&label="></a>
13
+ <a href="https://npmx.dev/package/vite-node"><img src="https://img.shields.io/npm/v/vite-node?color=FCC72B&label=" alt="vite-node"></a>
14
14
  <p>
15
15
 
16
16
  > [!NOTE]
@@ -188,7 +188,7 @@ Thanks [@brillout](https://github.com/brillout) for kindly sharing this package
188
188
 
189
189
  <p align="center">
190
190
  <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
191
- <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
191
+ <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt="Sponsors" />
192
192
  </a>
193
193
  </p>
194
194
 
package/dist/cli.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as ViteNodeServerOptions } from "./types-Dtew7m7O.mjs";
1
+ import { _ as ViteNodeServerOptions } from "./types-Bl6mw_Ii.mjs";
2
2
 
3
3
  //#region src/cli.d.ts
4
4
  interface CliOptions {
package/dist/cli.mjs CHANGED
@@ -1,19 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { t as C } from "./dist-B2ebky9O.mjs";
3
- import { t as ViteNodeServer } from "./server-BWywEVuB.mjs";
4
- import "./constants-DRkacFwN.mjs";
5
- import { h as toArray } from "./utils-ExLpYVUV.mjs";
6
- import { n as installSourcemapsSupport } from "./source-map-DQLD3K8K.mjs";
7
- import { r as ViteNodeRunner } from "./client-CyS7w_FB.mjs";
8
- import { r as handleMessage, s as viteNodeHmrPlugin, t as createHotContext } from "./hmr-qEG3qSgW.mjs";
2
+ import { t as y } from "./dist-2eHC7DTD.mjs";
3
+ import { t as ViteNodeServer } from "./server-Bdy4M7lM.mjs";
4
+ import { toArray } from "./utils.mjs";
5
+ import { n as installSourcemapsSupport } from "./source-map-BFKsz_pY.mjs";
6
+ import { ViteNodeRunner } from "./client.mjs";
7
+ import { createHotContext, handleMessage, viteNodeHmrPlugin } from "./hmr.mjs";
9
8
  import process from "node:process";
10
9
  import { createServer, loadEnv, version } from "vite";
11
10
  import { resolve } from "node:path";
12
11
  import cac from "cac";
13
-
14
12
  //#region package.json
15
- var version$1 = "5.2.0";
16
-
13
+ var version$1 = "6.0.0";
17
14
  //#endregion
18
15
  //#region src/cli.ts
19
16
  const cli = cac("vite-node");
@@ -56,7 +53,7 @@ async function run(files, options = {}) {
56
53
  process.exit(0);
57
54
  }
58
55
  if (!files.length) {
59
- console.error(C.red("No files specified."));
56
+ console.error(y.red("No files specified."));
60
57
  cli.version(version$1).outputHelp();
61
58
  process.exit(1);
62
59
  }
@@ -87,8 +84,8 @@ async function run(files, options = {}) {
87
84
  resolveId(id, importer) {
88
85
  return node.resolveId(id, importer);
89
86
  },
90
- createHotContext(runner$1, url) {
91
- return createHotContext(runner$1, server.emitter, files, url);
87
+ createHotContext(runner, url) {
88
+ return createHotContext(runner, server.emitter, files, url);
92
89
  }
93
90
  });
94
91
  await runner.executeId("/@vite/env");
@@ -99,12 +96,12 @@ async function run(files, options = {}) {
99
96
  });
100
97
  if (options.watch) {
101
98
  process.on("uncaughtException", (err) => {
102
- console.error(C.red("[vite-node] Failed to execute file: \n"), err);
99
+ console.error(y.red("[vite-node] Failed to execute file: \n"), err);
103
100
  });
104
101
  if (process.env.VITE_TEST_WATCHER_DEBUG) {
105
102
  const nodePath = await import("node:path");
106
- async function waitForWatched(files$1) {
107
- while (!files$1.every((file) => isWatched(file))) await new Promise((resolve$1) => setTimeout(resolve$1, 20));
103
+ async function waitForWatched(files) {
104
+ while (!files.every((file) => isWatched(file))) await new Promise((resolve) => setTimeout(resolve, 20));
108
105
  }
109
106
  function isWatched(file) {
110
107
  const watched = server.watcher.getWatched();
@@ -140,6 +137,5 @@ function parseServerOptions(serverOptions) {
140
137
  }
141
138
  };
142
139
  }
143
-
144
140
  //#endregion
145
- export { };
141
+ export {};
package/dist/client.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as ModuleExecutionInfo, S as ModuleCacheMap, T as ViteNodeRunner, w as ModuleExecutionInfoEntry, x as DEFAULT_REQUEST_STUBS } from "./types-Dtew7m7O.mjs";
1
+ import { S as ViteNodeRunner, b as ModuleExecutionInfo, v as DEFAULT_REQUEST_STUBS, x as ModuleExecutionInfoEntry, y as ModuleCacheMap } from "./types-Bl6mw_Ii.mjs";
2
2
  export { DEFAULT_REQUEST_STUBS, ModuleCacheMap, ModuleExecutionInfo, ModuleExecutionInfoEntry, ViteNodeRunner };
package/dist/client.mjs CHANGED
@@ -1,5 +1,503 @@
1
- import "./utils-ExLpYVUV.mjs";
2
- import "./source-map-DQLD3K8K.mjs";
3
- import { n as ModuleCacheMap, r as ViteNodeRunner, t as DEFAULT_REQUEST_STUBS } from "./client-CyS7w_FB.mjs";
1
+ import { cleanUrl, createImportMetaEnvProxy, isBareImport, isInternalRequest, isNodeBuiltin, isPrimitive, normalizeModuleId, normalizeRequestId, slash, toFilePath } from "./utils.mjs";
2
+ import { a as originalPositionFor, i as TraceMap, t as extractSourceMap } from "./source-map-BFKsz_pY.mjs";
3
+ import { createRequire } from "node:module";
4
+ import process from "node:process";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
+ import { createDebug } from "obug";
7
+ import { dirname, resolve } from "node:path";
8
+ import vm from "node:vm";
9
+ //#region src/client.ts
10
+ const { setTimeout, clearTimeout } = globalThis;
11
+ const debugExecute = createDebug("vite-node:client:execute");
12
+ const debugNative = createDebug("vite-node:client:native");
13
+ const clientStub = {
14
+ injectQuery: (id) => id,
15
+ createHotContext: () => {
16
+ return {
17
+ accept: () => {},
18
+ prune: () => {},
19
+ dispose: () => {},
20
+ decline: () => {},
21
+ invalidate: () => {},
22
+ on: () => {},
23
+ send: () => {}
24
+ };
25
+ },
26
+ updateStyle: () => {},
27
+ removeStyle: () => {}
28
+ };
29
+ const env = createImportMetaEnvProxy();
30
+ const DEFAULT_REQUEST_STUBS = {
31
+ "/@vite/client": clientStub,
32
+ "@vite/client": clientStub
33
+ };
34
+ var ModuleCacheMap = class extends Map {
35
+ normalizePath(fsPath) {
36
+ return normalizeModuleId(fsPath);
37
+ }
38
+ /**
39
+ * Assign partial data to the map
40
+ */
41
+ update(fsPath, mod) {
42
+ fsPath = this.normalizePath(fsPath);
43
+ if (!super.has(fsPath)) this.setByModuleId(fsPath, mod);
44
+ else Object.assign(super.get(fsPath), mod);
45
+ return this;
46
+ }
47
+ setByModuleId(modulePath, mod) {
48
+ return super.set(modulePath, mod);
49
+ }
50
+ set(fsPath, mod) {
51
+ return this.setByModuleId(this.normalizePath(fsPath), mod);
52
+ }
53
+ getByModuleId(modulePath) {
54
+ if (!super.has(modulePath)) this.setByModuleId(modulePath, {});
55
+ const mod = super.get(modulePath);
56
+ if (!mod.imports) Object.assign(mod, {
57
+ imports: /* @__PURE__ */ new Set(),
58
+ importers: /* @__PURE__ */ new Set()
59
+ });
60
+ return mod;
61
+ }
62
+ get(fsPath) {
63
+ return this.getByModuleId(this.normalizePath(fsPath));
64
+ }
65
+ deleteByModuleId(modulePath) {
66
+ return super.delete(modulePath);
67
+ }
68
+ delete(fsPath) {
69
+ return this.deleteByModuleId(this.normalizePath(fsPath));
70
+ }
71
+ invalidateModule(mod) {
72
+ delete mod.evaluated;
73
+ delete mod.resolving;
74
+ delete mod.promise;
75
+ delete mod.exports;
76
+ mod.importers?.clear();
77
+ mod.imports?.clear();
78
+ return true;
79
+ }
80
+ /**
81
+ * Invalidate modules that dependent on the given modules, up to the main entry
82
+ */
83
+ invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
84
+ for (const _id of ids) {
85
+ const id = this.normalizePath(_id);
86
+ if (invalidated.has(id)) continue;
87
+ invalidated.add(id);
88
+ const mod = super.get(id);
89
+ if (mod?.importers) this.invalidateDepTree(mod.importers, invalidated);
90
+ super.delete(id);
91
+ }
92
+ return invalidated;
93
+ }
94
+ /**
95
+ * Invalidate dependency modules of the given modules, down to the bottom-level dependencies
96
+ */
97
+ invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
98
+ for (const _id of ids) {
99
+ const id = this.normalizePath(_id);
100
+ if (invalidated.has(id)) continue;
101
+ invalidated.add(id);
102
+ const subIds = [...super.entries()].filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
103
+ if (subIds.length) this.invalidateSubDepTree(subIds, invalidated);
104
+ super.delete(id);
105
+ }
106
+ return invalidated;
107
+ }
108
+ /**
109
+ * Return parsed source map based on inlined source map of the module
110
+ */
111
+ getSourceMap(id) {
112
+ const cache = this.get(id);
113
+ if (cache.map) return cache.map;
114
+ const map = cache.code && extractSourceMap(cache.code);
115
+ if (map) {
116
+ cache.map = map;
117
+ return map;
118
+ }
119
+ return null;
120
+ }
121
+ };
122
+ var ViteNodeRunner = class {
123
+ root;
124
+ debug;
125
+ /**
126
+ * Holds the cache of modules
127
+ * Keys of the map are filepaths, or plain package names
128
+ */
129
+ moduleCache;
130
+ /**
131
+ * Tracks the stack of modules being executed for the purpose of calculating import self-time.
132
+ *
133
+ * Note that while in most cases, imports are a linear stack of modules,
134
+ * this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
135
+ *
136
+ * ```ts
137
+ * await Promise.all([
138
+ * import('./module1'),
139
+ * import('./module2'),
140
+ * ]);
141
+ * ```
142
+ *
143
+ * In this case, the self time will be reported incorrectly for one of the modules (could go negative).
144
+ * As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
145
+ */
146
+ executionStack = [];
147
+ performanceNow = performance.now.bind(performance);
148
+ constructor(options) {
149
+ this.options = options;
150
+ this.root = options.root ?? process.cwd();
151
+ this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
152
+ this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
153
+ }
154
+ async executeFile(file) {
155
+ const url = `/@fs/${slash(resolve(file))}`;
156
+ return await this.cachedRequest(url, url, []);
157
+ }
158
+ async executeId(rawId) {
159
+ const [id, url] = await this.resolveUrl(rawId);
160
+ return await this.cachedRequest(id, url, []);
161
+ }
162
+ /** @internal */
163
+ async cachedRequest(id, fsPath, callstack) {
164
+ const importee = callstack.at(-1);
165
+ const mod = this.moduleCache.get(fsPath);
166
+ const { imports, importers } = mod;
167
+ if (importee) importers.add(importee);
168
+ const getStack = () => `stack:\n${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
169
+ if (callstack.includes(fsPath) || [...imports.values()].some((i) => importers.has(i))) {
170
+ if (mod.exports) return mod.exports;
171
+ }
172
+ let debugTimer;
173
+ if (this.debug) debugTimer = setTimeout(() => console.warn(`[vite-node] module ${fsPath} takes over 2s to load.\n${getStack()}`), 2e3);
174
+ try {
175
+ if (mod.promise) return await mod.promise;
176
+ const promise = this.directRequest(id, fsPath, callstack);
177
+ Object.assign(mod, {
178
+ promise,
179
+ evaluated: false
180
+ });
181
+ return await promise;
182
+ } finally {
183
+ mod.evaluated = true;
184
+ if (debugTimer) clearTimeout(debugTimer);
185
+ }
186
+ }
187
+ shouldResolveId(id, _importee) {
188
+ return !isInternalRequest(id) && !isNodeBuiltin(id) && !id.startsWith("data:");
189
+ }
190
+ async _resolveUrl(id, importer) {
191
+ const dep = normalizeRequestId(id, this.options.base);
192
+ if (!this.shouldResolveId(dep)) return [dep, dep];
193
+ const { path, exists } = toFilePath(dep, this.root);
194
+ if (!this.options.resolveId || exists) return [dep, path];
195
+ const resolved = await this.options.resolveId(dep, importer);
196
+ if (resolved?.meta?.["vite:alias"]?.noResolved) {
197
+ const error = /* @__PURE__ */ new Error(`Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
4
198
 
5
- export { DEFAULT_REQUEST_STUBS, ModuleCacheMap, ViteNodeRunner };
199
+ - If you rely on tsconfig.json's "paths" to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
200
+ - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`);
201
+ Object.defineProperty(error, "code", {
202
+ value: "ERR_MODULE_NOT_FOUND",
203
+ enumerable: true
204
+ });
205
+ Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), {
206
+ value: {
207
+ id: dep,
208
+ importer
209
+ },
210
+ enumerable: false
211
+ });
212
+ throw error;
213
+ }
214
+ const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : dep;
215
+ return [resolvedId, resolvedId];
216
+ }
217
+ async resolveUrl(id, importee) {
218
+ const resolveKey = `resolve:${id}`;
219
+ this.moduleCache.setByModuleId(resolveKey, { resolving: true });
220
+ try {
221
+ return await this._resolveUrl(id, importee);
222
+ } finally {
223
+ this.moduleCache.deleteByModuleId(resolveKey);
224
+ }
225
+ }
226
+ /** @internal */
227
+ async dependencyRequest(id, fsPath, callstack) {
228
+ return await this.cachedRequest(id, fsPath, callstack);
229
+ }
230
+ async _fetchModule(id, importer) {
231
+ try {
232
+ return await this.options.fetchModule(id);
233
+ } catch (cause) {
234
+ if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url")) {
235
+ const error = new Error(`Cannot find ${isBareImport(id) ? "package" : "module"} '${id}'${importer ? ` imported from '${importer}'` : ""}`, { cause });
236
+ error.code = "ERR_MODULE_NOT_FOUND";
237
+ throw error;
238
+ }
239
+ throw cause;
240
+ }
241
+ }
242
+ /** @internal */
243
+ async directRequest(id, fsPath, _callstack) {
244
+ const moduleId = normalizeModuleId(fsPath);
245
+ const callstack = [..._callstack, moduleId];
246
+ const mod = this.moduleCache.getByModuleId(moduleId);
247
+ const request = async (dep) => {
248
+ const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
249
+ this.moduleCache.getByModuleId(depFsPath).importers.add(moduleId);
250
+ mod.imports.add(depFsPath);
251
+ return this.dependencyRequest(id, depFsPath, callstack);
252
+ };
253
+ const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
254
+ if (id in requestStubs) return requestStubs[id];
255
+ let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
256
+ if (externalize) {
257
+ debugNative(externalize);
258
+ const exports = await this.interopedImport(externalize);
259
+ mod.exports = exports;
260
+ return exports;
261
+ }
262
+ if (transformed == null) throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
263
+ const { Object, Reflect, Symbol } = this.getContextPrimitives();
264
+ const modulePath = cleanUrl(moduleId);
265
+ const href = pathToFileURL(modulePath).href;
266
+ const __filename = fileURLToPath(href);
267
+ const __dirname = dirname(__filename);
268
+ const meta = {
269
+ url: href,
270
+ env,
271
+ filename: __filename,
272
+ dirname: __dirname
273
+ };
274
+ const exports = Object.create(null);
275
+ Object.defineProperty(exports, Symbol.toStringTag, {
276
+ value: "Module",
277
+ enumerable: false,
278
+ configurable: false
279
+ });
280
+ const SYMBOL_NOT_DEFINED = Symbol("not defined");
281
+ let moduleExports = SYMBOL_NOT_DEFINED;
282
+ const cjsExports = new Proxy(exports, {
283
+ get: (target, p, receiver) => {
284
+ if (Reflect.has(target, p)) return Reflect.get(target, p, receiver);
285
+ return Reflect.get(Object.prototype, p, receiver);
286
+ },
287
+ getPrototypeOf: () => Object.prototype,
288
+ set: (_, p, value) => {
289
+ if (p === "default" && this.shouldInterop(modulePath, { default: value }) && cjsExports !== value) {
290
+ exportAll(cjsExports, value);
291
+ exports.default = value;
292
+ return true;
293
+ }
294
+ if (!Reflect.has(exports, "default")) exports.default = {};
295
+ if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {
296
+ defineExport(exports, p, () => void 0);
297
+ return true;
298
+ }
299
+ if (!isPrimitive(exports.default)) exports.default[p] = value;
300
+ if (p !== "default") defineExport(exports, p, () => value);
301
+ return true;
302
+ }
303
+ });
304
+ Object.assign(mod, {
305
+ code: transformed,
306
+ exports
307
+ });
308
+ const moduleProxy = {
309
+ set exports(value) {
310
+ exportAll(cjsExports, value);
311
+ exports.default = value;
312
+ moduleExports = value;
313
+ },
314
+ get exports() {
315
+ return cjsExports;
316
+ }
317
+ };
318
+ let hotContext;
319
+ if (this.options.createHotContext) Object.defineProperty(meta, "hot", {
320
+ enumerable: true,
321
+ get: () => {
322
+ hotContext ||= this.options.createHotContext?.(this, moduleId);
323
+ return hotContext;
324
+ },
325
+ set: (value) => {
326
+ hotContext = value;
327
+ }
328
+ });
329
+ const context = this.prepareContext({
330
+ __vite_ssr_import__: request,
331
+ __vite_ssr_dynamic_import__: request,
332
+ __vite_ssr_exports__: exports,
333
+ __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
334
+ __vite_ssr_exportName__: (name, getter) => Object.defineProperty(exports, name, {
335
+ enumerable: true,
336
+ configurable: true,
337
+ get: getter
338
+ }),
339
+ __vite_ssr_import_meta__: meta,
340
+ require: createRequire(href),
341
+ exports: cjsExports,
342
+ module: moduleProxy,
343
+ __filename,
344
+ __dirname
345
+ });
346
+ debugExecute(__filename);
347
+ if (transformed[0] === "#") transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
348
+ await this.runModule(context, transformed);
349
+ return exports;
350
+ }
351
+ getContextPrimitives() {
352
+ return {
353
+ Object,
354
+ Reflect,
355
+ Symbol
356
+ };
357
+ }
358
+ async runModule(context, transformed) {
359
+ const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
360
+ const code = `${codeDefinition}${transformed}\n}}`;
361
+ const options = {
362
+ filename: context.__filename,
363
+ lineOffset: 0,
364
+ columnOffset: -codeDefinition.length
365
+ };
366
+ const finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
367
+ try {
368
+ await vm.runInThisContext(code, options)(...Object.values(context));
369
+ } finally {
370
+ this.options.moduleExecutionInfo?.set(options.filename, finishModuleExecutionInfo());
371
+ }
372
+ }
373
+ /**
374
+ * mutate the given error to have fixed stacktraces based on source maps
375
+ * Does the same thing as Vite's ssrFixStacktrace
376
+ */
377
+ async ssrFixStacktrace(error) {
378
+ const stack = (error.stack || "").split("\n");
379
+ const rewrittenStack = [];
380
+ for (const line of stack) {
381
+ const match = line.match(/\((.*):(\d+):(\d+)\)$/);
382
+ if (match) {
383
+ const [, file, lineStr, columnStr] = match;
384
+ const lineNum = Number(lineStr);
385
+ const columnNum = Number(columnStr);
386
+ const sourceMap = this.moduleCache.getSourceMap(file);
387
+ if (sourceMap) {
388
+ const originalPos = originalPositionFor(new TraceMap(sourceMap), {
389
+ line: lineNum,
390
+ column: columnNum
391
+ });
392
+ if (originalPos.source) {
393
+ const rewrittenLine = line.replace(/\(.*:\d+:\d+\)$/, `(${file}:${originalPos.line || lineNum}:${originalPos.column || columnNum})`);
394
+ rewrittenStack.push(rewrittenLine);
395
+ continue;
396
+ }
397
+ }
398
+ }
399
+ rewrittenStack.push(line);
400
+ }
401
+ error.stack = rewrittenStack.join("\n") || error.stack;
402
+ return error;
403
+ }
404
+ /**
405
+ * Starts calculating the module execution info such as the total duration and self time spent on executing the module.
406
+ * Returns a function to call once the module has finished executing.
407
+ */
408
+ startCalculateModuleExecutionInfo(filename, startOffset) {
409
+ const startTime = this.performanceNow();
410
+ this.executionStack.push({
411
+ filename,
412
+ startTime,
413
+ subImportTime: 0
414
+ });
415
+ return () => {
416
+ const duration = this.performanceNow() - startTime;
417
+ const currentExecution = this.executionStack.pop();
418
+ if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
419
+ const selfTime = duration - currentExecution.subImportTime;
420
+ if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
421
+ return {
422
+ startOffset,
423
+ duration,
424
+ selfTime
425
+ };
426
+ };
427
+ }
428
+ prepareContext(context) {
429
+ return context;
430
+ }
431
+ /**
432
+ * Define if a module should be interop-ed
433
+ * This function mostly for the ability to override by subclass
434
+ */
435
+ shouldInterop(path, mod) {
436
+ if (this.options.interopDefault === false) return false;
437
+ return !path.endsWith(".mjs") && "default" in mod;
438
+ }
439
+ importExternalModule(path) {
440
+ return import(
441
+ /* @vite-ignore */
442
+ path
443
+ );
444
+ }
445
+ /**
446
+ * Import a module and interop it
447
+ */
448
+ async interopedImport(path) {
449
+ const importedModule = await this.importExternalModule(path);
450
+ if (!this.shouldInterop(path, importedModule)) return importedModule;
451
+ const { mod, defaultExport } = interopModule(importedModule);
452
+ return new Proxy(mod, {
453
+ get(mod, prop) {
454
+ if (prop === "default") return defaultExport;
455
+ return mod[prop] ?? defaultExport?.[prop];
456
+ },
457
+ has(mod, prop) {
458
+ if (prop === "default") return defaultExport !== void 0;
459
+ return prop in mod || defaultExport && prop in defaultExport;
460
+ },
461
+ getOwnPropertyDescriptor(mod, prop) {
462
+ const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
463
+ if (descriptor) return descriptor;
464
+ if (prop === "default" && defaultExport !== void 0) return {
465
+ value: defaultExport,
466
+ enumerable: true,
467
+ configurable: true
468
+ };
469
+ }
470
+ });
471
+ }
472
+ };
473
+ function interopModule(mod) {
474
+ if (isPrimitive(mod)) return {
475
+ mod: { default: mod },
476
+ defaultExport: mod
477
+ };
478
+ let defaultExport = "default" in mod ? mod.default : mod;
479
+ if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {
480
+ mod = defaultExport;
481
+ if ("default" in defaultExport) defaultExport = defaultExport.default;
482
+ }
483
+ return {
484
+ mod,
485
+ defaultExport
486
+ };
487
+ }
488
+ function defineExport(exports, key, value) {
489
+ Object.defineProperty(exports, key, {
490
+ enumerable: true,
491
+ configurable: true,
492
+ get: value
493
+ });
494
+ }
495
+ function exportAll(exports, sourceModule) {
496
+ if (exports === sourceModule) return;
497
+ if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
498
+ for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
499
+ defineExport(exports, key, () => sourceModule[key]);
500
+ } catch {}
501
+ }
502
+ //#endregion
503
+ export { DEFAULT_REQUEST_STUBS, ModuleCacheMap, ViteNodeRunner };
@@ -1,3 +1,33 @@
1
- import { n as KNOWN_ASSET_RE, r as KNOWN_ASSET_TYPES, t as CSS_LANGS_RE } from "./constants-DRkacFwN.mjs";
2
-
3
- export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES };
1
+ //#region src/constants.ts
2
+ const KNOWN_ASSET_TYPES = [
3
+ "apng",
4
+ "bmp",
5
+ "png",
6
+ "jpe?g",
7
+ "jfif",
8
+ "pjpeg",
9
+ "pjp",
10
+ "gif",
11
+ "svg",
12
+ "ico",
13
+ "webp",
14
+ "avif",
15
+ "mp4",
16
+ "webm",
17
+ "ogg",
18
+ "mp3",
19
+ "wav",
20
+ "flac",
21
+ "aac",
22
+ "woff2?",
23
+ "eot",
24
+ "ttf",
25
+ "otf",
26
+ "webmanifest",
27
+ "pdf",
28
+ "txt"
29
+ ];
30
+ const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
31
+ const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
32
+ //#endregion
33
+ export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES };