vite-node 4.0.0-beta.8 → 5.0.0-beta.2

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/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-BWFx6tPc.js';
2
- export { A as Arrayable, h as Awaitable, k as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, i as FetchFunction, F as FetchResult, b as HotContext, l as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, j as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, n as ViteNodeResolveModule, m as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-CvIJUDRh.js';
2
+ export { A as Arrayable, h as Awaitable, k as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, i as FetchFunction, F as FetchResult, b as HotContext, l as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, j as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, n as ViteNodeResolveModule, m as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-D6Pqey3g.js';
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './index.d-CvIJUDRh.js';
1
+ import { N as Nullable, A as Arrayable } from './index.d-D6Pqey3g.js';
2
2
  import './trace-mapping.d-BWFx6tPc.js';
3
3
 
4
4
  declare const isWindows: boolean;
@@ -1,10 +1,14 @@
1
1
  import { existsSync, promises } from 'node:fs';
2
2
  import { builtinModules } from 'node:module';
3
+ import process from 'node:process';
3
4
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
5
  import { resolve, join, dirname } from 'pathe';
5
6
 
6
7
  const isWindows = process.platform === "win32";
7
- const drive = isWindows ? process.cwd()[0] : null, driveOpposite = drive ? drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase() : null, driveRegexp = drive ? /* @__PURE__ */ new RegExp(`(?:^|/@fs/)${drive}(\:[\\/])`) : null, driveOppositeRegext = driveOpposite ? /* @__PURE__ */ new RegExp(`(?:^|/@fs/)${driveOpposite}(\:[\\/])`) : null;
8
+ const drive = isWindows ? process.cwd()[0] : null;
9
+ const driveOpposite = drive ? drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase() : null;
10
+ const driveRegexp = drive ? /* @__PURE__ */ new RegExp(`(?:^|/@fs/)${drive}(\:[\\/])`) : null;
11
+ const driveOppositeRegext = driveOpposite ? /* @__PURE__ */ new RegExp(`(?:^|/@fs/)${driveOpposite}(\:[\\/])`) : null;
8
12
  function slash(str) {
9
13
  return str.replace(/\\/g, "/");
10
14
  }
@@ -37,7 +41,7 @@ function splitFileAndPostfix(path) {
37
41
  postfix: path.slice(file.length)
38
42
  };
39
43
  }
40
- const internalRequests = ["@vite/client", "@vite/env"], internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${internalRequests.join("|")})$`);
44
+ const internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${["@vite/client", "@vite/env"].join("|")})$`);
41
45
  function isInternalRequest(id) {
42
46
  return internalRequestRegexp.test(id);
43
47
  }
@@ -47,7 +51,8 @@ const prefixedBuiltins = new Set([
47
51
  "node:sqlite",
48
52
  "node:test",
49
53
  "node:test/reporters"
50
- ]), builtins = new Set([
54
+ ]);
55
+ const builtins = new Set([
51
56
  ...builtinModules,
52
57
  "assert/strict",
53
58
  "diagnostics_channel",
@@ -64,7 +69,10 @@ const prefixedBuiltins = new Set([
64
69
  "wasi"
65
70
  ]);
66
71
  function normalizeModuleId(id) {
67
- return prefixedBuiltins.has(id) ? id : id.startsWith("file://") ? fileURLToPath(id) : id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
72
+ // unique id that is not available as "test"
73
+ if (prefixedBuiltins.has(id)) return id;
74
+ if (id.startsWith("file://")) return fileURLToPath(id);
75
+ return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
68
76
  }
69
77
  function isPrimitive(v) {
70
78
  return v !== Object(v);
@@ -100,7 +108,8 @@ function toFilePath(id, root) {
100
108
  }
101
109
  const NODE_BUILTIN_NAMESPACE = "node:";
102
110
  function isNodeBuiltin(id) {
103
- return prefixedBuiltins.has(id) ? true : builtins.has(id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(5) : id);
111
+ if (prefixedBuiltins.has(id)) return true;
112
+ return builtins.has(id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(5) : id);
104
113
  }
105
114
  /**
106
115
  * Convert `Arrayable<T>` to `Array<T>`
@@ -109,16 +118,21 @@ function isNodeBuiltin(id) {
109
118
  */
110
119
  function toArray(array) {
111
120
  if (array === null || array === void 0) array = [];
112
- return Array.isArray(array) ? array : [array];
121
+ if (Array.isArray(array)) return array;
122
+ return [array];
113
123
  }
114
124
  function getCachedData(cache, basedir, originalBasedir) {
115
125
  const pkgData = cache.get(getFnpdCacheKey(basedir));
116
- if (pkgData) return traverseBetweenDirs(originalBasedir, basedir, (dir) => {
117
- cache.set(getFnpdCacheKey(dir), pkgData);
118
- }), pkgData;
126
+ if (pkgData) {
127
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
128
+ cache.set(getFnpdCacheKey(dir), pkgData);
129
+ });
130
+ return pkgData;
131
+ }
119
132
  }
120
133
  function setCacheData(cache, data, basedir, originalBasedir) {
121
- cache.set(getFnpdCacheKey(basedir), data), traverseBetweenDirs(originalBasedir, basedir, (dir) => {
134
+ cache.set(getFnpdCacheKey(basedir), data);
135
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
122
136
  cache.set(getFnpdCacheKey(dir), data);
123
137
  });
124
138
  }
@@ -131,10 +145,14 @@ function getFnpdCacheKey(basedir) {
131
145
  * @param shorterDir Shorter dir path, e.g. `/User/foo`
132
146
  */
133
147
  function traverseBetweenDirs(longerDir, shorterDir, cb) {
134
- while (longerDir !== shorterDir) cb(longerDir), longerDir = dirname(longerDir);
148
+ while (longerDir !== shorterDir) {
149
+ cb(longerDir);
150
+ longerDir = dirname(longerDir);
151
+ }
135
152
  }
136
153
  function withTrailingSlash(path) {
137
- return path[path.length - 1] === "/" ? path : `${path}/`;
154
+ if (path[path.length - 1] !== "/") return `${path}/`;
155
+ return path;
138
156
  }
139
157
  function createImportMetaEnvProxy() {
140
158
  // packages/vitest/src/node/plugins/index.ts:146
@@ -145,7 +163,9 @@ function createImportMetaEnvProxy() {
145
163
  ];
146
164
  return new Proxy(process.env, {
147
165
  get(_, key) {
148
- return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
166
+ if (typeof key !== "string") return;
167
+ if (booleanKeys.includes(key)) return !!process.env[key];
168
+ return process.env[key];
149
169
  },
150
170
  set(_, key, value) {
151
171
  if (typeof key !== "string") return true;
package/package.json CHANGED
@@ -1,96 +1,77 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.8",
4
+ "version": "5.0.0-beta.2",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
8
- "funding": "https://opencollective.com/vitest",
9
- "homepage": "https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme",
8
+ "funding": "https://opencollective.com/antfu",
9
+ "homepage": "https://github.com/antfu-collective/vite-node#readme",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/vitest-dev/vitest.git",
13
- "directory": "packages/vite-node"
12
+ "url": "git+https://github.com/antfu-collective/vite-node.git"
14
13
  },
15
14
  "bugs": {
16
- "url": "https://github.com/vitest-dev/vitest/issues"
15
+ "url": "https://github.com/antfu-collective/vite-node/issues"
17
16
  },
18
17
  "sideEffects": false,
19
18
  "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "import": "./dist/index.mjs",
23
- "require": "./dist/index.cjs"
24
- },
25
- "./client": {
26
- "types": "./dist/client.d.ts",
27
- "import": "./dist/client.mjs",
28
- "require": "./dist/client.cjs"
29
- },
30
- "./server": {
31
- "types": "./dist/server.d.ts",
32
- "import": "./dist/server.mjs",
33
- "require": "./dist/server.cjs"
34
- },
35
- "./utils": {
36
- "types": "./dist/utils.d.ts",
37
- "import": "./dist/utils.mjs",
38
- "require": "./dist/utils.cjs"
39
- },
40
- "./hmr": {
41
- "types": "./dist/hmr.d.ts",
42
- "import": "./dist/hmr.mjs",
43
- "require": "./dist/hmr.cjs"
44
- },
45
- "./source-map": {
46
- "types": "./dist/source-map.d.ts",
47
- "import": "./dist/source-map.mjs",
48
- "require": "./dist/source-map.cjs"
49
- },
50
- "./constants": {
51
- "types": "./dist/constants.d.ts",
52
- "import": "./dist/constants.mjs",
53
- "require": "./dist/constants.cjs"
54
- },
19
+ ".": "./dist/index.js",
20
+ "./client": "./dist/client.js",
21
+ "./server": "./dist/server.js",
22
+ "./utils": "./dist/utils.js",
23
+ "./hmr": "./dist/hmr.js",
24
+ "./source-map": "./dist/source-map.js",
25
+ "./constants": "./dist/constants.js",
55
26
  "./*": "./*"
56
27
  },
57
- "main": "./dist/index.mjs",
58
- "module": "./dist/index.mjs",
28
+ "main": "./dist/index.js",
29
+ "module": "./dist/index.js",
59
30
  "types": "./dist/index.d.ts",
60
- "typesVersions": {
61
- "*": {
62
- "*": [
63
- "./dist/*",
64
- "./dist/index.d.ts"
65
- ]
66
- }
67
- },
68
31
  "bin": {
69
- "vite-node": "./vite-node.mjs"
32
+ "vite-node": "./vite-node.js"
70
33
  },
71
34
  "files": [
72
- "*.d.ts",
73
- "*.mjs",
74
- "dist"
35
+ "dist",
36
+ "vite-node.js"
75
37
  ],
76
38
  "engines": {
77
39
  "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
78
40
  },
79
41
  "dependencies": {
80
42
  "cac": "^6.7.14",
81
- "debug": "^4.4.1",
43
+ "debug": "^4.4.3",
82
44
  "es-module-lexer": "^1.7.0",
83
45
  "pathe": "^2.0.3",
84
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
46
+ "vite": "^7.2.0"
85
47
  },
86
48
  "devDependencies": {
87
- "@jridgewell/trace-mapping": "^0.3.29",
49
+ "@antfu/eslint-config": "^6.2.0",
50
+ "@jridgewell/trace-mapping": "^0.3.31",
51
+ "@rollup/plugin-commonjs": "^29.0.0",
52
+ "@rollup/plugin-json": "^6.1.0",
53
+ "@rollup/plugin-node-resolve": "^16.0.3",
88
54
  "@types/debug": "^4.1.12",
89
- "tinyrainbow": "^2.0.0"
55
+ "@types/node": "^24.10.0",
56
+ "bumpp": "^10.3.1",
57
+ "eslint": "^9.39.1",
58
+ "inquirer": "^12.10.0",
59
+ "rimraf": "^6.1.0",
60
+ "rollup": "^4.52.5",
61
+ "rollup-plugin-dts": "^6.2.3",
62
+ "tinyexec": "^1.0.2",
63
+ "tinyrainbow": "^3.0.3",
64
+ "typescript": "^5.9.3",
65
+ "unplugin-isolated-decl": "^0.15.3",
66
+ "unplugin-oxc": "^0.5.3",
67
+ "vitest": "^4.0.7"
90
68
  },
91
69
  "scripts": {
70
+ "lint": "eslint",
92
71
  "build": "rimraf dist && rollup -c",
93
72
  "dev": "rollup -c --watch --watch.include 'src/**' -m inline",
94
- "typecheck": "tsc --noEmit"
73
+ "typecheck": "tsc --noEmit",
74
+ "test": "vitest",
75
+ "release": "bumpp"
95
76
  }
96
77
  }
package/vite-node.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import('./dist/cli.js')
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- // src/index.ts
4
- var f = {
5
- reset: [0, 0],
6
- bold: [1, 22, "\x1B[22m\x1B[1m"],
7
- dim: [2, 22, "\x1B[22m\x1B[2m"],
8
- italic: [3, 23],
9
- underline: [4, 24],
10
- inverse: [7, 27],
11
- hidden: [8, 28],
12
- strikethrough: [9, 29],
13
- black: [30, 39],
14
- red: [31, 39],
15
- green: [32, 39],
16
- yellow: [33, 39],
17
- blue: [34, 39],
18
- magenta: [35, 39],
19
- cyan: [36, 39],
20
- white: [37, 39],
21
- gray: [90, 39],
22
- bgBlack: [40, 49],
23
- bgRed: [41, 49],
24
- bgGreen: [42, 49],
25
- bgYellow: [43, 49],
26
- bgBlue: [44, 49],
27
- bgMagenta: [45, 49],
28
- bgCyan: [46, 49],
29
- bgWhite: [47, 49],
30
- blackBright: [90, 39],
31
- redBright: [91, 39],
32
- greenBright: [92, 39],
33
- yellowBright: [93, 39],
34
- blueBright: [94, 39],
35
- magentaBright: [95, 39],
36
- cyanBright: [96, 39],
37
- whiteBright: [97, 39],
38
- bgBlackBright: [100, 49],
39
- bgRedBright: [101, 49],
40
- bgGreenBright: [102, 49],
41
- bgYellowBright: [103, 49],
42
- bgBlueBright: [104, 49],
43
- bgMagentaBright: [105, 49],
44
- bgCyanBright: [106, 49],
45
- bgWhiteBright: [107, 49]
46
- }, h = Object.entries(f);
47
- function a(n) {
48
- return String(n);
49
- }
50
- a.open = "";
51
- a.close = "";
52
- function C(n = false) {
53
- let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
54
- return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
55
- }
56
- function p(n = false) {
57
- let e = C(n), i = (r, t, c, o) => {
58
- let l = "", s = 0;
59
- do
60
- l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
61
- while (~o);
62
- return l + r.substring(s);
63
- }, g = (r, t, c = r) => {
64
- let o = (l) => {
65
- let s = String(l), b = s.indexOf(t, r.length);
66
- return ~b ? r + i(s, t, c, b) + t : r + s + t;
67
- };
68
- return o.open = r, o.close = t, o;
69
- }, u = {
70
- isColorSupported: e
71
- }, d = (r) => `\x1B[${r}m`;
72
- for (let [r, t] of h)
73
- u[r] = e ? g(
74
- d(t[0]),
75
- d(t[1]),
76
- t[2]
77
- ) : a;
78
- return u;
79
- }
80
-
81
- var s = p();
82
-
83
- exports.s = s;
@@ -1,221 +0,0 @@
1
- 'use strict';
2
-
3
- var node_events = require('node:events');
4
- var createDebug = require('debug');
5
- var browser = require('./chunk-browser.cjs');
6
- var utils = require('./utils.cjs');
7
-
8
- function createHmrEmitter() {
9
- const emitter = new node_events.EventEmitter();
10
- return emitter;
11
- }
12
- function viteNodeHmrPlugin() {
13
- const emitter = createHmrEmitter();
14
- return {
15
- name: "vite-node:hmr",
16
- config() {
17
- // chokidar fsevents is unstable on macos when emitting "ready" event
18
- if (process.platform === "darwin" && false);
19
- },
20
- configureServer(server) {
21
- const _send = server.ws.send;
22
- server.emitter = emitter, server.ws.send = function(payload) {
23
- _send(payload), emitter.emit("message", payload);
24
- };
25
- // eslint-disable-next-line ts/ban-ts-comment
26
- // @ts-ignore Vite 6 compat
27
- const environments = server.environments;
28
- if (environments) environments.ssr.hot.send = function(payload) {
29
- _send(payload), emitter.emit("message", payload);
30
- };
31
- }
32
- };
33
- }
34
-
35
- const debugHmr = createDebug("vite-node:hmr"), cache = /* @__PURE__ */ new WeakMap();
36
- function getCache(runner) {
37
- if (!cache.has(runner)) cache.set(runner, {
38
- hotModulesMap: /* @__PURE__ */ new Map(),
39
- dataMap: /* @__PURE__ */ new Map(),
40
- disposeMap: /* @__PURE__ */ new Map(),
41
- pruneMap: /* @__PURE__ */ new Map(),
42
- customListenersMap: /* @__PURE__ */ new Map(),
43
- ctxToListenersMap: /* @__PURE__ */ new Map(),
44
- messageBuffer: [],
45
- isFirstUpdate: false,
46
- pending: false,
47
- queued: []
48
- });
49
- return cache.get(runner);
50
- }
51
- function sendMessageBuffer(runner, emitter) {
52
- const maps = getCache(runner);
53
- maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg)), maps.messageBuffer.length = 0;
54
- }
55
- async function reload(runner, files) {
56
- return Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
57
- if (!fsPath.includes("node_modules")) runner.moduleCache.delete(fsPath);
58
- }), Promise.all(files.map((file) => runner.executeId(file)));
59
- }
60
- async function notifyListeners(runner, event, data) {
61
- const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
62
- if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
63
- }
64
- async function queueUpdate(runner, p) {
65
- const maps = getCache(runner);
66
- if (maps.queued.push(p), !maps.pending) {
67
- maps.pending = true, await Promise.resolve(), maps.pending = false;
68
- const loading = [...maps.queued];
69
- maps.queued = [], (await Promise.all(loading)).forEach((fn) => fn && fn());
70
- }
71
- }
72
- async function fetchUpdate(runner, { path, acceptedPath }) {
73
- path = utils.normalizeRequestId(path), acceptedPath = utils.normalizeRequestId(acceptedPath);
74
- const maps = getCache(runner), mod = maps.hotModulesMap.get(path);
75
- if (!mod)
76
- // In a code-splitting project,
77
- // it is common that the hot-updating module is not loaded yet.
78
- // https://github.com/vitejs/vite/issues/721
79
- return;
80
- const isSelfUpdate = path === acceptedPath;
81
- let fetchedModule;
82
- // determine the qualified callbacks before we re-import the modules
83
- const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
84
- if (isSelfUpdate || qualifiedCallbacks.length > 0) {
85
- const disposer = maps.disposeMap.get(acceptedPath);
86
- if (disposer) await disposer(maps.dataMap.get(acceptedPath));
87
- try {
88
- [fetchedModule] = await reload(runner, [acceptedPath]);
89
- } catch (e) {
90
- warnFailedFetch(e, acceptedPath);
91
- }
92
- }
93
- return () => {
94
- for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
95
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
96
- console.log(`${browser.s.cyan("[vite-node]")} hot updated: ${loggedPath}`);
97
- };
98
- }
99
- function warnFailedFetch(err, path) {
100
- if (!(err instanceof Error) || !err.message.match("fetch")) console.error(err);
101
- console.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
102
- }
103
- async function handleMessage(runner, emitter, files, payload) {
104
- const maps = getCache(runner);
105
- switch (payload.type) {
106
- case "connected":
107
- sendMessageBuffer(runner, emitter);
108
- break;
109
- case "update":
110
- await notifyListeners(runner, "vite:beforeUpdate", payload), await Promise.all(payload.updates.map((update) => {
111
- return update.type === "js-update" ? queueUpdate(runner, fetchUpdate(runner, update)) : (console.error(`${browser.s.cyan("[vite-node]")} no support css hmr.}`), null);
112
- })), await notifyListeners(runner, "vite:afterUpdate", payload);
113
- break;
114
- case "full-reload":
115
- await notifyListeners(runner, "vite:beforeFullReload", payload), maps.customListenersMap.delete("vite:beforeFullReload"), await reload(runner, files);
116
- break;
117
- case "custom":
118
- await notifyListeners(runner, payload.event, payload.data);
119
- break;
120
- case "prune":
121
- await notifyListeners(runner, "vite:beforePrune", payload), payload.paths.forEach((path) => {
122
- const fn = maps.pruneMap.get(path);
123
- if (fn) fn(maps.dataMap.get(path));
124
- });
125
- break;
126
- case "error": {
127
- await notifyListeners(runner, "vite:error", payload);
128
- const err = payload.err;
129
- console.error(`${browser.s.cyan("[vite-node]")} Internal Server Error\n${err.message}\n${err.stack}`);
130
- break;
131
- }
132
- }
133
- }
134
- function createHotContext(runner, emitter, files, ownerPath) {
135
- debugHmr("createHotContext", ownerPath);
136
- const maps = getCache(runner);
137
- if (!maps.dataMap.has(ownerPath)) maps.dataMap.set(ownerPath, {});
138
- // when a file is hot updated, a new context is created
139
- // clear its stale callbacks
140
- const mod = maps.hotModulesMap.get(ownerPath);
141
- if (mod) mod.callbacks = [];
142
- const newListeners = /* @__PURE__ */ new Map();
143
- maps.ctxToListenersMap.set(ownerPath, newListeners);
144
- function acceptDeps(deps, callback = () => {}) {
145
- const mod = maps.hotModulesMap.get(ownerPath) || {
146
- id: ownerPath,
147
- callbacks: []
148
- };
149
- mod.callbacks.push({
150
- deps,
151
- fn: callback
152
- }), maps.hotModulesMap.set(ownerPath, mod);
153
- }
154
- const hot = {
155
- get data() {
156
- return maps.dataMap.get(ownerPath);
157
- },
158
- acceptExports(_, callback) {
159
- acceptDeps([ownerPath], callback && (([mod]) => callback(mod)));
160
- },
161
- accept(deps, callback) {
162
- if (typeof deps === "function" || !deps)
163
- // self-accept: hot.accept(() => {})
164
- acceptDeps([ownerPath], ([mod]) => deps && deps(mod));
165
- else if (typeof deps === "string")
166
- // explicit deps
167
- acceptDeps([deps], ([mod]) => callback && callback(mod));
168
- else if (Array.isArray(deps)) acceptDeps(deps, callback);
169
- else throw new TypeError("invalid hot.accept() usage.");
170
- },
171
- dispose(cb) {
172
- maps.disposeMap.set(ownerPath, cb);
173
- },
174
- prune(cb) {
175
- maps.pruneMap.set(ownerPath, cb);
176
- },
177
- invalidate() {
178
- return notifyListeners(runner, "vite:invalidate", {
179
- path: ownerPath,
180
- message: void 0,
181
- firstInvalidatedBy: ownerPath
182
- }), reload(runner, files);
183
- },
184
- on(event, cb) {
185
- const addToMap = (map) => {
186
- const existing = map.get(event) || [];
187
- existing.push(cb), map.set(event, existing);
188
- };
189
- addToMap(maps.customListenersMap), addToMap(newListeners);
190
- },
191
- off(event, cb) {
192
- const removeFromMap = (map) => {
193
- const existing = map.get(event);
194
- if (existing === void 0) return;
195
- const pruned = existing.filter((l) => l !== cb);
196
- if (pruned.length === 0) {
197
- map.delete(event);
198
- return;
199
- }
200
- map.set(event, pruned);
201
- };
202
- removeFromMap(maps.customListenersMap), removeFromMap(newListeners);
203
- },
204
- send(event, data) {
205
- maps.messageBuffer.push(JSON.stringify({
206
- type: "custom",
207
- event,
208
- data
209
- })), sendMessageBuffer(runner, emitter);
210
- }
211
- };
212
- return hot;
213
- }
214
-
215
- exports.createHmrEmitter = createHmrEmitter;
216
- exports.createHotContext = createHotContext;
217
- exports.getCache = getCache;
218
- exports.handleMessage = handleMessage;
219
- exports.reload = reload;
220
- exports.sendMessageBuffer = sendMessageBuffer;
221
- exports.viteNodeHmrPlugin = viteNodeHmrPlugin;