vite-node 1.0.0-beta.4 → 1.0.0-beta.6

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
@@ -13,7 +13,6 @@ require('node:fs');
13
13
  require('node:assert');
14
14
  require('pathe');
15
15
  require('debug');
16
- require('mlly');
17
16
  require('./constants.cjs');
18
17
  require('node:module');
19
18
  require('node:path');
@@ -21,7 +20,7 @@ require('node:url');
21
20
  require('node:vm');
22
21
  require('node:events');
23
22
 
24
- var version = "1.0.0-beta.4";
23
+ var version = "1.0.0-beta.6";
25
24
 
26
25
  const cli = cac("vite-node");
27
26
  cli.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").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { V as ViteNodeServerOptions } from './index-ba8284b7.js';
2
- import './trace-mapping.d-cf594fd7.js';
1
+ import { V as ViteNodeServerOptions } from './index-IeUJleJC.js';
2
+ import './trace-mapping.d-aA9jxPtH.js';
3
3
 
4
4
  interface CliOptions {
5
5
  root?: string;
package/dist/cli.mjs CHANGED
@@ -11,7 +11,6 @@ import 'node:fs';
11
11
  import 'node:assert';
12
12
  import 'pathe';
13
13
  import 'debug';
14
- import 'mlly';
15
14
  import './constants.mjs';
16
15
  import 'node:module';
17
16
  import 'node:path';
@@ -19,7 +18,7 @@ import 'node:url';
19
18
  import 'node:vm';
20
19
  import 'node:events';
21
20
 
22
- var version = "1.0.0-beta.4";
21
+ var version = "1.0.0-beta.6";
23
22
 
24
23
  const cli = cac("vite-node");
25
24
  cli.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").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
package/dist/client.cjs CHANGED
@@ -199,8 +199,7 @@ ${getStack()}`), 2e3);
199
199
  return !utils.isInternalRequest(id) && !utils.isNodeBuiltin(id) && !id.startsWith("data:");
200
200
  }
201
201
  async _resolveUrl(id, importer) {
202
- if (importer && id.startsWith(utils.VALID_ID_PREFIX))
203
- importer = void 0;
202
+ var _a, _b;
204
203
  const dep = utils.normalizeRequestId(id, this.options.base);
205
204
  if (!this.shouldResolveId(dep))
206
205
  return [dep, dep];
@@ -208,6 +207,17 @@ ${getStack()}`), 2e3);
208
207
  if (!this.options.resolveId || exists)
209
208
  return [dep, path];
210
209
  const resolved = await this.options.resolveId(dep, importer);
210
+ if ((_b = (_a = resolved == null ? void 0 : resolved.meta) == null ? void 0 : _a["vite:alias"]) == null ? void 0 : _b.noResolved) {
211
+ const error = new Error(
212
+ `Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
213
+
214
+ - If you rely on tsconfig.json's "paths" to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
215
+ - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`
216
+ );
217
+ Object.defineProperty(error, "code", { value: "ERR_MODULE_NOT_FOUND", enumerable: true });
218
+ Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), { value: { id: dep, importer }, enumerable: false });
219
+ throw error;
220
+ }
211
221
  const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : dep;
212
222
  return [resolvedId, resolvedId];
213
223
  }
package/dist/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-ba8284b7.js';
2
- import './trace-mapping.d-cf594fd7.js';
1
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-IeUJleJC.js';
2
+ import './trace-mapping.d-aA9jxPtH.js';
package/dist/client.mjs CHANGED
@@ -4,7 +4,7 @@ import { pathToFileURL, fileURLToPath } from 'node:url';
4
4
  import vm from 'node:vm';
5
5
  import { resolve } from 'pathe';
6
6
  import createDebug from 'debug';
7
- import { createImportMetaEnvProxy, normalizeModuleId, slash, isInternalRequest, isNodeBuiltin, VALID_ID_PREFIX, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
7
+ import { createImportMetaEnvProxy, normalizeModuleId, slash, isInternalRequest, isNodeBuiltin, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
8
8
  import { extractSourceMap } from './source-map.mjs';
9
9
  import 'node:fs';
10
10
 
@@ -197,8 +197,7 @@ ${getStack()}`), 2e3);
197
197
  return !isInternalRequest(id) && !isNodeBuiltin(id) && !id.startsWith("data:");
198
198
  }
199
199
  async _resolveUrl(id, importer) {
200
- if (importer && id.startsWith(VALID_ID_PREFIX))
201
- importer = void 0;
200
+ var _a, _b;
202
201
  const dep = normalizeRequestId(id, this.options.base);
203
202
  if (!this.shouldResolveId(dep))
204
203
  return [dep, dep];
@@ -206,6 +205,17 @@ ${getStack()}`), 2e3);
206
205
  if (!this.options.resolveId || exists)
207
206
  return [dep, path];
208
207
  const resolved = await this.options.resolveId(dep, importer);
208
+ if ((_b = (_a = resolved == null ? void 0 : resolved.meta) == null ? void 0 : _a["vite:alias"]) == null ? void 0 : _b.noResolved) {
209
+ const error = new Error(
210
+ `Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
211
+
212
+ - If you rely on tsconfig.json's "paths" to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
213
+ - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`
214
+ );
215
+ Object.defineProperty(error, "code", { value: "ERR_MODULE_NOT_FOUND", enumerable: true });
216
+ Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), { value: { id: dep, importer }, enumerable: false });
217
+ throw error;
218
+ }
209
219
  const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : dep;
210
220
  return [resolvedId, resolvedId];
211
221
  }
package/dist/hmr.cjs CHANGED
@@ -232,8 +232,6 @@ function createHotContext(runner, emitter, files, ownerPath) {
232
232
  addToMap(maps.customListenersMap);
233
233
  addToMap(newListeners);
234
234
  },
235
- // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
236
- // @ts-ignore added in vite 5
237
235
  off(event, cb) {
238
236
  const removeFromMap = (map) => {
239
237
  const existing = map.get(event);
package/dist/hmr.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-ba8284b7.js';
4
- import './trace-mapping.d-cf594fd7.js';
3
+ import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-IeUJleJC.js';
4
+ import './trace-mapping.d-aA9jxPtH.js';
5
5
 
6
6
  type EventType = string | symbol;
7
7
  type Handler<T = unknown> = (event: T) => void;
package/dist/hmr.mjs CHANGED
@@ -230,8 +230,6 @@ function createHotContext(runner, emitter, files, ownerPath) {
230
230
  addToMap(maps.customListenersMap);
231
231
  addToMap(newListeners);
232
232
  },
233
- // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
234
- // @ts-ignore added in vite 5
235
233
  off(event, cb) {
236
234
  const removeFromMap = (map) => {
237
235
  const existing = map.get(event);
@@ -1,4 +1,4 @@
1
- import { E as EncodedSourceMap } from './trace-mapping.d-cf594fd7.js';
1
+ import { E as EncodedSourceMap } from './trace-mapping.d-aA9jxPtH.js';
2
2
 
3
3
  type HMRPayload =
4
4
  | ConnectedPayload
@@ -119,6 +119,10 @@ interface ViteHotContext {
119
119
  event: T,
120
120
  cb: (payload: InferCustomEventPayload<T>) => void,
121
121
  ): void
122
+ off<T extends string>(
123
+ event: T,
124
+ cb: (payload: InferCustomEventPayload<T>) => void,
125
+ ): void
122
126
  send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
123
127
  }
124
128
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-ba8284b7.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-cf594fd7.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-IeUJleJC.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-aA9jxPtH.js';
package/dist/server.cjs CHANGED
@@ -5,7 +5,6 @@ var fs = require('node:fs');
5
5
  var assert = require('node:assert');
6
6
  var pathe = require('pathe');
7
7
  var createDebug = require('debug');
8
- var mlly = require('mlly');
9
8
  var utils = require('./utils.cjs');
10
9
  var constants = require('./constants.cjs');
11
10
  var c = require('picocolors');
@@ -14,6 +13,8 @@ require('node:url');
14
13
  require('node:module');
15
14
  require('node:path');
16
15
 
16
+ const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
17
+ const ESM_SYNTAX_RE = /([\s;]|^)(import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
17
18
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
18
19
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
19
20
  const defaultInline = [
@@ -52,6 +53,21 @@ function guessCJSversion(id) {
52
53
  }
53
54
  }
54
55
  }
56
+ async function isValidNodeImport(id) {
57
+ const extension = pathe.extname(id);
58
+ if (BUILTIN_EXTENSIONS.has(extension))
59
+ return true;
60
+ if (extension !== ".js")
61
+ return false;
62
+ if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
63
+ return false;
64
+ id = id.replace("file:///", "");
65
+ const package_ = await utils.findNearestPackageData(pathe.dirname(id));
66
+ if (package_.type === "module")
67
+ return true;
68
+ const code = await fs.promises.readFile(id, "utf8").catch(() => "");
69
+ return !ESM_SYNTAX_RE.test(code);
70
+ }
55
71
  const _defaultExternalizeCache = /* @__PURE__ */ new Map();
56
72
  async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
57
73
  if (!cache.has(id))
@@ -78,7 +94,7 @@ async function _shouldExternalize(id, options) {
78
94
  return false;
79
95
  if (matchExternalizePattern(id, moduleDirectories, depsExternal))
80
96
  return id;
81
- if (isLibraryModule && await mlly.isValidNodeImport(id))
97
+ if (isLibraryModule && await isValidNodeImport(id))
82
98
  return id;
83
99
  return false;
84
100
  }
@@ -275,14 +291,11 @@ class ViteNodeServer {
275
291
  this.assertMode(mode);
276
292
  const promiseMap = this.fetchPromiseMap[mode];
277
293
  if (!promiseMap.has(moduleId)) {
278
- promiseMap.set(
279
- moduleId,
280
- this._fetchModule(moduleId, mode).then((r) => {
281
- return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
282
- }).finally(() => {
283
- promiseMap.delete(moduleId);
284
- })
285
- );
294
+ promiseMap.set(moduleId, this._fetchModule(moduleId, mode).then((r) => {
295
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
296
+ }).finally(() => {
297
+ promiseMap.delete(moduleId);
298
+ }));
286
299
  }
287
300
  return promiseMap.get(moduleId);
288
301
  }
@@ -291,12 +304,9 @@ class ViteNodeServer {
291
304
  this.assertMode(mode);
292
305
  const promiseMap = this.transformPromiseMap[mode];
293
306
  if (!promiseMap.has(id)) {
294
- promiseMap.set(
295
- id,
296
- this._transformRequest(id, filepath, mode).finally(() => {
297
- promiseMap.delete(id);
298
- })
299
- );
307
+ promiseMap.set(id, this._transformRequest(id, filepath, mode).finally(() => {
308
+ promiseMap.delete(id);
309
+ }));
300
310
  }
301
311
  return promiseMap.get(id);
302
312
  }
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-ba8284b7.js';
3
- import { E as EncodedSourceMap } from './trace-mapping.d-cf594fd7.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-IeUJleJC.js';
3
+ import { E as EncodedSourceMap } from './trace-mapping.d-aA9jxPtH.js';
4
4
 
5
5
  declare class Debugger {
6
6
  options: DebuggerOptions;
package/dist/server.mjs CHANGED
@@ -1,10 +1,9 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { existsSync, promises } from 'node:fs';
3
3
  import assert from 'node:assert';
4
- import { join, resolve, relative, normalize } from 'pathe';
4
+ import { join, extname, dirname, resolve, relative, normalize } from 'pathe';
5
5
  import createDebug from 'debug';
6
- import { isValidNodeImport } from 'mlly';
7
- import { isNodeBuiltin, slash, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
6
+ import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
8
7
  import { KNOWN_ASSET_TYPES } from './constants.mjs';
9
8
  import c from 'picocolors';
10
9
  import { withInlineSourcemap } from './source-map.mjs';
@@ -12,6 +11,8 @@ import 'node:url';
12
11
  import 'node:module';
13
12
  import 'node:path';
14
13
 
14
+ const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
15
+ const ESM_SYNTAX_RE = /([\s;]|^)(import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
15
16
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
16
17
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
17
18
  const defaultInline = [
@@ -50,6 +51,21 @@ function guessCJSversion(id) {
50
51
  }
51
52
  }
52
53
  }
54
+ async function isValidNodeImport(id) {
55
+ const extension = extname(id);
56
+ if (BUILTIN_EXTENSIONS.has(extension))
57
+ return true;
58
+ if (extension !== ".js")
59
+ return false;
60
+ if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
61
+ return false;
62
+ id = id.replace("file:///", "");
63
+ const package_ = await findNearestPackageData(dirname(id));
64
+ if (package_.type === "module")
65
+ return true;
66
+ const code = await promises.readFile(id, "utf8").catch(() => "");
67
+ return !ESM_SYNTAX_RE.test(code);
68
+ }
53
69
  const _defaultExternalizeCache = /* @__PURE__ */ new Map();
54
70
  async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
55
71
  if (!cache.has(id))
@@ -273,14 +289,11 @@ class ViteNodeServer {
273
289
  this.assertMode(mode);
274
290
  const promiseMap = this.fetchPromiseMap[mode];
275
291
  if (!promiseMap.has(moduleId)) {
276
- promiseMap.set(
277
- moduleId,
278
- this._fetchModule(moduleId, mode).then((r) => {
279
- return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
280
- }).finally(() => {
281
- promiseMap.delete(moduleId);
282
- })
283
- );
292
+ promiseMap.set(moduleId, this._fetchModule(moduleId, mode).then((r) => {
293
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
294
+ }).finally(() => {
295
+ promiseMap.delete(moduleId);
296
+ }));
284
297
  }
285
298
  return promiseMap.get(moduleId);
286
299
  }
@@ -289,12 +302,9 @@ class ViteNodeServer {
289
302
  this.assertMode(mode);
290
303
  const promiseMap = this.transformPromiseMap[mode];
291
304
  if (!promiseMap.has(id)) {
292
- promiseMap.set(
293
- id,
294
- this._transformRequest(id, filepath, mode).finally(() => {
295
- promiseMap.delete(id);
296
- })
297
- );
305
+ promiseMap.set(id, this._transformRequest(id, filepath, mode).finally(() => {
306
+ promiseMap.delete(id);
307
+ }));
298
308
  }
299
309
  return promiseMap.get(id);
300
310
  }
@@ -498,7 +498,7 @@ class TraceMap {
498
498
  const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
499
499
  this.version = version;
500
500
  this.file = file;
501
- this.names = names;
501
+ this.names = names || [];
502
502
  this.sourceRoot = sourceRoot;
503
503
  this.sources = sources;
504
504
  this.sourcesContent = sourcesContent;
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { E as EncodedSourceMap } from './trace-mapping.d-cf594fd7.js';
2
+ import { E as EncodedSourceMap } from './trace-mapping.d-aA9jxPtH.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => EncodedSourceMap | null | undefined;
@@ -496,7 +496,7 @@ class TraceMap {
496
496
  const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
497
497
  this.version = version;
498
498
  this.file = file;
499
- this.names = names;
499
+ this.names = names || [];
500
500
  this.sourceRoot = sourceRoot;
501
501
  this.sources = sources;
502
502
  this.sourcesContent = sourcesContent;
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-ba8284b7.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-cf594fd7.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-IeUJleJC.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-aA9jxPtH.js';
package/dist/utils.cjs CHANGED
@@ -150,10 +150,34 @@ function createImportMetaEnvProxy() {
150
150
  }
151
151
  });
152
152
  }
153
+ const packageCache = /* @__PURE__ */ new Map();
154
+ async function findNearestPackageData(basedir) {
155
+ var _a;
156
+ const originalBasedir = basedir;
157
+ while (basedir) {
158
+ const cached = getCachedData(packageCache, basedir, originalBasedir);
159
+ if (cached)
160
+ return cached;
161
+ const pkgPath = pathe.join(basedir, "package.json");
162
+ if ((_a = await fs.promises.stat(pkgPath).catch(() => {
163
+ })) == null ? void 0 : _a.isFile()) {
164
+ const pkgData = JSON.parse(await fs.promises.readFile(pkgPath, "utf8"));
165
+ if (packageCache)
166
+ setCacheData(packageCache, pkgData, basedir, originalBasedir);
167
+ return pkgData;
168
+ }
169
+ const nextBasedir = pathe.dirname(basedir);
170
+ if (nextBasedir === basedir)
171
+ break;
172
+ basedir = nextBasedir;
173
+ }
174
+ return {};
175
+ }
153
176
 
154
177
  exports.VALID_ID_PREFIX = VALID_ID_PREFIX;
155
178
  exports.cleanUrl = cleanUrl;
156
179
  exports.createImportMetaEnvProxy = createImportMetaEnvProxy;
180
+ exports.findNearestPackageData = findNearestPackageData;
157
181
  exports.getCachedData = getCachedData;
158
182
  exports.hashRE = hashRE;
159
183
  exports.isInternalRequest = isInternalRequest;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { N as Nullable, A as Arrayable } from './index-ba8284b7.js';
2
- import './trace-mapping.d-cf594fd7.js';
1
+ import { N as Nullable, A as Arrayable } from './index-IeUJleJC.js';
2
+ import './trace-mapping.d-aA9jxPtH.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
@@ -26,5 +26,8 @@ declare function getCachedData<T>(cache: Map<string, T>, basedir: string, origin
26
26
  declare function setCacheData<T>(cache: Map<string, T>, data: T, basedir: string, originalBasedir: string): void;
27
27
  declare function withTrailingSlash(path: string): string;
28
28
  declare function createImportMetaEnvProxy(): NodeJS.ProcessEnv;
29
+ declare function findNearestPackageData(basedir: string): Promise<{
30
+ type?: 'module' | 'commonjs';
31
+ }>;
29
32
 
30
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
33
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/dist/utils.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath, pathToFileURL } from 'node:url';
2
2
  import { builtinModules } from 'node:module';
3
- import { existsSync } from 'node:fs';
4
- import { resolve, dirname } from 'pathe';
3
+ import { existsSync, promises } from 'node:fs';
4
+ import { resolve, dirname, join } from 'pathe';
5
5
 
6
6
  const isWindows = process.platform === "win32";
7
7
  const drive = isWindows ? process.cwd()[0] : null;
@@ -148,5 +148,28 @@ function createImportMetaEnvProxy() {
148
148
  }
149
149
  });
150
150
  }
151
+ const packageCache = /* @__PURE__ */ new Map();
152
+ async function findNearestPackageData(basedir) {
153
+ var _a;
154
+ const originalBasedir = basedir;
155
+ while (basedir) {
156
+ const cached = getCachedData(packageCache, basedir, originalBasedir);
157
+ if (cached)
158
+ return cached;
159
+ const pkgPath = join(basedir, "package.json");
160
+ if ((_a = await promises.stat(pkgPath).catch(() => {
161
+ })) == null ? void 0 : _a.isFile()) {
162
+ const pkgData = JSON.parse(await promises.readFile(pkgPath, "utf8"));
163
+ if (packageCache)
164
+ setCacheData(packageCache, pkgData, basedir, originalBasedir);
165
+ return pkgData;
166
+ }
167
+ const nextBasedir = dirname(basedir);
168
+ if (nextBasedir === basedir)
169
+ break;
170
+ basedir = nextBasedir;
171
+ }
172
+ return {};
173
+ }
151
174
 
152
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
175
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.4",
4
+ "version": "1.0.0-beta.6",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -19,38 +19,38 @@
19
19
  "exports": {
20
20
  ".": {
21
21
  "types": "./dist/index.d.ts",
22
- "require": "./dist/index.cjs",
23
- "import": "./dist/index.mjs"
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.cjs"
24
24
  },
25
25
  "./client": {
26
26
  "types": "./dist/client.d.ts",
27
- "require": "./dist/client.cjs",
28
- "import": "./dist/client.mjs"
27
+ "import": "./dist/client.mjs",
28
+ "require": "./dist/client.cjs"
29
29
  },
30
30
  "./server": {
31
31
  "types": "./dist/server.d.ts",
32
- "require": "./dist/server.cjs",
33
- "import": "./dist/server.mjs"
32
+ "import": "./dist/server.mjs",
33
+ "require": "./dist/server.cjs"
34
34
  },
35
35
  "./utils": {
36
36
  "types": "./dist/utils.d.ts",
37
- "require": "./dist/utils.cjs",
38
- "import": "./dist/utils.mjs"
37
+ "import": "./dist/utils.mjs",
38
+ "require": "./dist/utils.cjs"
39
39
  },
40
40
  "./hmr": {
41
41
  "types": "./dist/hmr.d.ts",
42
- "require": "./dist/hmr.cjs",
43
- "import": "./dist/hmr.mjs"
42
+ "import": "./dist/hmr.mjs",
43
+ "require": "./dist/hmr.cjs"
44
44
  },
45
45
  "./source-map": {
46
46
  "types": "./dist/source-map.d.ts",
47
- "require": "./dist/source-map.cjs",
48
- "import": "./dist/source-map.mjs"
47
+ "import": "./dist/source-map.mjs",
48
+ "require": "./dist/source-map.cjs"
49
49
  },
50
50
  "./constants": {
51
51
  "types": "./dist/constants.d.ts",
52
- "require": "./dist/constants.cjs",
53
- "import": "./dist/constants.mjs"
52
+ "import": "./dist/constants.mjs",
53
+ "require": "./dist/constants.cjs"
54
54
  },
55
55
  "./*": "./*"
56
56
  },
@@ -69,9 +69,9 @@
69
69
  "vite-node": "./vite-node.mjs"
70
70
  },
71
71
  "files": [
72
- "dist",
73
72
  "*.d.ts",
74
- "*.mjs"
73
+ "*.mjs",
74
+ "dist"
75
75
  ],
76
76
  "engines": {
77
77
  "node": "^18.0.0 || >=20.0.0"
@@ -79,14 +79,13 @@
79
79
  "dependencies": {
80
80
  "cac": "^6.7.14",
81
81
  "debug": "^4.3.4",
82
- "mlly": "^1.4.0",
83
82
  "pathe": "^1.1.1",
84
83
  "picocolors": "^1.0.0",
85
- "vite": "^3.0.0 || ^4.0.0 || ^5.0.0-0"
84
+ "vite": "^5.0.0-beta.15 || ^5.0.0"
86
85
  },
87
86
  "devDependencies": {
88
- "@jridgewell/trace-mapping": "^0.3.18",
89
- "@types/debug": "^4.1.8"
87
+ "@jridgewell/trace-mapping": "^0.3.20",
88
+ "@types/debug": "^4.1.12"
90
89
  },
91
90
  "scripts": {
92
91
  "build": "rimraf dist && rollup -c",