vite-node 0.21.0 → 0.22.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
@@ -8,6 +8,7 @@ var client = require('./client.cjs');
8
8
  var utils = require('./utils.cjs');
9
9
  var hmr = require('./chunk-hmr.cjs');
10
10
  require('tty');
11
+ require('perf_hooks');
11
12
  require('pathe');
12
13
  require('debug');
13
14
  require('fs');
@@ -629,7 +630,7 @@ class CAC extends events.EventEmitter {
629
630
 
630
631
  const cac = (name = "") => new CAC(name);
631
632
 
632
- var version = "0.21.0";
633
+ var version = "0.22.1";
633
634
 
634
635
  const cli = cac("vite-node");
635
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-b9c999e6.js';
1
+ import { e as ViteNodeServerOptions } from './types-735b75af.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
package/dist/cli.mjs CHANGED
@@ -6,6 +6,7 @@ import { ViteNodeRunner } from './client.mjs';
6
6
  import { toArray } from './utils.mjs';
7
7
  import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
8
8
  import 'tty';
9
+ import 'perf_hooks';
9
10
  import 'pathe';
10
11
  import 'debug';
11
12
  import 'fs';
@@ -627,7 +628,7 @@ class CAC extends EventEmitter {
627
628
 
628
629
  const cac = (name = "") => new CAC(name);
629
630
 
630
- var version = "0.21.0";
631
+ var version = "0.22.1";
631
632
 
632
633
  const cli = cac("vite-node");
633
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
@@ -73,7 +73,7 @@ class ModuleCacheMap extends Map {
73
73
  normalizePath(fsPath) {
74
74
  return utils.normalizeModuleId(fsPath);
75
75
  }
76
- set(fsPath, mod) {
76
+ update(fsPath, mod) {
77
77
  fsPath = this.normalizePath(fsPath);
78
78
  if (!super.has(fsPath))
79
79
  super.set(fsPath, mod);
@@ -81,14 +81,33 @@ class ModuleCacheMap extends Map {
81
81
  Object.assign(super.get(fsPath), mod);
82
82
  return this;
83
83
  }
84
+ set(fsPath, mod) {
85
+ fsPath = this.normalizePath(fsPath);
86
+ return super.set(fsPath, mod);
87
+ }
84
88
  get(fsPath) {
85
89
  fsPath = this.normalizePath(fsPath);
90
+ if (!super.has(fsPath))
91
+ super.set(fsPath, {});
86
92
  return super.get(fsPath);
87
93
  }
88
94
  delete(fsPath) {
89
95
  fsPath = this.normalizePath(fsPath);
90
96
  return super.delete(fsPath);
91
97
  }
98
+ invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
99
+ for (const _id of ids) {
100
+ const id = this.normalizePath(_id);
101
+ if (invalidated.has(id))
102
+ continue;
103
+ invalidated.add(id);
104
+ const mod = super.get(id);
105
+ if (mod == null ? void 0 : mod.importers)
106
+ this.invalidateDepTree(mod.importers, invalidated);
107
+ super.delete(id);
108
+ }
109
+ return invalidated;
110
+ }
92
111
  }
93
112
  class ViteNodeRunner {
94
113
  constructor(options) {
@@ -104,39 +123,44 @@ class ViteNodeRunner {
104
123
  return await this.cachedRequest(id, []);
105
124
  }
106
125
  async cachedRequest(rawId, callstack) {
107
- var _a, _b, _c, _d;
108
126
  const id = utils.normalizeRequestId(rawId, this.options.base);
109
127
  const fsPath = utils.toFilePath(id, this.root);
110
- if (callstack.includes(fsPath) && ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports))
111
- return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.exports;
112
- if ((_c = this.moduleCache.get(fsPath)) == null ? void 0 : _c.promise)
113
- return (_d = this.moduleCache.get(fsPath)) == null ? void 0 : _d.promise;
128
+ const mod = this.moduleCache.get(fsPath);
129
+ const importee = callstack[callstack.length - 1];
130
+ if (!mod.importers)
131
+ mod.importers = /* @__PURE__ */ new Set();
132
+ if (importee)
133
+ mod.importers.add(importee);
134
+ if (callstack.includes(fsPath) && mod.exports)
135
+ return mod.exports;
136
+ if (mod.promise)
137
+ return mod.promise;
114
138
  const promise = this.directRequest(id, fsPath, callstack);
115
- this.moduleCache.set(fsPath, { promise });
139
+ Object.assign(mod, { promise });
116
140
  return await promise;
117
141
  }
118
142
  async directRequest(id, fsPath, _callstack) {
119
143
  const callstack = [..._callstack, fsPath];
144
+ const mod = this.moduleCache.get(fsPath);
120
145
  const request = async (dep) => {
121
146
  var _a;
122
- const fsPath2 = utils.toFilePath(utils.normalizeRequestId(dep, this.options.base), this.root);
147
+ const depFsPath = utils.toFilePath(utils.normalizeRequestId(dep, this.options.base), this.root);
123
148
  const getStack = () => {
124
149
  return `stack:
125
- ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
150
+ ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
126
151
  };
127
152
  let debugTimer;
128
153
  if (this.debug)
129
- debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
154
+ debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
130
155
  ${getStack()}`), 2e3);
131
156
  try {
132
- if (callstack.includes(fsPath2)) {
133
- const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
157
+ if (callstack.includes(depFsPath)) {
158
+ const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
134
159
  if (depExports)
135
160
  return depExports;
136
161
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
137
162
  }
138
- const mod = await this.cachedRequest(dep, callstack);
139
- return mod;
163
+ return await this.cachedRequest(dep, callstack);
140
164
  } finally {
141
165
  if (debugTimer)
142
166
  clearTimeout(debugTimer);
@@ -160,17 +184,21 @@ ${getStack()}`), 2e3);
160
184
  let { code: transformed, externalize } = await this.options.fetchModule(id);
161
185
  if (externalize) {
162
186
  debugNative(externalize);
163
- const mod = await this.interopedImport(externalize);
164
- this.moduleCache.set(fsPath, { exports: mod });
165
- return mod;
187
+ const exports2 = await this.interopedImport(externalize);
188
+ mod.exports = exports2;
189
+ return exports2;
166
190
  }
167
191
  if (transformed == null)
168
192
  throw new Error(`[vite-node] Failed to load ${id}`);
169
193
  const url$1 = url.pathToFileURL(fsPath).href;
170
194
  const meta = { url: url$1 };
171
195
  const exports = /* @__PURE__ */ Object.create(null);
172
- exports[Symbol.toStringTag] = "Module";
173
- this.moduleCache.set(fsPath, { code: transformed, exports });
196
+ Object.defineProperty(exports, Symbol.toStringTag, {
197
+ value: "Module",
198
+ enumerable: false,
199
+ configurable: false
200
+ });
201
+ Object.assign(mod, { code: transformed, exports });
174
202
  const __filename = url.fileURLToPath(url$1);
175
203
  const moduleProxy = {
176
204
  set exports(value) {
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-b9c999e6.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-735b75af.js';
package/dist/client.mjs CHANGED
@@ -46,7 +46,7 @@ class ModuleCacheMap extends Map {
46
46
  normalizePath(fsPath) {
47
47
  return normalizeModuleId(fsPath);
48
48
  }
49
- set(fsPath, mod) {
49
+ update(fsPath, mod) {
50
50
  fsPath = this.normalizePath(fsPath);
51
51
  if (!super.has(fsPath))
52
52
  super.set(fsPath, mod);
@@ -54,14 +54,33 @@ class ModuleCacheMap extends Map {
54
54
  Object.assign(super.get(fsPath), mod);
55
55
  return this;
56
56
  }
57
+ set(fsPath, mod) {
58
+ fsPath = this.normalizePath(fsPath);
59
+ return super.set(fsPath, mod);
60
+ }
57
61
  get(fsPath) {
58
62
  fsPath = this.normalizePath(fsPath);
63
+ if (!super.has(fsPath))
64
+ super.set(fsPath, {});
59
65
  return super.get(fsPath);
60
66
  }
61
67
  delete(fsPath) {
62
68
  fsPath = this.normalizePath(fsPath);
63
69
  return super.delete(fsPath);
64
70
  }
71
+ invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
72
+ for (const _id of ids) {
73
+ const id = this.normalizePath(_id);
74
+ if (invalidated.has(id))
75
+ continue;
76
+ invalidated.add(id);
77
+ const mod = super.get(id);
78
+ if (mod == null ? void 0 : mod.importers)
79
+ this.invalidateDepTree(mod.importers, invalidated);
80
+ super.delete(id);
81
+ }
82
+ return invalidated;
83
+ }
65
84
  }
66
85
  class ViteNodeRunner {
67
86
  constructor(options) {
@@ -77,39 +96,44 @@ class ViteNodeRunner {
77
96
  return await this.cachedRequest(id, []);
78
97
  }
79
98
  async cachedRequest(rawId, callstack) {
80
- var _a, _b, _c, _d;
81
99
  const id = normalizeRequestId(rawId, this.options.base);
82
100
  const fsPath = toFilePath(id, this.root);
83
- if (callstack.includes(fsPath) && ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports))
84
- return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.exports;
85
- if ((_c = this.moduleCache.get(fsPath)) == null ? void 0 : _c.promise)
86
- return (_d = this.moduleCache.get(fsPath)) == null ? void 0 : _d.promise;
101
+ const mod = this.moduleCache.get(fsPath);
102
+ const importee = callstack[callstack.length - 1];
103
+ if (!mod.importers)
104
+ mod.importers = /* @__PURE__ */ new Set();
105
+ if (importee)
106
+ mod.importers.add(importee);
107
+ if (callstack.includes(fsPath) && mod.exports)
108
+ return mod.exports;
109
+ if (mod.promise)
110
+ return mod.promise;
87
111
  const promise = this.directRequest(id, fsPath, callstack);
88
- this.moduleCache.set(fsPath, { promise });
112
+ Object.assign(mod, { promise });
89
113
  return await promise;
90
114
  }
91
115
  async directRequest(id, fsPath, _callstack) {
92
116
  const callstack = [..._callstack, fsPath];
117
+ const mod = this.moduleCache.get(fsPath);
93
118
  const request = async (dep) => {
94
119
  var _a;
95
- const fsPath2 = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
120
+ const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
96
121
  const getStack = () => {
97
122
  return `stack:
98
- ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
123
+ ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
99
124
  };
100
125
  let debugTimer;
101
126
  if (this.debug)
102
- debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
127
+ debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
103
128
  ${getStack()}`), 2e3);
104
129
  try {
105
- if (callstack.includes(fsPath2)) {
106
- const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
130
+ if (callstack.includes(depFsPath)) {
131
+ const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
107
132
  if (depExports)
108
133
  return depExports;
109
134
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
110
135
  }
111
- const mod = await this.cachedRequest(dep, callstack);
112
- return mod;
136
+ return await this.cachedRequest(dep, callstack);
113
137
  } finally {
114
138
  if (debugTimer)
115
139
  clearTimeout(debugTimer);
@@ -133,17 +157,21 @@ ${getStack()}`), 2e3);
133
157
  let { code: transformed, externalize } = await this.options.fetchModule(id);
134
158
  if (externalize) {
135
159
  debugNative(externalize);
136
- const mod = await this.interopedImport(externalize);
137
- this.moduleCache.set(fsPath, { exports: mod });
138
- return mod;
160
+ const exports2 = await this.interopedImport(externalize);
161
+ mod.exports = exports2;
162
+ return exports2;
139
163
  }
140
164
  if (transformed == null)
141
165
  throw new Error(`[vite-node] Failed to load ${id}`);
142
166
  const url = pathToFileURL(fsPath).href;
143
167
  const meta = { url };
144
168
  const exports = /* @__PURE__ */ Object.create(null);
145
- exports[Symbol.toStringTag] = "Module";
146
- this.moduleCache.set(fsPath, { code: transformed, exports });
169
+ Object.defineProperty(exports, Symbol.toStringTag, {
170
+ value: "Module",
171
+ enumerable: false,
172
+ configurable: false
173
+ });
174
+ Object.assign(mod, { code: transformed, exports });
147
175
  const __filename = fileURLToPath(url);
148
176
  const moduleProxy = {
149
177
  set exports(value) {
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-b9c999e6.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-735b75af.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-b9c999e6.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-735b75af.js';
package/dist/server.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var perf_hooks = require('perf_hooks');
5
6
  var pathe = require('pathe');
6
7
  var createDebug = require('debug');
7
8
  var fs = require('fs');
@@ -178,14 +179,18 @@ class ViteNodeServer {
178
179
  if (timestamp && cache && cache.timestamp >= timestamp)
179
180
  return cache.result;
180
181
  const externalize = await this.shouldExternalize(filePath);
182
+ let duration;
181
183
  if (externalize) {
182
184
  result = { externalize };
183
185
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
184
186
  } else {
187
+ const start = perf_hooks.performance.now();
185
188
  const r = await this._transformRequest(id);
189
+ duration = perf_hooks.performance.now() - start;
186
190
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
187
191
  }
188
192
  this.fetchCache.set(filePath, {
193
+ duration,
189
194
  timestamp,
190
195
  result
191
196
  });
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-b9c999e6.js';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-735b75af.js';
3
3
 
4
4
  declare class Debugger {
5
5
  options: DebuggerOptions;
@@ -24,6 +24,7 @@ declare class ViteNodeServer {
24
24
  private fetchPromiseMap;
25
25
  private transformPromiseMap;
26
26
  fetchCache: Map<string, {
27
+ duration?: number | undefined;
27
28
  timestamp: number;
28
29
  result: FetchResult;
29
30
  }>;
package/dist/server.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { performance } from 'perf_hooks';
1
2
  import { resolve } from 'pathe';
2
3
  import createDebug from 'debug';
3
4
  import { existsSync } from 'fs';
@@ -170,14 +171,18 @@ class ViteNodeServer {
170
171
  if (timestamp && cache && cache.timestamp >= timestamp)
171
172
  return cache.result;
172
173
  const externalize = await this.shouldExternalize(filePath);
174
+ let duration;
173
175
  if (externalize) {
174
176
  result = { externalize };
175
177
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
176
178
  } else {
179
+ const start = performance.now();
177
180
  const r = await this._transformRequest(id);
181
+ duration = performance.now() - start;
178
182
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
179
183
  }
180
184
  this.fetchCache.set(filePath, {
185
+ duration,
181
186
  timestamp,
182
187
  result
183
188
  });
@@ -114,9 +114,17 @@ declare const DEFAULT_REQUEST_STUBS: {
114
114
  };
115
115
  declare class ModuleCacheMap extends Map<string, ModuleCache> {
116
116
  normalizePath(fsPath: string): string;
117
- set(fsPath: string, mod: Partial<ModuleCache>): this;
118
- get(fsPath: string): ModuleCache | undefined;
117
+ /**
118
+ * Assign partial data to the map
119
+ */
120
+ update(fsPath: string, mod: Partial<ModuleCache>): this;
121
+ set(fsPath: string, mod: ModuleCache): this;
122
+ get(fsPath: string): ModuleCache;
119
123
  delete(fsPath: string): boolean;
124
+ /**
125
+ * Invalidate modules that dependent on the given modules, up to the main entry
126
+ */
127
+ invalidateDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
120
128
  }
121
129
  declare class ViteNodeRunner {
122
130
  options: ViteNodeRunnerOptions;
@@ -183,6 +191,10 @@ interface ModuleCache {
183
191
  promise?: Promise<any>;
184
192
  exports?: any;
185
193
  code?: string;
194
+ /**
195
+ * Module ids that imports this module
196
+ */
197
+ importers?: Set<string>;
186
198
  }
187
199
  interface ViteNodeRunnerOptions {
188
200
  root: string;
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-b9c999e6.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-735b75af.js';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { N as Nullable, A as Arrayable } from './types-b9c999e6.js';
2
+ import { N as Nullable, A as Arrayable } from './types-735b75af.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.21.0",
3
+ "version": "0.22.1",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "debug": "^4.3.4",
68
- "mlly": "^0.5.5",
68
+ "mlly": "^0.5.12",
69
69
  "pathe": "^0.2.0",
70
70
  "vite": "^2.9.12 || ^3.0.0-0"
71
71
  },
@@ -73,7 +73,7 @@
73
73
  "@types/debug": "^4.1.7",
74
74
  "cac": "^6.7.12",
75
75
  "picocolors": "^1.0.0",
76
- "rollup": "^2.77.2"
76
+ "rollup": "^2.78.0"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "rimraf dist && rollup -c",
package/cli.d.ts DELETED
@@ -1,8 +0,0 @@
1
- interface CliOptions {
2
- files?: string[];
3
- _?: string[];
4
- root?: string;
5
- config?: string;
6
- }
7
-
8
- export { CliOptions };
package/client.d.ts DELETED
@@ -1,37 +0,0 @@
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 };
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions } from './types.js';
package/server.d.ts DELETED
@@ -1,26 +0,0 @@
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 DELETED
@@ -1,68 +0,0 @@
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 DELETED
@@ -1,10 +0,0 @@
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 };