vite-node 1.6.0 → 2.0.0-beta.10

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 = "1.6.0";
23
+ var version = "2.0.0-beta.10";
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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { V as ViteNodeServerOptions } from './index-O2IrwHKf.js';
2
- import './trace-mapping.d-xyIfZtPm.js';
1
+ import { V as ViteNodeServerOptions } from './index-D1EszD4V.js';
2
+ import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  interface CliOptions {
5
5
  'root'?: string;
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 = "1.6.0";
21
+ var version = "2.0.0-beta.10";
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.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-O2IrwHKf.js';
2
- import './trace-mapping.d-xyIfZtPm.js';
1
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-D1EszD4V.js';
2
+ import './trace-mapping.d-DLVdEqOp.js';
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/hmr.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-O2IrwHKf.js';
4
- import './trace-mapping.d-xyIfZtPm.js';
3
+ import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-D1EszD4V.js';
4
+ import './trace-mapping.d-DLVdEqOp.js';
5
5
 
6
6
  type EventType = string | symbol;
7
7
  type Handler<T = unknown> = (event: T) => void;
@@ -1,4 +1,4 @@
1
- import { E as EncodedSourceMap } from './trace-mapping.d-xyIfZtPm.js';
1
+ import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
2
2
 
3
3
  type HMRPayload =
4
4
  | ConnectedPayload
@@ -274,6 +274,11 @@ interface ViteNodeResolveId {
274
274
  moduleSideEffects?: boolean | 'no-treeshake' | null;
275
275
  syntheticNamedExports?: boolean | string | null;
276
276
  }
277
+ interface ViteNodeResolveModule {
278
+ external: string | null;
279
+ id: string;
280
+ fsPath: string;
281
+ }
277
282
  interface ViteNodeServerOptions {
278
283
  /**
279
284
  * Inject inline sourcemap to modules
@@ -306,4 +311,4 @@ interface DebuggerOptions {
306
311
  loadDumppedModules?: boolean;
307
312
  }
308
313
 
309
- export { type Arrayable as A, type CustomEventMap as C, type DebuggerOptions as D, type FetchResult as F, type HMRPayload as H, ModuleCacheMap as M, type Nullable as N, type RawSourceMap as R, type StartOfSourceMap as S, type ViteNodeServerOptions as V, ViteNodeRunner as a, type HotContext as b, type DepsHandlingOptions as c, type ViteNodeResolveId as d, DEFAULT_REQUEST_STUBS as e, type Awaitable as f, type FetchFunction as g, type ResolveIdFunction as h, type CreateHotContextFunction as i, type ModuleCache as j, type ViteNodeRunnerOptions as k };
314
+ export { type Arrayable as A, type CustomEventMap as C, type DebuggerOptions as D, type FetchResult as F, type HMRPayload as H, ModuleCacheMap as M, type Nullable as N, type RawSourceMap as R, type StartOfSourceMap as S, type ViteNodeServerOptions as V, ViteNodeRunner as a, type HotContext as b, type DepsHandlingOptions as c, type ViteNodeResolveId as d, DEFAULT_REQUEST_STUBS as e, type Awaitable as f, type FetchFunction as g, type ResolveIdFunction as h, type CreateHotContextFunction as i, type ModuleCache as j, type ViteNodeRunnerOptions as k, type ViteNodeResolveModule as l };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-O2IrwHKf.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-xyIfZtPm.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, l as ViteNodeResolveModule, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-D1EszD4V.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
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
  }
@@ -284,6 +284,20 @@ class ViteNodeServer {
284
284
  const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
285
285
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
286
286
  }
287
+ async resolveModule(rawId, resolved) {
288
+ const id = (resolved == null ? void 0 : resolved.id) || rawId;
289
+ const external = !pathe.isAbsolute(id) || this.isModuleDirectory(id) ? rawId : null;
290
+ return {
291
+ id,
292
+ fsPath: utils.cleanUrl(id),
293
+ external
294
+ };
295
+ }
296
+ isModuleDirectory(path) {
297
+ var _a;
298
+ const moduleDirectories = ((_a = this.options.deps) == null ? void 0 : _a.moduleDirectories) || ["/node_modules/"];
299
+ return moduleDirectories.some((dir) => path.includes(dir));
300
+ }
287
301
  getSourceMap(source) {
288
302
  var _a, _b;
289
303
  const fetchResult = (_a = this.fetchCache.get(source)) == null ? void 0 : _a.result;
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-O2IrwHKf.js';
3
- import { E as EncodedSourceMap } from './trace-mapping.d-xyIfZtPm.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-D1EszD4V.js';
3
+ import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
4
4
 
5
5
  declare class Debugger {
6
6
  options: DebuggerOptions;
@@ -43,6 +43,12 @@ declare class ViteNodeServer {
43
43
  getTotalDuration(): number;
44
44
  private ensureExists;
45
45
  resolveId(id: string, importer?: string, transformMode?: 'web' | 'ssr'): Promise<ViteNodeResolveId | null>;
46
+ resolveModule(rawId: string, resolved: ViteNodeResolveId | null): Promise<{
47
+ id: string;
48
+ fsPath: string;
49
+ external: string | null;
50
+ }>;
51
+ private isModuleDirectory;
46
52
  getSourceMap(source: string): EncodedSourceMap | null;
47
53
  private assertMode;
48
54
  fetchModule(id: string, transformMode?: 'web' | 'ssr'): Promise<FetchResult>;
package/dist/server.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { existsSync, promises } from 'node:fs';
3
3
  import assert from 'node:assert';
4
- import { join, extname, dirname, resolve, relative, normalize } from 'pathe';
4
+ import { join, extname, dirname, resolve, relative, normalize, isAbsolute } from 'pathe';
5
5
  import createDebug from 'debug';
6
- import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
6
+ import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, cleanUrl, normalizeModuleId, toFilePath } from './utils.mjs';
7
7
  import { KNOWN_ASSET_TYPES } from './constants.mjs';
8
8
  import c from 'picocolors';
9
9
  import { withInlineSourcemap } from './source-map.mjs';
@@ -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
  }
@@ -282,6 +282,20 @@ class ViteNodeServer {
282
282
  const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
283
283
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
284
284
  }
285
+ async resolveModule(rawId, resolved) {
286
+ const id = (resolved == null ? void 0 : resolved.id) || rawId;
287
+ const external = !isAbsolute(id) || this.isModuleDirectory(id) ? rawId : null;
288
+ return {
289
+ id,
290
+ fsPath: cleanUrl(id),
291
+ external
292
+ };
293
+ }
294
+ isModuleDirectory(path) {
295
+ var _a;
296
+ const moduleDirectories = ((_a = this.options.deps) == null ? void 0 : _a.moduleDirectories) || ["/node_modules/"];
297
+ return moduleDirectories.some((dir) => path.includes(dir));
298
+ }
285
299
  getSourceMap(source) {
286
300
  var _a, _b;
287
301
  const fetchResult = (_a = this.fetchCache.get(source)) == null ? void 0 : _a.result;
@@ -479,16 +479,6 @@ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
479
479
  const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
480
480
  const LEAST_UPPER_BOUND = -1;
481
481
  const GREATEST_LOWER_BOUND = 1;
482
- /**
483
- * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
484
- */
485
- let decodedMappings;
486
- /**
487
- * A higher-level API to find the source/line/column associated with a generated line/column
488
- * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
489
- * `source-map` library.
490
- */
491
- let originalPositionFor;
492
482
  class TraceMap {
493
483
  constructor(map, mapUrl) {
494
484
  const isString = typeof map === 'string';
@@ -502,6 +492,7 @@ class TraceMap {
502
492
  this.sourceRoot = sourceRoot;
503
493
  this.sources = sources;
504
494
  this.sourcesContent = sourcesContent;
495
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
505
496
  const from = resolve(sourceRoot || '', stripFilename(mapUrl));
506
497
  this.resolvedSources = sources.map((s) => resolve(s || '', from));
507
498
  const { mappings } = parsed;
@@ -518,32 +509,47 @@ class TraceMap {
518
509
  this._bySourceMemos = undefined;
519
510
  }
520
511
  }
521
- (() => {
522
- decodedMappings = (map) => {
523
- return (map._decoded || (map._decoded = decode(map._encoded)));
524
- };
525
- originalPositionFor = (map, { line, column, bias }) => {
526
- line--;
527
- if (line < 0)
528
- throw new Error(LINE_GTR_ZERO);
529
- if (column < 0)
530
- throw new Error(COL_GTR_EQ_ZERO);
531
- const decoded = decodedMappings(map);
532
- // It's common for parent source maps to have pointers to lines that have no
533
- // mapping (like a "//# sourceMappingURL=") at the end of the child file.
534
- if (line >= decoded.length)
535
- return OMapping(null, null, null, null);
536
- const segments = decoded[line];
537
- const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
538
- if (index === -1)
539
- return OMapping(null, null, null, null);
540
- const segment = segments[index];
541
- if (segment.length === 1)
542
- return OMapping(null, null, null, null);
543
- const { names, resolvedSources } = map;
544
- return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
545
- };
546
- })();
512
+ /**
513
+ * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
514
+ * with public access modifiers.
515
+ */
516
+ function cast(map) {
517
+ return map;
518
+ }
519
+ /**
520
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
521
+ */
522
+ function decodedMappings(map) {
523
+ var _a;
524
+ return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
525
+ }
526
+ /**
527
+ * A higher-level API to find the source/line/column associated with a generated line/column
528
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
529
+ * `source-map` library.
530
+ */
531
+ function originalPositionFor(map, needle) {
532
+ let { line, column, bias } = needle;
533
+ line--;
534
+ if (line < 0)
535
+ throw new Error(LINE_GTR_ZERO);
536
+ if (column < 0)
537
+ throw new Error(COL_GTR_EQ_ZERO);
538
+ const decoded = decodedMappings(map);
539
+ // It's common for parent source maps to have pointers to lines that have no
540
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
541
+ if (line >= decoded.length)
542
+ return OMapping(null, null, null, null);
543
+ const segments = decoded[line];
544
+ const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
545
+ if (index === -1)
546
+ return OMapping(null, null, null, null);
547
+ const segment = segments[index];
548
+ if (segment.length === 1)
549
+ return OMapping(null, null, null, null);
550
+ const { names, resolvedSources } = map;
551
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
552
+ }
547
553
  function OMapping(source, line, column, name) {
548
554
  return { source, line, column, name };
549
555
  }
@@ -603,10 +609,10 @@ function supportRelativeURL(file, url) {
603
609
  if (!file)
604
610
  return url;
605
611
  const dir = path.dirname(file);
606
- const match = /^\w+:\/\/[^\/]*/.exec(dir);
612
+ const match = /^\w+:\/\/[^/]*/.exec(dir);
607
613
  let protocol = match ? match[0] : "";
608
614
  const startPath = dir.slice(protocol.length);
609
- if (protocol && /^\/\w\:/.test(startPath)) {
615
+ if (protocol && /^\/\w:/.test(startPath)) {
610
616
  protocol += "/";
611
617
  return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
612
618
  }
@@ -616,10 +622,9 @@ function retrieveSourceMapURL(source) {
616
622
  const fileData = retrieveFile(source);
617
623
  if (!fileData)
618
624
  return null;
619
- 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;
620
626
  let lastMatch, match;
621
- while (match = re.exec(fileData))
622
- lastMatch = match;
627
+ while (match = re.exec(fileData)) lastMatch = match;
623
628
  if (!lastMatch)
624
629
  return null;
625
630
  return lastMatch[1];
@@ -779,7 +784,7 @@ function wrapCallSite(frame, state) {
779
784
  if (source) {
780
785
  const line = frame.getLineNumber();
781
786
  let column = frame.getColumnNumber() - 1;
782
- 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)/;
783
788
  const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
784
789
  if (line === 1 && column > headerLength && !frame.isEval())
785
790
  column -= headerLength;
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { E as EncodedSourceMap } from './trace-mapping.d-xyIfZtPm.js';
2
+ import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => EncodedSourceMap | null | undefined;
@@ -477,16 +477,6 @@ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
477
477
  const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
478
478
  const LEAST_UPPER_BOUND = -1;
479
479
  const GREATEST_LOWER_BOUND = 1;
480
- /**
481
- * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
482
- */
483
- let decodedMappings;
484
- /**
485
- * A higher-level API to find the source/line/column associated with a generated line/column
486
- * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
487
- * `source-map` library.
488
- */
489
- let originalPositionFor;
490
480
  class TraceMap {
491
481
  constructor(map, mapUrl) {
492
482
  const isString = typeof map === 'string';
@@ -500,6 +490,7 @@ class TraceMap {
500
490
  this.sourceRoot = sourceRoot;
501
491
  this.sources = sources;
502
492
  this.sourcesContent = sourcesContent;
493
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
503
494
  const from = resolve(sourceRoot || '', stripFilename(mapUrl));
504
495
  this.resolvedSources = sources.map((s) => resolve(s || '', from));
505
496
  const { mappings } = parsed;
@@ -516,32 +507,47 @@ class TraceMap {
516
507
  this._bySourceMemos = undefined;
517
508
  }
518
509
  }
519
- (() => {
520
- decodedMappings = (map) => {
521
- return (map._decoded || (map._decoded = decode(map._encoded)));
522
- };
523
- originalPositionFor = (map, { line, column, bias }) => {
524
- line--;
525
- if (line < 0)
526
- throw new Error(LINE_GTR_ZERO);
527
- if (column < 0)
528
- throw new Error(COL_GTR_EQ_ZERO);
529
- const decoded = decodedMappings(map);
530
- // It's common for parent source maps to have pointers to lines that have no
531
- // mapping (like a "//# sourceMappingURL=") at the end of the child file.
532
- if (line >= decoded.length)
533
- return OMapping(null, null, null, null);
534
- const segments = decoded[line];
535
- const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
536
- if (index === -1)
537
- return OMapping(null, null, null, null);
538
- const segment = segments[index];
539
- if (segment.length === 1)
540
- return OMapping(null, null, null, null);
541
- const { names, resolvedSources } = map;
542
- return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
543
- };
544
- })();
510
+ /**
511
+ * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
512
+ * with public access modifiers.
513
+ */
514
+ function cast(map) {
515
+ return map;
516
+ }
517
+ /**
518
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
519
+ */
520
+ function decodedMappings(map) {
521
+ var _a;
522
+ return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
523
+ }
524
+ /**
525
+ * A higher-level API to find the source/line/column associated with a generated line/column
526
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
527
+ * `source-map` library.
528
+ */
529
+ function originalPositionFor(map, needle) {
530
+ let { line, column, bias } = needle;
531
+ line--;
532
+ if (line < 0)
533
+ throw new Error(LINE_GTR_ZERO);
534
+ if (column < 0)
535
+ throw new Error(COL_GTR_EQ_ZERO);
536
+ const decoded = decodedMappings(map);
537
+ // It's common for parent source maps to have pointers to lines that have no
538
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
539
+ if (line >= decoded.length)
540
+ return OMapping(null, null, null, null);
541
+ const segments = decoded[line];
542
+ const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
543
+ if (index === -1)
544
+ return OMapping(null, null, null, null);
545
+ const segment = segments[index];
546
+ if (segment.length === 1)
547
+ return OMapping(null, null, null, null);
548
+ const { names, resolvedSources } = map;
549
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
550
+ }
545
551
  function OMapping(source, line, column, name) {
546
552
  return { source, line, column, name };
547
553
  }
@@ -601,10 +607,10 @@ function supportRelativeURL(file, url) {
601
607
  if (!file)
602
608
  return url;
603
609
  const dir = path.dirname(file);
604
- const match = /^\w+:\/\/[^\/]*/.exec(dir);
610
+ const match = /^\w+:\/\/[^/]*/.exec(dir);
605
611
  let protocol = match ? match[0] : "";
606
612
  const startPath = dir.slice(protocol.length);
607
- if (protocol && /^\/\w\:/.test(startPath)) {
613
+ if (protocol && /^\/\w:/.test(startPath)) {
608
614
  protocol += "/";
609
615
  return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
610
616
  }
@@ -614,10 +620,9 @@ function retrieveSourceMapURL(source) {
614
620
  const fileData = retrieveFile(source);
615
621
  if (!fileData)
616
622
  return null;
617
- 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;
618
624
  let lastMatch, match;
619
- while (match = re.exec(fileData))
620
- lastMatch = match;
625
+ while (match = re.exec(fileData)) lastMatch = match;
621
626
  if (!lastMatch)
622
627
  return null;
623
628
  return lastMatch[1];
@@ -777,7 +782,7 @@ function wrapCallSite(frame, state) {
777
782
  if (source) {
778
783
  const line = frame.getLineNumber();
779
784
  let column = frame.getColumnNumber() - 1;
780
- 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)/;
781
786
  const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
782
787
  if (line === 1 && column > headerLength && !frame.isEval())
783
788
  column -= headerLength;
@@ -12,6 +12,7 @@ interface SourceMapV3 {
12
12
  sources: (string | null)[];
13
13
  sourcesContent?: (string | null)[];
14
14
  version: 3;
15
+ ignoreList?: number[];
15
16
  }
16
17
  interface EncodedSourceMap extends SourceMapV3 {
17
18
  mappings: string;
@@ -19,7 +20,12 @@ interface EncodedSourceMap extends SourceMapV3 {
19
20
  interface DecodedSourceMap extends SourceMapV3 {
20
21
  mappings: SourceMapSegment[][];
21
22
  }
22
- type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
23
+ type XInput = {
24
+ x_google_ignoreList?: SourceMapV3['ignoreList'];
25
+ };
26
+ type EncodedSourceMapXInput = EncodedSourceMap & XInput;
27
+ type DecodedSourceMapXInput = DecodedSourceMap & XInput;
28
+ type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
23
29
  declare abstract class SourceMap {
24
30
  version: SourceMapV3['version'];
25
31
  file: SourceMapV3['file'];
@@ -28,12 +34,8 @@ declare abstract class SourceMap {
28
34
  sources: SourceMapV3['sources'];
29
35
  sourcesContent: SourceMapV3['sourcesContent'];
30
36
  resolvedSources: SourceMapV3['sources'];
37
+ ignoreList: SourceMapV3['ignoreList'];
31
38
  }
32
- type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
33
- type RoArray<T> = Ro<T>[];
34
- type RoObject<T> = {
35
- [K in keyof T]: T[K] | Ro<T[K]>;
36
- };
37
39
 
38
40
  declare class TraceMap implements SourceMap {
39
41
  version: SourceMapV3['version'];
@@ -42,6 +44,7 @@ declare class TraceMap implements SourceMap {
42
44
  sourceRoot: SourceMapV3['sourceRoot'];
43
45
  sources: SourceMapV3['sources'];
44
46
  sourcesContent: SourceMapV3['sourcesContent'];
47
+ ignoreList: SourceMapV3['ignoreList'];
45
48
  resolvedSources: string[];
46
49
  private _encoded;
47
50
  private _decoded;
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-O2IrwHKf.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-xyIfZtPm.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, l as ViteNodeResolveModule, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-D1EszD4V.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
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
@@ -1,12 +1,10 @@
1
- import { N as Nullable, A as Arrayable } from './index-O2IrwHKf.js';
2
- import './trace-mapping.d-xyIfZtPm.js';
1
+ import { N as Nullable, A as Arrayable } from './index-D1EszD4V.js';
2
+ import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  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": "1.6.0",
4
+ "version": "2.0.0-beta.10",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -78,13 +78,13 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "cac": "^6.7.14",
81
- "debug": "^4.3.4",
82
- "pathe": "^1.1.1",
83
- "picocolors": "^1.0.0",
81
+ "debug": "^4.3.5",
82
+ "pathe": "^1.1.2",
83
+ "picocolors": "^1.0.1",
84
84
  "vite": "^5.0.0"
85
85
  },
86
86
  "devDependencies": {
87
- "@jridgewell/trace-mapping": "^0.3.22",
87
+ "@jridgewell/trace-mapping": "^0.3.25",
88
88
  "@types/debug": "^4.1.12"
89
89
  },
90
90
  "scripts": {