vite-node 0.23.0 → 0.23.1

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
@@ -630,7 +630,7 @@ class CAC extends events.EventEmitter {
630
630
 
631
631
  const cac = (name = "") => new CAC(name);
632
632
 
633
- var version = "0.23.0";
633
+ var version = "0.23.1";
634
634
 
635
635
  const cli = cac("vite-node");
636
636
  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.mjs CHANGED
@@ -628,7 +628,7 @@ class CAC extends EventEmitter {
628
628
 
629
629
  const cac = (name = "") => new CAC(name);
630
630
 
631
- var version = "0.23.0";
631
+ var version = "0.23.1";
632
632
 
633
633
  const cli = cac("vite-node");
634
634
  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
@@ -326,14 +326,9 @@ function defineExport(exports, key, value) {
326
326
  });
327
327
  }
328
328
  function exportAll(exports, sourceModule) {
329
- var _a;
330
329
  if (exports === sourceModule)
331
330
  return;
332
- const type = utils.getType(sourceModule);
333
- if (type !== "Object" && type !== "Module")
334
- return;
335
- const constructor = (_a = sourceModule.constructor) == null ? void 0 : _a.name;
336
- if (constructor && constructor !== "Object")
331
+ if (typeof sourceModule !== "object" || Array.isArray(sourceModule) || !sourceModule)
337
332
  return;
338
333
  for (const key in sourceModule) {
339
334
  if (key !== "default") {
package/dist/client.mjs CHANGED
@@ -4,7 +4,7 @@ import vm from 'vm';
4
4
  import { resolve, dirname, isAbsolute, extname } from 'pathe';
5
5
  import { isNodeBuiltin } from 'mlly';
6
6
  import createDebug from 'debug';
7
- import { normalizeModuleId, slash, normalizeRequestId, toFilePath, isPrimitive, getType, mergeSlashes } from './utils.mjs';
7
+ import { normalizeModuleId, slash, normalizeRequestId, toFilePath, isPrimitive, mergeSlashes } from './utils.mjs';
8
8
 
9
9
  const debugExecute = createDebug("vite-node:client:execute");
10
10
  const debugNative = createDebug("vite-node:client:native");
@@ -299,14 +299,9 @@ function defineExport(exports, key, value) {
299
299
  });
300
300
  }
301
301
  function exportAll(exports, sourceModule) {
302
- var _a;
303
302
  if (exports === sourceModule)
304
303
  return;
305
- const type = getType(sourceModule);
306
- if (type !== "Object" && type !== "Module")
307
- return;
308
- const constructor = (_a = sourceModule.constructor) == null ? void 0 : _a.name;
309
- if (constructor && constructor !== "Object")
304
+ if (typeof sourceModule !== "object" || Array.isArray(sourceModule) || !sourceModule)
310
305
  return;
311
306
  for (const key in sourceModule) {
312
307
  if (key !== "default") {
package/dist/utils.cjs CHANGED
@@ -4,14 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var url = require('url');
6
6
  var pathe = require('pathe');
7
+ var mlly = require('mlly');
7
8
 
8
9
  const isWindows = process.platform === "win32";
9
10
  function slash(str) {
10
11
  return str.replace(/\\/g, "/");
11
12
  }
12
- function getType(value) {
13
- return Object.prototype.toString.apply(value).slice(8, -1);
14
- }
15
13
  function mergeSlashes(str) {
16
14
  return str.replace(/\/\//g, "/");
17
15
  }
@@ -26,6 +24,23 @@ function normalizeModuleId(id) {
26
24
  function isPrimitive(v) {
27
25
  return v !== Object(v);
28
26
  }
27
+ function pathFromRoot(root, filename) {
28
+ if (mlly.isNodeBuiltin(filename))
29
+ return filename;
30
+ filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
31
+ if (!filename.startsWith(root))
32
+ return filename;
33
+ const relativePath = pathe.relative(root, filename);
34
+ if (!relativePath.startsWith("/") && !relativePath.startsWith("."))
35
+ return `/${relativePath}`;
36
+ let index = 0;
37
+ for (const char of relativePath) {
38
+ if (char !== "." && char !== "/")
39
+ return relativePath.slice(index - 1);
40
+ index++;
41
+ }
42
+ return relativePath;
43
+ }
29
44
  function toFilePath(id, root) {
30
45
  let absolute = id.startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? pathe.resolve(root, id.slice(1)) : id;
31
46
  if (absolute.startsWith("//"))
@@ -53,12 +68,12 @@ function toArray(array) {
53
68
  return [array];
54
69
  }
55
70
 
56
- exports.getType = getType;
57
71
  exports.isPrimitive = isPrimitive;
58
72
  exports.isWindows = isWindows;
59
73
  exports.mergeSlashes = mergeSlashes;
60
74
  exports.normalizeModuleId = normalizeModuleId;
61
75
  exports.normalizeRequestId = normalizeRequestId;
76
+ exports.pathFromRoot = pathFromRoot;
62
77
  exports.slash = slash;
63
78
  exports.toArray = toArray;
64
79
  exports.toFilePath = toFilePath;
package/dist/utils.d.ts CHANGED
@@ -3,11 +3,11 @@ import { N as Nullable, A as Arrayable } from './types-dca976ee.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
6
- declare function getType(value: unknown): string;
7
6
  declare function mergeSlashes(str: string): string;
8
7
  declare function normalizeRequestId(id: string, base?: string): string;
9
8
  declare function normalizeModuleId(id: string): string;
10
9
  declare function isPrimitive(v: any): boolean;
10
+ declare function pathFromRoot(root: string, filename: string): string;
11
11
  declare function toFilePath(id: string, root: string): string;
12
12
  declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
13
13
  /**
@@ -17,4 +17,4 @@ declare function withInlineSourcemap(result: TransformResult): Promise<Transform
17
17
  */
18
18
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
19
19
 
20
- export { getType, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
20
+ export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, slash, toArray, toFilePath, withInlineSourcemap };
package/dist/utils.mjs CHANGED
@@ -1,13 +1,11 @@
1
1
  import { fileURLToPath, pathToFileURL } from 'url';
2
- import { resolve } from 'pathe';
2
+ import { relative, resolve } from 'pathe';
3
+ import { isNodeBuiltin } from 'mlly';
3
4
 
4
5
  const isWindows = process.platform === "win32";
5
6
  function slash(str) {
6
7
  return str.replace(/\\/g, "/");
7
8
  }
8
- function getType(value) {
9
- return Object.prototype.toString.apply(value).slice(8, -1);
10
- }
11
9
  function mergeSlashes(str) {
12
10
  return str.replace(/\/\//g, "/");
13
11
  }
@@ -22,6 +20,23 @@ function normalizeModuleId(id) {
22
20
  function isPrimitive(v) {
23
21
  return v !== Object(v);
24
22
  }
23
+ function pathFromRoot(root, filename) {
24
+ if (isNodeBuiltin(filename))
25
+ return filename;
26
+ filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
27
+ if (!filename.startsWith(root))
28
+ return filename;
29
+ const relativePath = relative(root, filename);
30
+ if (!relativePath.startsWith("/") && !relativePath.startsWith("."))
31
+ return `/${relativePath}`;
32
+ let index = 0;
33
+ for (const char of relativePath) {
34
+ if (char !== "." && char !== "/")
35
+ return relativePath.slice(index - 1);
36
+ index++;
37
+ }
38
+ return relativePath;
39
+ }
25
40
  function toFilePath(id, root) {
26
41
  let absolute = id.startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? resolve(root, id.slice(1)) : id;
27
42
  if (absolute.startsWith("//"))
@@ -49,4 +64,4 @@ function toArray(array) {
49
64
  return [array];
50
65
  }
51
66
 
52
- export { getType, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
67
+ export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, slash, toArray, toFilePath, withInlineSourcemap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",