vite-node 2.0.0-beta.2 → 2.0.0-beta.3

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
@@ -20,7 +20,7 @@ require('node:url');
20
20
  require('node:vm');
21
21
  require('node:events');
22
22
 
23
- var version = "2.0.0-beta.2";
23
+ var version = "2.0.0-beta.3";
24
24
 
25
25
  const cli = cac("vite-node");
26
26
  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");
package/dist/cli.mjs CHANGED
@@ -18,7 +18,7 @@ import 'node:url';
18
18
  import 'node:vm';
19
19
  import 'node:events';
20
20
 
21
- var version = "2.0.0-beta.2";
21
+ var version = "2.0.0-beta.3";
22
22
 
23
23
  const cli = cac("vite-node");
24
24
  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");
package/dist/client.cjs CHANGED
@@ -344,7 +344,7 @@ ${getStack()}`), 2e3);
344
344
  });
345
345
  debugExecute(__filename);
346
346
  if (transformed[0] === "#")
347
- transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
347
+ transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
348
348
  await this.runModule(context, transformed);
349
349
  return exports;
350
350
  }
package/dist/client.mjs CHANGED
@@ -342,7 +342,7 @@ ${getStack()}`), 2e3);
342
342
  });
343
343
  debugExecute(__filename);
344
344
  if (transformed[0] === "#")
345
- transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
345
+ transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
346
346
  await this.runModule(context, transformed);
347
347
  return exports;
348
348
  }
package/dist/server.cjs CHANGED
@@ -14,7 +14,7 @@ require('node:module');
14
14
  require('node:path');
15
15
 
16
16
  const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
17
- const ESM_SYNTAX_RE = /([\s;]|^)(import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
17
+ const ESM_SYNTAX_RE = /(?:[\s;]|^)(?:import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
18
18
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
19
19
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
20
20
  const defaultInline = [
@@ -63,7 +63,7 @@ async function isValidNodeImport(id) {
63
63
  const package_ = await utils.findNearestPackageData(pathe.dirname(id));
64
64
  if (package_.type === "module")
65
65
  return true;
66
- if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
66
+ if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id))
67
67
  return false;
68
68
  const code = await fs.promises.readFile(id, "utf8").catch(() => "");
69
69
  return !ESM_SYNTAX_RE.test(code);
@@ -77,7 +77,7 @@ async function shouldExternalize(id, options, cache = _defaultExternalizeCache)
77
77
  async function _shouldExternalize(id, options) {
78
78
  if (utils.isNodeBuiltin(id))
79
79
  return id;
80
- if (id.startsWith("data:") || /^(https?:)?\/\//.test(id))
80
+ if (id.startsWith("data:") || /^(?:https?:)?\/\//.test(id))
81
81
  return id;
82
82
  id = patchWindowsImportPath(id);
83
83
  if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
@@ -153,7 +153,7 @@ class Debugger {
153
153
  await fs.promises.mkdir(this.dumpDir, { recursive: true });
154
154
  }
155
155
  encodeId(id) {
156
- return `${id.replace(/[^\w@_-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
156
+ return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
157
157
  }
158
158
  async recordExternalize(id, path) {
159
159
  if (!this.dumpDir)
@@ -179,7 +179,7 @@ ${result.code}`, "utf-8");
179
179
  return null;
180
180
  const code = await fs.promises.readFile(path, "utf-8");
181
181
  return {
182
- code: code.replace(/^\/\/.*?\n/, ""),
182
+ code: code.replace(/^\/\/.*\n/, ""),
183
183
  map: void 0
184
184
  };
185
185
  }
package/dist/server.mjs CHANGED
@@ -12,7 +12,7 @@ import 'node:module';
12
12
  import 'node:path';
13
13
 
14
14
  const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
15
- const ESM_SYNTAX_RE = /([\s;]|^)(import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
15
+ const ESM_SYNTAX_RE = /(?:[\s;]|^)(?:import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
16
16
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
17
17
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
18
18
  const defaultInline = [
@@ -61,7 +61,7 @@ async function isValidNodeImport(id) {
61
61
  const package_ = await findNearestPackageData(dirname(id));
62
62
  if (package_.type === "module")
63
63
  return true;
64
- if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
64
+ if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id))
65
65
  return false;
66
66
  const code = await promises.readFile(id, "utf8").catch(() => "");
67
67
  return !ESM_SYNTAX_RE.test(code);
@@ -75,7 +75,7 @@ async function shouldExternalize(id, options, cache = _defaultExternalizeCache)
75
75
  async function _shouldExternalize(id, options) {
76
76
  if (isNodeBuiltin(id))
77
77
  return id;
78
- if (id.startsWith("data:") || /^(https?:)?\/\//.test(id))
78
+ if (id.startsWith("data:") || /^(?:https?:)?\/\//.test(id))
79
79
  return id;
80
80
  id = patchWindowsImportPath(id);
81
81
  if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
@@ -151,7 +151,7 @@ class Debugger {
151
151
  await promises.mkdir(this.dumpDir, { recursive: true });
152
152
  }
153
153
  encodeId(id) {
154
- return `${id.replace(/[^\w@_-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
154
+ return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
155
155
  }
156
156
  async recordExternalize(id, path) {
157
157
  if (!this.dumpDir)
@@ -177,7 +177,7 @@ ${result.code}`, "utf-8");
177
177
  return null;
178
178
  const code = await promises.readFile(path, "utf-8");
179
179
  return {
180
- code: code.replace(/^\/\/.*?\n/, ""),
180
+ code: code.replace(/^\/\/.*\n/, ""),
181
181
  map: void 0
182
182
  };
183
183
  }
@@ -609,10 +609,10 @@ function supportRelativeURL(file, url) {
609
609
  if (!file)
610
610
  return url;
611
611
  const dir = path.dirname(file);
612
- const match = /^\w+:\/\/[^\/]*/.exec(dir);
612
+ const match = /^\w+:\/\/[^/]*/.exec(dir);
613
613
  let protocol = match ? match[0] : "";
614
614
  const startPath = dir.slice(protocol.length);
615
- if (protocol && /^\/\w\:/.test(startPath)) {
615
+ if (protocol && /^\/\w:/.test(startPath)) {
616
616
  protocol += "/";
617
617
  return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
618
618
  }
@@ -622,7 +622,7 @@ function retrieveSourceMapURL(source) {
622
622
  const fileData = retrieveFile(source);
623
623
  if (!fileData)
624
624
  return null;
625
- const re = /(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/mg;
625
+ const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
626
626
  let lastMatch, match;
627
627
  while (match = re.exec(fileData)) lastMatch = match;
628
628
  if (!lastMatch)
@@ -784,7 +784,7 @@ function wrapCallSite(frame, state) {
784
784
  if (source) {
785
785
  const line = frame.getLineNumber();
786
786
  let column = frame.getColumnNumber() - 1;
787
- const noHeader = /^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/;
787
+ 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)/;
788
788
  const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
789
789
  if (line === 1 && column > headerLength && !frame.isEval())
790
790
  column -= headerLength;
@@ -607,10 +607,10 @@ function supportRelativeURL(file, url) {
607
607
  if (!file)
608
608
  return url;
609
609
  const dir = path.dirname(file);
610
- const match = /^\w+:\/\/[^\/]*/.exec(dir);
610
+ const match = /^\w+:\/\/[^/]*/.exec(dir);
611
611
  let protocol = match ? match[0] : "";
612
612
  const startPath = dir.slice(protocol.length);
613
- if (protocol && /^\/\w\:/.test(startPath)) {
613
+ if (protocol && /^\/\w:/.test(startPath)) {
614
614
  protocol += "/";
615
615
  return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
616
616
  }
@@ -620,7 +620,7 @@ function retrieveSourceMapURL(source) {
620
620
  const fileData = retrieveFile(source);
621
621
  if (!fileData)
622
622
  return null;
623
- const re = /(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/mg;
623
+ const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
624
624
  let lastMatch, match;
625
625
  while (match = re.exec(fileData)) lastMatch = match;
626
626
  if (!lastMatch)
@@ -782,7 +782,7 @@ function wrapCallSite(frame, state) {
782
782
  if (source) {
783
783
  const line = frame.getLineNumber();
784
784
  let column = frame.getColumnNumber() - 1;
785
- const noHeader = /^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/;
785
+ 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)/;
786
786
  const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
787
787
  if (line === 1 && column > headerLength && !frame.isEval())
788
788
  column -= headerLength;
package/dist/utils.cjs CHANGED
@@ -21,16 +21,15 @@ function normalizeRequestId(id, base) {
21
21
  id = id.replace(driveOppositeRegext, `${drive}$1`);
22
22
  return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
23
23
  }
24
- const queryRE = /\?.*$/s;
25
- const hashRE = /#.*$/s;
24
+ const postfixRE = /[?#].*$/;
26
25
  function cleanUrl(url) {
27
- return url.replace(hashRE, "").replace(queryRE, "");
26
+ return url.replace(postfixRE, "");
28
27
  }
29
28
  const internalRequests = [
30
29
  "@vite/client",
31
30
  "@vite/env"
32
31
  ];
33
- const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
32
+ const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`);
34
33
  function isInternalRequest(id) {
35
34
  return internalRequestRegexp.test(id);
36
35
  }
@@ -179,14 +178,12 @@ exports.cleanUrl = cleanUrl;
179
178
  exports.createImportMetaEnvProxy = createImportMetaEnvProxy;
180
179
  exports.findNearestPackageData = findNearestPackageData;
181
180
  exports.getCachedData = getCachedData;
182
- exports.hashRE = hashRE;
183
181
  exports.isInternalRequest = isInternalRequest;
184
182
  exports.isNodeBuiltin = isNodeBuiltin;
185
183
  exports.isPrimitive = isPrimitive;
186
184
  exports.isWindows = isWindows;
187
185
  exports.normalizeModuleId = normalizeModuleId;
188
186
  exports.normalizeRequestId = normalizeRequestId;
189
- exports.queryRE = queryRE;
190
187
  exports.setCacheData = setCacheData;
191
188
  exports.slash = slash;
192
189
  exports.toArray = toArray;
package/dist/utils.d.ts CHANGED
@@ -5,8 +5,6 @@ declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
6
6
  declare const VALID_ID_PREFIX = "/@id/";
7
7
  declare function normalizeRequestId(id: string, base?: string): string;
8
- declare const queryRE: RegExp;
9
- declare const hashRE: RegExp;
10
8
  declare function cleanUrl(url: string): string;
11
9
  declare function isInternalRequest(id: string): boolean;
12
10
  declare function normalizeModuleId(id: string): string;
@@ -30,4 +28,4 @@ declare function findNearestPackageData(basedir: string): Promise<{
30
28
  type?: 'module' | 'commonjs';
31
29
  }>;
32
30
 
33
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
31
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/dist/utils.mjs CHANGED
@@ -19,16 +19,15 @@ function normalizeRequestId(id, base) {
19
19
  id = id.replace(driveOppositeRegext, `${drive}$1`);
20
20
  return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
21
21
  }
22
- const queryRE = /\?.*$/s;
23
- const hashRE = /#.*$/s;
22
+ const postfixRE = /[?#].*$/;
24
23
  function cleanUrl(url) {
25
- return url.replace(hashRE, "").replace(queryRE, "");
24
+ return url.replace(postfixRE, "");
26
25
  }
27
26
  const internalRequests = [
28
27
  "@vite/client",
29
28
  "@vite/env"
30
29
  ];
31
- const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
30
+ const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`);
32
31
  function isInternalRequest(id) {
33
32
  return internalRequestRegexp.test(id);
34
33
  }
@@ -172,4 +171,4 @@ async function findNearestPackageData(basedir) {
172
171
  return {};
173
172
  }
174
173
 
175
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
174
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.2",
4
+ "version": "2.0.0-beta.3",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",