vite-node 0.26.1 → 0.26.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
@@ -634,7 +634,7 @@ class CAC extends events.EventEmitter {
634
634
 
635
635
  const cac = (name = "") => new CAC(name);
636
636
 
637
- var version = "0.26.1";
637
+ var version = "0.26.3";
638
638
 
639
639
  const cli = cac("vite-node");
640
640
  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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { e as ViteNodeServerOptions } from './types-57a192bf.js';
1
+ import { e as ViteNodeServerOptions } from './types-63205a44.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
package/dist/cli.mjs CHANGED
@@ -632,7 +632,7 @@ class CAC extends EventEmitter {
632
632
 
633
633
  const cac = (name = "") => new CAC(name);
634
634
 
635
- var version = "0.26.1";
635
+ var version = "0.26.3";
636
636
 
637
637
  const cli = cac("vite-node");
638
638
  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
@@ -39,40 +39,42 @@ var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
39
39
 
40
40
  const debugExecute = createDebug__default["default"]("vite-node:client:execute");
41
41
  const debugNative = createDebug__default["default"]("vite-node:client:native");
42
- const DEFAULT_REQUEST_STUBS = {
43
- "/@vite/client": {
44
- injectQuery: (id) => id,
45
- createHotContext() {
46
- return {
47
- accept: () => {
48
- },
49
- prune: () => {
50
- },
51
- dispose: () => {
52
- },
53
- decline: () => {
54
- },
55
- invalidate: () => {
56
- },
57
- on: () => {
58
- }
59
- };
60
- },
61
- updateStyle(id, css) {
62
- if (typeof document === "undefined")
63
- return;
64
- const element = document.getElementById(id);
65
- if (element)
66
- element.remove();
67
- const head = document.querySelector("head");
68
- const style = document.createElement("style");
69
- style.setAttribute("type", "text/css");
70
- style.id = id;
71
- style.innerHTML = css;
72
- head == null ? void 0 : head.appendChild(style);
73
- }
42
+ const clientStub = {
43
+ injectQuery: (id) => id,
44
+ createHotContext() {
45
+ return {
46
+ accept: () => {
47
+ },
48
+ prune: () => {
49
+ },
50
+ dispose: () => {
51
+ },
52
+ decline: () => {
53
+ },
54
+ invalidate: () => {
55
+ },
56
+ on: () => {
57
+ }
58
+ };
59
+ },
60
+ updateStyle(id, css) {
61
+ if (typeof document === "undefined")
62
+ return;
63
+ const element = document.getElementById(id);
64
+ if (element)
65
+ element.remove();
66
+ const head = document.querySelector("head");
67
+ const style = document.createElement("style");
68
+ style.setAttribute("type", "text/css");
69
+ style.id = id;
70
+ style.innerHTML = css;
71
+ head == null ? void 0 : head.appendChild(style);
74
72
  }
75
73
  };
74
+ const DEFAULT_REQUEST_STUBS = {
75
+ "/@vite/client": clientStub,
76
+ "@vite/client": clientStub
77
+ };
76
78
  class ModuleCacheMap extends Map {
77
79
  normalizePath(fsPath) {
78
80
  return utils.normalizeModuleId(fsPath);
@@ -85,19 +87,25 @@ class ModuleCacheMap extends Map {
85
87
  Object.assign(super.get(fsPath), mod);
86
88
  return this;
87
89
  }
90
+ setByModuleId(modulePath, mod) {
91
+ return super.set(modulePath, mod);
92
+ }
88
93
  set(fsPath, mod) {
89
- fsPath = this.normalizePath(fsPath);
90
- return super.set(fsPath, mod);
94
+ return this.setByModuleId(this.normalizePath(fsPath), mod);
95
+ }
96
+ getByModuleId(modulePath) {
97
+ if (!super.has(modulePath))
98
+ super.set(modulePath, {});
99
+ return super.get(modulePath);
91
100
  }
92
101
  get(fsPath) {
93
- fsPath = this.normalizePath(fsPath);
94
- if (!super.has(fsPath))
95
- super.set(fsPath, {});
96
- return super.get(fsPath);
102
+ return this.getByModuleId(this.normalizePath(fsPath));
103
+ }
104
+ deleteByModuleId(modulePath) {
105
+ return super.delete(modulePath);
97
106
  }
98
107
  delete(fsPath) {
99
- fsPath = this.normalizePath(fsPath);
100
- return super.delete(fsPath);
108
+ return this.deleteByModuleId(this.normalizePath(fsPath));
101
109
  }
102
110
  invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
103
111
  for (const _id of ids) {
@@ -179,7 +187,7 @@ class ViteNodeRunner {
179
187
  shouldResolveId(id, _importee) {
180
188
  return !utils.isInternalRequest(id) && !mlly.isNodeBuiltin(id);
181
189
  }
182
- async resolveUrl(id, importee) {
190
+ async _resolveUrl(id, importee) {
183
191
  if (!this.shouldResolveId(id))
184
192
  return [id, id];
185
193
  if (importee && id.startsWith(utils.VALID_ID_PREFIX))
@@ -192,6 +200,15 @@ class ViteNodeRunner {
192
200
  const fsPath = resolved ? resolvedId : utils.toFilePath(id, this.root);
193
201
  return [resolvedId, fsPath];
194
202
  }
203
+ async resolveUrl(id, importee) {
204
+ const resolveKey = `resolve:${id}`;
205
+ this.moduleCache.setByModuleId(resolveKey, { resolving: true });
206
+ try {
207
+ return await this._resolveUrl(id, importee);
208
+ } finally {
209
+ this.moduleCache.deleteByModuleId(resolveKey);
210
+ }
211
+ }
195
212
  async dependencyRequest(id, fsPath, callstack) {
196
213
  var _a;
197
214
  const getStack = () => {
@@ -218,7 +235,7 @@ ${getStack()}`), 2e3);
218
235
  async directRequest(id, fsPath, _callstack) {
219
236
  const moduleId = utils.normalizeModuleId(fsPath);
220
237
  const callstack = [..._callstack, moduleId];
221
- const mod = this.moduleCache.get(fsPath);
238
+ const mod = this.moduleCache.getByModuleId(moduleId);
222
239
  const request = async (dep) => {
223
240
  const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
224
241
  return this.dependencyRequest(id2, depFsPath, callstack);
@@ -337,6 +354,25 @@ ${getStack()}`), 2e3);
337
354
  if (prop === "default")
338
355
  return defaultExport !== void 0;
339
356
  return prop in mod2 || defaultExport && prop in defaultExport;
357
+ },
358
+ ownKeys(mod2) {
359
+ const keys = Reflect.ownKeys(mod2);
360
+ if (!defaultExport || utils.isPrimitive(defaultExport))
361
+ return keys;
362
+ const allKeys = [...keys, "default", ...Reflect.ownKeys(defaultExport)];
363
+ return Array.from(new Set(allKeys));
364
+ },
365
+ getOwnPropertyDescriptor(mod2, prop) {
366
+ const descriptor = Reflect.getOwnPropertyDescriptor(mod2, prop);
367
+ if (descriptor)
368
+ return descriptor;
369
+ if (prop === "default" && defaultExport !== void 0) {
370
+ return {
371
+ value: defaultExport,
372
+ enumerable: true,
373
+ configurable: true
374
+ };
375
+ }
340
376
  }
341
377
  });
342
378
  }
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-57a192bf.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-63205a44.js';
package/dist/client.mjs CHANGED
@@ -12,40 +12,42 @@ import 'source-map-support';
12
12
 
13
13
  const debugExecute = createDebug("vite-node:client:execute");
14
14
  const debugNative = createDebug("vite-node:client:native");
15
- const DEFAULT_REQUEST_STUBS = {
16
- "/@vite/client": {
17
- injectQuery: (id) => id,
18
- createHotContext() {
19
- return {
20
- accept: () => {
21
- },
22
- prune: () => {
23
- },
24
- dispose: () => {
25
- },
26
- decline: () => {
27
- },
28
- invalidate: () => {
29
- },
30
- on: () => {
31
- }
32
- };
33
- },
34
- updateStyle(id, css) {
35
- if (typeof document === "undefined")
36
- return;
37
- const element = document.getElementById(id);
38
- if (element)
39
- element.remove();
40
- const head = document.querySelector("head");
41
- const style = document.createElement("style");
42
- style.setAttribute("type", "text/css");
43
- style.id = id;
44
- style.innerHTML = css;
45
- head == null ? void 0 : head.appendChild(style);
46
- }
15
+ const clientStub = {
16
+ injectQuery: (id) => id,
17
+ createHotContext() {
18
+ return {
19
+ accept: () => {
20
+ },
21
+ prune: () => {
22
+ },
23
+ dispose: () => {
24
+ },
25
+ decline: () => {
26
+ },
27
+ invalidate: () => {
28
+ },
29
+ on: () => {
30
+ }
31
+ };
32
+ },
33
+ updateStyle(id, css) {
34
+ if (typeof document === "undefined")
35
+ return;
36
+ const element = document.getElementById(id);
37
+ if (element)
38
+ element.remove();
39
+ const head = document.querySelector("head");
40
+ const style = document.createElement("style");
41
+ style.setAttribute("type", "text/css");
42
+ style.id = id;
43
+ style.innerHTML = css;
44
+ head == null ? void 0 : head.appendChild(style);
47
45
  }
48
46
  };
47
+ const DEFAULT_REQUEST_STUBS = {
48
+ "/@vite/client": clientStub,
49
+ "@vite/client": clientStub
50
+ };
49
51
  class ModuleCacheMap extends Map {
50
52
  normalizePath(fsPath) {
51
53
  return normalizeModuleId(fsPath);
@@ -58,19 +60,25 @@ class ModuleCacheMap extends Map {
58
60
  Object.assign(super.get(fsPath), mod);
59
61
  return this;
60
62
  }
63
+ setByModuleId(modulePath, mod) {
64
+ return super.set(modulePath, mod);
65
+ }
61
66
  set(fsPath, mod) {
62
- fsPath = this.normalizePath(fsPath);
63
- return super.set(fsPath, mod);
67
+ return this.setByModuleId(this.normalizePath(fsPath), mod);
68
+ }
69
+ getByModuleId(modulePath) {
70
+ if (!super.has(modulePath))
71
+ super.set(modulePath, {});
72
+ return super.get(modulePath);
64
73
  }
65
74
  get(fsPath) {
66
- fsPath = this.normalizePath(fsPath);
67
- if (!super.has(fsPath))
68
- super.set(fsPath, {});
69
- return super.get(fsPath);
75
+ return this.getByModuleId(this.normalizePath(fsPath));
76
+ }
77
+ deleteByModuleId(modulePath) {
78
+ return super.delete(modulePath);
70
79
  }
71
80
  delete(fsPath) {
72
- fsPath = this.normalizePath(fsPath);
73
- return super.delete(fsPath);
81
+ return this.deleteByModuleId(this.normalizePath(fsPath));
74
82
  }
75
83
  invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
76
84
  for (const _id of ids) {
@@ -152,7 +160,7 @@ class ViteNodeRunner {
152
160
  shouldResolveId(id, _importee) {
153
161
  return !isInternalRequest(id) && !isNodeBuiltin(id);
154
162
  }
155
- async resolveUrl(id, importee) {
163
+ async _resolveUrl(id, importee) {
156
164
  if (!this.shouldResolveId(id))
157
165
  return [id, id];
158
166
  if (importee && id.startsWith(VALID_ID_PREFIX))
@@ -165,6 +173,15 @@ class ViteNodeRunner {
165
173
  const fsPath = resolved ? resolvedId : toFilePath(id, this.root);
166
174
  return [resolvedId, fsPath];
167
175
  }
176
+ async resolveUrl(id, importee) {
177
+ const resolveKey = `resolve:${id}`;
178
+ this.moduleCache.setByModuleId(resolveKey, { resolving: true });
179
+ try {
180
+ return await this._resolveUrl(id, importee);
181
+ } finally {
182
+ this.moduleCache.deleteByModuleId(resolveKey);
183
+ }
184
+ }
168
185
  async dependencyRequest(id, fsPath, callstack) {
169
186
  var _a;
170
187
  const getStack = () => {
@@ -191,7 +208,7 @@ ${getStack()}`), 2e3);
191
208
  async directRequest(id, fsPath, _callstack) {
192
209
  const moduleId = normalizeModuleId(fsPath);
193
210
  const callstack = [..._callstack, moduleId];
194
- const mod = this.moduleCache.get(fsPath);
211
+ const mod = this.moduleCache.getByModuleId(moduleId);
195
212
  const request = async (dep) => {
196
213
  const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
197
214
  return this.dependencyRequest(id2, depFsPath, callstack);
@@ -310,6 +327,25 @@ ${getStack()}`), 2e3);
310
327
  if (prop === "default")
311
328
  return defaultExport !== void 0;
312
329
  return prop in mod2 || defaultExport && prop in defaultExport;
330
+ },
331
+ ownKeys(mod2) {
332
+ const keys = Reflect.ownKeys(mod2);
333
+ if (!defaultExport || isPrimitive(defaultExport))
334
+ return keys;
335
+ const allKeys = [...keys, "default", ...Reflect.ownKeys(defaultExport)];
336
+ return Array.from(new Set(allKeys));
337
+ },
338
+ getOwnPropertyDescriptor(mod2, prop) {
339
+ const descriptor = Reflect.getOwnPropertyDescriptor(mod2, prop);
340
+ if (descriptor)
341
+ return descriptor;
342
+ if (prop === "default" && defaultExport !== void 0) {
343
+ return {
344
+ value: defaultExport,
345
+ enumerable: true,
346
+ configurable: true
347
+ };
348
+ }
313
349
  }
314
350
  });
315
351
  }
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-57a192bf.js';
3
+ import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-63205a44.js';
4
4
 
5
5
  type EventType = string | symbol;
6
6
  type Handler<T = unknown> = (event: T) => void;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-57a192bf.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-63205a44.js';
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-57a192bf.js';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-63205a44.js';
3
3
 
4
4
  declare class Debugger {
5
5
  options: DebuggerOptions;
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { R as RawSourceMap } from './types-57a192bf.js';
2
+ import { R as RawSourceMap } from './types-63205a44.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => RawSourceMap | null | undefined;
@@ -121,6 +121,18 @@ declare const DEFAULT_REQUEST_STUBS: {
121
121
  };
122
122
  updateStyle(id: string, css: string): void;
123
123
  };
124
+ '@vite/client': {
125
+ injectQuery: (id: string) => string;
126
+ createHotContext(): {
127
+ accept: () => void;
128
+ prune: () => void;
129
+ dispose: () => void;
130
+ decline: () => void;
131
+ invalidate: () => void;
132
+ on: () => void;
133
+ };
134
+ updateStyle(id: string, css: string): void;
135
+ };
124
136
  };
125
137
  declare class ModuleCacheMap extends Map<string, ModuleCache> {
126
138
  normalizePath(fsPath: string): string;
@@ -128,8 +140,11 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
128
140
  * Assign partial data to the map
129
141
  */
130
142
  update(fsPath: string, mod: Partial<ModuleCache>): this;
143
+ setByModuleId(modulePath: string, mod: ModuleCache): this;
131
144
  set(fsPath: string, mod: ModuleCache): this;
145
+ getByModuleId(modulePath: string): ModuleCache;
132
146
  get(fsPath: string): ModuleCache;
147
+ deleteByModuleId(modulePath: string): boolean;
133
148
  delete(fsPath: string): boolean;
134
149
  /**
135
150
  * Invalidate modules that dependent on the given modules, up to the main entry
@@ -160,6 +175,7 @@ declare class ViteNodeRunner {
160
175
  /** @internal */
161
176
  cachedRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
162
177
  shouldResolveId(id: string, _importee?: string): boolean;
178
+ private _resolveUrl;
163
179
  resolveUrl(id: string, importee?: string): Promise<[url: string, fsPath: string]>;
164
180
  /** @internal */
165
181
  dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
@@ -212,6 +228,7 @@ interface ModuleCache {
212
228
  promise?: Promise<any>;
213
229
  exports?: any;
214
230
  evaluated?: boolean;
231
+ resolving?: boolean;
215
232
  code?: string;
216
233
  map?: RawSourceMap;
217
234
  /**
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-57a192bf.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-63205a44.js';
package/dist/utils.cjs CHANGED
@@ -22,8 +22,13 @@ function normalizeRequestId(id, base) {
22
22
  const queryRE = /\?.*$/s;
23
23
  const hashRE = /#.*$/s;
24
24
  const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
25
+ const internalRequests = [
26
+ "@vite/client",
27
+ "@vite/env"
28
+ ];
29
+ const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
25
30
  const isInternalRequest = (id) => {
26
- return id.startsWith("/@vite/");
31
+ return internalRequestRegexp.test(id);
27
32
  };
28
33
  function normalizeModuleId(id) {
29
34
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './types-57a192bf.js';
1
+ import { N as Nullable, A as Arrayable } from './types-63205a44.js';
2
2
 
3
3
  declare const isWindows: boolean;
4
4
  declare function slash(str: string): string;
package/dist/utils.mjs CHANGED
@@ -18,8 +18,13 @@ function normalizeRequestId(id, base) {
18
18
  const queryRE = /\?.*$/s;
19
19
  const hashRE = /#.*$/s;
20
20
  const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
21
+ const internalRequests = [
22
+ "@vite/client",
23
+ "@vite/env"
24
+ ];
25
+ const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
21
26
  const isInternalRequest = (id) => {
22
- return id.startsWith("/@vite/");
27
+ return internalRequestRegexp.test(id);
23
28
  };
24
29
  function normalizeModuleId(id) {
25
30
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.26.1",
3
+ "version": "0.26.3",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",