vite-node 4.0.0-beta.11 → 4.0.0-beta.12

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.
@@ -6,8 +6,7 @@ var index = require('./chunk-index.cjs');
6
6
  var utils = require('./utils.cjs');
7
7
 
8
8
  function createHmrEmitter() {
9
- const emitter = new node_events.EventEmitter();
10
- return emitter;
9
+ return new node_events.EventEmitter();
11
10
  }
12
11
  function viteNodeHmrPlugin() {
13
12
  const emitter = createHmrEmitter();
@@ -58,7 +57,7 @@ async function reload(runner, files) {
58
57
  }), Promise.all(files.map((file) => runner.executeId(file)));
59
58
  }
60
59
  async function notifyListeners(runner, event, data) {
61
- const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
60
+ const cbs = getCache(runner).customListenersMap.get(event);
62
61
  if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
63
62
  }
64
63
  async function queueUpdate(runner, p) {
@@ -151,7 +150,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
151
150
  fn: callback
152
151
  }), maps.hotModulesMap.set(ownerPath, mod);
153
152
  }
154
- const hot = {
153
+ return {
155
154
  get data() {
156
155
  return maps.dataMap.get(ownerPath);
157
156
  },
@@ -209,7 +208,6 @@ function createHotContext(runner, emitter, files, ownerPath) {
209
208
  })), sendMessageBuffer(runner, emitter);
210
209
  }
211
210
  };
212
- return hot;
213
211
  }
214
212
 
215
213
  exports.createHmrEmitter = createHmrEmitter;
@@ -4,8 +4,7 @@ import { C } from './chunk-index.mjs';
4
4
  import { normalizeRequestId } from './utils.mjs';
5
5
 
6
6
  function createHmrEmitter() {
7
- const emitter = new EventEmitter();
8
- return emitter;
7
+ return new EventEmitter();
9
8
  }
10
9
  function viteNodeHmrPlugin() {
11
10
  const emitter = createHmrEmitter();
@@ -56,7 +55,7 @@ async function reload(runner, files) {
56
55
  }), Promise.all(files.map((file) => runner.executeId(file)));
57
56
  }
58
57
  async function notifyListeners(runner, event, data) {
59
- const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
58
+ const cbs = getCache(runner).customListenersMap.get(event);
60
59
  if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
61
60
  }
62
61
  async function queueUpdate(runner, p) {
@@ -149,7 +148,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
149
148
  fn: callback
150
149
  }), maps.hotModulesMap.set(ownerPath, mod);
151
150
  }
152
- const hot = {
151
+ return {
153
152
  get data() {
154
153
  return maps.dataMap.get(ownerPath);
155
154
  },
@@ -207,7 +206,6 @@ function createHotContext(runner, emitter, files, ownerPath) {
207
206
  })), sendMessageBuffer(runner, emitter);
208
207
  }
209
208
  };
210
- return hot;
211
209
  }
212
210
 
213
211
  export { createHotContext as a, createHmrEmitter as c, getCache as g, handleMessage as h, reload as r, sendMessageBuffer as s, viteNodeHmrPlugin as v };
package/dist/cli.cjs CHANGED
@@ -21,7 +21,7 @@ require('node:perf_hooks');
21
21
  require('es-module-lexer');
22
22
  require('./constants.cjs');
23
23
 
24
- var version = "4.0.0-beta.11";
24
+ var version = "4.0.0-beta.12";
25
25
 
26
26
  const cli = cac("vite-node");
27
27
  if (cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", "Restart on file changes, similar to \"nodemon\"").option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command"), cli.command("[...files]").allowUnknownOptions().action(run), cli.parse(process.argv, { run: false }), cli.args.length === 0) cli.runMatchedCommand();
package/dist/cli.mjs CHANGED
@@ -19,7 +19,7 @@ import 'node:perf_hooks';
19
19
  import 'es-module-lexer';
20
20
  import './constants.mjs';
21
21
 
22
- var version = "4.0.0-beta.11";
22
+ var version = "4.0.0-beta.12";
23
23
 
24
24
  const cli = cac("vite-node");
25
25
  if (cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", "Restart on file changes, similar to \"nodemon\"").option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command"), cli.command("[...files]").allowUnknownOptions().action(run), cli.parse(process.argv, { run: false }), cli.args.length === 0) cli.runMatchedCommand();
package/dist/client.cjs CHANGED
@@ -231,8 +231,8 @@ class ViteNodeRunner {
231
231
  /** @internal */
232
232
  async directRequest(id, fsPath, _callstack) {
233
233
  const moduleId = utils.normalizeModuleId(fsPath), callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep) => {
234
- const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath), depMod = this.moduleCache.getByModuleId(depFsPath);
235
- return depMod.importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
234
+ const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
235
+ return this.moduleCache.getByModuleId(depFsPath).importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
236
236
  }, requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
237
237
  if (id in requestStubs) return requestStubs[id];
238
238
  let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
@@ -339,8 +339,7 @@ class ViteNodeRunner {
339
339
  columnOffset: -codeDefinition.length
340
340
  }, finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
341
341
  try {
342
- const fn = vm.runInThisContext(code, options);
343
- await fn(...Object.values(context));
342
+ await vm.runInThisContext(code, options)(...Object.values(context));
344
343
  } finally {
345
344
  var _this$options$moduleE;
346
345
  (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
package/dist/client.mjs CHANGED
@@ -229,8 +229,8 @@ class ViteNodeRunner {
229
229
  /** @internal */
230
230
  async directRequest(id, fsPath, _callstack) {
231
231
  const moduleId = normalizeModuleId(fsPath), callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep) => {
232
- const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath), depMod = this.moduleCache.getByModuleId(depFsPath);
233
- return depMod.importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
232
+ const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
233
+ return this.moduleCache.getByModuleId(depFsPath).importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
234
234
  }, requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
235
235
  if (id in requestStubs) return requestStubs[id];
236
236
  let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
@@ -337,8 +337,7 @@ class ViteNodeRunner {
337
337
  columnOffset: -codeDefinition.length
338
338
  }, finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
339
339
  try {
340
- const fn = vm.runInThisContext(code, options);
341
- await fn(...Object.values(context));
340
+ await vm.runInThisContext(code, options)(...Object.values(context));
342
341
  } finally {
343
342
  var _this$options$moduleE;
344
343
  (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
package/dist/server.cjs CHANGED
@@ -75,12 +75,10 @@ class Debugger {
75
75
  if (!this.dumpDir) return null;
76
76
  await this.initPromise;
77
77
  const name = this.encodeId(id), path = pathe.join(this.dumpDir, name);
78
- if (!fs.existsSync(path)) return null;
79
- const code = await fs.promises.readFile(path, "utf-8");
80
- return {
81
- code: code.replace(/^\/\/.*\n/, ""),
78
+ return fs.existsSync(path) ? {
79
+ code: (await fs.promises.readFile(path, "utf-8")).replace(/^\/\/.*\n/, ""),
82
80
  map: void 0
83
- };
81
+ } : null;
84
82
  }
85
83
  async writeInfo() {
86
84
  if (!this.dumpDir) return;
@@ -126,9 +124,7 @@ async function isValidNodeImport(id) {
126
124
  const extension = pathe.extname(id);
127
125
  if (BUILTIN_EXTENSIONS.has(extension)) return true;
128
126
  if (extension !== ".js") return false;
129
- id = id.replace("file:///", "");
130
- const package_ = await utils.findNearestPackageData(pathe.dirname(id));
131
- if (package_.type === "module") return true;
127
+ if (id = id.replace("file:///", ""), (await utils.findNearestPackageData(pathe.dirname(id))).type === "module") return true;
132
128
  if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id)) return false;
133
129
  try {
134
130
  await esModuleLexer__namespace.init;
@@ -154,8 +150,8 @@ async function _shouldExternalize(id, options) {
154
150
  // Unless the user explicitly opted to inline them, externalize Vite deps.
155
151
  // They are too big to inline by default.
156
152
  if (matchExternalizePattern(id, moduleDirectories, options === null || options === void 0 ? void 0 : options.external) || (options === null || options === void 0 ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) return id;
157
- const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir)), guessCJS = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS);
158
- return id = guessCJS ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
153
+ const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
154
+ return id = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS) ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
159
155
  }
160
156
  function matchExternalizePattern(id, moduleDirectories, patterns) {
161
157
  if (patterns == null) return false;
@@ -307,9 +303,7 @@ class ViteNodeServer {
307
303
  if (module) return module;
308
304
  const _modules = this.server.moduleGraph.getModulesByFile(file);
309
305
  if (!_modules || !_modules.size) return null;
310
- // find the latest changed module
311
- const modules = [..._modules];
312
- let mod = modules[0], latestMax = -1;
306
+ let mod = [..._modules][0], latestMax = -1;
313
307
  for (const m of _modules) {
314
308
  const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp);
315
309
  if (timestamp > latestMax) latestMax = timestamp, mod = m;
@@ -367,8 +361,7 @@ class ViteNodeServer {
367
361
  if (transformMode === "web") {
368
362
  if (result = await this.server.transformRequest(id), result) result = await this.server.ssrTransform(result.code, result.map, id);
369
363
  } else result = await this.server.transformRequest(id, { ssr: true });
370
- const sourcemap = this.options.sourcemap ?? "inline";
371
- if (sourcemap === "inline" && result) result = await this.processTransformResult(filepath, result);
364
+ if ((this.options.sourcemap ?? "inline") === "inline" && result) result = await this.processTransformResult(filepath, result);
372
365
  if ((_this$options$debug2 = this.options.debug) === null || _this$options$debug2 === void 0 ? void 0 : _this$options$debug2.dumpModules) {
373
366
  var _this$debugger3;
374
367
  await ((_this$debugger3 = this.debugger) === null || _this$debugger3 === void 0 ? void 0 : _this$debugger3.dumpFile(id, result));
package/dist/server.mjs CHANGED
@@ -54,12 +54,10 @@ class Debugger {
54
54
  if (!this.dumpDir) return null;
55
55
  await this.initPromise;
56
56
  const name = this.encodeId(id), path = join(this.dumpDir, name);
57
- if (!existsSync(path)) return null;
58
- const code = await promises.readFile(path, "utf-8");
59
- return {
60
- code: code.replace(/^\/\/.*\n/, ""),
57
+ return existsSync(path) ? {
58
+ code: (await promises.readFile(path, "utf-8")).replace(/^\/\/.*\n/, ""),
61
59
  map: void 0
62
- };
60
+ } : null;
63
61
  }
64
62
  async writeInfo() {
65
63
  if (!this.dumpDir) return;
@@ -105,9 +103,7 @@ async function isValidNodeImport(id) {
105
103
  const extension = extname(id);
106
104
  if (BUILTIN_EXTENSIONS.has(extension)) return true;
107
105
  if (extension !== ".js") return false;
108
- id = id.replace("file:///", "");
109
- const package_ = await findNearestPackageData(dirname(id));
110
- if (package_.type === "module") return true;
106
+ if (id = id.replace("file:///", ""), (await findNearestPackageData(dirname(id))).type === "module") return true;
111
107
  if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id)) return false;
112
108
  try {
113
109
  await esModuleLexer.init;
@@ -133,8 +129,8 @@ async function _shouldExternalize(id, options) {
133
129
  // Unless the user explicitly opted to inline them, externalize Vite deps.
134
130
  // They are too big to inline by default.
135
131
  if (matchExternalizePattern(id, moduleDirectories, options === null || options === void 0 ? void 0 : options.external) || (options === null || options === void 0 ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) return id;
136
- const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir)), guessCJS = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS);
137
- return id = guessCJS ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
132
+ const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
133
+ return id = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS) ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
138
134
  }
139
135
  function matchExternalizePattern(id, moduleDirectories, patterns) {
140
136
  if (patterns == null) return false;
@@ -286,9 +282,7 @@ class ViteNodeServer {
286
282
  if (module) return module;
287
283
  const _modules = this.server.moduleGraph.getModulesByFile(file);
288
284
  if (!_modules || !_modules.size) return null;
289
- // find the latest changed module
290
- const modules = [..._modules];
291
- let mod = modules[0], latestMax = -1;
285
+ let mod = [..._modules][0], latestMax = -1;
292
286
  for (const m of _modules) {
293
287
  const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp);
294
288
  if (timestamp > latestMax) latestMax = timestamp, mod = m;
@@ -346,8 +340,7 @@ class ViteNodeServer {
346
340
  if (transformMode === "web") {
347
341
  if (result = await this.server.transformRequest(id), result) result = await this.server.ssrTransform(result.code, result.map, id);
348
342
  } else result = await this.server.transformRequest(id, { ssr: true });
349
- const sourcemap = this.options.sourcemap ?? "inline";
350
- if (sourcemap === "inline" && result) result = await this.processTransformResult(filepath, result);
343
+ if ((this.options.sourcemap ?? "inline") === "inline" && result) result = await this.processTransformResult(filepath, result);
351
344
  if ((_this$options$debug2 = this.options.debug) === null || _this$options$debug2 === void 0 ? void 0 : _this$options$debug2.dumpModules) {
352
345
  var _this$debugger3;
353
346
  await ((_this$debugger3 = this.debugger) === null || _this$debugger3 === void 0 ? void 0 : _this$debugger3.dumpFile(id, result));
@@ -129,16 +129,6 @@ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#
129
129
  * 4. Hash, including "#", optional.
130
130
  */
131
131
  const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
132
- var UrlType;
133
- (function (UrlType) {
134
- UrlType[UrlType["Empty"] = 1] = "Empty";
135
- UrlType[UrlType["Hash"] = 2] = "Hash";
136
- UrlType[UrlType["Query"] = 3] = "Query";
137
- UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
138
- UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
139
- UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
140
- UrlType[UrlType["Absolute"] = 7] = "Absolute";
141
- })(UrlType || (UrlType = {}));
142
132
  function isAbsoluteUrl(input) {
143
133
  return schemeRegex.test(input);
144
134
  }
@@ -172,21 +162,21 @@ function makeUrl(scheme, user, host, port, path, query, hash) {
172
162
  path,
173
163
  query,
174
164
  hash,
175
- type: UrlType.Absolute,
165
+ type: 7 /* Absolute */,
176
166
  };
177
167
  }
178
168
  function parseUrl(input) {
179
169
  if (isSchemeRelativeUrl(input)) {
180
170
  const url = parseAbsoluteUrl('http:' + input);
181
171
  url.scheme = '';
182
- url.type = UrlType.SchemeRelative;
172
+ url.type = 6 /* SchemeRelative */;
183
173
  return url;
184
174
  }
185
175
  if (isAbsolutePath(input)) {
186
176
  const url = parseAbsoluteUrl('http://foo.com' + input);
187
177
  url.scheme = '';
188
178
  url.host = '';
189
- url.type = UrlType.AbsolutePath;
179
+ url.type = 5 /* AbsolutePath */;
190
180
  return url;
191
181
  }
192
182
  if (isFileUrl(input))
@@ -198,11 +188,11 @@ function parseUrl(input) {
198
188
  url.host = '';
199
189
  url.type = input
200
190
  ? input.startsWith('?')
201
- ? UrlType.Query
191
+ ? 3 /* Query */
202
192
  : input.startsWith('#')
203
- ? UrlType.Hash
204
- : UrlType.RelativePath
205
- : UrlType.Empty;
193
+ ? 2 /* Hash */
194
+ : 4 /* RelativePath */
195
+ : 1 /* Empty */;
206
196
  return url;
207
197
  }
208
198
  function stripPathFilename(path) {
@@ -230,7 +220,7 @@ function mergePaths(url, base) {
230
220
  * "foo/.". We need to normalize to a standard representation.
231
221
  */
232
222
  function normalizePath(url, type) {
233
- const rel = type <= UrlType.RelativePath;
223
+ const rel = type <= 4 /* RelativePath */;
234
224
  const pieces = url.path.split('/');
235
225
  // We need to preserve the first piece always, so that we output a leading slash. The item at
236
226
  // pieces[0] is an empty string.
@@ -291,27 +281,27 @@ function resolve(input, base) {
291
281
  return '';
292
282
  const url = parseUrl(input);
293
283
  let inputType = url.type;
294
- if (base && inputType !== UrlType.Absolute) {
284
+ if (base && inputType !== 7 /* Absolute */) {
295
285
  const baseUrl = parseUrl(base);
296
286
  const baseType = baseUrl.type;
297
287
  switch (inputType) {
298
- case UrlType.Empty:
288
+ case 1 /* Empty */:
299
289
  url.hash = baseUrl.hash;
300
290
  // fall through
301
- case UrlType.Hash:
291
+ case 2 /* Hash */:
302
292
  url.query = baseUrl.query;
303
293
  // fall through
304
- case UrlType.Query:
305
- case UrlType.RelativePath:
294
+ case 3 /* Query */:
295
+ case 4 /* RelativePath */:
306
296
  mergePaths(url, baseUrl);
307
297
  // fall through
308
- case UrlType.AbsolutePath:
298
+ case 5 /* AbsolutePath */:
309
299
  // The host, user, and port are joined, you can't copy one without the others.
310
300
  url.user = baseUrl.user;
311
301
  url.host = baseUrl.host;
312
302
  url.port = baseUrl.port;
313
303
  // fall through
314
- case UrlType.SchemeRelative:
304
+ case 6 /* SchemeRelative */:
315
305
  // The input doesn't have a schema at least, so we need to copy at least that over.
316
306
  url.scheme = baseUrl.scheme;
317
307
  }
@@ -323,10 +313,10 @@ function resolve(input, base) {
323
313
  switch (inputType) {
324
314
  // This is impossible, because of the empty checks at the start of the function.
325
315
  // case UrlType.Empty:
326
- case UrlType.Hash:
327
- case UrlType.Query:
316
+ case 2 /* Hash */:
317
+ case 3 /* Query */:
328
318
  return queryHash;
329
- case UrlType.RelativePath: {
319
+ case 4 /* RelativePath */: {
330
320
  // The first char is always a "/", and we need it to be relative.
331
321
  const path = url.path.slice(1);
332
322
  if (!path)
@@ -339,7 +329,7 @@ function resolve(input, base) {
339
329
  }
340
330
  return path + queryHash;
341
331
  }
342
- case UrlType.AbsolutePath:
332
+ case 5 /* AbsolutePath */:
343
333
  return url.path + queryHash;
344
334
  default:
345
335
  return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
@@ -706,8 +696,8 @@ function CallSiteToString() {
706
696
  let line = "";
707
697
  const functionName = this.getFunctionName();
708
698
  let addSuffix = true;
709
- const isConstructor = this.isConstructor(), isMethodCall = !(this.isToplevel() || isConstructor);
710
- if (isMethodCall) {
699
+ const isConstructor = this.isConstructor();
700
+ if (!(this.isToplevel() || isConstructor)) {
711
701
  let typeName = this.getTypeName();
712
702
  // Fixes shim to be backward compatible with Node v0 to v4
713
703
  if (typeName === "[object Object]") typeName = "null";
@@ -747,12 +737,7 @@ function wrapCallSite(frame, state) {
747
737
  if (source) {
748
738
  const line = frame.getLineNumber();
749
739
  let column = frame.getColumnNumber() - 1;
750
- // Fix position in Node where some (internal) code is prepended.
751
- // See https://github.com/evanw/node-source-map-support/issues/36
752
- // Header removed in node at ^10.16 || >=11.11.0
753
- // v11 is not an LTS candidate, we can just test the one version with it.
754
- // Test node versions for: 10.16-19, 10.20+, 12-19, 20-99, 100+, or 11.11
755
- const noHeader = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/, headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
740
+ const headerLength = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/.test(globalProcessVersion()) ? 0 : 62;
756
741
  if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
757
742
  const position = mapSourcePosition({
758
743
  name: null,
@@ -127,16 +127,6 @@ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#
127
127
  * 4. Hash, including "#", optional.
128
128
  */
129
129
  const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
130
- var UrlType;
131
- (function (UrlType) {
132
- UrlType[UrlType["Empty"] = 1] = "Empty";
133
- UrlType[UrlType["Hash"] = 2] = "Hash";
134
- UrlType[UrlType["Query"] = 3] = "Query";
135
- UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
136
- UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
137
- UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
138
- UrlType[UrlType["Absolute"] = 7] = "Absolute";
139
- })(UrlType || (UrlType = {}));
140
130
  function isAbsoluteUrl(input) {
141
131
  return schemeRegex.test(input);
142
132
  }
@@ -170,21 +160,21 @@ function makeUrl(scheme, user, host, port, path, query, hash) {
170
160
  path,
171
161
  query,
172
162
  hash,
173
- type: UrlType.Absolute,
163
+ type: 7 /* Absolute */,
174
164
  };
175
165
  }
176
166
  function parseUrl(input) {
177
167
  if (isSchemeRelativeUrl(input)) {
178
168
  const url = parseAbsoluteUrl('http:' + input);
179
169
  url.scheme = '';
180
- url.type = UrlType.SchemeRelative;
170
+ url.type = 6 /* SchemeRelative */;
181
171
  return url;
182
172
  }
183
173
  if (isAbsolutePath(input)) {
184
174
  const url = parseAbsoluteUrl('http://foo.com' + input);
185
175
  url.scheme = '';
186
176
  url.host = '';
187
- url.type = UrlType.AbsolutePath;
177
+ url.type = 5 /* AbsolutePath */;
188
178
  return url;
189
179
  }
190
180
  if (isFileUrl(input))
@@ -196,11 +186,11 @@ function parseUrl(input) {
196
186
  url.host = '';
197
187
  url.type = input
198
188
  ? input.startsWith('?')
199
- ? UrlType.Query
189
+ ? 3 /* Query */
200
190
  : input.startsWith('#')
201
- ? UrlType.Hash
202
- : UrlType.RelativePath
203
- : UrlType.Empty;
191
+ ? 2 /* Hash */
192
+ : 4 /* RelativePath */
193
+ : 1 /* Empty */;
204
194
  return url;
205
195
  }
206
196
  function stripPathFilename(path) {
@@ -228,7 +218,7 @@ function mergePaths(url, base) {
228
218
  * "foo/.". We need to normalize to a standard representation.
229
219
  */
230
220
  function normalizePath(url, type) {
231
- const rel = type <= UrlType.RelativePath;
221
+ const rel = type <= 4 /* RelativePath */;
232
222
  const pieces = url.path.split('/');
233
223
  // We need to preserve the first piece always, so that we output a leading slash. The item at
234
224
  // pieces[0] is an empty string.
@@ -289,27 +279,27 @@ function resolve(input, base) {
289
279
  return '';
290
280
  const url = parseUrl(input);
291
281
  let inputType = url.type;
292
- if (base && inputType !== UrlType.Absolute) {
282
+ if (base && inputType !== 7 /* Absolute */) {
293
283
  const baseUrl = parseUrl(base);
294
284
  const baseType = baseUrl.type;
295
285
  switch (inputType) {
296
- case UrlType.Empty:
286
+ case 1 /* Empty */:
297
287
  url.hash = baseUrl.hash;
298
288
  // fall through
299
- case UrlType.Hash:
289
+ case 2 /* Hash */:
300
290
  url.query = baseUrl.query;
301
291
  // fall through
302
- case UrlType.Query:
303
- case UrlType.RelativePath:
292
+ case 3 /* Query */:
293
+ case 4 /* RelativePath */:
304
294
  mergePaths(url, baseUrl);
305
295
  // fall through
306
- case UrlType.AbsolutePath:
296
+ case 5 /* AbsolutePath */:
307
297
  // The host, user, and port are joined, you can't copy one without the others.
308
298
  url.user = baseUrl.user;
309
299
  url.host = baseUrl.host;
310
300
  url.port = baseUrl.port;
311
301
  // fall through
312
- case UrlType.SchemeRelative:
302
+ case 6 /* SchemeRelative */:
313
303
  // The input doesn't have a schema at least, so we need to copy at least that over.
314
304
  url.scheme = baseUrl.scheme;
315
305
  }
@@ -321,10 +311,10 @@ function resolve(input, base) {
321
311
  switch (inputType) {
322
312
  // This is impossible, because of the empty checks at the start of the function.
323
313
  // case UrlType.Empty:
324
- case UrlType.Hash:
325
- case UrlType.Query:
314
+ case 2 /* Hash */:
315
+ case 3 /* Query */:
326
316
  return queryHash;
327
- case UrlType.RelativePath: {
317
+ case 4 /* RelativePath */: {
328
318
  // The first char is always a "/", and we need it to be relative.
329
319
  const path = url.path.slice(1);
330
320
  if (!path)
@@ -337,7 +327,7 @@ function resolve(input, base) {
337
327
  }
338
328
  return path + queryHash;
339
329
  }
340
- case UrlType.AbsolutePath:
330
+ case 5 /* AbsolutePath */:
341
331
  return url.path + queryHash;
342
332
  default:
343
333
  return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
@@ -704,8 +694,8 @@ function CallSiteToString() {
704
694
  let line = "";
705
695
  const functionName = this.getFunctionName();
706
696
  let addSuffix = true;
707
- const isConstructor = this.isConstructor(), isMethodCall = !(this.isToplevel() || isConstructor);
708
- if (isMethodCall) {
697
+ const isConstructor = this.isConstructor();
698
+ if (!(this.isToplevel() || isConstructor)) {
709
699
  let typeName = this.getTypeName();
710
700
  // Fixes shim to be backward compatible with Node v0 to v4
711
701
  if (typeName === "[object Object]") typeName = "null";
@@ -745,12 +735,7 @@ function wrapCallSite(frame, state) {
745
735
  if (source) {
746
736
  const line = frame.getLineNumber();
747
737
  let column = frame.getColumnNumber() - 1;
748
- // Fix position in Node where some (internal) code is prepended.
749
- // See https://github.com/evanw/node-source-map-support/issues/36
750
- // Header removed in node at ^10.16 || >=11.11.0
751
- // v11 is not an LTS candidate, we can just test the one version with it.
752
- // Test node versions for: 10.16-19, 10.20+, 12-19, 20-99, 100+, or 11.11
753
- const noHeader = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/, headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
738
+ const headerLength = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/.test(globalProcessVersion()) ? 0 : 62;
754
739
  if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
755
740
  const position = mapSourcePosition({
756
741
  name: null,
package/dist/utils.cjs CHANGED
@@ -39,7 +39,7 @@ function splitFileAndPostfix(path) {
39
39
  postfix: path.slice(file.length)
40
40
  };
41
41
  }
42
- const internalRequests = ["@vite/client", "@vite/env"], internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${internalRequests.join("|")})$`);
42
+ const internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${["@vite/client", "@vite/env"].join("|")})$`);
43
43
  function isInternalRequest(id) {
44
44
  return internalRequestRegexp.test(id);
45
45
  }
@@ -147,7 +147,7 @@ function createImportMetaEnvProxy() {
147
147
  ];
148
148
  return new Proxy(process.env, {
149
149
  get(_, key) {
150
- return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
150
+ if (typeof key === "string") return booleanKeys.includes(key) ? !!process.env[key] : process.env[key];
151
151
  },
152
152
  set(_, key, value) {
153
153
  if (typeof key !== "string") return true;
package/dist/utils.mjs CHANGED
@@ -37,7 +37,7 @@ function splitFileAndPostfix(path) {
37
37
  postfix: path.slice(file.length)
38
38
  };
39
39
  }
40
- const internalRequests = ["@vite/client", "@vite/env"], internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${internalRequests.join("|")})$`);
40
+ const internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${["@vite/client", "@vite/env"].join("|")})$`);
41
41
  function isInternalRequest(id) {
42
42
  return internalRequestRegexp.test(id);
43
43
  }
@@ -145,7 +145,7 @@ function createImportMetaEnvProxy() {
145
145
  ];
146
146
  return new Proxy(process.env, {
147
147
  get(_, key) {
148
- return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
148
+ if (typeof key === "string") return booleanKeys.includes(key) ? !!process.env[key] : process.env[key];
149
149
  },
150
150
  set(_, key, value) {
151
151
  if (typeof key !== "string") return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.11",
4
+ "version": "4.0.0-beta.12",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -78,18 +78,18 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "cac": "^6.7.14",
81
- "debug": "^4.4.1",
81
+ "debug": "^4.4.3",
82
82
  "es-module-lexer": "^1.7.0",
83
83
  "pathe": "^2.0.3",
84
84
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
85
85
  },
86
86
  "devDependencies": {
87
- "@jridgewell/trace-mapping": "0.3.30",
87
+ "@jridgewell/trace-mapping": "0.3.31",
88
88
  "@types/debug": "^4.1.12",
89
89
  "tinyrainbow": "^3.0.3"
90
90
  },
91
91
  "scripts": {
92
- "build": "rimraf dist && rollup -c",
92
+ "build": "premove dist && rollup -c",
93
93
  "dev": "rollup -c --watch --watch.include 'src/**' -m inline",
94
94
  "typecheck": "tsc --noEmit"
95
95
  }