@shopify/cli-hydrogen 7.1.0 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/hydrogen/build-vite.js +131 -0
- package/dist/commands/hydrogen/build.js +6 -15
- package/dist/commands/hydrogen/check.js +1 -1
- package/dist/commands/hydrogen/codegen.js +3 -3
- package/dist/commands/hydrogen/debug/cpu.js +1 -1
- package/dist/commands/hydrogen/deploy.js +46 -31
- package/dist/commands/hydrogen/deploy.test.js +35 -49
- package/dist/commands/hydrogen/dev-vite.js +159 -0
- package/dist/commands/hydrogen/dev.js +11 -14
- package/dist/commands/hydrogen/env/list.js +1 -1
- package/dist/commands/hydrogen/env/pull.js +3 -3
- package/dist/commands/hydrogen/env/pull.test.js +2 -0
- package/dist/commands/hydrogen/env/push__unstable.js +190 -0
- package/dist/commands/hydrogen/env/push__unstable.test.js +383 -0
- package/dist/commands/hydrogen/generate/route.js +2 -2
- package/dist/commands/hydrogen/init.d.ts +69 -0
- package/dist/commands/hydrogen/init.js +5 -5
- package/dist/commands/hydrogen/init.test.js +2 -2
- package/dist/commands/hydrogen/link.js +2 -2
- package/dist/commands/hydrogen/list.js +1 -1
- package/dist/commands/hydrogen/login.js +2 -9
- package/dist/commands/hydrogen/logout.js +1 -1
- package/dist/commands/hydrogen/preview.js +15 -7
- package/dist/commands/hydrogen/setup/css.js +3 -3
- package/dist/commands/hydrogen/setup/markets.js +4 -4
- package/dist/commands/hydrogen/setup/vite.js +209 -0
- package/dist/commands/hydrogen/setup.js +8 -6
- package/dist/commands/hydrogen/unlink.js +1 -1
- package/dist/commands/hydrogen/upgrade.js +5 -3
- package/dist/generator-templates/assets/vite/package.json +15 -0
- package/dist/generator-templates/assets/vite/vite.config.js +13 -0
- package/dist/generator-templates/starter/CHANGELOG.md +49 -0
- package/dist/generator-templates/starter/app/components/Search.tsx +12 -7
- package/dist/generator-templates/starter/app/root.tsx +1 -2
- package/dist/generator-templates/starter/app/routes/api.predictive-search.tsx +8 -15
- package/dist/generator-templates/starter/package.json +9 -8
- package/dist/generator-templates/starter/public/.gitkeep +0 -0
- package/dist/lib/build.js +2 -1
- package/dist/lib/codegen.js +8 -3
- package/dist/lib/environment-variables.test.js +4 -2
- package/dist/lib/flags.js +149 -95
- package/dist/lib/graphql/admin/pull-variables.js +1 -0
- package/dist/lib/graphql/admin/pull-variables.test.js +7 -1
- package/dist/lib/graphql/admin/push-variables.js +35 -0
- package/dist/lib/log.js +1 -0
- package/dist/lib/mini-oxygen/common.js +2 -1
- package/dist/lib/mini-oxygen/node.js +2 -2
- package/dist/lib/mini-oxygen/workerd-inspector.js +1 -1
- package/dist/lib/mini-oxygen/workerd.js +29 -17
- package/dist/lib/onboarding/common.js +0 -3
- package/dist/lib/onboarding/local.js +4 -1
- package/dist/lib/onboarding/remote.js +16 -11
- package/dist/lib/remix-config.js +1 -1
- package/dist/lib/request-events.js +3 -3
- package/dist/lib/setups/css/assets.js +7 -2
- package/dist/lib/template-diff.js +26 -11
- package/dist/lib/template-downloader.js +11 -2
- package/dist/lib/vite/hydrogen-middleware.js +82 -0
- package/dist/lib/vite/mini-oxygen.js +152 -0
- package/dist/lib/vite/plugins.d.ts +27 -0
- package/dist/lib/vite/plugins.js +139 -0
- package/dist/lib/vite/shared.js +10 -0
- package/dist/lib/vite/utils.js +55 -0
- package/dist/lib/vite/worker-entry.js +1518 -0
- package/dist/lib/vite-config.js +45 -0
- package/dist/virtual-routes/lib/useDebugNetworkServer.jsx +4 -2
- package/dist/virtual-routes/routes/index.jsx +5 -5
- package/dist/virtual-routes/routes/subrequest-profiler.jsx +1 -1
- package/dist/virtual-routes/virtual-root.jsx +1 -1
- package/oclif.manifest.json +1127 -494
- package/package.json +36 -11
- /package/dist/generator-templates/starter/{public → app/assets}/favicon.svg +0 -0
|
@@ -0,0 +1,1518 @@
|
|
|
1
|
+
// ../../node_modules/vite/dist/node/runtime.js
|
|
2
|
+
var HMRContext = class {
|
|
3
|
+
hmrClient;
|
|
4
|
+
ownerPath;
|
|
5
|
+
newListeners;
|
|
6
|
+
constructor(hmrClient, ownerPath) {
|
|
7
|
+
this.hmrClient = hmrClient;
|
|
8
|
+
this.ownerPath = ownerPath;
|
|
9
|
+
if (!hmrClient.dataMap.has(ownerPath)) {
|
|
10
|
+
hmrClient.dataMap.set(ownerPath, {});
|
|
11
|
+
}
|
|
12
|
+
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
|
13
|
+
if (mod) {
|
|
14
|
+
mod.callbacks = [];
|
|
15
|
+
}
|
|
16
|
+
const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
|
|
17
|
+
if (staleListeners) {
|
|
18
|
+
for (const [event, staleFns] of staleListeners) {
|
|
19
|
+
const listeners = hmrClient.customListenersMap.get(event);
|
|
20
|
+
if (listeners) {
|
|
21
|
+
hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
this.newListeners = /* @__PURE__ */ new Map();
|
|
26
|
+
hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
|
27
|
+
}
|
|
28
|
+
get data() {
|
|
29
|
+
return this.hmrClient.dataMap.get(this.ownerPath);
|
|
30
|
+
}
|
|
31
|
+
accept(deps, callback) {
|
|
32
|
+
if (typeof deps === "function" || !deps) {
|
|
33
|
+
this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
|
|
34
|
+
} else if (typeof deps === "string") {
|
|
35
|
+
this.acceptDeps([deps], ([mod]) => callback?.(mod));
|
|
36
|
+
} else if (Array.isArray(deps)) {
|
|
37
|
+
this.acceptDeps(deps, callback);
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error(`invalid hot.accept() usage.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// export names (first arg) are irrelevant on the client side, they're
|
|
43
|
+
// extracted in the server for propagation
|
|
44
|
+
acceptExports(_, callback) {
|
|
45
|
+
this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
|
|
46
|
+
}
|
|
47
|
+
dispose(cb) {
|
|
48
|
+
this.hmrClient.disposeMap.set(this.ownerPath, cb);
|
|
49
|
+
}
|
|
50
|
+
prune(cb) {
|
|
51
|
+
this.hmrClient.pruneMap.set(this.ownerPath, cb);
|
|
52
|
+
}
|
|
53
|
+
// Kept for backward compatibility (#11036)
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
55
|
+
decline() {
|
|
56
|
+
}
|
|
57
|
+
invalidate(message) {
|
|
58
|
+
this.hmrClient.notifyListeners("vite:invalidate", {
|
|
59
|
+
path: this.ownerPath,
|
|
60
|
+
message
|
|
61
|
+
});
|
|
62
|
+
this.send("vite:invalidate", { path: this.ownerPath, message });
|
|
63
|
+
this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
|
|
64
|
+
}
|
|
65
|
+
on(event, cb) {
|
|
66
|
+
const addToMap = (map) => {
|
|
67
|
+
const existing = map.get(event) || [];
|
|
68
|
+
existing.push(cb);
|
|
69
|
+
map.set(event, existing);
|
|
70
|
+
};
|
|
71
|
+
addToMap(this.hmrClient.customListenersMap);
|
|
72
|
+
addToMap(this.newListeners);
|
|
73
|
+
}
|
|
74
|
+
off(event, cb) {
|
|
75
|
+
const removeFromMap = (map) => {
|
|
76
|
+
const existing = map.get(event);
|
|
77
|
+
if (existing === void 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const pruned = existing.filter((l) => l !== cb);
|
|
81
|
+
if (pruned.length === 0) {
|
|
82
|
+
map.delete(event);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
map.set(event, pruned);
|
|
86
|
+
};
|
|
87
|
+
removeFromMap(this.hmrClient.customListenersMap);
|
|
88
|
+
removeFromMap(this.newListeners);
|
|
89
|
+
}
|
|
90
|
+
send(event, data) {
|
|
91
|
+
this.hmrClient.messenger.send(JSON.stringify({ type: "custom", event, data }));
|
|
92
|
+
}
|
|
93
|
+
acceptDeps(deps, callback = () => {
|
|
94
|
+
}) {
|
|
95
|
+
const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
|
|
96
|
+
id: this.ownerPath,
|
|
97
|
+
callbacks: []
|
|
98
|
+
};
|
|
99
|
+
mod.callbacks.push({
|
|
100
|
+
deps,
|
|
101
|
+
fn: callback
|
|
102
|
+
});
|
|
103
|
+
this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var HMRMessenger = class {
|
|
107
|
+
connection;
|
|
108
|
+
constructor(connection) {
|
|
109
|
+
this.connection = connection;
|
|
110
|
+
}
|
|
111
|
+
queue = [];
|
|
112
|
+
send(message) {
|
|
113
|
+
this.queue.push(message);
|
|
114
|
+
this.flush();
|
|
115
|
+
}
|
|
116
|
+
flush() {
|
|
117
|
+
if (this.connection.isReady()) {
|
|
118
|
+
this.queue.forEach((msg) => this.connection.send(msg));
|
|
119
|
+
this.queue = [];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var HMRClient = class {
|
|
124
|
+
logger;
|
|
125
|
+
importUpdatedModule;
|
|
126
|
+
hotModulesMap = /* @__PURE__ */ new Map();
|
|
127
|
+
disposeMap = /* @__PURE__ */ new Map();
|
|
128
|
+
pruneMap = /* @__PURE__ */ new Map();
|
|
129
|
+
dataMap = /* @__PURE__ */ new Map();
|
|
130
|
+
customListenersMap = /* @__PURE__ */ new Map();
|
|
131
|
+
ctxToListenersMap = /* @__PURE__ */ new Map();
|
|
132
|
+
messenger;
|
|
133
|
+
constructor(logger, connection, importUpdatedModule) {
|
|
134
|
+
this.logger = logger;
|
|
135
|
+
this.importUpdatedModule = importUpdatedModule;
|
|
136
|
+
this.messenger = new HMRMessenger(connection);
|
|
137
|
+
}
|
|
138
|
+
async notifyListeners(event, data) {
|
|
139
|
+
const cbs = this.customListenersMap.get(event);
|
|
140
|
+
if (cbs) {
|
|
141
|
+
await Promise.allSettled(cbs.map((cb) => cb(data)));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
clear() {
|
|
145
|
+
this.hotModulesMap.clear();
|
|
146
|
+
this.disposeMap.clear();
|
|
147
|
+
this.pruneMap.clear();
|
|
148
|
+
this.dataMap.clear();
|
|
149
|
+
this.customListenersMap.clear();
|
|
150
|
+
this.ctxToListenersMap.clear();
|
|
151
|
+
}
|
|
152
|
+
// After an HMR update, some modules are no longer imported on the page
|
|
153
|
+
// but they may have left behind side effects that need to be cleaned up
|
|
154
|
+
// (.e.g style injections)
|
|
155
|
+
// TODO Trigger their dispose callbacks.
|
|
156
|
+
prunePaths(paths) {
|
|
157
|
+
paths.forEach((path) => {
|
|
158
|
+
const fn = this.pruneMap.get(path);
|
|
159
|
+
if (fn) {
|
|
160
|
+
fn(this.dataMap.get(path));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
warnFailedUpdate(err, path) {
|
|
165
|
+
if (!err.message.includes("fetch")) {
|
|
166
|
+
this.logger.error(err);
|
|
167
|
+
}
|
|
168
|
+
this.logger.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
|
|
169
|
+
}
|
|
170
|
+
updateQueue = [];
|
|
171
|
+
pendingUpdateQueue = false;
|
|
172
|
+
/**
|
|
173
|
+
* buffer multiple hot updates triggered by the same src change
|
|
174
|
+
* so that they are invoked in the same order they were sent.
|
|
175
|
+
* (otherwise the order may be inconsistent because of the http request round trip)
|
|
176
|
+
*/
|
|
177
|
+
async queueUpdate(payload) {
|
|
178
|
+
this.updateQueue.push(this.fetchUpdate(payload));
|
|
179
|
+
if (!this.pendingUpdateQueue) {
|
|
180
|
+
this.pendingUpdateQueue = true;
|
|
181
|
+
await Promise.resolve();
|
|
182
|
+
this.pendingUpdateQueue = false;
|
|
183
|
+
const loading = [...this.updateQueue];
|
|
184
|
+
this.updateQueue = [];
|
|
185
|
+
(await Promise.all(loading)).forEach((fn) => fn && fn());
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async fetchUpdate(update) {
|
|
189
|
+
const { path, acceptedPath } = update;
|
|
190
|
+
const mod = this.hotModulesMap.get(path);
|
|
191
|
+
if (!mod) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
let fetchedModule;
|
|
195
|
+
const isSelfUpdate = path === acceptedPath;
|
|
196
|
+
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
|
197
|
+
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
|
198
|
+
const disposer = this.disposeMap.get(acceptedPath);
|
|
199
|
+
if (disposer)
|
|
200
|
+
await disposer(this.dataMap.get(acceptedPath));
|
|
201
|
+
try {
|
|
202
|
+
fetchedModule = await this.importUpdatedModule(update);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
this.warnFailedUpdate(e, acceptedPath);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return () => {
|
|
208
|
+
for (const { deps, fn } of qualifiedCallbacks) {
|
|
209
|
+
fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
|
|
210
|
+
}
|
|
211
|
+
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
212
|
+
this.logger.debug(`[vite] hot updated: ${loggedPath}`);
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
217
|
+
var decodeBase64 = typeof atob !== "undefined" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8");
|
|
218
|
+
var NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
219
|
+
var VALID_ID_PREFIX = `/@id/`;
|
|
220
|
+
function wrapId(id) {
|
|
221
|
+
return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
|
222
|
+
}
|
|
223
|
+
function unwrapId(id) {
|
|
224
|
+
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
|
|
225
|
+
}
|
|
226
|
+
var windowsSlashRE = /\\/g;
|
|
227
|
+
function slash(p) {
|
|
228
|
+
return p.replace(windowsSlashRE, "/");
|
|
229
|
+
}
|
|
230
|
+
var postfixRE = /[?#].*$/;
|
|
231
|
+
function cleanUrl(url) {
|
|
232
|
+
return url.replace(postfixRE, "");
|
|
233
|
+
}
|
|
234
|
+
function isPrimitive(value) {
|
|
235
|
+
return !value || typeof value !== "object" && typeof value !== "function";
|
|
236
|
+
}
|
|
237
|
+
var CHAR_FORWARD_SLASH = 47;
|
|
238
|
+
var CHAR_BACKWARD_SLASH = 92;
|
|
239
|
+
var percentRegEx = /%/g;
|
|
240
|
+
var backslashRegEx = /\\/g;
|
|
241
|
+
var newlineRegEx = /\n/g;
|
|
242
|
+
var carriageReturnRegEx = /\r/g;
|
|
243
|
+
var tabRegEx = /\t/g;
|
|
244
|
+
var questionRegex = /\?/g;
|
|
245
|
+
var hashRegex = /#/g;
|
|
246
|
+
function encodePathChars(filepath) {
|
|
247
|
+
if (filepath.indexOf("%") !== -1)
|
|
248
|
+
filepath = filepath.replace(percentRegEx, "%25");
|
|
249
|
+
if (!isWindows && filepath.indexOf("\\") !== -1)
|
|
250
|
+
filepath = filepath.replace(backslashRegEx, "%5C");
|
|
251
|
+
if (filepath.indexOf("\n") !== -1)
|
|
252
|
+
filepath = filepath.replace(newlineRegEx, "%0A");
|
|
253
|
+
if (filepath.indexOf("\r") !== -1)
|
|
254
|
+
filepath = filepath.replace(carriageReturnRegEx, "%0D");
|
|
255
|
+
if (filepath.indexOf(" ") !== -1)
|
|
256
|
+
filepath = filepath.replace(tabRegEx, "%09");
|
|
257
|
+
return filepath;
|
|
258
|
+
}
|
|
259
|
+
function posixPathToFileHref(posixPath) {
|
|
260
|
+
let resolved = posixResolve(posixPath);
|
|
261
|
+
const filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
|
262
|
+
if ((filePathLast === CHAR_FORWARD_SLASH || isWindows && filePathLast === CHAR_BACKWARD_SLASH) && resolved[resolved.length - 1] !== "/")
|
|
263
|
+
resolved += "/";
|
|
264
|
+
resolved = encodePathChars(resolved);
|
|
265
|
+
if (resolved.indexOf("?") !== -1)
|
|
266
|
+
resolved = resolved.replace(questionRegex, "%3F");
|
|
267
|
+
if (resolved.indexOf("#") !== -1)
|
|
268
|
+
resolved = resolved.replace(hashRegex, "%23");
|
|
269
|
+
return new URL(`file://${resolved}`).href;
|
|
270
|
+
}
|
|
271
|
+
function posixDirname(filepath) {
|
|
272
|
+
const normalizedPath = filepath.endsWith("/") ? filepath.substring(0, filepath.length - 1) : filepath;
|
|
273
|
+
return normalizedPath.substring(0, normalizedPath.lastIndexOf("/")) || "/";
|
|
274
|
+
}
|
|
275
|
+
function toWindowsPath(path) {
|
|
276
|
+
return path.replace(/\//g, "\\");
|
|
277
|
+
}
|
|
278
|
+
function cwd() {
|
|
279
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
280
|
+
return slash(process.cwd());
|
|
281
|
+
}
|
|
282
|
+
return "/";
|
|
283
|
+
}
|
|
284
|
+
function posixResolve(...segments) {
|
|
285
|
+
segments = segments.map((argument) => slash(argument));
|
|
286
|
+
let resolvedPath = "";
|
|
287
|
+
let resolvedAbsolute = false;
|
|
288
|
+
for (let index = segments.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
289
|
+
const path = index >= 0 ? segments[index] : cwd();
|
|
290
|
+
if (!path || path.length === 0) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
294
|
+
resolvedAbsolute = isAbsolute(path);
|
|
295
|
+
}
|
|
296
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
297
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
298
|
+
return `/${resolvedPath}`;
|
|
299
|
+
}
|
|
300
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
301
|
+
}
|
|
302
|
+
var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
303
|
+
function isAbsolute(p) {
|
|
304
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
305
|
+
}
|
|
306
|
+
function normalizeString(path, allowAboveRoot) {
|
|
307
|
+
let res = "";
|
|
308
|
+
let lastSegmentLength = 0;
|
|
309
|
+
let lastSlash = -1;
|
|
310
|
+
let dots = 0;
|
|
311
|
+
let char = null;
|
|
312
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
313
|
+
if (index < path.length) {
|
|
314
|
+
char = path[index];
|
|
315
|
+
} else if (char === "/") {
|
|
316
|
+
break;
|
|
317
|
+
} else {
|
|
318
|
+
char = "/";
|
|
319
|
+
}
|
|
320
|
+
if (char === "/") {
|
|
321
|
+
if (lastSlash === index - 1 || dots === 1)
|
|
322
|
+
;
|
|
323
|
+
else if (dots === 2) {
|
|
324
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
325
|
+
if (res.length > 2) {
|
|
326
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
327
|
+
if (lastSlashIndex === -1) {
|
|
328
|
+
res = "";
|
|
329
|
+
lastSegmentLength = 0;
|
|
330
|
+
} else {
|
|
331
|
+
res = res.slice(0, lastSlashIndex);
|
|
332
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
333
|
+
}
|
|
334
|
+
lastSlash = index;
|
|
335
|
+
dots = 0;
|
|
336
|
+
continue;
|
|
337
|
+
} else if (res.length > 0) {
|
|
338
|
+
res = "";
|
|
339
|
+
lastSegmentLength = 0;
|
|
340
|
+
lastSlash = index;
|
|
341
|
+
dots = 0;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (allowAboveRoot) {
|
|
346
|
+
res += res.length > 0 ? "/.." : "..";
|
|
347
|
+
lastSegmentLength = 2;
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
if (res.length > 0) {
|
|
351
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
352
|
+
} else {
|
|
353
|
+
res = path.slice(lastSlash + 1, index);
|
|
354
|
+
}
|
|
355
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
356
|
+
}
|
|
357
|
+
lastSlash = index;
|
|
358
|
+
dots = 0;
|
|
359
|
+
} else if (char === "." && dots !== -1) {
|
|
360
|
+
++dots;
|
|
361
|
+
} else {
|
|
362
|
+
dots = -1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return res;
|
|
366
|
+
}
|
|
367
|
+
var DecodedMap = class {
|
|
368
|
+
map;
|
|
369
|
+
_encoded;
|
|
370
|
+
_decoded;
|
|
371
|
+
_decodedMemo;
|
|
372
|
+
url;
|
|
373
|
+
version;
|
|
374
|
+
names = [];
|
|
375
|
+
resolvedSources;
|
|
376
|
+
constructor(map, from) {
|
|
377
|
+
this.map = map;
|
|
378
|
+
const { mappings, names, sources } = map;
|
|
379
|
+
this.version = map.version;
|
|
380
|
+
this.names = names || [];
|
|
381
|
+
this._encoded = mappings || "";
|
|
382
|
+
this._decodedMemo = memoizedState();
|
|
383
|
+
this.url = from;
|
|
384
|
+
this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
function indexOf(mappings, index) {
|
|
388
|
+
const idx = mappings.indexOf(";", index);
|
|
389
|
+
return idx === -1 ? mappings.length : idx;
|
|
390
|
+
}
|
|
391
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
392
|
+
var charToInt = new Uint8Array(128);
|
|
393
|
+
for (let i = 0; i < chars.length; i++) {
|
|
394
|
+
const c = chars.charCodeAt(i);
|
|
395
|
+
charToInt[c] = i;
|
|
396
|
+
}
|
|
397
|
+
function decodeInteger(mappings, pos, state, j) {
|
|
398
|
+
let value = 0;
|
|
399
|
+
let shift = 0;
|
|
400
|
+
let integer = 0;
|
|
401
|
+
do {
|
|
402
|
+
const c = mappings.charCodeAt(pos++);
|
|
403
|
+
integer = charToInt[c];
|
|
404
|
+
value |= (integer & 31) << shift;
|
|
405
|
+
shift += 5;
|
|
406
|
+
} while (integer & 32);
|
|
407
|
+
const shouldNegate = value & 1;
|
|
408
|
+
value >>>= 1;
|
|
409
|
+
if (shouldNegate) {
|
|
410
|
+
value = -2147483648 | -value;
|
|
411
|
+
}
|
|
412
|
+
state[j] += value;
|
|
413
|
+
return pos;
|
|
414
|
+
}
|
|
415
|
+
var comma = ",".charCodeAt(0);
|
|
416
|
+
function hasMoreVlq(mappings, i, length) {
|
|
417
|
+
if (i >= length)
|
|
418
|
+
return false;
|
|
419
|
+
return mappings.charCodeAt(i) !== comma;
|
|
420
|
+
}
|
|
421
|
+
function decode(mappings) {
|
|
422
|
+
const state = new Int32Array(5);
|
|
423
|
+
const decoded = [];
|
|
424
|
+
let index = 0;
|
|
425
|
+
do {
|
|
426
|
+
const semi = indexOf(mappings, index);
|
|
427
|
+
const line = [];
|
|
428
|
+
let sorted = true;
|
|
429
|
+
let lastCol = 0;
|
|
430
|
+
state[0] = 0;
|
|
431
|
+
for (let i = index; i < semi; i++) {
|
|
432
|
+
let seg;
|
|
433
|
+
i = decodeInteger(mappings, i, state, 0);
|
|
434
|
+
const col = state[0];
|
|
435
|
+
if (col < lastCol)
|
|
436
|
+
sorted = false;
|
|
437
|
+
lastCol = col;
|
|
438
|
+
if (hasMoreVlq(mappings, i, semi)) {
|
|
439
|
+
i = decodeInteger(mappings, i, state, 1);
|
|
440
|
+
i = decodeInteger(mappings, i, state, 2);
|
|
441
|
+
i = decodeInteger(mappings, i, state, 3);
|
|
442
|
+
if (hasMoreVlq(mappings, i, semi)) {
|
|
443
|
+
i = decodeInteger(mappings, i, state, 4);
|
|
444
|
+
seg = [col, state[1], state[2], state[3], state[4]];
|
|
445
|
+
} else {
|
|
446
|
+
seg = [col, state[1], state[2], state[3]];
|
|
447
|
+
}
|
|
448
|
+
} else {
|
|
449
|
+
seg = [col];
|
|
450
|
+
}
|
|
451
|
+
line.push(seg);
|
|
452
|
+
}
|
|
453
|
+
if (!sorted)
|
|
454
|
+
line.sort((a, b) => a[0] - b[0]);
|
|
455
|
+
decoded.push(line);
|
|
456
|
+
index = semi + 1;
|
|
457
|
+
} while (index <= mappings.length);
|
|
458
|
+
return decoded;
|
|
459
|
+
}
|
|
460
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
461
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
462
|
+
var COLUMN = 0;
|
|
463
|
+
var SOURCES_INDEX = 1;
|
|
464
|
+
var SOURCE_LINE = 2;
|
|
465
|
+
var SOURCE_COLUMN = 3;
|
|
466
|
+
var NAMES_INDEX = 4;
|
|
467
|
+
function OMapping(source, line, column, name) {
|
|
468
|
+
return { source, line, column, name };
|
|
469
|
+
}
|
|
470
|
+
function decodedMappings(map) {
|
|
471
|
+
return map._decoded || (map._decoded = decode(map._encoded));
|
|
472
|
+
}
|
|
473
|
+
var found = false;
|
|
474
|
+
function binarySearch(haystack, needle, low, high) {
|
|
475
|
+
while (low <= high) {
|
|
476
|
+
const mid = low + (high - low >> 1);
|
|
477
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
478
|
+
if (cmp === 0) {
|
|
479
|
+
found = true;
|
|
480
|
+
return mid;
|
|
481
|
+
}
|
|
482
|
+
if (cmp < 0) {
|
|
483
|
+
low = mid + 1;
|
|
484
|
+
} else {
|
|
485
|
+
high = mid - 1;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
found = false;
|
|
489
|
+
return low - 1;
|
|
490
|
+
}
|
|
491
|
+
function lowerBound(haystack, needle, index) {
|
|
492
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
493
|
+
if (haystack[i][COLUMN] !== needle)
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
return index;
|
|
497
|
+
}
|
|
498
|
+
function memoizedState() {
|
|
499
|
+
return {
|
|
500
|
+
lastKey: -1,
|
|
501
|
+
lastNeedle: -1,
|
|
502
|
+
lastIndex: -1
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
506
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
507
|
+
let low = 0;
|
|
508
|
+
let high = haystack.length - 1;
|
|
509
|
+
if (key === lastKey) {
|
|
510
|
+
if (needle === lastNeedle) {
|
|
511
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
512
|
+
return lastIndex;
|
|
513
|
+
}
|
|
514
|
+
if (needle >= lastNeedle) {
|
|
515
|
+
low = lastIndex === -1 ? 0 : lastIndex;
|
|
516
|
+
} else {
|
|
517
|
+
high = lastIndex;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
state.lastKey = key;
|
|
521
|
+
state.lastNeedle = needle;
|
|
522
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
523
|
+
}
|
|
524
|
+
function traceSegmentInternal(segments, memo, line, column) {
|
|
525
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
526
|
+
if (found) {
|
|
527
|
+
index = lowerBound(segments, column, index);
|
|
528
|
+
}
|
|
529
|
+
if (index === -1 || index === segments.length)
|
|
530
|
+
return -1;
|
|
531
|
+
return index;
|
|
532
|
+
}
|
|
533
|
+
function getOriginalPosition(map, { line, column }) {
|
|
534
|
+
line--;
|
|
535
|
+
if (line < 0)
|
|
536
|
+
throw new Error(LINE_GTR_ZERO);
|
|
537
|
+
if (column < 0)
|
|
538
|
+
throw new Error(COL_GTR_EQ_ZERO);
|
|
539
|
+
map._decodedMemo ??= memoizedState();
|
|
540
|
+
const decoded = decodedMappings(map);
|
|
541
|
+
if (line >= decoded.length)
|
|
542
|
+
return null;
|
|
543
|
+
const segments = decoded[line];
|
|
544
|
+
const index = traceSegmentInternal(segments, map._decodedMemo, line, column);
|
|
545
|
+
if (index === -1)
|
|
546
|
+
return null;
|
|
547
|
+
const segment = segments[index];
|
|
548
|
+
if (segment.length === 1)
|
|
549
|
+
return null;
|
|
550
|
+
const { names, resolvedSources } = map;
|
|
551
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
|
552
|
+
}
|
|
553
|
+
var SOURCEMAPPING_URL = "sourceMa";
|
|
554
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
555
|
+
var VITE_RUNTIME_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
|
556
|
+
var VITE_RUNTIME_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_RUNTIME_SOURCEMAPPING_URL};base64,(.+)`);
|
|
557
|
+
var ModuleCacheMap = class extends Map {
|
|
558
|
+
root;
|
|
559
|
+
constructor(root, entries) {
|
|
560
|
+
super(entries);
|
|
561
|
+
this.root = withTrailingSlash(root);
|
|
562
|
+
}
|
|
563
|
+
normalize(fsPath) {
|
|
564
|
+
return normalizeModuleId(fsPath, this.root);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Assign partial data to the map
|
|
568
|
+
*/
|
|
569
|
+
update(fsPath, mod) {
|
|
570
|
+
fsPath = this.normalize(fsPath);
|
|
571
|
+
if (!super.has(fsPath))
|
|
572
|
+
this.setByModuleId(fsPath, mod);
|
|
573
|
+
else
|
|
574
|
+
Object.assign(super.get(fsPath), mod);
|
|
575
|
+
return this;
|
|
576
|
+
}
|
|
577
|
+
setByModuleId(modulePath, mod) {
|
|
578
|
+
return super.set(modulePath, mod);
|
|
579
|
+
}
|
|
580
|
+
set(fsPath, mod) {
|
|
581
|
+
return this.setByModuleId(this.normalize(fsPath), mod);
|
|
582
|
+
}
|
|
583
|
+
getByModuleId(modulePath) {
|
|
584
|
+
if (!super.has(modulePath))
|
|
585
|
+
this.setByModuleId(modulePath, {});
|
|
586
|
+
const mod = super.get(modulePath);
|
|
587
|
+
if (!mod.imports) {
|
|
588
|
+
Object.assign(mod, {
|
|
589
|
+
imports: /* @__PURE__ */ new Set(),
|
|
590
|
+
importers: /* @__PURE__ */ new Set()
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
return mod;
|
|
594
|
+
}
|
|
595
|
+
get(fsPath) {
|
|
596
|
+
return this.getByModuleId(this.normalize(fsPath));
|
|
597
|
+
}
|
|
598
|
+
deleteByModuleId(modulePath) {
|
|
599
|
+
return super.delete(modulePath);
|
|
600
|
+
}
|
|
601
|
+
delete(fsPath) {
|
|
602
|
+
return this.deleteByModuleId(this.normalize(fsPath));
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Invalidate modules that dependent on the given modules, up to the main entry
|
|
606
|
+
*/
|
|
607
|
+
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
|
608
|
+
for (const _id of ids) {
|
|
609
|
+
const id = this.normalize(_id);
|
|
610
|
+
if (invalidated.has(id))
|
|
611
|
+
continue;
|
|
612
|
+
invalidated.add(id);
|
|
613
|
+
const mod = super.get(id);
|
|
614
|
+
if (mod?.importers)
|
|
615
|
+
this.invalidateDepTree(mod.importers, invalidated);
|
|
616
|
+
super.delete(id);
|
|
617
|
+
}
|
|
618
|
+
return invalidated;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Invalidate dependency modules of the given modules, down to the bottom-level dependencies
|
|
622
|
+
*/
|
|
623
|
+
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
|
624
|
+
for (const _id of ids) {
|
|
625
|
+
const id = this.normalize(_id);
|
|
626
|
+
if (invalidated.has(id))
|
|
627
|
+
continue;
|
|
628
|
+
invalidated.add(id);
|
|
629
|
+
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
|
630
|
+
subIds.length && this.invalidateSubDepTree(subIds, invalidated);
|
|
631
|
+
super.delete(id);
|
|
632
|
+
}
|
|
633
|
+
return invalidated;
|
|
634
|
+
}
|
|
635
|
+
getSourceMap(moduleId) {
|
|
636
|
+
const mod = this.get(moduleId);
|
|
637
|
+
if (mod.map)
|
|
638
|
+
return mod.map;
|
|
639
|
+
if (!mod.meta || !("code" in mod.meta))
|
|
640
|
+
return null;
|
|
641
|
+
const mapString = mod.meta.code.match(VITE_RUNTIME_SOURCEMAPPING_REGEXP)?.[1];
|
|
642
|
+
if (!mapString)
|
|
643
|
+
return null;
|
|
644
|
+
const baseFile = mod.meta.file || moduleId.split("?")[0];
|
|
645
|
+
mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), baseFile);
|
|
646
|
+
return mod.map;
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
function withTrailingSlash(path) {
|
|
650
|
+
if (path[path.length - 1] !== "/") {
|
|
651
|
+
return `${path}/`;
|
|
652
|
+
}
|
|
653
|
+
return path;
|
|
654
|
+
}
|
|
655
|
+
var prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
|
656
|
+
function normalizeModuleId(file, root) {
|
|
657
|
+
if (prefixedBuiltins.has(file))
|
|
658
|
+
return file;
|
|
659
|
+
let unixFile = file.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
660
|
+
if (unixFile.startsWith(root)) {
|
|
661
|
+
unixFile = unixFile.slice(root.length - 1);
|
|
662
|
+
}
|
|
663
|
+
return unixFile.replace(/^file:\//, "/");
|
|
664
|
+
}
|
|
665
|
+
var ssrModuleExportsKey = `__vite_ssr_exports__`;
|
|
666
|
+
var ssrImportKey = `__vite_ssr_import__`;
|
|
667
|
+
var ssrDynamicImportKey = `__vite_ssr_dynamic_import__`;
|
|
668
|
+
var ssrExportAllKey = `__vite_ssr_exportAll__`;
|
|
669
|
+
var ssrImportMetaKey = `__vite_ssr_import_meta__`;
|
|
670
|
+
var noop = () => {
|
|
671
|
+
};
|
|
672
|
+
var silentConsole = {
|
|
673
|
+
debug: noop,
|
|
674
|
+
error: noop
|
|
675
|
+
};
|
|
676
|
+
function createHMRHandler(runtime2) {
|
|
677
|
+
const queue = new Queue();
|
|
678
|
+
return (payload) => queue.enqueue(() => handleHMRPayload(runtime2, payload));
|
|
679
|
+
}
|
|
680
|
+
async function handleHMRPayload(runtime2, payload) {
|
|
681
|
+
const hmrClient = runtime2.hmrClient;
|
|
682
|
+
if (!hmrClient || runtime2.isDestroyed())
|
|
683
|
+
return;
|
|
684
|
+
switch (payload.type) {
|
|
685
|
+
case "connected":
|
|
686
|
+
hmrClient.logger.debug(`[vite] connected.`);
|
|
687
|
+
hmrClient.messenger.flush();
|
|
688
|
+
break;
|
|
689
|
+
case "update":
|
|
690
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload);
|
|
691
|
+
await Promise.all(payload.updates.map(async (update) => {
|
|
692
|
+
if (update.type === "js-update") {
|
|
693
|
+
update.acceptedPath = unwrapId(update.acceptedPath);
|
|
694
|
+
update.path = unwrapId(update.path);
|
|
695
|
+
return hmrClient.queueUpdate(update);
|
|
696
|
+
}
|
|
697
|
+
hmrClient.logger.error("[vite] css hmr is not supported in runtime mode.");
|
|
698
|
+
}));
|
|
699
|
+
await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
|
700
|
+
break;
|
|
701
|
+
case "custom": {
|
|
702
|
+
await hmrClient.notifyListeners(payload.event, payload.data);
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
case "full-reload":
|
|
706
|
+
hmrClient.logger.debug(`[vite] program reload`);
|
|
707
|
+
await hmrClient.notifyListeners("vite:beforeFullReload", payload);
|
|
708
|
+
Array.from(runtime2.moduleCache.keys()).forEach((id) => {
|
|
709
|
+
if (!id.includes("node_modules")) {
|
|
710
|
+
runtime2.moduleCache.deleteByModuleId(id);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
for (const id of runtime2.entrypoints) {
|
|
714
|
+
await runtime2.executeUrl(id);
|
|
715
|
+
}
|
|
716
|
+
break;
|
|
717
|
+
case "prune":
|
|
718
|
+
await hmrClient.notifyListeners("vite:beforePrune", payload);
|
|
719
|
+
hmrClient.prunePaths(payload.paths);
|
|
720
|
+
break;
|
|
721
|
+
case "error": {
|
|
722
|
+
await hmrClient.notifyListeners("vite:error", payload);
|
|
723
|
+
const err = payload.err;
|
|
724
|
+
hmrClient.logger.error(`[vite] Internal Server Error
|
|
725
|
+
${err.message}
|
|
726
|
+
${err.stack}`);
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
default: {
|
|
730
|
+
const check = payload;
|
|
731
|
+
return check;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
var Queue = class {
|
|
736
|
+
queue = [];
|
|
737
|
+
pending = false;
|
|
738
|
+
enqueue(promise) {
|
|
739
|
+
return new Promise((resolve, reject) => {
|
|
740
|
+
this.queue.push({
|
|
741
|
+
promise,
|
|
742
|
+
resolve,
|
|
743
|
+
reject
|
|
744
|
+
});
|
|
745
|
+
this.dequeue();
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
dequeue() {
|
|
749
|
+
if (this.pending) {
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
const item = this.queue.shift();
|
|
753
|
+
if (!item) {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
this.pending = true;
|
|
757
|
+
item.promise().then(item.resolve).catch(item.reject).finally(() => {
|
|
758
|
+
this.pending = false;
|
|
759
|
+
this.dequeue();
|
|
760
|
+
});
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
var sourceMapCache = {};
|
|
765
|
+
var fileContentsCache = {};
|
|
766
|
+
var moduleGraphs = /* @__PURE__ */ new Set();
|
|
767
|
+
var retrieveFileHandlers = /* @__PURE__ */ new Set();
|
|
768
|
+
var retrieveSourceMapHandlers = /* @__PURE__ */ new Set();
|
|
769
|
+
var createExecHandlers = (handlers) => {
|
|
770
|
+
return (...args) => {
|
|
771
|
+
for (const handler of handlers) {
|
|
772
|
+
const result = handler(...args);
|
|
773
|
+
if (result)
|
|
774
|
+
return result;
|
|
775
|
+
}
|
|
776
|
+
return null;
|
|
777
|
+
};
|
|
778
|
+
};
|
|
779
|
+
var retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers);
|
|
780
|
+
var retrievSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
|
|
781
|
+
var overriden = false;
|
|
782
|
+
var originalPrepare = Error.prepareStackTrace;
|
|
783
|
+
function resetInterceptor(runtime2, options) {
|
|
784
|
+
moduleGraphs.delete(runtime2.moduleCache);
|
|
785
|
+
if (options.retrieveFile)
|
|
786
|
+
retrieveFileHandlers.delete(options.retrieveFile);
|
|
787
|
+
if (options.retrieveSourceMap)
|
|
788
|
+
retrieveSourceMapHandlers.delete(options.retrieveSourceMap);
|
|
789
|
+
if (moduleGraphs.size === 0) {
|
|
790
|
+
Error.prepareStackTrace = originalPrepare;
|
|
791
|
+
overriden = false;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function interceptStackTrace(runtime2, options = {}) {
|
|
795
|
+
if (!overriden) {
|
|
796
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
797
|
+
overriden = true;
|
|
798
|
+
}
|
|
799
|
+
moduleGraphs.add(runtime2.moduleCache);
|
|
800
|
+
if (options.retrieveFile)
|
|
801
|
+
retrieveFileHandlers.add(options.retrieveFile);
|
|
802
|
+
if (options.retrieveSourceMap)
|
|
803
|
+
retrieveSourceMapHandlers.add(options.retrieveSourceMap);
|
|
804
|
+
return () => resetInterceptor(runtime2, options);
|
|
805
|
+
}
|
|
806
|
+
function supportRelativeURL(file, url) {
|
|
807
|
+
if (!file)
|
|
808
|
+
return url;
|
|
809
|
+
const dir = posixDirname(file.replace(/\\/g, "/"));
|
|
810
|
+
const match = /^\w+:\/\/[^/]*/.exec(dir);
|
|
811
|
+
let protocol = match ? match[0] : "";
|
|
812
|
+
const startPath = dir.slice(protocol.length);
|
|
813
|
+
if (protocol && /^\/\w:/.test(startPath)) {
|
|
814
|
+
protocol += "/";
|
|
815
|
+
return protocol + posixResolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
|
|
816
|
+
}
|
|
817
|
+
return protocol + posixResolve(dir.slice(protocol.length), url);
|
|
818
|
+
}
|
|
819
|
+
function getRuntimeSourceMap(position) {
|
|
820
|
+
for (const moduleCache of moduleGraphs) {
|
|
821
|
+
const sourceMap = moduleCache.getSourceMap(position.source);
|
|
822
|
+
if (sourceMap) {
|
|
823
|
+
return {
|
|
824
|
+
url: position.source,
|
|
825
|
+
map: sourceMap,
|
|
826
|
+
vite: true
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
function retrieveFile(path) {
|
|
833
|
+
if (path in fileContentsCache)
|
|
834
|
+
return fileContentsCache[path];
|
|
835
|
+
const content = retrieveFileFromHandlers(path);
|
|
836
|
+
if (typeof content === "string") {
|
|
837
|
+
fileContentsCache[path] = content;
|
|
838
|
+
return content;
|
|
839
|
+
}
|
|
840
|
+
return null;
|
|
841
|
+
}
|
|
842
|
+
function retrieveSourceMapURL(source) {
|
|
843
|
+
const fileData = retrieveFile(source);
|
|
844
|
+
if (!fileData)
|
|
845
|
+
return null;
|
|
846
|
+
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
|
847
|
+
let lastMatch, match;
|
|
848
|
+
while (match = re.exec(fileData))
|
|
849
|
+
lastMatch = match;
|
|
850
|
+
if (!lastMatch)
|
|
851
|
+
return null;
|
|
852
|
+
return lastMatch[1];
|
|
853
|
+
}
|
|
854
|
+
var reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
855
|
+
function retrieveSourceMap(source) {
|
|
856
|
+
const urlAndMap = retrievSourceMapFromHandlers(source);
|
|
857
|
+
if (urlAndMap)
|
|
858
|
+
return urlAndMap;
|
|
859
|
+
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
860
|
+
if (!sourceMappingURL)
|
|
861
|
+
return null;
|
|
862
|
+
let sourceMapData;
|
|
863
|
+
if (reSourceMap.test(sourceMappingURL)) {
|
|
864
|
+
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
865
|
+
sourceMapData = Buffer.from(rawData, "base64").toString();
|
|
866
|
+
sourceMappingURL = source;
|
|
867
|
+
} else {
|
|
868
|
+
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
|
869
|
+
sourceMapData = retrieveFile(sourceMappingURL);
|
|
870
|
+
}
|
|
871
|
+
if (!sourceMapData)
|
|
872
|
+
return null;
|
|
873
|
+
return {
|
|
874
|
+
url: sourceMappingURL,
|
|
875
|
+
map: sourceMapData
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
function mapSourcePosition(position) {
|
|
879
|
+
if (!position.source)
|
|
880
|
+
return position;
|
|
881
|
+
let sourceMap = getRuntimeSourceMap(position);
|
|
882
|
+
if (!sourceMap)
|
|
883
|
+
sourceMap = sourceMapCache[position.source];
|
|
884
|
+
if (!sourceMap) {
|
|
885
|
+
const urlAndMap = retrieveSourceMap(position.source);
|
|
886
|
+
if (urlAndMap && urlAndMap.map) {
|
|
887
|
+
const url = urlAndMap.url;
|
|
888
|
+
sourceMap = sourceMapCache[position.source] = {
|
|
889
|
+
url,
|
|
890
|
+
map: new DecodedMap(typeof urlAndMap.map === "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map, url)
|
|
891
|
+
};
|
|
892
|
+
const contents = sourceMap.map?.map.sourcesContent;
|
|
893
|
+
if (sourceMap.map && contents) {
|
|
894
|
+
sourceMap.map.resolvedSources.forEach((source, i) => {
|
|
895
|
+
const content = contents[i];
|
|
896
|
+
if (content && source && url) {
|
|
897
|
+
const contentUrl = supportRelativeURL(url, source);
|
|
898
|
+
fileContentsCache[contentUrl] = content;
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
} else {
|
|
903
|
+
sourceMap = sourceMapCache[position.source] = {
|
|
904
|
+
url: null,
|
|
905
|
+
map: null
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
if (sourceMap && sourceMap.map && sourceMap.url) {
|
|
910
|
+
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
|
911
|
+
if (originalPosition && originalPosition.source != null) {
|
|
912
|
+
originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
|
|
913
|
+
if (sourceMap.vite) {
|
|
914
|
+
originalPosition._vite = true;
|
|
915
|
+
}
|
|
916
|
+
return originalPosition;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return position;
|
|
920
|
+
}
|
|
921
|
+
function mapEvalOrigin(origin) {
|
|
922
|
+
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
|
923
|
+
if (match) {
|
|
924
|
+
const position = mapSourcePosition({
|
|
925
|
+
name: null,
|
|
926
|
+
source: match[2],
|
|
927
|
+
line: +match[3],
|
|
928
|
+
column: +match[4] - 1
|
|
929
|
+
});
|
|
930
|
+
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
931
|
+
}
|
|
932
|
+
match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
|
933
|
+
if (match)
|
|
934
|
+
return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
|
|
935
|
+
return origin;
|
|
936
|
+
}
|
|
937
|
+
function CallSiteToString() {
|
|
938
|
+
let fileName;
|
|
939
|
+
let fileLocation = "";
|
|
940
|
+
if (this.isNative()) {
|
|
941
|
+
fileLocation = "native";
|
|
942
|
+
} else {
|
|
943
|
+
fileName = this.getScriptNameOrSourceURL();
|
|
944
|
+
if (!fileName && this.isEval()) {
|
|
945
|
+
fileLocation = this.getEvalOrigin();
|
|
946
|
+
fileLocation += ", ";
|
|
947
|
+
}
|
|
948
|
+
if (fileName) {
|
|
949
|
+
fileLocation += fileName;
|
|
950
|
+
} else {
|
|
951
|
+
fileLocation += "<anonymous>";
|
|
952
|
+
}
|
|
953
|
+
const lineNumber = this.getLineNumber();
|
|
954
|
+
if (lineNumber != null) {
|
|
955
|
+
fileLocation += `:${lineNumber}`;
|
|
956
|
+
const columnNumber = this.getColumnNumber();
|
|
957
|
+
if (columnNumber)
|
|
958
|
+
fileLocation += `:${columnNumber}`;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
let line = "";
|
|
962
|
+
const functionName = this.getFunctionName();
|
|
963
|
+
let addSuffix = true;
|
|
964
|
+
const isConstructor = this.isConstructor();
|
|
965
|
+
const isMethodCall = !(this.isToplevel() || isConstructor);
|
|
966
|
+
if (isMethodCall) {
|
|
967
|
+
let typeName = this.getTypeName();
|
|
968
|
+
if (typeName === "[object Object]")
|
|
969
|
+
typeName = "null";
|
|
970
|
+
const methodName = this.getMethodName();
|
|
971
|
+
if (functionName) {
|
|
972
|
+
if (typeName && functionName.indexOf(typeName) !== 0)
|
|
973
|
+
line += `${typeName}.`;
|
|
974
|
+
line += functionName;
|
|
975
|
+
if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1)
|
|
976
|
+
line += ` [as ${methodName}]`;
|
|
977
|
+
} else {
|
|
978
|
+
line += `${typeName}.${methodName || "<anonymous>"}`;
|
|
979
|
+
}
|
|
980
|
+
} else if (isConstructor) {
|
|
981
|
+
line += `new ${functionName || "<anonymous>"}`;
|
|
982
|
+
} else if (functionName) {
|
|
983
|
+
line += functionName;
|
|
984
|
+
} else {
|
|
985
|
+
line += fileLocation;
|
|
986
|
+
addSuffix = false;
|
|
987
|
+
}
|
|
988
|
+
if (addSuffix)
|
|
989
|
+
line += ` (${fileLocation})`;
|
|
990
|
+
return line;
|
|
991
|
+
}
|
|
992
|
+
function cloneCallSite(frame) {
|
|
993
|
+
const object = {};
|
|
994
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
995
|
+
const key = name;
|
|
996
|
+
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
997
|
+
return frame[key].call(frame);
|
|
998
|
+
} : frame[key];
|
|
999
|
+
});
|
|
1000
|
+
object.toString = CallSiteToString;
|
|
1001
|
+
return object;
|
|
1002
|
+
}
|
|
1003
|
+
function wrapCallSite(frame, state) {
|
|
1004
|
+
if (state === void 0)
|
|
1005
|
+
state = { nextPosition: null, curPosition: null };
|
|
1006
|
+
if (frame.isNative()) {
|
|
1007
|
+
state.curPosition = null;
|
|
1008
|
+
return frame;
|
|
1009
|
+
}
|
|
1010
|
+
const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
1011
|
+
if (source) {
|
|
1012
|
+
const line = frame.getLineNumber();
|
|
1013
|
+
let column = frame.getColumnNumber() - 1;
|
|
1014
|
+
const headerLength = 62;
|
|
1015
|
+
if (line === 1 && column > headerLength && !frame.isEval())
|
|
1016
|
+
column -= headerLength;
|
|
1017
|
+
const position = mapSourcePosition({
|
|
1018
|
+
name: null,
|
|
1019
|
+
source,
|
|
1020
|
+
line,
|
|
1021
|
+
column
|
|
1022
|
+
});
|
|
1023
|
+
state.curPosition = position;
|
|
1024
|
+
frame = cloneCallSite(frame);
|
|
1025
|
+
const originalFunctionName = frame.getFunctionName;
|
|
1026
|
+
frame.getFunctionName = function() {
|
|
1027
|
+
const name = (() => {
|
|
1028
|
+
if (state.nextPosition == null)
|
|
1029
|
+
return originalFunctionName();
|
|
1030
|
+
return state.nextPosition.name || originalFunctionName();
|
|
1031
|
+
})();
|
|
1032
|
+
return name === "eval" && "_vite" in position ? null : name;
|
|
1033
|
+
};
|
|
1034
|
+
frame.getFileName = function() {
|
|
1035
|
+
return position.source ?? void 0;
|
|
1036
|
+
};
|
|
1037
|
+
frame.getLineNumber = function() {
|
|
1038
|
+
return position.line;
|
|
1039
|
+
};
|
|
1040
|
+
frame.getColumnNumber = function() {
|
|
1041
|
+
return position.column + 1;
|
|
1042
|
+
};
|
|
1043
|
+
frame.getScriptNameOrSourceURL = function() {
|
|
1044
|
+
return position.source;
|
|
1045
|
+
};
|
|
1046
|
+
return frame;
|
|
1047
|
+
}
|
|
1048
|
+
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
1049
|
+
if (origin) {
|
|
1050
|
+
origin = mapEvalOrigin(origin);
|
|
1051
|
+
frame = cloneCallSite(frame);
|
|
1052
|
+
frame.getEvalOrigin = function() {
|
|
1053
|
+
return origin || void 0;
|
|
1054
|
+
};
|
|
1055
|
+
return frame;
|
|
1056
|
+
}
|
|
1057
|
+
return frame;
|
|
1058
|
+
}
|
|
1059
|
+
function prepareStackTrace(error, stack) {
|
|
1060
|
+
const name = error.name || "Error";
|
|
1061
|
+
const message = error.message || "";
|
|
1062
|
+
const errorString = `${name}: ${message}`;
|
|
1063
|
+
const state = { nextPosition: null, curPosition: null };
|
|
1064
|
+
const processedStack = [];
|
|
1065
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
1066
|
+
processedStack.push(`
|
|
1067
|
+
at ${wrapCallSite(stack[i], state)}`);
|
|
1068
|
+
state.nextPosition = state.curPosition;
|
|
1069
|
+
}
|
|
1070
|
+
state.curPosition = state.nextPosition = null;
|
|
1071
|
+
return errorString + processedStack.reverse().join("");
|
|
1072
|
+
}
|
|
1073
|
+
function enableSourceMapSupport(runtime2) {
|
|
1074
|
+
if (runtime2.options.sourcemapInterceptor === "node") {
|
|
1075
|
+
if (typeof process === "undefined") {
|
|
1076
|
+
throw new TypeError(`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`);
|
|
1077
|
+
}
|
|
1078
|
+
if (typeof process.setSourceMapsEnabled !== "function") {
|
|
1079
|
+
throw new TypeError(`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`);
|
|
1080
|
+
}
|
|
1081
|
+
const isEnabledAlready = process.sourceMapsEnabled ?? false;
|
|
1082
|
+
process.setSourceMapsEnabled(true);
|
|
1083
|
+
return () => !isEnabledAlready && process.setSourceMapsEnabled(false);
|
|
1084
|
+
}
|
|
1085
|
+
return interceptStackTrace(runtime2, typeof runtime2.options.sourcemapInterceptor === "object" ? runtime2.options.sourcemapInterceptor : void 0);
|
|
1086
|
+
}
|
|
1087
|
+
var ViteRuntime = class {
|
|
1088
|
+
options;
|
|
1089
|
+
runner;
|
|
1090
|
+
debug;
|
|
1091
|
+
/**
|
|
1092
|
+
* Holds the cache of modules
|
|
1093
|
+
* Keys of the map are ids
|
|
1094
|
+
*/
|
|
1095
|
+
moduleCache;
|
|
1096
|
+
hmrClient;
|
|
1097
|
+
entrypoints = /* @__PURE__ */ new Set();
|
|
1098
|
+
idToUrlMap = /* @__PURE__ */ new Map();
|
|
1099
|
+
fileToIdMap = /* @__PURE__ */ new Map();
|
|
1100
|
+
envProxy = new Proxy({}, {
|
|
1101
|
+
get(_, p) {
|
|
1102
|
+
throw new Error(`[vite-runtime] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
_destroyed = false;
|
|
1106
|
+
_resetSourceMapSupport;
|
|
1107
|
+
constructor(options, runner, debug) {
|
|
1108
|
+
this.options = options;
|
|
1109
|
+
this.runner = runner;
|
|
1110
|
+
this.debug = debug;
|
|
1111
|
+
this.moduleCache = options.moduleCache ?? new ModuleCacheMap(options.root);
|
|
1112
|
+
if (typeof options.hmr === "object") {
|
|
1113
|
+
this.hmrClient = new HMRClient(options.hmr.logger === false ? silentConsole : options.hmr.logger || console, options.hmr.connection, ({ acceptedPath, ssrInvalidates }) => {
|
|
1114
|
+
this.moduleCache.delete(acceptedPath);
|
|
1115
|
+
if (ssrInvalidates) {
|
|
1116
|
+
this.invalidateFiles(ssrInvalidates);
|
|
1117
|
+
}
|
|
1118
|
+
return this.executeUrl(acceptedPath);
|
|
1119
|
+
});
|
|
1120
|
+
options.hmr.connection.onUpdate(createHMRHandler(this));
|
|
1121
|
+
}
|
|
1122
|
+
if (options.sourcemapInterceptor !== false) {
|
|
1123
|
+
this._resetSourceMapSupport = enableSourceMapSupport(this);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* URL to execute. Accepts file path, server path or id relative to the root.
|
|
1128
|
+
*/
|
|
1129
|
+
async executeUrl(url) {
|
|
1130
|
+
url = this.normalizeEntryUrl(url);
|
|
1131
|
+
const fetchedModule = await this.cachedModule(url);
|
|
1132
|
+
return await this.cachedRequest(url, fetchedModule);
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Entrypoint URL to execute. Accepts file path, server path or id relative to the root.
|
|
1136
|
+
* In the case of a full reload triggered by HMR, this is the module that will be reloaded.
|
|
1137
|
+
* If this method is called multiple times, all entrypoints will be reloaded one at a time.
|
|
1138
|
+
*/
|
|
1139
|
+
async executeEntrypoint(url) {
|
|
1140
|
+
url = this.normalizeEntryUrl(url);
|
|
1141
|
+
const fetchedModule = await this.cachedModule(url);
|
|
1142
|
+
return await this.cachedRequest(url, fetchedModule, [], {
|
|
1143
|
+
entrypoint: true
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Clear all caches including HMR listeners.
|
|
1148
|
+
*/
|
|
1149
|
+
clearCache() {
|
|
1150
|
+
this.moduleCache.clear();
|
|
1151
|
+
this.idToUrlMap.clear();
|
|
1152
|
+
this.entrypoints.clear();
|
|
1153
|
+
this.hmrClient?.clear();
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Clears all caches, removes all HMR listeners, and resets source map support.
|
|
1157
|
+
* This method doesn't stop the HMR connection.
|
|
1158
|
+
*/
|
|
1159
|
+
async destroy() {
|
|
1160
|
+
this._resetSourceMapSupport?.();
|
|
1161
|
+
this.clearCache();
|
|
1162
|
+
this.hmrClient = void 0;
|
|
1163
|
+
this._destroyed = true;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Returns `true` if the runtime has been destroyed by calling `destroy()` method.
|
|
1167
|
+
*/
|
|
1168
|
+
isDestroyed() {
|
|
1169
|
+
return this._destroyed;
|
|
1170
|
+
}
|
|
1171
|
+
invalidateFiles(files) {
|
|
1172
|
+
files.forEach((file) => {
|
|
1173
|
+
const ids = this.fileToIdMap.get(file);
|
|
1174
|
+
if (ids) {
|
|
1175
|
+
ids.forEach((id) => this.moduleCache.deleteByModuleId(id));
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
// we don't use moduleCache.normalize because this URL doesn't have to follow the same rules
|
|
1180
|
+
// this URL is something that user passes down manually, and is later resolved by fetchModule
|
|
1181
|
+
// moduleCache.normalize is used on resolved "file" property
|
|
1182
|
+
normalizeEntryUrl(url) {
|
|
1183
|
+
if (url[0] === ".") {
|
|
1184
|
+
return url;
|
|
1185
|
+
}
|
|
1186
|
+
if (url.startsWith("file://")) {
|
|
1187
|
+
url = url.slice(isWindows ? 8 : 7);
|
|
1188
|
+
}
|
|
1189
|
+
url = url.replace(/\\/g, "/");
|
|
1190
|
+
const _root = this.options.root;
|
|
1191
|
+
const root = _root[_root.length - 1] === "/" ? _root : `${_root}/`;
|
|
1192
|
+
if (url.startsWith(root)) {
|
|
1193
|
+
return url.slice(root.length - 1);
|
|
1194
|
+
}
|
|
1195
|
+
return url[0] === "/" ? url : wrapId(url);
|
|
1196
|
+
}
|
|
1197
|
+
processImport(exports, fetchResult, metadata) {
|
|
1198
|
+
if (!("externalize" in fetchResult)) {
|
|
1199
|
+
return exports;
|
|
1200
|
+
}
|
|
1201
|
+
const { id, type } = fetchResult;
|
|
1202
|
+
if (type !== "module" && type !== "commonjs")
|
|
1203
|
+
return exports;
|
|
1204
|
+
analyzeImportedModDifference(exports, id, type, metadata);
|
|
1205
|
+
return proxyGuardOnlyEsm(exports, id, metadata);
|
|
1206
|
+
}
|
|
1207
|
+
async cachedRequest(id, fetchedModule, callstack = [], metadata) {
|
|
1208
|
+
const moduleId = fetchedModule.id;
|
|
1209
|
+
if (metadata?.entrypoint) {
|
|
1210
|
+
this.entrypoints.add(moduleId);
|
|
1211
|
+
}
|
|
1212
|
+
const mod = this.moduleCache.getByModuleId(moduleId);
|
|
1213
|
+
const { imports, importers } = mod;
|
|
1214
|
+
const importee = callstack[callstack.length - 1];
|
|
1215
|
+
if (importee)
|
|
1216
|
+
importers.add(importee);
|
|
1217
|
+
if (callstack.includes(moduleId) || Array.from(imports.values()).some((i) => importers.has(i))) {
|
|
1218
|
+
if (mod.exports)
|
|
1219
|
+
return this.processImport(mod.exports, fetchedModule, metadata);
|
|
1220
|
+
}
|
|
1221
|
+
let debugTimer;
|
|
1222
|
+
if (this.debug) {
|
|
1223
|
+
debugTimer = setTimeout(() => {
|
|
1224
|
+
const getStack = () => `stack:
|
|
1225
|
+
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join("\n")}`;
|
|
1226
|
+
this.debug(`[vite-runtime] module ${moduleId} takes over 2s to load.
|
|
1227
|
+
${getStack()}`);
|
|
1228
|
+
}, 2e3);
|
|
1229
|
+
}
|
|
1230
|
+
try {
|
|
1231
|
+
if (mod.promise)
|
|
1232
|
+
return this.processImport(await mod.promise, fetchedModule, metadata);
|
|
1233
|
+
const promise = this.directRequest(id, fetchedModule, callstack);
|
|
1234
|
+
mod.promise = promise;
|
|
1235
|
+
mod.evaluated = false;
|
|
1236
|
+
return this.processImport(await promise, fetchedModule, metadata);
|
|
1237
|
+
} finally {
|
|
1238
|
+
mod.evaluated = true;
|
|
1239
|
+
if (debugTimer)
|
|
1240
|
+
clearTimeout(debugTimer);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
async cachedModule(id, importer) {
|
|
1244
|
+
if (this._destroyed) {
|
|
1245
|
+
throw new Error(`[vite] Vite runtime has been destroyed.`);
|
|
1246
|
+
}
|
|
1247
|
+
const normalized = this.idToUrlMap.get(id);
|
|
1248
|
+
if (normalized) {
|
|
1249
|
+
const mod2 = this.moduleCache.getByModuleId(normalized);
|
|
1250
|
+
if (mod2.meta) {
|
|
1251
|
+
return mod2.meta;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
this.debug?.("[vite-runtime] fetching", id);
|
|
1255
|
+
const fetchedModule = id.startsWith("data:") ? { externalize: id, type: "builtin" } : await this.options.fetchModule(id, importer);
|
|
1256
|
+
const idQuery = id.split("?")[1];
|
|
1257
|
+
const query = idQuery ? `?${idQuery}` : "";
|
|
1258
|
+
const file = "file" in fetchedModule ? fetchedModule.file : void 0;
|
|
1259
|
+
const fullFile = file ? `${file}${query}` : id;
|
|
1260
|
+
const moduleId = this.moduleCache.normalize(fullFile);
|
|
1261
|
+
const mod = this.moduleCache.getByModuleId(moduleId);
|
|
1262
|
+
fetchedModule.id = moduleId;
|
|
1263
|
+
mod.meta = fetchedModule;
|
|
1264
|
+
if (file) {
|
|
1265
|
+
const fileModules = this.fileToIdMap.get(file) || [];
|
|
1266
|
+
fileModules.push(moduleId);
|
|
1267
|
+
this.fileToIdMap.set(file, fileModules);
|
|
1268
|
+
}
|
|
1269
|
+
this.idToUrlMap.set(id, moduleId);
|
|
1270
|
+
this.idToUrlMap.set(unwrapId(id), moduleId);
|
|
1271
|
+
return fetchedModule;
|
|
1272
|
+
}
|
|
1273
|
+
// override is allowed, consider this a public API
|
|
1274
|
+
async directRequest(id, fetchResult, _callstack) {
|
|
1275
|
+
const moduleId = fetchResult.id;
|
|
1276
|
+
const callstack = [..._callstack, moduleId];
|
|
1277
|
+
const mod = this.moduleCache.getByModuleId(moduleId);
|
|
1278
|
+
const request = async (dep, metadata) => {
|
|
1279
|
+
const fetchedModule = await this.cachedModule(dep, moduleId);
|
|
1280
|
+
const depMod = this.moduleCache.getByModuleId(fetchedModule.id);
|
|
1281
|
+
depMod.importers.add(moduleId);
|
|
1282
|
+
mod.imports.add(fetchedModule.id);
|
|
1283
|
+
return this.cachedRequest(dep, fetchedModule, callstack, metadata);
|
|
1284
|
+
};
|
|
1285
|
+
const dynamicRequest = async (dep) => {
|
|
1286
|
+
dep = String(dep);
|
|
1287
|
+
if (dep[0] === ".") {
|
|
1288
|
+
dep = posixResolve(posixDirname(id), dep);
|
|
1289
|
+
}
|
|
1290
|
+
return request(dep, { isDynamicImport: true });
|
|
1291
|
+
};
|
|
1292
|
+
if ("externalize" in fetchResult) {
|
|
1293
|
+
const { externalize } = fetchResult;
|
|
1294
|
+
this.debug?.("[vite-runtime] externalizing", externalize);
|
|
1295
|
+
const exports2 = await this.runner.runExternalModule(externalize);
|
|
1296
|
+
mod.exports = exports2;
|
|
1297
|
+
return exports2;
|
|
1298
|
+
}
|
|
1299
|
+
const { code, file } = fetchResult;
|
|
1300
|
+
if (code == null) {
|
|
1301
|
+
const importer = callstack[callstack.length - 2];
|
|
1302
|
+
throw new Error(`[vite-runtime] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`);
|
|
1303
|
+
}
|
|
1304
|
+
const modulePath = cleanUrl(file || moduleId);
|
|
1305
|
+
const href = posixPathToFileHref(modulePath);
|
|
1306
|
+
const filename = modulePath;
|
|
1307
|
+
const dirname = posixDirname(modulePath);
|
|
1308
|
+
const meta = {
|
|
1309
|
+
filename: isWindows ? toWindowsPath(filename) : filename,
|
|
1310
|
+
dirname: isWindows ? toWindowsPath(dirname) : dirname,
|
|
1311
|
+
url: href,
|
|
1312
|
+
env: this.envProxy,
|
|
1313
|
+
resolve(id2, parent) {
|
|
1314
|
+
throw new Error('[vite-runtime] "import.meta.resolve" is not supported.');
|
|
1315
|
+
},
|
|
1316
|
+
// should be replaced during transformation
|
|
1317
|
+
glob() {
|
|
1318
|
+
throw new Error('[vite-runtime] "import.meta.glob" is not supported.');
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
const exports = /* @__PURE__ */ Object.create(null);
|
|
1322
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
1323
|
+
value: "Module",
|
|
1324
|
+
enumerable: false,
|
|
1325
|
+
configurable: false
|
|
1326
|
+
});
|
|
1327
|
+
mod.exports = exports;
|
|
1328
|
+
let hotContext;
|
|
1329
|
+
if (this.hmrClient) {
|
|
1330
|
+
Object.defineProperty(meta, "hot", {
|
|
1331
|
+
enumerable: true,
|
|
1332
|
+
get: () => {
|
|
1333
|
+
if (!this.hmrClient) {
|
|
1334
|
+
throw new Error(`[vite-runtime] HMR client was destroyed.`);
|
|
1335
|
+
}
|
|
1336
|
+
this.debug?.("[vite-runtime] creating hmr context for", moduleId);
|
|
1337
|
+
hotContext ||= new HMRContext(this.hmrClient, moduleId);
|
|
1338
|
+
return hotContext;
|
|
1339
|
+
},
|
|
1340
|
+
set: (value) => {
|
|
1341
|
+
hotContext = value;
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
const context = {
|
|
1346
|
+
[ssrImportKey]: request,
|
|
1347
|
+
[ssrDynamicImportKey]: dynamicRequest,
|
|
1348
|
+
[ssrModuleExportsKey]: exports,
|
|
1349
|
+
[ssrExportAllKey]: (obj) => exportAll(exports, obj),
|
|
1350
|
+
[ssrImportMetaKey]: meta
|
|
1351
|
+
};
|
|
1352
|
+
this.debug?.("[vite-runtime] executing", href);
|
|
1353
|
+
await this.runner.runViteModule(context, code, id);
|
|
1354
|
+
return exports;
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
function exportAll(exports, sourceModule) {
|
|
1358
|
+
if (exports === sourceModule)
|
|
1359
|
+
return;
|
|
1360
|
+
if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)
|
|
1361
|
+
return;
|
|
1362
|
+
for (const key in sourceModule) {
|
|
1363
|
+
if (key !== "default" && key !== "__esModule") {
|
|
1364
|
+
try {
|
|
1365
|
+
Object.defineProperty(exports, key, {
|
|
1366
|
+
enumerable: true,
|
|
1367
|
+
configurable: true,
|
|
1368
|
+
get: () => sourceModule[key]
|
|
1369
|
+
});
|
|
1370
|
+
} catch (_err) {
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
|
1376
|
+
if (metadata?.isDynamicImport)
|
|
1377
|
+
return;
|
|
1378
|
+
if (moduleType === "module")
|
|
1379
|
+
return;
|
|
1380
|
+
if (metadata?.importedNames?.length) {
|
|
1381
|
+
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
|
1382
|
+
if (missingBindings.length) {
|
|
1383
|
+
const lastBinding = missingBindings[missingBindings.length - 1];
|
|
1384
|
+
throw new SyntaxError(`[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.
|
|
1385
|
+
CommonJS modules can always be imported via the default export, for example using:
|
|
1386
|
+
|
|
1387
|
+
import pkg from '${rawId}';
|
|
1388
|
+
const {${missingBindings.join(", ")}} = pkg;
|
|
1389
|
+
`);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
function proxyGuardOnlyEsm(mod, rawId, metadata) {
|
|
1394
|
+
if (!metadata?.importedNames?.length)
|
|
1395
|
+
return mod;
|
|
1396
|
+
return new Proxy(mod, {
|
|
1397
|
+
get(mod2, prop) {
|
|
1398
|
+
if (prop !== "then" && !(prop in mod2)) {
|
|
1399
|
+
throw new SyntaxError(`[vite] The requested module '${rawId}' does not provide an export named '${prop.toString()}'`);
|
|
1400
|
+
}
|
|
1401
|
+
return mod2[prop];
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
var AsyncFunction = async function() {
|
|
1406
|
+
}.constructor;
|
|
1407
|
+
|
|
1408
|
+
// src/lib/vite/worker-entry.ts
|
|
1409
|
+
var O2_PREFIX = "[o2:runtime]";
|
|
1410
|
+
var worker_entry_default = {
|
|
1411
|
+
/**
|
|
1412
|
+
* Worker entry module that wraps the user app's entry module.
|
|
1413
|
+
*/
|
|
1414
|
+
async fetch(request, env, ctx) {
|
|
1415
|
+
env.__VITE_SETUP_ENV(request);
|
|
1416
|
+
const url = new URL(request.url);
|
|
1417
|
+
const module = await fetchEntryModule(url, env);
|
|
1418
|
+
if (url.pathname === env.__VITE_WARMUP_PATHNAME) {
|
|
1419
|
+
return new globalThis.Response(null);
|
|
1420
|
+
}
|
|
1421
|
+
return module.default.fetch(request, createUserEnv(env), ctx);
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
function createUserEnv(env) {
|
|
1425
|
+
return Object.fromEntries(
|
|
1426
|
+
Object.entries(env).filter(([key]) => !key.startsWith("__VITE_"))
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
var runtime;
|
|
1430
|
+
function fetchEntryModule(publicUrl, env) {
|
|
1431
|
+
if (!runtime) {
|
|
1432
|
+
let onHmrRecieve;
|
|
1433
|
+
let hmrReady = false;
|
|
1434
|
+
connectHmrWsClient(publicUrl, env).then((hmrWs) => {
|
|
1435
|
+
hmrReady = !!hmrWs;
|
|
1436
|
+
hmrWs?.addEventListener("message", (message) => {
|
|
1437
|
+
if (onHmrRecieve) {
|
|
1438
|
+
let data = JSON.parse(message.data?.toString());
|
|
1439
|
+
if (data?.type === "update") {
|
|
1440
|
+
data = { type: "full-reload", path: "*" };
|
|
1441
|
+
}
|
|
1442
|
+
onHmrRecieve(data);
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
}).catch((error) => console.error(error));
|
|
1446
|
+
runtime = new ViteRuntime(
|
|
1447
|
+
{
|
|
1448
|
+
root: env.__VITE_ROOT,
|
|
1449
|
+
sourcemapInterceptor: "prepareStackTrace",
|
|
1450
|
+
fetchModule: (id, importer) => {
|
|
1451
|
+
const url = new URL(env.__VITE_FETCH_MODULE_PATHNAME, publicUrl);
|
|
1452
|
+
url.searchParams.set("id", id);
|
|
1453
|
+
if (importer)
|
|
1454
|
+
url.searchParams.set("importer", importer);
|
|
1455
|
+
return fetch(url).then((res) => res.json());
|
|
1456
|
+
},
|
|
1457
|
+
hmr: {
|
|
1458
|
+
connection: {
|
|
1459
|
+
isReady: () => hmrReady,
|
|
1460
|
+
send: () => {
|
|
1461
|
+
},
|
|
1462
|
+
onUpdate(receiver) {
|
|
1463
|
+
onHmrRecieve = receiver;
|
|
1464
|
+
return () => {
|
|
1465
|
+
onHmrRecieve = void 0;
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
},
|
|
1471
|
+
{
|
|
1472
|
+
runExternalModule(filepath) {
|
|
1473
|
+
throw new Error(
|
|
1474
|
+
`${O2_PREFIX} External modules are not supported: "${filepath}"`
|
|
1475
|
+
);
|
|
1476
|
+
},
|
|
1477
|
+
async runViteModule(context, code, id) {
|
|
1478
|
+
if (!env.__VITE_UNSAFE_EVAL) {
|
|
1479
|
+
throw new Error(`${O2_PREFIX} unsafeEval module is not set`);
|
|
1480
|
+
}
|
|
1481
|
+
const initModule = env.__VITE_UNSAFE_EVAL.eval(
|
|
1482
|
+
// 'use strict' is implied in ESM so we enable it here. Also, we
|
|
1483
|
+
// add an extra block scope (`{}`) to allow redeclaring variables
|
|
1484
|
+
// with the same name as the parameters.
|
|
1485
|
+
`'use strict';async (${Object.keys(context).join(
|
|
1486
|
+
","
|
|
1487
|
+
)})=>{{${code}
|
|
1488
|
+
}}`,
|
|
1489
|
+
id
|
|
1490
|
+
);
|
|
1491
|
+
await initModule(...Object.values(context));
|
|
1492
|
+
Object.freeze(context[ssrModuleExportsKey]);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
return runtime.executeEntrypoint(env.__VITE_RUNTIME_EXECUTE_URL);
|
|
1498
|
+
}
|
|
1499
|
+
function connectHmrWsClient(url, env) {
|
|
1500
|
+
const hmrUrl = env.__VITE_HMR_URL.startsWith("http://") ? env.__VITE_HMR_URL : new URL(env.__VITE_HMR_URL, url.origin);
|
|
1501
|
+
return fetch(hmrUrl, {
|
|
1502
|
+
// When the HTTP port and the HMR port are the same, Vite reuses the same server for both.
|
|
1503
|
+
// This happens when not specifying the HMR port in the Vite config. Otherwise, Vite creates
|
|
1504
|
+
// a new server for HMR. In the first case, the protocol header is required to specify
|
|
1505
|
+
// that the connection to the main HTTP server via WS is for HMR.
|
|
1506
|
+
// Ref: https://github.com/vitejs/vite/blob/7440191715b07a50992fcf8c90d07600dffc375e/packages/vite/src/node/server/ws.ts#L120-L127
|
|
1507
|
+
headers: { Upgrade: "websocket", "sec-websocket-protocol": "vite-hmr" }
|
|
1508
|
+
}).then((response) => {
|
|
1509
|
+
const ws = response.webSocket;
|
|
1510
|
+
if (!ws)
|
|
1511
|
+
throw new Error(`${O2_PREFIX} Failed to connect to HMR server`);
|
|
1512
|
+
ws.accept();
|
|
1513
|
+
return ws;
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
export {
|
|
1517
|
+
worker_entry_default as default
|
|
1518
|
+
};
|