vite-node 1.1.3 → 1.2.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
@@ -20,7 +20,7 @@ require('node:url');
20
20
  require('node:vm');
21
21
  require('node:events');
22
22
 
23
- var version = "1.1.3";
23
+ var version = "1.2.1";
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-IeUJleJC.js';
2
- import './trace-mapping.d-aA9jxPtH.js';
1
+ import { V as ViteNodeServerOptions } from './index-WT31LSgS.js';
2
+ import './trace-mapping.d-xyIfZtPm.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.1.3";
21
+ var version = "1.2.1";
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.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-IeUJleJC.js';
2
- import './trace-mapping.d-aA9jxPtH.js';
1
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-WT31LSgS.js';
2
+ import './trace-mapping.d-xyIfZtPm.js';
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-IeUJleJC.js';
4
- import './trace-mapping.d-aA9jxPtH.js';
3
+ import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-WT31LSgS.js';
4
+ import './trace-mapping.d-xyIfZtPm.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-aA9jxPtH.js';
1
+ import { E as EncodedSourceMap } from './trace-mapping.d-xyIfZtPm.js';
2
2
 
3
3
  type HMRPayload =
4
4
  | ConnectedPayload
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-IeUJleJC.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-aA9jxPtH.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, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-WT31LSgS.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-xyIfZtPm.js';
package/dist/server.cjs CHANGED
@@ -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:"))
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))
@@ -208,7 +208,8 @@ class ViteNodeServer {
208
208
  (_a = options.deps).inline ?? (_a.inline = true);
209
209
  } else if (options.deps.inline !== true) {
210
210
  (_b = options.deps).inline ?? (_b.inline = []);
211
- options.deps.inline.push(...utils.toArray(ssrOptions.noExternal));
211
+ const inline = options.deps.inline;
212
+ options.deps.inline.push(...utils.toArray(ssrOptions.noExternal).filter((dep) => !inline.includes(dep)));
212
213
  }
213
214
  }
214
215
  if (process.env.VITE_NODE_DEBUG_DUMP) {
@@ -331,6 +332,25 @@ class ViteNodeServer {
331
332
  return "ssr";
332
333
  return "web";
333
334
  }
335
+ getChangedModule(id, file) {
336
+ const module = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(file);
337
+ if (module)
338
+ return module;
339
+ const _modules = this.server.moduleGraph.getModulesByFile(file);
340
+ if (!_modules || !_modules.size)
341
+ return null;
342
+ const modules = [..._modules];
343
+ let mod = modules[0];
344
+ let latestMax = -1;
345
+ for (const m of _modules) {
346
+ const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp);
347
+ if (timestamp > latestMax) {
348
+ latestMax = timestamp;
349
+ mod = m;
350
+ }
351
+ }
352
+ return mod;
353
+ }
334
354
  async _fetchModule(id, transformMode) {
335
355
  var _a, _b;
336
356
  let result;
@@ -345,7 +365,7 @@ class ViteNodeServer {
345
365
  clearTimeout(timeout);
346
366
  }
347
367
  const { path: filePath } = utils.toFilePath(id, this.server.config.root);
348
- const moduleNode = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(filePath);
368
+ const moduleNode = this.getChangedModule(id, filePath);
349
369
  const cache = this.fetchCaches[transformMode].get(filePath);
350
370
  const timestamp = moduleNode ? Math.max(moduleNode.lastHMRTimestamp, moduleNode.lastInvalidationTimestamp) : 0;
351
371
  if (cache && (timestamp === 0 || cache.timestamp >= timestamp))
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-IeUJleJC.js';
3
- import { E as EncodedSourceMap } from './trace-mapping.d-aA9jxPtH.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-WT31LSgS.js';
3
+ import { E as EncodedSourceMap } from './trace-mapping.d-xyIfZtPm.js';
4
4
 
5
5
  declare class Debugger {
6
6
  options: DebuggerOptions;
@@ -49,6 +49,7 @@ declare class ViteNodeServer {
49
49
  code: string | undefined;
50
50
  }>;
51
51
  getTransformMode(id: string): "web" | "ssr";
52
+ private getChangedModule;
52
53
  private _fetchModule;
53
54
  protected processTransformResult(filepath: string, result: TransformResult): Promise<TransformResult>;
54
55
  private _transformRequest;
package/dist/server.mjs CHANGED
@@ -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:"))
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))
@@ -206,7 +206,8 @@ class ViteNodeServer {
206
206
  (_a = options.deps).inline ?? (_a.inline = true);
207
207
  } else if (options.deps.inline !== true) {
208
208
  (_b = options.deps).inline ?? (_b.inline = []);
209
- options.deps.inline.push(...toArray(ssrOptions.noExternal));
209
+ const inline = options.deps.inline;
210
+ options.deps.inline.push(...toArray(ssrOptions.noExternal).filter((dep) => !inline.includes(dep)));
210
211
  }
211
212
  }
212
213
  if (process.env.VITE_NODE_DEBUG_DUMP) {
@@ -329,6 +330,25 @@ class ViteNodeServer {
329
330
  return "ssr";
330
331
  return "web";
331
332
  }
333
+ getChangedModule(id, file) {
334
+ const module = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(file);
335
+ if (module)
336
+ return module;
337
+ const _modules = this.server.moduleGraph.getModulesByFile(file);
338
+ if (!_modules || !_modules.size)
339
+ return null;
340
+ const modules = [..._modules];
341
+ let mod = modules[0];
342
+ let latestMax = -1;
343
+ for (const m of _modules) {
344
+ const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp);
345
+ if (timestamp > latestMax) {
346
+ latestMax = timestamp;
347
+ mod = m;
348
+ }
349
+ }
350
+ return mod;
351
+ }
332
352
  async _fetchModule(id, transformMode) {
333
353
  var _a, _b;
334
354
  let result;
@@ -343,7 +363,7 @@ class ViteNodeServer {
343
363
  clearTimeout(timeout);
344
364
  }
345
365
  const { path: filePath } = toFilePath(id, this.server.config.root);
346
- const moduleNode = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(filePath);
366
+ const moduleNode = this.getChangedModule(id, filePath);
347
367
  const cache = this.fetchCaches[transformMode].get(filePath);
348
368
  const timestamp = moduleNode ? Math.max(moduleNode.lastHMRTimestamp, moduleNode.lastInvalidationTimestamp) : 0;
349
369
  if (cache && (timestamp === 0 || cache.timestamp >= timestamp))
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { E as EncodedSourceMap } from './trace-mapping.d-aA9jxPtH.js';
2
+ import { E as EncodedSourceMap } from './trace-mapping.d-xyIfZtPm.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => EncodedSourceMap | null | undefined;
@@ -1,9 +1,9 @@
1
- declare type GeneratedColumn = number;
2
- declare type SourcesIndex = number;
3
- declare type SourceLine = number;
4
- declare type SourceColumn = number;
5
- declare type NamesIndex = number;
6
- declare type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
1
+ type GeneratedColumn = number;
2
+ type SourcesIndex = number;
3
+ type SourceLine = number;
4
+ type SourceColumn = number;
5
+ type NamesIndex = number;
6
+ type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
7
7
 
8
8
  interface SourceMapV3 {
9
9
  file?: string | null;
@@ -19,7 +19,7 @@ interface EncodedSourceMap extends SourceMapV3 {
19
19
  interface DecodedSourceMap extends SourceMapV3 {
20
20
  mappings: SourceMapSegment[][];
21
21
  }
22
- declare type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
22
+ type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
23
23
  declare abstract class SourceMap {
24
24
  version: SourceMapV3['version'];
25
25
  file: SourceMapV3['file'];
@@ -29,9 +29,9 @@ declare abstract class SourceMap {
29
29
  sourcesContent: SourceMapV3['sourcesContent'];
30
30
  resolvedSources: SourceMapV3['sources'];
31
31
  }
32
- declare 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
- declare type RoArray<T> = Ro<T>[];
34
- declare type RoObject<T> = {
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
35
  [K in keyof T]: T[K] | Ro<T[K]>;
36
36
  };
37
37
 
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-IeUJleJC.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-aA9jxPtH.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, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-WT31LSgS.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-xyIfZtPm.js';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { N as Nullable, A as Arrayable } from './index-IeUJleJC.js';
2
- import './trace-mapping.d-aA9jxPtH.js';
1
+ import { N as Nullable, A as Arrayable } from './index-WT31LSgS.js';
2
+ import './trace-mapping.d-xyIfZtPm.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "1.1.3",
4
+ "version": "1.2.1",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -84,7 +84,7 @@
84
84
  "vite": "^5.0.0"
85
85
  },
86
86
  "devDependencies": {
87
- "@jridgewell/trace-mapping": "^0.3.20",
87
+ "@jridgewell/trace-mapping": "^0.3.21",
88
88
  "@types/debug": "^4.1.12"
89
89
  },
90
90
  "scripts": {