@cloudflare/vite-plugin 2.0.0-beta.v.1 → 2.0.0-beta.v.10
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/README.md +34 -0
- package/dist/index.d.mts +13 -4
- package/dist/index.mjs +2105 -1164
- package/dist/{package-DNE1Ou5k.mjs → package-DkG_FTc0.mjs} +2 -3
- package/dist/workers/runner-worker/module-runner.js +230 -206
- package/package.json +15 -16
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@cloudflare/vite-plugin",
|
|
4
|
-
version: "2.0.0-beta.v.
|
|
4
|
+
version: "2.0.0-beta.v.10",
|
|
5
5
|
description: "Cloudflare plugin for Vite",
|
|
6
6
|
keywords: [
|
|
7
7
|
"cloudflare",
|
|
@@ -57,12 +57,11 @@ var package_default = {
|
|
|
57
57
|
"@cloudflare/workers-tsconfig": "workspace:*",
|
|
58
58
|
"@cloudflare/workers-types": "catalog:default",
|
|
59
59
|
"@cloudflare/workers-utils": "workspace:*",
|
|
60
|
-
"@remix-run/node-fetch-server": "^0.
|
|
60
|
+
"@remix-run/node-fetch-server": "^1.0.0",
|
|
61
61
|
"@types/node": "catalog:default",
|
|
62
62
|
"@types/semver": "^7.5.1",
|
|
63
63
|
"@types/ws": "^8.5.13",
|
|
64
64
|
"am-i-vibing": "^0.5.0",
|
|
65
|
-
"defu": "^6.1.4",
|
|
66
65
|
"get-port": "^7.1.0",
|
|
67
66
|
"magic-string": "^0.30.12",
|
|
68
67
|
"mlly": "^1.7.4",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/vite@8.
|
|
1
|
+
//#region ../../node_modules/.pnpm/vite@8.3.4_@types+node@22.15.17_esbuild@0.28.2_jiti@2.6.1_tsx@4.21.0_yaml@2.9.0/node_modules/vite/dist/node/module-runner.js
|
|
2
2
|
let SOURCEMAPPING_URL = "sourceMa";
|
|
3
3
|
SOURCEMAPPING_URL += "ppingURL";
|
|
4
4
|
const isWindows = typeof process < "u" && process.platform === "win32";
|
|
@@ -38,80 +38,33 @@ function promiseWithResolvers() {
|
|
|
38
38
|
reject
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let path = index >= 0 ? arguments_[index] : cwd();
|
|
54
|
-
!path || path.length === 0 || (resolvedPath = `${path}/${resolvedPath}`, resolvedAbsolute = isAbsolute(path));
|
|
55
|
-
}
|
|
56
|
-
return resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
57
|
-
};
|
|
58
|
-
function normalizeString(path, allowAboveRoot) {
|
|
59
|
-
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
|
60
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
61
|
-
if (index < path.length) char = path[index];
|
|
62
|
-
else if (char === "/") break;
|
|
63
|
-
else char = "/";
|
|
64
|
-
if (char === "/") {
|
|
65
|
-
if (!(lastSlash === index - 1 || dots === 1)) if (dots === 2) {
|
|
66
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
67
|
-
if (res.length > 2) {
|
|
68
|
-
let lastSlashIndex = res.lastIndexOf("/");
|
|
69
|
-
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
|
70
|
-
continue;
|
|
71
|
-
} else if (res.length > 0) {
|
|
72
|
-
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
|
77
|
-
} else res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
78
|
-
lastSlash = index, dots = 0;
|
|
79
|
-
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
|
80
|
-
}
|
|
81
|
-
return res;
|
|
82
|
-
}
|
|
83
|
-
const isAbsolute = function(p) {
|
|
84
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
85
|
-
}, dirname = function(p) {
|
|
86
|
-
let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
87
|
-
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
88
|
-
}, textDecoder = new TextDecoder(), decodeBase64 = (() => {
|
|
89
|
-
let capturedBuffer = typeof Buffer == "function" ? Buffer : void 0;
|
|
90
|
-
return capturedBuffer && typeof capturedBuffer.from == "function" ? (base64) => capturedBuffer.from(base64, "base64").toString("utf-8") : (base64) => textDecoder.decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)));
|
|
91
|
-
})(), percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g;
|
|
92
|
-
function encodePathChars(filepath) {
|
|
93
|
-
return filepath.includes("%") && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.includes("\\") && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.includes("\n") && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.includes("\r") && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.includes(" ") && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
|
94
|
-
}
|
|
95
|
-
const posixDirname = dirname, posixResolve = resolve;
|
|
96
|
-
function posixPathToFileHref(posixPath) {
|
|
97
|
-
let resolved = posixResolve(posixPath), filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
|
98
|
-
return (filePathLast === 47 || isWindows && filePathLast === 92) && resolved[resolved.length - 1] !== "/" && (resolved += "/"), resolved = encodePathChars(resolved), resolved.includes("?") && (resolved = resolved.replace(questionRegex, "%3F")), resolved.includes("#") && (resolved = resolved.replace(hashRegex, "%23")), new URL(`file://${resolved}`).href;
|
|
99
|
-
}
|
|
100
|
-
function toWindowsPath(path) {
|
|
101
|
-
return path.replace(/\//g, "\\");
|
|
41
|
+
const percentEncodedRE = /(?:%[0-9a-f]{2})+/gi, whitespaceOnlyRE = /^\s+$/;
|
|
42
|
+
/** Reverses {@link encodeSourceURL}. */
|
|
43
|
+
function decodeSourceURL(url) {
|
|
44
|
+
return url.replace(percentEncodedRE, (match) => {
|
|
45
|
+
let decoded;
|
|
46
|
+
try {
|
|
47
|
+
decoded = decodeURIComponent(match);
|
|
48
|
+
} catch {
|
|
49
|
+
return match;
|
|
50
|
+
}
|
|
51
|
+
return whitespaceOnlyRE.test(decoded) ? decoded : match;
|
|
52
|
+
});
|
|
102
53
|
}
|
|
103
54
|
var comma = 44, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = /* @__PURE__ */ new Uint8Array(64), charToInt = /* @__PURE__ */ new Uint8Array(128);
|
|
104
55
|
for (let i = 0; i < chars.length; i++) {
|
|
105
56
|
let c = chars.charCodeAt(i);
|
|
106
57
|
intToChar[i] = c, charToInt[c] = i;
|
|
107
58
|
}
|
|
108
|
-
function decodeInteger(reader
|
|
59
|
+
function decodeInteger(reader) {
|
|
109
60
|
let value = 0, shift = 0, integer = 0;
|
|
110
61
|
do
|
|
111
62
|
integer = charToInt[reader.next()], value |= (integer & 31) << shift, shift += 5;
|
|
112
63
|
while (integer & 32);
|
|
113
|
-
|
|
114
|
-
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function decodeSign(num) {
|
|
67
|
+
return num & 1 ? -2147483648 | -(num >>> 1) : num >>> 1;
|
|
115
68
|
}
|
|
116
69
|
function hasMoreVlq(reader, max) {
|
|
117
70
|
return reader.pos >= max ? !1 : reader.peek() !== comma;
|
|
@@ -137,7 +90,7 @@ function decode(mappings) {
|
|
|
137
90
|
let semi = reader.indexOf(";"), line = [], sorted = !0, lastCol = 0;
|
|
138
91
|
for (genColumn = 0; reader.pos < semi;) {
|
|
139
92
|
let seg;
|
|
140
|
-
genColumn
|
|
93
|
+
genColumn += decodeSign(decodeInteger(reader)), genColumn < lastCol && (sorted = !1), lastCol = genColumn, hasMoreVlq(reader, semi) ? (sourcesIndex += decodeSign(decodeInteger(reader)), sourceLine += decodeSign(decodeInteger(reader)), sourceColumn += decodeSign(decodeInteger(reader)), hasMoreVlq(reader, semi) ? (namesIndex += decodeSign(decodeInteger(reader)), seg = [
|
|
141
94
|
genColumn,
|
|
142
95
|
sourcesIndex,
|
|
143
96
|
sourceLine,
|
|
@@ -218,6 +171,69 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
|
218
171
|
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
219
172
|
return found ? index = (bias === -1 ? upperBound : lowerBound)(segments, column, index) : bias === -1 && index++, index === -1 || index === segments.length ? -1 : index;
|
|
220
173
|
}
|
|
174
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
175
|
+
function normalizeWindowsPath(input = "") {
|
|
176
|
+
return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
177
|
+
}
|
|
178
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
179
|
+
function cwd() {
|
|
180
|
+
return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
|
|
181
|
+
}
|
|
182
|
+
const resolve = function(...arguments_) {
|
|
183
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
184
|
+
let resolvedPath = "", resolvedAbsolute = !1;
|
|
185
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
186
|
+
let path = index >= 0 ? arguments_[index] : cwd();
|
|
187
|
+
path && path.length !== 0 && (resolvedPath = `${path}/${resolvedPath}`, resolvedAbsolute = isAbsolute(path));
|
|
188
|
+
}
|
|
189
|
+
return resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
190
|
+
};
|
|
191
|
+
function normalizeString(path, allowAboveRoot) {
|
|
192
|
+
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
|
193
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
194
|
+
if (index < path.length) char = path[index];
|
|
195
|
+
else if (char === "/") break;
|
|
196
|
+
else char = "/";
|
|
197
|
+
if (char === "/") {
|
|
198
|
+
if (lastSlash !== index - 1 && dots !== 1) if (dots === 2) {
|
|
199
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
200
|
+
if (res.length > 2) {
|
|
201
|
+
let lastSlashIndex = res.lastIndexOf("/");
|
|
202
|
+
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (res.length > 0) {
|
|
206
|
+
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
|
211
|
+
} else res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
212
|
+
lastSlash = index, dots = 0;
|
|
213
|
+
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
|
214
|
+
}
|
|
215
|
+
return res;
|
|
216
|
+
}
|
|
217
|
+
const isAbsolute = function(p) {
|
|
218
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
219
|
+
}, dirname = function(p) {
|
|
220
|
+
let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
221
|
+
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
222
|
+
}, textDecoder = new TextDecoder(), decodeBase64 = (() => {
|
|
223
|
+
let capturedBuffer = typeof Buffer == "function" ? Buffer : void 0;
|
|
224
|
+
return capturedBuffer && typeof capturedBuffer.from == "function" ? (base64) => capturedBuffer.from(base64, "base64").toString("utf-8") : (base64) => textDecoder.decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)));
|
|
225
|
+
})(), percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g;
|
|
226
|
+
function encodePathChars(filepath) {
|
|
227
|
+
return filepath.includes("%") && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.includes("\\") && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.includes("\n") && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.includes("\r") && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.includes(" ") && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
|
228
|
+
}
|
|
229
|
+
const posixDirname = dirname, posixResolve = resolve;
|
|
230
|
+
function posixPathToFileHref(posixPath) {
|
|
231
|
+
let resolved = posixResolve(posixPath), filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
|
232
|
+
return (filePathLast === 47 || isWindows && filePathLast === 92) && resolved.at(-1) !== "/" && (resolved += "/"), resolved = encodePathChars(resolved), resolved.includes("?") && (resolved = resolved.replace(questionRegex, "%3F")), resolved.includes("#") && (resolved = resolved.replace(hashRegex, "%23")), new URL(`file://${resolved}`).href;
|
|
233
|
+
}
|
|
234
|
+
function toWindowsPath(path) {
|
|
235
|
+
return path.replace(/\//g, "\\");
|
|
236
|
+
}
|
|
221
237
|
var DecodedMap = class {
|
|
222
238
|
map;
|
|
223
239
|
_encoded;
|
|
@@ -341,6 +357,10 @@ const prefixedBuiltins = /* @__PURE__ */ new Set([
|
|
|
341
357
|
function normalizeModuleId(file) {
|
|
342
358
|
return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\/+/, isWindows ? "" : "/");
|
|
343
359
|
}
|
|
360
|
+
function createIsBuiltin(builtins) {
|
|
361
|
+
let plainBuiltinsSet = new Set(builtins.filter((builtin) => typeof builtin == "string")), regexBuiltins = builtins.filter((builtin) => typeof builtin != "string");
|
|
362
|
+
return (id) => plainBuiltinsSet.has(id) || regexBuiltins.some((regexp) => regexp.test(id));
|
|
363
|
+
}
|
|
344
364
|
var HMRContext = class {
|
|
345
365
|
hmrClient;
|
|
346
366
|
ownerPath;
|
|
@@ -365,8 +385,8 @@ var HMRContext = class {
|
|
|
365
385
|
else if (Array.isArray(deps)) this.acceptDeps(deps, callback);
|
|
366
386
|
else throw Error("invalid hot.accept() usage.");
|
|
367
387
|
}
|
|
368
|
-
acceptExports(
|
|
369
|
-
this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
|
|
388
|
+
acceptExports(exportNames, callback) {
|
|
389
|
+
this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod), typeof exportNames == "string" ? [exportNames] : exportNames);
|
|
370
390
|
}
|
|
371
391
|
dispose(cb) {
|
|
372
392
|
this.hmrClient.disposeMap.set(this.ownerPath, cb);
|
|
@@ -414,14 +434,15 @@ var HMRContext = class {
|
|
|
414
434
|
data
|
|
415
435
|
});
|
|
416
436
|
}
|
|
417
|
-
acceptDeps(deps, callback = () => {}) {
|
|
437
|
+
acceptDeps(deps, callback = () => {}, exports) {
|
|
418
438
|
let mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
|
|
419
439
|
id: this.ownerPath,
|
|
420
440
|
callbacks: []
|
|
421
441
|
};
|
|
422
442
|
mod.callbacks.push({
|
|
423
443
|
deps,
|
|
424
|
-
fn: callback
|
|
444
|
+
fn: callback,
|
|
445
|
+
exports
|
|
425
446
|
}), this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
|
426
447
|
}
|
|
427
448
|
}, HMRClient = class {
|
|
@@ -451,13 +472,17 @@ var HMRContext = class {
|
|
|
451
472
|
this.hotModulesMap.clear(), this.disposeMap.clear(), this.pruneMap.clear(), this.dataMap.clear(), this.customListenersMap.clear(), this.ctxToListenersMap.clear();
|
|
452
473
|
}
|
|
453
474
|
async prunePaths(paths) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
475
|
+
try {
|
|
476
|
+
await Promise.all(paths.map((path) => {
|
|
477
|
+
let disposer = this.disposeMap.get(path);
|
|
478
|
+
if (disposer) return disposer(this.dataMap.get(path));
|
|
479
|
+
})), await Promise.all(paths.map((path) => {
|
|
480
|
+
let fn = this.pruneMap.get(path);
|
|
481
|
+
if (fn) return fn(this.dataMap.get(path));
|
|
482
|
+
}));
|
|
483
|
+
} finally {
|
|
484
|
+
paths.forEach((path) => this.dataMap.delete(path));
|
|
485
|
+
}
|
|
461
486
|
}
|
|
462
487
|
warnFailedUpdate(err, path) {
|
|
463
488
|
(!(err instanceof Error) || !err.message.includes("fetch")) && this.logger.error(err), this.logger.error(`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
|
|
@@ -501,26 +526,6 @@ var HMRContext = class {
|
|
|
501
526
|
};
|
|
502
527
|
}
|
|
503
528
|
};
|
|
504
|
-
/**
|
|
505
|
-
* Vite converts `import { } from 'foo'` to `const _ = __vite_ssr_import__('foo')`.
|
|
506
|
-
* Top-level imports and dynamic imports work slightly differently in Node.js.
|
|
507
|
-
* This function normalizes the differences so it matches prod behaviour.
|
|
508
|
-
*/
|
|
509
|
-
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
|
510
|
-
if (!metadata?.isDynamicImport && metadata?.importedNames?.length) {
|
|
511
|
-
let missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
|
512
|
-
if (missingBindings.length) {
|
|
513
|
-
let lastBinding = missingBindings[missingBindings.length - 1];
|
|
514
|
-
throw SyntaxError(moduleType === "module" ? `[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'` : `\
|
|
515
|
-
[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.
|
|
516
|
-
CommonJS modules can always be imported via the default export, for example using:
|
|
517
|
-
|
|
518
|
-
import pkg from '${rawId}';
|
|
519
|
-
const {${missingBindings.join(", ")}} = pkg;
|
|
520
|
-
`);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
529
|
let nanoid = (size = 21) => {
|
|
525
530
|
let id = "", i = size | 0;
|
|
526
531
|
for (; i-- > 0;) id += "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[Math.random() * 64 | 0];
|
|
@@ -684,16 +689,111 @@ const createWebSocketModuleRunnerTransport = (options) => {
|
|
|
684
689
|
}
|
|
685
690
|
};
|
|
686
691
|
};
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
692
|
+
/**
|
|
693
|
+
* Vite converts `import { } from 'foo'` to `const _ = __vite_ssr_import__('foo')`.
|
|
694
|
+
* Top-level imports and dynamic imports work slightly differently in Node.js.
|
|
695
|
+
* This function normalizes the differences so it matches prod behaviour.
|
|
696
|
+
*/
|
|
697
|
+
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
|
698
|
+
if (!metadata?.isDynamicImport && metadata?.importedNames?.length) {
|
|
699
|
+
let missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
|
700
|
+
if (missingBindings.length) {
|
|
701
|
+
let lastBinding = missingBindings.at(-1);
|
|
702
|
+
throw SyntaxError(moduleType === "module" ? `[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'` : `\
|
|
703
|
+
[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.
|
|
704
|
+
CommonJS modules can always be imported via the default export, for example using:
|
|
705
|
+
|
|
706
|
+
import pkg from '${rawId}';
|
|
707
|
+
const {${missingBindings.join(", ")}} = pkg;
|
|
708
|
+
`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
690
711
|
}
|
|
691
|
-
const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrExportNameKey = "__vite_ssr_exportName__", ssrImportMetaKey = "__vite_ssr_import_meta__",
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
712
|
+
const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrExportNameKey = "__vite_ssr_exportName__", ssrImportMetaKey = "__vite_ssr_import_meta__", customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/", customizationHooksModule = `
|
|
713
|
+
|
|
714
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
715
|
+
if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
|
|
716
|
+
const data = specifier.slice(${JSON.stringify(customizationHookNamespace)}.length)
|
|
717
|
+
const [parsedSpecifier, parsedImporter] = JSON.parse(data)
|
|
718
|
+
specifier = parsedSpecifier
|
|
719
|
+
context.parentURL = parsedImporter
|
|
720
|
+
}
|
|
721
|
+
return nextResolve(specifier, context)
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
`;
|
|
725
|
+
function customizationHookResolve(specifier, context, nextResolve) {
|
|
726
|
+
if (specifier.startsWith(customizationHookNamespace)) {
|
|
727
|
+
let data = specifier.slice(42), [parsedSpecifier, parsedImporter] = JSON.parse(data);
|
|
728
|
+
specifier = parsedSpecifier, context.parentURL = parsedImporter;
|
|
729
|
+
}
|
|
730
|
+
return nextResolve(specifier, context);
|
|
731
|
+
}
|
|
732
|
+
let isHookRegistered = !1;
|
|
733
|
+
function createImportMetaResolver() {
|
|
734
|
+
if (isHookRegistered) return importMetaResolveWithCustomHook;
|
|
735
|
+
let module;
|
|
736
|
+
try {
|
|
737
|
+
module = typeof process < "u" ? process.getBuiltinModule("node:module").Module : void 0;
|
|
738
|
+
} catch {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
if (module) {
|
|
742
|
+
if (module.registerHooks) return module.registerHooks({ resolve: customizationHookResolve }), isHookRegistered = !0, importMetaResolveWithCustomHook;
|
|
743
|
+
if (module.register) {
|
|
744
|
+
try {
|
|
745
|
+
let hookModuleContent = `data:text/javascript,${encodeURI(customizationHooksModule)}`;
|
|
746
|
+
module.register(hookModuleContent);
|
|
747
|
+
} catch (e) {
|
|
748
|
+
if ("code" in e && e.code === "ERR_NETWORK_IMPORT_DISALLOWED") return;
|
|
749
|
+
throw e;
|
|
750
|
+
}
|
|
751
|
+
return isHookRegistered = !0, importMetaResolveWithCustomHook;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function importMetaResolveWithCustomHook(specifier, importer) {
|
|
756
|
+
return import.meta.resolve(`${customizationHookNamespace}${JSON.stringify([specifier, importer])}`);
|
|
757
|
+
}
|
|
758
|
+
const envProxy = new Proxy({}, { get(_, p) {
|
|
759
|
+
throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
|
760
|
+
} });
|
|
761
|
+
function createDefaultImportMeta(modulePath) {
|
|
762
|
+
let href = posixPathToFileHref(modulePath), filename = modulePath, dirname$1 = posixDirname(modulePath);
|
|
763
|
+
return {
|
|
764
|
+
filename: isWindows ? toWindowsPath(filename) : filename,
|
|
765
|
+
dirname: isWindows ? toWindowsPath(dirname$1) : dirname$1,
|
|
766
|
+
url: href,
|
|
767
|
+
env: envProxy,
|
|
768
|
+
resolve(_id, _parent) {
|
|
769
|
+
throw Error("[module runner] \"import.meta.resolve\" is not supported.");
|
|
770
|
+
},
|
|
771
|
+
glob() {
|
|
772
|
+
throw Error("[module runner] \"import.meta.glob\" is statically replaced during file transformation. Make sure to reference it by the full name.");
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Create import.meta object for Node.js.
|
|
778
|
+
*/
|
|
779
|
+
function createNodeImportMeta(modulePath) {
|
|
780
|
+
let defaultMeta = createDefaultImportMeta(modulePath), href = defaultMeta.url, importMetaResolver = createImportMetaResolver();
|
|
781
|
+
return {
|
|
782
|
+
...defaultMeta,
|
|
783
|
+
main: !1,
|
|
784
|
+
resolve(id, parent) {
|
|
785
|
+
return (importMetaResolver ?? defaultMeta.resolve)(id, parent ?? href);
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
var ESModulesEvaluator = class {
|
|
790
|
+
startOffset = getAsyncFunctionDeclarationPaddingLineCount() + 1;
|
|
791
|
+
async runInlinedModule(context, code) {
|
|
792
|
+
await new AsyncFunction(ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, "\"use strict\";\n" + code)(context[ssrModuleExportsKey], context[ssrImportMetaKey], context[ssrImportKey], context[ssrDynamicImportKey], context[ssrExportAllKey], context[ssrExportNameKey]), Object.seal(context[ssrModuleExportsKey]);
|
|
793
|
+
}
|
|
794
|
+
runExternalModule(filepath) {
|
|
795
|
+
return import(filepath);
|
|
796
|
+
}
|
|
697
797
|
};
|
|
698
798
|
function createHMRHandler(handler) {
|
|
699
799
|
let queue = new Queue();
|
|
@@ -722,13 +822,13 @@ var Queue = class {
|
|
|
722
822
|
function createHMRHandlerForRunner(runner) {
|
|
723
823
|
return createHMRHandler(async (payload) => {
|
|
724
824
|
let hmrClient = runner.hmrClient;
|
|
725
|
-
if (
|
|
825
|
+
if (hmrClient && !runner.isClosed()) switch (payload.type) {
|
|
726
826
|
case "connected":
|
|
727
827
|
hmrClient.logger.debug("connected.");
|
|
728
828
|
break;
|
|
729
829
|
case "update":
|
|
730
830
|
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(payload.updates.map(async (update) => {
|
|
731
|
-
if (update.type === "js-update") return
|
|
831
|
+
if (update.type === "js-update") return hmrClient.queueUpdate(update);
|
|
732
832
|
hmrClient.logger.error("css hmr is not supported in runner mode.");
|
|
733
833
|
})), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
|
734
834
|
break;
|
|
@@ -760,6 +860,7 @@ function createHMRHandlerForRunner(runner) {
|
|
|
760
860
|
break;
|
|
761
861
|
}
|
|
762
862
|
case "ping": break;
|
|
863
|
+
case "bundled-dev-update": break;
|
|
763
864
|
default: return payload;
|
|
764
865
|
}
|
|
765
866
|
});
|
|
@@ -787,7 +888,13 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
|
|
|
787
888
|
for (let mod of runner.evaluatedModules.idToModuleMap.values()) mod.importers.size || entrypoints.add(mod.url);
|
|
788
889
|
return entrypoints;
|
|
789
890
|
}
|
|
790
|
-
const
|
|
891
|
+
const noop = () => {}, silentConsole = {
|
|
892
|
+
debug: noop,
|
|
893
|
+
error: noop
|
|
894
|
+
}, hmrLogger = {
|
|
895
|
+
debug: (...msg) => console.log("[vite]", ...msg),
|
|
896
|
+
error: (error) => console.log("[vite]", error)
|
|
897
|
+
}, sourceMapCache = {}, fileContentsCache = {}, evaluatedModulesCache = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => ((...args) => {
|
|
791
898
|
for (let handler of handlers) {
|
|
792
899
|
let result = handler(...args);
|
|
793
900
|
if (result) return result;
|
|
@@ -808,10 +915,11 @@ function supportRelativeURL(file, url) {
|
|
|
808
915
|
return protocol && /^\/\w:/.test(startPath) ? (protocol += "/", protocol + slash(posixResolve(startPath, url))) : protocol + posixResolve(startPath, url);
|
|
809
916
|
}
|
|
810
917
|
function getRunnerSourceMap(position) {
|
|
918
|
+
let id = decodeSourceURL(position.source);
|
|
811
919
|
for (let moduleGraph of evaluatedModulesCache) {
|
|
812
|
-
let sourceMap = moduleGraph.getModuleSourceMapById(
|
|
920
|
+
let sourceMap = moduleGraph.getModuleSourceMapById(id);
|
|
813
921
|
if (sourceMap) return {
|
|
814
|
-
url:
|
|
922
|
+
url: id,
|
|
815
923
|
map: sourceMap,
|
|
816
924
|
vite: !0
|
|
817
925
|
};
|
|
@@ -837,7 +945,9 @@ function retrieveSourceMap(source) {
|
|
|
837
945
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
838
946
|
if (!sourceMappingURL) return null;
|
|
839
947
|
let sourceMapData;
|
|
840
|
-
|
|
948
|
+
if (reSourceMap.test(sourceMappingURL)) sourceMapData = decodeBase64(sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1)), sourceMappingURL = source;
|
|
949
|
+
else sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
|
|
950
|
+
return sourceMapData ? {
|
|
841
951
|
url: sourceMappingURL,
|
|
842
952
|
map: sourceMapData
|
|
843
953
|
} : null;
|
|
@@ -889,7 +999,7 @@ function CallSiteToString() {
|
|
|
889
999
|
let fileName, fileLocation = "";
|
|
890
1000
|
if (this.isNative()) fileLocation = "native";
|
|
891
1001
|
else {
|
|
892
|
-
fileName = this.getScriptNameOrSourceURL(), !fileName && this.isEval() && (fileLocation = this.getEvalOrigin(), fileLocation += ", "),
|
|
1002
|
+
fileName = this.getScriptNameOrSourceURL(), !fileName && this.isEval() && (fileLocation = this.getEvalOrigin(), fileLocation += ", "), fileLocation += fileName || "<anonymous>";
|
|
893
1003
|
let lineNumber = this.getLineNumber();
|
|
894
1004
|
if (lineNumber != null) {
|
|
895
1005
|
fileLocation += `:${lineNumber}`;
|
|
@@ -908,7 +1018,7 @@ function CallSiteToString() {
|
|
|
908
1018
|
return addSuffix && (line += ` (${fileLocation})`), line;
|
|
909
1019
|
}
|
|
910
1020
|
function cloneCallSite(frame) {
|
|
911
|
-
let object =
|
|
1021
|
+
let object = Object.create(null);
|
|
912
1022
|
return Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
913
1023
|
let key = name;
|
|
914
1024
|
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
@@ -923,13 +1033,14 @@ function wrapCallSite(frame, state) {
|
|
|
923
1033
|
}), frame.isNative()) return state.curPosition = null, frame;
|
|
924
1034
|
let source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
925
1035
|
if (source) {
|
|
926
|
-
let
|
|
1036
|
+
let unmapped = {
|
|
927
1037
|
name: null,
|
|
928
1038
|
source,
|
|
929
1039
|
line: frame.getLineNumber() ?? 0,
|
|
930
1040
|
column: (frame.getColumnNumber() ?? 1) - 1
|
|
931
|
-
});
|
|
932
|
-
state.curPosition = position, frame
|
|
1041
|
+
}, position = mapSourcePosition(unmapped);
|
|
1042
|
+
if (state.curPosition = position, position === unmapped && !state.nextPosition?.name && frame.getColumnNumber() != null && frame.getScriptNameOrSourceURL() === source) return frame;
|
|
1043
|
+
frame = cloneCallSite(frame);
|
|
933
1044
|
let originalFunctionName = frame.getFunctionName;
|
|
934
1045
|
return frame.getFunctionName = function() {
|
|
935
1046
|
let name = state.nextPosition == null ? originalFunctionName() : state.nextPosition.name || originalFunctionName();
|
|
@@ -966,92 +1077,6 @@ function enableSourceMapSupport(runner) {
|
|
|
966
1077
|
}
|
|
967
1078
|
return interceptStackTrace(runner, typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0);
|
|
968
1079
|
}
|
|
969
|
-
var ESModulesEvaluator = class {
|
|
970
|
-
startOffset = getAsyncFunctionDeclarationPaddingLineCount() + 1;
|
|
971
|
-
async runInlinedModule(context, code) {
|
|
972
|
-
await new AsyncFunction(ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, "\"use strict\";\n" + code)(context[ssrModuleExportsKey], context[ssrImportMetaKey], context[ssrImportKey], context[ssrDynamicImportKey], context[ssrExportAllKey], context[ssrExportNameKey]), Object.seal(context[ssrModuleExportsKey]);
|
|
973
|
-
}
|
|
974
|
-
runExternalModule(filepath) {
|
|
975
|
-
return import(filepath);
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/", customizationHooksModule = `
|
|
979
|
-
|
|
980
|
-
export async function resolve(specifier, context, nextResolve) {
|
|
981
|
-
if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
|
|
982
|
-
const data = specifier.slice(${JSON.stringify(customizationHookNamespace)}.length)
|
|
983
|
-
const [parsedSpecifier, parsedImporter] = JSON.parse(data)
|
|
984
|
-
specifier = parsedSpecifier
|
|
985
|
-
context.parentURL = parsedImporter
|
|
986
|
-
}
|
|
987
|
-
return nextResolve(specifier, context)
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
`;
|
|
991
|
-
function customizationHookResolve(specifier, context, nextResolve) {
|
|
992
|
-
if (specifier.startsWith(customizationHookNamespace)) {
|
|
993
|
-
let data = specifier.slice(42), [parsedSpecifier, parsedImporter] = JSON.parse(data);
|
|
994
|
-
specifier = parsedSpecifier, context.parentURL = parsedImporter;
|
|
995
|
-
}
|
|
996
|
-
return nextResolve(specifier, context);
|
|
997
|
-
}
|
|
998
|
-
let isHookRegistered = !1;
|
|
999
|
-
function createImportMetaResolver() {
|
|
1000
|
-
if (isHookRegistered) return importMetaResolveWithCustomHook;
|
|
1001
|
-
let module;
|
|
1002
|
-
try {
|
|
1003
|
-
module = typeof process < "u" ? process.getBuiltinModule("node:module").Module : void 0;
|
|
1004
|
-
} catch {
|
|
1005
|
-
return;
|
|
1006
|
-
}
|
|
1007
|
-
if (module) {
|
|
1008
|
-
if (module.registerHooks) return module.registerHooks({ resolve: customizationHookResolve }), isHookRegistered = !0, importMetaResolveWithCustomHook;
|
|
1009
|
-
if (module.register) {
|
|
1010
|
-
try {
|
|
1011
|
-
let hookModuleContent = `data:text/javascript,${encodeURI(customizationHooksModule)}`;
|
|
1012
|
-
module.register(hookModuleContent);
|
|
1013
|
-
} catch (e) {
|
|
1014
|
-
if ("code" in e && e.code === "ERR_NETWORK_IMPORT_DISALLOWED") return;
|
|
1015
|
-
throw e;
|
|
1016
|
-
}
|
|
1017
|
-
return isHookRegistered = !0, importMetaResolveWithCustomHook;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
function importMetaResolveWithCustomHook(specifier, importer) {
|
|
1022
|
-
return import.meta.resolve(`${customizationHookNamespace}${JSON.stringify([specifier, importer])}`);
|
|
1023
|
-
}
|
|
1024
|
-
const envProxy = new Proxy({}, { get(_, p) {
|
|
1025
|
-
throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
|
1026
|
-
} });
|
|
1027
|
-
function createDefaultImportMeta(modulePath) {
|
|
1028
|
-
let href = posixPathToFileHref(modulePath), filename = modulePath, dirname$1 = posixDirname(modulePath);
|
|
1029
|
-
return {
|
|
1030
|
-
filename: isWindows ? toWindowsPath(filename) : filename,
|
|
1031
|
-
dirname: isWindows ? toWindowsPath(dirname$1) : dirname$1,
|
|
1032
|
-
url: href,
|
|
1033
|
-
env: envProxy,
|
|
1034
|
-
resolve(_id, _parent) {
|
|
1035
|
-
throw Error("[module runner] \"import.meta.resolve\" is not supported.");
|
|
1036
|
-
},
|
|
1037
|
-
glob() {
|
|
1038
|
-
throw Error("[module runner] \"import.meta.glob\" is statically replaced during file transformation. Make sure to reference it by the full name.");
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Create import.meta object for Node.js.
|
|
1044
|
-
*/
|
|
1045
|
-
function createNodeImportMeta(modulePath) {
|
|
1046
|
-
let defaultMeta = createDefaultImportMeta(modulePath), href = defaultMeta.url, importMetaResolver = createImportMetaResolver();
|
|
1047
|
-
return {
|
|
1048
|
-
...defaultMeta,
|
|
1049
|
-
main: !1,
|
|
1050
|
-
resolve(id, parent) {
|
|
1051
|
-
return (importMetaResolver ?? defaultMeta.resolve)(id, parent ?? href);
|
|
1052
|
-
}
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
1080
|
var ModuleRunner = class {
|
|
1056
1081
|
options;
|
|
1057
1082
|
evaluator;
|
|
@@ -1107,14 +1132,13 @@ var ModuleRunner = class {
|
|
|
1107
1132
|
if (visited.has(mod.id)) return !1;
|
|
1108
1133
|
visited.add(mod.id);
|
|
1109
1134
|
for (let importedModuleId of mod.imports) {
|
|
1110
|
-
if (callstack.includes(importedModuleId)) return !0;
|
|
1111
1135
|
let importedModule = this.evaluatedModules.getModuleById(importedModuleId);
|
|
1112
|
-
if (importedModule?.promise && !importedModule.evaluated && this.isCircularRequest(importedModule, callstack, visited)) return !0;
|
|
1136
|
+
if (importedModule?.promise && !importedModule.evaluated && (callstack.includes(importedModuleId) || this.isCircularRequest(importedModule, callstack, visited))) return !0;
|
|
1113
1137
|
}
|
|
1114
1138
|
return !1;
|
|
1115
1139
|
}
|
|
1116
1140
|
async cachedRequest(url, mod, callstack = [], metadata) {
|
|
1117
|
-
let meta = mod.meta, moduleId = meta.id, importee = callstack
|
|
1141
|
+
let meta = mod.meta, moduleId = meta.id, importee = callstack.at(-1);
|
|
1118
1142
|
if (importee && mod.importers.add(importee), mod.evaluated && mod.promise) return this.processImport(await mod.promise, meta, metadata);
|
|
1119
1143
|
if (mod.promise) return mod.exports && (callstack.includes(moduleId) || this.isCircularRequest(mod, callstack)) ? this.processImport(mod.exports, meta, metadata) : this.processImport(await mod.promise, meta, metadata);
|
|
1120
1144
|
let debugTimer;
|