vitest 0.18.1 → 0.20.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.md +5 -5
- package/dist/browser.d.ts +1890 -0
- package/dist/browser.mjs +22 -0
- package/dist/{chunk-api-setup.9d3f7670.mjs → chunk-api-setup.7c4c8879.mjs} +24 -6
- package/dist/{chunk-constants.d4406290.mjs → chunk-constants.16825f0c.mjs} +5 -4
- package/dist/{chunk-env-node.bbba78e5.mjs → chunk-defaults.1c51d585.mjs} +461 -457
- package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
- package/dist/chunk-integrations-globals.56a11010.mjs +26 -0
- package/dist/{chunk-utils-global.0a7416cf.mjs → chunk-mock-date.9160e13b.mjs} +16 -41
- package/dist/chunk-node-git.43dbdd42.mjs +1139 -0
- package/dist/chunk-runtime-chain.b6c2cdbc.mjs +2041 -0
- package/dist/chunk-runtime-error.0aa0dc06.mjs +648 -0
- package/dist/{chunk-runtime-chain.b60d57da.mjs → chunk-runtime-hooks.3ee34848.mjs} +14 -2014
- package/dist/{chunk-runtime-mocker.1d853e3a.mjs → chunk-runtime-mocker.0a8f7c5e.mjs} +23 -17
- package/dist/{chunk-runtime-rpc.9d1f4c48.mjs → chunk-runtime-rpc.dbf0b31d.mjs} +3 -1
- package/dist/chunk-utils-global.fa20c2f6.mjs +5 -0
- package/dist/{chunk-utils-source-map.c03f8bc4.mjs → chunk-utils-source-map.8198ebd9.mjs} +2 -2
- package/dist/chunk-utils-timers.b48455ed.mjs +27 -0
- package/dist/chunk-vite-node-client.a247c2c2.mjs +320 -0
- package/dist/chunk-vite-node-debug.c5887932.mjs +76 -0
- package/dist/{chunk-vite-node-externalize.6956d2d9.mjs → chunk-vite-node-externalize.2e90dadf.mjs} +165 -1182
- package/dist/{chunk-vite-node-utils.8077cd3c.mjs → chunk-vite-node-utils.9dfd1e3f.mjs} +4 -312
- package/dist/cli.mjs +10 -10
- package/dist/config.cjs +6 -3
- package/dist/config.d.ts +2 -0
- package/dist/config.mjs +6 -3
- package/dist/entry.mjs +17 -598
- package/dist/index.d.ts +81 -6
- package/dist/index.mjs +10 -5
- package/dist/loader.mjs +35 -0
- package/dist/node.d.ts +71 -4
- package/dist/node.mjs +13 -12
- package/dist/suite.mjs +15 -0
- package/dist/vendor-index.61438b77.mjs +335 -0
- package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
- package/dist/worker.mjs +9 -6
- package/package.json +12 -4
- package/dist/chunk-integrations-globals.00b6e1ad.mjs +0 -23
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as ViteNodeRunner } from './chunk-vite-node-client.a247c2c2.mjs';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { M as isWindows, N as mergeSlashes, d as dirname, j as join, z as basename, y as resolve, s as slash, k as getType, O as getAllProperties } from './chunk-mock-date.9160e13b.mjs';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
|
-
import {
|
|
5
|
+
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.9dfd1e3f.mjs';
|
|
6
|
+
import { d as distDir } from './chunk-constants.16825f0c.mjs';
|
|
7
|
+
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
6
8
|
|
|
7
9
|
class RefTracker {
|
|
8
10
|
constructor() {
|
|
@@ -72,16 +74,18 @@ const _VitestMocker = class {
|
|
|
72
74
|
}
|
|
73
75
|
async callFunctionMock(dep, mock) {
|
|
74
76
|
var _a;
|
|
75
|
-
const
|
|
76
|
-
const cached = (_a = this.moduleCache.get(cacheName)) == null ? void 0 : _a.exports;
|
|
77
|
+
const cached = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
|
|
77
78
|
if (cached)
|
|
78
79
|
return cached;
|
|
79
80
|
const exports = await mock();
|
|
80
|
-
this.moduleCache.set(
|
|
81
|
+
this.moduleCache.set(dep, { exports });
|
|
81
82
|
return exports;
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
return
|
|
84
|
+
getMockPath(dep) {
|
|
85
|
+
return `mock:${dep}`;
|
|
86
|
+
}
|
|
87
|
+
getDependencyMock(id) {
|
|
88
|
+
return this.getMocks()[id];
|
|
85
89
|
}
|
|
86
90
|
normalizePath(path) {
|
|
87
91
|
return normalizeRequestId(path.replace(this.root, ""), this.base).replace(/^\/@fs\//, isWindows ? "" : "/");
|
|
@@ -184,7 +188,8 @@ const _VitestMocker = class {
|
|
|
184
188
|
async importMock(id, importer) {
|
|
185
189
|
const { path, external } = await this.resolvePath(id, importer);
|
|
186
190
|
const fsPath = this.getFsPath(path, external);
|
|
187
|
-
|
|
191
|
+
const normalizedId = this.normalizePath(fsPath);
|
|
192
|
+
let mock = this.getDependencyMock(normalizedId);
|
|
188
193
|
if (mock === void 0)
|
|
189
194
|
mock = this.resolveMockPath(fsPath, external);
|
|
190
195
|
if (mock === null) {
|
|
@@ -207,23 +212,24 @@ const _VitestMocker = class {
|
|
|
207
212
|
this.ensureSpy(),
|
|
208
213
|
this.resolveMocks()
|
|
209
214
|
]);
|
|
210
|
-
const
|
|
215
|
+
const id = this.normalizePath(dep);
|
|
216
|
+
const mock = this.getDependencyMock(id);
|
|
211
217
|
const callstack = this.request.callstack;
|
|
218
|
+
const mockPath = this.getMockPath(id);
|
|
212
219
|
if (mock === null) {
|
|
213
|
-
const
|
|
214
|
-
const cache = this.moduleCache.get(cacheName);
|
|
220
|
+
const cache = this.moduleCache.get(mockPath);
|
|
215
221
|
if (cache == null ? void 0 : cache.exports)
|
|
216
222
|
return cache.exports;
|
|
217
223
|
const cacheKey = toFilePath(dep, this.root);
|
|
218
224
|
const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
|
|
219
225
|
const exports = this.mockObject(mod);
|
|
220
|
-
this.moduleCache.set(
|
|
226
|
+
this.moduleCache.set(mockPath, { exports });
|
|
221
227
|
return exports;
|
|
222
228
|
}
|
|
223
|
-
if (typeof mock === "function" && !callstack.includes(
|
|
224
|
-
callstack.push(
|
|
225
|
-
const result = await this.callFunctionMock(
|
|
226
|
-
const indexMock = callstack.indexOf(
|
|
229
|
+
if (typeof mock === "function" && !callstack.includes(mockPath)) {
|
|
230
|
+
callstack.push(mockPath);
|
|
231
|
+
const result = await this.callFunctionMock(mockPath, mock);
|
|
232
|
+
const indexMock = callstack.indexOf(mockPath);
|
|
227
233
|
callstack.splice(indexMock, 1);
|
|
228
234
|
return result;
|
|
229
235
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './chunk-mock-date.9160e13b.mjs';
|
|
2
|
+
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
3
|
+
import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
|
|
2
4
|
|
|
3
5
|
const rpc = () => {
|
|
4
6
|
const { rpc: rpc2 } = getWorkerState();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as slash,
|
|
1
|
+
import { s as slash, f as notNullish, p as picocolors } from './chunk-mock-date.9160e13b.mjs';
|
|
2
2
|
|
|
3
3
|
var build = {};
|
|
4
4
|
|
|
@@ -7435,4 +7435,4 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
|
|
|
7435
7435
|
diff: diff
|
|
7436
7436
|
});
|
|
7437
7437
|
|
|
7438
|
-
export {
|
|
7438
|
+
export { plugins_1 as a, posToNumber as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, sliceAnsi as i, interpretSourcePos as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, parseStacktrace as p, stringify as s, unifiedDiff as u };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const {
|
|
2
|
+
setTimeout: safeSetTimeout,
|
|
3
|
+
setInterval: safeSetInterval,
|
|
4
|
+
clearInterval: safeClearInterval,
|
|
5
|
+
clearTimeout: safeClearTimeout
|
|
6
|
+
} = globalThis;
|
|
7
|
+
function withSafeTimers(fn) {
|
|
8
|
+
const currentSetTimeout = globalThis.setTimeout;
|
|
9
|
+
const currentSetInterval = globalThis.setInterval;
|
|
10
|
+
const currentClearInterval = globalThis.clearInterval;
|
|
11
|
+
const currentClearTimeout = globalThis.clearTimeout;
|
|
12
|
+
try {
|
|
13
|
+
globalThis.setTimeout = safeSetTimeout;
|
|
14
|
+
globalThis.setInterval = safeSetInterval;
|
|
15
|
+
globalThis.clearInterval = safeClearInterval;
|
|
16
|
+
globalThis.clearTimeout = safeClearTimeout;
|
|
17
|
+
const result = fn();
|
|
18
|
+
return result;
|
|
19
|
+
} finally {
|
|
20
|
+
globalThis.setTimeout = currentSetTimeout;
|
|
21
|
+
globalThis.setInterval = currentSetInterval;
|
|
22
|
+
globalThis.clearInterval = currentClearInterval;
|
|
23
|
+
globalThis.clearTimeout = currentClearTimeout;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { safeClearTimeout as a, safeSetInterval as b, safeClearInterval as c, safeSetTimeout as s, withSafeTimers as w };
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
3
|
+
import vm from 'vm';
|
|
4
|
+
import { y as resolve, d as dirname, B as isAbsolute, L as extname } from './chunk-mock-date.9160e13b.mjs';
|
|
5
|
+
import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.9dfd1e3f.mjs';
|
|
6
|
+
import createDebug from 'debug';
|
|
7
|
+
|
|
8
|
+
const debugExecute = createDebug("vite-node:client:execute");
|
|
9
|
+
const debugNative = createDebug("vite-node:client:native");
|
|
10
|
+
const DEFAULT_REQUEST_STUBS = {
|
|
11
|
+
"/@vite/client": {
|
|
12
|
+
injectQuery: (id) => id,
|
|
13
|
+
createHotContext() {
|
|
14
|
+
return {
|
|
15
|
+
accept: () => {
|
|
16
|
+
},
|
|
17
|
+
prune: () => {
|
|
18
|
+
},
|
|
19
|
+
dispose: () => {
|
|
20
|
+
},
|
|
21
|
+
decline: () => {
|
|
22
|
+
},
|
|
23
|
+
invalidate: () => {
|
|
24
|
+
},
|
|
25
|
+
on: () => {
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
updateStyle(id, css) {
|
|
30
|
+
if (typeof document === "undefined")
|
|
31
|
+
return;
|
|
32
|
+
const element = document.getElementById(id);
|
|
33
|
+
if (element)
|
|
34
|
+
element.remove();
|
|
35
|
+
const head = document.querySelector("head");
|
|
36
|
+
const style = document.createElement("style");
|
|
37
|
+
style.setAttribute("type", "text/css");
|
|
38
|
+
style.id = id;
|
|
39
|
+
style.innerHTML = css;
|
|
40
|
+
head == null ? void 0 : head.appendChild(style);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
class ModuleCacheMap extends Map {
|
|
45
|
+
normalizePath(fsPath) {
|
|
46
|
+
return normalizeModuleId(fsPath);
|
|
47
|
+
}
|
|
48
|
+
set(fsPath, mod) {
|
|
49
|
+
fsPath = this.normalizePath(fsPath);
|
|
50
|
+
if (!super.has(fsPath))
|
|
51
|
+
super.set(fsPath, mod);
|
|
52
|
+
else
|
|
53
|
+
Object.assign(super.get(fsPath), mod);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
get(fsPath) {
|
|
57
|
+
fsPath = this.normalizePath(fsPath);
|
|
58
|
+
return super.get(fsPath);
|
|
59
|
+
}
|
|
60
|
+
delete(fsPath) {
|
|
61
|
+
fsPath = this.normalizePath(fsPath);
|
|
62
|
+
return super.delete(fsPath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class ViteNodeRunner {
|
|
66
|
+
constructor(options) {
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.root = options.root ?? process.cwd();
|
|
69
|
+
this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
|
|
70
|
+
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
|
|
71
|
+
}
|
|
72
|
+
async executeFile(file) {
|
|
73
|
+
return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
|
|
74
|
+
}
|
|
75
|
+
async executeId(id) {
|
|
76
|
+
return await this.cachedRequest(id, []);
|
|
77
|
+
}
|
|
78
|
+
async cachedRequest(rawId, callstack) {
|
|
79
|
+
var _a, _b, _c, _d;
|
|
80
|
+
const id = normalizeRequestId(rawId, this.options.base);
|
|
81
|
+
const fsPath = toFilePath(id, this.root);
|
|
82
|
+
if (callstack.includes(fsPath) && ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports))
|
|
83
|
+
return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.exports;
|
|
84
|
+
if ((_c = this.moduleCache.get(fsPath)) == null ? void 0 : _c.promise)
|
|
85
|
+
return (_d = this.moduleCache.get(fsPath)) == null ? void 0 : _d.promise;
|
|
86
|
+
const promise = this.directRequest(id, fsPath, callstack);
|
|
87
|
+
this.moduleCache.set(fsPath, { promise });
|
|
88
|
+
return await promise;
|
|
89
|
+
}
|
|
90
|
+
async directRequest(id, fsPath, _callstack) {
|
|
91
|
+
const callstack = [..._callstack, fsPath];
|
|
92
|
+
const request = async (dep) => {
|
|
93
|
+
var _a;
|
|
94
|
+
const fsPath2 = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
|
|
95
|
+
const getStack = () => {
|
|
96
|
+
return `stack:
|
|
97
|
+
${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
98
|
+
};
|
|
99
|
+
let debugTimer;
|
|
100
|
+
if (this.debug)
|
|
101
|
+
debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
|
|
102
|
+
${getStack()}`), 2e3);
|
|
103
|
+
try {
|
|
104
|
+
if (callstack.includes(fsPath2)) {
|
|
105
|
+
const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
|
|
106
|
+
if (depExports)
|
|
107
|
+
return depExports;
|
|
108
|
+
throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
|
|
109
|
+
}
|
|
110
|
+
const mod = await this.cachedRequest(dep, callstack);
|
|
111
|
+
return mod;
|
|
112
|
+
} finally {
|
|
113
|
+
if (debugTimer)
|
|
114
|
+
clearTimeout(debugTimer);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
Object.defineProperty(request, "callstack", { get: () => callstack });
|
|
118
|
+
const resolveId = async (dep, callstackPosition = 1) => {
|
|
119
|
+
if (this.options.resolveId && this.shouldResolveId(dep)) {
|
|
120
|
+
let importer = callstack[callstack.length - callstackPosition];
|
|
121
|
+
if (importer && importer.startsWith("mock:"))
|
|
122
|
+
importer = importer.slice(5);
|
|
123
|
+
const { id: id2 } = await this.options.resolveId(dep, importer) || {};
|
|
124
|
+
dep = id2 && isAbsolute(id2) ? mergeSlashes(`/@fs/${id2}`) : id2 || dep;
|
|
125
|
+
}
|
|
126
|
+
return dep;
|
|
127
|
+
};
|
|
128
|
+
id = await resolveId(id, 2);
|
|
129
|
+
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
130
|
+
if (id in requestStubs)
|
|
131
|
+
return requestStubs[id];
|
|
132
|
+
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
133
|
+
if (externalize) {
|
|
134
|
+
debugNative(externalize);
|
|
135
|
+
const mod = await this.interopedImport(externalize);
|
|
136
|
+
this.moduleCache.set(fsPath, { exports: mod });
|
|
137
|
+
return mod;
|
|
138
|
+
}
|
|
139
|
+
if (transformed == null)
|
|
140
|
+
throw new Error(`[vite-node] Failed to load ${id}`);
|
|
141
|
+
const url = pathToFileURL(fsPath).href;
|
|
142
|
+
const meta = { url };
|
|
143
|
+
const exports = /* @__PURE__ */ Object.create(null);
|
|
144
|
+
exports[Symbol.toStringTag] = "Module";
|
|
145
|
+
this.moduleCache.set(fsPath, { code: transformed, exports });
|
|
146
|
+
const __filename = fileURLToPath(url);
|
|
147
|
+
const moduleProxy = {
|
|
148
|
+
set exports(value) {
|
|
149
|
+
exportAll(exports, value);
|
|
150
|
+
exports.default = value;
|
|
151
|
+
},
|
|
152
|
+
get exports() {
|
|
153
|
+
return exports;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
let hotContext;
|
|
157
|
+
if (this.options.createHotContext) {
|
|
158
|
+
Object.defineProperty(meta, "hot", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: () => {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
|
|
163
|
+
return hotContext;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const context = this.prepareContext({
|
|
168
|
+
__vite_ssr_import__: request,
|
|
169
|
+
__vite_ssr_dynamic_import__: request,
|
|
170
|
+
__vite_ssr_exports__: exports,
|
|
171
|
+
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
172
|
+
__vite_ssr_import_meta__: meta,
|
|
173
|
+
__vitest_resolve_id__: resolveId,
|
|
174
|
+
require: createRequire(url),
|
|
175
|
+
exports,
|
|
176
|
+
module: moduleProxy,
|
|
177
|
+
__filename,
|
|
178
|
+
__dirname: dirname(__filename)
|
|
179
|
+
});
|
|
180
|
+
debugExecute(__filename);
|
|
181
|
+
if (transformed[0] === "#")
|
|
182
|
+
transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
|
|
183
|
+
const fn = vm.runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
|
|
184
|
+
}}`, {
|
|
185
|
+
filename: fsPath,
|
|
186
|
+
lineOffset: 0
|
|
187
|
+
});
|
|
188
|
+
await fn(...Object.values(context));
|
|
189
|
+
return exports;
|
|
190
|
+
}
|
|
191
|
+
prepareContext(context) {
|
|
192
|
+
return context;
|
|
193
|
+
}
|
|
194
|
+
shouldResolveId(dep) {
|
|
195
|
+
if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
|
|
196
|
+
return false;
|
|
197
|
+
return !isAbsolute(dep) || !extname(dep);
|
|
198
|
+
}
|
|
199
|
+
shouldInterop(path, mod) {
|
|
200
|
+
if (this.options.interopDefault === false)
|
|
201
|
+
return false;
|
|
202
|
+
return !path.endsWith(".mjs") && "default" in mod;
|
|
203
|
+
}
|
|
204
|
+
async interopedImport(path) {
|
|
205
|
+
const mod = await import(path);
|
|
206
|
+
if (this.shouldInterop(path, mod)) {
|
|
207
|
+
const tryDefault = this.hasNestedDefault(mod);
|
|
208
|
+
return new Proxy(mod, {
|
|
209
|
+
get: proxyMethod("get", tryDefault),
|
|
210
|
+
set: proxyMethod("set", tryDefault),
|
|
211
|
+
has: proxyMethod("has", tryDefault),
|
|
212
|
+
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return mod;
|
|
216
|
+
}
|
|
217
|
+
hasNestedDefault(target) {
|
|
218
|
+
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function proxyMethod(name, tryDefault) {
|
|
222
|
+
return function(target, key, ...args) {
|
|
223
|
+
const result = Reflect[name](target, key, ...args);
|
|
224
|
+
if (isPrimitive(target.default))
|
|
225
|
+
return result;
|
|
226
|
+
if (tryDefault && key === "default" || typeof result === "undefined")
|
|
227
|
+
return Reflect[name](target.default, key, ...args);
|
|
228
|
+
return result;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function exportAll(exports, sourceModule) {
|
|
232
|
+
if (exports === sourceModule)
|
|
233
|
+
return;
|
|
234
|
+
for (const key in sourceModule) {
|
|
235
|
+
if (key !== "default") {
|
|
236
|
+
try {
|
|
237
|
+
Object.defineProperty(exports, key, {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
configurable: true,
|
|
240
|
+
get() {
|
|
241
|
+
return sourceModule[key];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
} catch (_err) {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const DEFAULT_TIMEOUT = 6e4;
|
|
251
|
+
function createBirpc(functions, options) {
|
|
252
|
+
const {
|
|
253
|
+
post,
|
|
254
|
+
on,
|
|
255
|
+
eventNames = [],
|
|
256
|
+
serialize = (i) => i,
|
|
257
|
+
deserialize = (i) => i,
|
|
258
|
+
timeout = DEFAULT_TIMEOUT
|
|
259
|
+
} = options;
|
|
260
|
+
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
261
|
+
const rpc = new Proxy({}, {
|
|
262
|
+
get(_, method) {
|
|
263
|
+
const sendEvent = (...args) => {
|
|
264
|
+
post(serialize({ m: method, a: args, t: "q" }));
|
|
265
|
+
};
|
|
266
|
+
if (eventNames.includes(method)) {
|
|
267
|
+
sendEvent.asEvent = sendEvent;
|
|
268
|
+
return sendEvent;
|
|
269
|
+
}
|
|
270
|
+
const sendCall = (...args) => {
|
|
271
|
+
return new Promise((resolve, reject) => {
|
|
272
|
+
const id = nanoid();
|
|
273
|
+
rpcPromiseMap.set(id, { resolve, reject });
|
|
274
|
+
post(serialize({ m: method, a: args, i: id, t: "q" }));
|
|
275
|
+
if (timeout >= 0) {
|
|
276
|
+
setTimeout(() => {
|
|
277
|
+
reject(new Error(`[birpc] timeout on calling "${method}"`));
|
|
278
|
+
rpcPromiseMap.delete(id);
|
|
279
|
+
}, timeout);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
sendCall.asEvent = sendEvent;
|
|
284
|
+
return sendCall;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
on(async (data, ...extra) => {
|
|
288
|
+
const msg = deserialize(data);
|
|
289
|
+
if (msg.t === "q") {
|
|
290
|
+
const { m: method, a: args } = msg;
|
|
291
|
+
let result, error;
|
|
292
|
+
try {
|
|
293
|
+
result = await functions[method].apply(rpc, args);
|
|
294
|
+
} catch (e) {
|
|
295
|
+
error = e;
|
|
296
|
+
}
|
|
297
|
+
if (msg.i)
|
|
298
|
+
post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
|
|
299
|
+
} else {
|
|
300
|
+
const { i: ack, r: result, e: error } = msg;
|
|
301
|
+
const promise = rpcPromiseMap.get(ack);
|
|
302
|
+
if (error)
|
|
303
|
+
promise?.reject(error);
|
|
304
|
+
else
|
|
305
|
+
promise?.resolve(result);
|
|
306
|
+
rpcPromiseMap.delete(ack);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
return rpc;
|
|
310
|
+
}
|
|
311
|
+
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
312
|
+
function nanoid(size = 21) {
|
|
313
|
+
let id = "";
|
|
314
|
+
let i = size;
|
|
315
|
+
while (i--)
|
|
316
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
|
317
|
+
return id;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { ModuleCacheMap as M, ViteNodeRunner as V, createBirpc as c };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync, promises } from 'fs';
|
|
2
|
+
import { y as resolve, p as picocolors, j as join } from './chunk-mock-date.9160e13b.mjs';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'tty';
|
|
5
|
+
import 'local-pkg';
|
|
6
|
+
|
|
7
|
+
function hashCode(s) {
|
|
8
|
+
return s.split("").reduce((a, b) => {
|
|
9
|
+
a = (a << 5) - a + b.charCodeAt(0);
|
|
10
|
+
return a & a;
|
|
11
|
+
}, 0);
|
|
12
|
+
}
|
|
13
|
+
class Debugger {
|
|
14
|
+
constructor(root, options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.externalizeMap = /* @__PURE__ */ new Map();
|
|
17
|
+
if (options.dumpModules)
|
|
18
|
+
this.dumpDir = resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
|
|
19
|
+
if (this.dumpDir) {
|
|
20
|
+
if (options.loadDumppedModules)
|
|
21
|
+
console.info(picocolors.exports.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
|
|
22
|
+
else
|
|
23
|
+
console.info(picocolors.exports.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
|
|
24
|
+
}
|
|
25
|
+
this.initPromise = this.clearDump();
|
|
26
|
+
}
|
|
27
|
+
async clearDump() {
|
|
28
|
+
if (!this.dumpDir)
|
|
29
|
+
return;
|
|
30
|
+
if (!this.options.loadDumppedModules && existsSync(this.dumpDir))
|
|
31
|
+
await promises.rm(this.dumpDir, { recursive: true, force: true });
|
|
32
|
+
await promises.mkdir(this.dumpDir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
encodeId(id) {
|
|
35
|
+
return `${id.replace(/[^\w@_-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
|
|
36
|
+
}
|
|
37
|
+
async recordExternalize(id, path) {
|
|
38
|
+
if (!this.dumpDir)
|
|
39
|
+
return;
|
|
40
|
+
this.externalizeMap.set(id, path);
|
|
41
|
+
await this.writeInfo();
|
|
42
|
+
}
|
|
43
|
+
async dumpFile(id, result) {
|
|
44
|
+
if (!result || !this.dumpDir)
|
|
45
|
+
return;
|
|
46
|
+
await this.initPromise;
|
|
47
|
+
const name = this.encodeId(id);
|
|
48
|
+
return await promises.writeFile(join(this.dumpDir, name), `// ${id.replace(/\0/g, "\\0")}
|
|
49
|
+
${result.code}`, "utf-8");
|
|
50
|
+
}
|
|
51
|
+
async loadDump(id) {
|
|
52
|
+
if (!this.dumpDir)
|
|
53
|
+
return null;
|
|
54
|
+
await this.initPromise;
|
|
55
|
+
const name = this.encodeId(id);
|
|
56
|
+
const path = join(this.dumpDir, name);
|
|
57
|
+
if (!existsSync(path))
|
|
58
|
+
return null;
|
|
59
|
+
const code = await promises.readFile(path, "utf-8");
|
|
60
|
+
return {
|
|
61
|
+
code: code.replace(/^\/\/.*?\n/, ""),
|
|
62
|
+
map: void 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async writeInfo() {
|
|
66
|
+
if (!this.dumpDir)
|
|
67
|
+
return;
|
|
68
|
+
const info = JSON.stringify({
|
|
69
|
+
time: new Date().toLocaleString(),
|
|
70
|
+
externalize: Object.fromEntries(this.externalizeMap.entries())
|
|
71
|
+
}, null, 2);
|
|
72
|
+
return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { Debugger };
|