vite-node 0.10.5 → 0.12.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.
@@ -99,15 +99,11 @@ class ViteNodeRunner {
99
99
  async directRequest(id, fsPath, _callstack) {
100
100
  const callstack = [..._callstack, utils.normalizeModuleId(id)];
101
101
  const request = async (dep) => {
102
- var _a, _b;
102
+ var _a;
103
103
  const getStack = () => {
104
104
  return `stack:
105
105
  ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
106
106
  };
107
- if (this.options.resolveId && this.shouldResolveId(dep)) {
108
- const resolvedDep = await this.options.resolveId(dep, id);
109
- dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
110
- }
111
107
  let debugTimer;
112
108
  if (this.debug)
113
109
  debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
@@ -115,7 +111,7 @@ ${getStack()}`), 2e3);
115
111
  try {
116
112
  if (callstack.includes(utils.normalizeModuleId(dep))) {
117
113
  this.debugLog(() => `circular dependency, ${getStack()}`);
118
- const depExports = (_b = this.moduleCache.get(dep)) == null ? void 0 : _b.exports;
114
+ const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
119
115
  if (depExports)
120
116
  return depExports;
121
117
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
@@ -127,6 +123,18 @@ ${getStack()}`), 2e3);
127
123
  clearTimeout(debugTimer);
128
124
  }
129
125
  };
126
+ Object.defineProperty(request, "callstack", { get: () => callstack });
127
+ const resolveId = async (dep, callstackPosition = 1) => {
128
+ if (this.options.resolveId && this.shouldResolveId(dep)) {
129
+ let importer = callstack[callstack.length - callstackPosition];
130
+ if (importer && importer.startsWith("mock:"))
131
+ importer = importer.slice(5);
132
+ const { id: id2 } = await this.options.resolveId(dep, importer) || {};
133
+ dep = id2 && pathe.isAbsolute(id2) ? `/@fs/${id2}` : id2 || dep;
134
+ }
135
+ return dep;
136
+ };
137
+ id = await resolveId(id, 2);
130
138
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
131
139
  if (id in requestStubs)
132
140
  return requestStubs[id];
@@ -158,6 +166,7 @@ ${getStack()}`), 2e3);
158
166
  __vite_ssr_exports__: exports,
159
167
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
160
168
  __vite_ssr_import_meta__: { url: url$1 },
169
+ __vitest_resolve_id__: resolveId,
161
170
  require: module$1.createRequire(url$1),
162
171
  exports,
163
172
  module: moduleProxy,
@@ -178,7 +187,7 @@ ${getStack()}`), 2e3);
178
187
  return context;
179
188
  }
180
189
  shouldResolveId(dep) {
181
- if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
190
+ if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
182
191
  return false;
183
192
  return !pathe.isAbsolute(dep) || !pathe.extname(dep);
184
193
  }
@@ -75,15 +75,11 @@ class ViteNodeRunner {
75
75
  async directRequest(id, fsPath, _callstack) {
76
76
  const callstack = [..._callstack, normalizeModuleId(id)];
77
77
  const request = async (dep) => {
78
- var _a, _b;
78
+ var _a;
79
79
  const getStack = () => {
80
80
  return `stack:
81
81
  ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
82
82
  };
83
- if (this.options.resolveId && this.shouldResolveId(dep)) {
84
- const resolvedDep = await this.options.resolveId(dep, id);
85
- dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
86
- }
87
83
  let debugTimer;
88
84
  if (this.debug)
89
85
  debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
@@ -91,7 +87,7 @@ ${getStack()}`), 2e3);
91
87
  try {
92
88
  if (callstack.includes(normalizeModuleId(dep))) {
93
89
  this.debugLog(() => `circular dependency, ${getStack()}`);
94
- const depExports = (_b = this.moduleCache.get(dep)) == null ? void 0 : _b.exports;
90
+ const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
95
91
  if (depExports)
96
92
  return depExports;
97
93
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
@@ -103,6 +99,18 @@ ${getStack()}`), 2e3);
103
99
  clearTimeout(debugTimer);
104
100
  }
105
101
  };
102
+ Object.defineProperty(request, "callstack", { get: () => callstack });
103
+ const resolveId = async (dep, callstackPosition = 1) => {
104
+ if (this.options.resolveId && this.shouldResolveId(dep)) {
105
+ let importer = callstack[callstack.length - callstackPosition];
106
+ if (importer && importer.startsWith("mock:"))
107
+ importer = importer.slice(5);
108
+ const { id: id2 } = await this.options.resolveId(dep, importer) || {};
109
+ dep = id2 && isAbsolute(id2) ? `/@fs/${id2}` : id2 || dep;
110
+ }
111
+ return dep;
112
+ };
113
+ id = await resolveId(id, 2);
106
114
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
107
115
  if (id in requestStubs)
108
116
  return requestStubs[id];
@@ -134,6 +142,7 @@ ${getStack()}`), 2e3);
134
142
  __vite_ssr_exports__: exports,
135
143
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
136
144
  __vite_ssr_import_meta__: { url },
145
+ __vitest_resolve_id__: resolveId,
137
146
  require: createRequire(url),
138
147
  exports,
139
148
  module: moduleProxy,
@@ -154,7 +163,7 @@ ${getStack()}`), 2e3);
154
163
  return context;
155
164
  }
156
165
  shouldResolveId(dep) {
157
- if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
166
+ if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
158
167
  return false;
159
168
  return !isAbsolute(dep) || !extname(dep);
160
169
  }
package/dist/client.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-27c69c2f.js');
5
+ var client = require('./client-def5e426.js');
6
6
  require('module');
7
7
  require('url');
8
8
  require('vm');
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, V as ViteNodeRunner } from './client-d34f7f42.js';
1
+ export { D as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, V as ViteNodeRunner } from './client-e36231b1.js';
2
2
  import 'module';
3
3
  import 'url';
4
4
  import 'vm';
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,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "0.10.5",
4
+ "version": "0.12.1",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "homepage": "https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme",
7
7
  "bugs": {
@@ -58,14 +58,13 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "kolorist": "^1.5.1",
61
- "minimist": "^1.2.6",
62
61
  "mlly": "^0.5.2",
63
62
  "pathe": "^0.2.0",
64
63
  "vite": "^2.9.7"
65
64
  },
66
65
  "devDependencies": {
67
- "@types/minimist": "^1.2.2",
68
- "rollup": "^2.71.1"
66
+ "cac": "^6.7.12",
67
+ "rollup": "^2.72.1"
69
68
  },
70
69
  "engines": {
71
70
  "node": ">=v14.16.0"
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 };