vite-node 0.32.4 → 0.34.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/dist/client.mjs CHANGED
@@ -13,7 +13,7 @@ const debugExecute = createDebug("vite-node:client:execute");
13
13
  const debugNative = createDebug("vite-node:client:native");
14
14
  const clientStub = {
15
15
  injectQuery: (id) => id,
16
- createHotContext() {
16
+ createHotContext: () => {
17
17
  return {
18
18
  accept: () => {
19
19
  },
@@ -31,18 +31,9 @@ const clientStub = {
31
31
  }
32
32
  };
33
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);
34
+ updateStyle: () => {
35
+ },
36
+ removeStyle: () => {
46
37
  }
47
38
  };
48
39
  const DEFAULT_REQUEST_STUBS = {
@@ -254,29 +245,30 @@ ${getStack()}`), 2e3);
254
245
  }
255
246
  if (transformed == null)
256
247
  throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
248
+ const { Object: Object2, Reflect: Reflect2, Symbol: Symbol2 } = this.getContextPrimitives();
257
249
  const modulePath = cleanUrl(moduleId);
258
250
  const href = pathToFileURL(modulePath).href;
259
251
  const meta = { url: href };
260
- const exports = /* @__PURE__ */ Object.create(null);
261
- Object.defineProperty(exports, Symbol.toStringTag, {
252
+ const exports = Object2.create(null);
253
+ Object2.defineProperty(exports, Symbol2.toStringTag, {
262
254
  value: "Module",
263
255
  enumerable: false,
264
256
  configurable: false
265
257
  });
266
258
  const cjsExports = new Proxy(exports, {
267
259
  get: (target, p, receiver) => {
268
- if (Reflect.has(target, p))
269
- return Reflect.get(target, p, receiver);
270
- return Reflect.get(Object.prototype, p, receiver);
260
+ if (Reflect2.has(target, p))
261
+ return Reflect2.get(target, p, receiver);
262
+ return Reflect2.get(Object2.prototype, p, receiver);
271
263
  },
272
- getPrototypeOf: () => Object.prototype,
264
+ getPrototypeOf: () => Object2.prototype,
273
265
  set: (_, p, value) => {
274
266
  if (p === "default" && this.shouldInterop(modulePath, { default: value }) && cjsExports !== value) {
275
267
  exportAll(cjsExports, value);
276
268
  exports.default = value;
277
269
  return true;
278
270
  }
279
- if (!Reflect.has(exports, "default"))
271
+ if (!Reflect2.has(exports, "default"))
280
272
  exports.default = {};
281
273
  if (isPrimitive(exports.default)) {
282
274
  defineExport(exports, p, () => void 0);
@@ -288,7 +280,7 @@ ${getStack()}`), 2e3);
288
280
  return true;
289
281
  }
290
282
  });
291
- Object.assign(mod, { code: transformed, exports });
283
+ Object2.assign(mod, { code: transformed, exports });
292
284
  const __filename = fileURLToPath(href);
293
285
  const moduleProxy = {
294
286
  set exports(value) {
@@ -301,11 +293,11 @@ ${getStack()}`), 2e3);
301
293
  };
302
294
  let hotContext;
303
295
  if (this.options.createHotContext) {
304
- Object.defineProperty(meta, "hot", {
296
+ Object2.defineProperty(meta, "hot", {
305
297
  enumerable: true,
306
298
  get: () => {
307
299
  var _a, _b;
308
- hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
300
+ hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, moduleId));
309
301
  return hotContext;
310
302
  },
311
303
  set: (value) => {
@@ -330,16 +322,23 @@ ${getStack()}`), 2e3);
330
322
  debugExecute(__filename);
331
323
  if (transformed[0] === "#")
332
324
  transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
325
+ await this.runModule(context, transformed);
326
+ return exports;
327
+ }
328
+ getContextPrimitives() {
329
+ return { Object, Reflect, Symbol };
330
+ }
331
+ async runModule(context, transformed) {
333
332
  const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
334
333
  const code = `${codeDefinition}${transformed}
335
334
  }}`;
336
- const fn = vm.runInThisContext(code, {
337
- filename: __filename,
335
+ const options = {
336
+ filename: context.__filename,
338
337
  lineOffset: 0,
339
338
  columnOffset: -codeDefinition.length
340
- });
339
+ };
340
+ const fn = vm.runInThisContext(code, options);
341
341
  await fn(...Object.values(context));
342
- return exports;
343
342
  }
344
343
  prepareContext(context) {
345
344
  return context;
@@ -353,11 +352,14 @@ ${getStack()}`), 2e3);
353
352
  return false;
354
353
  return !path.endsWith(".mjs") && "default" in mod;
355
354
  }
355
+ importExternalModule(path) {
356
+ return import(path);
357
+ }
356
358
  /**
357
359
  * Import a module and interop it
358
360
  */
359
361
  async interopedImport(path) {
360
- const importedModule = await import(path);
362
+ const importedModule = await this.importExternalModule(path);
361
363
  if (!this.shouldInterop(path, importedModule))
362
364
  return importedModule;
363
365
  const { mod, defaultExport } = interopModule(importedModule);
@@ -412,7 +414,7 @@ function defineExport(exports, key, value) {
412
414
  function exportAll(exports, sourceModule) {
413
415
  if (exports === sourceModule)
414
416
  return;
415
- if (isPrimitive(sourceModule) || Array.isArray(sourceModule))
417
+ if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)
416
418
  return;
417
419
  for (const key in sourceModule) {
418
420
  if (key !== "default") {
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const KNOWN_ASSET_TYPES = [
6
+ // images
7
+ "apng",
8
+ "png",
9
+ "jpe?g",
10
+ "jfif",
11
+ "pjpeg",
12
+ "pjp",
13
+ "gif",
14
+ "svg",
15
+ "ico",
16
+ "webp",
17
+ "avif",
18
+ // media
19
+ "mp4",
20
+ "webm",
21
+ "ogg",
22
+ "mp3",
23
+ "wav",
24
+ "flac",
25
+ "aac",
26
+ // fonts
27
+ "woff2?",
28
+ "eot",
29
+ "ttf",
30
+ "otf",
31
+ // other
32
+ "webmanifest",
33
+ "pdf",
34
+ "txt"
35
+ ];
36
+ const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
37
+ const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
38
+
39
+ exports.CSS_LANGS_RE = CSS_LANGS_RE;
40
+ exports.KNOWN_ASSET_RE = KNOWN_ASSET_RE;
41
+ exports.KNOWN_ASSET_TYPES = KNOWN_ASSET_TYPES;
@@ -0,0 +1,5 @@
1
+ declare const KNOWN_ASSET_TYPES: string[];
2
+ declare const KNOWN_ASSET_RE: RegExp;
3
+ declare const CSS_LANGS_RE: RegExp;
4
+
5
+ export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES };
@@ -0,0 +1,35 @@
1
+ const KNOWN_ASSET_TYPES = [
2
+ // images
3
+ "apng",
4
+ "png",
5
+ "jpe?g",
6
+ "jfif",
7
+ "pjpeg",
8
+ "pjp",
9
+ "gif",
10
+ "svg",
11
+ "ico",
12
+ "webp",
13
+ "avif",
14
+ // media
15
+ "mp4",
16
+ "webm",
17
+ "ogg",
18
+ "mp3",
19
+ "wav",
20
+ "flac",
21
+ "aac",
22
+ // fonts
23
+ "woff2?",
24
+ "eot",
25
+ "ttf",
26
+ "otf",
27
+ // other
28
+ "webmanifest",
29
+ "pdf",
30
+ "txt"
31
+ ];
32
+ const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
33
+ const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
34
+
35
+ export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES };
package/dist/hmr.cjs CHANGED
@@ -6,6 +6,11 @@ var hmr = require('./chunk-hmr.cjs');
6
6
  require('node:events');
7
7
  require('picocolors');
8
8
  require('debug');
9
+ require('./utils.cjs');
10
+ require('node:url');
11
+ require('module');
12
+ require('fs');
13
+ require('pathe');
9
14
 
10
15
 
11
16
 
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload as HMRPayload$1, Plugin } from 'vite';
3
- import { h as ViteNodeRunner, H as HotContext } from './types-516036fa.js';
3
+ import { h as ViteNodeRunner, H as HotContext } from './types-e8623e9c.js';
4
4
  import 'vite/types/hot';
5
5
  import './types.d-7442d07f.js';
6
6
 
@@ -99,6 +99,9 @@ interface InvalidatePayload {
99
99
  message: string | undefined
100
100
  }
101
101
 
102
+ type ModuleNamespace = Record<string, any> & {
103
+ [Symbol.toStringTag]: 'Module';
104
+ };
102
105
  type InferCustomEventPayload<T extends string> = T extends keyof CustomEventMap ? CustomEventMap[T] : any;
103
106
  interface HotModule {
104
107
  id: string;
@@ -106,7 +109,7 @@ interface HotModule {
106
109
  }
107
110
  interface HotCallback {
108
111
  deps: string[];
109
- fn: (modules: object[]) => void;
112
+ fn: (modules: (ModuleNamespace | undefined)[]) => void;
110
113
  }
111
114
  interface CacheData {
112
115
  hotModulesMap: Map<string, HotModule>;
@@ -126,4 +129,4 @@ declare function reload(runner: ViteNodeRunner, files: string[]): Promise<any[]>
126
129
  declare function handleMessage(runner: ViteNodeRunner, emitter: HMREmitter, files: string[], payload: HMRPayload): Promise<void>;
127
130
  declare function createHotContext(runner: ViteNodeRunner, emitter: HMREmitter, files: string[], ownerPath: string): HotContext;
128
131
 
129
- export { Emitter, EventType, HMREmitter, Handler, HotCallback, HotModule, InferCustomEventPayload, createHmrEmitter, createHotContext, getCache, handleMessage, reload, sendMessageBuffer, viteNodeHmrPlugin };
132
+ export { Emitter, EventType, HMREmitter, Handler, HotCallback, HotModule, InferCustomEventPayload, ModuleNamespace, createHmrEmitter, createHotContext, getCache, handleMessage, reload, sendMessageBuffer, viteNodeHmrPlugin };
package/dist/hmr.mjs CHANGED
@@ -2,3 +2,8 @@ export { a as createHmrEmitter, c as createHotContext, g as getCache, h as handl
2
2
  import 'node:events';
3
3
  import 'picocolors';
4
4
  import 'debug';
5
+ import './utils.mjs';
6
+ import 'node:url';
7
+ import 'node:module';
8
+ import 'node:fs';
9
+ import 'pathe';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-516036fa.js';
1
+ export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-e8623e9c.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
3
3
  import 'vite/types/hot';
package/dist/server.cjs CHANGED
@@ -8,6 +8,7 @@ var pathe = require('pathe');
8
8
  var createDebug = require('debug');
9
9
  var mlly = require('mlly');
10
10
  var utils = require('./utils.cjs');
11
+ var constants = require('./constants.cjs');
11
12
  var c = require('picocolors');
12
13
  var sourceMap = require('./source-map.cjs');
13
14
  require('node:url');
@@ -19,37 +20,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
19
20
  var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
20
21
  var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
21
22
 
22
- const KNOWN_ASSET_TYPES = [
23
- // images
24
- "apng",
25
- "png",
26
- "jpe?g",
27
- "jfif",
28
- "pjpeg",
29
- "pjp",
30
- "gif",
31
- "svg",
32
- "ico",
33
- "webp",
34
- "avif",
35
- // media
36
- "mp4",
37
- "webm",
38
- "ogg",
39
- "mp3",
40
- "wav",
41
- "flac",
42
- "aac",
43
- // fonts
44
- "woff2?",
45
- "eot",
46
- "ttf",
47
- "otf",
48
- // other
49
- "webmanifest",
50
- "pdf",
51
- "txt"
52
- ];
53
23
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
54
24
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
55
25
  const defaultInline = [
@@ -58,7 +28,7 @@ const defaultInline = [
58
28
  // special Vite query strings
59
29
  /[?&](init|raw|url|inline)\b/,
60
30
  // Vite returns a string for assets imports, even if it's inside "node_modules"
61
- new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`)
31
+ new RegExp(`\\.(${constants.KNOWN_ASSET_TYPES.join("|")})$`)
62
32
  ];
63
33
  const depsExternal = [
64
34
  /\.cjs\.js$/,
@@ -95,7 +65,7 @@ async function shouldExternalize(id, options, cache = _defaultExternalizeCache)
95
65
  return cache.get(id);
96
66
  }
97
67
  async function _shouldExternalize(id, options) {
98
- if (mlly.isNodeBuiltin(id))
68
+ if (utils.isNodeBuiltin(id))
99
69
  return id;
100
70
  if (id.startsWith("data:"))
101
71
  return id;
@@ -222,7 +192,7 @@ class ViteNodeServer {
222
192
  var _a, _b, _c;
223
193
  const ssrOptions = server.config.ssr;
224
194
  options.deps ?? (options.deps = {});
225
- options.deps.cacheDir = pathe.relative(server.config.root, server.config.cacheDir);
195
+ options.deps.cacheDir = pathe.relative(server.config.root, options.deps.cacheDir || server.config.cacheDir);
226
196
  if (ssrOptions) {
227
197
  if (ssrOptions.noExternal === true) {
228
198
  (_a = options.deps).inline ?? (_a.inline = true);
@@ -244,6 +214,15 @@ class ViteNodeServer {
244
214
  const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
245
215
  if (customModuleDirectories)
246
216
  options.deps.moduleDirectories.push(...customModuleDirectories);
217
+ options.deps.moduleDirectories = options.deps.moduleDirectories.map((dir) => {
218
+ if (!dir.startsWith("/"))
219
+ dir = `/${dir}`;
220
+ if (!dir.endsWith("/"))
221
+ dir += "/";
222
+ return pathe.normalize(dir);
223
+ });
224
+ if (!options.deps.moduleDirectories.includes("/node_modules/"))
225
+ options.deps.moduleDirectories.push("/node_modules/");
247
226
  }
248
227
  fetchPromiseMap = /* @__PURE__ */ new Map();
249
228
  transformPromiseMap = /* @__PURE__ */ new Map();
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
2
  import { E as EncodedSourceMap } from './types.d-7442d07f.js';
3
- import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-516036fa.js';
3
+ import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-e8623e9c.js';
4
4
  import 'vite/types/hot';
5
5
 
6
6
  declare class Debugger {
package/dist/server.mjs CHANGED
@@ -1,46 +1,16 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { existsSync, promises } from 'node:fs';
3
- import { join, resolve, relative } from 'pathe';
3
+ import { join, resolve, relative, normalize } from 'pathe';
4
4
  import createDebug from 'debug';
5
- import { isNodeBuiltin, isValidNodeImport } from 'mlly';
6
- import { slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
5
+ import { isValidNodeImport } from 'mlly';
6
+ import { isNodeBuiltin, slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
7
+ import { KNOWN_ASSET_TYPES } from './constants.mjs';
7
8
  import c from 'picocolors';
8
9
  import { withInlineSourcemap } from './source-map.mjs';
9
10
  import 'node:url';
10
11
  import 'node:module';
11
12
  import 'node:path';
12
13
 
13
- const KNOWN_ASSET_TYPES = [
14
- // images
15
- "apng",
16
- "png",
17
- "jpe?g",
18
- "jfif",
19
- "pjpeg",
20
- "pjp",
21
- "gif",
22
- "svg",
23
- "ico",
24
- "webp",
25
- "avif",
26
- // media
27
- "mp4",
28
- "webm",
29
- "ogg",
30
- "mp3",
31
- "wav",
32
- "flac",
33
- "aac",
34
- // fonts
35
- "woff2?",
36
- "eot",
37
- "ttf",
38
- "otf",
39
- // other
40
- "webmanifest",
41
- "pdf",
42
- "txt"
43
- ];
44
14
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
45
15
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
46
16
  const defaultInline = [
@@ -213,7 +183,7 @@ class ViteNodeServer {
213
183
  var _a, _b, _c;
214
184
  const ssrOptions = server.config.ssr;
215
185
  options.deps ?? (options.deps = {});
216
- options.deps.cacheDir = relative(server.config.root, server.config.cacheDir);
186
+ options.deps.cacheDir = relative(server.config.root, options.deps.cacheDir || server.config.cacheDir);
217
187
  if (ssrOptions) {
218
188
  if (ssrOptions.noExternal === true) {
219
189
  (_a = options.deps).inline ?? (_a.inline = true);
@@ -235,6 +205,15 @@ class ViteNodeServer {
235
205
  const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
236
206
  if (customModuleDirectories)
237
207
  options.deps.moduleDirectories.push(...customModuleDirectories);
208
+ options.deps.moduleDirectories = options.deps.moduleDirectories.map((dir) => {
209
+ if (!dir.startsWith("/"))
210
+ dir = `/${dir}`;
211
+ if (!dir.endsWith("/"))
212
+ dir += "/";
213
+ return normalize(dir);
214
+ });
215
+ if (!options.deps.moduleDirectories.includes("/node_modules/"))
216
+ options.deps.moduleDirectories.push("/node_modules/");
238
217
  }
239
218
  fetchPromiseMap = /* @__PURE__ */ new Map();
240
219
  transformPromiseMap = /* @__PURE__ */ new Map();
@@ -1,7 +1,7 @@
1
1
  import { ViteHotContext } from 'vite/types/hot';
2
2
  import { E as EncodedSourceMap } from './types.d-7442d07f.js';
3
3
 
4
- declare const DEFAULT_REQUEST_STUBS: Record<string, unknown>;
4
+ declare const DEFAULT_REQUEST_STUBS: Record<string, Record<string, unknown>>;
5
5
  declare class ModuleCacheMap extends Map<string, ModuleCache> {
6
6
  normalizePath(fsPath: string): string;
7
7
  /**
@@ -49,12 +49,19 @@ declare class ViteNodeRunner {
49
49
  dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
50
50
  /** @internal */
51
51
  directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
52
+ protected getContextPrimitives(): {
53
+ Object: ObjectConstructor;
54
+ Reflect: typeof Reflect;
55
+ Symbol: SymbolConstructor;
56
+ };
57
+ protected runModule(context: Record<string, any>, transformed: string): Promise<void>;
52
58
  prepareContext(context: Record<string, any>): Record<string, any>;
53
59
  /**
54
60
  * Define if a module should be interop-ed
55
61
  * This function mostly for the ability to override by subclass
56
62
  */
57
63
  shouldInterop(path: string, mod: any): boolean;
64
+ protected importExternalModule(path: string): Promise<any>;
58
65
  /**
59
66
  * Import a module and interop it
60
67
  */
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import 'vite/types/hot';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
3
- export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-516036fa.js';
3
+ export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-e8623e9c.js';
package/dist/utils.cjs CHANGED
@@ -8,6 +8,10 @@ var fs = require('fs');
8
8
  var pathe = require('pathe');
9
9
 
10
10
  const isWindows = process.platform === "win32";
11
+ const drive = isWindows ? process.cwd()[0] : null;
12
+ const driveOpposite = drive ? drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase() : null;
13
+ const driveRegexp = drive ? new RegExp(`(?:^|/@fs/)${drive}(:[\\/])`) : null;
14
+ const driveOppositeRegext = driveOpposite ? new RegExp(`(?:^|/@fs/)${driveOpposite}(:[\\/])`) : null;
11
15
  function slash(str) {
12
16
  return str.replace(/\\/g, "/");
13
17
  }
@@ -15,6 +19,8 @@ const VALID_ID_PREFIX = "/@id/";
15
19
  function normalizeRequestId(id, base) {
16
20
  if (base && id.startsWith(base))
17
21
  id = `/${id.slice(base.length)}`;
22
+ if (driveRegexp && !(driveRegexp == null ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext == null ? void 0 : driveOppositeRegext.test(id)))
23
+ id = id.replace(driveOppositeRegext, `${drive}$1`);
18
24
  return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
19
25
  }
20
26
  const queryRE = /\?.*$/s;
@@ -30,7 +36,28 @@ const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
30
36
  function isInternalRequest(id) {
31
37
  return internalRequestRegexp.test(id);
32
38
  }
39
+ const prefixedBuiltins = /* @__PURE__ */ new Set([
40
+ "node:test"
41
+ ]);
42
+ const builtins = /* @__PURE__ */ new Set([
43
+ ...module$1.builtinModules,
44
+ "assert/strict",
45
+ "diagnostics_channel",
46
+ "dns/promises",
47
+ "fs/promises",
48
+ "path/posix",
49
+ "path/win32",
50
+ "readline/promises",
51
+ "stream/consumers",
52
+ "stream/promises",
53
+ "stream/web",
54
+ "timers/promises",
55
+ "util/types",
56
+ "wasi"
57
+ ]);
33
58
  function normalizeModuleId(id) {
59
+ if (prefixedBuiltins.has(id))
60
+ return id;
34
61
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
35
62
  }
36
63
  function isPrimitive(v) {
@@ -56,24 +83,10 @@ function toFilePath(id, root) {
56
83
  exists
57
84
  };
58
85
  }
59
- const builtins = /* @__PURE__ */ new Set([
60
- ...module$1.builtinModules,
61
- "assert/strict",
62
- "diagnostics_channel",
63
- "dns/promises",
64
- "fs/promises",
65
- "path/posix",
66
- "path/win32",
67
- "readline/promises",
68
- "stream/consumers",
69
- "stream/promises",
70
- "stream/web",
71
- "timers/promises",
72
- "util/types",
73
- "wasi"
74
- ]);
75
86
  const NODE_BUILTIN_NAMESPACE = "node:";
76
87
  function isNodeBuiltin(id) {
88
+ if (prefixedBuiltins.has(id))
89
+ return true;
77
90
  return builtins.has(
78
91
  id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(NODE_BUILTIN_NAMESPACE.length) : id
79
92
  );
@@ -85,9 +98,34 @@ function toArray(array) {
85
98
  return array;
86
99
  return [array];
87
100
  }
101
+ function getCachedData(cache, basedir, originalBasedir) {
102
+ const pkgData = cache.get(getFnpdCacheKey(basedir));
103
+ if (pkgData) {
104
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
105
+ cache.set(getFnpdCacheKey(dir), pkgData);
106
+ });
107
+ return pkgData;
108
+ }
109
+ }
110
+ function setCacheData(cache, data, basedir, originalBasedir) {
111
+ cache.set(getFnpdCacheKey(basedir), data);
112
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
113
+ cache.set(getFnpdCacheKey(dir), data);
114
+ });
115
+ }
116
+ function getFnpdCacheKey(basedir) {
117
+ return `fnpd_${basedir}`;
118
+ }
119
+ function traverseBetweenDirs(longerDir, shorterDir, cb) {
120
+ while (longerDir !== shorterDir) {
121
+ cb(longerDir);
122
+ longerDir = pathe.dirname(longerDir);
123
+ }
124
+ }
88
125
 
89
126
  exports.VALID_ID_PREFIX = VALID_ID_PREFIX;
90
127
  exports.cleanUrl = cleanUrl;
128
+ exports.getCachedData = getCachedData;
91
129
  exports.hashRE = hashRE;
92
130
  exports.isInternalRequest = isInternalRequest;
93
131
  exports.isNodeBuiltin = isNodeBuiltin;
@@ -96,6 +134,7 @@ exports.isWindows = isWindows;
96
134
  exports.normalizeModuleId = normalizeModuleId;
97
135
  exports.normalizeRequestId = normalizeRequestId;
98
136
  exports.queryRE = queryRE;
137
+ exports.setCacheData = setCacheData;
99
138
  exports.slash = slash;
100
139
  exports.toArray = toArray;
101
140
  exports.toFilePath = toFilePath;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './types-516036fa.js';
1
+ import { N as Nullable, A as Arrayable } from './types-e8623e9c.js';
2
2
  import 'vite/types/hot';
3
3
  import './types.d-7442d07f.js';
4
4
 
@@ -23,5 +23,7 @@ declare function isNodeBuiltin(id: string): boolean;
23
23
  * @category Array
24
24
  */
25
25
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
26
+ declare function getCachedData<T>(cache: Map<string, T>, basedir: string, originalBasedir: string): NonNullable<T> | undefined;
27
+ declare function setCacheData<T>(cache: Map<string, T>, data: T, basedir: string, originalBasedir: string): void;
26
28
 
27
- export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };
29
+ export { VALID_ID_PREFIX, cleanUrl, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };