vite-node 0.28.5 → 0.29.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
@@ -9,14 +9,13 @@ var utils = require('./utils.cjs');
9
9
  var sourceMap = require('./source-map.cjs');
10
10
  var hmr = require('./chunk-hmr.cjs');
11
11
  require('perf_hooks');
12
+ require('fs');
12
13
  require('pathe');
13
14
  require('debug');
14
- require('fs');
15
15
  require('mlly');
16
16
  require('node:url');
17
- require('source-map-support');
18
- require('module');
19
17
  require('path');
18
+ require('module');
20
19
  require('vm');
21
20
  require('node:events');
22
21
 
@@ -25,10 +24,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
25
24
  var cac__default = /*#__PURE__*/_interopDefaultLegacy(cac);
26
25
  var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
27
26
 
28
- var version = "0.28.5";
27
+ var version = "0.29.1";
29
28
 
30
29
  const cli = cac__default["default"]("vite-node");
31
- 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("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").help();
30
+ cli.version(version).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").help();
32
31
  cli.command("[...files]").allowUnknownOptions().action(run);
33
32
  cli.parse();
34
33
  async function run(files, options = {}) {
@@ -50,6 +49,7 @@ async function run(files, options = {}) {
50
49
  logLevel: "error",
51
50
  configFile: options.config,
52
51
  root: options.root,
52
+ mode: options.mode,
53
53
  plugins: [
54
54
  options.watch && hmr.viteNodeHmrPlugin()
55
55
  ]
package/dist/cli.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { e as ViteNodeServerOptions } from './types-63205a44.js';
1
+ import { e as ViteNodeServerOptions } from './types-e288fc62.js';
2
+ import './types.d-1e7e3fdf.js';
2
3
 
3
4
  interface CliOptions {
4
5
  root?: string;
5
6
  script?: boolean;
6
7
  config?: string;
8
+ mode?: string;
7
9
  watch?: boolean;
8
10
  options?: ViteNodeServerOptionsCLI;
9
11
  '--'?: string[];
package/dist/cli.mjs CHANGED
@@ -7,21 +7,20 @@ import { toArray } from './utils.mjs';
7
7
  import { installSourcemapsSupport } from './source-map.mjs';
8
8
  import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
9
9
  import 'node:perf_hooks';
10
+ import 'node:fs';
10
11
  import 'pathe';
11
12
  import 'debug';
12
- import 'node:fs';
13
13
  import 'mlly';
14
14
  import 'node:url';
15
- import 'source-map-support';
16
- import 'node:module';
17
15
  import 'node:path';
16
+ import 'node:module';
18
17
  import 'node:vm';
19
18
  import 'node:events';
20
19
 
21
- var version = "0.28.5";
20
+ var version = "0.29.1";
22
21
 
23
22
  const cli = cac("vite-node");
24
- 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("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").help();
23
+ cli.version(version).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").help();
25
24
  cli.command("[...files]").allowUnknownOptions().action(run);
26
25
  cli.parse();
27
26
  async function run(files, options = {}) {
@@ -43,6 +42,7 @@ async function run(files, options = {}) {
43
42
  logLevel: "error",
44
43
  configFile: options.config,
45
44
  root: options.root,
45
+ mode: options.mode,
46
46
  plugins: [
47
47
  options.watch && viteNodeHmrPlugin()
48
48
  ]
package/dist/client.cjs CHANGED
@@ -12,7 +12,6 @@ var createDebug = require('debug');
12
12
  var utils = require('./utils.cjs');
13
13
  var sourceMap = require('./source-map.cjs');
14
14
  require('fs');
15
- require('source-map-support');
16
15
 
17
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
17
 
@@ -163,9 +162,6 @@ class ViteNodeRunner {
163
162
  const [id, url] = await this.resolveUrl(rawId);
164
163
  return await this.cachedRequest(id, url, []);
165
164
  }
166
- getSourceMap(id) {
167
- return this.moduleCache.getSourceMap(id);
168
- }
169
165
  async cachedRequest(id, fsPath, callstack) {
170
166
  const importee = callstack[callstack.length - 1];
171
167
  const mod = this.moduleCache.get(fsPath);
@@ -188,16 +184,16 @@ class ViteNodeRunner {
188
184
  shouldResolveId(id, _importee) {
189
185
  return !utils.isInternalRequest(id) && !mlly.isNodeBuiltin(id);
190
186
  }
191
- async _resolveUrl(id, importee) {
192
- if (importee && id.startsWith(utils.VALID_ID_PREFIX))
193
- importee = void 0;
187
+ async _resolveUrl(id, importer) {
188
+ if (importer && id.startsWith(utils.VALID_ID_PREFIX))
189
+ importer = void 0;
194
190
  id = utils.normalizeRequestId(id, this.options.base);
195
191
  if (!this.shouldResolveId(id))
196
192
  return [id, id];
197
193
  const { path, exists } = utils.toFilePath(id, this.root);
198
194
  if (!this.options.resolveId || exists)
199
195
  return [id, path];
200
- const resolved = await this.options.resolveId(id, importee);
196
+ const resolved = await this.options.resolveId(id, importer);
201
197
  const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : id;
202
198
  const fsPath = resolved ? resolvedId : path;
203
199
  return [resolvedId, fsPath];
package/dist/client.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-63205a44.js';
1
+ import './types.d-1e7e3fdf.js';
2
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-e288fc62.js';
package/dist/client.mjs CHANGED
@@ -8,7 +8,6 @@ import createDebug from 'debug';
8
8
  import { normalizeModuleId, slash, isInternalRequest, VALID_ID_PREFIX, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
9
9
  import { extractSourceMap } from './source-map.mjs';
10
10
  import 'node:fs';
11
- import 'source-map-support';
12
11
 
13
12
  const { setTimeout, clearTimeout } = globalThis;
14
13
  const debugExecute = createDebug("vite-node:client:execute");
@@ -136,9 +135,6 @@ class ViteNodeRunner {
136
135
  const [id, url] = await this.resolveUrl(rawId);
137
136
  return await this.cachedRequest(id, url, []);
138
137
  }
139
- getSourceMap(id) {
140
- return this.moduleCache.getSourceMap(id);
141
- }
142
138
  async cachedRequest(id, fsPath, callstack) {
143
139
  const importee = callstack[callstack.length - 1];
144
140
  const mod = this.moduleCache.get(fsPath);
@@ -161,16 +157,16 @@ class ViteNodeRunner {
161
157
  shouldResolveId(id, _importee) {
162
158
  return !isInternalRequest(id) && !isNodeBuiltin(id);
163
159
  }
164
- async _resolveUrl(id, importee) {
165
- if (importee && id.startsWith(VALID_ID_PREFIX))
166
- importee = void 0;
160
+ async _resolveUrl(id, importer) {
161
+ if (importer && id.startsWith(VALID_ID_PREFIX))
162
+ importer = void 0;
167
163
  id = normalizeRequestId(id, this.options.base);
168
164
  if (!this.shouldResolveId(id))
169
165
  return [id, id];
170
166
  const { path, exists } = toFilePath(id, this.root);
171
167
  if (!this.options.resolveId || exists)
172
168
  return [id, path];
173
- const resolved = await this.options.resolveId(id, importee);
169
+ const resolved = await this.options.resolveId(id, importer);
174
170
  const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : id;
175
171
  const fsPath = resolved ? resolvedId : path;
176
172
  return [resolvedId, fsPath];
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,7 @@
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-63205a44.js';
3
+ import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-e288fc62.js';
4
+ import './types.d-1e7e3fdf.js';
4
5
 
5
6
  type EventType = string | symbol;
6
7
  type Handler<T = unknown> = (event: T) => void;
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
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';
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-e288fc62.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-1e7e3fdf.js';
package/dist/server.cjs CHANGED
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var perf_hooks = require('perf_hooks');
6
+ var fs = require('fs');
6
7
  var pathe = require('pathe');
7
8
  var createDebug = require('debug');
8
- var fs = require('fs');
9
9
  var mlly = require('mlly');
10
10
  var utils = require('./utils.cjs');
11
11
  var c = require('picocolors');
12
12
  var sourceMap = require('./source-map.cjs');
13
13
  require('node:url');
14
- require('source-map-support');
14
+ require('path');
15
15
 
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
17
 
@@ -92,6 +92,8 @@ async function _shouldExternalize(id, options) {
92
92
  if (id.startsWith("data:"))
93
93
  return id;
94
94
  id = patchWindowsImportPath(id);
95
+ if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
96
+ return id;
95
97
  if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
96
98
  return false;
97
99
  if (matchExternalizePattern(id, options == null ? void 0 : options.external))
@@ -209,12 +211,14 @@ class ViteNodeServer {
209
211
  this.options = options;
210
212
  this.fetchPromiseMap = /* @__PURE__ */ new Map();
211
213
  this.transformPromiseMap = /* @__PURE__ */ new Map();
214
+ this.existingOptimizedDeps = /* @__PURE__ */ new Set();
212
215
  this.fetchCache = /* @__PURE__ */ new Map();
213
216
  this.externalizeCache = /* @__PURE__ */ new Map();
214
217
  var _a, _b;
215
218
  const ssrOptions = server.config.ssr;
219
+ options.deps ?? (options.deps = {});
220
+ options.deps.cacheDir = pathe.relative(server.config.root, server.config.cacheDir);
216
221
  if (ssrOptions) {
217
- options.deps ?? (options.deps = {});
218
222
  if (ssrOptions.noExternal === true) {
219
223
  (_a = options.deps).inline ?? (_a.inline = true);
220
224
  } else if (options.deps.inline !== true) {
@@ -234,10 +238,25 @@ class ViteNodeServer {
234
238
  shouldExternalize(id) {
235
239
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
236
240
  }
237
- async resolveId(id, importer) {
241
+ async ensureExists(id) {
242
+ if (this.existingOptimizedDeps.has(id))
243
+ return true;
244
+ if (fs.existsSync(id)) {
245
+ this.existingOptimizedDeps.add(id);
246
+ return true;
247
+ }
248
+ return new Promise((resolve2) => {
249
+ setTimeout(() => {
250
+ this.ensureExists(id).then(() => {
251
+ resolve2(true);
252
+ });
253
+ });
254
+ });
255
+ }
256
+ async resolveId(id, importer, transformMode) {
238
257
  if (importer && !importer.startsWith(this.server.config.root))
239
258
  importer = pathe.resolve(this.server.config.root, importer);
240
- const mode = importer && this.getTransformMode(importer) || "ssr";
259
+ const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
241
260
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
242
261
  }
243
262
  getSourceMap(source) {
@@ -248,12 +267,12 @@ class ViteNodeServer {
248
267
  const ssrTransformResult = (_b = this.server.moduleGraph.getModuleById(source)) == null ? void 0 : _b.ssrTransformResult;
249
268
  return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
250
269
  }
251
- async fetchModule(id) {
270
+ async fetchModule(id, transformMode) {
252
271
  id = utils.normalizeModuleId(id);
253
272
  if (!this.fetchPromiseMap.has(id)) {
254
273
  this.fetchPromiseMap.set(
255
274
  id,
256
- this._fetchModule(id).then((r) => {
275
+ this._fetchModule(id, transformMode).then((r) => {
257
276
  return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
258
277
  }).finally(() => {
259
278
  this.fetchPromiseMap.delete(id);
@@ -284,9 +303,19 @@ class ViteNodeServer {
284
303
  return "ssr";
285
304
  return "web";
286
305
  }
287
- async _fetchModule(id) {
288
- var _a;
306
+ async _fetchModule(id, transformMode) {
307
+ var _a, _b;
289
308
  let result;
309
+ const cacheDir = (_a = this.options.deps) == null ? void 0 : _a.cacheDir;
310
+ if (cacheDir && id.includes(cacheDir)) {
311
+ if (!id.startsWith(this.server.config.root))
312
+ id = pathe.join(this.server.config.root, id);
313
+ const timeout = setTimeout(() => {
314
+ throw new Error(`ViteNodeServer: ${id} not found. This is a bug, please report it.`);
315
+ }, 5e3);
316
+ await this.ensureExists(id);
317
+ clearTimeout(timeout);
318
+ }
290
319
  const { path: filePath } = utils.toFilePath(id, this.server.config.root);
291
320
  const module = this.server.moduleGraph.getModuleById(id);
292
321
  const timestamp = module ? module.lastHMRTimestamp : null;
@@ -298,10 +327,10 @@ class ViteNodeServer {
298
327
  let duration;
299
328
  if (externalize) {
300
329
  result = { externalize };
301
- (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
330
+ (_b = this.debugger) == null ? void 0 : _b.recordExternalize(id, externalize);
302
331
  } else {
303
332
  const start = perf_hooks.performance.now();
304
- const r = await this._transformRequest(id);
333
+ const r = await this._transformRequest(id, transformMode);
305
334
  duration = perf_hooks.performance.now() - start;
306
335
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
307
336
  }
@@ -312,7 +341,7 @@ class ViteNodeServer {
312
341
  });
313
342
  return result;
314
343
  }
315
- async _transformRequest(id) {
344
+ async _transformRequest(id, customTransformMode) {
316
345
  var _a, _b, _c, _d;
317
346
  debugRequest(id);
318
347
  let result = null;
@@ -321,7 +350,8 @@ class ViteNodeServer {
321
350
  if (result)
322
351
  return result;
323
352
  }
324
- if (this.getTransformMode(id) === "web") {
353
+ const transformMode = customTransformMode ?? this.getTransformMode(id);
354
+ if (transformMode === "web") {
325
355
  result = await this.server.transformRequest(id);
326
356
  if (result)
327
357
  result = await this.server.ssrTransform(result.code, result.map, id);
package/dist/server.d.ts CHANGED
@@ -1,5 +1,6 @@
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-63205a44.js';
2
+ import { E as EncodedSourceMap } from './types.d-1e7e3fdf.js';
3
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-e288fc62.js';
3
4
 
4
5
  declare class Debugger {
5
6
  options: DebuggerOptions;
@@ -23,6 +24,7 @@ declare class ViteNodeServer {
23
24
  options: ViteNodeServerOptions;
24
25
  private fetchPromiseMap;
25
26
  private transformPromiseMap;
27
+ private existingOptimizedDeps;
26
28
  fetchCache: Map<string, {
27
29
  duration?: number | undefined;
28
30
  timestamp: number;
@@ -32,9 +34,10 @@ declare class ViteNodeServer {
32
34
  debugger?: Debugger;
33
35
  constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
34
36
  shouldExternalize(id: string): Promise<string | false>;
35
- resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
36
- getSourceMap(source: string): RawSourceMap | null;
37
- fetchModule(id: string): Promise<FetchResult>;
37
+ private ensureExists;
38
+ resolveId(id: string, importer?: string, transformMode?: 'web' | 'ssr'): Promise<ViteNodeResolveId | null>;
39
+ getSourceMap(source: string): EncodedSourceMap | null;
40
+ fetchModule(id: string, transformMode?: 'web' | 'ssr'): Promise<FetchResult>;
38
41
  transformRequest(id: string): Promise<TransformResult | null | undefined>;
39
42
  getTransformMode(id: string): "web" | "ssr";
40
43
  private _fetchModule;
package/dist/server.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { performance } from 'node:perf_hooks';
2
- import { resolve, join } from 'pathe';
3
- import createDebug from 'debug';
4
2
  import { existsSync, promises } from 'node:fs';
3
+ import { resolve, join, relative } from 'pathe';
4
+ import createDebug from 'debug';
5
5
  import { isNodeBuiltin, isValidNodeImport } from 'mlly';
6
6
  import { slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
7
7
  import c from 'picocolors';
8
8
  import { withInlineSourcemap } from './source-map.mjs';
9
9
  import 'node:url';
10
- import 'source-map-support';
10
+ import 'node:path';
11
11
 
12
12
  const KNOWN_ASSET_TYPES = [
13
13
  "png",
@@ -83,6 +83,8 @@ async function _shouldExternalize(id, options) {
83
83
  if (id.startsWith("data:"))
84
84
  return id;
85
85
  id = patchWindowsImportPath(id);
86
+ if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
87
+ return id;
86
88
  if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
87
89
  return false;
88
90
  if (matchExternalizePattern(id, options == null ? void 0 : options.external))
@@ -200,12 +202,14 @@ class ViteNodeServer {
200
202
  this.options = options;
201
203
  this.fetchPromiseMap = /* @__PURE__ */ new Map();
202
204
  this.transformPromiseMap = /* @__PURE__ */ new Map();
205
+ this.existingOptimizedDeps = /* @__PURE__ */ new Set();
203
206
  this.fetchCache = /* @__PURE__ */ new Map();
204
207
  this.externalizeCache = /* @__PURE__ */ new Map();
205
208
  var _a, _b;
206
209
  const ssrOptions = server.config.ssr;
210
+ options.deps ?? (options.deps = {});
211
+ options.deps.cacheDir = relative(server.config.root, server.config.cacheDir);
207
212
  if (ssrOptions) {
208
- options.deps ?? (options.deps = {});
209
213
  if (ssrOptions.noExternal === true) {
210
214
  (_a = options.deps).inline ?? (_a.inline = true);
211
215
  } else if (options.deps.inline !== true) {
@@ -225,10 +229,25 @@ class ViteNodeServer {
225
229
  shouldExternalize(id) {
226
230
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
227
231
  }
228
- async resolveId(id, importer) {
232
+ async ensureExists(id) {
233
+ if (this.existingOptimizedDeps.has(id))
234
+ return true;
235
+ if (existsSync(id)) {
236
+ this.existingOptimizedDeps.add(id);
237
+ return true;
238
+ }
239
+ return new Promise((resolve2) => {
240
+ setTimeout(() => {
241
+ this.ensureExists(id).then(() => {
242
+ resolve2(true);
243
+ });
244
+ });
245
+ });
246
+ }
247
+ async resolveId(id, importer, transformMode) {
229
248
  if (importer && !importer.startsWith(this.server.config.root))
230
249
  importer = resolve(this.server.config.root, importer);
231
- const mode = importer && this.getTransformMode(importer) || "ssr";
250
+ const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
232
251
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
233
252
  }
234
253
  getSourceMap(source) {
@@ -239,12 +258,12 @@ class ViteNodeServer {
239
258
  const ssrTransformResult = (_b = this.server.moduleGraph.getModuleById(source)) == null ? void 0 : _b.ssrTransformResult;
240
259
  return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
241
260
  }
242
- async fetchModule(id) {
261
+ async fetchModule(id, transformMode) {
243
262
  id = normalizeModuleId(id);
244
263
  if (!this.fetchPromiseMap.has(id)) {
245
264
  this.fetchPromiseMap.set(
246
265
  id,
247
- this._fetchModule(id).then((r) => {
266
+ this._fetchModule(id, transformMode).then((r) => {
248
267
  return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
249
268
  }).finally(() => {
250
269
  this.fetchPromiseMap.delete(id);
@@ -275,9 +294,19 @@ class ViteNodeServer {
275
294
  return "ssr";
276
295
  return "web";
277
296
  }
278
- async _fetchModule(id) {
279
- var _a;
297
+ async _fetchModule(id, transformMode) {
298
+ var _a, _b;
280
299
  let result;
300
+ const cacheDir = (_a = this.options.deps) == null ? void 0 : _a.cacheDir;
301
+ if (cacheDir && id.includes(cacheDir)) {
302
+ if (!id.startsWith(this.server.config.root))
303
+ id = join(this.server.config.root, id);
304
+ const timeout = setTimeout(() => {
305
+ throw new Error(`ViteNodeServer: ${id} not found. This is a bug, please report it.`);
306
+ }, 5e3);
307
+ await this.ensureExists(id);
308
+ clearTimeout(timeout);
309
+ }
281
310
  const { path: filePath } = toFilePath(id, this.server.config.root);
282
311
  const module = this.server.moduleGraph.getModuleById(id);
283
312
  const timestamp = module ? module.lastHMRTimestamp : null;
@@ -289,10 +318,10 @@ class ViteNodeServer {
289
318
  let duration;
290
319
  if (externalize) {
291
320
  result = { externalize };
292
- (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
321
+ (_b = this.debugger) == null ? void 0 : _b.recordExternalize(id, externalize);
293
322
  } else {
294
323
  const start = performance.now();
295
- const r = await this._transformRequest(id);
324
+ const r = await this._transformRequest(id, transformMode);
296
325
  duration = performance.now() - start;
297
326
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
298
327
  }
@@ -303,7 +332,7 @@ class ViteNodeServer {
303
332
  });
304
333
  return result;
305
334
  }
306
- async _transformRequest(id) {
335
+ async _transformRequest(id, customTransformMode) {
307
336
  var _a, _b, _c, _d;
308
337
  debugRequest(id);
309
338
  let result = null;
@@ -312,7 +341,8 @@ class ViteNodeServer {
312
341
  if (result)
313
342
  return result;
314
343
  }
315
- if (this.getTransformMode(id) === "web") {
344
+ const transformMode = customTransformMode ?? this.getTransformMode(id);
345
+ if (transformMode === "web") {
316
346
  result = await this.server.transformRequest(id);
317
347
  if (result)
318
348
  result = await this.server.ssrTransform(result.code, result.map, id);