vite-node 0.25.8 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -17,6 +17,7 @@ require('mlly');
17
17
  require('url');
18
18
  require('source-map-support');
19
19
  require('module');
20
+ require('path');
20
21
  require('vm');
21
22
 
22
23
  function toArr(any) {
@@ -632,7 +633,7 @@ class CAC extends events.EventEmitter {
632
633
 
633
634
  const cac = (name = "") => new CAC(name);
634
635
 
635
- var version = "0.25.8";
636
+ var version = "0.26.0";
636
637
 
637
638
  const cli = cac("vite-node");
638
639
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { e as ViteNodeServerOptions } from './types-fc7e68bc.js';
1
+ import { e as ViteNodeServerOptions } from './types-aaf02e1c.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
package/dist/cli.mjs CHANGED
@@ -15,6 +15,7 @@ import 'mlly';
15
15
  import 'url';
16
16
  import 'source-map-support';
17
17
  import 'module';
18
+ import 'path';
18
19
  import 'vm';
19
20
 
20
21
  function toArr(any) {
@@ -630,7 +631,7 @@ class CAC extends EventEmitter {
630
631
 
631
632
  const cac = (name = "") => new CAC(name);
632
633
 
633
- var version = "0.25.8";
634
+ var version = "0.26.0";
634
635
 
635
636
  const cli = cac("vite-node");
636
637
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
package/dist/client.cjs CHANGED
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var module$1 = require('module');
6
+ var path = require('path');
6
7
  var url = require('url');
7
8
  var vm = require('vm');
8
9
  var pathe = require('pathe');
9
- var mlly = require('mlly');
10
10
  var createDebug = require('debug');
11
11
  var utils = require('./utils.cjs');
12
12
  var sourceMap = require('./source-map.cjs');
@@ -146,19 +146,19 @@ class ViteNodeRunner {
146
146
  this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
147
147
  }
148
148
  async executeFile(file) {
149
- return await this.cachedRequest(`/@fs/${utils.slash(pathe.resolve(file))}`, []);
149
+ const url = `/@fs/${utils.slash(pathe.resolve(file))}`;
150
+ return await this.cachedRequest(url, url, []);
150
151
  }
151
- async executeId(id) {
152
- return await this.cachedRequest(id, []);
152
+ async executeId(rawId) {
153
+ const [id, url] = await this.resolveUrl(rawId);
154
+ return await this.cachedRequest(id, url, []);
153
155
  }
154
156
  getSourceMap(id) {
155
157
  return this.moduleCache.getSourceMap(id);
156
158
  }
157
- async cachedRequest(rawId, callstack) {
158
- const id = utils.normalizeRequestId(rawId, this.options.base);
159
- const fsPath = utils.toFilePath(id, this.root);
160
- const mod = this.moduleCache.get(fsPath);
159
+ async cachedRequest(id, fsPath, callstack) {
161
160
  const importee = callstack[callstack.length - 1];
161
+ const mod = this.moduleCache.get(fsPath);
162
162
  if (!mod.importers)
163
163
  mod.importers = /* @__PURE__ */ new Set();
164
164
  if (importee)
@@ -175,63 +175,54 @@ class ViteNodeRunner {
175
175
  mod.evaluated = true;
176
176
  }
177
177
  }
178
- async directRequest(id, fsPath, _callstack) {
179
- const callstack = [..._callstack, fsPath];
180
- let mod = this.moduleCache.get(fsPath);
181
- const request = async (dep2) => {
182
- var _a;
183
- const depFsPath = utils.toFilePath(utils.normalizeRequestId(dep2, this.options.base), this.root);
184
- const getStack = () => {
185
- return `stack:
186
- ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
187
- };
188
- let debugTimer;
189
- if (this.debug)
190
- debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
191
- ${getStack()}`), 2e3);
192
- try {
193
- if (callstack.includes(depFsPath)) {
194
- const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
195
- if (depExports)
196
- return depExports;
197
- throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
198
- }
199
- return await this.cachedRequest(dep2, callstack);
200
- } finally {
201
- if (debugTimer)
202
- clearTimeout(debugTimer);
203
- }
178
+ async resolveUrl(id, importee) {
179
+ if (utils.isInternalRequest(id))
180
+ return [id, id];
181
+ if (importee && id.startsWith(utils.VALID_ID_PREFIX))
182
+ importee = void 0;
183
+ id = utils.normalizeRequestId(id, this.options.base);
184
+ if (!this.options.resolveId)
185
+ return [id, utils.toFilePath(id, this.root)];
186
+ const resolved = await this.options.resolveId(id, importee);
187
+ const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : id;
188
+ const fsPath = resolved ? resolvedId : utils.toFilePath(id, this.root);
189
+ return [resolvedId, fsPath];
190
+ }
191
+ async dependencyRequest(id, fsPath, callstack) {
192
+ var _a;
193
+ const getStack = () => {
194
+ return `stack:
195
+ ${[...callstack, fsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
204
196
  };
205
- Object.defineProperty(request, "callstack", { get: () => callstack });
206
- const resolveId = async (dep2, callstackPosition = 1) => {
207
- if (this.options.resolveId && this.shouldResolveId(dep2)) {
208
- let importer = callstack[callstack.length - callstackPosition];
209
- if (importer && !dep2.startsWith("."))
210
- importer = void 0;
211
- if (importer && importer.startsWith("mock:"))
212
- importer = importer.slice(5);
213
- const resolved = await this.options.resolveId(utils.normalizeRequestId(dep2), importer);
214
- return [dep2, resolved == null ? void 0 : resolved.id];
197
+ let debugTimer;
198
+ if (this.debug)
199
+ debugTimer = setTimeout(() => console.warn(() => `module ${fsPath} takes over 2s to load.
200
+ ${getStack()}`), 2e3);
201
+ try {
202
+ if (callstack.includes(fsPath)) {
203
+ const depExports = (_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports;
204
+ if (depExports)
205
+ return depExports;
206
+ throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
215
207
  }
216
- return [dep2, void 0];
208
+ return await this.cachedRequest(id, fsPath, callstack);
209
+ } finally {
210
+ if (debugTimer)
211
+ clearTimeout(debugTimer);
212
+ }
213
+ }
214
+ async directRequest(id, fsPath, _callstack) {
215
+ const moduleId = utils.normalizeModuleId(fsPath);
216
+ const callstack = [..._callstack, moduleId];
217
+ const mod = this.moduleCache.get(fsPath);
218
+ const request = async (dep) => {
219
+ const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
220
+ return this.dependencyRequest(id2, depFsPath, callstack);
217
221
  };
218
- const [dep, resolvedId] = await resolveId(id, 2);
219
222
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
220
223
  if (id in requestStubs)
221
224
  return requestStubs[id];
222
- let { code: transformed, externalize } = await this.options.fetchModule(resolvedId || dep);
223
- if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
224
- if (this.moduleCache.has(resolvedId)) {
225
- mod = this.moduleCache.get(resolvedId);
226
- this.moduleCache.set(fsPath, mod);
227
- if (mod.promise)
228
- return mod.promise;
229
- if (mod.exports)
230
- return mod.exports;
231
- } else {
232
- this.moduleCache.set(resolvedId, mod);
233
- }
234
- }
225
+ let { code: transformed, externalize } = await this.options.fetchModule(id);
235
226
  if (externalize) {
236
227
  debugNative(externalize);
237
228
  const exports2 = await this.interopedImport(externalize);
@@ -239,10 +230,10 @@ ${getStack()}`), 2e3);
239
230
  return exports2;
240
231
  }
241
232
  if (transformed == null)
242
- throw new Error(`[vite-node] Failed to load ${id}`);
243
- const file = utils.cleanUrl(resolvedId || fsPath);
244
- const url$1 = url.pathToFileURL(file).href;
245
- const meta = { url: url$1 };
233
+ throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
234
+ const modulePath = utils.cleanUrl(moduleId);
235
+ const href = url.pathToFileURL(modulePath).href;
236
+ const meta = { url: href };
246
237
  const exports = /* @__PURE__ */ Object.create(null);
247
238
  Object.defineProperty(exports, Symbol.toStringTag, {
248
239
  value: "Module",
@@ -250,7 +241,12 @@ ${getStack()}`), 2e3);
250
241
  configurable: false
251
242
  });
252
243
  const cjsExports = new Proxy(exports, {
253
- set(_, p, value) {
244
+ set: (_, p, value) => {
245
+ if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
246
+ exportAll(cjsExports, value);
247
+ exports.default = value;
248
+ return true;
249
+ }
254
250
  if (!Reflect.has(exports, "default"))
255
251
  exports.default = {};
256
252
  if (utils.isPrimitive(exports.default)) {
@@ -264,7 +260,7 @@ ${getStack()}`), 2e3);
264
260
  }
265
261
  });
266
262
  Object.assign(mod, { code: transformed, exports });
267
- const __filename = url.fileURLToPath(url$1);
263
+ const __filename = url.fileURLToPath(href);
268
264
  const moduleProxy = {
269
265
  set exports(value) {
270
266
  exportAll(cjsExports, value);
@@ -282,6 +278,9 @@ ${getStack()}`), 2e3);
282
278
  var _a, _b;
283
279
  hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
284
280
  return hotContext;
281
+ },
282
+ set: (value) => {
283
+ hotContext = value;
285
284
  }
286
285
  });
287
286
  }
@@ -291,12 +290,11 @@ ${getStack()}`), 2e3);
291
290
  __vite_ssr_exports__: exports,
292
291
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
293
292
  __vite_ssr_import_meta__: meta,
294
- __vitest_resolve_id__: resolveId,
295
- require: module$1.createRequire(url$1),
293
+ require: module$1.createRequire(href),
296
294
  exports: cjsExports,
297
295
  module: moduleProxy,
298
296
  __filename,
299
- __dirname: pathe.dirname(__filename)
297
+ __dirname: path.dirname(__filename)
300
298
  });
301
299
  debugExecute(__filename);
302
300
  if (transformed[0] === "#")
@@ -315,42 +313,44 @@ ${getStack()}`), 2e3);
315
313
  prepareContext(context) {
316
314
  return context;
317
315
  }
318
- shouldResolveId(dep) {
319
- if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
320
- return false;
321
- return !pathe.isAbsolute(dep) || !pathe.extname(dep);
322
- }
323
316
  shouldInterop(path, mod) {
324
317
  if (this.options.interopDefault === false)
325
318
  return false;
326
319
  return !path.endsWith(".mjs") && "default" in mod;
327
320
  }
328
321
  async interopedImport(path) {
329
- const mod = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
330
- if (this.shouldInterop(path, mod)) {
331
- const tryDefault = this.hasNestedDefault(mod);
332
- return new Proxy(mod, {
333
- get: proxyMethod("get", tryDefault),
334
- set: proxyMethod("set", tryDefault),
335
- has: proxyMethod("has", tryDefault),
336
- deleteProperty: proxyMethod("deleteProperty", tryDefault)
337
- });
338
- }
339
- return mod;
340
- }
341
- hasNestedDefault(target) {
342
- return "__esModule" in target && target.__esModule && "default" in target.default;
322
+ const importedModule = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
323
+ if (!this.shouldInterop(path, importedModule))
324
+ return importedModule;
325
+ const { mod, defaultExport } = interopModule(importedModule);
326
+ return new Proxy(mod, {
327
+ get(mod2, prop) {
328
+ if (prop === "default")
329
+ return defaultExport;
330
+ return mod2[prop] ?? (defaultExport == null ? void 0 : defaultExport[prop]);
331
+ },
332
+ has(mod2, prop) {
333
+ if (prop === "default")
334
+ return defaultExport !== void 0;
335
+ return prop in mod2 || defaultExport && prop in defaultExport;
336
+ }
337
+ });
343
338
  }
344
339
  }
345
- function proxyMethod(name, tryDefault) {
346
- return function(target, key, ...args) {
347
- const result = Reflect[name](target, key, ...args);
348
- if (utils.isPrimitive(target.default))
349
- return result;
350
- if (tryDefault && key === "default" || typeof result === "undefined")
351
- return Reflect[name](target.default, key, ...args);
352
- return result;
353
- };
340
+ function interopModule(mod) {
341
+ if (utils.isPrimitive(mod)) {
342
+ return {
343
+ mod: { default: mod },
344
+ defaultExport: mod
345
+ };
346
+ }
347
+ let defaultExport = "default" in mod ? mod.default : mod;
348
+ if (!utils.isPrimitive(defaultExport) && "__esModule" in defaultExport) {
349
+ mod = defaultExport;
350
+ if ("default" in defaultExport)
351
+ defaultExport = defaultExport.default;
352
+ }
353
+ return { mod, defaultExport };
354
354
  }
355
355
  function defineExport(exports, key, value) {
356
356
  Object.defineProperty(exports, key, {
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-fc7e68bc.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-aaf02e1c.js';
package/dist/client.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { createRequire } from 'module';
2
+ import { dirname } from 'path';
2
3
  import { pathToFileURL, fileURLToPath } from 'url';
3
4
  import vm from 'vm';
4
- import { resolve, dirname, isAbsolute, extname } from 'pathe';
5
- import { isNodeBuiltin } from 'mlly';
5
+ import { resolve } from 'pathe';
6
6
  import createDebug from 'debug';
7
- import { normalizeModuleId, slash, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
7
+ import { normalizeModuleId, slash, isInternalRequest, VALID_ID_PREFIX, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
8
8
  import { extractSourceMap } from './source-map.mjs';
9
9
  import 'fs';
10
10
  import 'source-map-support';
@@ -119,19 +119,19 @@ class ViteNodeRunner {
119
119
  this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
120
120
  }
121
121
  async executeFile(file) {
122
- return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
122
+ const url = `/@fs/${slash(resolve(file))}`;
123
+ return await this.cachedRequest(url, url, []);
123
124
  }
124
- async executeId(id) {
125
- return await this.cachedRequest(id, []);
125
+ async executeId(rawId) {
126
+ const [id, url] = await this.resolveUrl(rawId);
127
+ return await this.cachedRequest(id, url, []);
126
128
  }
127
129
  getSourceMap(id) {
128
130
  return this.moduleCache.getSourceMap(id);
129
131
  }
130
- async cachedRequest(rawId, callstack) {
131
- const id = normalizeRequestId(rawId, this.options.base);
132
- const fsPath = toFilePath(id, this.root);
133
- const mod = this.moduleCache.get(fsPath);
132
+ async cachedRequest(id, fsPath, callstack) {
134
133
  const importee = callstack[callstack.length - 1];
134
+ const mod = this.moduleCache.get(fsPath);
135
135
  if (!mod.importers)
136
136
  mod.importers = /* @__PURE__ */ new Set();
137
137
  if (importee)
@@ -148,63 +148,54 @@ class ViteNodeRunner {
148
148
  mod.evaluated = true;
149
149
  }
150
150
  }
151
- async directRequest(id, fsPath, _callstack) {
152
- const callstack = [..._callstack, fsPath];
153
- let mod = this.moduleCache.get(fsPath);
154
- const request = async (dep2) => {
155
- var _a;
156
- const depFsPath = toFilePath(normalizeRequestId(dep2, this.options.base), this.root);
157
- const getStack = () => {
158
- return `stack:
159
- ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
160
- };
161
- let debugTimer;
162
- if (this.debug)
163
- debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
164
- ${getStack()}`), 2e3);
165
- try {
166
- if (callstack.includes(depFsPath)) {
167
- const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
168
- if (depExports)
169
- return depExports;
170
- throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
171
- }
172
- return await this.cachedRequest(dep2, callstack);
173
- } finally {
174
- if (debugTimer)
175
- clearTimeout(debugTimer);
176
- }
151
+ async resolveUrl(id, importee) {
152
+ if (isInternalRequest(id))
153
+ return [id, id];
154
+ if (importee && id.startsWith(VALID_ID_PREFIX))
155
+ importee = void 0;
156
+ id = normalizeRequestId(id, this.options.base);
157
+ if (!this.options.resolveId)
158
+ return [id, toFilePath(id, this.root)];
159
+ const resolved = await this.options.resolveId(id, importee);
160
+ const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : id;
161
+ const fsPath = resolved ? resolvedId : toFilePath(id, this.root);
162
+ return [resolvedId, fsPath];
163
+ }
164
+ async dependencyRequest(id, fsPath, callstack) {
165
+ var _a;
166
+ const getStack = () => {
167
+ return `stack:
168
+ ${[...callstack, fsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
177
169
  };
178
- Object.defineProperty(request, "callstack", { get: () => callstack });
179
- const resolveId = async (dep2, callstackPosition = 1) => {
180
- if (this.options.resolveId && this.shouldResolveId(dep2)) {
181
- let importer = callstack[callstack.length - callstackPosition];
182
- if (importer && !dep2.startsWith("."))
183
- importer = void 0;
184
- if (importer && importer.startsWith("mock:"))
185
- importer = importer.slice(5);
186
- const resolved = await this.options.resolveId(normalizeRequestId(dep2), importer);
187
- return [dep2, resolved == null ? void 0 : resolved.id];
170
+ let debugTimer;
171
+ if (this.debug)
172
+ debugTimer = setTimeout(() => console.warn(() => `module ${fsPath} takes over 2s to load.
173
+ ${getStack()}`), 2e3);
174
+ try {
175
+ if (callstack.includes(fsPath)) {
176
+ const depExports = (_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports;
177
+ if (depExports)
178
+ return depExports;
179
+ throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
188
180
  }
189
- return [dep2, void 0];
181
+ return await this.cachedRequest(id, fsPath, callstack);
182
+ } finally {
183
+ if (debugTimer)
184
+ clearTimeout(debugTimer);
185
+ }
186
+ }
187
+ async directRequest(id, fsPath, _callstack) {
188
+ const moduleId = normalizeModuleId(fsPath);
189
+ const callstack = [..._callstack, moduleId];
190
+ const mod = this.moduleCache.get(fsPath);
191
+ const request = async (dep) => {
192
+ const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
193
+ return this.dependencyRequest(id2, depFsPath, callstack);
190
194
  };
191
- const [dep, resolvedId] = await resolveId(id, 2);
192
195
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
193
196
  if (id in requestStubs)
194
197
  return requestStubs[id];
195
- let { code: transformed, externalize } = await this.options.fetchModule(resolvedId || dep);
196
- if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
197
- if (this.moduleCache.has(resolvedId)) {
198
- mod = this.moduleCache.get(resolvedId);
199
- this.moduleCache.set(fsPath, mod);
200
- if (mod.promise)
201
- return mod.promise;
202
- if (mod.exports)
203
- return mod.exports;
204
- } else {
205
- this.moduleCache.set(resolvedId, mod);
206
- }
207
- }
198
+ let { code: transformed, externalize } = await this.options.fetchModule(id);
208
199
  if (externalize) {
209
200
  debugNative(externalize);
210
201
  const exports2 = await this.interopedImport(externalize);
@@ -212,10 +203,10 @@ ${getStack()}`), 2e3);
212
203
  return exports2;
213
204
  }
214
205
  if (transformed == null)
215
- throw new Error(`[vite-node] Failed to load ${id}`);
216
- const file = cleanUrl(resolvedId || fsPath);
217
- const url = pathToFileURL(file).href;
218
- const meta = { url };
206
+ throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
207
+ const modulePath = cleanUrl(moduleId);
208
+ const href = pathToFileURL(modulePath).href;
209
+ const meta = { url: href };
219
210
  const exports = /* @__PURE__ */ Object.create(null);
220
211
  Object.defineProperty(exports, Symbol.toStringTag, {
221
212
  value: "Module",
@@ -223,7 +214,12 @@ ${getStack()}`), 2e3);
223
214
  configurable: false
224
215
  });
225
216
  const cjsExports = new Proxy(exports, {
226
- set(_, p, value) {
217
+ set: (_, p, value) => {
218
+ if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
219
+ exportAll(cjsExports, value);
220
+ exports.default = value;
221
+ return true;
222
+ }
227
223
  if (!Reflect.has(exports, "default"))
228
224
  exports.default = {};
229
225
  if (isPrimitive(exports.default)) {
@@ -237,7 +233,7 @@ ${getStack()}`), 2e3);
237
233
  }
238
234
  });
239
235
  Object.assign(mod, { code: transformed, exports });
240
- const __filename = fileURLToPath(url);
236
+ const __filename = fileURLToPath(href);
241
237
  const moduleProxy = {
242
238
  set exports(value) {
243
239
  exportAll(cjsExports, value);
@@ -255,6 +251,9 @@ ${getStack()}`), 2e3);
255
251
  var _a, _b;
256
252
  hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
257
253
  return hotContext;
254
+ },
255
+ set: (value) => {
256
+ hotContext = value;
258
257
  }
259
258
  });
260
259
  }
@@ -264,8 +263,7 @@ ${getStack()}`), 2e3);
264
263
  __vite_ssr_exports__: exports,
265
264
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
266
265
  __vite_ssr_import_meta__: meta,
267
- __vitest_resolve_id__: resolveId,
268
- require: createRequire(url),
266
+ require: createRequire(href),
269
267
  exports: cjsExports,
270
268
  module: moduleProxy,
271
269
  __filename,
@@ -288,42 +286,44 @@ ${getStack()}`), 2e3);
288
286
  prepareContext(context) {
289
287
  return context;
290
288
  }
291
- shouldResolveId(dep) {
292
- if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
293
- return false;
294
- return !isAbsolute(dep) || !extname(dep);
295
- }
296
289
  shouldInterop(path, mod) {
297
290
  if (this.options.interopDefault === false)
298
291
  return false;
299
292
  return !path.endsWith(".mjs") && "default" in mod;
300
293
  }
301
294
  async interopedImport(path) {
302
- const mod = await import(path);
303
- if (this.shouldInterop(path, mod)) {
304
- const tryDefault = this.hasNestedDefault(mod);
305
- return new Proxy(mod, {
306
- get: proxyMethod("get", tryDefault),
307
- set: proxyMethod("set", tryDefault),
308
- has: proxyMethod("has", tryDefault),
309
- deleteProperty: proxyMethod("deleteProperty", tryDefault)
310
- });
311
- }
312
- return mod;
313
- }
314
- hasNestedDefault(target) {
315
- return "__esModule" in target && target.__esModule && "default" in target.default;
295
+ const importedModule = await import(path);
296
+ if (!this.shouldInterop(path, importedModule))
297
+ return importedModule;
298
+ const { mod, defaultExport } = interopModule(importedModule);
299
+ return new Proxy(mod, {
300
+ get(mod2, prop) {
301
+ if (prop === "default")
302
+ return defaultExport;
303
+ return mod2[prop] ?? (defaultExport == null ? void 0 : defaultExport[prop]);
304
+ },
305
+ has(mod2, prop) {
306
+ if (prop === "default")
307
+ return defaultExport !== void 0;
308
+ return prop in mod2 || defaultExport && prop in defaultExport;
309
+ }
310
+ });
316
311
  }
317
312
  }
318
- function proxyMethod(name, tryDefault) {
319
- return function(target, key, ...args) {
320
- const result = Reflect[name](target, key, ...args);
321
- if (isPrimitive(target.default))
322
- return result;
323
- if (tryDefault && key === "default" || typeof result === "undefined")
324
- return Reflect[name](target.default, key, ...args);
325
- return result;
326
- };
313
+ function interopModule(mod) {
314
+ if (isPrimitive(mod)) {
315
+ return {
316
+ mod: { default: mod },
317
+ defaultExport: mod
318
+ };
319
+ }
320
+ let defaultExport = "default" in mod ? mod.default : mod;
321
+ if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {
322
+ mod = defaultExport;
323
+ if ("default" in defaultExport)
324
+ defaultExport = defaultExport.default;
325
+ }
326
+ return { mod, defaultExport };
327
327
  }
328
328
  function defineExport(exports, key, value) {
329
329
  Object.defineProperty(exports, key, {
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-fc7e68bc.js';
3
+ import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-aaf02e1c.js';
4
4
 
5
5
  type EventType = string | symbol;
6
6
  type Handler<T = unknown> = (event: T) => void;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-fc7e68bc.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-aaf02e1c.js';
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-fc7e68bc.js';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-aaf02e1c.js';
3
3
 
4
4
  declare class Debugger {
5
5
  options: DebuggerOptions;
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { R as RawSourceMap } from './types-fc7e68bc.js';
2
+ import { R as RawSourceMap } from './types-aaf02e1c.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => RawSourceMap | null | undefined;
@@ -155,14 +155,16 @@ declare class ViteNodeRunner {
155
155
  moduleCache: ModuleCacheMap;
156
156
  constructor(options: ViteNodeRunnerOptions);
157
157
  executeFile(file: string): Promise<any>;
158
- executeId(id: string): Promise<any>;
158
+ executeId(rawId: string): Promise<any>;
159
159
  getSourceMap(id: string): RawSourceMap | null;
160
160
  /** @internal */
161
- cachedRequest(rawId: string, callstack: string[]): Promise<any>;
161
+ cachedRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
162
+ resolveUrl(id: string, importee?: string): Promise<[url: string, fsPath: string]>;
163
+ /** @internal */
164
+ dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
162
165
  /** @internal */
163
166
  directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
164
167
  prepareContext(context: Record<string, any>): Record<string, any>;
165
- shouldResolveId(dep: string): boolean;
166
168
  /**
167
169
  * Define if a module should be interop-ed
168
170
  * This function mostly for the ability to override by subclass
@@ -172,7 +174,6 @@ declare class ViteNodeRunner {
172
174
  * Import a module and interop it
173
175
  */
174
176
  interopedImport(path: string): Promise<any>;
175
- hasNestedDefault(target: any): any;
176
177
  }
177
178
 
178
179
  type Nullable<T> = T | null | undefined;
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-fc7e68bc.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-aaf02e1c.js';
package/dist/utils.cjs CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var url = require('url');
6
6
  var fs = require('fs');
7
7
  var pathe = require('pathe');
8
- var mlly = require('mlly');
9
8
 
10
9
  const isWindows = process.platform === "win32";
11
10
  function slash(str) {
@@ -14,6 +13,7 @@ function slash(str) {
14
13
  function mergeSlashes(str) {
15
14
  return str.replace(/\/\//g, "/");
16
15
  }
16
+ const VALID_ID_PREFIX = "/@id/";
17
17
  function normalizeRequestId(id, base) {
18
18
  if (base && id.startsWith(base))
19
19
  id = `/${id.slice(base.length)}`;
@@ -22,23 +22,15 @@ function normalizeRequestId(id, base) {
22
22
  const queryRE = /\?.*$/s;
23
23
  const hashRE = /#.*$/s;
24
24
  const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
25
+ const isInternalRequest = (id) => {
26
+ return id.startsWith("/@vite/");
27
+ };
25
28
  function normalizeModuleId(id) {
26
- return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
29
+ return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
27
30
  }
28
31
  function isPrimitive(v) {
29
32
  return v !== Object(v);
30
33
  }
31
- function pathFromRoot(root, filename) {
32
- if (mlly.isNodeBuiltin(filename))
33
- return filename;
34
- filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
35
- if (!filename.startsWith(root))
36
- return filename;
37
- const relativePath = pathe.relative(root, filename);
38
- const segments = relativePath.split("/");
39
- const startIndex = segments.findIndex((segment) => segment !== ".." && segment !== ".");
40
- return `/${segments.slice(startIndex).join("/")}`;
41
- }
42
34
  function toFilePath(id, root) {
43
35
  let absolute = (() => {
44
36
  if (id.startsWith("/@fs/"))
@@ -62,14 +54,15 @@ function toArray(array) {
62
54
  return [array];
63
55
  }
64
56
 
57
+ exports.VALID_ID_PREFIX = VALID_ID_PREFIX;
65
58
  exports.cleanUrl = cleanUrl;
66
59
  exports.hashRE = hashRE;
60
+ exports.isInternalRequest = isInternalRequest;
67
61
  exports.isPrimitive = isPrimitive;
68
62
  exports.isWindows = isWindows;
69
63
  exports.mergeSlashes = mergeSlashes;
70
64
  exports.normalizeModuleId = normalizeModuleId;
71
65
  exports.normalizeRequestId = normalizeRequestId;
72
- exports.pathFromRoot = pathFromRoot;
73
66
  exports.queryRE = queryRE;
74
67
  exports.slash = slash;
75
68
  exports.toArray = toArray;
package/dist/utils.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { N as Nullable, A as Arrayable } from './types-fc7e68bc.js';
1
+ import { N as Nullable, A as Arrayable } from './types-aaf02e1c.js';
2
2
 
3
3
  declare const isWindows: boolean;
4
4
  declare function slash(str: string): string;
5
5
  declare function mergeSlashes(str: string): string;
6
+ declare const VALID_ID_PREFIX = "/@id/";
6
7
  declare function normalizeRequestId(id: string, base?: string): string;
7
8
  declare const queryRE: RegExp;
8
9
  declare const hashRE: RegExp;
9
10
  declare const cleanUrl: (url: string) => string;
11
+ declare const isInternalRequest: (id: string) => boolean;
10
12
  declare function normalizeModuleId(id: string): string;
11
13
  declare function isPrimitive(v: any): boolean;
12
- declare function pathFromRoot(root: string, filename: string): string;
13
14
  declare function toFilePath(id: string, root: string): string;
14
15
  /**
15
16
  * Convert `Arrayable<T>` to `Array<T>`
@@ -18,4 +19,4 @@ declare function toFilePath(id: string, root: string): string;
18
19
  */
19
20
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
20
21
 
21
- export { cleanUrl, hashRE, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, queryRE, slash, toArray, toFilePath };
22
+ export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };
package/dist/utils.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import { fileURLToPath, pathToFileURL } from 'url';
2
2
  import { existsSync } from 'fs';
3
- import { relative, resolve } from 'pathe';
4
- import { isNodeBuiltin } from 'mlly';
3
+ import { resolve } from 'pathe';
5
4
 
6
5
  const isWindows = process.platform === "win32";
7
6
  function slash(str) {
@@ -10,6 +9,7 @@ function slash(str) {
10
9
  function mergeSlashes(str) {
11
10
  return str.replace(/\/\//g, "/");
12
11
  }
12
+ const VALID_ID_PREFIX = "/@id/";
13
13
  function normalizeRequestId(id, base) {
14
14
  if (base && id.startsWith(base))
15
15
  id = `/${id.slice(base.length)}`;
@@ -18,23 +18,15 @@ function normalizeRequestId(id, base) {
18
18
  const queryRE = /\?.*$/s;
19
19
  const hashRE = /#.*$/s;
20
20
  const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
21
+ const isInternalRequest = (id) => {
22
+ return id.startsWith("/@vite/");
23
+ };
21
24
  function normalizeModuleId(id) {
22
- return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
25
+ return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
23
26
  }
24
27
  function isPrimitive(v) {
25
28
  return v !== Object(v);
26
29
  }
27
- function pathFromRoot(root, filename) {
28
- if (isNodeBuiltin(filename))
29
- return filename;
30
- filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
31
- if (!filename.startsWith(root))
32
- return filename;
33
- const relativePath = relative(root, filename);
34
- const segments = relativePath.split("/");
35
- const startIndex = segments.findIndex((segment) => segment !== ".." && segment !== ".");
36
- return `/${segments.slice(startIndex).join("/")}`;
37
- }
38
30
  function toFilePath(id, root) {
39
31
  let absolute = (() => {
40
32
  if (id.startsWith("/@fs/"))
@@ -58,4 +50,4 @@ function toArray(array) {
58
50
  return [array];
59
51
  }
60
52
 
61
- export { cleanUrl, hashRE, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, queryRE, slash, toArray, toFilePath };
53
+ export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.25.8",
3
+ "version": "0.26.0",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "scripts": {
88
88
  "build": "rimraf dist && rollup -c",
89
- "dev": "rollup -c --watch --watch.include=src -m inline",
89
+ "dev": "rollup -c --watch --watch.include 'src/**' -m inline",
90
90
  "typecheck": "tsc --noEmit"
91
91
  }
92
92
  }