vite-node 0.15.1 → 0.17.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/chunk-client.cjs +13 -1
- package/dist/chunk-client.mjs +13 -1
- package/dist/chunk-hmr.cjs +233 -0
- package/dist/chunk-hmr.mjs +221 -0
- package/dist/chunk-server.cjs +3 -21
- package/dist/chunk-server.mjs +3 -21
- package/dist/chunk-utils.cjs +2 -2
- package/dist/chunk-utils.mjs +3 -3
- package/dist/cli.cjs +21 -35
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +22 -36
- package/dist/client.d.ts +1 -1
- package/dist/hmr.cjs +18 -0
- package/dist/hmr.d.ts +57 -0
- package/dist/hmr.mjs +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/{types-93bdaf32.d.ts → types-b59fb161.d.ts} +104 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +9 -4
package/dist/chunk-client.cjs
CHANGED
|
@@ -152,6 +152,7 @@ ${getStack()}`), 2e3);
|
|
|
152
152
|
if (transformed == null)
|
|
153
153
|
throw new Error(`[vite-node] Failed to load ${id}`);
|
|
154
154
|
const url$1 = url.pathToFileURL(fsPath).href;
|
|
155
|
+
const meta = { url: url$1 };
|
|
155
156
|
const exports = /* @__PURE__ */ Object.create(null);
|
|
156
157
|
exports[Symbol.toStringTag] = "Module";
|
|
157
158
|
this.moduleCache.set(id, { code: transformed, exports });
|
|
@@ -165,12 +166,23 @@ ${getStack()}`), 2e3);
|
|
|
165
166
|
return exports;
|
|
166
167
|
}
|
|
167
168
|
};
|
|
169
|
+
let hotContext;
|
|
170
|
+
if (this.options.createHotContext) {
|
|
171
|
+
Object.defineProperty(meta, "hot", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: () => {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
|
|
176
|
+
return hotContext;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
168
180
|
const context = this.prepareContext({
|
|
169
181
|
__vite_ssr_import__: request,
|
|
170
182
|
__vite_ssr_dynamic_import__: request,
|
|
171
183
|
__vite_ssr_exports__: exports,
|
|
172
184
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
173
|
-
__vite_ssr_import_meta__:
|
|
185
|
+
__vite_ssr_import_meta__: meta,
|
|
174
186
|
__vitest_resolve_id__: resolveId,
|
|
175
187
|
require: module$1.createRequire(url$1),
|
|
176
188
|
exports,
|
package/dist/chunk-client.mjs
CHANGED
|
@@ -127,6 +127,7 @@ ${getStack()}`), 2e3);
|
|
|
127
127
|
if (transformed == null)
|
|
128
128
|
throw new Error(`[vite-node] Failed to load ${id}`);
|
|
129
129
|
const url = pathToFileURL(fsPath).href;
|
|
130
|
+
const meta = { url };
|
|
130
131
|
const exports = /* @__PURE__ */ Object.create(null);
|
|
131
132
|
exports[Symbol.toStringTag] = "Module";
|
|
132
133
|
this.moduleCache.set(id, { code: transformed, exports });
|
|
@@ -140,12 +141,23 @@ ${getStack()}`), 2e3);
|
|
|
140
141
|
return exports;
|
|
141
142
|
}
|
|
142
143
|
};
|
|
144
|
+
let hotContext;
|
|
145
|
+
if (this.options.createHotContext) {
|
|
146
|
+
Object.defineProperty(meta, "hot", {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: () => {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
|
|
151
|
+
return hotContext;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
143
155
|
const context = this.prepareContext({
|
|
144
156
|
__vite_ssr_import__: request,
|
|
145
157
|
__vite_ssr_dynamic_import__: request,
|
|
146
158
|
__vite_ssr_exports__: exports,
|
|
147
159
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
148
|
-
__vite_ssr_import_meta__:
|
|
160
|
+
__vite_ssr_import_meta__: meta,
|
|
149
161
|
__vitest_resolve_id__: resolveId,
|
|
150
162
|
require: createRequire(url),
|
|
151
163
|
exports,
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var events = require('events');
|
|
4
|
+
var kolorist = require('kolorist');
|
|
5
|
+
var createDebug = require('debug');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
10
|
+
|
|
11
|
+
function createHmrEmitter() {
|
|
12
|
+
const emitter = new events.EventEmitter();
|
|
13
|
+
return emitter;
|
|
14
|
+
}
|
|
15
|
+
function viteNodeHmrPlugin() {
|
|
16
|
+
const emitter = createHmrEmitter();
|
|
17
|
+
return {
|
|
18
|
+
name: "vite-node:hmr",
|
|
19
|
+
configureServer(server) {
|
|
20
|
+
const _send = server.ws.send;
|
|
21
|
+
server.emitter = emitter;
|
|
22
|
+
server.ws.send = function(payload) {
|
|
23
|
+
_send(payload);
|
|
24
|
+
emitter.emit("message", payload);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const debugHmr = createDebug__default["default"]("vite-node:hmr");
|
|
31
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
function getCache(runner) {
|
|
33
|
+
if (!cache.has(runner)) {
|
|
34
|
+
cache.set(runner, {
|
|
35
|
+
hotModulesMap: /* @__PURE__ */ new Map(),
|
|
36
|
+
dataMap: /* @__PURE__ */ new Map(),
|
|
37
|
+
disposeMap: /* @__PURE__ */ new Map(),
|
|
38
|
+
pruneMap: /* @__PURE__ */ new Map(),
|
|
39
|
+
customListenersMap: /* @__PURE__ */ new Map(),
|
|
40
|
+
ctxToListenersMap: /* @__PURE__ */ new Map(),
|
|
41
|
+
messageBuffer: [],
|
|
42
|
+
isFirstUpdate: false,
|
|
43
|
+
pending: false,
|
|
44
|
+
queued: []
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return cache.get(runner);
|
|
48
|
+
}
|
|
49
|
+
function sendMessageBuffer(runner, emitter) {
|
|
50
|
+
const maps = getCache(runner);
|
|
51
|
+
maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg));
|
|
52
|
+
maps.messageBuffer.length = 0;
|
|
53
|
+
}
|
|
54
|
+
async function reload(runner, files) {
|
|
55
|
+
Array.from(runner.moduleCache.keys()).forEach((i) => {
|
|
56
|
+
if (!i.includes("node_modules"))
|
|
57
|
+
runner.moduleCache.delete(i);
|
|
58
|
+
});
|
|
59
|
+
return Promise.all(files.map((file) => runner.executeId(file)));
|
|
60
|
+
}
|
|
61
|
+
function notifyListeners(runner, event, data) {
|
|
62
|
+
const maps = getCache(runner);
|
|
63
|
+
const cbs = maps.customListenersMap.get(event);
|
|
64
|
+
if (cbs)
|
|
65
|
+
cbs.forEach((cb) => cb(data));
|
|
66
|
+
}
|
|
67
|
+
async function queueUpdate(runner, p) {
|
|
68
|
+
const maps = getCache(runner);
|
|
69
|
+
maps.queued.push(p);
|
|
70
|
+
if (!maps.pending) {
|
|
71
|
+
maps.pending = true;
|
|
72
|
+
await Promise.resolve();
|
|
73
|
+
maps.pending = false;
|
|
74
|
+
const loading = [...maps.queued];
|
|
75
|
+
maps.queued = [];
|
|
76
|
+
(await Promise.all(loading)).forEach((fn) => fn && fn());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function fetchUpdate(runner, { path, acceptedPath }) {
|
|
80
|
+
const maps = getCache(runner);
|
|
81
|
+
const mod = maps.hotModulesMap.get(path);
|
|
82
|
+
if (!mod) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const moduleMap = /* @__PURE__ */ new Map();
|
|
86
|
+
const isSelfUpdate = path === acceptedPath;
|
|
87
|
+
const modulesToUpdate = /* @__PURE__ */ new Set();
|
|
88
|
+
if (isSelfUpdate) {
|
|
89
|
+
modulesToUpdate.add(path);
|
|
90
|
+
} else {
|
|
91
|
+
for (const { deps } of mod.callbacks) {
|
|
92
|
+
deps.forEach((dep) => {
|
|
93
|
+
if (acceptedPath === dep)
|
|
94
|
+
modulesToUpdate.add(dep);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => {
|
|
99
|
+
return deps.some((dep) => modulesToUpdate.has(dep));
|
|
100
|
+
});
|
|
101
|
+
await Promise.all(Array.from(modulesToUpdate).map(async (dep) => {
|
|
102
|
+
const disposer = maps.disposeMap.get(dep);
|
|
103
|
+
if (disposer)
|
|
104
|
+
await disposer(maps.dataMap.get(dep));
|
|
105
|
+
try {
|
|
106
|
+
const newMod = await reload(runner, [dep]);
|
|
107
|
+
moduleMap.set(dep, newMod);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
warnFailedFetch(e, dep);
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
return () => {
|
|
113
|
+
for (const { deps, fn } of qualifiedCallbacks)
|
|
114
|
+
fn(deps.map((dep) => moduleMap.get(dep)));
|
|
115
|
+
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
116
|
+
console.log(`${kolorist.cyan("[vite-node]")} hot updated: ${loggedPath}`);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function warnFailedFetch(err, path) {
|
|
120
|
+
if (!err.message.match("fetch"))
|
|
121
|
+
console.error(err);
|
|
122
|
+
console.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
|
|
123
|
+
}
|
|
124
|
+
async function handleMessage(runner, emitter, files, payload) {
|
|
125
|
+
const maps = getCache(runner);
|
|
126
|
+
switch (payload.type) {
|
|
127
|
+
case "connected":
|
|
128
|
+
sendMessageBuffer(runner, emitter);
|
|
129
|
+
break;
|
|
130
|
+
case "update":
|
|
131
|
+
notifyListeners(runner, "vite:beforeUpdate", payload);
|
|
132
|
+
if (maps.isFirstUpdate) {
|
|
133
|
+
reload(runner, files);
|
|
134
|
+
maps.isFirstUpdate = true;
|
|
135
|
+
}
|
|
136
|
+
payload.updates.forEach((update) => {
|
|
137
|
+
if (update.type === "js-update") {
|
|
138
|
+
queueUpdate(runner, fetchUpdate(runner, update));
|
|
139
|
+
} else {
|
|
140
|
+
console.error(`${kolorist.cyan("[vite-node]")} no support css hmr.}`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
break;
|
|
144
|
+
case "full-reload":
|
|
145
|
+
reload(runner, files);
|
|
146
|
+
break;
|
|
147
|
+
case "prune":
|
|
148
|
+
payload.paths.forEach((path) => {
|
|
149
|
+
const fn = maps.pruneMap.get(path);
|
|
150
|
+
if (fn)
|
|
151
|
+
fn(maps.dataMap.get(path));
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
case "error": {
|
|
155
|
+
notifyListeners(runner, "vite:error", payload);
|
|
156
|
+
const err = payload.err;
|
|
157
|
+
console.error(`${kolorist.cyan("[vite-node]")} Internal Server Error
|
|
158
|
+
${err.message}
|
|
159
|
+
${err.stack}`);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function createHotContext(runner, emitter, files, ownerPath) {
|
|
165
|
+
debugHmr("createHotContext", ownerPath);
|
|
166
|
+
const maps = getCache(runner);
|
|
167
|
+
if (!maps.dataMap.has(ownerPath))
|
|
168
|
+
maps.dataMap.set(ownerPath, {});
|
|
169
|
+
const mod = maps.hotModulesMap.get(ownerPath);
|
|
170
|
+
if (mod)
|
|
171
|
+
mod.callbacks = [];
|
|
172
|
+
const newListeners = /* @__PURE__ */ new Map();
|
|
173
|
+
maps.ctxToListenersMap.set(ownerPath, newListeners);
|
|
174
|
+
function acceptDeps(deps, callback = () => {
|
|
175
|
+
}) {
|
|
176
|
+
const mod2 = maps.hotModulesMap.get(ownerPath) || {
|
|
177
|
+
id: ownerPath,
|
|
178
|
+
callbacks: []
|
|
179
|
+
};
|
|
180
|
+
mod2.callbacks.push({
|
|
181
|
+
deps,
|
|
182
|
+
fn: callback
|
|
183
|
+
});
|
|
184
|
+
maps.hotModulesMap.set(ownerPath, mod2);
|
|
185
|
+
}
|
|
186
|
+
const hot = {
|
|
187
|
+
get data() {
|
|
188
|
+
return maps.dataMap.get(ownerPath);
|
|
189
|
+
},
|
|
190
|
+
accept(deps, callback) {
|
|
191
|
+
if (typeof deps === "function" || !deps) {
|
|
192
|
+
acceptDeps([ownerPath], ([mod2]) => deps && deps(mod2));
|
|
193
|
+
} else if (typeof deps === "string") {
|
|
194
|
+
acceptDeps([deps], ([mod2]) => callback && callback(mod2));
|
|
195
|
+
} else if (Array.isArray(deps)) {
|
|
196
|
+
acceptDeps(deps, callback);
|
|
197
|
+
} else {
|
|
198
|
+
throw new TypeError("invalid hot.accept() usage.");
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
dispose(cb) {
|
|
202
|
+
maps.disposeMap.set(ownerPath, cb);
|
|
203
|
+
},
|
|
204
|
+
prune(cb) {
|
|
205
|
+
maps.pruneMap.set(ownerPath, cb);
|
|
206
|
+
},
|
|
207
|
+
invalidate() {
|
|
208
|
+
return reload(runner, files);
|
|
209
|
+
},
|
|
210
|
+
on(event, cb) {
|
|
211
|
+
const addToMap = (map) => {
|
|
212
|
+
const existing = map.get(event) || [];
|
|
213
|
+
existing.push(cb);
|
|
214
|
+
map.set(event, existing);
|
|
215
|
+
};
|
|
216
|
+
addToMap(maps.customListenersMap);
|
|
217
|
+
addToMap(newListeners);
|
|
218
|
+
},
|
|
219
|
+
send(event, data) {
|
|
220
|
+
maps.messageBuffer.push(JSON.stringify({ type: "custom", event, data }));
|
|
221
|
+
sendMessageBuffer(runner, emitter);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
return hot;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
exports.createHmrEmitter = createHmrEmitter;
|
|
228
|
+
exports.createHotContext = createHotContext;
|
|
229
|
+
exports.getCache = getCache;
|
|
230
|
+
exports.handleMessage = handleMessage;
|
|
231
|
+
exports.reload = reload;
|
|
232
|
+
exports.sendMessageBuffer = sendMessageBuffer;
|
|
233
|
+
exports.viteNodeHmrPlugin = viteNodeHmrPlugin;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { cyan } from 'kolorist';
|
|
3
|
+
import createDebug from 'debug';
|
|
4
|
+
|
|
5
|
+
function createHmrEmitter() {
|
|
6
|
+
const emitter = new EventEmitter();
|
|
7
|
+
return emitter;
|
|
8
|
+
}
|
|
9
|
+
function viteNodeHmrPlugin() {
|
|
10
|
+
const emitter = createHmrEmitter();
|
|
11
|
+
return {
|
|
12
|
+
name: "vite-node:hmr",
|
|
13
|
+
configureServer(server) {
|
|
14
|
+
const _send = server.ws.send;
|
|
15
|
+
server.emitter = emitter;
|
|
16
|
+
server.ws.send = function(payload) {
|
|
17
|
+
_send(payload);
|
|
18
|
+
emitter.emit("message", payload);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const debugHmr = createDebug("vite-node:hmr");
|
|
25
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
function getCache(runner) {
|
|
27
|
+
if (!cache.has(runner)) {
|
|
28
|
+
cache.set(runner, {
|
|
29
|
+
hotModulesMap: /* @__PURE__ */ new Map(),
|
|
30
|
+
dataMap: /* @__PURE__ */ new Map(),
|
|
31
|
+
disposeMap: /* @__PURE__ */ new Map(),
|
|
32
|
+
pruneMap: /* @__PURE__ */ new Map(),
|
|
33
|
+
customListenersMap: /* @__PURE__ */ new Map(),
|
|
34
|
+
ctxToListenersMap: /* @__PURE__ */ new Map(),
|
|
35
|
+
messageBuffer: [],
|
|
36
|
+
isFirstUpdate: false,
|
|
37
|
+
pending: false,
|
|
38
|
+
queued: []
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return cache.get(runner);
|
|
42
|
+
}
|
|
43
|
+
function sendMessageBuffer(runner, emitter) {
|
|
44
|
+
const maps = getCache(runner);
|
|
45
|
+
maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg));
|
|
46
|
+
maps.messageBuffer.length = 0;
|
|
47
|
+
}
|
|
48
|
+
async function reload(runner, files) {
|
|
49
|
+
Array.from(runner.moduleCache.keys()).forEach((i) => {
|
|
50
|
+
if (!i.includes("node_modules"))
|
|
51
|
+
runner.moduleCache.delete(i);
|
|
52
|
+
});
|
|
53
|
+
return Promise.all(files.map((file) => runner.executeId(file)));
|
|
54
|
+
}
|
|
55
|
+
function notifyListeners(runner, event, data) {
|
|
56
|
+
const maps = getCache(runner);
|
|
57
|
+
const cbs = maps.customListenersMap.get(event);
|
|
58
|
+
if (cbs)
|
|
59
|
+
cbs.forEach((cb) => cb(data));
|
|
60
|
+
}
|
|
61
|
+
async function queueUpdate(runner, p) {
|
|
62
|
+
const maps = getCache(runner);
|
|
63
|
+
maps.queued.push(p);
|
|
64
|
+
if (!maps.pending) {
|
|
65
|
+
maps.pending = true;
|
|
66
|
+
await Promise.resolve();
|
|
67
|
+
maps.pending = false;
|
|
68
|
+
const loading = [...maps.queued];
|
|
69
|
+
maps.queued = [];
|
|
70
|
+
(await Promise.all(loading)).forEach((fn) => fn && fn());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function fetchUpdate(runner, { path, acceptedPath }) {
|
|
74
|
+
const maps = getCache(runner);
|
|
75
|
+
const mod = maps.hotModulesMap.get(path);
|
|
76
|
+
if (!mod) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const moduleMap = /* @__PURE__ */ new Map();
|
|
80
|
+
const isSelfUpdate = path === acceptedPath;
|
|
81
|
+
const modulesToUpdate = /* @__PURE__ */ new Set();
|
|
82
|
+
if (isSelfUpdate) {
|
|
83
|
+
modulesToUpdate.add(path);
|
|
84
|
+
} else {
|
|
85
|
+
for (const { deps } of mod.callbacks) {
|
|
86
|
+
deps.forEach((dep) => {
|
|
87
|
+
if (acceptedPath === dep)
|
|
88
|
+
modulesToUpdate.add(dep);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => {
|
|
93
|
+
return deps.some((dep) => modulesToUpdate.has(dep));
|
|
94
|
+
});
|
|
95
|
+
await Promise.all(Array.from(modulesToUpdate).map(async (dep) => {
|
|
96
|
+
const disposer = maps.disposeMap.get(dep);
|
|
97
|
+
if (disposer)
|
|
98
|
+
await disposer(maps.dataMap.get(dep));
|
|
99
|
+
try {
|
|
100
|
+
const newMod = await reload(runner, [dep]);
|
|
101
|
+
moduleMap.set(dep, newMod);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
warnFailedFetch(e, dep);
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
return () => {
|
|
107
|
+
for (const { deps, fn } of qualifiedCallbacks)
|
|
108
|
+
fn(deps.map((dep) => moduleMap.get(dep)));
|
|
109
|
+
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
110
|
+
console.log(`${cyan("[vite-node]")} hot updated: ${loggedPath}`);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function warnFailedFetch(err, path) {
|
|
114
|
+
if (!err.message.match("fetch"))
|
|
115
|
+
console.error(err);
|
|
116
|
+
console.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
|
|
117
|
+
}
|
|
118
|
+
async function handleMessage(runner, emitter, files, payload) {
|
|
119
|
+
const maps = getCache(runner);
|
|
120
|
+
switch (payload.type) {
|
|
121
|
+
case "connected":
|
|
122
|
+
sendMessageBuffer(runner, emitter);
|
|
123
|
+
break;
|
|
124
|
+
case "update":
|
|
125
|
+
notifyListeners(runner, "vite:beforeUpdate", payload);
|
|
126
|
+
if (maps.isFirstUpdate) {
|
|
127
|
+
reload(runner, files);
|
|
128
|
+
maps.isFirstUpdate = true;
|
|
129
|
+
}
|
|
130
|
+
payload.updates.forEach((update) => {
|
|
131
|
+
if (update.type === "js-update") {
|
|
132
|
+
queueUpdate(runner, fetchUpdate(runner, update));
|
|
133
|
+
} else {
|
|
134
|
+
console.error(`${cyan("[vite-node]")} no support css hmr.}`);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case "full-reload":
|
|
139
|
+
reload(runner, files);
|
|
140
|
+
break;
|
|
141
|
+
case "prune":
|
|
142
|
+
payload.paths.forEach((path) => {
|
|
143
|
+
const fn = maps.pruneMap.get(path);
|
|
144
|
+
if (fn)
|
|
145
|
+
fn(maps.dataMap.get(path));
|
|
146
|
+
});
|
|
147
|
+
break;
|
|
148
|
+
case "error": {
|
|
149
|
+
notifyListeners(runner, "vite:error", payload);
|
|
150
|
+
const err = payload.err;
|
|
151
|
+
console.error(`${cyan("[vite-node]")} Internal Server Error
|
|
152
|
+
${err.message}
|
|
153
|
+
${err.stack}`);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function createHotContext(runner, emitter, files, ownerPath) {
|
|
159
|
+
debugHmr("createHotContext", ownerPath);
|
|
160
|
+
const maps = getCache(runner);
|
|
161
|
+
if (!maps.dataMap.has(ownerPath))
|
|
162
|
+
maps.dataMap.set(ownerPath, {});
|
|
163
|
+
const mod = maps.hotModulesMap.get(ownerPath);
|
|
164
|
+
if (mod)
|
|
165
|
+
mod.callbacks = [];
|
|
166
|
+
const newListeners = /* @__PURE__ */ new Map();
|
|
167
|
+
maps.ctxToListenersMap.set(ownerPath, newListeners);
|
|
168
|
+
function acceptDeps(deps, callback = () => {
|
|
169
|
+
}) {
|
|
170
|
+
const mod2 = maps.hotModulesMap.get(ownerPath) || {
|
|
171
|
+
id: ownerPath,
|
|
172
|
+
callbacks: []
|
|
173
|
+
};
|
|
174
|
+
mod2.callbacks.push({
|
|
175
|
+
deps,
|
|
176
|
+
fn: callback
|
|
177
|
+
});
|
|
178
|
+
maps.hotModulesMap.set(ownerPath, mod2);
|
|
179
|
+
}
|
|
180
|
+
const hot = {
|
|
181
|
+
get data() {
|
|
182
|
+
return maps.dataMap.get(ownerPath);
|
|
183
|
+
},
|
|
184
|
+
accept(deps, callback) {
|
|
185
|
+
if (typeof deps === "function" || !deps) {
|
|
186
|
+
acceptDeps([ownerPath], ([mod2]) => deps && deps(mod2));
|
|
187
|
+
} else if (typeof deps === "string") {
|
|
188
|
+
acceptDeps([deps], ([mod2]) => callback && callback(mod2));
|
|
189
|
+
} else if (Array.isArray(deps)) {
|
|
190
|
+
acceptDeps(deps, callback);
|
|
191
|
+
} else {
|
|
192
|
+
throw new TypeError("invalid hot.accept() usage.");
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
dispose(cb) {
|
|
196
|
+
maps.disposeMap.set(ownerPath, cb);
|
|
197
|
+
},
|
|
198
|
+
prune(cb) {
|
|
199
|
+
maps.pruneMap.set(ownerPath, cb);
|
|
200
|
+
},
|
|
201
|
+
invalidate() {
|
|
202
|
+
return reload(runner, files);
|
|
203
|
+
},
|
|
204
|
+
on(event, cb) {
|
|
205
|
+
const addToMap = (map) => {
|
|
206
|
+
const existing = map.get(event) || [];
|
|
207
|
+
existing.push(cb);
|
|
208
|
+
map.set(event, existing);
|
|
209
|
+
};
|
|
210
|
+
addToMap(maps.customListenersMap);
|
|
211
|
+
addToMap(newListeners);
|
|
212
|
+
},
|
|
213
|
+
send(event, data) {
|
|
214
|
+
maps.messageBuffer.push(JSON.stringify({ type: "custom", event, data }));
|
|
215
|
+
sendMessageBuffer(runner, emitter);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
return hot;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { createHmrEmitter as a, createHotContext as c, getCache as g, handleMessage as h, reload as r, sendMessageBuffer as s, viteNodeHmrPlugin as v };
|
package/dist/chunk-server.cjs
CHANGED
|
@@ -95,25 +95,6 @@ function patchWindowsImportPath(path) {
|
|
|
95
95
|
return path;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
var __defProp = Object.defineProperty;
|
|
99
|
-
var __defProps = Object.defineProperties;
|
|
100
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
101
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
102
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
103
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
104
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
105
|
-
var __spreadValues = (a, b) => {
|
|
106
|
-
for (var prop in b || (b = {}))
|
|
107
|
-
if (__hasOwnProp.call(b, prop))
|
|
108
|
-
__defNormalProp(a, prop, b[prop]);
|
|
109
|
-
if (__getOwnPropSymbols)
|
|
110
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
111
|
-
if (__propIsEnum.call(b, prop))
|
|
112
|
-
__defNormalProp(a, prop, b[prop]);
|
|
113
|
-
}
|
|
114
|
-
return a;
|
|
115
|
-
};
|
|
116
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
117
98
|
const debugRequest = createDebug__default["default"]("vite-node:server:request");
|
|
118
99
|
const RealDate = Date;
|
|
119
100
|
class ViteNodeServer {
|
|
@@ -141,12 +122,13 @@ class ViteNodeServer {
|
|
|
141
122
|
async resolveId(id, importer) {
|
|
142
123
|
if (importer && !importer.startsWith(this.server.config.root))
|
|
143
124
|
importer = pathe.join(this.server.config.root, importer);
|
|
144
|
-
|
|
125
|
+
const mode = importer && this.getTransformMode(importer) || "ssr";
|
|
126
|
+
return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
|
|
145
127
|
}
|
|
146
128
|
async fetchModule(id) {
|
|
147
129
|
if (!this.fetchPromiseMap.has(id)) {
|
|
148
130
|
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
|
|
149
|
-
return this.options.sourcemap !== true ?
|
|
131
|
+
return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
|
|
150
132
|
}).finally(() => {
|
|
151
133
|
this.fetchPromiseMap.delete(id);
|
|
152
134
|
}));
|
package/dist/chunk-server.mjs
CHANGED
|
@@ -89,25 +89,6 @@ function patchWindowsImportPath(path) {
|
|
|
89
89
|
return path;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
var __defProp = Object.defineProperty;
|
|
93
|
-
var __defProps = Object.defineProperties;
|
|
94
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
95
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
96
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
97
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
98
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
99
|
-
var __spreadValues = (a, b) => {
|
|
100
|
-
for (var prop in b || (b = {}))
|
|
101
|
-
if (__hasOwnProp.call(b, prop))
|
|
102
|
-
__defNormalProp(a, prop, b[prop]);
|
|
103
|
-
if (__getOwnPropSymbols)
|
|
104
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
105
|
-
if (__propIsEnum.call(b, prop))
|
|
106
|
-
__defNormalProp(a, prop, b[prop]);
|
|
107
|
-
}
|
|
108
|
-
return a;
|
|
109
|
-
};
|
|
110
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
111
92
|
const debugRequest = createDebug("vite-node:server:request");
|
|
112
93
|
const RealDate = Date;
|
|
113
94
|
class ViteNodeServer {
|
|
@@ -135,12 +116,13 @@ class ViteNodeServer {
|
|
|
135
116
|
async resolveId(id, importer) {
|
|
136
117
|
if (importer && !importer.startsWith(this.server.config.root))
|
|
137
118
|
importer = join(this.server.config.root, importer);
|
|
138
|
-
|
|
119
|
+
const mode = importer && this.getTransformMode(importer) || "ssr";
|
|
120
|
+
return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
|
|
139
121
|
}
|
|
140
122
|
async fetchModule(id) {
|
|
141
123
|
if (!this.fetchPromiseMap.has(id)) {
|
|
142
124
|
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
|
|
143
|
-
return this.options.sourcemap !== true ?
|
|
125
|
+
return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
|
|
144
126
|
}).finally(() => {
|
|
145
127
|
this.fetchPromiseMap.delete(id);
|
|
146
128
|
}));
|
package/dist/chunk-utils.cjs
CHANGED
|
@@ -13,7 +13,7 @@ function mergeSlashes(str) {
|
|
|
13
13
|
function normalizeRequestId(id, base) {
|
|
14
14
|
if (base && id.startsWith(base))
|
|
15
15
|
id = `/${id.slice(base.length)}`;
|
|
16
|
-
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?+$/, "");
|
|
16
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
17
17
|
}
|
|
18
18
|
function normalizeModuleId(id) {
|
|
19
19
|
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
@@ -22,7 +22,7 @@ function isPrimitive(v) {
|
|
|
22
22
|
return v !== Object(v);
|
|
23
23
|
}
|
|
24
24
|
function toFilePath(id, root) {
|
|
25
|
-
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(
|
|
25
|
+
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? slash(pathe.resolve(root, id.slice(1))) : id;
|
|
26
26
|
if (absolute.startsWith("//"))
|
|
27
27
|
absolute = absolute.slice(1);
|
|
28
28
|
return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
|
package/dist/chunk-utils.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
2
|
-
import {
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
3
|
|
|
4
4
|
const isWindows = process.platform === "win32";
|
|
5
5
|
function slash(str) {
|
|
@@ -11,7 +11,7 @@ function mergeSlashes(str) {
|
|
|
11
11
|
function normalizeRequestId(id, base) {
|
|
12
12
|
if (base && id.startsWith(base))
|
|
13
13
|
id = `/${id.slice(base.length)}`;
|
|
14
|
-
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?+$/, "");
|
|
14
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
15
15
|
}
|
|
16
16
|
function normalizeModuleId(id) {
|
|
17
17
|
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
@@ -20,7 +20,7 @@ function isPrimitive(v) {
|
|
|
20
20
|
return v !== Object(v);
|
|
21
21
|
}
|
|
22
22
|
function toFilePath(id, root) {
|
|
23
|
-
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(
|
|
23
|
+
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
|
|
24
24
|
if (absolute.startsWith("//"))
|
|
25
25
|
absolute = absolute.slice(1);
|
|
26
26
|
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
package/dist/cli.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var vite = require('vite');
|
|
|
6
6
|
var server = require('./chunk-server.cjs');
|
|
7
7
|
var client = require('./chunk-client.cjs');
|
|
8
8
|
var utils = require('./chunk-utils.cjs');
|
|
9
|
+
var hmr = require('./chunk-hmr.cjs');
|
|
9
10
|
require('pathe');
|
|
10
11
|
require('debug');
|
|
11
12
|
require('fs');
|
|
@@ -627,32 +628,14 @@ class CAC extends events.EventEmitter {
|
|
|
627
628
|
|
|
628
629
|
const cac = (name = "") => new CAC(name);
|
|
629
630
|
|
|
630
|
-
var version = "0.
|
|
631
|
+
var version = "0.17.0";
|
|
631
632
|
|
|
632
|
-
var __defProp = Object.defineProperty;
|
|
633
|
-
var __defProps = Object.defineProperties;
|
|
634
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
635
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
636
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
637
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
638
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
639
|
-
var __spreadValues = (a, b) => {
|
|
640
|
-
for (var prop in b || (b = {}))
|
|
641
|
-
if (__hasOwnProp.call(b, prop))
|
|
642
|
-
__defNormalProp(a, prop, b[prop]);
|
|
643
|
-
if (__getOwnPropSymbols)
|
|
644
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
645
|
-
if (__propIsEnum.call(b, prop))
|
|
646
|
-
__defNormalProp(a, prop, b[prop]);
|
|
647
|
-
}
|
|
648
|
-
return a;
|
|
649
|
-
};
|
|
650
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
651
633
|
const cli = cac("vite-node");
|
|
652
634
|
cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
|
|
653
635
|
cli.command("[...files]").action(run);
|
|
654
636
|
cli.parse();
|
|
655
637
|
async function run(files, options = {}) {
|
|
638
|
+
var _a;
|
|
656
639
|
if (!files.length) {
|
|
657
640
|
console.error(kolorist.red("No files specified."));
|
|
658
641
|
cli.outputHelp();
|
|
@@ -663,7 +646,10 @@ async function run(files, options = {}) {
|
|
|
663
646
|
const server$1 = await vite.createServer({
|
|
664
647
|
logLevel: "error",
|
|
665
648
|
configFile: options.config,
|
|
666
|
-
root: options.root
|
|
649
|
+
root: options.root,
|
|
650
|
+
plugins: [
|
|
651
|
+
options.watch && hmr.viteNodeHmrPlugin()
|
|
652
|
+
]
|
|
667
653
|
});
|
|
668
654
|
await server$1.pluginContainer.buildStart({});
|
|
669
655
|
const node = new server.ViteNodeServer(server$1, parsedServerOptions);
|
|
@@ -675,6 +661,9 @@ async function run(files, options = {}) {
|
|
|
675
661
|
},
|
|
676
662
|
resolveId(id, importer) {
|
|
677
663
|
return node.resolveId(id, importer);
|
|
664
|
+
},
|
|
665
|
+
createHotContext(runner2, url) {
|
|
666
|
+
return hmr.createHotContext(runner2, server$1.emitter, files, url);
|
|
678
667
|
}
|
|
679
668
|
});
|
|
680
669
|
await runner.executeId("/@vite/env");
|
|
@@ -682,31 +671,28 @@ async function run(files, options = {}) {
|
|
|
682
671
|
await runner.executeFile(file);
|
|
683
672
|
if (!options.watch)
|
|
684
673
|
await server$1.close();
|
|
685
|
-
server$1.
|
|
686
|
-
|
|
687
|
-
Array.from(runner.moduleCache.keys()).forEach((i) => {
|
|
688
|
-
if (!i.includes("node_modules"))
|
|
689
|
-
runner.moduleCache.delete(i);
|
|
690
|
-
});
|
|
691
|
-
for (const file of files)
|
|
692
|
-
await runner.executeFile(file);
|
|
674
|
+
(_a = server$1.emitter) == null ? void 0 : _a.on("message", (payload) => {
|
|
675
|
+
hmr.handleMessage(runner, server$1.emitter, files, payload);
|
|
693
676
|
});
|
|
694
677
|
}
|
|
695
678
|
function parseServerOptions(serverOptions) {
|
|
696
679
|
var _a, _b, _c, _d, _e;
|
|
697
680
|
const inlineOptions = ((_a = serverOptions.deps) == null ? void 0 : _a.inline) === true ? true : utils.toArray((_b = serverOptions.deps) == null ? void 0 : _b.inline);
|
|
698
|
-
return
|
|
699
|
-
|
|
681
|
+
return {
|
|
682
|
+
...serverOptions,
|
|
683
|
+
deps: {
|
|
684
|
+
...serverOptions.deps,
|
|
700
685
|
inline: inlineOptions !== true ? inlineOptions.map((dep) => {
|
|
701
686
|
return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
|
|
702
687
|
}) : true,
|
|
703
688
|
external: utils.toArray((_c = serverOptions.deps) == null ? void 0 : _c.external).map((dep) => {
|
|
704
689
|
return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
|
|
705
690
|
})
|
|
706
|
-
}
|
|
707
|
-
transformMode:
|
|
691
|
+
},
|
|
692
|
+
transformMode: {
|
|
693
|
+
...serverOptions.transformMode,
|
|
708
694
|
ssr: utils.toArray((_d = serverOptions.transformMode) == null ? void 0 : _d.ssr).map((dep) => new RegExp(dep)),
|
|
709
695
|
web: utils.toArray((_e = serverOptions.transformMode) == null ? void 0 : _e.web).map((dep) => new RegExp(dep))
|
|
710
|
-
}
|
|
711
|
-
}
|
|
696
|
+
}
|
|
697
|
+
};
|
|
712
698
|
}
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { red
|
|
2
|
+
import { red } from 'kolorist';
|
|
3
3
|
import { createServer } from 'vite';
|
|
4
4
|
import { V as ViteNodeServer } from './chunk-server.mjs';
|
|
5
5
|
import { V as ViteNodeRunner } from './chunk-client.mjs';
|
|
6
6
|
import { t as toArray } from './chunk-utils.mjs';
|
|
7
|
+
import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
|
|
7
8
|
import 'pathe';
|
|
8
9
|
import 'debug';
|
|
9
10
|
import 'fs';
|
|
@@ -625,32 +626,14 @@ class CAC extends EventEmitter {
|
|
|
625
626
|
|
|
626
627
|
const cac = (name = "") => new CAC(name);
|
|
627
628
|
|
|
628
|
-
var version = "0.
|
|
629
|
+
var version = "0.17.0";
|
|
629
630
|
|
|
630
|
-
var __defProp = Object.defineProperty;
|
|
631
|
-
var __defProps = Object.defineProperties;
|
|
632
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
633
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
634
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
635
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
636
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
637
|
-
var __spreadValues = (a, b) => {
|
|
638
|
-
for (var prop in b || (b = {}))
|
|
639
|
-
if (__hasOwnProp.call(b, prop))
|
|
640
|
-
__defNormalProp(a, prop, b[prop]);
|
|
641
|
-
if (__getOwnPropSymbols)
|
|
642
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
643
|
-
if (__propIsEnum.call(b, prop))
|
|
644
|
-
__defNormalProp(a, prop, b[prop]);
|
|
645
|
-
}
|
|
646
|
-
return a;
|
|
647
|
-
};
|
|
648
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
649
631
|
const cli = cac("vite-node");
|
|
650
632
|
cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
|
|
651
633
|
cli.command("[...files]").action(run);
|
|
652
634
|
cli.parse();
|
|
653
635
|
async function run(files, options = {}) {
|
|
636
|
+
var _a;
|
|
654
637
|
if (!files.length) {
|
|
655
638
|
console.error(red("No files specified."));
|
|
656
639
|
cli.outputHelp();
|
|
@@ -661,7 +644,10 @@ async function run(files, options = {}) {
|
|
|
661
644
|
const server = await createServer({
|
|
662
645
|
logLevel: "error",
|
|
663
646
|
configFile: options.config,
|
|
664
|
-
root: options.root
|
|
647
|
+
root: options.root,
|
|
648
|
+
plugins: [
|
|
649
|
+
options.watch && viteNodeHmrPlugin()
|
|
650
|
+
]
|
|
665
651
|
});
|
|
666
652
|
await server.pluginContainer.buildStart({});
|
|
667
653
|
const node = new ViteNodeServer(server, parsedServerOptions);
|
|
@@ -673,6 +659,9 @@ async function run(files, options = {}) {
|
|
|
673
659
|
},
|
|
674
660
|
resolveId(id, importer) {
|
|
675
661
|
return node.resolveId(id, importer);
|
|
662
|
+
},
|
|
663
|
+
createHotContext(runner2, url) {
|
|
664
|
+
return createHotContext(runner2, server.emitter, files, url);
|
|
676
665
|
}
|
|
677
666
|
});
|
|
678
667
|
await runner.executeId("/@vite/env");
|
|
@@ -680,31 +669,28 @@ async function run(files, options = {}) {
|
|
|
680
669
|
await runner.executeFile(file);
|
|
681
670
|
if (!options.watch)
|
|
682
671
|
await server.close();
|
|
683
|
-
server.
|
|
684
|
-
|
|
685
|
-
Array.from(runner.moduleCache.keys()).forEach((i) => {
|
|
686
|
-
if (!i.includes("node_modules"))
|
|
687
|
-
runner.moduleCache.delete(i);
|
|
688
|
-
});
|
|
689
|
-
for (const file of files)
|
|
690
|
-
await runner.executeFile(file);
|
|
672
|
+
(_a = server.emitter) == null ? void 0 : _a.on("message", (payload) => {
|
|
673
|
+
handleMessage(runner, server.emitter, files, payload);
|
|
691
674
|
});
|
|
692
675
|
}
|
|
693
676
|
function parseServerOptions(serverOptions) {
|
|
694
677
|
var _a, _b, _c, _d, _e;
|
|
695
678
|
const inlineOptions = ((_a = serverOptions.deps) == null ? void 0 : _a.inline) === true ? true : toArray((_b = serverOptions.deps) == null ? void 0 : _b.inline);
|
|
696
|
-
return
|
|
697
|
-
|
|
679
|
+
return {
|
|
680
|
+
...serverOptions,
|
|
681
|
+
deps: {
|
|
682
|
+
...serverOptions.deps,
|
|
698
683
|
inline: inlineOptions !== true ? inlineOptions.map((dep) => {
|
|
699
684
|
return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
|
|
700
685
|
}) : true,
|
|
701
686
|
external: toArray((_c = serverOptions.deps) == null ? void 0 : _c.external).map((dep) => {
|
|
702
687
|
return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
|
|
703
688
|
})
|
|
704
|
-
}
|
|
705
|
-
transformMode:
|
|
689
|
+
},
|
|
690
|
+
transformMode: {
|
|
691
|
+
...serverOptions.transformMode,
|
|
706
692
|
ssr: toArray((_d = serverOptions.transformMode) == null ? void 0 : _d.ssr).map((dep) => new RegExp(dep)),
|
|
707
693
|
web: toArray((_e = serverOptions.transformMode) == null ? void 0 : _e.web).map((dep) => new RegExp(dep))
|
|
708
|
-
}
|
|
709
|
-
}
|
|
694
|
+
}
|
|
695
|
+
};
|
|
710
696
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { i as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, g as ViteNodeRunner } from './types-b59fb161.js';
|
package/dist/hmr.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var hmr = require('./chunk-hmr.cjs');
|
|
6
|
+
require('events');
|
|
7
|
+
require('kolorist');
|
|
8
|
+
require('debug');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.createHmrEmitter = hmr.createHmrEmitter;
|
|
13
|
+
exports.createHotContext = hmr.createHotContext;
|
|
14
|
+
exports.getCache = hmr.getCache;
|
|
15
|
+
exports.handleMessage = hmr.handleMessage;
|
|
16
|
+
exports.reload = hmr.reload;
|
|
17
|
+
exports.sendMessageBuffer = hmr.sendMessageBuffer;
|
|
18
|
+
exports.viteNodeHmrPlugin = hmr.viteNodeHmrPlugin;
|
package/dist/hmr.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { HMRPayload, Plugin } from 'vite';
|
|
3
|
+
import { U as UpdatePayload, P as PrunePayload, f as FullReloadPayload, E as ErrorPayload, g as ViteNodeRunner, h as HMRPayload$1, H as HotContext } from './types-b59fb161.js';
|
|
4
|
+
|
|
5
|
+
declare type EventType = string | symbol;
|
|
6
|
+
declare type Handler<T = unknown> = (event: T) => void;
|
|
7
|
+
interface Emitter<Events extends Record<EventType, unknown>> {
|
|
8
|
+
on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
|
|
9
|
+
off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
|
|
10
|
+
emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;
|
|
11
|
+
emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;
|
|
12
|
+
}
|
|
13
|
+
declare type HMREmitter = Emitter<{
|
|
14
|
+
'message': HMRPayload;
|
|
15
|
+
}> & EventEmitter;
|
|
16
|
+
declare module 'vite' {
|
|
17
|
+
interface ViteDevServer {
|
|
18
|
+
emitter: HMREmitter;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
declare function createHmrEmitter(): HMREmitter;
|
|
22
|
+
declare function viteNodeHmrPlugin(): Plugin;
|
|
23
|
+
|
|
24
|
+
interface CustomEventMap {
|
|
25
|
+
'vite:beforeUpdate': UpdatePayload;
|
|
26
|
+
'vite:beforePrune': PrunePayload;
|
|
27
|
+
'vite:beforeFullReload': FullReloadPayload;
|
|
28
|
+
'vite:error': ErrorPayload;
|
|
29
|
+
}
|
|
30
|
+
declare type InferCustomEventPayload<T extends string> = T extends keyof CustomEventMap ? CustomEventMap[T] : any;
|
|
31
|
+
interface HotModule {
|
|
32
|
+
id: string;
|
|
33
|
+
callbacks: HotCallback[];
|
|
34
|
+
}
|
|
35
|
+
interface HotCallback {
|
|
36
|
+
deps: string[];
|
|
37
|
+
fn: (modules: object[]) => void;
|
|
38
|
+
}
|
|
39
|
+
interface CacheData {
|
|
40
|
+
hotModulesMap: Map<string, HotModule>;
|
|
41
|
+
dataMap: Map<string, any>;
|
|
42
|
+
disposeMap: Map<string, (data: any) => void | Promise<void>>;
|
|
43
|
+
pruneMap: Map<string, (data: any) => void | Promise<void>>;
|
|
44
|
+
customListenersMap: Map<string, ((data: any) => void)[]>;
|
|
45
|
+
ctxToListenersMap: Map<string, Map<string, ((data: any) => void)[]>>;
|
|
46
|
+
messageBuffer: string[];
|
|
47
|
+
isFirstUpdate: boolean;
|
|
48
|
+
pending: boolean;
|
|
49
|
+
queued: Promise<(() => void) | undefined>[];
|
|
50
|
+
}
|
|
51
|
+
declare function getCache(runner: ViteNodeRunner): CacheData;
|
|
52
|
+
declare function sendMessageBuffer(runner: ViteNodeRunner, emitter: HMREmitter): void;
|
|
53
|
+
declare function reload(runner: ViteNodeRunner, files: string[]): Promise<any[]>;
|
|
54
|
+
declare function handleMessage(runner: ViteNodeRunner, emitter: HMREmitter, files: string[], payload: HMRPayload$1): Promise<void>;
|
|
55
|
+
declare function createHotContext(runner: ViteNodeRunner, emitter: HMREmitter, files: string[], ownerPath: string): HotContext;
|
|
56
|
+
|
|
57
|
+
export { CustomEventMap, Emitter, EventType, HMREmitter, Handler, HotCallback, HotModule, InferCustomEventPayload, createHmrEmitter, createHotContext, getCache, handleMessage, reload, sendMessageBuffer, viteNodeHmrPlugin };
|
package/dist/hmr.mjs
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as Arrayable, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-
|
|
1
|
+
export { A as Arrayable, C as CreateHotContextFunction, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-b59fb161.js';
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ViteDevServer, TransformResult } from 'vite';
|
|
2
|
-
import { D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-
|
|
2
|
+
import { D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-b59fb161.js';
|
|
3
3
|
|
|
4
4
|
declare function guessCJSversion(id: string): string | undefined;
|
|
5
5
|
declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
|
|
@@ -1,3 +1,103 @@
|
|
|
1
|
+
type HMRPayload =
|
|
2
|
+
| ConnectedPayload
|
|
3
|
+
| UpdatePayload
|
|
4
|
+
| FullReloadPayload
|
|
5
|
+
| CustomPayload
|
|
6
|
+
| ErrorPayload
|
|
7
|
+
| PrunePayload
|
|
8
|
+
|
|
9
|
+
interface ConnectedPayload {
|
|
10
|
+
type: 'connected'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface UpdatePayload {
|
|
14
|
+
type: 'update'
|
|
15
|
+
updates: Update[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Update {
|
|
19
|
+
type: 'js-update' | 'css-update'
|
|
20
|
+
path: string
|
|
21
|
+
acceptedPath: string
|
|
22
|
+
timestamp: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface PrunePayload {
|
|
26
|
+
type: 'prune'
|
|
27
|
+
paths: string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface FullReloadPayload {
|
|
31
|
+
type: 'full-reload'
|
|
32
|
+
path?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface CustomPayload {
|
|
36
|
+
type: 'custom'
|
|
37
|
+
event: string
|
|
38
|
+
data?: any
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface ErrorPayload {
|
|
42
|
+
type: 'error'
|
|
43
|
+
err: {
|
|
44
|
+
[name: string]: any
|
|
45
|
+
message: string
|
|
46
|
+
stack: string
|
|
47
|
+
id?: string
|
|
48
|
+
frame?: string
|
|
49
|
+
plugin?: string
|
|
50
|
+
pluginCode?: string
|
|
51
|
+
loc?: {
|
|
52
|
+
file?: string
|
|
53
|
+
line: number
|
|
54
|
+
column: number
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface CustomEventMap {
|
|
60
|
+
'vite:beforeUpdate': UpdatePayload
|
|
61
|
+
'vite:beforePrune': PrunePayload
|
|
62
|
+
'vite:beforeFullReload': FullReloadPayload
|
|
63
|
+
'vite:error': ErrorPayload
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type InferCustomEventPayload<T extends string> =
|
|
67
|
+
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
68
|
+
|
|
69
|
+
type ModuleNamespace = Record<string, any> & {
|
|
70
|
+
[Symbol.toStringTag]: 'Module'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ViteHotContext {
|
|
74
|
+
readonly data: any
|
|
75
|
+
|
|
76
|
+
accept(): void
|
|
77
|
+
accept(cb: (mod: ModuleNamespace | undefined) => void): void
|
|
78
|
+
accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
|
|
79
|
+
accept(
|
|
80
|
+
deps: readonly string[],
|
|
81
|
+
cb: (mods: Array<ModuleNamespace | undefined>) => void
|
|
82
|
+
): void
|
|
83
|
+
|
|
84
|
+
acceptExports(exportNames: string | readonly string[]): void
|
|
85
|
+
acceptExports(
|
|
86
|
+
exportNames: string | readonly string[],
|
|
87
|
+
cb: (mod: ModuleNamespace | undefined) => void
|
|
88
|
+
): void
|
|
89
|
+
|
|
90
|
+
dispose(cb: (data: any) => void): void
|
|
91
|
+
decline(): void
|
|
92
|
+
invalidate(): void
|
|
93
|
+
|
|
94
|
+
on<T extends string>(
|
|
95
|
+
event: T,
|
|
96
|
+
cb: (payload: InferCustomEventPayload<T>) => void
|
|
97
|
+
): void
|
|
98
|
+
send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
|
|
99
|
+
}
|
|
100
|
+
|
|
1
101
|
declare const DEFAULT_REQUEST_STUBS: {
|
|
2
102
|
'/@vite/client': {
|
|
3
103
|
injectQuery: (id: string) => string;
|
|
@@ -76,8 +176,10 @@ interface FetchResult {
|
|
|
76
176
|
externalize?: string;
|
|
77
177
|
map?: RawSourceMap;
|
|
78
178
|
}
|
|
179
|
+
declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
|
|
79
180
|
declare type FetchFunction = (id: string) => Promise<FetchResult>;
|
|
80
181
|
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
182
|
+
declare type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) => HotContext;
|
|
81
183
|
interface ModuleCache {
|
|
82
184
|
promise?: Promise<any>;
|
|
83
185
|
exports?: any;
|
|
@@ -87,6 +189,7 @@ interface ViteNodeRunnerOptions {
|
|
|
87
189
|
root: string;
|
|
88
190
|
fetchModule: FetchFunction;
|
|
89
191
|
resolveId?: ResolveIdFunction;
|
|
192
|
+
createHotContext?: CreateHotContextFunction;
|
|
90
193
|
base?: string;
|
|
91
194
|
moduleCache?: ModuleCacheMap;
|
|
92
195
|
interopDefault?: boolean;
|
|
@@ -119,4 +222,4 @@ interface ViteNodeServerOptions {
|
|
|
119
222
|
};
|
|
120
223
|
}
|
|
121
224
|
|
|
122
|
-
export { Arrayable as A, DepsHandlingOptions as D, FetchResult as F, ModuleCacheMap as M, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeRunnerOptions as V, FetchFunction as a, ResolveIdFunction as b, ModuleCache as c, ViteNodeResolveId as d, ViteNodeServerOptions as e,
|
|
225
|
+
export { Arrayable as A, CreateHotContextFunction as C, DepsHandlingOptions as D, ErrorPayload as E, FetchResult as F, HotContext as H, ModuleCacheMap as M, Nullable as N, PrunePayload as P, RawSourceMap as R, StartOfSourceMap as S, UpdatePayload as U, ViteNodeRunnerOptions as V, FetchFunction as a, ResolveIdFunction as b, ModuleCache as c, ViteNodeResolveId as d, ViteNodeServerOptions as e, FullReloadPayload as f, ViteNodeRunner as g, HMRPayload as h, DEFAULT_REQUEST_STUBS as i };
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as Arrayable, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-
|
|
1
|
+
export { A as Arrayable, C as CreateHotContextFunction, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-b59fb161.js';
|
package/dist/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Vite as Node.js runtime",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"types": "./dist/utils.d.ts",
|
|
35
35
|
"require": "./dist/utils.cjs",
|
|
36
36
|
"import": "./dist/utils.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./hmr": {
|
|
39
|
+
"types": "./dist/hmr.d.ts",
|
|
40
|
+
"require": "./dist/hmr.cjs",
|
|
41
|
+
"import": "./dist/hmr.mjs"
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
"main": "./dist/index.mjs",
|
|
@@ -61,14 +66,14 @@
|
|
|
61
66
|
"dependencies": {
|
|
62
67
|
"debug": "^4.3.4",
|
|
63
68
|
"kolorist": "^1.5.1",
|
|
64
|
-
"mlly": "^0.5.
|
|
69
|
+
"mlly": "^0.5.3",
|
|
65
70
|
"pathe": "^0.2.0",
|
|
66
|
-
"vite": "^2.9.12"
|
|
71
|
+
"vite": "^2.9.12 || ^3.0.0-0"
|
|
67
72
|
},
|
|
68
73
|
"devDependencies": {
|
|
69
74
|
"@types/debug": "^4.1.7",
|
|
70
75
|
"cac": "^6.7.12",
|
|
71
|
-
"rollup": "^2.75.
|
|
76
|
+
"rollup": "^2.75.7"
|
|
72
77
|
},
|
|
73
78
|
"scripts": {
|
|
74
79
|
"build": "rimraf dist && rollup -c",
|