vite-node 0.22.1 → 0.23.0

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/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ interface CliOptions {
2
+ files?: string[];
3
+ _?: string[];
4
+ root?: string;
5
+ config?: string;
6
+ }
7
+
8
+ export { CliOptions };
package/client.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { ViteNodeRunnerOptions, ModuleCache } from './types.js';
2
+
3
+ declare const DEFAULT_REQUEST_STUBS: {
4
+ '/@vite/client': {
5
+ injectQuery: (id: string) => string;
6
+ createHotContext(): {
7
+ accept: () => void;
8
+ prune: () => void;
9
+ };
10
+ updateStyle(): void;
11
+ };
12
+ };
13
+ declare class ViteNodeRunner {
14
+ options: ViteNodeRunnerOptions;
15
+ root: string;
16
+ moduleCache: Map<string, ModuleCache>;
17
+ constructor(options: ViteNodeRunnerOptions);
18
+ executeFile(file: string): Promise<any>;
19
+ executeId(id: string): Promise<any>;
20
+ cachedRequest(rawId: string, callstack: string[]): Promise<any>;
21
+ directRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
22
+ prepareContext(context: Record<string, any>): Record<string, any>;
23
+ setCache(id: string, mod: Partial<ModuleCache>): void;
24
+ shouldResolveId(dep: string): boolean;
25
+ /**
26
+ * Define if a module should be interop-ed
27
+ * This function mostly for the ability to override by subclass
28
+ */
29
+ shouldInterop(path: string, mod: any): boolean;
30
+ /**
31
+ * Import a module and interop it
32
+ */
33
+ interopedImport(path: string): Promise<any>;
34
+ hasNestedDefault(target: any): any;
35
+ }
36
+
37
+ export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
@@ -98,17 +98,19 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
98
98
  const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => {
99
99
  return deps.some((dep) => modulesToUpdate.has(dep));
100
100
  });
101
- await Promise.all(Array.from(modulesToUpdate).map(async (dep) => {
102
- const disposer = maps.disposeMap.get(dep);
103
- if (disposer)
104
- await disposer(maps.dataMap.get(dep));
105
- try {
106
- const newMod = await reload(runner, [dep]);
107
- moduleMap.set(dep, newMod);
108
- } catch (e) {
109
- warnFailedFetch(e, dep);
110
- }
111
- }));
101
+ await Promise.all(
102
+ Array.from(modulesToUpdate).map(async (dep) => {
103
+ const disposer = maps.disposeMap.get(dep);
104
+ if (disposer)
105
+ await disposer(maps.dataMap.get(dep));
106
+ try {
107
+ const newMod = await reload(runner, [dep]);
108
+ moduleMap.set(dep, newMod);
109
+ } catch (e) {
110
+ warnFailedFetch(e, dep);
111
+ }
112
+ })
113
+ );
112
114
  return () => {
113
115
  for (const { deps, fn } of qualifiedCallbacks)
114
116
  fn(deps.map((dep) => moduleMap.get(dep)));
@@ -119,7 +121,9 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
119
121
  function warnFailedFetch(err, path) {
120
122
  if (!err.message.match("fetch"))
121
123
  console.error(err);
122
- console.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
124
+ console.error(
125
+ `[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
126
+ );
123
127
  }
124
128
  async function handleMessage(runner, emitter, files, payload) {
125
129
  const maps = getCache(runner);
@@ -92,17 +92,19 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
92
92
  const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => {
93
93
  return deps.some((dep) => modulesToUpdate.has(dep));
94
94
  });
95
- await Promise.all(Array.from(modulesToUpdate).map(async (dep) => {
96
- const disposer = maps.disposeMap.get(dep);
97
- if (disposer)
98
- await disposer(maps.dataMap.get(dep));
99
- try {
100
- const newMod = await reload(runner, [dep]);
101
- moduleMap.set(dep, newMod);
102
- } catch (e) {
103
- warnFailedFetch(e, dep);
104
- }
105
- }));
95
+ await Promise.all(
96
+ Array.from(modulesToUpdate).map(async (dep) => {
97
+ const disposer = maps.disposeMap.get(dep);
98
+ if (disposer)
99
+ await disposer(maps.dataMap.get(dep));
100
+ try {
101
+ const newMod = await reload(runner, [dep]);
102
+ moduleMap.set(dep, newMod);
103
+ } catch (e) {
104
+ warnFailedFetch(e, dep);
105
+ }
106
+ })
107
+ );
106
108
  return () => {
107
109
  for (const { deps, fn } of qualifiedCallbacks)
108
110
  fn(deps.map((dep) => moduleMap.get(dep)));
@@ -113,7 +115,9 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
113
115
  function warnFailedFetch(err, path) {
114
116
  if (!err.message.match("fetch"))
115
117
  console.error(err);
116
- console.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
118
+ console.error(
119
+ `[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
120
+ );
117
121
  }
118
122
  async function handleMessage(runner, emitter, files, payload) {
119
123
  const maps = getCache(runner);
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.22.1";
633
+ var version = "0.23.0";
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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { e as ViteNodeServerOptions } from './types-735b75af.js';
1
+ import { e as ViteNodeServerOptions } from './types-dca976ee.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
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.22.1";
631
+ var version = "0.23.0";
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
@@ -108,6 +108,21 @@ class ModuleCacheMap extends Map {
108
108
  }
109
109
  return invalidated;
110
110
  }
111
+ invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
112
+ for (const _id of ids) {
113
+ const id = this.normalizePath(_id);
114
+ if (invalidated.has(id))
115
+ continue;
116
+ invalidated.add(id);
117
+ const subIds = Array.from(super.entries()).filter(([, mod]) => {
118
+ var _a;
119
+ return (_a = mod.importers) == null ? void 0 : _a.has(id);
120
+ }).map(([key]) => key);
121
+ subIds.length && this.invalidateSubDepTree(subIds, invalidated);
122
+ super.delete(id);
123
+ }
124
+ return invalidated;
125
+ }
111
126
  }
112
127
  class ViteNodeRunner {
113
128
  constructor(options) {
@@ -198,15 +213,34 @@ ${getStack()}`), 2e3);
198
213
  enumerable: false,
199
214
  configurable: false
200
215
  });
216
+ const cjsExports = new Proxy(exports, {
217
+ get(_, p, receiver) {
218
+ return Reflect.get(exports, p, receiver);
219
+ },
220
+ set(_, p, value) {
221
+ if (p !== "default") {
222
+ if (!Reflect.has(exports, "default"))
223
+ exports.default = {};
224
+ if (exports.default === null || typeof exports.default !== "object") {
225
+ defineExport(exports, p, () => void 0);
226
+ return true;
227
+ }
228
+ exports.default[p] = value;
229
+ defineExport(exports, p, () => value);
230
+ return true;
231
+ }
232
+ return Reflect.set(exports, p, value);
233
+ }
234
+ });
201
235
  Object.assign(mod, { code: transformed, exports });
202
236
  const __filename = url.fileURLToPath(url$1);
203
237
  const moduleProxy = {
204
238
  set exports(value) {
205
- exportAll(exports, value);
206
- exports.default = value;
239
+ exportAll(cjsExports, value);
240
+ cjsExports.default = value;
207
241
  },
208
242
  get exports() {
209
- return exports;
243
+ return cjsExports;
210
244
  }
211
245
  };
212
246
  let hotContext;
@@ -228,7 +262,7 @@ ${getStack()}`), 2e3);
228
262
  __vite_ssr_import_meta__: meta,
229
263
  __vitest_resolve_id__: resolveId,
230
264
  require: module$1.createRequire(url$1),
231
- exports,
265
+ exports: cjsExports,
232
266
  module: moduleProxy,
233
267
  __filename,
234
268
  __dirname: pathe.dirname(__filename)
@@ -284,19 +318,27 @@ function proxyMethod(name, tryDefault) {
284
318
  return result;
285
319
  };
286
320
  }
321
+ function defineExport(exports, key, value) {
322
+ Object.defineProperty(exports, key, {
323
+ enumerable: true,
324
+ configurable: true,
325
+ get: value
326
+ });
327
+ }
287
328
  function exportAll(exports, sourceModule) {
329
+ var _a;
288
330
  if (exports === sourceModule)
289
331
  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")
337
+ return;
290
338
  for (const key in sourceModule) {
291
339
  if (key !== "default") {
292
340
  try {
293
- Object.defineProperty(exports, key, {
294
- enumerable: true,
295
- configurable: true,
296
- get() {
297
- return sourceModule[key];
298
- }
299
- });
341
+ defineExport(exports, key, () => sourceModule[key]);
300
342
  } catch (_err) {
301
343
  }
302
344
  }
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-735b75af.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-dca976ee.js';
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, mergeSlashes } from './utils.mjs';
7
+ import { normalizeModuleId, slash, normalizeRequestId, toFilePath, isPrimitive, getType, mergeSlashes } from './utils.mjs';
8
8
 
9
9
  const debugExecute = createDebug("vite-node:client:execute");
10
10
  const debugNative = createDebug("vite-node:client:native");
@@ -81,6 +81,21 @@ class ModuleCacheMap extends Map {
81
81
  }
82
82
  return invalidated;
83
83
  }
84
+ invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
85
+ for (const _id of ids) {
86
+ const id = this.normalizePath(_id);
87
+ if (invalidated.has(id))
88
+ continue;
89
+ invalidated.add(id);
90
+ const subIds = Array.from(super.entries()).filter(([, mod]) => {
91
+ var _a;
92
+ return (_a = mod.importers) == null ? void 0 : _a.has(id);
93
+ }).map(([key]) => key);
94
+ subIds.length && this.invalidateSubDepTree(subIds, invalidated);
95
+ super.delete(id);
96
+ }
97
+ return invalidated;
98
+ }
84
99
  }
85
100
  class ViteNodeRunner {
86
101
  constructor(options) {
@@ -171,15 +186,34 @@ ${getStack()}`), 2e3);
171
186
  enumerable: false,
172
187
  configurable: false
173
188
  });
189
+ const cjsExports = new Proxy(exports, {
190
+ get(_, p, receiver) {
191
+ return Reflect.get(exports, p, receiver);
192
+ },
193
+ set(_, p, value) {
194
+ if (p !== "default") {
195
+ if (!Reflect.has(exports, "default"))
196
+ exports.default = {};
197
+ if (exports.default === null || typeof exports.default !== "object") {
198
+ defineExport(exports, p, () => void 0);
199
+ return true;
200
+ }
201
+ exports.default[p] = value;
202
+ defineExport(exports, p, () => value);
203
+ return true;
204
+ }
205
+ return Reflect.set(exports, p, value);
206
+ }
207
+ });
174
208
  Object.assign(mod, { code: transformed, exports });
175
209
  const __filename = fileURLToPath(url);
176
210
  const moduleProxy = {
177
211
  set exports(value) {
178
- exportAll(exports, value);
179
- exports.default = value;
212
+ exportAll(cjsExports, value);
213
+ cjsExports.default = value;
180
214
  },
181
215
  get exports() {
182
- return exports;
216
+ return cjsExports;
183
217
  }
184
218
  };
185
219
  let hotContext;
@@ -201,7 +235,7 @@ ${getStack()}`), 2e3);
201
235
  __vite_ssr_import_meta__: meta,
202
236
  __vitest_resolve_id__: resolveId,
203
237
  require: createRequire(url),
204
- exports,
238
+ exports: cjsExports,
205
239
  module: moduleProxy,
206
240
  __filename,
207
241
  __dirname: dirname(__filename)
@@ -257,19 +291,27 @@ function proxyMethod(name, tryDefault) {
257
291
  return result;
258
292
  };
259
293
  }
294
+ function defineExport(exports, key, value) {
295
+ Object.defineProperty(exports, key, {
296
+ enumerable: true,
297
+ configurable: true,
298
+ get: value
299
+ });
300
+ }
260
301
  function exportAll(exports, sourceModule) {
302
+ var _a;
261
303
  if (exports === sourceModule)
262
304
  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")
310
+ return;
263
311
  for (const key in sourceModule) {
264
312
  if (key !== "default") {
265
313
  try {
266
- Object.defineProperty(exports, key, {
267
- enumerable: true,
268
- configurable: true,
269
- get() {
270
- return sourceModule[key];
271
- }
272
- });
314
+ defineExport(exports, key, () => sourceModule[key]);
273
315
  } catch (_err) {
274
316
  }
275
317
  }
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { U as UpdatePayload, P as PrunePayload, g as FullReloadPayload, E as ErrorPayload, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-735b75af.js';
3
+ import { U as UpdatePayload, P as PrunePayload, g as FullReloadPayload, E as ErrorPayload, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-dca976ee.js';
4
4
 
5
5
  declare type EventType = string | symbol;
6
6
  declare 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-735b75af.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-dca976ee.js';
package/dist/server.cjs CHANGED
@@ -142,19 +142,25 @@ class ViteNodeServer {
142
142
  }
143
143
  async fetchModule(id) {
144
144
  if (!this.fetchPromiseMap.has(id)) {
145
- this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
146
- return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
147
- }).finally(() => {
148
- this.fetchPromiseMap.delete(id);
149
- }));
145
+ this.fetchPromiseMap.set(
146
+ id,
147
+ this._fetchModule(id).then((r) => {
148
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
149
+ }).finally(() => {
150
+ this.fetchPromiseMap.delete(id);
151
+ })
152
+ );
150
153
  }
151
154
  return this.fetchPromiseMap.get(id);
152
155
  }
153
156
  async transformRequest(id) {
154
157
  if (!this.transformPromiseMap.has(id)) {
155
- this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
156
- this.transformPromiseMap.delete(id);
157
- }));
158
+ this.transformPromiseMap.set(
159
+ id,
160
+ this._transformRequest(id).finally(() => {
161
+ this.transformPromiseMap.delete(id);
162
+ })
163
+ );
158
164
  }
159
165
  return this.transformPromiseMap.get(id);
160
166
  }
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 } from './types-735b75af.js';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-dca976ee.js';
3
3
 
4
4
  declare class Debugger {
5
5
  options: DebuggerOptions;
package/dist/server.mjs CHANGED
@@ -134,19 +134,25 @@ class ViteNodeServer {
134
134
  }
135
135
  async fetchModule(id) {
136
136
  if (!this.fetchPromiseMap.has(id)) {
137
- this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
138
- return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
139
- }).finally(() => {
140
- this.fetchPromiseMap.delete(id);
141
- }));
137
+ this.fetchPromiseMap.set(
138
+ id,
139
+ this._fetchModule(id).then((r) => {
140
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
141
+ }).finally(() => {
142
+ this.fetchPromiseMap.delete(id);
143
+ })
144
+ );
142
145
  }
143
146
  return this.fetchPromiseMap.get(id);
144
147
  }
145
148
  async transformRequest(id) {
146
149
  if (!this.transformPromiseMap.has(id)) {
147
- this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
148
- this.transformPromiseMap.delete(id);
149
- }));
150
+ this.transformPromiseMap.set(
151
+ id,
152
+ this._transformRequest(id).finally(() => {
153
+ this.transformPromiseMap.delete(id);
154
+ })
155
+ );
150
156
  }
151
157
  return this.transformPromiseMap.get(id);
152
158
  }
@@ -125,6 +125,10 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
125
125
  * Invalidate modules that dependent on the given modules, up to the main entry
126
126
  */
127
127
  invalidateDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
128
+ /**
129
+ * Invalidate dependency modules of the given modules, down to the bottom-level dependencies
130
+ */
131
+ invalidateSubDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
128
132
  }
129
133
  declare class ViteNodeRunner {
130
134
  options: ViteNodeRunnerOptions;
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-735b75af.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-dca976ee.js';
package/dist/utils.cjs CHANGED
@@ -9,6 +9,9 @@ const isWindows = process.platform === "win32";
9
9
  function slash(str) {
10
10
  return str.replace(/\\/g, "/");
11
11
  }
12
+ function getType(value) {
13
+ return Object.prototype.toString.apply(value).slice(8, -1);
14
+ }
12
15
  function mergeSlashes(str) {
13
16
  return str.replace(/\/\//g, "/");
14
17
  }
@@ -50,6 +53,7 @@ function toArray(array) {
50
53
  return [array];
51
54
  }
52
55
 
56
+ exports.getType = getType;
53
57
  exports.isPrimitive = isPrimitive;
54
58
  exports.isWindows = isWindows;
55
59
  exports.mergeSlashes = mergeSlashes;
package/dist/utils.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { TransformResult } from 'vite';
2
- import { N as Nullable, A as Arrayable } from './types-735b75af.js';
2
+ 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;
6
7
  declare function mergeSlashes(str: string): string;
7
8
  declare function normalizeRequestId(id: string, base?: string): string;
8
9
  declare function normalizeModuleId(id: string): string;
@@ -16,4 +17,4 @@ declare function withInlineSourcemap(result: TransformResult): Promise<Transform
16
17
  */
17
18
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
18
19
 
19
- export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
20
+ export { getType, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
package/dist/utils.mjs CHANGED
@@ -5,6 +5,9 @@ const isWindows = process.platform === "win32";
5
5
  function slash(str) {
6
6
  return str.replace(/\\/g, "/");
7
7
  }
8
+ function getType(value) {
9
+ return Object.prototype.toString.apply(value).slice(8, -1);
10
+ }
8
11
  function mergeSlashes(str) {
9
12
  return str.replace(/\/\//g, "/");
10
13
  }
@@ -46,4 +49,4 @@ function toArray(array) {
46
49
  return [array];
47
50
  }
48
51
 
49
- export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
52
+ export { getType, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions } from './types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -65,15 +65,15 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "debug": "^4.3.4",
68
- "mlly": "^0.5.12",
68
+ "mlly": "^0.5.14",
69
69
  "pathe": "^0.2.0",
70
70
  "vite": "^2.9.12 || ^3.0.0-0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@types/debug": "^4.1.7",
74
- "cac": "^6.7.12",
74
+ "cac": "^6.7.14",
75
75
  "picocolors": "^1.0.0",
76
- "rollup": "^2.78.0"
76
+ "rollup": "^2.78.1"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "rimraf dist && rollup -c",
package/server.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { ViteDevServer, TransformResult } from 'vite';
2
+ import { DepsHandlingOptions, ViteNodeServerOptions, FetchResult, ViteNodeResolveId } from './types.js';
3
+
4
+ declare function guessCJSversion(id: string): string | undefined;
5
+ declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
6
+
7
+ declare class ViteNodeServer {
8
+ server: ViteDevServer;
9
+ options: ViteNodeServerOptions;
10
+ private fetchPromiseMap;
11
+ private transformPromiseMap;
12
+ fetchCache: Map<string, {
13
+ timestamp: number;
14
+ result: FetchResult;
15
+ }>;
16
+ constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
17
+ shouldExternalize(id: string): Promise<string | false>;
18
+ resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
19
+ fetchModule(id: string): Promise<FetchResult>;
20
+ transformRequest(id: string): Promise<TransformResult | null | undefined>;
21
+ getTransformMode(id: string): "web" | "ssr";
22
+ private _fetchModule;
23
+ private _transformRequest;
24
+ }
25
+
26
+ export { ViteNodeServer, guessCJSversion, shouldExternalize };
package/types.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ interface DepsHandlingOptions {
2
+ external?: (string | RegExp)[];
3
+ inline?: (string | RegExp)[];
4
+ /**
5
+ * Try to guess the CJS version of a package when it's invalid ESM
6
+ * @default true
7
+ */
8
+ fallbackCJS?: boolean;
9
+ }
10
+ interface StartOfSourceMap {
11
+ file?: string;
12
+ sourceRoot?: string;
13
+ }
14
+ interface RawSourceMap extends StartOfSourceMap {
15
+ version: string;
16
+ sources: string[];
17
+ names: string[];
18
+ sourcesContent?: string[];
19
+ mappings: string;
20
+ }
21
+ interface FetchResult {
22
+ code?: string;
23
+ externalize?: string;
24
+ map?: RawSourceMap;
25
+ }
26
+ declare type FetchFunction = (id: string) => Promise<FetchResult>;
27
+ declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
28
+ interface ModuleCache {
29
+ promise?: Promise<any>;
30
+ exports?: any;
31
+ code?: string;
32
+ }
33
+ interface ViteNodeRunnerOptions {
34
+ fetchModule: FetchFunction;
35
+ resolveId: ResolveIdFunction;
36
+ root: string;
37
+ base?: string;
38
+ moduleCache?: Map<string, ModuleCache>;
39
+ interopDefault?: boolean;
40
+ requestStubs?: Record<string, any>;
41
+ }
42
+ interface ViteNodeResolveId {
43
+ external?: boolean | 'absolute' | 'relative';
44
+ id: string;
45
+ meta?: Record<string, any> | null;
46
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
47
+ syntheticNamedExports?: boolean | string | null;
48
+ }
49
+ interface ViteNodeServerOptions {
50
+ /**
51
+ * Inject inline sourcemap to modules
52
+ * @default 'inline'
53
+ */
54
+ sourcemap?: 'inline' | boolean;
55
+ /**
56
+ * Deps handling
57
+ */
58
+ deps?: DepsHandlingOptions;
59
+ /**
60
+ * Transform method for modules
61
+ */
62
+ transformMode?: {
63
+ ssr?: RegExp[];
64
+ web?: RegExp[];
65
+ };
66
+ }
67
+
68
+ export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
package/utils.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { TransformResult } from 'vite';
2
+
3
+ declare const isWindows: boolean;
4
+ declare function slash(str: string): string;
5
+ declare function normalizeId(id: string, base?: string): string;
6
+ declare function isPrimitive(v: any): boolean;
7
+ declare function toFilePath(id: string, root: string): string;
8
+ declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
9
+
10
+ export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap };