vite-node 4.0.0-beta.9 → 5.0.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/LICENSE +1 -1
- package/README.md +8 -4
- package/dist/{chunk-hmr.mjs → chunk-hmr.js} +63 -34
- package/dist/{chunk-browser.mjs → chunk-index.js} +26 -25
- package/dist/cli.d.ts +1 -1
- package/dist/{cli.mjs → cli.js} +67 -23
- package/dist/client.d.ts +1 -1
- package/dist/{client.mjs → client.js} +110 -46
- package/dist/hmr.d.ts +1 -4
- package/dist/{hmr.mjs → hmr.js} +4 -3
- package/dist/{index.d-CvIJUDRh.d.ts → index.d-D6Pqey3g.d.ts} +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/{server.mjs → server.js} +110 -56
- package/dist/{source-map.mjs → source-map.js} +229 -173
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/{utils.mjs → utils.js} +33 -13
- package/package.json +41 -60
- package/vite-node.js +2 -0
- package/dist/chunk-browser.cjs +0 -83
- package/dist/chunk-hmr.cjs +0 -221
- package/dist/cli.cjs +0 -114
- package/dist/client.cjs +0 -447
- package/dist/constants.cjs +0 -36
- package/dist/hmr.cjs +0 -21
- package/dist/index.cjs +0 -2
- package/dist/server.cjs +0 -382
- package/dist/source-map.cjs +0 -867
- package/dist/types.cjs +0 -2
- package/dist/utils.cjs +0 -196
- package/vite-node.mjs +0 -2
- /package/dist/{constants.mjs → constants.js} +0 -0
- /package/dist/{index.mjs → index.js} +0 -0
- /package/dist/{types.mjs → types.js} +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021-
|
|
3
|
+
Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://github.com/
|
|
2
|
+
<img src="https://github.com/antfu/vite-node/blob/main/assets/vite-node.svg?raw=true" height="120">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<h1 align="center">
|
|
6
6
|
vite-node
|
|
7
7
|
</h1>
|
|
8
8
|
<p align="center">
|
|
9
|
-
Vite as Node runtime.<br>The engine that powers <a href="https://github.com/vitest-dev/vitest">
|
|
9
|
+
Vite as Node runtime.<br>The engine that powers <a href="https://github.com/nuxt/nuxt">Nuxt 3 Dev SSR</a> and <i><a href="https://github.com/vitest-dev/vitest/pull/8208">used to</a></i> power <a href="https://github.com/vitest-dev/vitest">Vitest</a>.
|
|
10
|
+
|
|
10
11
|
<p>
|
|
11
12
|
<p align="center">
|
|
12
|
-
<a href="https://www.npmjs.com/package/
|
|
13
|
+
<a href="https://www.npmjs.com/package/vite-node"><img src="https://img.shields.io/npm/v/vite-node?color=FCC72B&label="></a>
|
|
13
14
|
<p>
|
|
14
15
|
|
|
16
|
+
> [!NOTE]
|
|
17
|
+
> This project is firstly inspired by [Nuxt 3's SSR](https://antfu.me/posts/dev-ssr-on-nuxt) implementation made by [@pi0](https://github.com/pi0), as a PoC. Later, it made [Vitest](https://github.com/vitest-dev/vitest) possible by providing the same pipeline as in Vite. It served the ecosystem well for a few years and later became a more generalized built-in solution as [Vite Environment Module Runner](https://vite.dev/guide/api-environment.html). Vitest has [migrated to the new official solution](https://github.com/vitest-dev/vitest/pull/8208), which means `vite-node` has finished its mission. We will still keep it around for the ecosystem that built around it, but for new projects, please consider using the builtin Vite one instead.
|
|
18
|
+
|
|
15
19
|
## Features
|
|
16
20
|
|
|
17
21
|
- On-demand evaluation
|
|
@@ -40,7 +44,7 @@ npx vite-node -h
|
|
|
40
44
|
|
|
41
45
|
### Options via CLI
|
|
42
46
|
|
|
43
|
-
[All `ViteNodeServer` options](https://github.com/
|
|
47
|
+
[All `ViteNodeServer` options](https://github.com/antfu-collective/vite-node/blob/main/src/types.ts#L92-L111) are supported by the CLI. They may be defined through the dot syntax, as shown below:
|
|
44
48
|
|
|
45
49
|
```bash
|
|
46
50
|
npx vite-node --options.deps.inline="module-name" --options.deps.external="/module-regexp/" index.ts
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import process from 'node:process';
|
|
2
3
|
import createDebug from 'debug';
|
|
3
|
-
import {
|
|
4
|
-
import { normalizeRequestId } from './utils.
|
|
4
|
+
import { C } from './chunk-index.js';
|
|
5
|
+
import { normalizeRequestId } from './utils.js';
|
|
5
6
|
|
|
6
7
|
function createHmrEmitter() {
|
|
7
|
-
|
|
8
|
-
return emitter;
|
|
8
|
+
return new EventEmitter();
|
|
9
9
|
}
|
|
10
10
|
function viteNodeHmrPlugin() {
|
|
11
11
|
const emitter = createHmrEmitter();
|
|
@@ -13,24 +13,31 @@ function viteNodeHmrPlugin() {
|
|
|
13
13
|
name: "vite-node:hmr",
|
|
14
14
|
config() {
|
|
15
15
|
// chokidar fsevents is unstable on macos when emitting "ready" event
|
|
16
|
-
if (process.platform === "darwin" &&
|
|
16
|
+
if (process.platform === "darwin" && process.env.VITE_TEST_WATCHER_DEBUG) return { server: { watch: {
|
|
17
|
+
useFsEvents: false,
|
|
18
|
+
usePolling: false
|
|
19
|
+
} } };
|
|
17
20
|
},
|
|
18
21
|
configureServer(server) {
|
|
19
22
|
const _send = server.ws.send;
|
|
20
|
-
server.emitter = emitter
|
|
21
|
-
|
|
23
|
+
server.emitter = emitter;
|
|
24
|
+
server.ws.send = function(payload) {
|
|
25
|
+
_send(payload);
|
|
26
|
+
emitter.emit("message", payload);
|
|
22
27
|
};
|
|
23
28
|
// eslint-disable-next-line ts/ban-ts-comment
|
|
24
29
|
// @ts-ignore Vite 6 compat
|
|
25
30
|
const environments = server.environments;
|
|
26
31
|
if (environments) environments.ssr.hot.send = function(payload) {
|
|
27
|
-
_send(payload)
|
|
32
|
+
_send(payload);
|
|
33
|
+
emitter.emit("message", payload);
|
|
28
34
|
};
|
|
29
35
|
}
|
|
30
36
|
};
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
const debugHmr = createDebug("vite-node:hmr")
|
|
39
|
+
const debugHmr = createDebug("vite-node:hmr");
|
|
40
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
34
41
|
function getCache(runner) {
|
|
35
42
|
if (!cache.has(runner)) cache.set(runner, {
|
|
36
43
|
hotModulesMap: /* @__PURE__ */ new Map(),
|
|
@@ -48,28 +55,37 @@ function getCache(runner) {
|
|
|
48
55
|
}
|
|
49
56
|
function sendMessageBuffer(runner, emitter) {
|
|
50
57
|
const maps = getCache(runner);
|
|
51
|
-
maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg))
|
|
58
|
+
maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg));
|
|
59
|
+
maps.messageBuffer.length = 0;
|
|
52
60
|
}
|
|
53
61
|
async function reload(runner, files) {
|
|
54
|
-
|
|
62
|
+
// invalidate module cache but not node_modules
|
|
63
|
+
Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
|
|
55
64
|
if (!fsPath.includes("node_modules")) runner.moduleCache.delete(fsPath);
|
|
56
|
-
})
|
|
65
|
+
});
|
|
66
|
+
return Promise.all(files.map((file) => runner.executeId(file)));
|
|
57
67
|
}
|
|
58
68
|
async function notifyListeners(runner, event, data) {
|
|
59
|
-
const
|
|
69
|
+
const cbs = getCache(runner).customListenersMap.get(event);
|
|
60
70
|
if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
|
|
61
71
|
}
|
|
62
72
|
async function queueUpdate(runner, p) {
|
|
63
73
|
const maps = getCache(runner);
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
maps.queued.push(p);
|
|
75
|
+
if (!maps.pending) {
|
|
76
|
+
maps.pending = true;
|
|
77
|
+
await Promise.resolve();
|
|
78
|
+
maps.pending = false;
|
|
66
79
|
const loading = [...maps.queued];
|
|
67
|
-
maps.queued = []
|
|
80
|
+
maps.queued = [];
|
|
81
|
+
(await Promise.all(loading)).forEach((fn) => fn && fn());
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
async function fetchUpdate(runner, { path, acceptedPath }) {
|
|
71
|
-
path = normalizeRequestId(path)
|
|
72
|
-
|
|
85
|
+
path = normalizeRequestId(path);
|
|
86
|
+
acceptedPath = normalizeRequestId(acceptedPath);
|
|
87
|
+
const maps = getCache(runner);
|
|
88
|
+
const mod = maps.hotModulesMap.get(path);
|
|
73
89
|
if (!mod)
|
|
74
90
|
// In a code-splitting project,
|
|
75
91
|
// it is common that the hot-updating module is not loaded yet.
|
|
@@ -91,7 +107,7 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
|
|
|
91
107
|
return () => {
|
|
92
108
|
for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
|
|
93
109
|
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
94
|
-
console.log(`${
|
|
110
|
+
console.log(`${C.cyan("[vite-node]")} hot updated: ${loggedPath}`);
|
|
95
111
|
};
|
|
96
112
|
}
|
|
97
113
|
function warnFailedFetch(err, path) {
|
|
@@ -105,18 +121,26 @@ async function handleMessage(runner, emitter, files, payload) {
|
|
|
105
121
|
sendMessageBuffer(runner, emitter);
|
|
106
122
|
break;
|
|
107
123
|
case "update":
|
|
108
|
-
await notifyListeners(runner, "vite:beforeUpdate", payload)
|
|
109
|
-
|
|
110
|
-
|
|
124
|
+
await notifyListeners(runner, "vite:beforeUpdate", payload);
|
|
125
|
+
await Promise.all(payload.updates.map((update) => {
|
|
126
|
+
if (update.type === "js-update") return queueUpdate(runner, fetchUpdate(runner, update));
|
|
127
|
+
// css-update
|
|
128
|
+
console.error(`${C.cyan("[vite-node]")} no support css hmr.}`);
|
|
129
|
+
return null;
|
|
130
|
+
}));
|
|
131
|
+
await notifyListeners(runner, "vite:afterUpdate", payload);
|
|
111
132
|
break;
|
|
112
133
|
case "full-reload":
|
|
113
|
-
await notifyListeners(runner, "vite:beforeFullReload", payload)
|
|
134
|
+
await notifyListeners(runner, "vite:beforeFullReload", payload);
|
|
135
|
+
maps.customListenersMap.delete("vite:beforeFullReload");
|
|
136
|
+
await reload(runner, files);
|
|
114
137
|
break;
|
|
115
138
|
case "custom":
|
|
116
139
|
await notifyListeners(runner, payload.event, payload.data);
|
|
117
140
|
break;
|
|
118
141
|
case "prune":
|
|
119
|
-
await notifyListeners(runner, "vite:beforePrune", payload)
|
|
142
|
+
await notifyListeners(runner, "vite:beforePrune", payload);
|
|
143
|
+
payload.paths.forEach((path) => {
|
|
120
144
|
const fn = maps.pruneMap.get(path);
|
|
121
145
|
if (fn) fn(maps.dataMap.get(path));
|
|
122
146
|
});
|
|
@@ -124,7 +148,7 @@ async function handleMessage(runner, emitter, files, payload) {
|
|
|
124
148
|
case "error": {
|
|
125
149
|
await notifyListeners(runner, "vite:error", payload);
|
|
126
150
|
const err = payload.err;
|
|
127
|
-
console.error(`${
|
|
151
|
+
console.error(`${C.cyan("[vite-node]")} Internal Server Error\n${err.message}\n${err.stack}`);
|
|
128
152
|
break;
|
|
129
153
|
}
|
|
130
154
|
}
|
|
@@ -147,9 +171,10 @@ function createHotContext(runner, emitter, files, ownerPath) {
|
|
|
147
171
|
mod.callbacks.push({
|
|
148
172
|
deps,
|
|
149
173
|
fn: callback
|
|
150
|
-
})
|
|
174
|
+
});
|
|
175
|
+
maps.hotModulesMap.set(ownerPath, mod);
|
|
151
176
|
}
|
|
152
|
-
|
|
177
|
+
return {
|
|
153
178
|
get data() {
|
|
154
179
|
return maps.dataMap.get(ownerPath);
|
|
155
180
|
},
|
|
@@ -173,18 +198,21 @@ function createHotContext(runner, emitter, files, ownerPath) {
|
|
|
173
198
|
maps.pruneMap.set(ownerPath, cb);
|
|
174
199
|
},
|
|
175
200
|
invalidate() {
|
|
176
|
-
|
|
201
|
+
notifyListeners(runner, "vite:invalidate", {
|
|
177
202
|
path: ownerPath,
|
|
178
203
|
message: void 0,
|
|
179
204
|
firstInvalidatedBy: ownerPath
|
|
180
|
-
})
|
|
205
|
+
});
|
|
206
|
+
return reload(runner, files);
|
|
181
207
|
},
|
|
182
208
|
on(event, cb) {
|
|
183
209
|
const addToMap = (map) => {
|
|
184
210
|
const existing = map.get(event) || [];
|
|
185
|
-
existing.push(cb)
|
|
211
|
+
existing.push(cb);
|
|
212
|
+
map.set(event, existing);
|
|
186
213
|
};
|
|
187
|
-
addToMap(maps.customListenersMap)
|
|
214
|
+
addToMap(maps.customListenersMap);
|
|
215
|
+
addToMap(newListeners);
|
|
188
216
|
},
|
|
189
217
|
off(event, cb) {
|
|
190
218
|
const removeFromMap = (map) => {
|
|
@@ -197,17 +225,18 @@ function createHotContext(runner, emitter, files, ownerPath) {
|
|
|
197
225
|
}
|
|
198
226
|
map.set(event, pruned);
|
|
199
227
|
};
|
|
200
|
-
removeFromMap(maps.customListenersMap)
|
|
228
|
+
removeFromMap(maps.customListenersMap);
|
|
229
|
+
removeFromMap(newListeners);
|
|
201
230
|
},
|
|
202
231
|
send(event, data) {
|
|
203
232
|
maps.messageBuffer.push(JSON.stringify({
|
|
204
233
|
type: "custom",
|
|
205
234
|
event,
|
|
206
235
|
data
|
|
207
|
-
}))
|
|
236
|
+
}));
|
|
237
|
+
sendMessageBuffer(runner, emitter);
|
|
208
238
|
}
|
|
209
239
|
};
|
|
210
|
-
return hot;
|
|
211
240
|
}
|
|
212
241
|
|
|
213
242
|
export { createHotContext as a, createHmrEmitter as c, getCache as g, handleMessage as h, reload as r, sendMessageBuffer as s, viteNodeHmrPlugin as v };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
var
|
|
2
|
+
var d = {
|
|
3
3
|
reset: [0, 0],
|
|
4
4
|
bold: [1, 22, "\x1B[22m\x1B[1m"],
|
|
5
5
|
dim: [2, 22, "\x1B[22m\x1B[2m"],
|
|
@@ -41,41 +41,42 @@ var f = {
|
|
|
41
41
|
bgMagentaBright: [105, 49],
|
|
42
42
|
bgCyanBright: [106, 49],
|
|
43
43
|
bgWhiteBright: [107, 49]
|
|
44
|
-
}
|
|
45
|
-
function
|
|
46
|
-
return String(
|
|
44
|
+
};
|
|
45
|
+
function g(e) {
|
|
46
|
+
return String(e);
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
function
|
|
51
|
-
let e = typeof process != "undefined" ? process : void 0,
|
|
52
|
-
return !("NO_COLOR" in
|
|
48
|
+
g.open = "";
|
|
49
|
+
g.close = "";
|
|
50
|
+
function h() {
|
|
51
|
+
let e = typeof process != "undefined" ? process : void 0, n = (e == null ? void 0 : e.env) || {}, a = n.FORCE_TTY !== "false", i = (e == null ? void 0 : e.argv) || [];
|
|
52
|
+
return !("NO_COLOR" in n || i.includes("--no-color")) && ("FORCE_COLOR" in n || i.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || a && n.TERM !== "dumb" || "CI" in n) || typeof window != "undefined" && !!window.chrome;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
let e =
|
|
54
|
+
function f() {
|
|
55
|
+
let e = h(), n = (r, t, u, o) => {
|
|
56
56
|
let l = "", s = 0;
|
|
57
57
|
do
|
|
58
|
-
l += r.substring(s, o) +
|
|
58
|
+
l += r.substring(s, o) + u, s = o + t.length, o = r.indexOf(t, s);
|
|
59
59
|
while (~o);
|
|
60
60
|
return l + r.substring(s);
|
|
61
|
-
},
|
|
61
|
+
}, a = (r, t, u = r) => {
|
|
62
62
|
let o = (l) => {
|
|
63
63
|
let s = String(l), b = s.indexOf(t, r.length);
|
|
64
|
-
return ~b ? r +
|
|
64
|
+
return ~b ? r + n(s, t, u, b) + t : r + s + t;
|
|
65
65
|
};
|
|
66
66
|
return o.open = r, o.close = t, o;
|
|
67
|
-
},
|
|
67
|
+
}, i = {
|
|
68
68
|
isColorSupported: e
|
|
69
|
-
},
|
|
70
|
-
for (let
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
}, c = (r) => `\x1B[${r}m`;
|
|
70
|
+
for (let r in d) {
|
|
71
|
+
let t = d[r];
|
|
72
|
+
i[r] = e ? a(
|
|
73
|
+
c(t[0]),
|
|
74
|
+
c(t[1]),
|
|
74
75
|
t[2]
|
|
75
|
-
) :
|
|
76
|
-
|
|
76
|
+
) : g;
|
|
77
|
+
}
|
|
78
|
+
return i;
|
|
77
79
|
}
|
|
80
|
+
var C = f();
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export { s };
|
|
82
|
+
export { C };
|
package/dist/cli.d.ts
CHANGED
package/dist/{cli.mjs → cli.js}
RENAMED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
2
3
|
import cac from 'cac';
|
|
3
|
-
import {
|
|
4
|
+
import { C } from './chunk-index.js';
|
|
4
5
|
import { createServer, version as version$1, loadEnv } from 'vite';
|
|
5
|
-
import { ViteNodeRunner } from './client.
|
|
6
|
-
import { ViteNodeServer } from './server.
|
|
7
|
-
import { installSourcemapsSupport } from './source-map.
|
|
8
|
-
import { toArray } from './utils.
|
|
9
|
-
import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.
|
|
6
|
+
import { ViteNodeRunner } from './client.js';
|
|
7
|
+
import { ViteNodeServer } from './server.js';
|
|
8
|
+
import { installSourcemapsSupport } from './source-map.js';
|
|
9
|
+
import { toArray } from './utils.js';
|
|
10
|
+
import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.js';
|
|
10
11
|
import 'node:module';
|
|
11
12
|
import 'node:url';
|
|
12
13
|
import 'node:vm';
|
|
13
14
|
import 'debug';
|
|
15
|
+
import 'node:buffer';
|
|
14
16
|
import 'pathe';
|
|
15
17
|
import 'node:fs';
|
|
16
18
|
import 'node:assert';
|
|
17
19
|
import 'node:perf_hooks';
|
|
18
20
|
import 'es-module-lexer';
|
|
19
|
-
import './constants.
|
|
21
|
+
import './constants.js';
|
|
20
22
|
import 'node:events';
|
|
21
23
|
|
|
22
|
-
var version = "
|
|
24
|
+
var version = "5.0.0";
|
|
23
25
|
|
|
24
26
|
const cli = cac("vite-node");
|
|
25
|
-
|
|
27
|
+
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");
|
|
28
|
+
cli.command("[...files]").allowUnknownOptions().action(run);
|
|
29
|
+
cli.parse(process.argv, { run: false });
|
|
30
|
+
if (cli.args.length === 0) cli.runMatchedCommand();
|
|
26
31
|
else {
|
|
27
|
-
const i = cli.rawArgs.indexOf(cli.args[0]) + 1
|
|
32
|
+
const i = cli.rawArgs.indexOf(cli.args[0]) + 1;
|
|
33
|
+
const scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--");
|
|
34
|
+
const executeArgs = [
|
|
28
35
|
...cli.rawArgs.slice(0, i),
|
|
29
36
|
"--",
|
|
30
37
|
...scriptArgs
|
|
@@ -33,16 +40,31 @@ else {
|
|
|
33
40
|
}
|
|
34
41
|
async function run(files, options = {}) {
|
|
35
42
|
var _server$emitter;
|
|
36
|
-
if (options.script)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (options.script) {
|
|
44
|
+
files = [files[0]];
|
|
45
|
+
options = {};
|
|
46
|
+
process.argv = [
|
|
47
|
+
process.argv[0],
|
|
48
|
+
resolve(files[0]),
|
|
49
|
+
...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
|
|
50
|
+
];
|
|
51
|
+
} else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
|
|
52
|
+
if (options.version) {
|
|
53
|
+
cli.version(version);
|
|
54
|
+
cli.outputVersion();
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
if (options.help) {
|
|
58
|
+
cli.version(version).outputHelp();
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
if (!files.length) {
|
|
62
|
+
console.error(C.red("No files specified."));
|
|
63
|
+
cli.version(version).outputHelp();
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
const serverOptions = options.options ? parseServerOptions(options.options) : {};
|
|
67
|
+
const server = await createServer({
|
|
46
68
|
logLevel: "error",
|
|
47
69
|
configFile: options.config,
|
|
48
70
|
root: options.root,
|
|
@@ -81,11 +103,33 @@ async function run(files, options = {}) {
|
|
|
81
103
|
await runner.executeId("/@vite/env");
|
|
82
104
|
for (const file of files) await runner.executeFile(file);
|
|
83
105
|
if (!options.watch) await server.close();
|
|
84
|
-
|
|
106
|
+
(_server$emitter = server.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
|
|
85
107
|
handleMessage(runner, server.emitter, files, payload);
|
|
86
|
-
}), options.watch) process.on("uncaughtException", (err) => {
|
|
87
|
-
console.error(s.red("[vite-node] Failed to execute file: \n"), err);
|
|
88
108
|
});
|
|
109
|
+
if (options.watch) {
|
|
110
|
+
process.on("uncaughtException", (err) => {
|
|
111
|
+
console.error(C.red("[vite-node] Failed to execute file: \n"), err);
|
|
112
|
+
});
|
|
113
|
+
if (process.env.VITE_TEST_WATCHER_DEBUG) {
|
|
114
|
+
// manually check `watcher.getWatched()` to make sure entry files are ready
|
|
115
|
+
// since watcher.on('ready', ...) event is not reliable since 5.1.
|
|
116
|
+
// https://github.com/vitejs/vite/blob/63a39c244b08cf1f2299bc2c3cfddcb82070d05b/playground/hmr-ssr/__tests__/hmr.spec.ts#L1065
|
|
117
|
+
const nodePath = await import('node:path');
|
|
118
|
+
async function waitForWatched(files) {
|
|
119
|
+
while (!files.every((file) => isWatched(file))) await new Promise((resolve) => setTimeout(resolve, 20));
|
|
120
|
+
}
|
|
121
|
+
function isWatched(file) {
|
|
122
|
+
var _watched$dir;
|
|
123
|
+
const watched = server.watcher.getWatched();
|
|
124
|
+
const resolved = nodePath.resolve(file);
|
|
125
|
+
const dir = nodePath.dirname(resolved);
|
|
126
|
+
const base = nodePath.basename(resolved);
|
|
127
|
+
return (_watched$dir = watched[dir]) === null || _watched$dir === void 0 ? void 0 : _watched$dir.includes(base);
|
|
128
|
+
}
|
|
129
|
+
await waitForWatched(files);
|
|
130
|
+
console.log("[debug] watcher is ready");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
89
133
|
}
|
|
90
134
|
function parseServerOptions(serverOptions) {
|
|
91
135
|
var _serverOptions$deps, _serverOptions$deps2, _serverOptions$deps3, _serverOptions$deps4, _serverOptions$deps5, _serverOptions$deps6, _serverOptions$transf, _serverOptions$transf2;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './trace-mapping.d-BWFx6tPc.js';
|
|
2
|
-
export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, f as ModuleExecutionInfo, g as ModuleExecutionInfoEntry, a as ViteNodeRunner } from './index.d-
|
|
2
|
+
export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, f as ModuleExecutionInfo, g as ModuleExecutionInfoEntry, a as ViteNodeRunner } from './index.d-D6Pqey3g.js';
|