vite-node 0.34.3 → 0.34.4

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/README.md CHANGED
@@ -40,7 +40,7 @@ npx vite-node -h
40
40
 
41
41
  ### Options via CLI
42
42
 
43
- [All `ViteNodeServer` options](https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/types.ts#L70-L89) are supported by the CLI. They may be defined through the dot syntax, as shown below:
43
+ [All `ViteNodeServer` options](https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/types.ts#L92-L111) are supported by the CLI. They may be defined through the dot syntax, as shown below:
44
44
 
45
45
  ```bash
46
46
  npx vite-node --options.deps.inline="module-name" --options.deps.external="/module-regexp/" index.ts
@@ -130,7 +130,7 @@ await server.close()
130
130
 
131
131
  Sometimes you might want to inspect the transformed code to investigate issues. You can set environment variable `VITE_NODE_DEBUG_DUMP=true` to let vite-node write the transformed result of each module under `.vite-node/dump`.
132
132
 
133
- If you want to debug by modifying the dumped code, you can change the value of `VITE_NODE_DEBUG_DUMP` to `load` and search for the dumpped files and use them for executing.
133
+ If you want to debug by modifying the dumped code, you can change the value of `VITE_NODE_DEBUG_DUMP` to `load` and search for the dumped files and use them for executing.
134
134
 
135
135
  ```bash
136
136
  VITE_NODE_DEBUG_DUMP=load vite-node example.ts
@@ -151,7 +151,7 @@ const server = new ViteNodeServer(viteServer, {
151
151
 
152
152
  ### Debug Execution
153
153
 
154
- If the process get stuck, it might because there is a unresolvable circular dependencies, you can set `VITE_NODE_DEBUG_RUNNER=true` to vite-node warn about it.
154
+ If the process gets stuck, it might be because there are unresolvable circular dependencies. You can set `VITE_NODE_DEBUG_RUNNER=true` for vite-node to warn about this.
155
155
 
156
156
  ```bash
157
157
  VITE_NODE_DEBUG_RUNNER=true vite-node example.ts
package/dist/cli.cjs CHANGED
@@ -6,8 +6,8 @@ var vite = require('vite');
6
6
  var server = require('./server.cjs');
7
7
  var client = require('./client.cjs');
8
8
  var utils = require('./utils.cjs');
9
- var sourceMap = require('./source-map.cjs');
10
9
  var hmr = require('./chunk-hmr.cjs');
10
+ var sourceMap = require('./source-map.cjs');
11
11
  require('perf_hooks');
12
12
  require('fs');
13
13
  require('pathe');
@@ -25,7 +25,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
25
25
  var cac__default = /*#__PURE__*/_interopDefaultLegacy(cac);
26
26
  var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
27
27
 
28
- var version = "0.34.3";
28
+ var version = "0.34.4";
29
29
 
30
30
  const cli = cac__default["default"]("vite-node");
31
31
  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,4 +1,4 @@
1
- import { f as ViteNodeServerOptions } from './types-2dc895bd.js';
1
+ import { f as ViteNodeServerOptions } from './types-0f31b933.js';
2
2
  import './types.d-7442d07f.js';
3
3
 
4
4
  interface CliOptions {
package/dist/cli.mjs CHANGED
@@ -18,7 +18,7 @@ import 'node:path';
18
18
  import 'node:vm';
19
19
  import 'node:events';
20
20
 
21
- var version = "0.34.3";
21
+ var version = "0.34.4";
22
22
 
23
23
  const cli = cac("vite-node");
24
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.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './types.d-7442d07f.js';
2
- export { k as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, i as ViteNodeRunner } from './types-2dc895bd.js';
2
+ export { k as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, i as ViteNodeRunner } from './types-0f31b933.js';
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { h as CustomEventMap, i as ViteNodeRunner, j as HMRPayload$1, H as HotContext } from './types-2dc895bd.js';
3
+ import { h as CustomEventMap, i as ViteNodeRunner, j as HMRPayload$1, H as HotContext } from './types-0f31b933.js';
4
4
  import './types.d-7442d07f.js';
5
5
 
6
6
  type EventType = string | symbol;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
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-2dc895bd.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-0f31b933.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
package/dist/server.cjs CHANGED
@@ -249,7 +249,7 @@ class ViteNodeServer {
249
249
  });
250
250
  }
251
251
  async resolveId(id, importer, transformMode) {
252
- if (importer && !importer.startsWith(this.server.config.root))
252
+ if (importer && !importer.startsWith(utils.withTrailingSlash(this.server.config.root)))
253
253
  importer = pathe.resolve(this.server.config.root, importer);
254
254
  const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
255
255
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
@@ -313,7 +313,7 @@ class ViteNodeServer {
313
313
  let result;
314
314
  const cacheDir = (_a = this.options.deps) == null ? void 0 : _a.cacheDir;
315
315
  if (cacheDir && id.includes(cacheDir)) {
316
- if (!id.startsWith(this.server.config.root))
316
+ if (!id.startsWith(utils.withTrailingSlash(this.server.config.root)))
317
317
  id = pathe.join(this.server.config.root, id);
318
318
  const timeout = setTimeout(() => {
319
319
  throw new Error(`ViteNodeServer: ${id} not found. This is a bug, please report it.`);
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-2dc895bd.js';
3
+ import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-0f31b933.js';
4
4
 
5
5
  declare class Debugger {
6
6
  options: DebuggerOptions;
package/dist/server.mjs CHANGED
@@ -3,7 +3,7 @@ import { existsSync, promises } from 'node:fs';
3
3
  import { join, resolve, relative, normalize } from 'pathe';
4
4
  import createDebug from 'debug';
5
5
  import { isValidNodeImport } from 'mlly';
6
- import { isNodeBuiltin, slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
6
+ import { isNodeBuiltin, slash, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
7
7
  import { KNOWN_ASSET_TYPES } from './constants.mjs';
8
8
  import c from 'picocolors';
9
9
  import { withInlineSourcemap } from './source-map.mjs';
@@ -240,7 +240,7 @@ class ViteNodeServer {
240
240
  });
241
241
  }
242
242
  async resolveId(id, importer, transformMode) {
243
- if (importer && !importer.startsWith(this.server.config.root))
243
+ if (importer && !importer.startsWith(withTrailingSlash(this.server.config.root)))
244
244
  importer = resolve(this.server.config.root, importer);
245
245
  const mode = transformMode ?? (importer && this.getTransformMode(importer) || "ssr");
246
246
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
@@ -304,7 +304,7 @@ class ViteNodeServer {
304
304
  let result;
305
305
  const cacheDir = (_a = this.options.deps) == null ? void 0 : _a.cacheDir;
306
306
  if (cacheDir && id.includes(cacheDir)) {
307
- if (!id.startsWith(this.server.config.root))
307
+ if (!id.startsWith(withTrailingSlash(this.server.config.root)))
308
308
  id = join(this.server.config.root, id);
309
309
  const timeout = setTimeout(() => {
310
310
  throw new Error(`ViteNodeServer: ${id} not found. This is a bug, please report it.`);
@@ -3,8 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var pathe = require('pathe');
6
+ var utils = require('./utils.cjs');
6
7
  var path = require('path');
7
8
  var fs = require('fs');
9
+ require('node:url');
10
+ require('module');
8
11
 
9
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
13
 
@@ -871,15 +874,17 @@ function withInlineSourcemap(result, options) {
871
874
  let code = result.code;
872
875
  if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE))
873
876
  return result;
874
- map.sources = (_a = map.sources) == null ? void 0 : _a.map((source) => {
875
- if (!source)
877
+ if ("sources" in map) {
878
+ map.sources = (_a = map.sources) == null ? void 0 : _a.map((source) => {
879
+ if (!source)
880
+ return source;
881
+ if (pathe.isAbsolute(source)) {
882
+ const actualPath = !source.startsWith(utils.withTrailingSlash(options.root)) && source.startsWith("/") ? pathe.resolve(options.root, source.slice(1)) : source;
883
+ return pathe.relative(pathe.dirname(options.filepath), actualPath);
884
+ }
876
885
  return source;
877
- if (pathe.isAbsolute(source)) {
878
- const actualPath = !source.startsWith(options.root) && source.startsWith("/") ? pathe.resolve(options.root, source.slice(1)) : source;
879
- return pathe.relative(pathe.dirname(options.filepath), actualPath);
880
- }
881
- return source;
882
- });
886
+ });
887
+ }
883
888
  const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
884
889
  while (OTHER_SOURCE_MAP_REGEXP.test(code))
885
890
  code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
@@ -1,6 +1,9 @@
1
1
  import { isAbsolute, resolve as resolve$2, relative, dirname } from 'pathe';
2
+ import { withTrailingSlash } from './utils.mjs';
2
3
  import path from 'node:path';
3
4
  import fs from 'node:fs';
5
+ import 'node:url';
6
+ import 'node:module';
4
7
 
5
8
  const comma = ','.charCodeAt(0);
6
9
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -862,15 +865,17 @@ function withInlineSourcemap(result, options) {
862
865
  let code = result.code;
863
866
  if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE))
864
867
  return result;
865
- map.sources = (_a = map.sources) == null ? void 0 : _a.map((source) => {
866
- if (!source)
868
+ if ("sources" in map) {
869
+ map.sources = (_a = map.sources) == null ? void 0 : _a.map((source) => {
870
+ if (!source)
871
+ return source;
872
+ if (isAbsolute(source)) {
873
+ const actualPath = !source.startsWith(withTrailingSlash(options.root)) && source.startsWith("/") ? resolve$2(options.root, source.slice(1)) : source;
874
+ return relative(dirname(options.filepath), actualPath);
875
+ }
867
876
  return source;
868
- if (isAbsolute(source)) {
869
- const actualPath = !source.startsWith(options.root) && source.startsWith("/") ? resolve$2(options.root, source.slice(1)) : source;
870
- return relative(dirname(options.filepath), actualPath);
871
- }
872
- return source;
873
- });
877
+ });
878
+ }
874
879
  const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
875
880
  while (OTHER_SOURCE_MAP_REGEXP.test(code))
876
881
  code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
@@ -69,6 +69,18 @@ interface CustomEventMap {
69
69
  'vite:beforeFullReload': FullReloadPayload
70
70
  'vite:error': ErrorPayload
71
71
  'vite:invalidate': InvalidatePayload
72
+ 'vite:ws:connect': WebSocketConnectionPayload
73
+ 'vite:ws:disconnect': WebSocketConnectionPayload
74
+ }
75
+
76
+ interface WebSocketConnectionPayload {
77
+ /**
78
+ * @experimental
79
+ * We expose this instance experimentally to see potential usage.
80
+ * This might be removed in the future if we didn't find reasonable use cases.
81
+ * If you find this useful, please open an issue with details so we can discuss and make it stable API.
82
+ */
83
+ webSocket: WebSocket
72
84
  }
73
85
 
74
86
  interface InvalidatePayload {
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
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-2dc895bd.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-0f31b933.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
package/dist/utils.cjs CHANGED
@@ -17,7 +17,7 @@ function slash(str) {
17
17
  }
18
18
  const VALID_ID_PREFIX = "/@id/";
19
19
  function normalizeRequestId(id, base) {
20
- if (base && id.startsWith(base))
20
+ if (base && id.startsWith(withTrailingSlash(base)))
21
21
  id = `/${id.slice(base.length)}`;
22
22
  if (driveRegexp && !(driveRegexp == null ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext == null ? void 0 : driveOppositeRegext.test(id)))
23
23
  id = id.replace(driveOppositeRegext, `${drive}$1`);
@@ -67,11 +67,11 @@ function toFilePath(id, root) {
67
67
  let { absolute, exists } = (() => {
68
68
  if (id.startsWith("/@fs/"))
69
69
  return { absolute: id.slice(4), exists: true };
70
- if (!id.startsWith(root) && id.startsWith("/")) {
70
+ if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
71
71
  const resolved = pathe.resolve(root, id.slice(1));
72
72
  if (fs.existsSync(cleanUrl(resolved)))
73
73
  return { absolute: resolved, exists: true };
74
- } else if (id.startsWith(root) && fs.existsSync(cleanUrl(id))) {
74
+ } else if (id.startsWith(withTrailingSlash(root)) && fs.existsSync(cleanUrl(id))) {
75
75
  return { absolute: id, exists: true };
76
76
  }
77
77
  return { absolute: id, exists: false };
@@ -122,6 +122,11 @@ function traverseBetweenDirs(longerDir, shorterDir, cb) {
122
122
  longerDir = pathe.dirname(longerDir);
123
123
  }
124
124
  }
125
+ function withTrailingSlash(path) {
126
+ if (path[path.length - 1] !== "/")
127
+ return `${path}/`;
128
+ return path;
129
+ }
125
130
  function createImportMetaEnvProxy() {
126
131
  const booleanKeys = [
127
132
  "DEV",
@@ -164,3 +169,4 @@ exports.setCacheData = setCacheData;
164
169
  exports.slash = slash;
165
170
  exports.toArray = toArray;
166
171
  exports.toFilePath = toFilePath;
172
+ exports.withTrailingSlash = withTrailingSlash;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './types-2dc895bd.js';
1
+ import { N as Nullable, A as Arrayable } from './types-0f31b933.js';
2
2
  import './types.d-7442d07f.js';
3
3
 
4
4
  declare const isWindows: boolean;
@@ -24,6 +24,7 @@ declare function isNodeBuiltin(id: string): boolean;
24
24
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
25
25
  declare function getCachedData<T>(cache: Map<string, T>, basedir: string, originalBasedir: string): NonNullable<T> | undefined;
26
26
  declare function setCacheData<T>(cache: Map<string, T>, data: T, basedir: string, originalBasedir: string): void;
27
+ declare function withTrailingSlash(path: string): string;
27
28
  declare function createImportMetaEnvProxy(): NodeJS.ProcessEnv;
28
29
 
29
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
30
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/dist/utils.mjs CHANGED
@@ -13,7 +13,7 @@ function slash(str) {
13
13
  }
14
14
  const VALID_ID_PREFIX = "/@id/";
15
15
  function normalizeRequestId(id, base) {
16
- if (base && id.startsWith(base))
16
+ if (base && id.startsWith(withTrailingSlash(base)))
17
17
  id = `/${id.slice(base.length)}`;
18
18
  if (driveRegexp && !(driveRegexp == null ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext == null ? void 0 : driveOppositeRegext.test(id)))
19
19
  id = id.replace(driveOppositeRegext, `${drive}$1`);
@@ -63,11 +63,11 @@ function toFilePath(id, root) {
63
63
  let { absolute, exists } = (() => {
64
64
  if (id.startsWith("/@fs/"))
65
65
  return { absolute: id.slice(4), exists: true };
66
- if (!id.startsWith(root) && id.startsWith("/")) {
66
+ if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
67
67
  const resolved = resolve(root, id.slice(1));
68
68
  if (existsSync(cleanUrl(resolved)))
69
69
  return { absolute: resolved, exists: true };
70
- } else if (id.startsWith(root) && existsSync(cleanUrl(id))) {
70
+ } else if (id.startsWith(withTrailingSlash(root)) && existsSync(cleanUrl(id))) {
71
71
  return { absolute: id, exists: true };
72
72
  }
73
73
  return { absolute: id, exists: false };
@@ -118,6 +118,11 @@ function traverseBetweenDirs(longerDir, shorterDir, cb) {
118
118
  longerDir = dirname(longerDir);
119
119
  }
120
120
  }
121
+ function withTrailingSlash(path) {
122
+ if (path[path.length - 1] !== "/")
123
+ return `${path}/`;
124
+ return path;
125
+ }
121
126
  function createImportMetaEnvProxy() {
122
127
  const booleanKeys = [
123
128
  "DEV",
@@ -144,4 +149,4 @@ function createImportMetaEnvProxy() {
144
149
  });
145
150
  }
146
151
 
147
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
152
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.34.3",
3
+ "version": "0.34.4",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",