@cloudflare/vite-plugin 1.7.5 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asset-workers/router-worker.js +4 -2
- package/dist/index.js +51 -55
- package/dist/runner-worker/index.js +437 -574
- package/package.json +6 -6
|
@@ -30,7 +30,7 @@ function stripInternalEnv(internalEnv) {
|
|
|
30
30
|
return userEnv;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
// ../../node_modules/.pnpm/vite@
|
|
33
|
+
// ../../node_modules/.pnpm/vite@7.0.0_@types+node@20.17.32_jiti@2.4.2_lightningcss@1.29.2/node_modules/vite/dist/node/module-runner.js
|
|
34
34
|
var VALID_ID_PREFIX = "/@id/";
|
|
35
35
|
var NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
36
36
|
var SOURCEMAPPING_URL = "sourceMa";
|
|
@@ -55,18 +55,21 @@ var AsyncFunction = async function() {
|
|
|
55
55
|
}.constructor;
|
|
56
56
|
var asyncFunctionDeclarationPaddingLineCount;
|
|
57
57
|
function getAsyncFunctionDeclarationPaddingLineCount() {
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
asyncFunctionDeclarationPaddingLineCount = source.slice(0, source.indexOf(body)).split(
|
|
61
|
-
`).length - 1;
|
|
58
|
+
if (asyncFunctionDeclarationPaddingLineCount === void 0) {
|
|
59
|
+
let body = "/*code*/", source = new AsyncFunction("a", "b", body).toString();
|
|
60
|
+
asyncFunctionDeclarationPaddingLineCount = source.slice(0, source.indexOf(body)).split("\n").length - 1;
|
|
62
61
|
}
|
|
63
62
|
return asyncFunctionDeclarationPaddingLineCount;
|
|
64
63
|
}
|
|
65
64
|
function promiseWithResolvers() {
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
let resolve$1, reject, promise = new Promise((_resolve, _reject) => {
|
|
66
|
+
resolve$1 = _resolve, reject = _reject;
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
promise,
|
|
70
|
+
resolve: resolve$1,
|
|
71
|
+
reject
|
|
72
|
+
};
|
|
70
73
|
}
|
|
71
74
|
var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
72
75
|
function normalizeWindowsPath(input = "") {
|
|
@@ -81,7 +84,7 @@ var resolve = function(...arguments_) {
|
|
|
81
84
|
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
82
85
|
let resolvedPath = "", resolvedAbsolute = false;
|
|
83
86
|
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
84
|
-
|
|
87
|
+
let path = index >= 0 ? arguments_[index] : cwd();
|
|
85
88
|
!path || path.length === 0 || (resolvedPath = `${path}/${resolvedPath}`, resolvedAbsolute = isAbsolute(path));
|
|
86
89
|
}
|
|
87
90
|
return resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
@@ -89,18 +92,14 @@ var resolve = function(...arguments_) {
|
|
|
89
92
|
function normalizeString(path, allowAboveRoot) {
|
|
90
93
|
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
|
91
94
|
for (let index = 0; index <= path.length; ++index) {
|
|
92
|
-
if (index < path.length)
|
|
93
|
-
|
|
94
|
-
else
|
|
95
|
-
if (char === "/")
|
|
96
|
-
break;
|
|
97
|
-
char = "/";
|
|
98
|
-
}
|
|
95
|
+
if (index < path.length) char = path[index];
|
|
96
|
+
else if (char === "/") break;
|
|
97
|
+
else char = "/";
|
|
99
98
|
if (char === "/") {
|
|
100
99
|
if (!(lastSlash === index - 1 || dots === 1)) if (dots === 2) {
|
|
101
100
|
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
102
101
|
if (res.length > 2) {
|
|
103
|
-
|
|
102
|
+
let lastSlashIndex = res.lastIndexOf("/");
|
|
104
103
|
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
|
105
104
|
continue;
|
|
106
105
|
} else if (res.length > 0) {
|
|
@@ -109,8 +108,7 @@ function normalizeString(path, allowAboveRoot) {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
|
112
|
-
} else
|
|
113
|
-
res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
111
|
+
} else res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
114
112
|
lastSlash = index, dots = 0;
|
|
115
113
|
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
|
116
114
|
}
|
|
@@ -120,7 +118,7 @@ var isAbsolute = function(p) {
|
|
|
120
118
|
return _IS_ABSOLUTE_RE.test(p);
|
|
121
119
|
};
|
|
122
120
|
var dirname = function(p) {
|
|
123
|
-
|
|
121
|
+
let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
124
122
|
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
125
123
|
};
|
|
126
124
|
var decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8");
|
|
@@ -134,14 +132,12 @@ var tabRegEx = /\t/g;
|
|
|
134
132
|
var questionRegex = /\?/g;
|
|
135
133
|
var hashRegex = /#/g;
|
|
136
134
|
function encodePathChars(filepath) {
|
|
137
|
-
return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf(
|
|
138
|
-
`) !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
|
135
|
+
return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf("\n") !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
|
139
136
|
}
|
|
140
137
|
var posixDirname = dirname;
|
|
141
138
|
var posixResolve = resolve;
|
|
142
139
|
function posixPathToFileHref(posixPath) {
|
|
143
|
-
let resolved = posixResolve(posixPath);
|
|
144
|
-
const filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
|
140
|
+
let resolved = posixResolve(posixPath), filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
|
145
141
|
return (filePathLast === CHAR_FORWARD_SLASH || isWindows && filePathLast === CHAR_BACKWARD_SLASH) && resolved[resolved.length - 1] !== "/" && (resolved += "/"), resolved = encodePathChars(resolved), resolved.indexOf("?") !== -1 && (resolved = resolved.replace(questionRegex, "%3F")), resolved.indexOf("#") !== -1 && (resolved = resolved.replace(hashRegex, "%23")), new URL(`file://${resolved}`).href;
|
|
146
142
|
}
|
|
147
143
|
function toWindowsPath(path) {
|
|
@@ -152,21 +148,22 @@ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
152
148
|
var intToChar = new Uint8Array(64);
|
|
153
149
|
var charToInt = new Uint8Array(128);
|
|
154
150
|
for (let i = 0; i < chars.length; i++) {
|
|
155
|
-
|
|
151
|
+
let c = chars.charCodeAt(i);
|
|
156
152
|
intToChar[i] = c, charToInt[c] = i;
|
|
157
153
|
}
|
|
158
154
|
function decodeInteger(reader, relative) {
|
|
159
155
|
let value = 0, shift = 0, integer = 0;
|
|
160
156
|
do {
|
|
161
|
-
|
|
157
|
+
let c = reader.next();
|
|
162
158
|
integer = charToInt[c], value |= (integer & 31) << shift, shift += 5;
|
|
163
159
|
} while (integer & 32);
|
|
164
|
-
|
|
160
|
+
let shouldNegate = value & 1;
|
|
165
161
|
return value >>>= 1, shouldNegate && (value = -2147483648 | -value), relative + value;
|
|
166
162
|
}
|
|
167
163
|
function hasMoreVlq(reader, max) {
|
|
168
164
|
return reader.pos >= max ? false : reader.peek() !== comma;
|
|
169
165
|
}
|
|
166
|
+
var bufLength = 1024 * 16;
|
|
170
167
|
var StringReader = class {
|
|
171
168
|
constructor(buffer) {
|
|
172
169
|
this.pos = 0, this.buffer = buffer;
|
|
@@ -178,19 +175,28 @@ var StringReader = class {
|
|
|
178
175
|
return this.buffer.charCodeAt(this.pos);
|
|
179
176
|
}
|
|
180
177
|
indexOf(char) {
|
|
181
|
-
|
|
178
|
+
let { buffer, pos } = this, idx = buffer.indexOf(char, pos);
|
|
182
179
|
return idx === -1 ? buffer.length : idx;
|
|
183
180
|
}
|
|
184
181
|
};
|
|
185
182
|
function decode(mappings) {
|
|
186
|
-
|
|
187
|
-
let genColumn = 0, sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
|
|
183
|
+
let { length } = mappings, reader = new StringReader(mappings), decoded = [], genColumn = 0, sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
|
|
188
184
|
do {
|
|
189
|
-
|
|
190
|
-
let sorted = true, lastCol = 0;
|
|
185
|
+
let semi = reader.indexOf(";"), line = [], sorted = true, lastCol = 0;
|
|
191
186
|
for (genColumn = 0; reader.pos < semi; ) {
|
|
192
187
|
let seg;
|
|
193
|
-
genColumn = decodeInteger(reader, genColumn), genColumn < lastCol && (sorted = false), lastCol = genColumn, hasMoreVlq(reader, semi) ? (sourcesIndex = decodeInteger(reader, sourcesIndex), sourceLine = decodeInteger(reader, sourceLine), sourceColumn = decodeInteger(reader, sourceColumn), hasMoreVlq(reader, semi) ? (namesIndex = decodeInteger(reader, namesIndex), seg = [
|
|
188
|
+
genColumn = decodeInteger(reader, genColumn), genColumn < lastCol && (sorted = false), lastCol = genColumn, hasMoreVlq(reader, semi) ? (sourcesIndex = decodeInteger(reader, sourcesIndex), sourceLine = decodeInteger(reader, sourceLine), sourceColumn = decodeInteger(reader, sourceColumn), hasMoreVlq(reader, semi) ? (namesIndex = decodeInteger(reader, namesIndex), seg = [
|
|
189
|
+
genColumn,
|
|
190
|
+
sourcesIndex,
|
|
191
|
+
sourceLine,
|
|
192
|
+
sourceColumn,
|
|
193
|
+
namesIndex
|
|
194
|
+
]) : seg = [
|
|
195
|
+
genColumn,
|
|
196
|
+
sourcesIndex,
|
|
197
|
+
sourceLine,
|
|
198
|
+
sourceColumn
|
|
199
|
+
]) : seg = [genColumn], line.push(seg), reader.pos++;
|
|
194
200
|
}
|
|
195
201
|
sorted || sort(line), decoded.push(line), reader.pos = semi + 1;
|
|
196
202
|
} while (reader.pos <= length);
|
|
@@ -210,29 +216,24 @@ var NAMES_INDEX = 4;
|
|
|
210
216
|
var found = false;
|
|
211
217
|
function binarySearch(haystack, needle, low, high) {
|
|
212
218
|
for (; low <= high; ) {
|
|
213
|
-
|
|
214
|
-
if (cmp === 0)
|
|
215
|
-
return found = true, mid;
|
|
219
|
+
let mid = low + (high - low >> 1), cmp = haystack[mid][COLUMN] - needle;
|
|
220
|
+
if (cmp === 0) return found = true, mid;
|
|
216
221
|
cmp < 0 ? low = mid + 1 : high = mid - 1;
|
|
217
222
|
}
|
|
218
223
|
return found = false, low - 1;
|
|
219
224
|
}
|
|
220
225
|
function upperBound(haystack, needle, index) {
|
|
221
|
-
for (let i = index + 1; i < haystack.length && haystack[i][COLUMN] === needle; index = i++)
|
|
222
|
-
;
|
|
226
|
+
for (let i = index + 1; i < haystack.length && haystack[i][COLUMN] === needle; index = i++) ;
|
|
223
227
|
return index;
|
|
224
228
|
}
|
|
225
229
|
function lowerBound(haystack, needle, index) {
|
|
226
|
-
for (let i = index - 1; i >= 0 && haystack[i][COLUMN] === needle; index = i--)
|
|
227
|
-
;
|
|
230
|
+
for (let i = index - 1; i >= 0 && haystack[i][COLUMN] === needle; index = i--) ;
|
|
228
231
|
return index;
|
|
229
232
|
}
|
|
230
233
|
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
231
|
-
|
|
232
|
-
let low = 0, high = haystack.length - 1;
|
|
234
|
+
let { lastKey, lastNeedle, lastIndex } = state, low = 0, high = haystack.length - 1;
|
|
233
235
|
if (key === lastKey) {
|
|
234
|
-
if (needle === lastNeedle)
|
|
235
|
-
return found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle, lastIndex;
|
|
236
|
+
if (needle === lastNeedle) return found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle, lastIndex;
|
|
236
237
|
needle >= lastNeedle ? low = lastIndex === -1 ? 0 : lastIndex : high = lastIndex;
|
|
237
238
|
}
|
|
238
239
|
return state.lastKey = key, state.lastNeedle = needle, state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
@@ -241,43 +242,39 @@ var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
|
241
242
|
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
242
243
|
var LEAST_UPPER_BOUND = -1;
|
|
243
244
|
var GREATEST_LOWER_BOUND = 1;
|
|
245
|
+
function cast(map) {
|
|
246
|
+
return map;
|
|
247
|
+
}
|
|
244
248
|
function decodedMappings(map) {
|
|
245
249
|
var _a;
|
|
246
|
-
return (_a = map)._decoded || (_a._decoded = decode(map._encoded));
|
|
250
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
247
251
|
}
|
|
248
252
|
function originalPositionFor(map, needle) {
|
|
249
253
|
let { line, column, bias } = needle;
|
|
250
|
-
if (line--, line < 0)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return OMapping(null, null, null, null);
|
|
260
|
-
const segment = segments[index];
|
|
261
|
-
if (segment.length === 1)
|
|
262
|
-
return OMapping(null, null, null, null);
|
|
263
|
-
const { names, resolvedSources } = map;
|
|
254
|
+
if (line--, line < 0) throw Error(LINE_GTR_ZERO);
|
|
255
|
+
if (column < 0) throw Error(COL_GTR_EQ_ZERO);
|
|
256
|
+
let decoded = decodedMappings(map);
|
|
257
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
258
|
+
let segments = decoded[line], index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
|
259
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
260
|
+
let segment = segments[index];
|
|
261
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
262
|
+
let { names, resolvedSources } = map;
|
|
264
263
|
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
|
265
264
|
}
|
|
266
265
|
function OMapping(source, line, column, name) {
|
|
267
|
-
return {
|
|
266
|
+
return {
|
|
267
|
+
source,
|
|
268
|
+
line,
|
|
269
|
+
column,
|
|
270
|
+
name
|
|
271
|
+
};
|
|
268
272
|
}
|
|
269
273
|
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
270
274
|
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
271
275
|
return found ? index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index) : bias === LEAST_UPPER_BOUND && index++, index === -1 || index === segments.length ? -1 : index;
|
|
272
276
|
}
|
|
273
277
|
var DecodedMap = class {
|
|
274
|
-
constructor(map, from) {
|
|
275
|
-
this.map = map;
|
|
276
|
-
const { mappings, names, sources } = map;
|
|
277
|
-
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map(
|
|
278
|
-
(s) => posixResolve(s || "", from)
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
278
|
_encoded;
|
|
282
279
|
_decoded;
|
|
283
280
|
_decodedMemo;
|
|
@@ -285,6 +282,11 @@ var DecodedMap = class {
|
|
|
285
282
|
version;
|
|
286
283
|
names = [];
|
|
287
284
|
resolvedSources;
|
|
285
|
+
constructor(map, from) {
|
|
286
|
+
this.map = map;
|
|
287
|
+
let { mappings, names, sources } = map;
|
|
288
|
+
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
|
289
|
+
}
|
|
288
290
|
};
|
|
289
291
|
function memoizedState() {
|
|
290
292
|
return {
|
|
@@ -294,16 +296,11 @@ function memoizedState() {
|
|
|
294
296
|
};
|
|
295
297
|
}
|
|
296
298
|
function getOriginalPosition(map, needle) {
|
|
297
|
-
|
|
299
|
+
let result = originalPositionFor(map, needle);
|
|
298
300
|
return result.column == null ? null : result;
|
|
299
301
|
}
|
|
300
|
-
var MODULE_RUNNER_SOURCEMAPPING_REGEXP =
|
|
301
|
-
`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`
|
|
302
|
-
);
|
|
302
|
+
var MODULE_RUNNER_SOURCEMAPPING_REGEXP = /* @__PURE__ */ RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`);
|
|
303
303
|
var EvaluatedModuleNode = class {
|
|
304
|
-
constructor(id, url) {
|
|
305
|
-
this.id = id, this.url = url, this.file = cleanUrl(id);
|
|
306
|
-
}
|
|
307
304
|
importers = /* @__PURE__ */ new Set();
|
|
308
305
|
imports = /* @__PURE__ */ new Set();
|
|
309
306
|
evaluated = false;
|
|
@@ -312,71 +309,72 @@ var EvaluatedModuleNode = class {
|
|
|
312
309
|
exports;
|
|
313
310
|
file;
|
|
314
311
|
map;
|
|
312
|
+
constructor(id, url) {
|
|
313
|
+
this.id = id, this.url = url, this.file = cleanUrl(id);
|
|
314
|
+
}
|
|
315
315
|
};
|
|
316
316
|
var EvaluatedModules = class {
|
|
317
317
|
idToModuleMap = /* @__PURE__ */ new Map();
|
|
318
318
|
fileToModulesMap = /* @__PURE__ */ new Map();
|
|
319
319
|
urlToIdModuleMap = /* @__PURE__ */ new Map();
|
|
320
320
|
/**
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
321
|
+
* Returns the module node by the resolved module ID. Usually, module ID is
|
|
322
|
+
* the file system path with query and/or hash. It can also be a virtual module.
|
|
323
|
+
*
|
|
324
|
+
* Module runner graph will have 1 to 1 mapping with the server module graph.
|
|
325
|
+
* @param id Resolved module ID
|
|
326
|
+
*/
|
|
327
327
|
getModuleById(id) {
|
|
328
328
|
return this.idToModuleMap.get(id);
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
* Returns all modules related to the file system path. Different modules
|
|
332
|
+
* might have different query parameters or hash, so it's possible to have
|
|
333
|
+
* multiple modules for the same file.
|
|
334
|
+
* @param file The file system path of the module
|
|
335
|
+
*/
|
|
336
336
|
getModulesByFile(file) {
|
|
337
337
|
return this.fileToModulesMap.get(file);
|
|
338
338
|
}
|
|
339
339
|
/**
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
* Returns the module node by the URL that was used in the import statement.
|
|
341
|
+
* Unlike module graph on the server, the URL is not resolved and is used as is.
|
|
342
|
+
* @param url Server URL that was used in the import statement
|
|
343
|
+
*/
|
|
344
344
|
getModuleByUrl(url) {
|
|
345
345
|
return this.urlToIdModuleMap.get(unwrapId(url));
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
* Ensure that module is in the graph. If the module is already in the graph,
|
|
349
|
+
* it will return the existing module node. Otherwise, it will create a new
|
|
350
|
+
* module node and add it to the graph.
|
|
351
|
+
* @param id Resolved module ID
|
|
352
|
+
* @param url URL that was used in the import statement
|
|
353
|
+
*/
|
|
354
354
|
ensureModule(id, url) {
|
|
355
355
|
if (id = normalizeModuleId(id), this.idToModuleMap.has(id)) {
|
|
356
|
-
|
|
357
|
-
return this.urlToIdModuleMap.set(url,
|
|
356
|
+
let moduleNode$1 = this.idToModuleMap.get(id);
|
|
357
|
+
return this.urlToIdModuleMap.set(url, moduleNode$1), moduleNode$1;
|
|
358
358
|
}
|
|
359
|
-
|
|
359
|
+
let moduleNode = new EvaluatedModuleNode(id, url);
|
|
360
360
|
this.idToModuleMap.set(id, moduleNode), this.urlToIdModuleMap.set(url, moduleNode);
|
|
361
|
-
|
|
361
|
+
let fileModules = this.fileToModulesMap.get(moduleNode.file) || /* @__PURE__ */ new Set();
|
|
362
362
|
return fileModules.add(moduleNode), this.fileToModulesMap.set(moduleNode.file, fileModules), moduleNode;
|
|
363
363
|
}
|
|
364
364
|
invalidateModule(node) {
|
|
365
365
|
node.evaluated = false, node.meta = void 0, node.map = void 0, node.promise = void 0, node.exports = void 0, node.imports.clear();
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
368
|
+
* Extracts the inlined source map from the module code and returns the decoded
|
|
369
|
+
* source map. If the source map is not inlined, it will return null.
|
|
370
|
+
* @param id Resolved module ID
|
|
371
|
+
*/
|
|
372
372
|
getModuleSourceMapById(id) {
|
|
373
|
-
|
|
373
|
+
let mod = this.getModuleById(id);
|
|
374
374
|
if (!mod) return null;
|
|
375
375
|
if (mod.map) return mod.map;
|
|
376
376
|
if (!mod.meta || !("code" in mod.meta)) return null;
|
|
377
|
-
|
|
378
|
-
mod.meta.code
|
|
379
|
-
)?.[1];
|
|
377
|
+
let mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(mod.meta.code)?.[1];
|
|
380
378
|
return mapString ? (mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), mod.file), mod.map) : null;
|
|
381
379
|
}
|
|
382
380
|
clear() {
|
|
@@ -390,40 +388,32 @@ var prefixedBuiltins = /* @__PURE__ */ new Set([
|
|
|
390
388
|
"node:test/reporters"
|
|
391
389
|
]);
|
|
392
390
|
function normalizeModuleId(file) {
|
|
393
|
-
|
|
391
|
+
if (prefixedBuiltins.has(file)) return file;
|
|
392
|
+
let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
393
|
+
return unixFile.replace(/^file:\//, "/");
|
|
394
394
|
}
|
|
395
395
|
var HMRContext = class {
|
|
396
|
+
newListeners;
|
|
396
397
|
constructor(hmrClient, ownerPath) {
|
|
397
398
|
this.hmrClient = hmrClient, this.ownerPath = ownerPath, hmrClient.dataMap.has(ownerPath) || hmrClient.dataMap.set(ownerPath, {});
|
|
398
|
-
|
|
399
|
+
let mod = hmrClient.hotModulesMap.get(ownerPath);
|
|
399
400
|
mod && (mod.callbacks = []);
|
|
400
|
-
|
|
401
|
-
if (staleListeners)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
event,
|
|
406
|
-
listeners.filter((l) => !staleFns.includes(l))
|
|
407
|
-
);
|
|
408
|
-
}
|
|
401
|
+
let staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
|
|
402
|
+
if (staleListeners) for (let [event, staleFns] of staleListeners) {
|
|
403
|
+
let listeners = hmrClient.customListenersMap.get(event);
|
|
404
|
+
listeners && hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
|
|
405
|
+
}
|
|
409
406
|
this.newListeners = /* @__PURE__ */ new Map(), hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
|
410
407
|
}
|
|
411
|
-
newListeners;
|
|
412
408
|
get data() {
|
|
413
409
|
return this.hmrClient.dataMap.get(this.ownerPath);
|
|
414
410
|
}
|
|
415
411
|
accept(deps, callback) {
|
|
416
|
-
if (typeof deps == "function" || !deps)
|
|
417
|
-
|
|
418
|
-
else if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
this.acceptDeps(deps, callback);
|
|
422
|
-
else
|
|
423
|
-
throw new Error("invalid hot.accept() usage.");
|
|
424
|
-
}
|
|
425
|
-
// export names (first arg) are irrelevant on the client side, they're
|
|
426
|
-
// extracted in the server for propagation
|
|
412
|
+
if (typeof deps == "function" || !deps) this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
|
|
413
|
+
else if (typeof deps == "string") this.acceptDeps([deps], ([mod]) => callback?.(mod));
|
|
414
|
+
else if (Array.isArray(deps)) this.acceptDeps(deps, callback);
|
|
415
|
+
else throw Error("invalid hot.accept() usage.");
|
|
416
|
+
}
|
|
427
417
|
acceptExports(_, callback) {
|
|
428
418
|
this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
|
|
429
419
|
}
|
|
@@ -433,34 +423,32 @@ var HMRContext = class {
|
|
|
433
423
|
prune(cb) {
|
|
434
424
|
this.hmrClient.pruneMap.set(this.ownerPath, cb);
|
|
435
425
|
}
|
|
436
|
-
// Kept for backward compatibility (#11036)
|
|
437
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
438
426
|
decline() {
|
|
439
427
|
}
|
|
440
428
|
invalidate(message) {
|
|
429
|
+
let firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
|
|
441
430
|
this.hmrClient.notifyListeners("vite:invalidate", {
|
|
442
431
|
path: this.ownerPath,
|
|
443
|
-
message
|
|
432
|
+
message,
|
|
433
|
+
firstInvalidatedBy
|
|
444
434
|
}), this.send("vite:invalidate", {
|
|
445
435
|
path: this.ownerPath,
|
|
446
|
-
message
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
);
|
|
436
|
+
message,
|
|
437
|
+
firstInvalidatedBy
|
|
438
|
+
}), this.hmrClient.logger.debug(`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
|
|
450
439
|
}
|
|
451
440
|
on(event, cb) {
|
|
452
|
-
|
|
453
|
-
|
|
441
|
+
let addToMap = (map) => {
|
|
442
|
+
let existing = map.get(event) || [];
|
|
454
443
|
existing.push(cb), map.set(event, existing);
|
|
455
444
|
};
|
|
456
445
|
addToMap(this.hmrClient.customListenersMap), addToMap(this.newListeners);
|
|
457
446
|
}
|
|
458
447
|
off(event, cb) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (existing === void 0)
|
|
462
|
-
|
|
463
|
-
const pruned = existing.filter((l) => l !== cb);
|
|
448
|
+
let removeFromMap = (map) => {
|
|
449
|
+
let existing = map.get(event);
|
|
450
|
+
if (existing === void 0) return;
|
|
451
|
+
let pruned = existing.filter((l) => l !== cb);
|
|
464
452
|
if (pruned.length === 0) {
|
|
465
453
|
map.delete(event);
|
|
466
454
|
return;
|
|
@@ -470,11 +458,15 @@ var HMRContext = class {
|
|
|
470
458
|
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
|
471
459
|
}
|
|
472
460
|
send(event, data) {
|
|
473
|
-
this.hmrClient.send({
|
|
461
|
+
this.hmrClient.send({
|
|
462
|
+
type: "custom",
|
|
463
|
+
event,
|
|
464
|
+
data
|
|
465
|
+
});
|
|
474
466
|
}
|
|
475
467
|
acceptDeps(deps, callback = () => {
|
|
476
468
|
}) {
|
|
477
|
-
|
|
469
|
+
let mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
|
|
478
470
|
id: this.ownerPath,
|
|
479
471
|
callbacks: []
|
|
480
472
|
};
|
|
@@ -485,17 +477,18 @@ var HMRContext = class {
|
|
|
485
477
|
}
|
|
486
478
|
};
|
|
487
479
|
var HMRClient = class {
|
|
488
|
-
constructor(logger, transport, importUpdatedModule) {
|
|
489
|
-
this.logger = logger, this.transport = transport, this.importUpdatedModule = importUpdatedModule;
|
|
490
|
-
}
|
|
491
480
|
hotModulesMap = /* @__PURE__ */ new Map();
|
|
492
481
|
disposeMap = /* @__PURE__ */ new Map();
|
|
493
482
|
pruneMap = /* @__PURE__ */ new Map();
|
|
494
483
|
dataMap = /* @__PURE__ */ new Map();
|
|
495
484
|
customListenersMap = /* @__PURE__ */ new Map();
|
|
496
485
|
ctxToListenersMap = /* @__PURE__ */ new Map();
|
|
486
|
+
currentFirstInvalidatedBy;
|
|
487
|
+
constructor(logger, transport, importUpdatedModule) {
|
|
488
|
+
this.logger = logger, this.transport = transport, this.importUpdatedModule = importUpdatedModule;
|
|
489
|
+
}
|
|
497
490
|
async notifyListeners(event, data) {
|
|
498
|
-
|
|
491
|
+
let cbs = this.customListenersMap.get(event);
|
|
499
492
|
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
|
500
493
|
}
|
|
501
494
|
send(payload) {
|
|
@@ -506,49 +499,38 @@ var HMRClient = class {
|
|
|
506
499
|
clear() {
|
|
507
500
|
this.hotModulesMap.clear(), this.disposeMap.clear(), this.pruneMap.clear(), this.dataMap.clear(), this.customListenersMap.clear(), this.ctxToListenersMap.clear();
|
|
508
501
|
}
|
|
509
|
-
// After an HMR update, some modules are no longer imported on the page
|
|
510
|
-
// but they may have left behind side effects that need to be cleaned up
|
|
511
|
-
// (e.g. style injections)
|
|
512
502
|
async prunePaths(paths) {
|
|
513
|
-
await Promise.all(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
), paths.forEach((path) => {
|
|
519
|
-
const fn = this.pruneMap.get(path);
|
|
503
|
+
await Promise.all(paths.map((path) => {
|
|
504
|
+
let disposer = this.disposeMap.get(path);
|
|
505
|
+
if (disposer) return disposer(this.dataMap.get(path));
|
|
506
|
+
})), paths.forEach((path) => {
|
|
507
|
+
let fn = this.pruneMap.get(path);
|
|
520
508
|
fn && fn(this.dataMap.get(path));
|
|
521
509
|
});
|
|
522
510
|
}
|
|
523
511
|
warnFailedUpdate(err, path) {
|
|
524
|
-
err.message.includes("fetch")
|
|
525
|
-
`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
|
526
|
-
);
|
|
512
|
+
(!(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)`);
|
|
527
513
|
}
|
|
528
514
|
updateQueue = [];
|
|
529
515
|
pendingUpdateQueue = false;
|
|
530
516
|
/**
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
517
|
+
* buffer multiple hot updates triggered by the same src change
|
|
518
|
+
* so that they are invoked in the same order they were sent.
|
|
519
|
+
* (otherwise the order may be inconsistent because of the http request round trip)
|
|
520
|
+
*/
|
|
535
521
|
async queueUpdate(payload) {
|
|
536
522
|
if (this.updateQueue.push(this.fetchUpdate(payload)), !this.pendingUpdateQueue) {
|
|
537
523
|
this.pendingUpdateQueue = true, await Promise.resolve(), this.pendingUpdateQueue = false;
|
|
538
|
-
|
|
524
|
+
let loading = [...this.updateQueue];
|
|
539
525
|
this.updateQueue = [], (await Promise.all(loading)).forEach((fn) => fn && fn());
|
|
540
526
|
}
|
|
541
527
|
}
|
|
542
528
|
async fetchUpdate(update) {
|
|
543
|
-
|
|
544
|
-
if (!mod)
|
|
545
|
-
|
|
546
|
-
let fetchedModule;
|
|
547
|
-
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
|
548
|
-
({ deps }) => deps.includes(acceptedPath)
|
|
549
|
-
);
|
|
529
|
+
let { path, acceptedPath, firstInvalidatedBy } = update, mod = this.hotModulesMap.get(path);
|
|
530
|
+
if (!mod) return;
|
|
531
|
+
let fetchedModule, isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
|
550
532
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
|
551
|
-
|
|
533
|
+
let disposer = this.disposeMap.get(acceptedPath);
|
|
552
534
|
disposer && await disposer(this.dataMap.get(acceptedPath));
|
|
553
535
|
try {
|
|
554
536
|
fetchedModule = await this.importUpdatedModule(update);
|
|
@@ -557,23 +539,23 @@ var HMRClient = class {
|
|
|
557
539
|
}
|
|
558
540
|
}
|
|
559
541
|
return () => {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
542
|
+
try {
|
|
543
|
+
this.currentFirstInvalidatedBy = firstInvalidatedBy;
|
|
544
|
+
for (let { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
|
|
545
|
+
let loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
546
|
+
this.logger.debug(`hot updated: ${loggedPath}`);
|
|
547
|
+
} finally {
|
|
548
|
+
this.currentFirstInvalidatedBy = void 0;
|
|
549
|
+
}
|
|
566
550
|
};
|
|
567
551
|
}
|
|
568
552
|
};
|
|
569
553
|
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
|
570
554
|
if (!metadata?.isDynamicImport && metadata?.importedNames?.length) {
|
|
571
|
-
|
|
555
|
+
let missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
|
572
556
|
if (missingBindings.length) {
|
|
573
|
-
|
|
574
|
-
throw moduleType === "module" ?
|
|
575
|
-
`[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`
|
|
576
|
-
) : 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.
|
|
557
|
+
let lastBinding = missingBindings[missingBindings.length - 1];
|
|
558
|
+
throw moduleType === "module" ? SyntaxError(`[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`) : 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.
|
|
577
559
|
CommonJS modules can always be imported via the default export, for example using:
|
|
578
560
|
|
|
579
561
|
import pkg from '${rawId}';
|
|
@@ -585,54 +567,44 @@ const {${missingBindings.join(", ")}} = pkg;
|
|
|
585
567
|
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
586
568
|
var nanoid = (size = 21) => {
|
|
587
569
|
let id = "", i = size | 0;
|
|
588
|
-
for (; i--; )
|
|
589
|
-
id += urlAlphabet[Math.random() * 64 | 0];
|
|
570
|
+
for (; i--; ) id += urlAlphabet[Math.random() * 64 | 0];
|
|
590
571
|
return id;
|
|
591
572
|
};
|
|
592
573
|
function reviveInvokeError(e) {
|
|
593
|
-
|
|
594
|
-
return Object.assign(error, e, {
|
|
595
|
-
// pass the whole error instead of just the stacktrace
|
|
596
|
-
// so that it gets formatted nicely with console.log
|
|
597
|
-
runnerError: new Error("RunnerError")
|
|
598
|
-
}), error;
|
|
574
|
+
let error = Error(e.message || "Unknown invoke error");
|
|
575
|
+
return Object.assign(error, e, { runnerError: /* @__PURE__ */ Error("RunnerError") }), error;
|
|
599
576
|
}
|
|
600
577
|
var createInvokeableTransport = (transport) => {
|
|
601
|
-
if (transport.invoke)
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
if (!transport.send || !transport.connect)
|
|
620
|
-
throw new Error(
|
|
621
|
-
"transport must implement send and connect when invoke is not implemented"
|
|
622
|
-
);
|
|
623
|
-
const rpcPromises = /* @__PURE__ */ new Map();
|
|
578
|
+
if (transport.invoke) return {
|
|
579
|
+
...transport,
|
|
580
|
+
async invoke(name, data) {
|
|
581
|
+
let result = await transport.invoke({
|
|
582
|
+
type: "custom",
|
|
583
|
+
event: "vite:invoke",
|
|
584
|
+
data: {
|
|
585
|
+
id: "send",
|
|
586
|
+
name,
|
|
587
|
+
data
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
if ("error" in result) throw reviveInvokeError(result.error);
|
|
591
|
+
return result.result;
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
if (!transport.send || !transport.connect) throw Error("transport must implement send and connect when invoke is not implemented");
|
|
595
|
+
let rpcPromises = /* @__PURE__ */ new Map();
|
|
624
596
|
return {
|
|
625
597
|
...transport,
|
|
626
598
|
connect({ onMessage, onDisconnection }) {
|
|
627
599
|
return transport.connect({
|
|
628
600
|
onMessage(payload) {
|
|
629
601
|
if (payload.type === "custom" && payload.event === "vite:invoke") {
|
|
630
|
-
|
|
602
|
+
let data = payload.data;
|
|
631
603
|
if (data.id.startsWith("response:")) {
|
|
632
|
-
|
|
604
|
+
let invokeId = data.id.slice(9), promise = rpcPromises.get(invokeId);
|
|
633
605
|
if (!promise) return;
|
|
634
606
|
promise.timeoutId && clearTimeout(promise.timeoutId), rpcPromises.delete(invokeId);
|
|
635
|
-
|
|
607
|
+
let { error, result } = data.data;
|
|
636
608
|
error ? promise.reject(error) : promise.resolve(result);
|
|
637
609
|
return;
|
|
638
610
|
}
|
|
@@ -644,18 +616,14 @@ var createInvokeableTransport = (transport) => {
|
|
|
644
616
|
},
|
|
645
617
|
disconnect() {
|
|
646
618
|
return rpcPromises.forEach((promise) => {
|
|
647
|
-
promise.reject(
|
|
648
|
-
new Error(
|
|
649
|
-
`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`
|
|
650
|
-
)
|
|
651
|
-
);
|
|
619
|
+
promise.reject(/* @__PURE__ */ Error(`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`));
|
|
652
620
|
}), rpcPromises.clear(), transport.disconnect?.();
|
|
653
621
|
},
|
|
654
622
|
send(data) {
|
|
655
623
|
return transport.send(data);
|
|
656
624
|
},
|
|
657
625
|
async invoke(name, data) {
|
|
658
|
-
|
|
626
|
+
let promiseId = nanoid(), wrappedData = {
|
|
659
627
|
type: "custom",
|
|
660
628
|
event: "vite:invoke",
|
|
661
629
|
data: {
|
|
@@ -663,15 +631,15 @@ var createInvokeableTransport = (transport) => {
|
|
|
663
631
|
id: `send:${promiseId}`,
|
|
664
632
|
data
|
|
665
633
|
}
|
|
666
|
-
}, sendPromise = transport.send(wrappedData), { promise, resolve:
|
|
667
|
-
let timeoutId;
|
|
634
|
+
}, sendPromise = transport.send(wrappedData), { promise, resolve: resolve$1, reject } = promiseWithResolvers(), timeout = transport.timeout ?? 6e4, timeoutId;
|
|
668
635
|
timeout > 0 && (timeoutId = setTimeout(() => {
|
|
669
|
-
rpcPromises.delete(promiseId), reject(
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
636
|
+
rpcPromises.delete(promiseId), reject(/* @__PURE__ */ Error(`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`));
|
|
637
|
+
}, timeout), timeoutId?.unref?.()), rpcPromises.set(promiseId, {
|
|
638
|
+
resolve: resolve$1,
|
|
639
|
+
reject,
|
|
640
|
+
name,
|
|
641
|
+
timeoutId
|
|
642
|
+
}), sendPromise && sendPromise.catch((err) => {
|
|
675
643
|
clearTimeout(timeoutId), rpcPromises.delete(promiseId), reject(err);
|
|
676
644
|
});
|
|
677
645
|
try {
|
|
@@ -683,72 +651,56 @@ var createInvokeableTransport = (transport) => {
|
|
|
683
651
|
};
|
|
684
652
|
};
|
|
685
653
|
var normalizeModuleRunnerTransport = (transport) => {
|
|
686
|
-
|
|
687
|
-
let isConnected = !invokeableTransport.connect, connectingPromise;
|
|
654
|
+
let invokeableTransport = createInvokeableTransport(transport), isConnected = !invokeableTransport.connect, connectingPromise;
|
|
688
655
|
return {
|
|
689
656
|
...transport,
|
|
690
|
-
...invokeableTransport.connect ? {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
const maybePromise = invokeableTransport.connect({
|
|
698
|
-
onMessage: onMessage ?? (() => {
|
|
699
|
-
}),
|
|
700
|
-
onDisconnection() {
|
|
701
|
-
isConnected = false;
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
maybePromise && (connectingPromise = maybePromise, await connectingPromise, connectingPromise = void 0), isConnected = true;
|
|
705
|
-
}
|
|
706
|
-
} : {},
|
|
707
|
-
...invokeableTransport.disconnect ? {
|
|
708
|
-
async disconnect() {
|
|
709
|
-
isConnected && (connectingPromise && await connectingPromise, isConnected = false, await invokeableTransport.disconnect());
|
|
657
|
+
...invokeableTransport.connect ? { async connect(onMessage) {
|
|
658
|
+
if (isConnected) return;
|
|
659
|
+
if (connectingPromise) {
|
|
660
|
+
await connectingPromise;
|
|
661
|
+
return;
|
|
710
662
|
}
|
|
711
|
-
|
|
663
|
+
let maybePromise = invokeableTransport.connect({
|
|
664
|
+
onMessage: onMessage ?? (() => {
|
|
665
|
+
}),
|
|
666
|
+
onDisconnection() {
|
|
667
|
+
isConnected = false;
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
maybePromise && (connectingPromise = maybePromise, await connectingPromise, connectingPromise = void 0), isConnected = true;
|
|
671
|
+
} } : {},
|
|
672
|
+
...invokeableTransport.disconnect ? { async disconnect() {
|
|
673
|
+
isConnected && (connectingPromise && await connectingPromise, isConnected = false, await invokeableTransport.disconnect());
|
|
674
|
+
} } : {},
|
|
712
675
|
async send(data) {
|
|
713
676
|
if (invokeableTransport.send) {
|
|
714
|
-
if (!isConnected)
|
|
715
|
-
|
|
716
|
-
await connectingPromise;
|
|
717
|
-
else
|
|
718
|
-
throw new Error("send was called before connect");
|
|
677
|
+
if (!isConnected) if (connectingPromise) await connectingPromise;
|
|
678
|
+
else throw Error("send was called before connect");
|
|
719
679
|
await invokeableTransport.send(data);
|
|
720
680
|
}
|
|
721
681
|
},
|
|
722
682
|
async invoke(name, data) {
|
|
723
|
-
if (!isConnected)
|
|
724
|
-
|
|
725
|
-
await connectingPromise;
|
|
726
|
-
else
|
|
727
|
-
throw new Error("invoke was called before connect");
|
|
683
|
+
if (!isConnected) if (connectingPromise) await connectingPromise;
|
|
684
|
+
else throw Error("invoke was called before connect");
|
|
728
685
|
return invokeableTransport.invoke(name, data);
|
|
729
686
|
}
|
|
730
687
|
};
|
|
731
688
|
};
|
|
732
689
|
var createWebSocketModuleRunnerTransport = (options) => {
|
|
733
|
-
|
|
734
|
-
let ws, pingIntervalId;
|
|
690
|
+
let pingInterval = options.pingInterval ?? 3e4, ws, pingIntervalId;
|
|
735
691
|
return {
|
|
736
692
|
async connect({ onMessage, onDisconnection }) {
|
|
737
|
-
|
|
693
|
+
let socket = options.createConnection();
|
|
738
694
|
socket.addEventListener("message", async ({ data }) => {
|
|
739
695
|
onMessage(JSON.parse(data));
|
|
740
696
|
});
|
|
741
697
|
let isOpened = socket.readyState === socket.OPEN;
|
|
742
|
-
isOpened || await new Promise((
|
|
743
|
-
socket.addEventListener(
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
isOpened = true, resolve2();
|
|
747
|
-
},
|
|
748
|
-
{ once: true }
|
|
749
|
-
), socket.addEventListener("close", async () => {
|
|
698
|
+
isOpened || await new Promise((resolve$1, reject) => {
|
|
699
|
+
socket.addEventListener("open", () => {
|
|
700
|
+
isOpened = true, resolve$1();
|
|
701
|
+
}, { once: true }), socket.addEventListener("close", async () => {
|
|
750
702
|
if (!isOpened) {
|
|
751
|
-
reject(
|
|
703
|
+
reject(/* @__PURE__ */ Error("WebSocket closed without opened."));
|
|
752
704
|
return;
|
|
753
705
|
}
|
|
754
706
|
onMessage({
|
|
@@ -777,6 +729,7 @@ var ssrModuleExportsKey = "__vite_ssr_exports__";
|
|
|
777
729
|
var ssrImportKey = "__vite_ssr_import__";
|
|
778
730
|
var ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
|
|
779
731
|
var ssrExportAllKey = "__vite_ssr_exportAll__";
|
|
732
|
+
var ssrExportNameKey = "__vite_ssr_exportName__";
|
|
780
733
|
var ssrImportMetaKey = "__vite_ssr_import_meta__";
|
|
781
734
|
var noop = () => {
|
|
782
735
|
};
|
|
@@ -788,47 +741,57 @@ var hmrLogger = {
|
|
|
788
741
|
debug: (...msg) => console.log("[vite]", ...msg),
|
|
789
742
|
error: (error) => console.log("[vite]", error)
|
|
790
743
|
};
|
|
791
|
-
function createHMRHandler(
|
|
792
|
-
|
|
793
|
-
return (payload) => queue.enqueue(() =>
|
|
744
|
+
function createHMRHandler(handler) {
|
|
745
|
+
let queue = new Queue();
|
|
746
|
+
return (payload) => queue.enqueue(() => handler(payload));
|
|
794
747
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
748
|
+
var Queue = class {
|
|
749
|
+
queue = [];
|
|
750
|
+
pending = false;
|
|
751
|
+
enqueue(promise) {
|
|
752
|
+
return new Promise((resolve$1, reject) => {
|
|
753
|
+
this.queue.push({
|
|
754
|
+
promise,
|
|
755
|
+
resolve: resolve$1,
|
|
756
|
+
reject
|
|
757
|
+
}), this.dequeue();
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
dequeue() {
|
|
761
|
+
if (this.pending) return false;
|
|
762
|
+
let item = this.queue.shift();
|
|
763
|
+
return item ? (this.pending = true, item.promise().then(item.resolve).catch(item.reject).finally(() => {
|
|
764
|
+
this.pending = false, this.dequeue();
|
|
765
|
+
}), true) : false;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
function createHMRHandlerForRunner(runner) {
|
|
769
|
+
return createHMRHandler(async (payload) => {
|
|
770
|
+
let hmrClient = runner.hmrClient;
|
|
771
|
+
if (!(!hmrClient || runner.isClosed())) switch (payload.type) {
|
|
799
772
|
case "connected":
|
|
800
773
|
hmrClient.logger.debug("connected.");
|
|
801
774
|
break;
|
|
802
775
|
case "update":
|
|
803
|
-
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
hmrClient.logger.error("css hmr is not supported in runner mode.");
|
|
808
|
-
})
|
|
809
|
-
), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
|
776
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(payload.updates.map(async (update) => {
|
|
777
|
+
if (update.type === "js-update") return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
|
|
778
|
+
hmrClient.logger.error("css hmr is not supported in runner mode.");
|
|
779
|
+
})), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
|
810
780
|
break;
|
|
811
|
-
case "custom":
|
|
781
|
+
case "custom":
|
|
812
782
|
await hmrClient.notifyListeners(payload.event, payload.data);
|
|
813
783
|
break;
|
|
814
|
-
}
|
|
815
784
|
case "full-reload": {
|
|
816
|
-
|
|
817
|
-
runner,
|
|
818
|
-
getModulesByFile(runner, slash(triggeredBy))
|
|
819
|
-
) : findAllEntrypoints(runner);
|
|
785
|
+
let { triggeredBy } = payload, clearEntrypointUrls = triggeredBy ? getModulesEntrypoints(runner, getModulesByFile(runner, slash(triggeredBy))) : findAllEntrypoints(runner);
|
|
820
786
|
if (!clearEntrypointUrls.size) break;
|
|
821
787
|
hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.evaluatedModules.clear();
|
|
822
|
-
for (
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
err.code !== ERR_OUTDATED_OPTIMIZED_DEP && hmrClient.logger.error(
|
|
827
|
-
`An error happened during full reload
|
|
788
|
+
for (let url of clearEntrypointUrls) try {
|
|
789
|
+
await runner.import(url);
|
|
790
|
+
} catch (err) {
|
|
791
|
+
err.code !== ERR_OUTDATED_OPTIMIZED_DEP && hmrClient.logger.error(`An error happened during full reload
|
|
828
792
|
${err.message}
|
|
829
|
-
${err.stack}`
|
|
830
|
-
|
|
831
|
-
}
|
|
793
|
+
${err.stack}`);
|
|
794
|
+
}
|
|
832
795
|
break;
|
|
833
796
|
}
|
|
834
797
|
case "prune":
|
|
@@ -836,64 +799,41 @@ ${err.stack}`
|
|
|
836
799
|
break;
|
|
837
800
|
case "error": {
|
|
838
801
|
await hmrClient.notifyListeners("vite:error", payload);
|
|
839
|
-
|
|
840
|
-
hmrClient.logger.error(
|
|
841
|
-
`Internal Server Error
|
|
802
|
+
let err = payload.err;
|
|
803
|
+
hmrClient.logger.error(`Internal Server Error
|
|
842
804
|
${err.message}
|
|
843
|
-
${err.stack}`
|
|
844
|
-
);
|
|
805
|
+
${err.stack}`);
|
|
845
806
|
break;
|
|
846
807
|
}
|
|
847
808
|
case "ping":
|
|
848
809
|
break;
|
|
849
|
-
default:
|
|
850
|
-
|
|
810
|
+
default: {
|
|
811
|
+
let check = payload;
|
|
812
|
+
return check;
|
|
813
|
+
}
|
|
851
814
|
}
|
|
815
|
+
});
|
|
852
816
|
}
|
|
853
|
-
var Queue = class {
|
|
854
|
-
queue = [];
|
|
855
|
-
pending = false;
|
|
856
|
-
enqueue(promise) {
|
|
857
|
-
return new Promise((resolve2, reject) => {
|
|
858
|
-
this.queue.push({
|
|
859
|
-
promise,
|
|
860
|
-
resolve: resolve2,
|
|
861
|
-
reject
|
|
862
|
-
}), this.dequeue();
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
dequeue() {
|
|
866
|
-
if (this.pending)
|
|
867
|
-
return false;
|
|
868
|
-
const item = this.queue.shift();
|
|
869
|
-
return item ? (this.pending = true, item.promise().then(item.resolve).catch(item.reject).finally(() => {
|
|
870
|
-
this.pending = false, this.dequeue();
|
|
871
|
-
}), true) : false;
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
817
|
function getModulesByFile(runner, file) {
|
|
875
|
-
|
|
818
|
+
let nodes = runner.evaluatedModules.getModulesByFile(file);
|
|
876
819
|
return nodes ? [...nodes].map((node) => node.id) : [];
|
|
877
820
|
}
|
|
878
821
|
function getModulesEntrypoints(runner, modules, visited = /* @__PURE__ */ new Set(), entrypoints = /* @__PURE__ */ new Set()) {
|
|
879
|
-
for (
|
|
822
|
+
for (let moduleId of modules) {
|
|
880
823
|
if (visited.has(moduleId)) continue;
|
|
881
824
|
visited.add(moduleId);
|
|
882
|
-
|
|
883
|
-
if (module)
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
for (const importer of module.importers)
|
|
889
|
-
getModulesEntrypoints(runner, [importer], visited, entrypoints);
|
|
825
|
+
let module = runner.evaluatedModules.getModuleById(moduleId);
|
|
826
|
+
if (!module) continue;
|
|
827
|
+
if (!module.importers.size) {
|
|
828
|
+
entrypoints.add(module.url);
|
|
829
|
+
continue;
|
|
890
830
|
}
|
|
831
|
+
for (let importer of module.importers) getModulesEntrypoints(runner, [importer], visited, entrypoints);
|
|
891
832
|
}
|
|
892
833
|
return entrypoints;
|
|
893
834
|
}
|
|
894
835
|
function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
|
|
895
|
-
for (
|
|
896
|
-
mod.importers.size || entrypoints.add(mod.url);
|
|
836
|
+
for (let mod of runner.evaluatedModules.idToModuleMap.values()) mod.importers.size || entrypoints.add(mod.url);
|
|
897
837
|
return entrypoints;
|
|
898
838
|
}
|
|
899
839
|
var sourceMapCache = {};
|
|
@@ -902,16 +842,14 @@ var evaluatedModulesCache = /* @__PURE__ */ new Set();
|
|
|
902
842
|
var retrieveFileHandlers = /* @__PURE__ */ new Set();
|
|
903
843
|
var retrieveSourceMapHandlers = /* @__PURE__ */ new Set();
|
|
904
844
|
var createExecHandlers = (handlers) => (...args) => {
|
|
905
|
-
for (
|
|
906
|
-
|
|
845
|
+
for (let handler of handlers) {
|
|
846
|
+
let result = handler(...args);
|
|
907
847
|
if (result) return result;
|
|
908
848
|
}
|
|
909
849
|
return null;
|
|
910
850
|
};
|
|
911
851
|
var retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers);
|
|
912
|
-
var retrieveSourceMapFromHandlers = createExecHandlers(
|
|
913
|
-
retrieveSourceMapHandlers
|
|
914
|
-
);
|
|
852
|
+
var retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
|
|
915
853
|
var overridden = false;
|
|
916
854
|
var originalPrepare = Error.prepareStackTrace;
|
|
917
855
|
function resetInterceptor(runner, options) {
|
|
@@ -922,48 +860,43 @@ function interceptStackTrace(runner, options = {}) {
|
|
|
922
860
|
}
|
|
923
861
|
function supportRelativeURL(file, url) {
|
|
924
862
|
if (!file) return url;
|
|
925
|
-
|
|
926
|
-
let protocol = match ? match[0] : "";
|
|
927
|
-
const startPath = dir.slice(protocol.length);
|
|
863
|
+
let dir = posixDirname(slash(file)), match = /^\w+:\/\/[^/]*/.exec(dir), protocol = match ? match[0] : "", startPath = dir.slice(protocol.length);
|
|
928
864
|
return protocol && /^\/\w:/.test(startPath) ? (protocol += "/", protocol + slash(posixResolve(startPath, url))) : protocol + posixResolve(startPath, url);
|
|
929
865
|
}
|
|
930
866
|
function getRunnerSourceMap(position) {
|
|
931
|
-
for (
|
|
932
|
-
|
|
933
|
-
if (sourceMap)
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
};
|
|
867
|
+
for (let moduleGraph of evaluatedModulesCache) {
|
|
868
|
+
let sourceMap = moduleGraph.getModuleSourceMapById(position.source);
|
|
869
|
+
if (sourceMap) return {
|
|
870
|
+
url: position.source,
|
|
871
|
+
map: sourceMap,
|
|
872
|
+
vite: true
|
|
873
|
+
};
|
|
939
874
|
}
|
|
940
875
|
return null;
|
|
941
876
|
}
|
|
942
877
|
function retrieveFile(path) {
|
|
943
878
|
if (path in fileContentsCache) return fileContentsCache[path];
|
|
944
|
-
|
|
879
|
+
let content = retrieveFileFromHandlers(path);
|
|
945
880
|
return typeof content == "string" ? (fileContentsCache[path] = content, content) : null;
|
|
946
881
|
}
|
|
947
882
|
function retrieveSourceMapURL(source) {
|
|
948
|
-
|
|
883
|
+
let fileData = retrieveFile(source);
|
|
949
884
|
if (!fileData) return null;
|
|
950
|
-
|
|
951
|
-
let lastMatch, match;
|
|
885
|
+
let re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm, lastMatch, match;
|
|
952
886
|
for (; match = re.exec(fileData); ) lastMatch = match;
|
|
953
887
|
return lastMatch ? lastMatch[1] : null;
|
|
954
888
|
}
|
|
955
889
|
var reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
956
890
|
function retrieveSourceMap(source) {
|
|
957
|
-
|
|
891
|
+
let urlAndMap = retrieveSourceMapFromHandlers(source);
|
|
958
892
|
if (urlAndMap) return urlAndMap;
|
|
959
893
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
960
894
|
if (!sourceMappingURL) return null;
|
|
961
895
|
let sourceMapData;
|
|
962
896
|
if (reSourceMap.test(sourceMappingURL)) {
|
|
963
|
-
|
|
897
|
+
let rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
964
898
|
sourceMapData = Buffer.from(rawData, "base64").toString(), sourceMappingURL = source;
|
|
965
|
-
} else
|
|
966
|
-
sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
|
|
899
|
+
} else sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
|
|
967
900
|
return sourceMapData ? {
|
|
968
901
|
url: sourceMappingURL,
|
|
969
902
|
map: sourceMapData
|
|
@@ -972,49 +905,41 @@ function retrieveSourceMap(source) {
|
|
|
972
905
|
function mapSourcePosition(position) {
|
|
973
906
|
if (!position.source) return position;
|
|
974
907
|
let sourceMap = getRunnerSourceMap(position);
|
|
975
|
-
if (sourceMap
|
|
976
|
-
|
|
908
|
+
if (sourceMap ||= sourceMapCache[position.source], !sourceMap) {
|
|
909
|
+
let urlAndMap = retrieveSourceMap(position.source);
|
|
977
910
|
if (urlAndMap && urlAndMap.map) {
|
|
978
|
-
|
|
911
|
+
let url = urlAndMap.url;
|
|
979
912
|
sourceMap = sourceMapCache[position.source] = {
|
|
980
913
|
url,
|
|
981
|
-
map: new DecodedMap(
|
|
982
|
-
typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map,
|
|
983
|
-
url
|
|
984
|
-
)
|
|
914
|
+
map: new DecodedMap(typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map, url)
|
|
985
915
|
};
|
|
986
|
-
|
|
916
|
+
let contents = sourceMap.map?.map.sourcesContent;
|
|
987
917
|
sourceMap.map && contents && sourceMap.map.resolvedSources.forEach((source, i) => {
|
|
988
|
-
|
|
918
|
+
let content = contents[i];
|
|
989
919
|
if (content && source && url) {
|
|
990
|
-
|
|
920
|
+
let contentUrl = supportRelativeURL(url, source);
|
|
991
921
|
fileContentsCache[contentUrl] = content;
|
|
992
922
|
}
|
|
993
923
|
});
|
|
994
|
-
} else
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
};
|
|
924
|
+
} else sourceMap = sourceMapCache[position.source] = {
|
|
925
|
+
url: null,
|
|
926
|
+
map: null
|
|
927
|
+
};
|
|
999
928
|
}
|
|
1000
929
|
if (sourceMap.map && sourceMap.url) {
|
|
1001
|
-
|
|
1002
|
-
if (originalPosition && originalPosition.source != null)
|
|
1003
|
-
return originalPosition.source = supportRelativeURL(
|
|
1004
|
-
sourceMap.url,
|
|
1005
|
-
originalPosition.source
|
|
1006
|
-
), sourceMap.vite && (originalPosition._vite = true), originalPosition;
|
|
930
|
+
let originalPosition = getOriginalPosition(sourceMap.map, position);
|
|
931
|
+
if (originalPosition && originalPosition.source != null) return originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source), sourceMap.vite && (originalPosition._vite = true), originalPosition;
|
|
1007
932
|
}
|
|
1008
933
|
return position;
|
|
1009
934
|
}
|
|
1010
935
|
function mapEvalOrigin(origin) {
|
|
1011
936
|
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
|
1012
937
|
if (match) {
|
|
1013
|
-
|
|
938
|
+
let position = mapSourcePosition({
|
|
1014
939
|
name: null,
|
|
1015
940
|
source: match[2],
|
|
1016
941
|
line: +match[3],
|
|
1017
|
-
column:
|
|
942
|
+
column: match[4] - 1
|
|
1018
943
|
});
|
|
1019
944
|
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
1020
945
|
}
|
|
@@ -1022,62 +947,56 @@ function mapEvalOrigin(origin) {
|
|
|
1022
947
|
}
|
|
1023
948
|
function CallSiteToString() {
|
|
1024
949
|
let fileName, fileLocation = "";
|
|
1025
|
-
if (this.isNative())
|
|
1026
|
-
fileLocation = "native";
|
|
950
|
+
if (this.isNative()) fileLocation = "native";
|
|
1027
951
|
else {
|
|
1028
952
|
fileName = this.getScriptNameOrSourceURL(), !fileName && this.isEval() && (fileLocation = this.getEvalOrigin(), fileLocation += ", "), fileName ? fileLocation += fileName : fileLocation += "<anonymous>";
|
|
1029
|
-
|
|
953
|
+
let lineNumber = this.getLineNumber();
|
|
1030
954
|
if (lineNumber != null) {
|
|
1031
955
|
fileLocation += `:${lineNumber}`;
|
|
1032
|
-
|
|
956
|
+
let columnNumber = this.getColumnNumber();
|
|
1033
957
|
columnNumber && (fileLocation += `:${columnNumber}`);
|
|
1034
958
|
}
|
|
1035
959
|
}
|
|
1036
|
-
let line = "";
|
|
1037
|
-
|
|
1038
|
-
let addSuffix = true;
|
|
1039
|
-
const isConstructor = this.isConstructor();
|
|
1040
|
-
if (this.isToplevel() || isConstructor)
|
|
1041
|
-
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = false);
|
|
1042
|
-
else {
|
|
960
|
+
let line = "", functionName = this.getFunctionName(), addSuffix = true, isConstructor = this.isConstructor(), isMethodCall = !(this.isToplevel() || isConstructor);
|
|
961
|
+
if (isMethodCall) {
|
|
1043
962
|
let typeName = this.getTypeName();
|
|
1044
963
|
typeName === "[object Object]" && (typeName = "null");
|
|
1045
|
-
|
|
964
|
+
let methodName = this.getMethodName();
|
|
1046
965
|
functionName ? (typeName && functionName.indexOf(typeName) !== 0 && (line += `${typeName}.`), line += functionName, methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1 && (line += ` [as ${methodName}]`)) : line += `${typeName}.${methodName || "<anonymous>"}`;
|
|
1047
|
-
}
|
|
966
|
+
} else isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = false);
|
|
1048
967
|
return addSuffix && (line += ` (${fileLocation})`), line;
|
|
1049
968
|
}
|
|
1050
969
|
function cloneCallSite(frame) {
|
|
1051
|
-
|
|
970
|
+
let object = {};
|
|
1052
971
|
return Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
1053
|
-
|
|
972
|
+
let key = name;
|
|
1054
973
|
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
1055
974
|
return frame[key].call(frame);
|
|
1056
975
|
} : frame[key];
|
|
1057
976
|
}), object.toString = CallSiteToString, object;
|
|
1058
977
|
}
|
|
1059
978
|
function wrapCallSite(frame, state) {
|
|
1060
|
-
if (state === void 0 && (state = {
|
|
1061
|
-
|
|
1062
|
-
|
|
979
|
+
if (state === void 0 && (state = {
|
|
980
|
+
nextPosition: null,
|
|
981
|
+
curPosition: null
|
|
982
|
+
}), frame.isNative()) return state.curPosition = null, frame;
|
|
983
|
+
let source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
1063
984
|
if (source) {
|
|
1064
|
-
|
|
1065
|
-
let column = frame.getColumnNumber() - 1;
|
|
1066
|
-
const headerLength = 62;
|
|
985
|
+
let line = frame.getLineNumber(), column = frame.getColumnNumber() - 1, headerLength = 62;
|
|
1067
986
|
line === 1 && column > headerLength && !frame.isEval() && (column -= headerLength);
|
|
1068
|
-
|
|
987
|
+
let position = mapSourcePosition({
|
|
1069
988
|
name: null,
|
|
1070
989
|
source,
|
|
1071
990
|
line,
|
|
1072
991
|
column
|
|
1073
992
|
});
|
|
1074
993
|
state.curPosition = position, frame = cloneCallSite(frame);
|
|
1075
|
-
|
|
994
|
+
let originalFunctionName = frame.getFunctionName;
|
|
1076
995
|
return frame.getFunctionName = function() {
|
|
1077
|
-
|
|
996
|
+
let name = (() => state.nextPosition == null ? originalFunctionName() : state.nextPosition.name || originalFunctionName())();
|
|
1078
997
|
return name === "eval" && "_vite" in position ? null : name;
|
|
1079
998
|
}, frame.getFileName = function() {
|
|
1080
|
-
return position.source ??
|
|
999
|
+
return position.source ?? null;
|
|
1081
1000
|
}, frame.getLineNumber = function() {
|
|
1082
1001
|
return position.line;
|
|
1083
1002
|
}, frame.getColumnNumber = function() {
|
|
@@ -1087,156 +1006,113 @@ function wrapCallSite(frame, state) {
|
|
|
1087
1006
|
}, frame;
|
|
1088
1007
|
}
|
|
1089
1008
|
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
1090
|
-
return origin
|
|
1009
|
+
return origin ? (origin = mapEvalOrigin(origin), frame = cloneCallSite(frame), frame.getEvalOrigin = function() {
|
|
1091
1010
|
return origin || void 0;
|
|
1092
|
-
}
|
|
1011
|
+
}, frame) : frame;
|
|
1093
1012
|
}
|
|
1094
1013
|
function prepareStackTrace(error, stack) {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1014
|
+
let name = error.name || "Error", message = error.message || "", errorString = `${name}: ${message}`, state = {
|
|
1015
|
+
nextPosition: null,
|
|
1016
|
+
curPosition: null
|
|
1017
|
+
}, processedStack = [];
|
|
1018
|
+
for (let i = stack.length - 1; i >= 0; i--) processedStack.push(`
|
|
1098
1019
|
at ${wrapCallSite(stack[i], state)}`), state.nextPosition = state.curPosition;
|
|
1099
1020
|
return state.curPosition = state.nextPosition = null, errorString + processedStack.reverse().join("");
|
|
1100
1021
|
}
|
|
1101
1022
|
function enableSourceMapSupport(runner) {
|
|
1102
1023
|
if (runner.options.sourcemapInterceptor === "node") {
|
|
1103
|
-
if (typeof process > "u")
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
);
|
|
1107
|
-
if (typeof process.setSourceMapsEnabled != "function")
|
|
1108
|
-
throw new TypeError(
|
|
1109
|
-
`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`
|
|
1110
|
-
);
|
|
1111
|
-
const isEnabledAlready = process.sourceMapsEnabled ?? false;
|
|
1024
|
+
if (typeof process > "u") throw TypeError(`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`);
|
|
1025
|
+
if (typeof process.setSourceMapsEnabled != "function") throw TypeError(`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`);
|
|
1026
|
+
let isEnabledAlready = process.sourceMapsEnabled ?? false;
|
|
1112
1027
|
return process.setSourceMapsEnabled(true), () => !isEnabledAlready && process.setSourceMapsEnabled(false);
|
|
1113
1028
|
}
|
|
1114
|
-
return interceptStackTrace(
|
|
1115
|
-
runner,
|
|
1116
|
-
typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0
|
|
1117
|
-
);
|
|
1029
|
+
return interceptStackTrace(runner, typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0);
|
|
1118
1030
|
}
|
|
1119
1031
|
var ESModulesEvaluator = class {
|
|
1120
1032
|
startOffset = getAsyncFunctionDeclarationPaddingLineCount();
|
|
1121
1033
|
async runInlinedModule(context, code) {
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
ssrImportMetaKey,
|
|
1125
|
-
ssrImportKey,
|
|
1126
|
-
ssrDynamicImportKey,
|
|
1127
|
-
ssrExportAllKey,
|
|
1128
|
-
// source map should already be inlined by Vite
|
|
1129
|
-
'"use strict";' + code
|
|
1130
|
-
)(
|
|
1131
|
-
context[ssrModuleExportsKey],
|
|
1132
|
-
context[ssrImportMetaKey],
|
|
1133
|
-
context[ssrImportKey],
|
|
1134
|
-
context[ssrDynamicImportKey],
|
|
1135
|
-
context[ssrExportAllKey]
|
|
1136
|
-
), Object.seal(context[ssrModuleExportsKey]);
|
|
1034
|
+
let initModule = new AsyncFunction(ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, '"use strict";' + code);
|
|
1035
|
+
await initModule(context[ssrModuleExportsKey], context[ssrImportMetaKey], context[ssrImportKey], context[ssrDynamicImportKey], context[ssrExportAllKey], context[ssrExportNameKey]), Object.seal(context[ssrModuleExportsKey]);
|
|
1137
1036
|
}
|
|
1138
1037
|
runExternalModule(filepath) {
|
|
1139
1038
|
return import(filepath);
|
|
1140
1039
|
}
|
|
1141
1040
|
};
|
|
1142
1041
|
var ModuleRunner = class {
|
|
1143
|
-
constructor(options, evaluator = new ESModulesEvaluator(), debug) {
|
|
1144
|
-
if (this.options = options, this.evaluator = evaluator, this.debug = debug, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr !== false) {
|
|
1145
|
-
const optionsHmr = options.hmr ?? true, resolvedHmrLogger = optionsHmr === true || optionsHmr.logger === void 0 ? hmrLogger : optionsHmr.logger === false ? silentConsole : optionsHmr.logger;
|
|
1146
|
-
if (this.hmrClient = new HMRClient(
|
|
1147
|
-
resolvedHmrLogger,
|
|
1148
|
-
this.transport,
|
|
1149
|
-
({ acceptedPath }) => this.import(acceptedPath)
|
|
1150
|
-
), !this.transport.connect)
|
|
1151
|
-
throw new Error(
|
|
1152
|
-
"HMR is not supported by this runner transport, but `hmr` option was set to true"
|
|
1153
|
-
);
|
|
1154
|
-
this.transport.connect(createHMRHandler(this));
|
|
1155
|
-
} else
|
|
1156
|
-
this.transport.connect?.();
|
|
1157
|
-
options.sourcemapInterceptor !== false && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
|
1158
|
-
}
|
|
1159
1042
|
evaluatedModules;
|
|
1160
1043
|
hmrClient;
|
|
1161
|
-
envProxy = new Proxy({}, {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
});
|
|
1044
|
+
envProxy = new Proxy({}, { get(_, p) {
|
|
1045
|
+
throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
|
1046
|
+
} });
|
|
1168
1047
|
transport;
|
|
1169
1048
|
resetSourceMapSupport;
|
|
1170
1049
|
concurrentModuleNodePromises = /* @__PURE__ */ new Map();
|
|
1171
1050
|
closed = false;
|
|
1051
|
+
constructor(options, evaluator = new ESModulesEvaluator(), debug) {
|
|
1052
|
+
if (this.options = options, this.evaluator = evaluator, this.debug = debug, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr !== false) {
|
|
1053
|
+
let optionsHmr = options.hmr ?? true, resolvedHmrLogger = optionsHmr === true || optionsHmr.logger === void 0 ? hmrLogger : optionsHmr.logger === false ? silentConsole : optionsHmr.logger;
|
|
1054
|
+
if (this.hmrClient = new HMRClient(resolvedHmrLogger, this.transport, ({ acceptedPath }) => this.import(acceptedPath)), !this.transport.connect) throw Error("HMR is not supported by this runner transport, but `hmr` option was set to true");
|
|
1055
|
+
this.transport.connect(createHMRHandlerForRunner(this));
|
|
1056
|
+
} else this.transport.connect?.();
|
|
1057
|
+
options.sourcemapInterceptor !== false && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
|
1058
|
+
}
|
|
1172
1059
|
/**
|
|
1173
|
-
|
|
1174
|
-
|
|
1060
|
+
* URL to execute. Accepts file path, server path or id relative to the root.
|
|
1061
|
+
*/
|
|
1175
1062
|
async import(url) {
|
|
1176
|
-
|
|
1063
|
+
let fetchedModule = await this.cachedModule(url);
|
|
1177
1064
|
return await this.cachedRequest(url, fetchedModule);
|
|
1178
1065
|
}
|
|
1179
1066
|
/**
|
|
1180
|
-
|
|
1181
|
-
|
|
1067
|
+
* Clear all caches including HMR listeners.
|
|
1068
|
+
*/
|
|
1182
1069
|
clearCache() {
|
|
1183
1070
|
this.evaluatedModules.clear(), this.hmrClient?.clear();
|
|
1184
1071
|
}
|
|
1185
1072
|
/**
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1073
|
+
* Clears all caches, removes all HMR listeners, and resets source map support.
|
|
1074
|
+
* This method doesn't stop the HMR connection.
|
|
1075
|
+
*/
|
|
1189
1076
|
async close() {
|
|
1190
1077
|
this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = true, await this.transport.disconnect?.();
|
|
1191
1078
|
}
|
|
1192
1079
|
/**
|
|
1193
|
-
|
|
1194
|
-
|
|
1080
|
+
* Returns `true` if the runtime has been closed by calling `close()` method.
|
|
1081
|
+
*/
|
|
1195
1082
|
isClosed() {
|
|
1196
1083
|
return this.closed;
|
|
1197
1084
|
}
|
|
1198
1085
|
processImport(exports, fetchResult, metadata) {
|
|
1199
|
-
if (!("externalize" in fetchResult))
|
|
1200
|
-
|
|
1201
|
-
const { url, type } = fetchResult;
|
|
1086
|
+
if (!("externalize" in fetchResult)) return exports;
|
|
1087
|
+
let { url, type } = fetchResult;
|
|
1202
1088
|
return type !== "module" && type !== "commonjs" || analyzeImportedModDifference(exports, url, type, metadata), exports;
|
|
1203
1089
|
}
|
|
1204
1090
|
isCircularModule(mod) {
|
|
1205
|
-
for (
|
|
1206
|
-
if (mod.importers.has(importedFile))
|
|
1207
|
-
return true;
|
|
1091
|
+
for (let importedFile of mod.imports) if (mod.importers.has(importedFile)) return true;
|
|
1208
1092
|
return false;
|
|
1209
1093
|
}
|
|
1210
1094
|
isCircularImport(importers, moduleUrl, visited = /* @__PURE__ */ new Set()) {
|
|
1211
|
-
for (
|
|
1212
|
-
if (visited.has(importer))
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
const mod = this.evaluatedModules.getModuleById(importer);
|
|
1217
|
-
if (mod && mod.importers.size && this.isCircularImport(mod.importers, moduleUrl, visited))
|
|
1218
|
-
return true;
|
|
1095
|
+
for (let importer of importers) {
|
|
1096
|
+
if (visited.has(importer)) continue;
|
|
1097
|
+
if (visited.add(importer), importer === moduleUrl) return true;
|
|
1098
|
+
let mod = this.evaluatedModules.getModuleById(importer);
|
|
1099
|
+
if (mod && mod.importers.size && this.isCircularImport(mod.importers, moduleUrl, visited)) return true;
|
|
1219
1100
|
}
|
|
1220
1101
|
return false;
|
|
1221
1102
|
}
|
|
1222
1103
|
async cachedRequest(url, mod, callstack = [], metadata) {
|
|
1223
|
-
|
|
1224
|
-
if (importee && importers.add(importee), (callstack.includes(moduleId) || this.isCircularModule(mod) || this.isCircularImport(importers, moduleId)) && mod.exports)
|
|
1225
|
-
return this.processImport(mod.exports, meta, metadata);
|
|
1104
|
+
let meta = mod.meta, moduleId = meta.id, { importers } = mod, importee = callstack[callstack.length - 1];
|
|
1105
|
+
if (importee && importers.add(importee), (callstack.includes(moduleId) || this.isCircularModule(mod) || this.isCircularImport(importers, moduleId)) && mod.exports) return this.processImport(mod.exports, meta, metadata);
|
|
1226
1106
|
let debugTimer;
|
|
1227
1107
|
this.debug && (debugTimer = setTimeout(() => {
|
|
1228
|
-
|
|
1229
|
-
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join(
|
|
1230
|
-
`
|
|
1231
|
-
|
|
1232
|
-
`[module runner] module ${moduleId} takes over 2s to load.
|
|
1233
|
-
${getStack()}`
|
|
1234
|
-
);
|
|
1108
|
+
let getStack = () => `stack:
|
|
1109
|
+
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join("\n")}`;
|
|
1110
|
+
this.debug(`[module runner] module ${moduleId} takes over 2s to load.
|
|
1111
|
+
${getStack()}`);
|
|
1235
1112
|
}, 2e3));
|
|
1236
1113
|
try {
|
|
1237
|
-
if (mod.promise)
|
|
1238
|
-
|
|
1239
|
-
const promise = this.directRequest(url, mod, callstack);
|
|
1114
|
+
if (mod.promise) return this.processImport(await mod.promise, meta, metadata);
|
|
1115
|
+
let promise = this.directRequest(url, mod, callstack);
|
|
1240
1116
|
return mod.promise = promise, mod.evaluated = false, this.processImport(await promise, meta, metadata);
|
|
1241
1117
|
} finally {
|
|
1242
1118
|
mod.evaluated = true, debugTimer && clearTimeout(debugTimer);
|
|
@@ -1244,77 +1120,62 @@ ${getStack()}`
|
|
|
1244
1120
|
}
|
|
1245
1121
|
async cachedModule(url, importer) {
|
|
1246
1122
|
let cached = this.concurrentModuleNodePromises.get(url);
|
|
1247
|
-
if (cached)
|
|
1248
|
-
this.debug?.("[module runner] using cached module info for", url);
|
|
1123
|
+
if (cached) this.debug?.("[module runner] using cached module info for", url);
|
|
1249
1124
|
else {
|
|
1250
|
-
|
|
1251
|
-
cached = this.getModuleInformation(url, importer, cachedModule).finally(
|
|
1252
|
-
()
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
), this.concurrentModuleNodePromises.set(url, cached);
|
|
1125
|
+
let cachedModule = this.evaluatedModules.getModuleByUrl(url);
|
|
1126
|
+
cached = this.getModuleInformation(url, importer, cachedModule).finally(() => {
|
|
1127
|
+
this.concurrentModuleNodePromises.delete(url);
|
|
1128
|
+
}), this.concurrentModuleNodePromises.set(url, cached);
|
|
1256
1129
|
}
|
|
1257
1130
|
return cached;
|
|
1258
1131
|
}
|
|
1259
1132
|
async getModuleInformation(url, importer, cachedModule) {
|
|
1260
|
-
if (this.closed)
|
|
1261
|
-
throw new Error("Vite module runner has been closed.");
|
|
1133
|
+
if (this.closed) throw Error("Vite module runner has been closed.");
|
|
1262
1134
|
this.debug?.("[module runner] fetching", url);
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
);
|
|
1135
|
+
let isCached = !!(typeof cachedModule == "object" && cachedModule.meta), fetchedModule = url.startsWith("data:") ? {
|
|
1136
|
+
externalize: url,
|
|
1137
|
+
type: "builtin"
|
|
1138
|
+
} : await this.transport.invoke("fetchModule", [
|
|
1139
|
+
url,
|
|
1140
|
+
importer,
|
|
1141
|
+
{
|
|
1142
|
+
cached: isCached,
|
|
1143
|
+
startOffset: this.evaluator.startOffset
|
|
1144
|
+
}
|
|
1145
|
+
]);
|
|
1274
1146
|
if ("cache" in fetchedModule) {
|
|
1275
|
-
if (!cachedModule || !cachedModule.meta)
|
|
1276
|
-
throw new Error(
|
|
1277
|
-
`Module "${url}" was mistakenly invalidated during fetch phase.`
|
|
1278
|
-
);
|
|
1147
|
+
if (!cachedModule || !cachedModule.meta) throw Error(`Module "${url}" was mistakenly invalidated during fetch phase.`);
|
|
1279
1148
|
return cachedModule;
|
|
1280
1149
|
}
|
|
1281
|
-
|
|
1150
|
+
let moduleId = "externalize" in fetchedModule ? fetchedModule.externalize : fetchedModule.id, moduleUrl = "url" in fetchedModule ? fetchedModule.url : url, module = this.evaluatedModules.ensureModule(moduleId, moduleUrl);
|
|
1282
1151
|
return "invalidate" in fetchedModule && fetchedModule.invalidate && this.evaluatedModules.invalidateModule(module), fetchedModule.url = moduleUrl, fetchedModule.id = moduleId, module.meta = fetchedModule, module;
|
|
1283
1152
|
}
|
|
1284
|
-
// override is allowed, consider this a public API
|
|
1285
1153
|
async directRequest(url, mod, _callstack) {
|
|
1286
|
-
|
|
1287
|
-
|
|
1154
|
+
let fetchResult = mod.meta, moduleId = fetchResult.id, callstack = [..._callstack, moduleId], request = async (dep, metadata) => {
|
|
1155
|
+
let importer = "file" in fetchResult && fetchResult.file || moduleId, depMod = await this.cachedModule(dep, importer);
|
|
1288
1156
|
return depMod.importers.add(moduleId), mod.imports.add(depMod.id), this.cachedRequest(dep, depMod, callstack, metadata);
|
|
1289
1157
|
}, dynamicRequest = async (dep) => (dep = String(dep), dep[0] === "." && (dep = posixResolve(posixDirname(url), dep)), request(dep, { isDynamicImport: true }));
|
|
1290
1158
|
if ("externalize" in fetchResult) {
|
|
1291
|
-
|
|
1159
|
+
let { externalize } = fetchResult;
|
|
1292
1160
|
this.debug?.("[module runner] externalizing", externalize);
|
|
1293
|
-
|
|
1294
|
-
return mod.exports =
|
|
1161
|
+
let exports$1 = await this.evaluator.runExternalModule(externalize);
|
|
1162
|
+
return mod.exports = exports$1, exports$1;
|
|
1295
1163
|
}
|
|
1296
|
-
|
|
1164
|
+
let { code, file } = fetchResult;
|
|
1297
1165
|
if (code == null) {
|
|
1298
|
-
|
|
1299
|
-
throw
|
|
1300
|
-
`[module runner] Failed to load "${url}"${importer ? ` imported from ${importer}` : ""}`
|
|
1301
|
-
);
|
|
1166
|
+
let importer = callstack[callstack.length - 2];
|
|
1167
|
+
throw Error(`[module runner] Failed to load "${url}"${importer ? ` imported from ${importer}` : ""}`);
|
|
1302
1168
|
}
|
|
1303
|
-
|
|
1169
|
+
let modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname$1 = posixDirname(modulePath), meta = {
|
|
1304
1170
|
filename: isWindows ? toWindowsPath(filename) : filename,
|
|
1305
|
-
dirname: isWindows ? toWindowsPath(
|
|
1171
|
+
dirname: isWindows ? toWindowsPath(dirname$1) : dirname$1,
|
|
1306
1172
|
url: href,
|
|
1307
1173
|
env: this.envProxy,
|
|
1308
1174
|
resolve(_id, _parent) {
|
|
1309
|
-
throw
|
|
1310
|
-
'[module runner] "import.meta.resolve" is not supported.'
|
|
1311
|
-
);
|
|
1175
|
+
throw Error('[module runner] "import.meta.resolve" is not supported.');
|
|
1312
1176
|
},
|
|
1313
|
-
// should be replaced during transformation
|
|
1314
1177
|
glob() {
|
|
1315
|
-
throw
|
|
1316
|
-
'[module runner] "import.meta.glob" is statically replaced during file transformation. Make sure to reference it by the full name.'
|
|
1317
|
-
);
|
|
1178
|
+
throw Error('[module runner] "import.meta.glob" is statically replaced during file transformation. Make sure to reference it by the full name.');
|
|
1318
1179
|
}
|
|
1319
1180
|
}, exports = /* @__PURE__ */ Object.create(null);
|
|
1320
1181
|
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
@@ -1326,19 +1187,23 @@ ${getStack()}`
|
|
|
1326
1187
|
this.hmrClient && Object.defineProperty(meta, "hot", {
|
|
1327
1188
|
enumerable: true,
|
|
1328
1189
|
get: () => {
|
|
1329
|
-
if (!this.hmrClient)
|
|
1330
|
-
throw new Error("[module runner] HMR client was closed.");
|
|
1190
|
+
if (!this.hmrClient) throw Error("[module runner] HMR client was closed.");
|
|
1331
1191
|
return this.debug?.("[module runner] creating hmr context for", mod.url), hotContext ||= new HMRContext(this.hmrClient, mod.url), hotContext;
|
|
1332
1192
|
},
|
|
1333
1193
|
set: (value) => {
|
|
1334
1194
|
hotContext = value;
|
|
1335
1195
|
}
|
|
1336
1196
|
});
|
|
1337
|
-
|
|
1197
|
+
let context = {
|
|
1338
1198
|
[ssrImportKey]: request,
|
|
1339
1199
|
[ssrDynamicImportKey]: dynamicRequest,
|
|
1340
1200
|
[ssrModuleExportsKey]: exports,
|
|
1341
1201
|
[ssrExportAllKey]: (obj) => exportAll(exports, obj),
|
|
1202
|
+
[ssrExportNameKey]: (name, getter) => Object.defineProperty(exports, name, {
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
configurable: true,
|
|
1205
|
+
get: getter
|
|
1206
|
+
}),
|
|
1342
1207
|
[ssrImportMetaKey]: meta
|
|
1343
1208
|
};
|
|
1344
1209
|
return this.debug?.("[module runner] executing", href), await this.evaluator.runInlinedModule(context, code, mod), exports;
|
|
@@ -1346,16 +1211,14 @@ ${getStack()}`
|
|
|
1346
1211
|
};
|
|
1347
1212
|
function exportAll(exports, sourceModule) {
|
|
1348
1213
|
if (exports !== sourceModule && !(isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)) {
|
|
1349
|
-
for (
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
} catch {
|
|
1358
|
-
}
|
|
1214
|
+
for (let key in sourceModule) if (key !== "default" && key !== "__esModule" && !(key in exports)) try {
|
|
1215
|
+
Object.defineProperty(exports, key, {
|
|
1216
|
+
enumerable: true,
|
|
1217
|
+
configurable: true,
|
|
1218
|
+
get: () => sourceModule[key]
|
|
1219
|
+
});
|
|
1220
|
+
} catch {
|
|
1221
|
+
}
|
|
1359
1222
|
}
|
|
1360
1223
|
}
|
|
1361
1224
|
|