@cloudflare/vite-plugin 0.1.12 → 0.1.14
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 +61 -1
- package/dist/asset-workers/asset-worker.js +449 -420
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2168 -2015
- package/dist/runner-worker/index.js +55 -22
- package/package.json +10 -9
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
2
|
+
import assert8 from "node:assert";
|
|
3
3
|
import * as fs5 from "node:fs";
|
|
4
|
+
import * as fsp2 from "node:fs/promises";
|
|
4
5
|
import { builtinModules as builtinModules2 } from "node:module";
|
|
5
6
|
import * as path7 from "node:path";
|
|
6
7
|
import { createMiddleware } from "@hattip/adapter-node";
|
|
@@ -1073,997 +1074,297 @@ var MagicString = class _MagicString {
|
|
|
1073
1074
|
import { Miniflare } from "miniflare";
|
|
1074
1075
|
import * as vite6 from "vite";
|
|
1075
1076
|
|
|
1076
|
-
// src/cloudflare-environment.ts
|
|
1077
|
-
import assert from "node:assert";
|
|
1078
|
-
import * as vite2 from "vite";
|
|
1079
|
-
|
|
1080
1077
|
// src/constants.ts
|
|
1081
1078
|
var ROUTER_WORKER_NAME = "__router-worker__";
|
|
1082
1079
|
var ASSET_WORKER_NAME = "__asset-worker__";
|
|
1083
1080
|
var ASSET_WORKERS_COMPATIBILITY_DATE = "2024-10-04";
|
|
1084
|
-
var
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
var
|
|
1081
|
+
var ADDITIONAL_MODULE_TYPES = [
|
|
1082
|
+
"CompiledWasm",
|
|
1083
|
+
"Data",
|
|
1084
|
+
"Text"
|
|
1085
|
+
];
|
|
1086
|
+
var DEFAULT_INSPECTOR_PORT = 9229;
|
|
1090
1087
|
|
|
1091
|
-
// src/
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
headers: [["accept-encoding", "identity"], ...request.headers],
|
|
1103
|
-
body: request.body,
|
|
1104
|
-
duplex: "half"
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
function nodeHeadersToWebHeaders(nodeHeaders) {
|
|
1108
|
-
const headers = new Headers();
|
|
1109
|
-
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
1110
|
-
if (typeof value === "string") {
|
|
1111
|
-
headers.append(key, value);
|
|
1112
|
-
} else if (Array.isArray(value)) {
|
|
1113
|
-
for (const item of value) {
|
|
1114
|
-
headers.append(key, item);
|
|
1088
|
+
// src/additional-modules.ts
|
|
1089
|
+
var moduleRules = [
|
|
1090
|
+
{ type: "CompiledWasm", extensions: [".wasm", ".wasm?module"] },
|
|
1091
|
+
{ type: "Data", extensions: [".bin"] },
|
|
1092
|
+
{ type: "Text", extensions: [".txt", ".html"] }
|
|
1093
|
+
];
|
|
1094
|
+
function matchAdditionalModule(source) {
|
|
1095
|
+
for (const rule of moduleRules) {
|
|
1096
|
+
for (const extension of rule.extensions) {
|
|
1097
|
+
if (source.endsWith(extension)) {
|
|
1098
|
+
return rule.type;
|
|
1115
1099
|
}
|
|
1116
1100
|
}
|
|
1117
1101
|
}
|
|
1118
|
-
return
|
|
1102
|
+
return null;
|
|
1103
|
+
}
|
|
1104
|
+
function createModuleReference(type, id) {
|
|
1105
|
+
return `__CLOUDFLARE_MODULE__${type}__${id}__`;
|
|
1119
1106
|
}
|
|
1120
1107
|
|
|
1121
1108
|
// src/cloudflare-environment.ts
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1109
|
+
import assert3 from "node:assert";
|
|
1110
|
+
import * as vite2 from "vite";
|
|
1111
|
+
|
|
1112
|
+
// src/node-js-compat.ts
|
|
1113
|
+
import assert2 from "node:assert";
|
|
1114
|
+
import { cloudflare } from "@cloudflare/unenv-preset";
|
|
1115
|
+
import { getNodeCompat } from "miniflare";
|
|
1116
|
+
|
|
1117
|
+
// ../../node_modules/.pnpm/acorn@8.14.0/node_modules/acorn/dist/acorn.mjs
|
|
1118
|
+
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
1119
|
+
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
|
|
1120
|
+
var nonASCIIidentifierChars = "\u200C\u200D\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0897-\u089F\u08CA-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3C\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0CF3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D81-\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECE\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u180F-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1ABF-\u1ACE\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DFF\u200C\u200D\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\u30FB\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA82C\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F\uFF65";
|
|
1121
|
+
var nonASCIIidentifierStartChars = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC";
|
|
1122
|
+
var reservedWords = {
|
|
1123
|
+
3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
|
|
1124
|
+
5: "class enum extends super const export import",
|
|
1125
|
+
6: "enum",
|
|
1126
|
+
strict: "implements interface let package private protected public static yield",
|
|
1127
|
+
strictBind: "eval arguments"
|
|
1128
|
+
};
|
|
1129
|
+
var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
|
|
1130
|
+
var keywords$1 = {
|
|
1131
|
+
5: ecma5AndLessKeywords,
|
|
1132
|
+
"5module": ecma5AndLessKeywords + " export import",
|
|
1133
|
+
6: ecma5AndLessKeywords + " const class extends export import super"
|
|
1134
|
+
};
|
|
1135
|
+
var keywordRelationalOperator = /^in(stanceof)?$/;
|
|
1136
|
+
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
|
1137
|
+
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
|
1138
|
+
function isInAstralSet(code, set) {
|
|
1139
|
+
var pos = 65536;
|
|
1140
|
+
for (var i = 0; i < set.length; i += 2) {
|
|
1141
|
+
pos += set[i];
|
|
1142
|
+
if (pos > code) {
|
|
1143
|
+
return false;
|
|
1130
1144
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
const listeners = listenersMap.get(payload.event) ?? /* @__PURE__ */ new Set();
|
|
1135
|
-
for (const listener of listeners) {
|
|
1136
|
-
listener(payload.data, client);
|
|
1145
|
+
pos += set[i + 1];
|
|
1146
|
+
if (pos >= code) {
|
|
1147
|
+
return true;
|
|
1137
1148
|
}
|
|
1138
1149
|
}
|
|
1139
|
-
return
|
|
1140
|
-
send(payload) {
|
|
1141
|
-
const webSocket = webSocketContainer.webSocket;
|
|
1142
|
-
assert(webSocket, webSocketUndefinedError);
|
|
1143
|
-
webSocket.send(JSON.stringify(payload));
|
|
1144
|
-
},
|
|
1145
|
-
on(event, listener) {
|
|
1146
|
-
const listeners = listenersMap.get(event) ?? /* @__PURE__ */ new Set();
|
|
1147
|
-
listeners.add(listener);
|
|
1148
|
-
listenersMap.set(event, listeners);
|
|
1149
|
-
},
|
|
1150
|
-
off(event, listener) {
|
|
1151
|
-
listenersMap.get(event)?.delete(listener);
|
|
1152
|
-
},
|
|
1153
|
-
listen() {
|
|
1154
|
-
const webSocket = webSocketContainer.webSocket;
|
|
1155
|
-
assert(webSocket, webSocketUndefinedError);
|
|
1156
|
-
webSocket.addEventListener("message", onMessage);
|
|
1157
|
-
},
|
|
1158
|
-
close() {
|
|
1159
|
-
const webSocket = webSocketContainer.webSocket;
|
|
1160
|
-
assert(webSocket, webSocketUndefinedError);
|
|
1161
|
-
webSocket.removeEventListener("message", onMessage);
|
|
1162
|
-
}
|
|
1163
|
-
};
|
|
1150
|
+
return false;
|
|
1164
1151
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
constructor(name2, config) {
|
|
1169
|
-
const webSocketContainer = {};
|
|
1170
|
-
super(name2, config, {
|
|
1171
|
-
hot: true,
|
|
1172
|
-
transport: createHotChannel(webSocketContainer)
|
|
1173
|
-
});
|
|
1174
|
-
this.#webSocketContainer = webSocketContainer;
|
|
1152
|
+
function isIdentifierStart(code, astral) {
|
|
1153
|
+
if (code < 65) {
|
|
1154
|
+
return code === 36;
|
|
1175
1155
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
const response = await this.#worker.fetch(
|
|
1179
|
-
new URL(INIT_PATH, UNKNOWN_HOST),
|
|
1180
|
-
{
|
|
1181
|
-
headers: {
|
|
1182
|
-
upgrade: "websocket"
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
);
|
|
1186
|
-
assert(
|
|
1187
|
-
response.ok,
|
|
1188
|
-
`Failed to initialize module runner, error: ${await response.text()}`
|
|
1189
|
-
);
|
|
1190
|
-
const webSocket = response.webSocket;
|
|
1191
|
-
assert(webSocket, "Failed to establish WebSocket");
|
|
1192
|
-
webSocket.accept();
|
|
1193
|
-
this.#webSocketContainer.webSocket = webSocket;
|
|
1156
|
+
if (code < 91) {
|
|
1157
|
+
return true;
|
|
1194
1158
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
"cloudflare:email",
|
|
1198
|
-
"cloudflare:sockets",
|
|
1199
|
-
"cloudflare:workers",
|
|
1200
|
-
"cloudflare:workflows"
|
|
1201
|
-
];
|
|
1202
|
-
var defaultConditions = ["workerd", "module", "browser"];
|
|
1203
|
-
function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmentName) {
|
|
1204
|
-
return {
|
|
1205
|
-
resolve: {
|
|
1206
|
-
// Note: in order for ssr pre-bundling to take effect we need to ask vite to treat all
|
|
1207
|
-
// dependencies as not external
|
|
1208
|
-
noExternal: true,
|
|
1209
|
-
// We want to use `workerd` package exports if available (e.g. for postgres).
|
|
1210
|
-
conditions: [...defaultConditions, "development|production"],
|
|
1211
|
-
// The Cloudflare ones are proper builtins in the environment
|
|
1212
|
-
builtins: [...cloudflareBuiltInModules]
|
|
1213
|
-
},
|
|
1214
|
-
dev: {
|
|
1215
|
-
createEnvironment(name2, config) {
|
|
1216
|
-
return new CloudflareDevEnvironment(name2, config);
|
|
1217
|
-
}
|
|
1218
|
-
},
|
|
1219
|
-
build: {
|
|
1220
|
-
createEnvironment(name2, config) {
|
|
1221
|
-
return new vite2.BuildEnvironment(name2, config);
|
|
1222
|
-
},
|
|
1223
|
-
target: "es2022",
|
|
1224
|
-
// We need to enable `emitAssets` in order to support additional modules defined by `rules`
|
|
1225
|
-
emitAssets: true,
|
|
1226
|
-
outDir: getOutputDirectory(userConfig, environmentName),
|
|
1227
|
-
copyPublicDir: false,
|
|
1228
|
-
ssr: true,
|
|
1229
|
-
rollupOptions: {
|
|
1230
|
-
// Note: vite starts dev pre-bundling crawling from either optimizeDeps.entries or rollupOptions.input
|
|
1231
|
-
// so the input value here serves both as the build input as well as the starting point for
|
|
1232
|
-
// dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
|
|
1233
|
-
// optimizeDeps.entries in the dev config)
|
|
1234
|
-
input: workerConfig.main
|
|
1235
|
-
}
|
|
1236
|
-
},
|
|
1237
|
-
optimizeDeps: {
|
|
1238
|
-
// Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
|
|
1239
|
-
noDiscovery: false,
|
|
1240
|
-
entries: workerConfig.main,
|
|
1241
|
-
exclude: [...cloudflareBuiltInModules],
|
|
1242
|
-
esbuildOptions: {
|
|
1243
|
-
platform: "neutral",
|
|
1244
|
-
conditions: [...defaultConditions, "development"],
|
|
1245
|
-
resolveExtensions: [
|
|
1246
|
-
".mjs",
|
|
1247
|
-
".js",
|
|
1248
|
-
".mts",
|
|
1249
|
-
".ts",
|
|
1250
|
-
".jsx",
|
|
1251
|
-
".tsx",
|
|
1252
|
-
".json",
|
|
1253
|
-
".cjs",
|
|
1254
|
-
".cts",
|
|
1255
|
-
".ctx"
|
|
1256
|
-
]
|
|
1257
|
-
}
|
|
1258
|
-
},
|
|
1259
|
-
keepProcessEnv: false
|
|
1260
|
-
};
|
|
1261
|
-
}
|
|
1262
|
-
function initRunners(resolvedPluginConfig, viteDevServer, miniflare) {
|
|
1263
|
-
if (resolvedPluginConfig.type === "assets-only") {
|
|
1264
|
-
return;
|
|
1159
|
+
if (code < 97) {
|
|
1160
|
+
return code === 95;
|
|
1265
1161
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1162
|
+
if (code < 123) {
|
|
1163
|
+
return true;
|
|
1164
|
+
}
|
|
1165
|
+
if (code <= 65535) {
|
|
1166
|
+
return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code));
|
|
1167
|
+
}
|
|
1168
|
+
if (astral === false) {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
return isInAstralSet(code, astralIdentifierStartCodes);
|
|
1274
1172
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1173
|
+
function isIdentifierChar(code, astral) {
|
|
1174
|
+
if (code < 48) {
|
|
1175
|
+
return code === 36;
|
|
1176
|
+
}
|
|
1177
|
+
if (code < 58) {
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
if (code < 65) {
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
if (code < 91) {
|
|
1184
|
+
return true;
|
|
1185
|
+
}
|
|
1186
|
+
if (code < 97) {
|
|
1187
|
+
return code === 95;
|
|
1188
|
+
}
|
|
1189
|
+
if (code < 123) {
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
if (code <= 65535) {
|
|
1193
|
+
return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code));
|
|
1194
|
+
}
|
|
1195
|
+
if (astral === false) {
|
|
1196
|
+
return false;
|
|
1197
|
+
}
|
|
1198
|
+
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
|
|
1283
1199
|
}
|
|
1284
|
-
function
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1200
|
+
var TokenType = function TokenType2(label, conf) {
|
|
1201
|
+
if (conf === void 0) conf = {};
|
|
1202
|
+
this.label = label;
|
|
1203
|
+
this.keyword = conf.keyword;
|
|
1204
|
+
this.beforeExpr = !!conf.beforeExpr;
|
|
1205
|
+
this.startsExpr = !!conf.startsExpr;
|
|
1206
|
+
this.isLoop = !!conf.isLoop;
|
|
1207
|
+
this.isAssign = !!conf.isAssign;
|
|
1208
|
+
this.prefix = !!conf.prefix;
|
|
1209
|
+
this.postfix = !!conf.postfix;
|
|
1210
|
+
this.binop = conf.binop || null;
|
|
1211
|
+
this.updateContext = null;
|
|
1212
|
+
};
|
|
1213
|
+
function binop(name, prec) {
|
|
1214
|
+
return new TokenType(name, { beforeExpr: true, binop: prec });
|
|
1295
1215
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
);
|
|
1216
|
+
var beforeExpr = { beforeExpr: true };
|
|
1217
|
+
var startsExpr = { startsExpr: true };
|
|
1218
|
+
var keywords = {};
|
|
1219
|
+
function kw(name, options) {
|
|
1220
|
+
if (options === void 0) options = {};
|
|
1221
|
+
options.keyword = name;
|
|
1222
|
+
return keywords[name] = new TokenType(name, options);
|
|
1301
1223
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1224
|
+
var types$1 = {
|
|
1225
|
+
num: new TokenType("num", startsExpr),
|
|
1226
|
+
regexp: new TokenType("regexp", startsExpr),
|
|
1227
|
+
string: new TokenType("string", startsExpr),
|
|
1228
|
+
name: new TokenType("name", startsExpr),
|
|
1229
|
+
privateId: new TokenType("privateId", startsExpr),
|
|
1230
|
+
eof: new TokenType("eof"),
|
|
1231
|
+
// Punctuation token types.
|
|
1232
|
+
bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
|
|
1233
|
+
bracketR: new TokenType("]"),
|
|
1234
|
+
braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
|
|
1235
|
+
braceR: new TokenType("}"),
|
|
1236
|
+
parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
|
|
1237
|
+
parenR: new TokenType(")"),
|
|
1238
|
+
comma: new TokenType(",", beforeExpr),
|
|
1239
|
+
semi: new TokenType(";", beforeExpr),
|
|
1240
|
+
colon: new TokenType(":", beforeExpr),
|
|
1241
|
+
dot: new TokenType("."),
|
|
1242
|
+
question: new TokenType("?", beforeExpr),
|
|
1243
|
+
questionDot: new TokenType("?."),
|
|
1244
|
+
arrow: new TokenType("=>", beforeExpr),
|
|
1245
|
+
template: new TokenType("template"),
|
|
1246
|
+
invalidTemplate: new TokenType("invalidTemplate"),
|
|
1247
|
+
ellipsis: new TokenType("...", beforeExpr),
|
|
1248
|
+
backQuote: new TokenType("`", startsExpr),
|
|
1249
|
+
dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
|
|
1250
|
+
// Operators. These carry several kinds of properties to help the
|
|
1251
|
+
// parser use them properly (the presence of these properties is
|
|
1252
|
+
// what categorizes them as operators).
|
|
1253
|
+
//
|
|
1254
|
+
// `binop`, when present, specifies that this operator is a binary
|
|
1255
|
+
// operator, and will refer to its precedence.
|
|
1256
|
+
//
|
|
1257
|
+
// `prefix` and `postfix` mark the operator as a prefix or postfix
|
|
1258
|
+
// unary operator.
|
|
1259
|
+
//
|
|
1260
|
+
// `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
|
|
1261
|
+
// binary operators with a very low precedence, that should result
|
|
1262
|
+
// in AssignmentExpression nodes.
|
|
1263
|
+
eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
|
|
1264
|
+
assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
|
|
1265
|
+
incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
|
|
1266
|
+
prefix: new TokenType("!/~", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|
1267
|
+
logicalOR: binop("||", 1),
|
|
1268
|
+
logicalAND: binop("&&", 2),
|
|
1269
|
+
bitwiseOR: binop("|", 3),
|
|
1270
|
+
bitwiseXOR: binop("^", 4),
|
|
1271
|
+
bitwiseAND: binop("&", 5),
|
|
1272
|
+
equality: binop("==/!=/===/!==", 6),
|
|
1273
|
+
relational: binop("</>/<=/>=", 7),
|
|
1274
|
+
bitShift: binop("<</>>/>>>", 8),
|
|
1275
|
+
plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
|
|
1276
|
+
modulo: binop("%", 10),
|
|
1277
|
+
star: binop("*", 10),
|
|
1278
|
+
slash: binop("/", 10),
|
|
1279
|
+
starstar: new TokenType("**", { beforeExpr: true }),
|
|
1280
|
+
coalesce: binop("??", 1),
|
|
1281
|
+
// Keyword token types.
|
|
1282
|
+
_break: kw("break"),
|
|
1283
|
+
_case: kw("case", beforeExpr),
|
|
1284
|
+
_catch: kw("catch"),
|
|
1285
|
+
_continue: kw("continue"),
|
|
1286
|
+
_debugger: kw("debugger"),
|
|
1287
|
+
_default: kw("default", beforeExpr),
|
|
1288
|
+
_do: kw("do", { isLoop: true, beforeExpr: true }),
|
|
1289
|
+
_else: kw("else", beforeExpr),
|
|
1290
|
+
_finally: kw("finally"),
|
|
1291
|
+
_for: kw("for", { isLoop: true }),
|
|
1292
|
+
_function: kw("function", startsExpr),
|
|
1293
|
+
_if: kw("if"),
|
|
1294
|
+
_return: kw("return", beforeExpr),
|
|
1295
|
+
_switch: kw("switch"),
|
|
1296
|
+
_throw: kw("throw", beforeExpr),
|
|
1297
|
+
_try: kw("try"),
|
|
1298
|
+
_var: kw("var"),
|
|
1299
|
+
_const: kw("const"),
|
|
1300
|
+
_while: kw("while", { isLoop: true }),
|
|
1301
|
+
_with: kw("with"),
|
|
1302
|
+
_new: kw("new", { beforeExpr: true, startsExpr: true }),
|
|
1303
|
+
_this: kw("this", startsExpr),
|
|
1304
|
+
_super: kw("super", startsExpr),
|
|
1305
|
+
_class: kw("class", startsExpr),
|
|
1306
|
+
_extends: kw("extends", beforeExpr),
|
|
1307
|
+
_export: kw("export"),
|
|
1308
|
+
_import: kw("import", startsExpr),
|
|
1309
|
+
_null: kw("null", startsExpr),
|
|
1310
|
+
_true: kw("true", startsExpr),
|
|
1311
|
+
_false: kw("false", startsExpr),
|
|
1312
|
+
_in: kw("in", { beforeExpr: true, binop: 7 }),
|
|
1313
|
+
_instanceof: kw("instanceof", { beforeExpr: true, binop: 7 }),
|
|
1314
|
+
_typeof: kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|
1315
|
+
_void: kw("void", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|
1316
|
+
_delete: kw("delete", { beforeExpr: true, prefix: true, startsExpr: true })
|
|
1317
|
+
};
|
|
1318
|
+
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
|
1319
|
+
var lineBreakG = new RegExp(lineBreak.source, "g");
|
|
1320
|
+
function isNewLine(code) {
|
|
1321
|
+
return code === 10 || code === 13 || code === 8232 || code === 8233;
|
|
1322
|
+
}
|
|
1323
|
+
function nextLineBreak(code, from, end) {
|
|
1324
|
+
if (end === void 0) end = code.length;
|
|
1325
|
+
for (var i = from; i < end; i++) {
|
|
1326
|
+
var next = code.charCodeAt(i);
|
|
1327
|
+
if (isNewLine(next)) {
|
|
1328
|
+
return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1;
|
|
1340
1329
|
}
|
|
1341
|
-
assert2(
|
|
1342
|
-
entryWorkerConfigPath,
|
|
1343
|
-
`Unexpected error: entryWorkerConfigPath is undefined`
|
|
1344
|
-
);
|
|
1345
|
-
const deployConfig = {
|
|
1346
|
-
configPath: entryWorkerConfigPath,
|
|
1347
|
-
auxiliaryWorkers
|
|
1348
|
-
};
|
|
1349
|
-
fs.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
1350
1330
|
}
|
|
1331
|
+
return -1;
|
|
1351
1332
|
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
return
|
|
1333
|
+
var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
|
|
1334
|
+
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
|
|
1335
|
+
var ref = Object.prototype;
|
|
1336
|
+
var hasOwnProperty = ref.hasOwnProperty;
|
|
1337
|
+
var toString2 = ref.toString;
|
|
1338
|
+
var hasOwn = Object.hasOwn || function(obj, propName) {
|
|
1339
|
+
return hasOwnProperty.call(obj, propName);
|
|
1340
|
+
};
|
|
1341
|
+
var isArray = Array.isArray || function(obj) {
|
|
1342
|
+
return toString2.call(obj) === "[object Array]";
|
|
1343
|
+
};
|
|
1344
|
+
var regexpCache = /* @__PURE__ */ Object.create(null);
|
|
1345
|
+
function wordsRegexp(words) {
|
|
1346
|
+
return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"));
|
|
1359
1347
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
import * as fs2 from "node:fs";
|
|
1364
|
-
import * as fsp from "node:fs/promises";
|
|
1365
|
-
import * as path3 from "node:path";
|
|
1366
|
-
import { fileURLToPath } from "node:url";
|
|
1367
|
-
import {
|
|
1368
|
-
kCurrentWorker,
|
|
1369
|
-
Log,
|
|
1370
|
-
LogLevel,
|
|
1371
|
-
Response as MiniflareResponse
|
|
1372
|
-
} from "miniflare";
|
|
1373
|
-
import { globSync } from "tinyglobby";
|
|
1374
|
-
import "vite";
|
|
1375
|
-
import {
|
|
1376
|
-
unstable_getMiniflareWorkerOptions,
|
|
1377
|
-
unstable_readConfig
|
|
1378
|
-
} from "wrangler";
|
|
1379
|
-
function getPersistence(root, persistState) {
|
|
1380
|
-
if (persistState === false) {
|
|
1381
|
-
return {};
|
|
1348
|
+
function codePointToString(code) {
|
|
1349
|
+
if (code <= 65535) {
|
|
1350
|
+
return String.fromCharCode(code);
|
|
1382
1351
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
root,
|
|
1386
|
-
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
1387
|
-
"v3"
|
|
1388
|
-
);
|
|
1389
|
-
return {
|
|
1390
|
-
cachePersist: path3.join(persistPath, "cache"),
|
|
1391
|
-
d1Persist: path3.join(persistPath, "d1"),
|
|
1392
|
-
durableObjectsPersist: path3.join(persistPath, "do"),
|
|
1393
|
-
kvPersist: path3.join(persistPath, "kv"),
|
|
1394
|
-
r2Persist: path3.join(persistPath, "r2"),
|
|
1395
|
-
workflowsPersist: path3.join(persistPath, "workflows")
|
|
1396
|
-
};
|
|
1397
|
-
}
|
|
1398
|
-
function missingWorkerErrorMessage(workerName) {
|
|
1399
|
-
return `${workerName} does not match a worker name.`;
|
|
1352
|
+
code -= 65536;
|
|
1353
|
+
return String.fromCharCode((code >> 10) + 55296, (code & 1023) + 56320);
|
|
1400
1354
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
}
|
|
1415
|
-
return workerToWorkerEntrypointNamesMap;
|
|
1416
|
-
}
|
|
1417
|
-
function getWorkerToDurableObjectClassNamesMap(workers) {
|
|
1418
|
-
const workerToDurableObjectClassNamesMap = new Map(
|
|
1419
|
-
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
1420
|
-
);
|
|
1421
|
-
for (const worker of workers) {
|
|
1422
|
-
for (const value of Object.values(worker.durableObjects ?? {})) {
|
|
1423
|
-
if (typeof value === "string") {
|
|
1424
|
-
const classNames = workerToDurableObjectClassNamesMap.get(worker.name);
|
|
1425
|
-
assert4(classNames, missingWorkerErrorMessage(worker.name));
|
|
1426
|
-
classNames.add(value);
|
|
1427
|
-
} else if (typeof value === "object") {
|
|
1428
|
-
if (value.scriptName) {
|
|
1429
|
-
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
1430
|
-
value.scriptName
|
|
1431
|
-
);
|
|
1432
|
-
assert4(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
1433
|
-
classNames.add(value.className);
|
|
1434
|
-
} else {
|
|
1435
|
-
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
1436
|
-
worker.name
|
|
1437
|
-
);
|
|
1438
|
-
assert4(classNames, missingWorkerErrorMessage(worker.name));
|
|
1439
|
-
classNames.add(value.className);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
return workerToDurableObjectClassNamesMap;
|
|
1445
|
-
}
|
|
1446
|
-
function getWorkerToWorkflowEntrypointClassNamesMap(workers) {
|
|
1447
|
-
const workerToWorkflowEntrypointClassNamesMap = new Map(
|
|
1448
|
-
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
1449
|
-
);
|
|
1450
|
-
for (const worker of workers) {
|
|
1451
|
-
for (const value of Object.values(worker.workflows ?? {})) {
|
|
1452
|
-
if (value.scriptName) {
|
|
1453
|
-
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
1454
|
-
value.scriptName
|
|
1455
|
-
);
|
|
1456
|
-
assert4(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
1457
|
-
classNames.add(value.className);
|
|
1458
|
-
} else {
|
|
1459
|
-
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
1460
|
-
worker.name
|
|
1461
|
-
);
|
|
1462
|
-
assert4(classNames, missingWorkerErrorMessage(worker.name));
|
|
1463
|
-
classNames.add(value.className);
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
return workerToWorkflowEntrypointClassNamesMap;
|
|
1468
|
-
}
|
|
1469
|
-
var miniflareModulesRoot = process.platform === "win32" ? "Z:\\" : "/";
|
|
1470
|
-
var ROUTER_WORKER_PATH = "./asset-workers/router-worker.js";
|
|
1471
|
-
var ASSET_WORKER_PATH = "./asset-workers/asset-worker.js";
|
|
1472
|
-
var WRAPPER_PATH = "__VITE_WORKER_ENTRY__";
|
|
1473
|
-
var RUNNER_PATH = "./runner-worker/index.js";
|
|
1474
|
-
function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
1475
|
-
if (resolvedPluginConfig.type === "assets-only") {
|
|
1476
|
-
return;
|
|
1477
|
-
}
|
|
1478
|
-
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
1479
|
-
}
|
|
1480
|
-
function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
1481
|
-
const resolvedViteConfig = viteDevServer.config;
|
|
1482
|
-
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
1483
|
-
const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
|
|
1484
|
-
const assetWorkers = [
|
|
1485
|
-
{
|
|
1486
|
-
name: ROUTER_WORKER_NAME,
|
|
1487
|
-
compatibilityDate: ASSET_WORKERS_COMPATIBILITY_DATE,
|
|
1488
|
-
modulesRoot: miniflareModulesRoot,
|
|
1489
|
-
modules: [
|
|
1490
|
-
{
|
|
1491
|
-
type: "ESModule",
|
|
1492
|
-
path: path3.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
|
|
1493
|
-
contents: fs2.readFileSync(
|
|
1494
|
-
fileURLToPath(new URL(ROUTER_WORKER_PATH, import.meta.url))
|
|
1495
|
-
)
|
|
1496
|
-
}
|
|
1497
|
-
],
|
|
1498
|
-
bindings: {
|
|
1499
|
-
CONFIG: {
|
|
1500
|
-
has_user_worker: resolvedPluginConfig.type === "workers"
|
|
1501
|
-
}
|
|
1502
|
-
},
|
|
1503
|
-
serviceBindings: {
|
|
1504
|
-
ASSET_WORKER: ASSET_WORKER_NAME,
|
|
1505
|
-
...entryWorkerConfig ? { USER_WORKER: entryWorkerConfig.name } : {}
|
|
1506
|
-
}
|
|
1507
|
-
},
|
|
1508
|
-
{
|
|
1509
|
-
name: ASSET_WORKER_NAME,
|
|
1510
|
-
compatibilityDate: ASSET_WORKERS_COMPATIBILITY_DATE,
|
|
1511
|
-
modulesRoot: miniflareModulesRoot,
|
|
1512
|
-
modules: [
|
|
1513
|
-
{
|
|
1514
|
-
type: "ESModule",
|
|
1515
|
-
path: path3.join(miniflareModulesRoot, ASSET_WORKER_PATH),
|
|
1516
|
-
contents: fs2.readFileSync(
|
|
1517
|
-
fileURLToPath(new URL(ASSET_WORKER_PATH, import.meta.url))
|
|
1518
|
-
)
|
|
1519
|
-
}
|
|
1520
|
-
],
|
|
1521
|
-
bindings: {
|
|
1522
|
-
CONFIG: {
|
|
1523
|
-
...assetsConfig?.html_handling ? { html_handling: assetsConfig.html_handling } : {},
|
|
1524
|
-
...assetsConfig?.not_found_handling ? { not_found_handling: assetsConfig.not_found_handling } : {}
|
|
1525
|
-
}
|
|
1526
|
-
},
|
|
1527
|
-
serviceBindings: {
|
|
1528
|
-
__VITE_ASSET_EXISTS__: async (request) => {
|
|
1529
|
-
const { pathname } = new URL(request.url);
|
|
1530
|
-
const filePath = path3.join(resolvedViteConfig.root, pathname);
|
|
1531
|
-
let exists;
|
|
1532
|
-
try {
|
|
1533
|
-
exists = fs2.statSync(filePath).isFile();
|
|
1534
|
-
} catch (error) {
|
|
1535
|
-
exists = false;
|
|
1536
|
-
}
|
|
1537
|
-
return MiniflareResponse.json(exists);
|
|
1538
|
-
},
|
|
1539
|
-
__VITE_FETCH_ASSET__: async (request) => {
|
|
1540
|
-
const { pathname } = new URL(request.url);
|
|
1541
|
-
const filePath = path3.join(resolvedViteConfig.root, pathname);
|
|
1542
|
-
try {
|
|
1543
|
-
let html = await fsp.readFile(filePath, "utf-8");
|
|
1544
|
-
html = await viteDevServer.transformIndexHtml(pathname, html);
|
|
1545
|
-
return new MiniflareResponse(html, {
|
|
1546
|
-
headers: { "Content-Type": "text/html" }
|
|
1547
|
-
});
|
|
1548
|
-
} catch (error) {
|
|
1549
|
-
throw new Error(`Unexpected error. Failed to load ${pathname}`);
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
];
|
|
1555
|
-
const workersFromConfig = resolvedPluginConfig.type === "workers" ? Object.entries(resolvedPluginConfig.workers).map(
|
|
1556
|
-
([environmentName, workerConfig]) => {
|
|
1557
|
-
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
1558
|
-
{
|
|
1559
|
-
...workerConfig,
|
|
1560
|
-
assets: void 0
|
|
1561
|
-
},
|
|
1562
|
-
resolvedPluginConfig.cloudflareEnv
|
|
1563
|
-
);
|
|
1564
|
-
const { externalWorkers: externalWorkers2 } = miniflareWorkerOptions;
|
|
1565
|
-
const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
1566
|
-
return {
|
|
1567
|
-
externalWorkers: externalWorkers2,
|
|
1568
|
-
worker: {
|
|
1569
|
-
...workerOptions,
|
|
1570
|
-
name: workerOptions.name ?? workerConfig.name,
|
|
1571
|
-
modulesRoot: miniflareModulesRoot,
|
|
1572
|
-
unsafeEvalBinding: "__VITE_UNSAFE_EVAL__",
|
|
1573
|
-
bindings: {
|
|
1574
|
-
...workerOptions.bindings,
|
|
1575
|
-
__VITE_ROOT__: resolvedViteConfig.root,
|
|
1576
|
-
__VITE_ENTRY_PATH__: workerConfig.main
|
|
1577
|
-
},
|
|
1578
|
-
serviceBindings: {
|
|
1579
|
-
...workerOptions.serviceBindings,
|
|
1580
|
-
...environmentName === resolvedPluginConfig.entryWorkerEnvironmentName && workerConfig.assets?.binding ? {
|
|
1581
|
-
[workerConfig.assets.binding]: ASSET_WORKER_NAME
|
|
1582
|
-
} : {},
|
|
1583
|
-
__VITE_INVOKE_MODULE__: async (request) => {
|
|
1584
|
-
const payload = await request.json();
|
|
1585
|
-
const invokePayloadData = payload.data;
|
|
1586
|
-
assert4(
|
|
1587
|
-
invokePayloadData.name === "fetchModule",
|
|
1588
|
-
`Invalid invoke event: ${invokePayloadData.name}`
|
|
1589
|
-
);
|
|
1590
|
-
const [moduleId] = invokePayloadData.data;
|
|
1591
|
-
const moduleRE = new RegExp(MODULE_PATTERN);
|
|
1592
|
-
const shouldExternalize = (
|
|
1593
|
-
// Worker modules (CompiledWasm, Text, Data)
|
|
1594
|
-
moduleRE.test(moduleId)
|
|
1595
|
-
);
|
|
1596
|
-
if (shouldExternalize) {
|
|
1597
|
-
const result2 = {
|
|
1598
|
-
externalize: moduleId,
|
|
1599
|
-
type: "module"
|
|
1600
|
-
};
|
|
1601
|
-
return MiniflareResponse.json({ result: result2 });
|
|
1602
|
-
}
|
|
1603
|
-
const devEnvironment = viteDevServer.environments[environmentName];
|
|
1604
|
-
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
1605
|
-
return MiniflareResponse.json(result);
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
};
|
|
1610
|
-
}
|
|
1611
|
-
) : [];
|
|
1612
|
-
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
1613
|
-
const externalWorkers = workersFromConfig.flatMap(
|
|
1614
|
-
(options) => options.externalWorkers
|
|
1615
|
-
);
|
|
1616
|
-
const workerToWorkerEntrypointNamesMap = getWorkerToWorkerEntrypointNamesMap(userWorkers);
|
|
1617
|
-
const workerToDurableObjectClassNamesMap = getWorkerToDurableObjectClassNamesMap(userWorkers);
|
|
1618
|
-
const workerToWorkflowEntrypointClassNamesMap = getWorkerToWorkflowEntrypointClassNamesMap(userWorkers);
|
|
1619
|
-
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
1620
|
-
return {
|
|
1621
|
-
log: logger,
|
|
1622
|
-
handleRuntimeStdio(stdout, stderr) {
|
|
1623
|
-
const decoder = new TextDecoder();
|
|
1624
|
-
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
1625
|
-
stderr.forEach(
|
|
1626
|
-
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
1627
|
-
);
|
|
1628
|
-
},
|
|
1629
|
-
...getPersistence(
|
|
1630
|
-
resolvedViteConfig.root,
|
|
1631
|
-
resolvedPluginConfig.persistState
|
|
1632
|
-
),
|
|
1633
|
-
workers: [
|
|
1634
|
-
...assetWorkers,
|
|
1635
|
-
...externalWorkers,
|
|
1636
|
-
...userWorkers.map((workerOptions) => {
|
|
1637
|
-
const wrappers = [
|
|
1638
|
-
`import { createWorkerEntrypointWrapper, createDurableObjectWrapper, createWorkflowEntrypointWrapper } from '${RUNNER_PATH}';`,
|
|
1639
|
-
`export default createWorkerEntrypointWrapper('default');`
|
|
1640
|
-
];
|
|
1641
|
-
const workerEntrypointNames = workerToWorkerEntrypointNamesMap.get(
|
|
1642
|
-
workerOptions.name
|
|
1643
|
-
);
|
|
1644
|
-
assert4(
|
|
1645
|
-
workerEntrypointNames,
|
|
1646
|
-
`WorkerEntrypoint names not found for worker ${workerOptions.name}`
|
|
1647
|
-
);
|
|
1648
|
-
for (const entrypointName of [...workerEntrypointNames].sort()) {
|
|
1649
|
-
wrappers.push(
|
|
1650
|
-
`export const ${entrypointName} = createWorkerEntrypointWrapper('${entrypointName}');`
|
|
1651
|
-
);
|
|
1652
|
-
}
|
|
1653
|
-
const durableObjectClassNames = workerToDurableObjectClassNamesMap.get(
|
|
1654
|
-
workerOptions.name
|
|
1655
|
-
);
|
|
1656
|
-
assert4(
|
|
1657
|
-
durableObjectClassNames,
|
|
1658
|
-
`DurableObject class names not found for worker ${workerOptions.name}`
|
|
1659
|
-
);
|
|
1660
|
-
for (const className of [...durableObjectClassNames].sort()) {
|
|
1661
|
-
wrappers.push(
|
|
1662
|
-
`export const ${className} = createDurableObjectWrapper('${className}');`
|
|
1663
|
-
);
|
|
1664
|
-
}
|
|
1665
|
-
const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
|
|
1666
|
-
assert4(
|
|
1667
|
-
workflowEntrypointClassNames,
|
|
1668
|
-
`WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
|
|
1669
|
-
);
|
|
1670
|
-
for (const className of [...workflowEntrypointClassNames].sort()) {
|
|
1671
|
-
wrappers.push(
|
|
1672
|
-
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
1673
|
-
);
|
|
1674
|
-
}
|
|
1675
|
-
return {
|
|
1676
|
-
...workerOptions,
|
|
1677
|
-
modules: [
|
|
1678
|
-
{
|
|
1679
|
-
type: "ESModule",
|
|
1680
|
-
path: path3.join(miniflareModulesRoot, WRAPPER_PATH),
|
|
1681
|
-
contents: wrappers.join("\n")
|
|
1682
|
-
},
|
|
1683
|
-
{
|
|
1684
|
-
type: "ESModule",
|
|
1685
|
-
path: path3.join(miniflareModulesRoot, RUNNER_PATH),
|
|
1686
|
-
contents: fs2.readFileSync(
|
|
1687
|
-
fileURLToPath(new URL(RUNNER_PATH, import.meta.url))
|
|
1688
|
-
)
|
|
1689
|
-
}
|
|
1690
|
-
],
|
|
1691
|
-
unsafeUseModuleFallbackService: true
|
|
1692
|
-
};
|
|
1693
|
-
})
|
|
1694
|
-
],
|
|
1695
|
-
unsafeModuleFallbackService(request) {
|
|
1696
|
-
const url = new URL(request.url);
|
|
1697
|
-
const rawSpecifier = url.searchParams.get("rawSpecifier");
|
|
1698
|
-
assert4(
|
|
1699
|
-
rawSpecifier,
|
|
1700
|
-
`Unexpected error: no specifier in request to module fallback service.`
|
|
1701
|
-
);
|
|
1702
|
-
const moduleRE = new RegExp(MODULE_PATTERN);
|
|
1703
|
-
const match = moduleRE.exec(rawSpecifier);
|
|
1704
|
-
assert4(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
|
|
1705
|
-
const [full, moduleType, modulePath] = match;
|
|
1706
|
-
assert4(
|
|
1707
|
-
modulePath,
|
|
1708
|
-
`Unexpected error: module path not found in reference: ${full}.`
|
|
1709
|
-
);
|
|
1710
|
-
let source;
|
|
1711
|
-
try {
|
|
1712
|
-
source = fs2.readFileSync(modulePath);
|
|
1713
|
-
} catch (error) {
|
|
1714
|
-
throw new Error(
|
|
1715
|
-
`Import "${modulePath}" not found. Does the file exist?`
|
|
1716
|
-
);
|
|
1717
|
-
}
|
|
1718
|
-
return MiniflareResponse.json({
|
|
1719
|
-
// Cap'n Proto expects byte arrays for `:Data` typed fields from JSON
|
|
1720
|
-
wasm: Array.from(source)
|
|
1721
|
-
});
|
|
1722
|
-
}
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1725
|
-
function getPreviewModules(main, modulesRules) {
|
|
1726
|
-
assert4(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
1727
|
-
const rootPath = path3.dirname(main);
|
|
1728
|
-
const entryPath = path3.basename(main);
|
|
1729
|
-
return {
|
|
1730
|
-
rootPath,
|
|
1731
|
-
modules: [
|
|
1732
|
-
{
|
|
1733
|
-
type: "ESModule",
|
|
1734
|
-
path: entryPath
|
|
1735
|
-
},
|
|
1736
|
-
...modulesRules.flatMap(
|
|
1737
|
-
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path8) => ({
|
|
1738
|
-
type,
|
|
1739
|
-
path: path8
|
|
1740
|
-
}))
|
|
1741
|
-
)
|
|
1742
|
-
]
|
|
1743
|
-
};
|
|
1744
|
-
}
|
|
1745
|
-
function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
|
|
1746
|
-
const resolvedViteConfig = vitePreviewServer.config;
|
|
1747
|
-
const configPaths = getWorkerConfigPaths(resolvedViteConfig.root);
|
|
1748
|
-
const workerConfigs = configPaths.map(
|
|
1749
|
-
(configPath) => unstable_readConfig({ config: configPath })
|
|
1750
|
-
);
|
|
1751
|
-
const workers = workerConfigs.flatMap((config) => {
|
|
1752
|
-
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(config);
|
|
1753
|
-
const { externalWorkers } = miniflareWorkerOptions;
|
|
1754
|
-
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
1755
|
-
return [
|
|
1756
|
-
{
|
|
1757
|
-
...workerOptions,
|
|
1758
|
-
name: workerOptions.name ?? config.name,
|
|
1759
|
-
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
1760
|
-
},
|
|
1761
|
-
...externalWorkers
|
|
1762
|
-
];
|
|
1763
|
-
});
|
|
1764
|
-
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
1765
|
-
return {
|
|
1766
|
-
log: logger,
|
|
1767
|
-
handleRuntimeStdio(stdout, stderr) {
|
|
1768
|
-
const decoder = new TextDecoder();
|
|
1769
|
-
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
1770
|
-
stderr.forEach(
|
|
1771
|
-
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
1772
|
-
);
|
|
1773
|
-
},
|
|
1774
|
-
...getPersistence(resolvedViteConfig.root, persistState),
|
|
1775
|
-
workers
|
|
1776
|
-
};
|
|
1777
|
-
}
|
|
1778
|
-
var ViteMiniflareLogger = class extends Log {
|
|
1779
|
-
logger;
|
|
1780
|
-
constructor(config) {
|
|
1781
|
-
super(miniflareLogLevelFromViteLogLevel(config.logLevel));
|
|
1782
|
-
this.logger = config.logger;
|
|
1783
|
-
}
|
|
1784
|
-
logWithLevel(level, message) {
|
|
1785
|
-
if (/^Ready on http/.test(message)) {
|
|
1786
|
-
level = LogLevel.DEBUG;
|
|
1787
|
-
}
|
|
1788
|
-
switch (level) {
|
|
1789
|
-
case LogLevel.ERROR:
|
|
1790
|
-
return this.logger.error(message);
|
|
1791
|
-
case LogLevel.WARN:
|
|
1792
|
-
return this.logger.warn(message);
|
|
1793
|
-
case LogLevel.INFO:
|
|
1794
|
-
return this.logger.info(message);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
};
|
|
1798
|
-
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
1799
|
-
switch (level) {
|
|
1800
|
-
case "error":
|
|
1801
|
-
return LogLevel.ERROR;
|
|
1802
|
-
case "warn":
|
|
1803
|
-
return LogLevel.WARN;
|
|
1804
|
-
case "info":
|
|
1805
|
-
return LogLevel.INFO;
|
|
1806
|
-
case "silent":
|
|
1807
|
-
return LogLevel.NONE;
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
// src/node-js-compat.ts
|
|
1812
|
-
import assert6 from "node:assert";
|
|
1813
|
-
import { cloudflare } from "@cloudflare/unenv-preset";
|
|
1814
|
-
import { getNodeCompat } from "miniflare";
|
|
1815
|
-
|
|
1816
|
-
// ../../node_modules/.pnpm/acorn@8.14.0/node_modules/acorn/dist/acorn.mjs
|
|
1817
|
-
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
1818
|
-
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
|
|
1819
|
-
var nonASCIIidentifierChars = "\u200C\u200D\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0897-\u089F\u08CA-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3C\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0CF3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D81-\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECE\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u180F-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1ABF-\u1ACE\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DFF\u200C\u200D\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\u30FB\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA82C\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F\uFF65";
|
|
1820
|
-
var nonASCIIidentifierStartChars = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC";
|
|
1821
|
-
var reservedWords = {
|
|
1822
|
-
3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
|
|
1823
|
-
5: "class enum extends super const export import",
|
|
1824
|
-
6: "enum",
|
|
1825
|
-
strict: "implements interface let package private protected public static yield",
|
|
1826
|
-
strictBind: "eval arguments"
|
|
1827
|
-
};
|
|
1828
|
-
var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
|
|
1829
|
-
var keywords$1 = {
|
|
1830
|
-
5: ecma5AndLessKeywords,
|
|
1831
|
-
"5module": ecma5AndLessKeywords + " export import",
|
|
1832
|
-
6: ecma5AndLessKeywords + " const class extends export import super"
|
|
1833
|
-
};
|
|
1834
|
-
var keywordRelationalOperator = /^in(stanceof)?$/;
|
|
1835
|
-
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
|
1836
|
-
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
|
1837
|
-
function isInAstralSet(code, set) {
|
|
1838
|
-
var pos = 65536;
|
|
1839
|
-
for (var i = 0; i < set.length; i += 2) {
|
|
1840
|
-
pos += set[i];
|
|
1841
|
-
if (pos > code) {
|
|
1842
|
-
return false;
|
|
1843
|
-
}
|
|
1844
|
-
pos += set[i + 1];
|
|
1845
|
-
if (pos >= code) {
|
|
1846
|
-
return true;
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
return false;
|
|
1850
|
-
}
|
|
1851
|
-
function isIdentifierStart(code, astral) {
|
|
1852
|
-
if (code < 65) {
|
|
1853
|
-
return code === 36;
|
|
1854
|
-
}
|
|
1855
|
-
if (code < 91) {
|
|
1856
|
-
return true;
|
|
1857
|
-
}
|
|
1858
|
-
if (code < 97) {
|
|
1859
|
-
return code === 95;
|
|
1860
|
-
}
|
|
1861
|
-
if (code < 123) {
|
|
1862
|
-
return true;
|
|
1863
|
-
}
|
|
1864
|
-
if (code <= 65535) {
|
|
1865
|
-
return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code));
|
|
1866
|
-
}
|
|
1867
|
-
if (astral === false) {
|
|
1868
|
-
return false;
|
|
1869
|
-
}
|
|
1870
|
-
return isInAstralSet(code, astralIdentifierStartCodes);
|
|
1871
|
-
}
|
|
1872
|
-
function isIdentifierChar(code, astral) {
|
|
1873
|
-
if (code < 48) {
|
|
1874
|
-
return code === 36;
|
|
1875
|
-
}
|
|
1876
|
-
if (code < 58) {
|
|
1877
|
-
return true;
|
|
1878
|
-
}
|
|
1879
|
-
if (code < 65) {
|
|
1880
|
-
return false;
|
|
1881
|
-
}
|
|
1882
|
-
if (code < 91) {
|
|
1883
|
-
return true;
|
|
1884
|
-
}
|
|
1885
|
-
if (code < 97) {
|
|
1886
|
-
return code === 95;
|
|
1887
|
-
}
|
|
1888
|
-
if (code < 123) {
|
|
1889
|
-
return true;
|
|
1890
|
-
}
|
|
1891
|
-
if (code <= 65535) {
|
|
1892
|
-
return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code));
|
|
1893
|
-
}
|
|
1894
|
-
if (astral === false) {
|
|
1895
|
-
return false;
|
|
1896
|
-
}
|
|
1897
|
-
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
|
|
1898
|
-
}
|
|
1899
|
-
var TokenType = function TokenType2(label, conf) {
|
|
1900
|
-
if (conf === void 0) conf = {};
|
|
1901
|
-
this.label = label;
|
|
1902
|
-
this.keyword = conf.keyword;
|
|
1903
|
-
this.beforeExpr = !!conf.beforeExpr;
|
|
1904
|
-
this.startsExpr = !!conf.startsExpr;
|
|
1905
|
-
this.isLoop = !!conf.isLoop;
|
|
1906
|
-
this.isAssign = !!conf.isAssign;
|
|
1907
|
-
this.prefix = !!conf.prefix;
|
|
1908
|
-
this.postfix = !!conf.postfix;
|
|
1909
|
-
this.binop = conf.binop || null;
|
|
1910
|
-
this.updateContext = null;
|
|
1911
|
-
};
|
|
1912
|
-
function binop(name2, prec) {
|
|
1913
|
-
return new TokenType(name2, { beforeExpr: true, binop: prec });
|
|
1914
|
-
}
|
|
1915
|
-
var beforeExpr = { beforeExpr: true };
|
|
1916
|
-
var startsExpr = { startsExpr: true };
|
|
1917
|
-
var keywords = {};
|
|
1918
|
-
function kw(name2, options) {
|
|
1919
|
-
if (options === void 0) options = {};
|
|
1920
|
-
options.keyword = name2;
|
|
1921
|
-
return keywords[name2] = new TokenType(name2, options);
|
|
1922
|
-
}
|
|
1923
|
-
var types$1 = {
|
|
1924
|
-
num: new TokenType("num", startsExpr),
|
|
1925
|
-
regexp: new TokenType("regexp", startsExpr),
|
|
1926
|
-
string: new TokenType("string", startsExpr),
|
|
1927
|
-
name: new TokenType("name", startsExpr),
|
|
1928
|
-
privateId: new TokenType("privateId", startsExpr),
|
|
1929
|
-
eof: new TokenType("eof"),
|
|
1930
|
-
// Punctuation token types.
|
|
1931
|
-
bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
|
|
1932
|
-
bracketR: new TokenType("]"),
|
|
1933
|
-
braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
|
|
1934
|
-
braceR: new TokenType("}"),
|
|
1935
|
-
parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
|
|
1936
|
-
parenR: new TokenType(")"),
|
|
1937
|
-
comma: new TokenType(",", beforeExpr),
|
|
1938
|
-
semi: new TokenType(";", beforeExpr),
|
|
1939
|
-
colon: new TokenType(":", beforeExpr),
|
|
1940
|
-
dot: new TokenType("."),
|
|
1941
|
-
question: new TokenType("?", beforeExpr),
|
|
1942
|
-
questionDot: new TokenType("?."),
|
|
1943
|
-
arrow: new TokenType("=>", beforeExpr),
|
|
1944
|
-
template: new TokenType("template"),
|
|
1945
|
-
invalidTemplate: new TokenType("invalidTemplate"),
|
|
1946
|
-
ellipsis: new TokenType("...", beforeExpr),
|
|
1947
|
-
backQuote: new TokenType("`", startsExpr),
|
|
1948
|
-
dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
|
|
1949
|
-
// Operators. These carry several kinds of properties to help the
|
|
1950
|
-
// parser use them properly (the presence of these properties is
|
|
1951
|
-
// what categorizes them as operators).
|
|
1952
|
-
//
|
|
1953
|
-
// `binop`, when present, specifies that this operator is a binary
|
|
1954
|
-
// operator, and will refer to its precedence.
|
|
1955
|
-
//
|
|
1956
|
-
// `prefix` and `postfix` mark the operator as a prefix or postfix
|
|
1957
|
-
// unary operator.
|
|
1958
|
-
//
|
|
1959
|
-
// `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
|
|
1960
|
-
// binary operators with a very low precedence, that should result
|
|
1961
|
-
// in AssignmentExpression nodes.
|
|
1962
|
-
eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
|
|
1963
|
-
assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
|
|
1964
|
-
incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
|
|
1965
|
-
prefix: new TokenType("!/~", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|
1966
|
-
logicalOR: binop("||", 1),
|
|
1967
|
-
logicalAND: binop("&&", 2),
|
|
1968
|
-
bitwiseOR: binop("|", 3),
|
|
1969
|
-
bitwiseXOR: binop("^", 4),
|
|
1970
|
-
bitwiseAND: binop("&", 5),
|
|
1971
|
-
equality: binop("==/!=/===/!==", 6),
|
|
1972
|
-
relational: binop("</>/<=/>=", 7),
|
|
1973
|
-
bitShift: binop("<</>>/>>>", 8),
|
|
1974
|
-
plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
|
|
1975
|
-
modulo: binop("%", 10),
|
|
1976
|
-
star: binop("*", 10),
|
|
1977
|
-
slash: binop("/", 10),
|
|
1978
|
-
starstar: new TokenType("**", { beforeExpr: true }),
|
|
1979
|
-
coalesce: binop("??", 1),
|
|
1980
|
-
// Keyword token types.
|
|
1981
|
-
_break: kw("break"),
|
|
1982
|
-
_case: kw("case", beforeExpr),
|
|
1983
|
-
_catch: kw("catch"),
|
|
1984
|
-
_continue: kw("continue"),
|
|
1985
|
-
_debugger: kw("debugger"),
|
|
1986
|
-
_default: kw("default", beforeExpr),
|
|
1987
|
-
_do: kw("do", { isLoop: true, beforeExpr: true }),
|
|
1988
|
-
_else: kw("else", beforeExpr),
|
|
1989
|
-
_finally: kw("finally"),
|
|
1990
|
-
_for: kw("for", { isLoop: true }),
|
|
1991
|
-
_function: kw("function", startsExpr),
|
|
1992
|
-
_if: kw("if"),
|
|
1993
|
-
_return: kw("return", beforeExpr),
|
|
1994
|
-
_switch: kw("switch"),
|
|
1995
|
-
_throw: kw("throw", beforeExpr),
|
|
1996
|
-
_try: kw("try"),
|
|
1997
|
-
_var: kw("var"),
|
|
1998
|
-
_const: kw("const"),
|
|
1999
|
-
_while: kw("while", { isLoop: true }),
|
|
2000
|
-
_with: kw("with"),
|
|
2001
|
-
_new: kw("new", { beforeExpr: true, startsExpr: true }),
|
|
2002
|
-
_this: kw("this", startsExpr),
|
|
2003
|
-
_super: kw("super", startsExpr),
|
|
2004
|
-
_class: kw("class", startsExpr),
|
|
2005
|
-
_extends: kw("extends", beforeExpr),
|
|
2006
|
-
_export: kw("export"),
|
|
2007
|
-
_import: kw("import", startsExpr),
|
|
2008
|
-
_null: kw("null", startsExpr),
|
|
2009
|
-
_true: kw("true", startsExpr),
|
|
2010
|
-
_false: kw("false", startsExpr),
|
|
2011
|
-
_in: kw("in", { beforeExpr: true, binop: 7 }),
|
|
2012
|
-
_instanceof: kw("instanceof", { beforeExpr: true, binop: 7 }),
|
|
2013
|
-
_typeof: kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|
2014
|
-
_void: kw("void", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|
2015
|
-
_delete: kw("delete", { beforeExpr: true, prefix: true, startsExpr: true })
|
|
2016
|
-
};
|
|
2017
|
-
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
|
2018
|
-
var lineBreakG = new RegExp(lineBreak.source, "g");
|
|
2019
|
-
function isNewLine(code) {
|
|
2020
|
-
return code === 10 || code === 13 || code === 8232 || code === 8233;
|
|
2021
|
-
}
|
|
2022
|
-
function nextLineBreak(code, from, end) {
|
|
2023
|
-
if (end === void 0) end = code.length;
|
|
2024
|
-
for (var i = from; i < end; i++) {
|
|
2025
|
-
var next = code.charCodeAt(i);
|
|
2026
|
-
if (isNewLine(next)) {
|
|
2027
|
-
return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1;
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
return -1;
|
|
2031
|
-
}
|
|
2032
|
-
var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
|
|
2033
|
-
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
|
|
2034
|
-
var ref = Object.prototype;
|
|
2035
|
-
var hasOwnProperty = ref.hasOwnProperty;
|
|
2036
|
-
var toString2 = ref.toString;
|
|
2037
|
-
var hasOwn = Object.hasOwn || function(obj, propName) {
|
|
2038
|
-
return hasOwnProperty.call(obj, propName);
|
|
2039
|
-
};
|
|
2040
|
-
var isArray = Array.isArray || function(obj) {
|
|
2041
|
-
return toString2.call(obj) === "[object Array]";
|
|
2042
|
-
};
|
|
2043
|
-
var regexpCache = /* @__PURE__ */ Object.create(null);
|
|
2044
|
-
function wordsRegexp(words) {
|
|
2045
|
-
return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"));
|
|
2046
|
-
}
|
|
2047
|
-
function codePointToString(code) {
|
|
2048
|
-
if (code <= 65535) {
|
|
2049
|
-
return String.fromCharCode(code);
|
|
2050
|
-
}
|
|
2051
|
-
code -= 65536;
|
|
2052
|
-
return String.fromCharCode((code >> 10) + 55296, (code & 1023) + 56320);
|
|
2053
|
-
}
|
|
2054
|
-
var loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/;
|
|
2055
|
-
var Position = function Position2(line, col) {
|
|
2056
|
-
this.line = line;
|
|
2057
|
-
this.column = col;
|
|
2058
|
-
};
|
|
2059
|
-
Position.prototype.offset = function offset(n2) {
|
|
2060
|
-
return new Position(this.line, this.column + n2);
|
|
2061
|
-
};
|
|
2062
|
-
var SourceLocation = function SourceLocation2(p, start, end) {
|
|
2063
|
-
this.start = start;
|
|
2064
|
-
this.end = end;
|
|
2065
|
-
if (p.sourceFile !== null) {
|
|
2066
|
-
this.source = p.sourceFile;
|
|
1355
|
+
var loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/;
|
|
1356
|
+
var Position = function Position2(line, col) {
|
|
1357
|
+
this.line = line;
|
|
1358
|
+
this.column = col;
|
|
1359
|
+
};
|
|
1360
|
+
Position.prototype.offset = function offset(n2) {
|
|
1361
|
+
return new Position(this.line, this.column + n2);
|
|
1362
|
+
};
|
|
1363
|
+
var SourceLocation = function SourceLocation2(p, start, end) {
|
|
1364
|
+
this.start = start;
|
|
1365
|
+
this.end = end;
|
|
1366
|
+
if (p.sourceFile !== null) {
|
|
1367
|
+
this.source = p.sourceFile;
|
|
2067
1368
|
}
|
|
2068
1369
|
};
|
|
2069
1370
|
function getLineInfo(input, offset2) {
|
|
@@ -2395,18 +1696,18 @@ pp$9.eat = function(type) {
|
|
|
2395
1696
|
return false;
|
|
2396
1697
|
}
|
|
2397
1698
|
};
|
|
2398
|
-
pp$9.isContextual = function(
|
|
2399
|
-
return this.type === types$1.name && this.value ===
|
|
1699
|
+
pp$9.isContextual = function(name) {
|
|
1700
|
+
return this.type === types$1.name && this.value === name && !this.containsEsc;
|
|
2400
1701
|
};
|
|
2401
|
-
pp$9.eatContextual = function(
|
|
2402
|
-
if (!this.isContextual(
|
|
1702
|
+
pp$9.eatContextual = function(name) {
|
|
1703
|
+
if (!this.isContextual(name)) {
|
|
2403
1704
|
return false;
|
|
2404
1705
|
}
|
|
2405
1706
|
this.next();
|
|
2406
1707
|
return true;
|
|
2407
1708
|
};
|
|
2408
|
-
pp$9.expectContextual = function(
|
|
2409
|
-
if (!this.eatContextual(
|
|
1709
|
+
pp$9.expectContextual = function(name) {
|
|
1710
|
+
if (!this.eatContextual(name)) {
|
|
2410
1711
|
this.unexpected();
|
|
2411
1712
|
}
|
|
2412
1713
|
};
|
|
@@ -2500,8 +1801,8 @@ pp$8.parseTopLevel = function(node) {
|
|
|
2500
1801
|
}
|
|
2501
1802
|
if (this.inModule) {
|
|
2502
1803
|
for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1) {
|
|
2503
|
-
var
|
|
2504
|
-
this.raiseRecoverable(this.undefinedExports[
|
|
1804
|
+
var name = list[i];
|
|
1805
|
+
this.raiseRecoverable(this.undefinedExports[name].start, "Export '" + name + "' is not defined");
|
|
2505
1806
|
}
|
|
2506
1807
|
}
|
|
2507
1808
|
this.adaptDirectivePrologue(node.body);
|
|
@@ -3244,26 +2545,26 @@ pp$8.exitClassBody = function() {
|
|
|
3244
2545
|
}
|
|
3245
2546
|
};
|
|
3246
2547
|
function isPrivateNameConflicted(privateNameMap, element) {
|
|
3247
|
-
var
|
|
3248
|
-
var curr = privateNameMap[
|
|
2548
|
+
var name = element.key.name;
|
|
2549
|
+
var curr = privateNameMap[name];
|
|
3249
2550
|
var next = "true";
|
|
3250
2551
|
if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
|
|
3251
2552
|
next = (element.static ? "s" : "i") + element.kind;
|
|
3252
2553
|
}
|
|
3253
2554
|
if (curr === "iget" && next === "iset" || curr === "iset" && next === "iget" || curr === "sget" && next === "sset" || curr === "sset" && next === "sget") {
|
|
3254
|
-
privateNameMap[
|
|
2555
|
+
privateNameMap[name] = "true";
|
|
3255
2556
|
return false;
|
|
3256
2557
|
} else if (!curr) {
|
|
3257
|
-
privateNameMap[
|
|
2558
|
+
privateNameMap[name] = next;
|
|
3258
2559
|
return false;
|
|
3259
2560
|
} else {
|
|
3260
2561
|
return true;
|
|
3261
2562
|
}
|
|
3262
2563
|
}
|
|
3263
|
-
function checkKeyName(node,
|
|
2564
|
+
function checkKeyName(node, name) {
|
|
3264
2565
|
var computed = node.computed;
|
|
3265
2566
|
var key = node.key;
|
|
3266
|
-
return !computed && (key.type === "Identifier" && key.name ===
|
|
2567
|
+
return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name);
|
|
3267
2568
|
}
|
|
3268
2569
|
pp$8.parseExportAllDeclaration = function(node, exports) {
|
|
3269
2570
|
if (this.options.ecmaVersion >= 11) {
|
|
@@ -3351,17 +2652,17 @@ pp$8.parseExportDefaultDeclaration = function() {
|
|
|
3351
2652
|
return declaration;
|
|
3352
2653
|
}
|
|
3353
2654
|
};
|
|
3354
|
-
pp$8.checkExport = function(exports,
|
|
2655
|
+
pp$8.checkExport = function(exports, name, pos) {
|
|
3355
2656
|
if (!exports) {
|
|
3356
2657
|
return;
|
|
3357
2658
|
}
|
|
3358
|
-
if (typeof
|
|
3359
|
-
|
|
2659
|
+
if (typeof name !== "string") {
|
|
2660
|
+
name = name.type === "Identifier" ? name.name : name.value;
|
|
3360
2661
|
}
|
|
3361
|
-
if (hasOwn(exports,
|
|
3362
|
-
this.raiseRecoverable(pos, "Duplicate export '" +
|
|
2662
|
+
if (hasOwn(exports, name)) {
|
|
2663
|
+
this.raiseRecoverable(pos, "Duplicate export '" + name + "'");
|
|
3363
2664
|
}
|
|
3364
|
-
exports[
|
|
2665
|
+
exports[name] = true;
|
|
3365
2666
|
};
|
|
3366
2667
|
pp$8.checkPatternExport = function(exports, pat) {
|
|
3367
2668
|
var type = pat.type;
|
|
@@ -3941,20 +3242,20 @@ pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
|
|
|
3941
3242
|
return;
|
|
3942
3243
|
}
|
|
3943
3244
|
var key = prop.key;
|
|
3944
|
-
var
|
|
3245
|
+
var name;
|
|
3945
3246
|
switch (key.type) {
|
|
3946
3247
|
case "Identifier":
|
|
3947
|
-
|
|
3248
|
+
name = key.name;
|
|
3948
3249
|
break;
|
|
3949
3250
|
case "Literal":
|
|
3950
|
-
|
|
3251
|
+
name = String(key.value);
|
|
3951
3252
|
break;
|
|
3952
3253
|
default:
|
|
3953
3254
|
return;
|
|
3954
3255
|
}
|
|
3955
3256
|
var kind = prop.kind;
|
|
3956
3257
|
if (this.options.ecmaVersion >= 6) {
|
|
3957
|
-
if (
|
|
3258
|
+
if (name === "__proto__" && kind === "init") {
|
|
3958
3259
|
if (propHash.proto) {
|
|
3959
3260
|
if (refDestructuringErrors) {
|
|
3960
3261
|
if (refDestructuringErrors.doubleProto < 0) {
|
|
@@ -3968,8 +3269,8 @@ pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
|
|
|
3968
3269
|
}
|
|
3969
3270
|
return;
|
|
3970
3271
|
}
|
|
3971
|
-
|
|
3972
|
-
var other = propHash[
|
|
3272
|
+
name = "$" + name;
|
|
3273
|
+
var other = propHash[name];
|
|
3973
3274
|
if (other) {
|
|
3974
3275
|
var redefinition;
|
|
3975
3276
|
if (kind === "init") {
|
|
@@ -3981,7 +3282,7 @@ pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
|
|
|
3981
3282
|
this.raiseRecoverable(key.start, "Redefinition of property");
|
|
3982
3283
|
}
|
|
3983
3284
|
} else {
|
|
3984
|
-
other = propHash[
|
|
3285
|
+
other = propHash[name] = {
|
|
3985
3286
|
init: false,
|
|
3986
3287
|
get: false,
|
|
3987
3288
|
set: false
|
|
@@ -4881,31 +4182,31 @@ pp$5.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestruct
|
|
|
4881
4182
|
pp$5.checkUnreserved = function(ref2) {
|
|
4882
4183
|
var start = ref2.start;
|
|
4883
4184
|
var end = ref2.end;
|
|
4884
|
-
var
|
|
4885
|
-
if (this.inGenerator &&
|
|
4185
|
+
var name = ref2.name;
|
|
4186
|
+
if (this.inGenerator && name === "yield") {
|
|
4886
4187
|
this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator");
|
|
4887
4188
|
}
|
|
4888
|
-
if (this.inAsync &&
|
|
4189
|
+
if (this.inAsync && name === "await") {
|
|
4889
4190
|
this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function");
|
|
4890
4191
|
}
|
|
4891
|
-
if (this.currentThisScope().inClassFieldInit &&
|
|
4192
|
+
if (this.currentThisScope().inClassFieldInit && name === "arguments") {
|
|
4892
4193
|
this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer");
|
|
4893
4194
|
}
|
|
4894
|
-
if (this.inClassStaticBlock && (
|
|
4895
|
-
this.raise(start, "Cannot use " +
|
|
4195
|
+
if (this.inClassStaticBlock && (name === "arguments" || name === "await")) {
|
|
4196
|
+
this.raise(start, "Cannot use " + name + " in class static initialization block");
|
|
4896
4197
|
}
|
|
4897
|
-
if (this.keywords.test(
|
|
4898
|
-
this.raise(start, "Unexpected keyword '" +
|
|
4198
|
+
if (this.keywords.test(name)) {
|
|
4199
|
+
this.raise(start, "Unexpected keyword '" + name + "'");
|
|
4899
4200
|
}
|
|
4900
4201
|
if (this.options.ecmaVersion < 6 && this.input.slice(start, end).indexOf("\\") !== -1) {
|
|
4901
4202
|
return;
|
|
4902
4203
|
}
|
|
4903
4204
|
var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
|
|
4904
|
-
if (re.test(
|
|
4905
|
-
if (!this.inAsync &&
|
|
4205
|
+
if (re.test(name)) {
|
|
4206
|
+
if (!this.inAsync && name === "await") {
|
|
4906
4207
|
this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function");
|
|
4907
4208
|
}
|
|
4908
|
-
this.raiseRecoverable(start, "The keyword '" +
|
|
4209
|
+
this.raiseRecoverable(start, "The keyword '" + name + "' is reserved");
|
|
4909
4210
|
}
|
|
4910
4211
|
};
|
|
4911
4212
|
pp$5.parseIdent = function(liberal) {
|
|
@@ -5010,36 +4311,36 @@ pp$3.exitScope = function() {
|
|
|
5010
4311
|
pp$3.treatFunctionsAsVarInScope = function(scope) {
|
|
5011
4312
|
return scope.flags & SCOPE_FUNCTION || !this.inModule && scope.flags & SCOPE_TOP;
|
|
5012
4313
|
};
|
|
5013
|
-
pp$3.declareName = function(
|
|
4314
|
+
pp$3.declareName = function(name, bindingType, pos) {
|
|
5014
4315
|
var redeclared = false;
|
|
5015
4316
|
if (bindingType === BIND_LEXICAL) {
|
|
5016
4317
|
var scope = this.currentScope();
|
|
5017
|
-
redeclared = scope.lexical.indexOf(
|
|
5018
|
-
scope.lexical.push(
|
|
4318
|
+
redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
|
|
4319
|
+
scope.lexical.push(name);
|
|
5019
4320
|
if (this.inModule && scope.flags & SCOPE_TOP) {
|
|
5020
|
-
delete this.undefinedExports[
|
|
4321
|
+
delete this.undefinedExports[name];
|
|
5021
4322
|
}
|
|
5022
4323
|
} else if (bindingType === BIND_SIMPLE_CATCH) {
|
|
5023
4324
|
var scope$1 = this.currentScope();
|
|
5024
|
-
scope$1.lexical.push(
|
|
4325
|
+
scope$1.lexical.push(name);
|
|
5025
4326
|
} else if (bindingType === BIND_FUNCTION) {
|
|
5026
4327
|
var scope$2 = this.currentScope();
|
|
5027
4328
|
if (this.treatFunctionsAsVar) {
|
|
5028
|
-
redeclared = scope$2.lexical.indexOf(
|
|
4329
|
+
redeclared = scope$2.lexical.indexOf(name) > -1;
|
|
5029
4330
|
} else {
|
|
5030
|
-
redeclared = scope$2.lexical.indexOf(
|
|
4331
|
+
redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1;
|
|
5031
4332
|
}
|
|
5032
|
-
scope$2.functions.push(
|
|
4333
|
+
scope$2.functions.push(name);
|
|
5033
4334
|
} else {
|
|
5034
4335
|
for (var i = this.scopeStack.length - 1; i >= 0; --i) {
|
|
5035
4336
|
var scope$3 = this.scopeStack[i];
|
|
5036
|
-
if (scope$3.lexical.indexOf(
|
|
4337
|
+
if (scope$3.lexical.indexOf(name) > -1 && !(scope$3.flags & SCOPE_SIMPLE_CATCH && scope$3.lexical[0] === name) || !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
|
|
5037
4338
|
redeclared = true;
|
|
5038
4339
|
break;
|
|
5039
4340
|
}
|
|
5040
|
-
scope$3.var.push(
|
|
4341
|
+
scope$3.var.push(name);
|
|
5041
4342
|
if (this.inModule && scope$3.flags & SCOPE_TOP) {
|
|
5042
|
-
delete this.undefinedExports[
|
|
4343
|
+
delete this.undefinedExports[name];
|
|
5043
4344
|
}
|
|
5044
4345
|
if (scope$3.flags & SCOPE_VAR) {
|
|
5045
4346
|
break;
|
|
@@ -5047,7 +4348,7 @@ pp$3.declareName = function(name2, bindingType, pos) {
|
|
|
5047
4348
|
}
|
|
5048
4349
|
}
|
|
5049
4350
|
if (redeclared) {
|
|
5050
|
-
this.raiseRecoverable(pos, "Identifier '" +
|
|
4351
|
+
this.raiseRecoverable(pos, "Identifier '" + name + "' has already been declared");
|
|
5051
4352
|
}
|
|
5052
4353
|
};
|
|
5053
4354
|
pp$3.checkLocalExport = function(id) {
|
|
@@ -5367,8 +4668,8 @@ pp$1.regexp_pattern = function(state) {
|
|
|
5367
4668
|
state.raise("Invalid escape");
|
|
5368
4669
|
}
|
|
5369
4670
|
for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
|
|
5370
|
-
var
|
|
5371
|
-
if (!state.groupNames[
|
|
4671
|
+
var name = list[i];
|
|
4672
|
+
if (!state.groupNames[name]) {
|
|
5372
4673
|
state.raise("Invalid named capture referenced");
|
|
5373
4674
|
}
|
|
5374
4675
|
}
|
|
@@ -6007,10 +5308,10 @@ pp$1.regexp_eatUnicodePropertyValueExpression = function(state) {
|
|
|
6007
5308
|
61
|
|
6008
5309
|
/* = */
|
|
6009
5310
|
)) {
|
|
6010
|
-
var
|
|
5311
|
+
var name = state.lastStringValue;
|
|
6011
5312
|
if (this.regexp_eatUnicodePropertyValue(state)) {
|
|
6012
5313
|
var value = state.lastStringValue;
|
|
6013
|
-
this.regexp_validateUnicodePropertyNameAndValue(state,
|
|
5314
|
+
this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
|
|
6014
5315
|
return CharSetOk;
|
|
6015
5316
|
}
|
|
6016
5317
|
}
|
|
@@ -6021,11 +5322,11 @@ pp$1.regexp_eatUnicodePropertyValueExpression = function(state) {
|
|
|
6021
5322
|
}
|
|
6022
5323
|
return CharSetNone;
|
|
6023
5324
|
};
|
|
6024
|
-
pp$1.regexp_validateUnicodePropertyNameAndValue = function(state,
|
|
6025
|
-
if (!hasOwn(state.unicodeProperties.nonBinary,
|
|
5325
|
+
pp$1.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
|
|
5326
|
+
if (!hasOwn(state.unicodeProperties.nonBinary, name)) {
|
|
6026
5327
|
state.raise("Invalid property name");
|
|
6027
5328
|
}
|
|
6028
|
-
if (!state.unicodeProperties.nonBinary[
|
|
5329
|
+
if (!state.unicodeProperties.nonBinary[name].test(value)) {
|
|
6029
5330
|
state.raise("Invalid property value");
|
|
6030
5331
|
}
|
|
6031
5332
|
};
|
|
@@ -7342,7 +6643,7 @@ Parser.acorn = {
|
|
|
7342
6643
|
|
|
7343
6644
|
// ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
|
|
7344
6645
|
import { builtinModules, createRequire } from "node:module";
|
|
7345
|
-
import
|
|
6646
|
+
import fs, { realpathSync, statSync, promises } from "node:fs";
|
|
7346
6647
|
|
|
7347
6648
|
// ../../node_modules/.pnpm/ufo@1.5.4/node_modules/ufo/dist/index.mjs
|
|
7348
6649
|
var r = String.fromCharCode;
|
|
@@ -7399,9 +6700,9 @@ var isAbsolute = function(p) {
|
|
|
7399
6700
|
|
|
7400
6701
|
// ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
|
|
7401
6702
|
import { fileURLToPath as fileURLToPath$1, URL as URL$1, pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
7402
|
-
import
|
|
6703
|
+
import assert from "node:assert";
|
|
7403
6704
|
import process$1 from "node:process";
|
|
7404
|
-
import
|
|
6705
|
+
import path, { dirname as dirname2 } from "node:path";
|
|
7405
6706
|
import v8 from "node:v8";
|
|
7406
6707
|
import { format as format2, inspect } from "node:util";
|
|
7407
6708
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
@@ -7436,31 +6737,31 @@ codes.ERR_INVALID_ARG_TYPE = createError(
|
|
|
7436
6737
|
* @param {Array<string> | string} expected
|
|
7437
6738
|
* @param {unknown} actual
|
|
7438
6739
|
*/
|
|
7439
|
-
(
|
|
7440
|
-
|
|
6740
|
+
(name, expected, actual) => {
|
|
6741
|
+
assert(typeof name === "string", "'name' must be a string");
|
|
7441
6742
|
if (!Array.isArray(expected)) {
|
|
7442
6743
|
expected = [expected];
|
|
7443
6744
|
}
|
|
7444
6745
|
let message = "The ";
|
|
7445
|
-
if (
|
|
7446
|
-
message += `${
|
|
6746
|
+
if (name.endsWith(" argument")) {
|
|
6747
|
+
message += `${name} `;
|
|
7447
6748
|
} else {
|
|
7448
|
-
const type =
|
|
7449
|
-
message += `"${
|
|
6749
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
6750
|
+
message += `"${name}" ${type} `;
|
|
7450
6751
|
}
|
|
7451
6752
|
message += "must be ";
|
|
7452
6753
|
const types2 = [];
|
|
7453
6754
|
const instances = [];
|
|
7454
6755
|
const other = [];
|
|
7455
6756
|
for (const value of expected) {
|
|
7456
|
-
|
|
6757
|
+
assert(
|
|
7457
6758
|
typeof value === "string",
|
|
7458
6759
|
"All expected entries have to be of type string"
|
|
7459
6760
|
);
|
|
7460
6761
|
if (kTypes.has(value)) {
|
|
7461
6762
|
types2.push(value.toLowerCase());
|
|
7462
6763
|
} else if (classRegExp.exec(value) === null) {
|
|
7463
|
-
|
|
6764
|
+
assert(
|
|
7464
6765
|
value !== "object",
|
|
7465
6766
|
'The value "object" should be written as "Object"'
|
|
7466
6767
|
);
|
|
@@ -7533,14 +6834,14 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
|
7533
6834
|
* @param {boolean} [isImport=false]
|
|
7534
6835
|
* @param {string} [base]
|
|
7535
6836
|
*/
|
|
7536
|
-
(packagePath, key,
|
|
7537
|
-
const relatedError = typeof
|
|
6837
|
+
(packagePath, key, target2, isImport = false, base = void 0) => {
|
|
6838
|
+
const relatedError = typeof target2 === "string" && !isImport && target2.length > 0 && !target2.startsWith("./");
|
|
7538
6839
|
if (key === ".") {
|
|
7539
|
-
|
|
7540
|
-
return `Invalid "exports" main target ${JSON.stringify(
|
|
6840
|
+
assert(isImport === false);
|
|
6841
|
+
return `Invalid "exports" main target ${JSON.stringify(target2)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
7541
6842
|
}
|
|
7542
6843
|
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
|
|
7543
|
-
|
|
6844
|
+
target2
|
|
7544
6845
|
)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
7545
6846
|
},
|
|
7546
6847
|
Error
|
|
@@ -7616,13 +6917,13 @@ codes.ERR_INVALID_ARG_VALUE = createError(
|
|
|
7616
6917
|
* @param {unknown} value
|
|
7617
6918
|
* @param {string} [reason='is invalid']
|
|
7618
6919
|
*/
|
|
7619
|
-
(
|
|
6920
|
+
(name, value, reason = "is invalid") => {
|
|
7620
6921
|
let inspected = inspect(value);
|
|
7621
6922
|
if (inspected.length > 128) {
|
|
7622
6923
|
inspected = `${inspected.slice(0, 128)}...`;
|
|
7623
6924
|
}
|
|
7624
|
-
const type =
|
|
7625
|
-
return `The ${type} '${
|
|
6925
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
6926
|
+
return `The ${type} '${name}' ${reason}. Received ${inspected}`;
|
|
7626
6927
|
},
|
|
7627
6928
|
TypeError
|
|
7628
6929
|
// Note: extra classes have been shaken out.
|
|
@@ -7701,9 +7002,9 @@ var captureLargerStackTrace = hideStackFrames(
|
|
|
7701
7002
|
);
|
|
7702
7003
|
function getMessage(key, parameters, self) {
|
|
7703
7004
|
const message = messages.get(key);
|
|
7704
|
-
|
|
7005
|
+
assert(message !== void 0, "expected `message` to be found");
|
|
7705
7006
|
if (typeof message === "function") {
|
|
7706
|
-
|
|
7007
|
+
assert(
|
|
7707
7008
|
message.length <= parameters.length,
|
|
7708
7009
|
// Default options do not count.
|
|
7709
7010
|
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
|
|
@@ -7713,7 +7014,7 @@ function getMessage(key, parameters, self) {
|
|
|
7713
7014
|
const regex = /%[dfijoOs]/g;
|
|
7714
7015
|
let expectedLength = 0;
|
|
7715
7016
|
while (regex.exec(message) !== null) expectedLength++;
|
|
7716
|
-
|
|
7017
|
+
assert(
|
|
7717
7018
|
expectedLength === parameters.length,
|
|
7718
7019
|
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
|
|
7719
7020
|
);
|
|
@@ -7750,7 +7051,7 @@ function read(jsonPath, { base, specifier }) {
|
|
|
7750
7051
|
}
|
|
7751
7052
|
let string;
|
|
7752
7053
|
try {
|
|
7753
|
-
string =
|
|
7054
|
+
string = fs.readFileSync(path.toNamespacedPath(jsonPath), "utf8");
|
|
7754
7055
|
} catch (error) {
|
|
7755
7056
|
const exception = (
|
|
7756
7057
|
/** @type {ErrnoException} */
|
|
@@ -7881,967 +7182,1760 @@ function extname2(url) {
|
|
|
7881
7182
|
return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
|
|
7882
7183
|
}
|
|
7883
7184
|
}
|
|
7884
|
-
return "";
|
|
7885
|
-
}
|
|
7886
|
-
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
7887
|
-
const value = extname2(url);
|
|
7888
|
-
if (value === ".js") {
|
|
7889
|
-
const packageType = getPackageType(url);
|
|
7890
|
-
if (packageType !== "none") {
|
|
7891
|
-
return packageType;
|
|
7185
|
+
return "";
|
|
7186
|
+
}
|
|
7187
|
+
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
7188
|
+
const value = extname2(url);
|
|
7189
|
+
if (value === ".js") {
|
|
7190
|
+
const packageType = getPackageType(url);
|
|
7191
|
+
if (packageType !== "none") {
|
|
7192
|
+
return packageType;
|
|
7193
|
+
}
|
|
7194
|
+
return "commonjs";
|
|
7195
|
+
}
|
|
7196
|
+
if (value === "") {
|
|
7197
|
+
const packageType = getPackageType(url);
|
|
7198
|
+
if (packageType === "none" || packageType === "commonjs") {
|
|
7199
|
+
return "commonjs";
|
|
7200
|
+
}
|
|
7201
|
+
return "module";
|
|
7202
|
+
}
|
|
7203
|
+
const format3 = extensionFormatMap[value];
|
|
7204
|
+
if (format3) return format3;
|
|
7205
|
+
if (ignoreErrors) {
|
|
7206
|
+
return void 0;
|
|
7207
|
+
}
|
|
7208
|
+
const filepath = fileURLToPath$1(url);
|
|
7209
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath);
|
|
7210
|
+
}
|
|
7211
|
+
function getHttpProtocolModuleFormat() {
|
|
7212
|
+
}
|
|
7213
|
+
function defaultGetFormatWithoutErrors(url, context) {
|
|
7214
|
+
const protocol = url.protocol;
|
|
7215
|
+
if (!hasOwnProperty2.call(protocolHandlers, protocol)) {
|
|
7216
|
+
return null;
|
|
7217
|
+
}
|
|
7218
|
+
return protocolHandlers[protocol](url, context, true) || null;
|
|
7219
|
+
}
|
|
7220
|
+
var RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
7221
|
+
var {
|
|
7222
|
+
ERR_NETWORK_IMPORT_DISALLOWED,
|
|
7223
|
+
ERR_INVALID_MODULE_SPECIFIER,
|
|
7224
|
+
ERR_INVALID_PACKAGE_CONFIG,
|
|
7225
|
+
ERR_INVALID_PACKAGE_TARGET,
|
|
7226
|
+
ERR_MODULE_NOT_FOUND,
|
|
7227
|
+
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
7228
|
+
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
7229
|
+
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
7230
|
+
ERR_UNSUPPORTED_RESOLVE_REQUEST
|
|
7231
|
+
} = codes;
|
|
7232
|
+
var own = {}.hasOwnProperty;
|
|
7233
|
+
var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
7234
|
+
var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
7235
|
+
var invalidPackageNameRegEx = /^\.|%|\\/;
|
|
7236
|
+
var patternRegEx = /\*/g;
|
|
7237
|
+
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
7238
|
+
var emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
7239
|
+
var doubleSlashRegEx = /[/\\]{2}/;
|
|
7240
|
+
function emitInvalidSegmentDeprecation(target2, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
7241
|
+
if (process$1.noDeprecation) {
|
|
7242
|
+
return;
|
|
7243
|
+
}
|
|
7244
|
+
const pjsonPath = fileURLToPath$1(packageJsonUrl);
|
|
7245
|
+
const double = doubleSlashRegEx.exec(isTarget ? target2 : request) !== null;
|
|
7246
|
+
process$1.emitWarning(
|
|
7247
|
+
`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target2}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}.`,
|
|
7248
|
+
"DeprecationWarning",
|
|
7249
|
+
"DEP0166"
|
|
7250
|
+
);
|
|
7251
|
+
}
|
|
7252
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
7253
|
+
if (process$1.noDeprecation) {
|
|
7254
|
+
return;
|
|
7255
|
+
}
|
|
7256
|
+
const format3 = defaultGetFormatWithoutErrors(url, { parentURL: base.href });
|
|
7257
|
+
if (format3 !== "module") return;
|
|
7258
|
+
const urlPath = fileURLToPath$1(url.href);
|
|
7259
|
+
const packagePath = fileURLToPath$1(new URL$1(".", packageJsonUrl));
|
|
7260
|
+
const basePath = fileURLToPath$1(base);
|
|
7261
|
+
if (!main) {
|
|
7262
|
+
process$1.emitWarning(
|
|
7263
|
+
`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(
|
|
7264
|
+
packagePath.length
|
|
7265
|
+
)}", imported from ${basePath}.
|
|
7266
|
+
Default "index" lookups for the main are deprecated for ES modules.`,
|
|
7267
|
+
"DeprecationWarning",
|
|
7268
|
+
"DEP0151"
|
|
7269
|
+
);
|
|
7270
|
+
} else if (path.resolve(packagePath, main) !== urlPath) {
|
|
7271
|
+
process$1.emitWarning(
|
|
7272
|
+
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
7273
|
+
packagePath.length
|
|
7274
|
+
)}", imported from ${basePath}.
|
|
7275
|
+
Automatic extension resolution of the "main" field is deprecated for ES modules.`,
|
|
7276
|
+
"DeprecationWarning",
|
|
7277
|
+
"DEP0151"
|
|
7278
|
+
);
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
function tryStatSync(path8) {
|
|
7282
|
+
try {
|
|
7283
|
+
return statSync(path8);
|
|
7284
|
+
} catch {
|
|
7285
|
+
}
|
|
7286
|
+
}
|
|
7287
|
+
function fileExists(url) {
|
|
7288
|
+
const stats = statSync(url, { throwIfNoEntry: false });
|
|
7289
|
+
const isFile = stats ? stats.isFile() : void 0;
|
|
7290
|
+
return isFile === null || isFile === void 0 ? false : isFile;
|
|
7291
|
+
}
|
|
7292
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
7293
|
+
let guess;
|
|
7294
|
+
if (packageConfig.main !== void 0) {
|
|
7295
|
+
guess = new URL$1(packageConfig.main, packageJsonUrl);
|
|
7296
|
+
if (fileExists(guess)) return guess;
|
|
7297
|
+
const tries2 = [
|
|
7298
|
+
`./${packageConfig.main}.js`,
|
|
7299
|
+
`./${packageConfig.main}.json`,
|
|
7300
|
+
`./${packageConfig.main}.node`,
|
|
7301
|
+
`./${packageConfig.main}/index.js`,
|
|
7302
|
+
`./${packageConfig.main}/index.json`,
|
|
7303
|
+
`./${packageConfig.main}/index.node`
|
|
7304
|
+
];
|
|
7305
|
+
let i2 = -1;
|
|
7306
|
+
while (++i2 < tries2.length) {
|
|
7307
|
+
guess = new URL$1(tries2[i2], packageJsonUrl);
|
|
7308
|
+
if (fileExists(guess)) break;
|
|
7309
|
+
guess = void 0;
|
|
7310
|
+
}
|
|
7311
|
+
if (guess) {
|
|
7312
|
+
emitLegacyIndexDeprecation(
|
|
7313
|
+
guess,
|
|
7314
|
+
packageJsonUrl,
|
|
7315
|
+
base,
|
|
7316
|
+
packageConfig.main
|
|
7317
|
+
);
|
|
7318
|
+
return guess;
|
|
7319
|
+
}
|
|
7320
|
+
}
|
|
7321
|
+
const tries = ["./index.js", "./index.json", "./index.node"];
|
|
7322
|
+
let i = -1;
|
|
7323
|
+
while (++i < tries.length) {
|
|
7324
|
+
guess = new URL$1(tries[i], packageJsonUrl);
|
|
7325
|
+
if (fileExists(guess)) break;
|
|
7326
|
+
guess = void 0;
|
|
7327
|
+
}
|
|
7328
|
+
if (guess) {
|
|
7329
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
7330
|
+
return guess;
|
|
7331
|
+
}
|
|
7332
|
+
throw new ERR_MODULE_NOT_FOUND(
|
|
7333
|
+
fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
7334
|
+
fileURLToPath$1(base)
|
|
7335
|
+
);
|
|
7336
|
+
}
|
|
7337
|
+
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
7338
|
+
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
|
|
7339
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
7340
|
+
resolved.pathname,
|
|
7341
|
+
'must not include encoded "/" or "\\" characters',
|
|
7342
|
+
fileURLToPath$1(base)
|
|
7343
|
+
);
|
|
7344
|
+
}
|
|
7345
|
+
let filePath;
|
|
7346
|
+
try {
|
|
7347
|
+
filePath = fileURLToPath$1(resolved);
|
|
7348
|
+
} catch (error) {
|
|
7349
|
+
const cause = (
|
|
7350
|
+
/** @type {ErrnoException} */
|
|
7351
|
+
error
|
|
7352
|
+
);
|
|
7353
|
+
Object.defineProperty(cause, "input", { value: String(resolved) });
|
|
7354
|
+
Object.defineProperty(cause, "module", { value: String(base) });
|
|
7355
|
+
throw cause;
|
|
7356
|
+
}
|
|
7357
|
+
const stats = tryStatSync(
|
|
7358
|
+
filePath.endsWith("/") ? filePath.slice(-1) : filePath
|
|
7359
|
+
);
|
|
7360
|
+
if (stats && stats.isDirectory()) {
|
|
7361
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath$1(base));
|
|
7362
|
+
error.url = String(resolved);
|
|
7363
|
+
throw error;
|
|
7364
|
+
}
|
|
7365
|
+
if (!stats || !stats.isFile()) {
|
|
7366
|
+
const error = new ERR_MODULE_NOT_FOUND(
|
|
7367
|
+
filePath || resolved.pathname,
|
|
7368
|
+
base && fileURLToPath$1(base),
|
|
7369
|
+
true
|
|
7370
|
+
);
|
|
7371
|
+
error.url = String(resolved);
|
|
7372
|
+
throw error;
|
|
7373
|
+
}
|
|
7374
|
+
{
|
|
7375
|
+
const real = realpathSync(filePath);
|
|
7376
|
+
const { search, hash } = resolved;
|
|
7377
|
+
resolved = pathToFileURL$1(real + (filePath.endsWith(path.sep) ? "/" : ""));
|
|
7378
|
+
resolved.search = search;
|
|
7379
|
+
resolved.hash = hash;
|
|
7380
|
+
}
|
|
7381
|
+
return resolved;
|
|
7382
|
+
}
|
|
7383
|
+
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
7384
|
+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
7385
|
+
specifier,
|
|
7386
|
+
packageJsonUrl && fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
7387
|
+
fileURLToPath$1(base)
|
|
7388
|
+
);
|
|
7389
|
+
}
|
|
7390
|
+
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
7391
|
+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
7392
|
+
fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
7393
|
+
subpath,
|
|
7394
|
+
base && fileURLToPath$1(base)
|
|
7395
|
+
);
|
|
7396
|
+
}
|
|
7397
|
+
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
7398
|
+
const reason = `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath$1(packageJsonUrl)}`;
|
|
7399
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
7400
|
+
request,
|
|
7401
|
+
reason,
|
|
7402
|
+
base && fileURLToPath$1(base)
|
|
7403
|
+
);
|
|
7404
|
+
}
|
|
7405
|
+
function invalidPackageTarget(subpath, target2, packageJsonUrl, internal, base) {
|
|
7406
|
+
target2 = typeof target2 === "object" && target2 !== null ? JSON.stringify(target2, null, "") : `${target2}`;
|
|
7407
|
+
return new ERR_INVALID_PACKAGE_TARGET(
|
|
7408
|
+
fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
7409
|
+
subpath,
|
|
7410
|
+
target2,
|
|
7411
|
+
internal,
|
|
7412
|
+
base && fileURLToPath$1(base)
|
|
7413
|
+
);
|
|
7414
|
+
}
|
|
7415
|
+
function resolvePackageTargetString(target2, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
7416
|
+
if (subpath !== "" && !pattern && target2[target2.length - 1] !== "/")
|
|
7417
|
+
throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
|
|
7418
|
+
if (!target2.startsWith("./")) {
|
|
7419
|
+
if (internal && !target2.startsWith("../") && !target2.startsWith("/")) {
|
|
7420
|
+
let isURL = false;
|
|
7421
|
+
try {
|
|
7422
|
+
new URL$1(target2);
|
|
7423
|
+
isURL = true;
|
|
7424
|
+
} catch {
|
|
7425
|
+
}
|
|
7426
|
+
if (!isURL) {
|
|
7427
|
+
const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
7428
|
+
patternRegEx,
|
|
7429
|
+
target2,
|
|
7430
|
+
() => subpath
|
|
7431
|
+
) : target2 + subpath;
|
|
7432
|
+
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
7433
|
+
}
|
|
7434
|
+
}
|
|
7435
|
+
throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
|
|
7436
|
+
}
|
|
7437
|
+
if (invalidSegmentRegEx.exec(target2.slice(2)) !== null) {
|
|
7438
|
+
if (deprecatedInvalidSegmentRegEx.exec(target2.slice(2)) === null) {
|
|
7439
|
+
if (!isPathMap) {
|
|
7440
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
7441
|
+
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
7442
|
+
patternRegEx,
|
|
7443
|
+
target2,
|
|
7444
|
+
() => subpath
|
|
7445
|
+
) : target2;
|
|
7446
|
+
emitInvalidSegmentDeprecation(
|
|
7447
|
+
resolvedTarget,
|
|
7448
|
+
request,
|
|
7449
|
+
match,
|
|
7450
|
+
packageJsonUrl,
|
|
7451
|
+
internal,
|
|
7452
|
+
base,
|
|
7453
|
+
true
|
|
7454
|
+
);
|
|
7455
|
+
}
|
|
7456
|
+
} else {
|
|
7457
|
+
throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
|
|
7892
7458
|
}
|
|
7893
|
-
return "commonjs";
|
|
7894
7459
|
}
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7460
|
+
const resolved = new URL$1(target2, packageJsonUrl);
|
|
7461
|
+
const resolvedPath = resolved.pathname;
|
|
7462
|
+
const packagePath = new URL$1(".", packageJsonUrl).pathname;
|
|
7463
|
+
if (!resolvedPath.startsWith(packagePath))
|
|
7464
|
+
throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
|
|
7465
|
+
if (subpath === "") return resolved;
|
|
7466
|
+
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
7467
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
7468
|
+
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
7469
|
+
if (!isPathMap) {
|
|
7470
|
+
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
7471
|
+
patternRegEx,
|
|
7472
|
+
target2,
|
|
7473
|
+
() => subpath
|
|
7474
|
+
) : target2;
|
|
7475
|
+
emitInvalidSegmentDeprecation(
|
|
7476
|
+
resolvedTarget,
|
|
7477
|
+
request,
|
|
7478
|
+
match,
|
|
7479
|
+
packageJsonUrl,
|
|
7480
|
+
internal,
|
|
7481
|
+
base,
|
|
7482
|
+
false
|
|
7483
|
+
);
|
|
7484
|
+
}
|
|
7485
|
+
} else {
|
|
7486
|
+
throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
7899
7487
|
}
|
|
7900
|
-
return "module";
|
|
7901
|
-
}
|
|
7902
|
-
const format3 = extensionFormatMap[value];
|
|
7903
|
-
if (format3) return format3;
|
|
7904
|
-
if (ignoreErrors) {
|
|
7905
|
-
return void 0;
|
|
7906
7488
|
}
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
return null;
|
|
7489
|
+
if (pattern) {
|
|
7490
|
+
return new URL$1(
|
|
7491
|
+
RegExpPrototypeSymbolReplace.call(
|
|
7492
|
+
patternRegEx,
|
|
7493
|
+
resolved.href,
|
|
7494
|
+
() => subpath
|
|
7495
|
+
)
|
|
7496
|
+
);
|
|
7916
7497
|
}
|
|
7917
|
-
return
|
|
7498
|
+
return new URL$1(subpath, resolved);
|
|
7918
7499
|
}
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
ERR_INVALID_PACKAGE_CONFIG,
|
|
7924
|
-
ERR_INVALID_PACKAGE_TARGET,
|
|
7925
|
-
ERR_MODULE_NOT_FOUND,
|
|
7926
|
-
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
7927
|
-
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
7928
|
-
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
7929
|
-
ERR_UNSUPPORTED_RESOLVE_REQUEST
|
|
7930
|
-
} = codes;
|
|
7931
|
-
var own = {}.hasOwnProperty;
|
|
7932
|
-
var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
7933
|
-
var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
7934
|
-
var invalidPackageNameRegEx = /^\.|%|\\/;
|
|
7935
|
-
var patternRegEx = /\*/g;
|
|
7936
|
-
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
7937
|
-
var emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
7938
|
-
var doubleSlashRegEx = /[/\\]{2}/;
|
|
7939
|
-
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
7940
|
-
if (process$1.noDeprecation) {
|
|
7941
|
-
return;
|
|
7942
|
-
}
|
|
7943
|
-
const pjsonPath = fileURLToPath$1(packageJsonUrl);
|
|
7944
|
-
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
7945
|
-
process$1.emitWarning(
|
|
7946
|
-
`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}.`,
|
|
7947
|
-
"DeprecationWarning",
|
|
7948
|
-
"DEP0166"
|
|
7949
|
-
);
|
|
7500
|
+
function isArrayIndex(key) {
|
|
7501
|
+
const keyNumber = Number(key);
|
|
7502
|
+
if (`${keyNumber}` !== key) return false;
|
|
7503
|
+
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
7950
7504
|
}
|
|
7951
|
-
function
|
|
7952
|
-
if (
|
|
7953
|
-
return
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
packagePath.length
|
|
7964
|
-
)}", imported from ${basePath}.
|
|
7965
|
-
Default "index" lookups for the main are deprecated for ES modules.`,
|
|
7966
|
-
"DeprecationWarning",
|
|
7967
|
-
"DEP0151"
|
|
7968
|
-
);
|
|
7969
|
-
} else if (path4.resolve(packagePath, main) !== urlPath) {
|
|
7970
|
-
process$1.emitWarning(
|
|
7971
|
-
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
7972
|
-
packagePath.length
|
|
7973
|
-
)}", imported from ${basePath}.
|
|
7974
|
-
Automatic extension resolution of the "main" field is deprecated for ES modules.`,
|
|
7975
|
-
"DeprecationWarning",
|
|
7976
|
-
"DEP0151"
|
|
7505
|
+
function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
7506
|
+
if (typeof target2 === "string") {
|
|
7507
|
+
return resolvePackageTargetString(
|
|
7508
|
+
target2,
|
|
7509
|
+
subpath,
|
|
7510
|
+
packageSubpath,
|
|
7511
|
+
packageJsonUrl,
|
|
7512
|
+
base,
|
|
7513
|
+
pattern,
|
|
7514
|
+
internal,
|
|
7515
|
+
isPathMap,
|
|
7516
|
+
conditions
|
|
7977
7517
|
);
|
|
7978
7518
|
}
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7519
|
+
if (Array.isArray(target2)) {
|
|
7520
|
+
const targetList = target2;
|
|
7521
|
+
if (targetList.length === 0) return null;
|
|
7522
|
+
let lastException;
|
|
7523
|
+
let i = -1;
|
|
7524
|
+
while (++i < targetList.length) {
|
|
7525
|
+
const targetItem = targetList[i];
|
|
7526
|
+
let resolveResult;
|
|
7527
|
+
try {
|
|
7528
|
+
resolveResult = resolvePackageTarget(
|
|
7529
|
+
packageJsonUrl,
|
|
7530
|
+
targetItem,
|
|
7531
|
+
subpath,
|
|
7532
|
+
packageSubpath,
|
|
7533
|
+
base,
|
|
7534
|
+
pattern,
|
|
7535
|
+
internal,
|
|
7536
|
+
isPathMap,
|
|
7537
|
+
conditions
|
|
7538
|
+
);
|
|
7539
|
+
} catch (error) {
|
|
7540
|
+
const exception = (
|
|
7541
|
+
/** @type {ErrnoException} */
|
|
7542
|
+
error
|
|
7543
|
+
);
|
|
7544
|
+
lastException = exception;
|
|
7545
|
+
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
7546
|
+
throw error;
|
|
7547
|
+
}
|
|
7548
|
+
if (resolveResult === void 0) continue;
|
|
7549
|
+
if (resolveResult === null) {
|
|
7550
|
+
lastException = null;
|
|
7551
|
+
continue;
|
|
7552
|
+
}
|
|
7553
|
+
return resolveResult;
|
|
7554
|
+
}
|
|
7555
|
+
if (lastException === void 0 || lastException === null) {
|
|
7556
|
+
return null;
|
|
7557
|
+
}
|
|
7558
|
+
throw lastException;
|
|
7984
7559
|
}
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
`./${packageConfig.main}.js`,
|
|
7998
|
-
`./${packageConfig.main}.json`,
|
|
7999
|
-
`./${packageConfig.main}.node`,
|
|
8000
|
-
`./${packageConfig.main}/index.js`,
|
|
8001
|
-
`./${packageConfig.main}/index.json`,
|
|
8002
|
-
`./${packageConfig.main}/index.node`
|
|
8003
|
-
];
|
|
8004
|
-
let i2 = -1;
|
|
8005
|
-
while (++i2 < tries2.length) {
|
|
8006
|
-
guess = new URL$1(tries2[i2], packageJsonUrl);
|
|
8007
|
-
if (fileExists(guess)) break;
|
|
8008
|
-
guess = void 0;
|
|
7560
|
+
if (typeof target2 === "object" && target2 !== null) {
|
|
7561
|
+
const keys = Object.getOwnPropertyNames(target2);
|
|
7562
|
+
let i = -1;
|
|
7563
|
+
while (++i < keys.length) {
|
|
7564
|
+
const key = keys[i];
|
|
7565
|
+
if (isArrayIndex(key)) {
|
|
7566
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
7567
|
+
fileURLToPath$1(packageJsonUrl),
|
|
7568
|
+
base,
|
|
7569
|
+
'"exports" cannot contain numeric property keys.'
|
|
7570
|
+
);
|
|
7571
|
+
}
|
|
8009
7572
|
}
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
7573
|
+
i = -1;
|
|
7574
|
+
while (++i < keys.length) {
|
|
7575
|
+
const key = keys[i];
|
|
7576
|
+
if (key === "default" || conditions && conditions.has(key)) {
|
|
7577
|
+
const conditionalTarget = (
|
|
7578
|
+
/** @type {unknown} */
|
|
7579
|
+
target2[key]
|
|
7580
|
+
);
|
|
7581
|
+
const resolveResult = resolvePackageTarget(
|
|
7582
|
+
packageJsonUrl,
|
|
7583
|
+
conditionalTarget,
|
|
7584
|
+
subpath,
|
|
7585
|
+
packageSubpath,
|
|
7586
|
+
base,
|
|
7587
|
+
pattern,
|
|
7588
|
+
internal,
|
|
7589
|
+
isPathMap,
|
|
7590
|
+
conditions
|
|
7591
|
+
);
|
|
7592
|
+
if (resolveResult === void 0) continue;
|
|
7593
|
+
return resolveResult;
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
7596
|
+
return null;
|
|
7597
|
+
}
|
|
7598
|
+
if (target2 === null) {
|
|
7599
|
+
return null;
|
|
7600
|
+
}
|
|
7601
|
+
throw invalidPackageTarget(
|
|
7602
|
+
packageSubpath,
|
|
7603
|
+
target2,
|
|
7604
|
+
packageJsonUrl,
|
|
7605
|
+
internal,
|
|
7606
|
+
base
|
|
7607
|
+
);
|
|
7608
|
+
}
|
|
7609
|
+
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
7610
|
+
if (typeof exports === "string" || Array.isArray(exports)) return true;
|
|
7611
|
+
if (typeof exports !== "object" || exports === null) return false;
|
|
7612
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
7613
|
+
let isConditionalSugar = false;
|
|
7614
|
+
let i = 0;
|
|
7615
|
+
let keyIndex = -1;
|
|
7616
|
+
while (++keyIndex < keys.length) {
|
|
7617
|
+
const key = keys[keyIndex];
|
|
7618
|
+
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
7619
|
+
if (i++ === 0) {
|
|
7620
|
+
isConditionalSugar = currentIsConditionalSugar;
|
|
7621
|
+
} else if (isConditionalSugar !== currentIsConditionalSugar) {
|
|
7622
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
7623
|
+
fileURLToPath$1(packageJsonUrl),
|
|
8014
7624
|
base,
|
|
8015
|
-
|
|
7625
|
+
`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`
|
|
8016
7626
|
);
|
|
8017
|
-
return guess;
|
|
8018
7627
|
}
|
|
8019
7628
|
}
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
guess = void 0;
|
|
8026
|
-
}
|
|
8027
|
-
if (guess) {
|
|
8028
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
8029
|
-
return guess;
|
|
7629
|
+
return isConditionalSugar;
|
|
7630
|
+
}
|
|
7631
|
+
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
7632
|
+
if (process$1.noDeprecation) {
|
|
7633
|
+
return;
|
|
8030
7634
|
}
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
7635
|
+
const pjsonPath = fileURLToPath$1(pjsonUrl);
|
|
7636
|
+
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
7637
|
+
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
7638
|
+
process$1.emitWarning(
|
|
7639
|
+
`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`,
|
|
7640
|
+
"DeprecationWarning",
|
|
7641
|
+
"DEP0155"
|
|
8034
7642
|
);
|
|
8035
7643
|
}
|
|
8036
|
-
function
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
'must not include encoded "/" or "\\" characters',
|
|
8041
|
-
fileURLToPath$1(base)
|
|
8042
|
-
);
|
|
7644
|
+
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
7645
|
+
let exports = packageConfig.exports;
|
|
7646
|
+
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
|
|
7647
|
+
exports = { ".": exports };
|
|
8043
7648
|
}
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
7649
|
+
if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
7650
|
+
const target2 = exports[packageSubpath];
|
|
7651
|
+
const resolveResult = resolvePackageTarget(
|
|
7652
|
+
packageJsonUrl,
|
|
7653
|
+
target2,
|
|
7654
|
+
"",
|
|
7655
|
+
packageSubpath,
|
|
7656
|
+
base,
|
|
7657
|
+
false,
|
|
7658
|
+
false,
|
|
7659
|
+
false,
|
|
7660
|
+
conditions
|
|
8051
7661
|
);
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
7662
|
+
if (resolveResult === null || resolveResult === void 0) {
|
|
7663
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
7664
|
+
}
|
|
7665
|
+
return resolveResult;
|
|
8055
7666
|
}
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
);
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
7667
|
+
let bestMatch = "";
|
|
7668
|
+
let bestMatchSubpath = "";
|
|
7669
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
7670
|
+
let i = -1;
|
|
7671
|
+
while (++i < keys.length) {
|
|
7672
|
+
const key = keys[i];
|
|
7673
|
+
const patternIndex = key.indexOf("*");
|
|
7674
|
+
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
7675
|
+
if (packageSubpath.endsWith("/")) {
|
|
7676
|
+
emitTrailingSlashPatternDeprecation(
|
|
7677
|
+
packageSubpath,
|
|
7678
|
+
packageJsonUrl,
|
|
7679
|
+
base
|
|
7680
|
+
);
|
|
7681
|
+
}
|
|
7682
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
7683
|
+
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
7684
|
+
bestMatch = key;
|
|
7685
|
+
bestMatchSubpath = packageSubpath.slice(
|
|
7686
|
+
patternIndex,
|
|
7687
|
+
packageSubpath.length - patternTrailer.length
|
|
7688
|
+
);
|
|
7689
|
+
}
|
|
7690
|
+
}
|
|
8063
7691
|
}
|
|
8064
|
-
if (
|
|
8065
|
-
const
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
true
|
|
7692
|
+
if (bestMatch) {
|
|
7693
|
+
const target2 = (
|
|
7694
|
+
/** @type {unknown} */
|
|
7695
|
+
exports[bestMatch]
|
|
8069
7696
|
);
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
7697
|
+
const resolveResult = resolvePackageTarget(
|
|
7698
|
+
packageJsonUrl,
|
|
7699
|
+
target2,
|
|
7700
|
+
bestMatchSubpath,
|
|
7701
|
+
bestMatch,
|
|
7702
|
+
base,
|
|
7703
|
+
true,
|
|
7704
|
+
false,
|
|
7705
|
+
packageSubpath.endsWith("/"),
|
|
7706
|
+
conditions
|
|
7707
|
+
);
|
|
7708
|
+
if (resolveResult === null || resolveResult === void 0) {
|
|
7709
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
7710
|
+
}
|
|
7711
|
+
return resolveResult;
|
|
8079
7712
|
}
|
|
8080
|
-
|
|
8081
|
-
}
|
|
8082
|
-
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
8083
|
-
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
8084
|
-
specifier,
|
|
8085
|
-
packageJsonUrl && fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
8086
|
-
fileURLToPath$1(base)
|
|
8087
|
-
);
|
|
8088
|
-
}
|
|
8089
|
-
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
8090
|
-
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
8091
|
-
fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
8092
|
-
subpath,
|
|
8093
|
-
base && fileURLToPath$1(base)
|
|
8094
|
-
);
|
|
8095
|
-
}
|
|
8096
|
-
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
8097
|
-
const reason = `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath$1(packageJsonUrl)}`;
|
|
8098
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
8099
|
-
request,
|
|
8100
|
-
reason,
|
|
8101
|
-
base && fileURLToPath$1(base)
|
|
8102
|
-
);
|
|
7713
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
8103
7714
|
}
|
|
8104
|
-
function
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
);
|
|
7715
|
+
function patternKeyCompare(a, b) {
|
|
7716
|
+
const aPatternIndex = a.indexOf("*");
|
|
7717
|
+
const bPatternIndex = b.indexOf("*");
|
|
7718
|
+
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
7719
|
+
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
7720
|
+
if (baseLengthA > baseLengthB) return -1;
|
|
7721
|
+
if (baseLengthB > baseLengthA) return 1;
|
|
7722
|
+
if (aPatternIndex === -1) return 1;
|
|
7723
|
+
if (bPatternIndex === -1) return -1;
|
|
7724
|
+
if (a.length > b.length) return -1;
|
|
7725
|
+
if (b.length > a.length) return 1;
|
|
7726
|
+
return 0;
|
|
8113
7727
|
}
|
|
8114
|
-
function
|
|
8115
|
-
if (
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
8119
|
-
let isURL = false;
|
|
8120
|
-
try {
|
|
8121
|
-
new URL$1(target);
|
|
8122
|
-
isURL = true;
|
|
8123
|
-
} catch {
|
|
8124
|
-
}
|
|
8125
|
-
if (!isURL) {
|
|
8126
|
-
const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
8127
|
-
patternRegEx,
|
|
8128
|
-
target,
|
|
8129
|
-
() => subpath
|
|
8130
|
-
) : target + subpath;
|
|
8131
|
-
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
8132
|
-
}
|
|
8133
|
-
}
|
|
8134
|
-
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
7728
|
+
function packageImportsResolve(name, base, conditions) {
|
|
7729
|
+
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) {
|
|
7730
|
+
const reason = "is not a valid internal imports specifier name";
|
|
7731
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath$1(base));
|
|
8135
7732
|
}
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
) : target;
|
|
8145
|
-
emitInvalidSegmentDeprecation(
|
|
8146
|
-
resolvedTarget,
|
|
8147
|
-
request,
|
|
8148
|
-
match,
|
|
7733
|
+
let packageJsonUrl;
|
|
7734
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
7735
|
+
if (packageConfig.exists) {
|
|
7736
|
+
packageJsonUrl = pathToFileURL$1(packageConfig.pjsonPath);
|
|
7737
|
+
const imports = packageConfig.imports;
|
|
7738
|
+
if (imports) {
|
|
7739
|
+
if (own.call(imports, name) && !name.includes("*")) {
|
|
7740
|
+
const resolveResult = resolvePackageTarget(
|
|
8149
7741
|
packageJsonUrl,
|
|
8150
|
-
|
|
7742
|
+
imports[name],
|
|
7743
|
+
"",
|
|
7744
|
+
name,
|
|
8151
7745
|
base,
|
|
8152
|
-
|
|
7746
|
+
false,
|
|
7747
|
+
true,
|
|
7748
|
+
false,
|
|
7749
|
+
conditions
|
|
8153
7750
|
);
|
|
7751
|
+
if (resolveResult !== null && resolveResult !== void 0) {
|
|
7752
|
+
return resolveResult;
|
|
7753
|
+
}
|
|
7754
|
+
} else {
|
|
7755
|
+
let bestMatch = "";
|
|
7756
|
+
let bestMatchSubpath = "";
|
|
7757
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
7758
|
+
let i = -1;
|
|
7759
|
+
while (++i < keys.length) {
|
|
7760
|
+
const key = keys[i];
|
|
7761
|
+
const patternIndex = key.indexOf("*");
|
|
7762
|
+
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
7763
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
7764
|
+
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
7765
|
+
bestMatch = key;
|
|
7766
|
+
bestMatchSubpath = name.slice(
|
|
7767
|
+
patternIndex,
|
|
7768
|
+
name.length - patternTrailer.length
|
|
7769
|
+
);
|
|
7770
|
+
}
|
|
7771
|
+
}
|
|
7772
|
+
}
|
|
7773
|
+
if (bestMatch) {
|
|
7774
|
+
const target2 = imports[bestMatch];
|
|
7775
|
+
const resolveResult = resolvePackageTarget(
|
|
7776
|
+
packageJsonUrl,
|
|
7777
|
+
target2,
|
|
7778
|
+
bestMatchSubpath,
|
|
7779
|
+
bestMatch,
|
|
7780
|
+
base,
|
|
7781
|
+
true,
|
|
7782
|
+
true,
|
|
7783
|
+
false,
|
|
7784
|
+
conditions
|
|
7785
|
+
);
|
|
7786
|
+
if (resolveResult !== null && resolveResult !== void 0) {
|
|
7787
|
+
return resolveResult;
|
|
7788
|
+
}
|
|
7789
|
+
}
|
|
8154
7790
|
}
|
|
8155
|
-
} else {
|
|
8156
|
-
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8157
7791
|
}
|
|
8158
7792
|
}
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
if (
|
|
8166
|
-
|
|
8167
|
-
if (
|
|
8168
|
-
|
|
8169
|
-
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
8170
|
-
patternRegEx,
|
|
8171
|
-
target,
|
|
8172
|
-
() => subpath
|
|
8173
|
-
) : target;
|
|
8174
|
-
emitInvalidSegmentDeprecation(
|
|
8175
|
-
resolvedTarget,
|
|
8176
|
-
request,
|
|
8177
|
-
match,
|
|
8178
|
-
packageJsonUrl,
|
|
8179
|
-
internal,
|
|
8180
|
-
base,
|
|
8181
|
-
false
|
|
8182
|
-
);
|
|
8183
|
-
}
|
|
7793
|
+
throw importNotDefined(name, packageJsonUrl, base);
|
|
7794
|
+
}
|
|
7795
|
+
function parsePackageName(specifier, base) {
|
|
7796
|
+
let separatorIndex = specifier.indexOf("/");
|
|
7797
|
+
let validPackageName = true;
|
|
7798
|
+
let isScoped = false;
|
|
7799
|
+
if (specifier[0] === "@") {
|
|
7800
|
+
isScoped = true;
|
|
7801
|
+
if (separatorIndex === -1 || specifier.length === 0) {
|
|
7802
|
+
validPackageName = false;
|
|
8184
7803
|
} else {
|
|
8185
|
-
|
|
7804
|
+
separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
8186
7805
|
}
|
|
8187
7806
|
}
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
7807
|
+
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
7808
|
+
if (invalidPackageNameRegEx.exec(packageName) !== null) {
|
|
7809
|
+
validPackageName = false;
|
|
7810
|
+
}
|
|
7811
|
+
if (!validPackageName) {
|
|
7812
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
7813
|
+
specifier,
|
|
7814
|
+
"is not a valid package name",
|
|
7815
|
+
fileURLToPath$1(base)
|
|
8195
7816
|
);
|
|
8196
7817
|
}
|
|
8197
|
-
|
|
8198
|
-
}
|
|
8199
|
-
function isArrayIndex(key) {
|
|
8200
|
-
const keyNumber = Number(key);
|
|
8201
|
-
if (`${keyNumber}` !== key) return false;
|
|
8202
|
-
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
7818
|
+
const packageSubpath = "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex));
|
|
7819
|
+
return { packageName, packageSubpath, isScoped };
|
|
8203
7820
|
}
|
|
8204
|
-
function
|
|
8205
|
-
if (
|
|
8206
|
-
return
|
|
8207
|
-
target,
|
|
8208
|
-
subpath,
|
|
8209
|
-
packageSubpath,
|
|
8210
|
-
packageJsonUrl,
|
|
8211
|
-
base,
|
|
8212
|
-
pattern,
|
|
8213
|
-
internal,
|
|
8214
|
-
isPathMap,
|
|
8215
|
-
conditions
|
|
8216
|
-
);
|
|
7821
|
+
function packageResolve(specifier, base, conditions) {
|
|
7822
|
+
if (builtinModules.includes(specifier)) {
|
|
7823
|
+
return new URL$1("node:" + specifier);
|
|
8217
7824
|
}
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
pattern,
|
|
8234
|
-
internal,
|
|
8235
|
-
isPathMap,
|
|
8236
|
-
conditions
|
|
8237
|
-
);
|
|
8238
|
-
} catch (error) {
|
|
8239
|
-
const exception = (
|
|
8240
|
-
/** @type {ErrnoException} */
|
|
8241
|
-
error
|
|
8242
|
-
);
|
|
8243
|
-
lastException = exception;
|
|
8244
|
-
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
8245
|
-
throw error;
|
|
8246
|
-
}
|
|
8247
|
-
if (resolveResult === void 0) continue;
|
|
8248
|
-
if (resolveResult === null) {
|
|
8249
|
-
lastException = null;
|
|
8250
|
-
continue;
|
|
8251
|
-
}
|
|
8252
|
-
return resolveResult;
|
|
7825
|
+
const { packageName, packageSubpath, isScoped } = parsePackageName(
|
|
7826
|
+
specifier,
|
|
7827
|
+
base
|
|
7828
|
+
);
|
|
7829
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
7830
|
+
if (packageConfig.exists) {
|
|
7831
|
+
const packageJsonUrl2 = pathToFileURL$1(packageConfig.pjsonPath);
|
|
7832
|
+
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
|
|
7833
|
+
return packageExportsResolve(
|
|
7834
|
+
packageJsonUrl2,
|
|
7835
|
+
packageSubpath,
|
|
7836
|
+
packageConfig,
|
|
7837
|
+
base,
|
|
7838
|
+
conditions
|
|
7839
|
+
);
|
|
8253
7840
|
}
|
|
8254
|
-
|
|
8255
|
-
|
|
7841
|
+
}
|
|
7842
|
+
let packageJsonUrl = new URL$1(
|
|
7843
|
+
"./node_modules/" + packageName + "/package.json",
|
|
7844
|
+
base
|
|
7845
|
+
);
|
|
7846
|
+
let packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
7847
|
+
let lastPath;
|
|
7848
|
+
do {
|
|
7849
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
7850
|
+
if (!stat || !stat.isDirectory()) {
|
|
7851
|
+
lastPath = packageJsonPath;
|
|
7852
|
+
packageJsonUrl = new URL$1(
|
|
7853
|
+
(isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
|
|
7854
|
+
packageJsonUrl
|
|
7855
|
+
);
|
|
7856
|
+
packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
7857
|
+
continue;
|
|
7858
|
+
}
|
|
7859
|
+
const packageConfig2 = read(packageJsonPath, { base, specifier });
|
|
7860
|
+
if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
|
|
7861
|
+
return packageExportsResolve(
|
|
7862
|
+
packageJsonUrl,
|
|
7863
|
+
packageSubpath,
|
|
7864
|
+
packageConfig2,
|
|
7865
|
+
base,
|
|
7866
|
+
conditions
|
|
7867
|
+
);
|
|
7868
|
+
}
|
|
7869
|
+
if (packageSubpath === ".") {
|
|
7870
|
+
return legacyMainResolve(packageJsonUrl, packageConfig2, base);
|
|
7871
|
+
}
|
|
7872
|
+
return new URL$1(packageSubpath, packageJsonUrl);
|
|
7873
|
+
} while (packageJsonPath.length !== lastPath.length);
|
|
7874
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath$1(base), false);
|
|
7875
|
+
}
|
|
7876
|
+
function isRelativeSpecifier(specifier) {
|
|
7877
|
+
if (specifier[0] === ".") {
|
|
7878
|
+
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
7879
|
+
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) {
|
|
7880
|
+
return true;
|
|
8256
7881
|
}
|
|
8257
|
-
throw lastException;
|
|
8258
7882
|
}
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
7883
|
+
return false;
|
|
7884
|
+
}
|
|
7885
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
7886
|
+
if (specifier === "") return false;
|
|
7887
|
+
if (specifier[0] === "/") return true;
|
|
7888
|
+
return isRelativeSpecifier(specifier);
|
|
7889
|
+
}
|
|
7890
|
+
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
7891
|
+
const protocol = base.protocol;
|
|
7892
|
+
const isData = protocol === "data:";
|
|
7893
|
+
const isRemote = isData || protocol === "http:" || protocol === "https:";
|
|
7894
|
+
let resolved;
|
|
7895
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
7896
|
+
try {
|
|
7897
|
+
resolved = new URL$1(specifier, base);
|
|
7898
|
+
} catch (error_) {
|
|
7899
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
7900
|
+
error.cause = error_;
|
|
7901
|
+
throw error;
|
|
8271
7902
|
}
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
);
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
conditionalTarget,
|
|
8283
|
-
subpath,
|
|
8284
|
-
packageSubpath,
|
|
8285
|
-
base,
|
|
8286
|
-
pattern,
|
|
8287
|
-
internal,
|
|
8288
|
-
isPathMap,
|
|
8289
|
-
conditions
|
|
8290
|
-
);
|
|
8291
|
-
if (resolveResult === void 0) continue;
|
|
8292
|
-
return resolveResult;
|
|
7903
|
+
} else if (protocol === "file:" && specifier[0] === "#") {
|
|
7904
|
+
resolved = packageImportsResolve(specifier, base, conditions);
|
|
7905
|
+
} else {
|
|
7906
|
+
try {
|
|
7907
|
+
resolved = new URL$1(specifier);
|
|
7908
|
+
} catch (error_) {
|
|
7909
|
+
if (isRemote && !builtinModules.includes(specifier)) {
|
|
7910
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
7911
|
+
error.cause = error_;
|
|
7912
|
+
throw error;
|
|
8293
7913
|
}
|
|
7914
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
7917
|
+
assert(resolved !== void 0, "expected to be defined");
|
|
7918
|
+
if (resolved.protocol !== "file:") {
|
|
7919
|
+
return resolved;
|
|
7920
|
+
}
|
|
7921
|
+
return finalizeResolution(resolved, base);
|
|
7922
|
+
}
|
|
7923
|
+
function fileURLToPath(id) {
|
|
7924
|
+
if (typeof id === "string" && !id.startsWith("file://")) {
|
|
7925
|
+
return normalizeSlash(id);
|
|
7926
|
+
}
|
|
7927
|
+
return normalizeSlash(fileURLToPath$1(id));
|
|
7928
|
+
}
|
|
7929
|
+
function pathToFileURL(id) {
|
|
7930
|
+
return pathToFileURL$1(fileURLToPath(id)).toString();
|
|
7931
|
+
}
|
|
7932
|
+
function normalizeid(id) {
|
|
7933
|
+
if (typeof id !== "string") {
|
|
7934
|
+
id = id.toString();
|
|
7935
|
+
}
|
|
7936
|
+
if (/(node|data|http|https|file):/.test(id)) {
|
|
7937
|
+
return id;
|
|
7938
|
+
}
|
|
7939
|
+
if (BUILTIN_MODULES.has(id)) {
|
|
7940
|
+
return "node:" + id;
|
|
7941
|
+
}
|
|
7942
|
+
return "file://" + encodeURI(normalizeSlash(id));
|
|
7943
|
+
}
|
|
7944
|
+
var DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
|
|
7945
|
+
var DEFAULT_EXTENSIONS = [".mjs", ".cjs", ".js", ".json"];
|
|
7946
|
+
var NOT_FOUND_ERRORS = /* @__PURE__ */ new Set([
|
|
7947
|
+
"ERR_MODULE_NOT_FOUND",
|
|
7948
|
+
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
7949
|
+
"MODULE_NOT_FOUND",
|
|
7950
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED"
|
|
7951
|
+
]);
|
|
7952
|
+
function _tryModuleResolve(id, url, conditions) {
|
|
7953
|
+
try {
|
|
7954
|
+
return moduleResolve(id, url, conditions);
|
|
7955
|
+
} catch (error) {
|
|
7956
|
+
if (!NOT_FOUND_ERRORS.has(error?.code)) {
|
|
7957
|
+
throw error;
|
|
8294
7958
|
}
|
|
8295
|
-
return null;
|
|
8296
|
-
}
|
|
8297
|
-
if (target === null) {
|
|
8298
|
-
return null;
|
|
8299
7959
|
}
|
|
8300
|
-
throw invalidPackageTarget(
|
|
8301
|
-
packageSubpath,
|
|
8302
|
-
target,
|
|
8303
|
-
packageJsonUrl,
|
|
8304
|
-
internal,
|
|
8305
|
-
base
|
|
8306
|
-
);
|
|
8307
7960
|
}
|
|
8308
|
-
function
|
|
8309
|
-
if (typeof
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
let keyIndex = -1;
|
|
8315
|
-
while (++keyIndex < keys.length) {
|
|
8316
|
-
const key = keys[keyIndex];
|
|
8317
|
-
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
8318
|
-
if (i++ === 0) {
|
|
8319
|
-
isConditionalSugar = currentIsConditionalSugar;
|
|
8320
|
-
} else if (isConditionalSugar !== currentIsConditionalSugar) {
|
|
8321
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
8322
|
-
fileURLToPath$1(packageJsonUrl),
|
|
8323
|
-
base,
|
|
8324
|
-
`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`
|
|
8325
|
-
);
|
|
7961
|
+
function _resolve(id, options = {}) {
|
|
7962
|
+
if (typeof id !== "string") {
|
|
7963
|
+
if (id instanceof URL) {
|
|
7964
|
+
id = fileURLToPath(id);
|
|
7965
|
+
} else {
|
|
7966
|
+
throw new TypeError("input must be a `string` or `URL`");
|
|
8326
7967
|
}
|
|
8327
7968
|
}
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
8331
|
-
if (process$1.noDeprecation) {
|
|
8332
|
-
return;
|
|
7969
|
+
if (/(node|data|http|https):/.test(id)) {
|
|
7970
|
+
return id;
|
|
8333
7971
|
}
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
8337
|
-
process$1.emitWarning(
|
|
8338
|
-
`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`,
|
|
8339
|
-
"DeprecationWarning",
|
|
8340
|
-
"DEP0155"
|
|
8341
|
-
);
|
|
8342
|
-
}
|
|
8343
|
-
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
8344
|
-
let exports = packageConfig.exports;
|
|
8345
|
-
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
|
|
8346
|
-
exports = { ".": exports };
|
|
7972
|
+
if (BUILTIN_MODULES.has(id)) {
|
|
7973
|
+
return "node:" + id;
|
|
8347
7974
|
}
|
|
8348
|
-
if (
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
if (resolveResult === null || resolveResult === void 0) {
|
|
8362
|
-
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
7975
|
+
if (id.startsWith("file://")) {
|
|
7976
|
+
id = fileURLToPath(id);
|
|
7977
|
+
}
|
|
7978
|
+
if (isAbsolute(id)) {
|
|
7979
|
+
try {
|
|
7980
|
+
const stat = statSync(id);
|
|
7981
|
+
if (stat.isFile()) {
|
|
7982
|
+
return pathToFileURL(id);
|
|
7983
|
+
}
|
|
7984
|
+
} catch (error) {
|
|
7985
|
+
if (error?.code !== "ENOENT") {
|
|
7986
|
+
throw error;
|
|
7987
|
+
}
|
|
8363
7988
|
}
|
|
8364
|
-
return resolveResult;
|
|
8365
7989
|
}
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
if (
|
|
8374
|
-
|
|
8375
|
-
|
|
8376
|
-
|
|
8377
|
-
|
|
8378
|
-
|
|
7990
|
+
const conditionsSet = options.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
|
|
7991
|
+
const _urls = (Array.isArray(options.url) ? options.url : [options.url]).filter(Boolean).map((url) => new URL(normalizeid(url.toString())));
|
|
7992
|
+
if (_urls.length === 0) {
|
|
7993
|
+
_urls.push(new URL(pathToFileURL(process.cwd())));
|
|
7994
|
+
}
|
|
7995
|
+
const urls = [..._urls];
|
|
7996
|
+
for (const url of _urls) {
|
|
7997
|
+
if (url.protocol === "file:") {
|
|
7998
|
+
urls.push(
|
|
7999
|
+
new URL("./", url),
|
|
8000
|
+
// If url is directory
|
|
8001
|
+
new URL(joinURL(url.pathname, "_index.js"), url),
|
|
8002
|
+
// TODO: Remove in next major version?
|
|
8003
|
+
new URL("node_modules", url)
|
|
8004
|
+
);
|
|
8005
|
+
}
|
|
8006
|
+
}
|
|
8007
|
+
let resolved;
|
|
8008
|
+
for (const url of urls) {
|
|
8009
|
+
resolved = _tryModuleResolve(id, url, conditionsSet);
|
|
8010
|
+
if (resolved) {
|
|
8011
|
+
break;
|
|
8012
|
+
}
|
|
8013
|
+
for (const prefix of ["", "/index"]) {
|
|
8014
|
+
for (const extension of options.extensions || DEFAULT_EXTENSIONS) {
|
|
8015
|
+
resolved = _tryModuleResolve(
|
|
8016
|
+
joinURL(id, prefix) + extension,
|
|
8017
|
+
url,
|
|
8018
|
+
conditionsSet
|
|
8379
8019
|
);
|
|
8020
|
+
if (resolved) {
|
|
8021
|
+
break;
|
|
8022
|
+
}
|
|
8380
8023
|
}
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
bestMatch = key;
|
|
8384
|
-
bestMatchSubpath = packageSubpath.slice(
|
|
8385
|
-
patternIndex,
|
|
8386
|
-
packageSubpath.length - patternTrailer.length
|
|
8387
|
-
);
|
|
8024
|
+
if (resolved) {
|
|
8025
|
+
break;
|
|
8388
8026
|
}
|
|
8389
8027
|
}
|
|
8028
|
+
if (resolved) {
|
|
8029
|
+
break;
|
|
8030
|
+
}
|
|
8390
8031
|
}
|
|
8391
|
-
if (
|
|
8392
|
-
const
|
|
8393
|
-
|
|
8394
|
-
exports[bestMatch]
|
|
8032
|
+
if (!resolved) {
|
|
8033
|
+
const error = new Error(
|
|
8034
|
+
`Cannot find module ${id} imported from ${urls.join(", ")}`
|
|
8395
8035
|
);
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8036
|
+
error.code = "ERR_MODULE_NOT_FOUND";
|
|
8037
|
+
throw error;
|
|
8038
|
+
}
|
|
8039
|
+
return pathToFileURL(resolved);
|
|
8040
|
+
}
|
|
8041
|
+
function resolveSync(id, options) {
|
|
8042
|
+
return _resolve(id, options);
|
|
8043
|
+
}
|
|
8044
|
+
function resolvePathSync(id, options) {
|
|
8045
|
+
return fileURLToPath(resolveSync(id, options));
|
|
8046
|
+
}
|
|
8047
|
+
|
|
8048
|
+
// src/node-js-compat.ts
|
|
8049
|
+
import { defineEnv } from "unenv";
|
|
8050
|
+
var { env } = defineEnv({
|
|
8051
|
+
nodeCompat: true,
|
|
8052
|
+
presets: [cloudflare]
|
|
8053
|
+
});
|
|
8054
|
+
var nodeCompatExternals = new Set(env.external);
|
|
8055
|
+
var nodeCompatEntries = getNodeCompatEntries();
|
|
8056
|
+
function isNodeCompat(workerConfig) {
|
|
8057
|
+
if (workerConfig === void 0) {
|
|
8058
|
+
return false;
|
|
8059
|
+
}
|
|
8060
|
+
const nodeCompatMode = getNodeCompat(
|
|
8061
|
+
workerConfig.compatibility_date,
|
|
8062
|
+
workerConfig.compatibility_flags ?? []
|
|
8063
|
+
).mode;
|
|
8064
|
+
if (nodeCompatMode === "v2") {
|
|
8065
|
+
return true;
|
|
8066
|
+
}
|
|
8067
|
+
if (nodeCompatMode === "v1") {
|
|
8068
|
+
throw new Error(
|
|
8069
|
+
`Unsupported Node.js compat mode (v1). Only the v2 mode is supported, either change your compat date to "2024-09-23" or later, or set the "nodejs_compat_v2" compatibility flag`
|
|
8406
8070
|
);
|
|
8407
|
-
|
|
8408
|
-
|
|
8071
|
+
}
|
|
8072
|
+
return false;
|
|
8073
|
+
}
|
|
8074
|
+
function injectGlobalCode(id, code) {
|
|
8075
|
+
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
8076
|
+
if (typeof globalInject === "string") {
|
|
8077
|
+
const moduleSpecifier2 = globalInject;
|
|
8078
|
+
return `import var_${globalName} from "${moduleSpecifier2}";
|
|
8079
|
+
globalThis.${globalName} = var_${globalName};
|
|
8080
|
+
`;
|
|
8409
8081
|
}
|
|
8410
|
-
|
|
8082
|
+
const [moduleSpecifier, exportName] = globalInject;
|
|
8083
|
+
assert2(
|
|
8084
|
+
moduleSpecifier !== void 0,
|
|
8085
|
+
"Expected moduleSpecifier to be defined"
|
|
8086
|
+
);
|
|
8087
|
+
assert2(exportName !== void 0, "Expected exportName to be defined");
|
|
8088
|
+
return `import var_${globalName} from "${moduleSpecifier}";
|
|
8089
|
+
globalThis.${globalName} = var_${globalName}.${exportName};
|
|
8090
|
+
`;
|
|
8091
|
+
}).join("\n");
|
|
8092
|
+
const polyfillCode = env.polyfill.map((polyfillPath) => `import "${polyfillPath}";
|
|
8093
|
+
`).join("");
|
|
8094
|
+
const modified = new MagicString(code);
|
|
8095
|
+
modified.prepend(injectedCode);
|
|
8096
|
+
modified.prepend(polyfillCode);
|
|
8097
|
+
return {
|
|
8098
|
+
code: modified.toString(),
|
|
8099
|
+
map: modified.generateMap({ hires: "boundary", source: id })
|
|
8100
|
+
};
|
|
8101
|
+
}
|
|
8102
|
+
function resolveNodeJSImport(source) {
|
|
8103
|
+
const alias = env.alias[source];
|
|
8104
|
+
if (alias) {
|
|
8105
|
+
return {
|
|
8106
|
+
unresolved: alias,
|
|
8107
|
+
resolved: resolvePathSync(alias, { url: import.meta.url })
|
|
8108
|
+
};
|
|
8411
8109
|
}
|
|
8412
|
-
|
|
8110
|
+
if (nodeCompatEntries.has(source)) {
|
|
8111
|
+
return {
|
|
8112
|
+
unresolved: source,
|
|
8113
|
+
resolved: resolvePathSync(source, { url: import.meta.url })
|
|
8114
|
+
};
|
|
8115
|
+
}
|
|
8116
|
+
}
|
|
8117
|
+
function getNodeCompatEntries() {
|
|
8118
|
+
const entries = new Set(Object.values(env.alias));
|
|
8119
|
+
for (const globalInject of Object.values(env.inject)) {
|
|
8120
|
+
if (typeof globalInject === "string") {
|
|
8121
|
+
entries.add(globalInject);
|
|
8122
|
+
} else {
|
|
8123
|
+
assert2(
|
|
8124
|
+
globalInject[0] !== void 0,
|
|
8125
|
+
"Expected first element of globalInject to be defined"
|
|
8126
|
+
);
|
|
8127
|
+
entries.add(globalInject[0]);
|
|
8128
|
+
}
|
|
8129
|
+
}
|
|
8130
|
+
env.polyfill.forEach((polyfill) => entries.add(polyfill));
|
|
8131
|
+
nodeCompatExternals.forEach((external) => entries.delete(external));
|
|
8132
|
+
return entries;
|
|
8133
|
+
}
|
|
8134
|
+
|
|
8135
|
+
// src/shared.ts
|
|
8136
|
+
var UNKNOWN_HOST = "http://localhost";
|
|
8137
|
+
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
8138
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__`;
|
|
8139
|
+
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
8140
|
+
var additionalModuleGlobalRE = new RegExp(
|
|
8141
|
+
ADDITIONAL_MODULE_PATTERN,
|
|
8142
|
+
"g"
|
|
8143
|
+
);
|
|
8144
|
+
var VITE_DEV_METADATA_HEADER = "__VITE_DEV_METADATA__";
|
|
8145
|
+
|
|
8146
|
+
// src/utils.ts
|
|
8147
|
+
import * as path2 from "node:path";
|
|
8148
|
+
import { Request as MiniflareRequest } from "miniflare";
|
|
8149
|
+
import "vite";
|
|
8150
|
+
function getOutputDirectory(userConfig, environmentName) {
|
|
8151
|
+
const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
|
|
8152
|
+
return userConfig.environments?.[environmentName]?.build?.outDir ?? path2.join(rootOutputDirectory, environmentName);
|
|
8413
8153
|
}
|
|
8414
|
-
function
|
|
8415
|
-
|
|
8416
|
-
const bPatternIndex = b.indexOf("*");
|
|
8417
|
-
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
8418
|
-
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
8419
|
-
if (baseLengthA > baseLengthB) return -1;
|
|
8420
|
-
if (baseLengthB > baseLengthA) return 1;
|
|
8421
|
-
if (aPatternIndex === -1) return 1;
|
|
8422
|
-
if (bPatternIndex === -1) return -1;
|
|
8423
|
-
if (a.length > b.length) return -1;
|
|
8424
|
-
if (b.length > a.length) return 1;
|
|
8425
|
-
return 0;
|
|
8154
|
+
function getRouterWorker(miniflare) {
|
|
8155
|
+
return miniflare.getWorker(ROUTER_WORKER_NAME);
|
|
8426
8156
|
}
|
|
8427
|
-
function
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
name2,
|
|
8444
|
-
base,
|
|
8445
|
-
false,
|
|
8446
|
-
true,
|
|
8447
|
-
false,
|
|
8448
|
-
conditions
|
|
8449
|
-
);
|
|
8450
|
-
if (resolveResult !== null && resolveResult !== void 0) {
|
|
8451
|
-
return resolveResult;
|
|
8452
|
-
}
|
|
8453
|
-
} else {
|
|
8454
|
-
let bestMatch = "";
|
|
8455
|
-
let bestMatchSubpath = "";
|
|
8456
|
-
const keys = Object.getOwnPropertyNames(imports);
|
|
8457
|
-
let i = -1;
|
|
8458
|
-
while (++i < keys.length) {
|
|
8459
|
-
const key = keys[i];
|
|
8460
|
-
const patternIndex = key.indexOf("*");
|
|
8461
|
-
if (patternIndex !== -1 && name2.startsWith(key.slice(0, -1))) {
|
|
8462
|
-
const patternTrailer = key.slice(patternIndex + 1);
|
|
8463
|
-
if (name2.length >= key.length && name2.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
8464
|
-
bestMatch = key;
|
|
8465
|
-
bestMatchSubpath = name2.slice(
|
|
8466
|
-
patternIndex,
|
|
8467
|
-
name2.length - patternTrailer.length
|
|
8468
|
-
);
|
|
8469
|
-
}
|
|
8470
|
-
}
|
|
8471
|
-
}
|
|
8472
|
-
if (bestMatch) {
|
|
8473
|
-
const target = imports[bestMatch];
|
|
8474
|
-
const resolveResult = resolvePackageTarget(
|
|
8475
|
-
packageJsonUrl,
|
|
8476
|
-
target,
|
|
8477
|
-
bestMatchSubpath,
|
|
8478
|
-
bestMatch,
|
|
8479
|
-
base,
|
|
8480
|
-
true,
|
|
8481
|
-
true,
|
|
8482
|
-
false,
|
|
8483
|
-
conditions
|
|
8484
|
-
);
|
|
8485
|
-
if (resolveResult !== null && resolveResult !== void 0) {
|
|
8486
|
-
return resolveResult;
|
|
8487
|
-
}
|
|
8488
|
-
}
|
|
8157
|
+
function toMiniflareRequest(request) {
|
|
8158
|
+
return new MiniflareRequest(request.url, {
|
|
8159
|
+
method: request.method,
|
|
8160
|
+
headers: [["accept-encoding", "identity"], ...request.headers],
|
|
8161
|
+
body: request.body,
|
|
8162
|
+
duplex: "half"
|
|
8163
|
+
});
|
|
8164
|
+
}
|
|
8165
|
+
function nodeHeadersToWebHeaders(nodeHeaders) {
|
|
8166
|
+
const headers = new Headers();
|
|
8167
|
+
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
8168
|
+
if (typeof value === "string") {
|
|
8169
|
+
headers.append(key, value);
|
|
8170
|
+
} else if (Array.isArray(value)) {
|
|
8171
|
+
for (const item of value) {
|
|
8172
|
+
headers.append(key, item);
|
|
8489
8173
|
}
|
|
8490
8174
|
}
|
|
8491
8175
|
}
|
|
8492
|
-
|
|
8176
|
+
return headers;
|
|
8493
8177
|
}
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8503
|
-
|
|
8178
|
+
var postfixRE = /[?#].*$/;
|
|
8179
|
+
function cleanUrl(url) {
|
|
8180
|
+
return url.replace(postfixRE, "");
|
|
8181
|
+
}
|
|
8182
|
+
|
|
8183
|
+
// src/cloudflare-environment.ts
|
|
8184
|
+
var webSocketUndefinedError = "The WebSocket is undefined";
|
|
8185
|
+
function createHotChannel(webSocketContainer) {
|
|
8186
|
+
const listenersMap = /* @__PURE__ */ new Map();
|
|
8187
|
+
const client = {
|
|
8188
|
+
send(payload) {
|
|
8189
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8190
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8191
|
+
webSocket.send(JSON.stringify(payload));
|
|
8192
|
+
}
|
|
8193
|
+
};
|
|
8194
|
+
function onMessage(event) {
|
|
8195
|
+
const payload = JSON.parse(event.data.toString());
|
|
8196
|
+
const listeners = listenersMap.get(payload.event) ?? /* @__PURE__ */ new Set();
|
|
8197
|
+
for (const listener of listeners) {
|
|
8198
|
+
listener(payload.data, client);
|
|
8504
8199
|
}
|
|
8505
8200
|
}
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8201
|
+
return {
|
|
8202
|
+
send(payload) {
|
|
8203
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8204
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8205
|
+
webSocket.send(JSON.stringify(payload));
|
|
8206
|
+
},
|
|
8207
|
+
on(event, listener) {
|
|
8208
|
+
const listeners = listenersMap.get(event) ?? /* @__PURE__ */ new Set();
|
|
8209
|
+
listeners.add(listener);
|
|
8210
|
+
listenersMap.set(event, listeners);
|
|
8211
|
+
},
|
|
8212
|
+
off(event, listener) {
|
|
8213
|
+
listenersMap.get(event)?.delete(listener);
|
|
8214
|
+
},
|
|
8215
|
+
listen() {
|
|
8216
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8217
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8218
|
+
webSocket.addEventListener("message", onMessage);
|
|
8219
|
+
},
|
|
8220
|
+
close() {
|
|
8221
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8222
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8223
|
+
webSocket.removeEventListener("message", onMessage);
|
|
8224
|
+
}
|
|
8225
|
+
};
|
|
8226
|
+
}
|
|
8227
|
+
var CloudflareDevEnvironment = class extends vite2.DevEnvironment {
|
|
8228
|
+
#webSocketContainer;
|
|
8229
|
+
#worker;
|
|
8230
|
+
constructor(name, config) {
|
|
8231
|
+
const webSocketContainer = {};
|
|
8232
|
+
super(name, config, {
|
|
8233
|
+
hot: true,
|
|
8234
|
+
transport: createHotChannel(webSocketContainer)
|
|
8235
|
+
});
|
|
8236
|
+
this.#webSocketContainer = webSocketContainer;
|
|
8509
8237
|
}
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
|
|
8513
|
-
|
|
8514
|
-
|
|
8238
|
+
async initRunner(worker, root, workerConfig) {
|
|
8239
|
+
this.#worker = worker;
|
|
8240
|
+
const response = await this.#worker.fetch(
|
|
8241
|
+
new URL(INIT_PATH, UNKNOWN_HOST),
|
|
8242
|
+
{
|
|
8243
|
+
headers: {
|
|
8244
|
+
[VITE_DEV_METADATA_HEADER]: JSON.stringify({
|
|
8245
|
+
root,
|
|
8246
|
+
entryPath: workerConfig.main
|
|
8247
|
+
}),
|
|
8248
|
+
upgrade: "websocket"
|
|
8249
|
+
}
|
|
8250
|
+
}
|
|
8515
8251
|
);
|
|
8252
|
+
assert3(
|
|
8253
|
+
response.ok,
|
|
8254
|
+
`Failed to initialize module runner, error: ${await response.text()}`
|
|
8255
|
+
);
|
|
8256
|
+
const webSocket = response.webSocket;
|
|
8257
|
+
assert3(webSocket, "Failed to establish WebSocket");
|
|
8258
|
+
webSocket.accept();
|
|
8259
|
+
this.#webSocketContainer.webSocket = webSocket;
|
|
8516
8260
|
}
|
|
8517
|
-
|
|
8518
|
-
|
|
8261
|
+
};
|
|
8262
|
+
var cloudflareBuiltInModules = [
|
|
8263
|
+
"cloudflare:email",
|
|
8264
|
+
"cloudflare:sockets",
|
|
8265
|
+
"cloudflare:workers",
|
|
8266
|
+
"cloudflare:workflows"
|
|
8267
|
+
];
|
|
8268
|
+
var defaultConditions = ["workerd", "module", "browser"];
|
|
8269
|
+
var target = "es2022";
|
|
8270
|
+
function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmentName) {
|
|
8271
|
+
return {
|
|
8272
|
+
resolve: {
|
|
8273
|
+
// Note: in order for ssr pre-bundling to take effect we need to ask vite to treat all
|
|
8274
|
+
// dependencies as not external
|
|
8275
|
+
noExternal: true,
|
|
8276
|
+
// We want to use `workerd` package exports if available (e.g. for postgres).
|
|
8277
|
+
conditions: [...defaultConditions, "development|production"],
|
|
8278
|
+
// The Cloudflare ones are proper builtins in the environment
|
|
8279
|
+
builtins: [...cloudflareBuiltInModules]
|
|
8280
|
+
},
|
|
8281
|
+
dev: {
|
|
8282
|
+
createEnvironment(name, config) {
|
|
8283
|
+
return new CloudflareDevEnvironment(name, config);
|
|
8284
|
+
}
|
|
8285
|
+
},
|
|
8286
|
+
build: {
|
|
8287
|
+
createEnvironment(name, config) {
|
|
8288
|
+
return new vite2.BuildEnvironment(name, config);
|
|
8289
|
+
},
|
|
8290
|
+
target,
|
|
8291
|
+
// We need to enable `emitAssets` in order to support additional modules defined by `rules`
|
|
8292
|
+
emitAssets: true,
|
|
8293
|
+
outDir: getOutputDirectory(userConfig, environmentName),
|
|
8294
|
+
copyPublicDir: false,
|
|
8295
|
+
ssr: true,
|
|
8296
|
+
rollupOptions: {
|
|
8297
|
+
// Note: vite starts dev pre-bundling crawling from either optimizeDeps.entries or rollupOptions.input
|
|
8298
|
+
// so the input value here serves both as the build input as well as the starting point for
|
|
8299
|
+
// dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
|
|
8300
|
+
// optimizeDeps.entries in the dev config)
|
|
8301
|
+
input: workerConfig.main
|
|
8302
|
+
}
|
|
8303
|
+
},
|
|
8304
|
+
optimizeDeps: {
|
|
8305
|
+
// Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
|
|
8306
|
+
noDiscovery: false,
|
|
8307
|
+
entries: workerConfig.main,
|
|
8308
|
+
exclude: [...cloudflareBuiltInModules],
|
|
8309
|
+
esbuildOptions: {
|
|
8310
|
+
platform: "neutral",
|
|
8311
|
+
target,
|
|
8312
|
+
conditions: [...defaultConditions, "development"],
|
|
8313
|
+
resolveExtensions: [
|
|
8314
|
+
".mjs",
|
|
8315
|
+
".js",
|
|
8316
|
+
".mts",
|
|
8317
|
+
".ts",
|
|
8318
|
+
".jsx",
|
|
8319
|
+
".tsx",
|
|
8320
|
+
".json",
|
|
8321
|
+
".cjs",
|
|
8322
|
+
".cts",
|
|
8323
|
+
".ctx"
|
|
8324
|
+
]
|
|
8325
|
+
}
|
|
8326
|
+
},
|
|
8327
|
+
// if nodeCompat is enabled then let's keep the real process.env so that workerd can manipulate it
|
|
8328
|
+
keepProcessEnv: isNodeCompat(workerConfig)
|
|
8329
|
+
};
|
|
8519
8330
|
}
|
|
8520
|
-
function
|
|
8521
|
-
if (
|
|
8522
|
-
return
|
|
8523
|
-
}
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
|
|
8532
|
-
return packageExportsResolve(
|
|
8533
|
-
packageJsonUrl2,
|
|
8534
|
-
packageSubpath,
|
|
8535
|
-
packageConfig,
|
|
8536
|
-
base,
|
|
8537
|
-
conditions
|
|
8538
|
-
);
|
|
8539
|
-
}
|
|
8540
|
-
}
|
|
8541
|
-
let packageJsonUrl = new URL$1(
|
|
8542
|
-
"./node_modules/" + packageName + "/package.json",
|
|
8543
|
-
base
|
|
8331
|
+
function initRunners(resolvedPluginConfig, viteDevServer, miniflare) {
|
|
8332
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
8333
|
+
return;
|
|
8334
|
+
}
|
|
8335
|
+
return Promise.all(
|
|
8336
|
+
Object.entries(resolvedPluginConfig.workers).map(
|
|
8337
|
+
async ([environmentName, workerConfig]) => {
|
|
8338
|
+
const worker = await miniflare.getWorker(workerConfig.name);
|
|
8339
|
+
return viteDevServer.environments[environmentName].initRunner(worker, viteDevServer.config.root, workerConfig);
|
|
8340
|
+
}
|
|
8341
|
+
)
|
|
8544
8342
|
);
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8343
|
+
}
|
|
8344
|
+
|
|
8345
|
+
// src/debugging.ts
|
|
8346
|
+
import assert4 from "node:assert";
|
|
8347
|
+
import colors from "picocolors";
|
|
8348
|
+
var debuggingPath = "/__debug";
|
|
8349
|
+
function addDebugToVitePrintUrls(server) {
|
|
8350
|
+
const originalPrintUrls = server.printUrls;
|
|
8351
|
+
server.printUrls = () => {
|
|
8352
|
+
originalPrintUrls();
|
|
8353
|
+
const localUrl = server.resolvedUrls?.local[0];
|
|
8354
|
+
if (localUrl) {
|
|
8355
|
+
const { protocol, hostname, port } = new URL(localUrl);
|
|
8356
|
+
const colorDebugUrl = (url) => colors.dim(
|
|
8357
|
+
colors.yellow(
|
|
8358
|
+
url.replace(/:(\d+)\//, (_, port2) => `:${colors.bold(port2)}/`)
|
|
8359
|
+
)
|
|
8554
8360
|
);
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
}
|
|
8558
|
-
const packageConfig2 = read(packageJsonPath, { base, specifier });
|
|
8559
|
-
if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
|
|
8560
|
-
return packageExportsResolve(
|
|
8561
|
-
packageJsonUrl,
|
|
8562
|
-
packageSubpath,
|
|
8563
|
-
packageConfig2,
|
|
8564
|
-
base,
|
|
8565
|
-
conditions
|
|
8361
|
+
server.config.logger.info(
|
|
8362
|
+
` ${colors.green("\u279C")} ${colors.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${debuggingPath}`)}`
|
|
8566
8363
|
);
|
|
8567
8364
|
}
|
|
8568
|
-
|
|
8569
|
-
return legacyMainResolve(packageJsonUrl, packageConfig2, base);
|
|
8570
|
-
}
|
|
8571
|
-
return new URL$1(packageSubpath, packageJsonUrl);
|
|
8572
|
-
} while (packageJsonPath.length !== lastPath.length);
|
|
8573
|
-
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath$1(base), false);
|
|
8365
|
+
};
|
|
8574
8366
|
}
|
|
8575
|
-
function
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8367
|
+
function getDebugPathHtml(workerNames, inspectorPort) {
|
|
8368
|
+
assert4(workerNames.length >= 1, "no workers present to debug");
|
|
8369
|
+
const workerDevtoolsUrls = workerNames.map((workerName) => {
|
|
8370
|
+
const localHost = `localhost:${inspectorPort}/${workerName}`;
|
|
8371
|
+
const searchParams = new URLSearchParams({
|
|
8372
|
+
theme: "systemPreferred",
|
|
8373
|
+
debugger: "true",
|
|
8374
|
+
ws: localHost,
|
|
8375
|
+
domain: workerName
|
|
8376
|
+
});
|
|
8377
|
+
const devtoolsFrontendUrl = `https://devtools.devprod.cloudflare.dev/js_app?${searchParams}`;
|
|
8378
|
+
return devtoolsFrontendUrl;
|
|
8379
|
+
});
|
|
8380
|
+
return `
|
|
8381
|
+
<script>
|
|
8382
|
+
const workerUrls = ${JSON.stringify(workerDevtoolsUrls)};
|
|
8383
|
+
const [firstUrl, ...rest] = workerUrls;
|
|
8384
|
+
for (const workerUrl of rest) {
|
|
8385
|
+
// open new tabs for the devtools of the various workers
|
|
8386
|
+
window.open(workerUrl);
|
|
8387
|
+
}
|
|
8388
|
+
// redirect the current tab to the devtools of the first worker
|
|
8389
|
+
window.location.replace(firstUrl);
|
|
8390
|
+
</script>
|
|
8391
|
+
`;
|
|
8583
8392
|
}
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8393
|
+
|
|
8394
|
+
// src/deploy-config.ts
|
|
8395
|
+
import assert5 from "node:assert";
|
|
8396
|
+
import * as fs2 from "node:fs";
|
|
8397
|
+
import * as path3 from "node:path";
|
|
8398
|
+
import "vite";
|
|
8399
|
+
import { unstable_readConfig } from "wrangler";
|
|
8400
|
+
function getDeployConfigPath(root) {
|
|
8401
|
+
return path3.resolve(root, ".wrangler", "deploy", "config.json");
|
|
8588
8402
|
}
|
|
8589
|
-
function
|
|
8590
|
-
const
|
|
8591
|
-
const
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8598
|
-
|
|
8599
|
-
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8403
|
+
function getWorkerConfigs(root) {
|
|
8404
|
+
const deployConfigPath = getDeployConfigPath(root);
|
|
8405
|
+
const deployConfig = JSON.parse(
|
|
8406
|
+
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
8407
|
+
);
|
|
8408
|
+
return [
|
|
8409
|
+
{ configPath: deployConfig.configPath },
|
|
8410
|
+
...deployConfig.auxiliaryWorkers
|
|
8411
|
+
].map(({ configPath }) => {
|
|
8412
|
+
const resolvedConfigPath = path3.resolve(
|
|
8413
|
+
path3.dirname(deployConfigPath),
|
|
8414
|
+
configPath
|
|
8415
|
+
);
|
|
8416
|
+
return unstable_readConfig({ config: resolvedConfigPath });
|
|
8417
|
+
});
|
|
8418
|
+
}
|
|
8419
|
+
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
8420
|
+
return path3.relative(
|
|
8421
|
+
deployConfigDirectory,
|
|
8422
|
+
path3.resolve(root, outputDirectory, "wrangler.json")
|
|
8423
|
+
);
|
|
8424
|
+
}
|
|
8425
|
+
function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
8426
|
+
const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
|
|
8427
|
+
const deployConfigDirectory = path3.dirname(deployConfigPath);
|
|
8428
|
+
fs2.mkdirSync(deployConfigDirectory, { recursive: true });
|
|
8429
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
8430
|
+
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
8431
|
+
assert5(
|
|
8432
|
+
clientOutputDirectory,
|
|
8433
|
+
"Unexpected error: client environment output directory is undefined"
|
|
8434
|
+
);
|
|
8435
|
+
const deployConfig = {
|
|
8436
|
+
configPath: getRelativePathToWorkerConfig(
|
|
8437
|
+
deployConfigDirectory,
|
|
8438
|
+
resolvedViteConfig.root,
|
|
8439
|
+
clientOutputDirectory
|
|
8440
|
+
),
|
|
8441
|
+
auxiliaryWorkers: []
|
|
8442
|
+
};
|
|
8443
|
+
fs2.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
8604
8444
|
} else {
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8445
|
+
let entryWorkerConfigPath;
|
|
8446
|
+
const auxiliaryWorkers = [];
|
|
8447
|
+
for (const environmentName of Object.keys(resolvedPluginConfig.workers)) {
|
|
8448
|
+
const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
|
|
8449
|
+
assert5(
|
|
8450
|
+
outputDirectory,
|
|
8451
|
+
`Unexpected error: ${environmentName} environment output directory is undefined`
|
|
8452
|
+
);
|
|
8453
|
+
const configPath = getRelativePathToWorkerConfig(
|
|
8454
|
+
deployConfigDirectory,
|
|
8455
|
+
resolvedViteConfig.root,
|
|
8456
|
+
outputDirectory
|
|
8457
|
+
);
|
|
8458
|
+
if (environmentName === resolvedPluginConfig.entryWorkerEnvironmentName) {
|
|
8459
|
+
entryWorkerConfigPath = configPath;
|
|
8460
|
+
} else {
|
|
8461
|
+
auxiliaryWorkers.push({ configPath });
|
|
8612
8462
|
}
|
|
8613
|
-
resolved = packageResolve(specifier, base, conditions);
|
|
8614
8463
|
}
|
|
8464
|
+
assert5(
|
|
8465
|
+
entryWorkerConfigPath,
|
|
8466
|
+
`Unexpected error: entryWorkerConfigPath is undefined`
|
|
8467
|
+
);
|
|
8468
|
+
const deployConfig = {
|
|
8469
|
+
configPath: entryWorkerConfigPath,
|
|
8470
|
+
auxiliaryWorkers
|
|
8471
|
+
};
|
|
8472
|
+
fs2.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
8615
8473
|
}
|
|
8616
|
-
assert5(resolved !== void 0, "expected to be defined");
|
|
8617
|
-
if (resolved.protocol !== "file:") {
|
|
8618
|
-
return resolved;
|
|
8619
|
-
}
|
|
8620
|
-
return finalizeResolution(resolved, base);
|
|
8621
8474
|
}
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8475
|
+
|
|
8476
|
+
// src/miniflare-options.ts
|
|
8477
|
+
import assert6 from "node:assert";
|
|
8478
|
+
import * as fs3 from "node:fs";
|
|
8479
|
+
import * as fsp from "node:fs/promises";
|
|
8480
|
+
import * as path4 from "node:path";
|
|
8481
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
8482
|
+
import {
|
|
8483
|
+
kCurrentWorker,
|
|
8484
|
+
Log,
|
|
8485
|
+
LogLevel,
|
|
8486
|
+
Response as MiniflareResponse
|
|
8487
|
+
} from "miniflare";
|
|
8488
|
+
import { globSync } from "tinyglobby";
|
|
8489
|
+
import "vite";
|
|
8490
|
+
import {
|
|
8491
|
+
unstable_getMiniflareWorkerOptions
|
|
8492
|
+
} from "wrangler";
|
|
8493
|
+
function getPersistence(root, persistState) {
|
|
8494
|
+
if (persistState === false) {
|
|
8495
|
+
return {};
|
|
8625
8496
|
}
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8497
|
+
const defaultPersistPath = ".wrangler/state";
|
|
8498
|
+
const persistPath = path4.resolve(
|
|
8499
|
+
root,
|
|
8500
|
+
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
8501
|
+
"v3"
|
|
8502
|
+
);
|
|
8503
|
+
return {
|
|
8504
|
+
cachePersist: path4.join(persistPath, "cache"),
|
|
8505
|
+
d1Persist: path4.join(persistPath, "d1"),
|
|
8506
|
+
durableObjectsPersist: path4.join(persistPath, "do"),
|
|
8507
|
+
kvPersist: path4.join(persistPath, "kv"),
|
|
8508
|
+
r2Persist: path4.join(persistPath, "r2"),
|
|
8509
|
+
workflowsPersist: path4.join(persistPath, "workflows")
|
|
8510
|
+
};
|
|
8630
8511
|
}
|
|
8631
|
-
function
|
|
8632
|
-
|
|
8633
|
-
id = id.toString();
|
|
8634
|
-
}
|
|
8635
|
-
if (/(node|data|http|https|file):/.test(id)) {
|
|
8636
|
-
return id;
|
|
8637
|
-
}
|
|
8638
|
-
if (BUILTIN_MODULES.has(id)) {
|
|
8639
|
-
return "node:" + id;
|
|
8640
|
-
}
|
|
8641
|
-
return "file://" + encodeURI(normalizeSlash(id));
|
|
8512
|
+
function missingWorkerErrorMessage(workerName) {
|
|
8513
|
+
return `${workerName} does not match a worker name.`;
|
|
8642
8514
|
}
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
if (!NOT_FOUND_ERRORS.has(error?.code)) {
|
|
8656
|
-
throw error;
|
|
8515
|
+
function getWorkerToWorkerEntrypointNamesMap(workers) {
|
|
8516
|
+
const workerToWorkerEntrypointNamesMap = new Map(
|
|
8517
|
+
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
8518
|
+
);
|
|
8519
|
+
for (const worker of workers) {
|
|
8520
|
+
for (const value of Object.values(worker.serviceBindings ?? {})) {
|
|
8521
|
+
if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
|
|
8522
|
+
const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
|
|
8523
|
+
const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
|
|
8524
|
+
assert6(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
|
|
8525
|
+
entrypointNames.add(value.entrypoint);
|
|
8526
|
+
}
|
|
8657
8527
|
}
|
|
8658
8528
|
}
|
|
8529
|
+
return workerToWorkerEntrypointNamesMap;
|
|
8659
8530
|
}
|
|
8660
|
-
function
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8531
|
+
function getWorkerToDurableObjectClassNamesMap(workers) {
|
|
8532
|
+
const workerToDurableObjectClassNamesMap = new Map(
|
|
8533
|
+
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
8534
|
+
);
|
|
8535
|
+
for (const worker of workers) {
|
|
8536
|
+
for (const value of Object.values(worker.durableObjects ?? {})) {
|
|
8537
|
+
if (typeof value === "string") {
|
|
8538
|
+
const classNames = workerToDurableObjectClassNamesMap.get(worker.name);
|
|
8539
|
+
assert6(classNames, missingWorkerErrorMessage(worker.name));
|
|
8540
|
+
classNames.add(value);
|
|
8541
|
+
} else if (typeof value === "object") {
|
|
8542
|
+
if (value.scriptName) {
|
|
8543
|
+
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
8544
|
+
value.scriptName
|
|
8545
|
+
);
|
|
8546
|
+
assert6(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
8547
|
+
classNames.add(value.className);
|
|
8548
|
+
} else {
|
|
8549
|
+
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
8550
|
+
worker.name
|
|
8551
|
+
);
|
|
8552
|
+
assert6(classNames, missingWorkerErrorMessage(worker.name));
|
|
8553
|
+
classNames.add(value.className);
|
|
8554
|
+
}
|
|
8555
|
+
}
|
|
8666
8556
|
}
|
|
8667
8557
|
}
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8558
|
+
return workerToDurableObjectClassNamesMap;
|
|
8559
|
+
}
|
|
8560
|
+
function getWorkerToWorkflowEntrypointClassNamesMap(workers) {
|
|
8561
|
+
const workerToWorkflowEntrypointClassNamesMap = new Map(
|
|
8562
|
+
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
8563
|
+
);
|
|
8564
|
+
for (const worker of workers) {
|
|
8565
|
+
for (const value of Object.values(worker.workflows ?? {})) {
|
|
8566
|
+
if (value.scriptName) {
|
|
8567
|
+
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
8568
|
+
value.scriptName
|
|
8569
|
+
);
|
|
8570
|
+
assert6(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
8571
|
+
classNames.add(value.className);
|
|
8572
|
+
} else {
|
|
8573
|
+
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
8574
|
+
worker.name
|
|
8575
|
+
);
|
|
8576
|
+
assert6(classNames, missingWorkerErrorMessage(worker.name));
|
|
8577
|
+
classNames.add(value.className);
|
|
8578
|
+
}
|
|
8579
|
+
}
|
|
8673
8580
|
}
|
|
8674
|
-
|
|
8675
|
-
|
|
8581
|
+
return workerToWorkflowEntrypointClassNamesMap;
|
|
8582
|
+
}
|
|
8583
|
+
var miniflareModulesRoot = process.platform === "win32" ? "Z:\\" : "/";
|
|
8584
|
+
var ROUTER_WORKER_PATH = "./asset-workers/router-worker.js";
|
|
8585
|
+
var ASSET_WORKER_PATH = "./asset-workers/asset-worker.js";
|
|
8586
|
+
var WRAPPER_PATH = "__VITE_WORKER_ENTRY__";
|
|
8587
|
+
var RUNNER_PATH = "./runner-worker/index.js";
|
|
8588
|
+
function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
8589
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
8590
|
+
return;
|
|
8676
8591
|
}
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8592
|
+
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
8593
|
+
}
|
|
8594
|
+
function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
8595
|
+
const resolvedViteConfig = viteDevServer.config;
|
|
8596
|
+
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
8597
|
+
const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
|
|
8598
|
+
const assetWorkers = [
|
|
8599
|
+
{
|
|
8600
|
+
name: ROUTER_WORKER_NAME,
|
|
8601
|
+
compatibilityDate: ASSET_WORKERS_COMPATIBILITY_DATE,
|
|
8602
|
+
modulesRoot: miniflareModulesRoot,
|
|
8603
|
+
modules: [
|
|
8604
|
+
{
|
|
8605
|
+
type: "ESModule",
|
|
8606
|
+
path: path4.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
|
|
8607
|
+
contents: fs3.readFileSync(
|
|
8608
|
+
fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
|
|
8609
|
+
)
|
|
8610
|
+
}
|
|
8611
|
+
],
|
|
8612
|
+
bindings: {
|
|
8613
|
+
CONFIG: {
|
|
8614
|
+
has_user_worker: resolvedPluginConfig.type === "workers"
|
|
8615
|
+
}
|
|
8616
|
+
},
|
|
8617
|
+
serviceBindings: {
|
|
8618
|
+
ASSET_WORKER: ASSET_WORKER_NAME,
|
|
8619
|
+
...entryWorkerConfig ? { USER_WORKER: entryWorkerConfig.name } : {}
|
|
8682
8620
|
}
|
|
8683
|
-
}
|
|
8684
|
-
|
|
8685
|
-
|
|
8621
|
+
},
|
|
8622
|
+
{
|
|
8623
|
+
name: ASSET_WORKER_NAME,
|
|
8624
|
+
compatibilityDate: ASSET_WORKERS_COMPATIBILITY_DATE,
|
|
8625
|
+
modulesRoot: miniflareModulesRoot,
|
|
8626
|
+
modules: [
|
|
8627
|
+
{
|
|
8628
|
+
type: "ESModule",
|
|
8629
|
+
path: path4.join(miniflareModulesRoot, ASSET_WORKER_PATH),
|
|
8630
|
+
contents: fs3.readFileSync(
|
|
8631
|
+
fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
|
|
8632
|
+
)
|
|
8633
|
+
}
|
|
8634
|
+
],
|
|
8635
|
+
bindings: {
|
|
8636
|
+
CONFIG: {
|
|
8637
|
+
...assetsConfig?.html_handling ? { html_handling: assetsConfig.html_handling } : {},
|
|
8638
|
+
...assetsConfig?.not_found_handling ? { not_found_handling: assetsConfig.not_found_handling } : {}
|
|
8639
|
+
}
|
|
8640
|
+
},
|
|
8641
|
+
serviceBindings: {
|
|
8642
|
+
__VITE_ASSET_EXISTS__: async (request) => {
|
|
8643
|
+
const { pathname } = new URL(request.url);
|
|
8644
|
+
const filePath = path4.join(resolvedViteConfig.root, pathname);
|
|
8645
|
+
let exists;
|
|
8646
|
+
try {
|
|
8647
|
+
exists = fs3.statSync(filePath).isFile();
|
|
8648
|
+
} catch (error) {
|
|
8649
|
+
exists = false;
|
|
8650
|
+
}
|
|
8651
|
+
return MiniflareResponse.json(exists);
|
|
8652
|
+
},
|
|
8653
|
+
__VITE_FETCH_ASSET__: async (request) => {
|
|
8654
|
+
const { pathname } = new URL(request.url);
|
|
8655
|
+
const filePath = path4.join(resolvedViteConfig.root, pathname);
|
|
8656
|
+
try {
|
|
8657
|
+
let html = await fsp.readFile(filePath, "utf-8");
|
|
8658
|
+
html = await viteDevServer.transformIndexHtml(pathname, html);
|
|
8659
|
+
return new MiniflareResponse(html, {
|
|
8660
|
+
headers: { "Content-Type": "text/html" }
|
|
8661
|
+
});
|
|
8662
|
+
} catch (error) {
|
|
8663
|
+
throw new Error(`Unexpected error. Failed to load ${pathname}`);
|
|
8664
|
+
}
|
|
8665
|
+
}
|
|
8686
8666
|
}
|
|
8687
8667
|
}
|
|
8688
|
-
|
|
8689
|
-
const
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
urls.push(
|
|
8698
|
-
new URL("./", url),
|
|
8699
|
-
// If url is directory
|
|
8700
|
-
new URL(joinURL(url.pathname, "_index.js"), url),
|
|
8701
|
-
// TODO: Remove in next major version?
|
|
8702
|
-
new URL("node_modules", url)
|
|
8668
|
+
];
|
|
8669
|
+
const workersFromConfig = resolvedPluginConfig.type === "workers" ? Object.entries(resolvedPluginConfig.workers).map(
|
|
8670
|
+
([environmentName, workerConfig]) => {
|
|
8671
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
8672
|
+
{
|
|
8673
|
+
...workerConfig,
|
|
8674
|
+
assets: void 0
|
|
8675
|
+
},
|
|
8676
|
+
resolvedPluginConfig.cloudflareEnv
|
|
8703
8677
|
);
|
|
8678
|
+
const { externalWorkers: externalWorkers2 } = miniflareWorkerOptions;
|
|
8679
|
+
const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
8680
|
+
return {
|
|
8681
|
+
externalWorkers: externalWorkers2,
|
|
8682
|
+
worker: {
|
|
8683
|
+
...workerOptions,
|
|
8684
|
+
name: workerOptions.name ?? workerConfig.name,
|
|
8685
|
+
unsafeInspectorProxy: resolvedPluginConfig.inspectorPort !== false,
|
|
8686
|
+
modulesRoot: miniflareModulesRoot,
|
|
8687
|
+
unsafeEvalBinding: "__VITE_UNSAFE_EVAL__",
|
|
8688
|
+
serviceBindings: {
|
|
8689
|
+
...workerOptions.serviceBindings,
|
|
8690
|
+
...environmentName === resolvedPluginConfig.entryWorkerEnvironmentName && workerConfig.assets?.binding ? {
|
|
8691
|
+
[workerConfig.assets.binding]: ASSET_WORKER_NAME
|
|
8692
|
+
} : {},
|
|
8693
|
+
__VITE_INVOKE_MODULE__: async (request) => {
|
|
8694
|
+
const payload = await request.json();
|
|
8695
|
+
const invokePayloadData = payload.data;
|
|
8696
|
+
assert6(
|
|
8697
|
+
invokePayloadData.name === "fetchModule",
|
|
8698
|
+
`Invalid invoke event: ${invokePayloadData.name}`
|
|
8699
|
+
);
|
|
8700
|
+
const [moduleId] = invokePayloadData.data;
|
|
8701
|
+
if (additionalModuleRE.test(moduleId)) {
|
|
8702
|
+
const result2 = {
|
|
8703
|
+
externalize: moduleId,
|
|
8704
|
+
type: "module"
|
|
8705
|
+
};
|
|
8706
|
+
return MiniflareResponse.json({ result: result2 });
|
|
8707
|
+
}
|
|
8708
|
+
const devEnvironment = viteDevServer.environments[environmentName];
|
|
8709
|
+
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
8710
|
+
return MiniflareResponse.json(result);
|
|
8711
|
+
}
|
|
8712
|
+
}
|
|
8713
|
+
}
|
|
8714
|
+
};
|
|
8704
8715
|
}
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8716
|
+
) : [];
|
|
8717
|
+
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
8718
|
+
const externalWorkers = workersFromConfig.flatMap(
|
|
8719
|
+
(options) => options.externalWorkers
|
|
8720
|
+
);
|
|
8721
|
+
const workerToWorkerEntrypointNamesMap = getWorkerToWorkerEntrypointNamesMap(userWorkers);
|
|
8722
|
+
const workerToDurableObjectClassNamesMap = getWorkerToDurableObjectClassNamesMap(userWorkers);
|
|
8723
|
+
const workerToWorkflowEntrypointClassNamesMap = getWorkerToWorkflowEntrypointClassNamesMap(userWorkers);
|
|
8724
|
+
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
8725
|
+
return {
|
|
8726
|
+
log: logger,
|
|
8727
|
+
inspectorPort: resolvedPluginConfig.inspectorPort || void 0,
|
|
8728
|
+
unsafeInspectorProxy: resolvedPluginConfig.inspectorPort !== false,
|
|
8729
|
+
handleRuntimeStdio(stdout, stderr) {
|
|
8730
|
+
const decoder = new TextDecoder();
|
|
8731
|
+
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
8732
|
+
stderr.forEach(
|
|
8733
|
+
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
8734
|
+
);
|
|
8735
|
+
},
|
|
8736
|
+
...getPersistence(
|
|
8737
|
+
resolvedViteConfig.root,
|
|
8738
|
+
resolvedPluginConfig.persistState
|
|
8739
|
+
),
|
|
8740
|
+
workers: [
|
|
8741
|
+
...assetWorkers,
|
|
8742
|
+
...externalWorkers,
|
|
8743
|
+
...userWorkers.map((workerOptions) => {
|
|
8744
|
+
const wrappers = [
|
|
8745
|
+
`import { createWorkerEntrypointWrapper, createDurableObjectWrapper, createWorkflowEntrypointWrapper } from '${RUNNER_PATH}';`,
|
|
8746
|
+
`export default createWorkerEntrypointWrapper('default');`
|
|
8747
|
+
];
|
|
8748
|
+
const workerEntrypointNames = workerToWorkerEntrypointNamesMap.get(
|
|
8749
|
+
workerOptions.name
|
|
8718
8750
|
);
|
|
8719
|
-
|
|
8720
|
-
|
|
8751
|
+
assert6(
|
|
8752
|
+
workerEntrypointNames,
|
|
8753
|
+
`WorkerEntrypoint names not found for worker ${workerOptions.name}`
|
|
8754
|
+
);
|
|
8755
|
+
for (const entrypointName of [...workerEntrypointNames].sort()) {
|
|
8756
|
+
wrappers.push(
|
|
8757
|
+
`export const ${entrypointName} = createWorkerEntrypointWrapper('${entrypointName}');`
|
|
8758
|
+
);
|
|
8759
|
+
}
|
|
8760
|
+
const durableObjectClassNames = workerToDurableObjectClassNamesMap.get(
|
|
8761
|
+
workerOptions.name
|
|
8762
|
+
);
|
|
8763
|
+
assert6(
|
|
8764
|
+
durableObjectClassNames,
|
|
8765
|
+
`DurableObject class names not found for worker ${workerOptions.name}`
|
|
8766
|
+
);
|
|
8767
|
+
for (const className of [...durableObjectClassNames].sort()) {
|
|
8768
|
+
wrappers.push(
|
|
8769
|
+
`export const ${className} = createDurableObjectWrapper('${className}');`
|
|
8770
|
+
);
|
|
8771
|
+
}
|
|
8772
|
+
const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
|
|
8773
|
+
assert6(
|
|
8774
|
+
workflowEntrypointClassNames,
|
|
8775
|
+
`WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
|
|
8776
|
+
);
|
|
8777
|
+
for (const className of [...workflowEntrypointClassNames].sort()) {
|
|
8778
|
+
wrappers.push(
|
|
8779
|
+
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
8780
|
+
);
|
|
8781
|
+
}
|
|
8782
|
+
return {
|
|
8783
|
+
...workerOptions,
|
|
8784
|
+
modules: [
|
|
8785
|
+
{
|
|
8786
|
+
type: "ESModule",
|
|
8787
|
+
path: path4.join(miniflareModulesRoot, WRAPPER_PATH),
|
|
8788
|
+
contents: wrappers.join("\n")
|
|
8789
|
+
},
|
|
8790
|
+
{
|
|
8791
|
+
type: "ESModule",
|
|
8792
|
+
path: path4.join(miniflareModulesRoot, RUNNER_PATH),
|
|
8793
|
+
contents: fs3.readFileSync(
|
|
8794
|
+
fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
|
|
8795
|
+
)
|
|
8796
|
+
}
|
|
8797
|
+
],
|
|
8798
|
+
unsafeUseModuleFallbackService: true
|
|
8799
|
+
};
|
|
8800
|
+
})
|
|
8801
|
+
],
|
|
8802
|
+
async unsafeModuleFallbackService(request) {
|
|
8803
|
+
const url = new URL(request.url);
|
|
8804
|
+
const rawSpecifier = url.searchParams.get("rawSpecifier");
|
|
8805
|
+
assert6(
|
|
8806
|
+
rawSpecifier,
|
|
8807
|
+
`Unexpected error: no specifier in request to module fallback service.`
|
|
8808
|
+
);
|
|
8809
|
+
const match = additionalModuleRE.exec(rawSpecifier);
|
|
8810
|
+
assert6(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
|
|
8811
|
+
const [full, moduleType, modulePath] = match;
|
|
8812
|
+
assert6(
|
|
8813
|
+
moduleType,
|
|
8814
|
+
`Unexpected error: module type not found in reference: ${full}.`
|
|
8815
|
+
);
|
|
8816
|
+
assert6(
|
|
8817
|
+
modulePath,
|
|
8818
|
+
`Unexpected error: module path not found in reference: ${full}.`
|
|
8819
|
+
);
|
|
8820
|
+
let contents;
|
|
8821
|
+
try {
|
|
8822
|
+
contents = await fsp.readFile(modulePath);
|
|
8823
|
+
} catch (error) {
|
|
8824
|
+
throw new Error(
|
|
8825
|
+
`Import "${modulePath}" not found. Does the file exist?`
|
|
8826
|
+
);
|
|
8827
|
+
}
|
|
8828
|
+
switch (moduleType) {
|
|
8829
|
+
case "CompiledWasm": {
|
|
8830
|
+
return MiniflareResponse.json({ wasm: Array.from(contents) });
|
|
8831
|
+
}
|
|
8832
|
+
case "Data": {
|
|
8833
|
+
return MiniflareResponse.json({ data: Array.from(contents) });
|
|
8834
|
+
}
|
|
8835
|
+
case "Text": {
|
|
8836
|
+
return MiniflareResponse.json({ text: contents.toString() });
|
|
8837
|
+
}
|
|
8838
|
+
default: {
|
|
8839
|
+
return MiniflareResponse.error();
|
|
8721
8840
|
}
|
|
8722
8841
|
}
|
|
8723
|
-
if (resolved) {
|
|
8724
|
-
break;
|
|
8725
|
-
}
|
|
8726
|
-
}
|
|
8727
|
-
if (resolved) {
|
|
8728
|
-
break;
|
|
8729
8842
|
}
|
|
8730
|
-
}
|
|
8731
|
-
if (!resolved) {
|
|
8732
|
-
const error = new Error(
|
|
8733
|
-
`Cannot find module ${id} imported from ${urls.join(", ")}`
|
|
8734
|
-
);
|
|
8735
|
-
error.code = "ERR_MODULE_NOT_FOUND";
|
|
8736
|
-
throw error;
|
|
8737
|
-
}
|
|
8738
|
-
return pathToFileURL(resolved);
|
|
8739
|
-
}
|
|
8740
|
-
function resolveSync(id, options) {
|
|
8741
|
-
return _resolve(id, options);
|
|
8742
|
-
}
|
|
8743
|
-
function resolvePathSync(id, options) {
|
|
8744
|
-
return fileURLToPath2(resolveSync(id, options));
|
|
8843
|
+
};
|
|
8745
8844
|
}
|
|
8746
|
-
|
|
8747
|
-
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
}
|
|
8766
|
-
if (nodeCompatMode === "v1") {
|
|
8767
|
-
throw new Error(
|
|
8768
|
-
`Unsupported Node.js compat mode (v1). Only the v2 mode is supported, either change your compat date to "2024-09-23" or later, or set the "nodejs_compat_v2" compatibility flag`
|
|
8769
|
-
);
|
|
8770
|
-
}
|
|
8771
|
-
return false;
|
|
8845
|
+
function getPreviewModules(main, modulesRules) {
|
|
8846
|
+
assert6(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
8847
|
+
const rootPath = path4.dirname(main);
|
|
8848
|
+
const entryPath = path4.basename(main);
|
|
8849
|
+
return {
|
|
8850
|
+
rootPath,
|
|
8851
|
+
modules: [
|
|
8852
|
+
{
|
|
8853
|
+
type: "ESModule",
|
|
8854
|
+
path: entryPath
|
|
8855
|
+
},
|
|
8856
|
+
...modulesRules.flatMap(
|
|
8857
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path8) => ({
|
|
8858
|
+
type,
|
|
8859
|
+
path: path8
|
|
8860
|
+
}))
|
|
8861
|
+
)
|
|
8862
|
+
]
|
|
8863
|
+
};
|
|
8772
8864
|
}
|
|
8773
|
-
function
|
|
8774
|
-
const
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
}).join("\n");
|
|
8791
|
-
const modified = new MagicString(code);
|
|
8792
|
-
modified.prepend(injectedCode);
|
|
8865
|
+
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort = DEFAULT_INSPECTOR_PORT) {
|
|
8866
|
+
const resolvedViteConfig = vitePreviewServer.config;
|
|
8867
|
+
const workers = workerConfigs.flatMap((config) => {
|
|
8868
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(config);
|
|
8869
|
+
const { externalWorkers } = miniflareWorkerOptions;
|
|
8870
|
+
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
8871
|
+
return [
|
|
8872
|
+
{
|
|
8873
|
+
...workerOptions,
|
|
8874
|
+
name: workerOptions.name ?? config.name,
|
|
8875
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
8876
|
+
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
8877
|
+
},
|
|
8878
|
+
...externalWorkers
|
|
8879
|
+
];
|
|
8880
|
+
});
|
|
8881
|
+
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
8793
8882
|
return {
|
|
8794
|
-
|
|
8795
|
-
|
|
8883
|
+
log: logger,
|
|
8884
|
+
inspectorPort: inspectorPort || void 0,
|
|
8885
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
8886
|
+
handleRuntimeStdio(stdout, stderr) {
|
|
8887
|
+
const decoder = new TextDecoder();
|
|
8888
|
+
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
8889
|
+
stderr.forEach(
|
|
8890
|
+
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
8891
|
+
);
|
|
8892
|
+
},
|
|
8893
|
+
...getPersistence(resolvedViteConfig.root, persistState),
|
|
8894
|
+
workers
|
|
8796
8895
|
};
|
|
8797
8896
|
}
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
resolved: resolvePathSync(alias, { url: import.meta.url })
|
|
8804
|
-
};
|
|
8805
|
-
}
|
|
8806
|
-
if (nodeCompatEntries.has(source)) {
|
|
8807
|
-
return {
|
|
8808
|
-
unresolved: source,
|
|
8809
|
-
resolved: resolvePathSync(source, { url: import.meta.url })
|
|
8810
|
-
};
|
|
8897
|
+
var ViteMiniflareLogger = class extends Log {
|
|
8898
|
+
logger;
|
|
8899
|
+
constructor(config) {
|
|
8900
|
+
super(miniflareLogLevelFromViteLogLevel(config.logLevel));
|
|
8901
|
+
this.logger = config.logger;
|
|
8811
8902
|
}
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
entries.add(globalInject[0]);
|
|
8903
|
+
logWithLevel(level, message) {
|
|
8904
|
+
if (/^Ready on http/.test(message)) {
|
|
8905
|
+
level = LogLevel.DEBUG;
|
|
8906
|
+
}
|
|
8907
|
+
switch (level) {
|
|
8908
|
+
case LogLevel.ERROR:
|
|
8909
|
+
return this.logger.error(message);
|
|
8910
|
+
case LogLevel.WARN:
|
|
8911
|
+
return this.logger.warn(message);
|
|
8912
|
+
case LogLevel.INFO:
|
|
8913
|
+
return this.logger.info(message);
|
|
8824
8914
|
}
|
|
8825
8915
|
}
|
|
8826
|
-
|
|
8827
|
-
|
|
8916
|
+
};
|
|
8917
|
+
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
8918
|
+
switch (level) {
|
|
8919
|
+
case "error":
|
|
8920
|
+
return LogLevel.ERROR;
|
|
8921
|
+
case "warn":
|
|
8922
|
+
return LogLevel.WARN;
|
|
8923
|
+
case "info":
|
|
8924
|
+
return LogLevel.INFO;
|
|
8925
|
+
case "silent":
|
|
8926
|
+
return LogLevel.NONE;
|
|
8927
|
+
}
|
|
8828
8928
|
}
|
|
8829
8929
|
|
|
8830
8930
|
// src/plugin-config.ts
|
|
8831
|
-
import
|
|
8931
|
+
import assert7 from "node:assert";
|
|
8832
8932
|
import * as path6 from "node:path";
|
|
8833
8933
|
import * as vite5 from "vite";
|
|
8834
8934
|
|
|
8835
8935
|
// src/workers-configs.ts
|
|
8836
|
-
import assert7 from "node:assert";
|
|
8837
8936
|
import * as fs4 from "node:fs";
|
|
8838
8937
|
import * as path5 from "node:path";
|
|
8839
|
-
import { unstable_readConfig as
|
|
8840
|
-
|
|
8841
|
-
// package.json
|
|
8842
|
-
var name = "@cloudflare/vite-plugin";
|
|
8843
|
-
|
|
8844
|
-
// src/workers-configs.ts
|
|
8938
|
+
import { unstable_readConfig as unstable_readConfig3 } from "wrangler";
|
|
8845
8939
|
var nonApplicableWorkerConfigs = {
|
|
8846
8940
|
/**
|
|
8847
8941
|
* Object containing configs that have a vite replacement, the object's field contain details about the config's replacement
|
|
@@ -8870,14 +8964,11 @@ var nonApplicableWorkerConfigs = {
|
|
|
8870
8964
|
"find_additional_modules",
|
|
8871
8965
|
"no_bundle",
|
|
8872
8966
|
"preserve_file_names",
|
|
8967
|
+
"rules",
|
|
8873
8968
|
"site",
|
|
8874
8969
|
"tsconfig",
|
|
8875
8970
|
"upload_source_maps"
|
|
8876
|
-
]
|
|
8877
|
-
/**
|
|
8878
|
-
* All the configs that get overridden by our plugin
|
|
8879
|
-
*/
|
|
8880
|
-
overridden: ["rules"]
|
|
8971
|
+
]
|
|
8881
8972
|
};
|
|
8882
8973
|
var nullableNonApplicable = [
|
|
8883
8974
|
"alias",
|
|
@@ -8893,10 +8984,9 @@ var nullableNonApplicable = [
|
|
|
8893
8984
|
function readWorkerConfig(configPath, env2) {
|
|
8894
8985
|
const nonApplicable = {
|
|
8895
8986
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
8896
|
-
notRelevant: /* @__PURE__ */ new Set()
|
|
8897
|
-
overridden: /* @__PURE__ */ new Set()
|
|
8987
|
+
notRelevant: /* @__PURE__ */ new Set()
|
|
8898
8988
|
};
|
|
8899
|
-
const config =
|
|
8989
|
+
const config = unstable_readConfig3({ config: configPath, env: env2 }, {});
|
|
8900
8990
|
const raw = structuredClone(config);
|
|
8901
8991
|
nullableNonApplicable.forEach((prop) => {
|
|
8902
8992
|
if (config[prop] !== void 0) {
|
|
@@ -8906,9 +8996,6 @@ function readWorkerConfig(configPath, env2) {
|
|
|
8906
8996
|
if (isNotRelevant(prop)) {
|
|
8907
8997
|
nonApplicable.notRelevant.add(prop);
|
|
8908
8998
|
}
|
|
8909
|
-
if (isOverridden(prop)) {
|
|
8910
|
-
nonApplicable.overridden.add(prop);
|
|
8911
|
-
}
|
|
8912
8999
|
}
|
|
8913
9000
|
delete config[prop];
|
|
8914
9001
|
});
|
|
@@ -8921,7 +9008,7 @@ function readWorkerConfig(configPath, env2) {
|
|
|
8921
9008
|
}
|
|
8922
9009
|
delete config["define"];
|
|
8923
9010
|
if (config.rules.length > 0) {
|
|
8924
|
-
nonApplicable.
|
|
9011
|
+
nonApplicable.notRelevant.add("rules");
|
|
8925
9012
|
}
|
|
8926
9013
|
return {
|
|
8927
9014
|
raw,
|
|
@@ -8973,7 +9060,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
8973
9060
|
}
|
|
8974
9061
|
function getWorkerNonApplicableWarnLines(workerConfig, linePrefix) {
|
|
8975
9062
|
const lines = [];
|
|
8976
|
-
const { replacedByVite, notRelevant
|
|
9063
|
+
const { replacedByVite, notRelevant } = workerConfig.nonApplicable;
|
|
8977
9064
|
for (const config of replacedByVite) {
|
|
8978
9065
|
lines.push(
|
|
8979
9066
|
`${linePrefix}\`${config}\` which is replaced by Vite's \`${nonApplicableWorkerConfigs.replacedByVite[config].viteReplacement}\` (docs: ${nonApplicableWorkerConfigs.replacedByVite[config].viteDocs})`
|
|
@@ -8983,10 +9070,6 @@ function getWorkerNonApplicableWarnLines(workerConfig, linePrefix) {
|
|
|
8983
9070
|
lines.push(
|
|
8984
9071
|
`${linePrefix}${[...notRelevant].map((config) => `\`${config}\``).join(", ")} which ${notRelevant.size > 1 ? "are" : "is"} not relevant in the context of a Vite project`
|
|
8985
9072
|
);
|
|
8986
|
-
if (overridden.size > 0)
|
|
8987
|
-
lines.push(
|
|
8988
|
-
`${linePrefix}${[...overridden].map((config) => `\`${config}\``).join(", ")} which ${overridden.size > 1 ? "are" : "is"} overridden by \`${name}\``
|
|
8989
|
-
);
|
|
8990
9073
|
return lines;
|
|
8991
9074
|
}
|
|
8992
9075
|
function isReplacedByVite(configName) {
|
|
@@ -8995,9 +9078,6 @@ function isReplacedByVite(configName) {
|
|
|
8995
9078
|
function isNotRelevant(configName) {
|
|
8996
9079
|
return nonApplicableWorkerConfigs.notRelevant.includes(configName);
|
|
8997
9080
|
}
|
|
8998
|
-
function isOverridden(configName) {
|
|
8999
|
-
return nonApplicableWorkerConfigs.overridden.includes(configName);
|
|
9000
|
-
}
|
|
9001
9081
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
9002
9082
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
9003
9083
|
}
|
|
@@ -9007,42 +9087,55 @@ function getWorkerConfig(configPath, env2, opts) {
|
|
|
9007
9087
|
}
|
|
9008
9088
|
const { raw, config, nonApplicable } = readWorkerConfig(configPath, env2);
|
|
9009
9089
|
opts?.visitedConfigPaths?.add(configPath);
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
)
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
|
|
9017
|
-
|
|
9018
|
-
)
|
|
9019
|
-
|
|
9020
|
-
|
|
9021
|
-
config.assets,
|
|
9022
|
-
missingFieldErrorMessage(`'main' or 'assets'`, configPath, env2)
|
|
9090
|
+
if (!config.name) {
|
|
9091
|
+
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
9092
|
+
}
|
|
9093
|
+
if (!config.topLevelName) {
|
|
9094
|
+
throw new Error(
|
|
9095
|
+
missingFieldErrorMessage(`top-level 'name'`, configPath, env2)
|
|
9096
|
+
);
|
|
9097
|
+
}
|
|
9098
|
+
if (!config.compatibility_date) {
|
|
9099
|
+
throw new Error(
|
|
9100
|
+
missingFieldErrorMessage(`'compatibility_date`, configPath, env2)
|
|
9023
9101
|
);
|
|
9102
|
+
}
|
|
9103
|
+
const requiredFields = {
|
|
9104
|
+
topLevelName: config.topLevelName,
|
|
9105
|
+
name: config.name,
|
|
9106
|
+
compatibility_date: config.compatibility_date
|
|
9107
|
+
};
|
|
9108
|
+
if (opts?.isEntryWorker && !config.main) {
|
|
9024
9109
|
return {
|
|
9025
9110
|
type: "assets-only",
|
|
9026
9111
|
raw,
|
|
9027
9112
|
config: {
|
|
9028
9113
|
...config,
|
|
9029
|
-
|
|
9030
|
-
name: config.name,
|
|
9031
|
-
compatibility_date: config.compatibility_date,
|
|
9032
|
-
assets: config.assets
|
|
9114
|
+
...requiredFields
|
|
9033
9115
|
},
|
|
9034
9116
|
nonApplicable
|
|
9035
9117
|
};
|
|
9036
9118
|
}
|
|
9037
|
-
|
|
9119
|
+
if (!config.main) {
|
|
9120
|
+
throw new Error(missingFieldErrorMessage(`'main'`, configPath, env2));
|
|
9121
|
+
}
|
|
9122
|
+
const mainStat = fs4.statSync(config.main, { throwIfNoEntry: false });
|
|
9123
|
+
if (!mainStat) {
|
|
9124
|
+
throw new Error(
|
|
9125
|
+
`The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
|
|
9126
|
+
);
|
|
9127
|
+
}
|
|
9128
|
+
if (mainStat.isDirectory()) {
|
|
9129
|
+
throw new Error(
|
|
9130
|
+
`The provided Wrangler config main field (${config.main}) points to a directory, it needs to point to a file instead`
|
|
9131
|
+
);
|
|
9132
|
+
}
|
|
9038
9133
|
return {
|
|
9039
9134
|
type: "worker",
|
|
9040
9135
|
raw,
|
|
9041
9136
|
config: {
|
|
9042
9137
|
...config,
|
|
9043
|
-
|
|
9044
|
-
name: config.name,
|
|
9045
|
-
compatibility_date: config.compatibility_date,
|
|
9138
|
+
...requiredFields,
|
|
9046
9139
|
main: config.main
|
|
9047
9140
|
},
|
|
9048
9141
|
nonApplicable
|
|
@@ -9064,6 +9157,7 @@ function workerNameToEnvironmentName(workerName) {
|
|
|
9064
9157
|
function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
9065
9158
|
const configPaths = /* @__PURE__ */ new Set();
|
|
9066
9159
|
const persistState = pluginConfig.persistState ?? true;
|
|
9160
|
+
const inspectorPort = pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT;
|
|
9067
9161
|
const root = userConfig.root ? path6.resolve(userConfig.root) : process.cwd();
|
|
9068
9162
|
const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
|
|
9069
9163
|
viteEnv.mode,
|
|
@@ -9072,10 +9166,11 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9072
9166
|
""
|
|
9073
9167
|
);
|
|
9074
9168
|
const configPath = pluginConfig.configPath ? path6.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9169
|
+
if (!configPath) {
|
|
9170
|
+
throw new Error(
|
|
9171
|
+
`Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
|
|
9172
|
+
);
|
|
9173
|
+
}
|
|
9079
9174
|
const entryWorkerResolvedConfig = getWorkerConfig(configPath, cloudflareEnv, {
|
|
9080
9175
|
visitedConfigPaths: configPaths,
|
|
9081
9176
|
isEntryWorker: true
|
|
@@ -9085,6 +9180,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9085
9180
|
type: "assets-only",
|
|
9086
9181
|
config: entryWorkerResolvedConfig.config,
|
|
9087
9182
|
configPaths,
|
|
9183
|
+
inspectorPort,
|
|
9088
9184
|
persistState,
|
|
9089
9185
|
rawConfigs: {
|
|
9090
9186
|
entryWorker: entryWorkerResolvedConfig
|
|
@@ -9107,7 +9203,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9107
9203
|
}
|
|
9108
9204
|
);
|
|
9109
9205
|
auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
|
|
9110
|
-
|
|
9206
|
+
assert7(
|
|
9111
9207
|
workerResolvedConfig.type === "worker",
|
|
9112
9208
|
"Unexpected error: received AssetsOnlyResult with auxiliary workers."
|
|
9113
9209
|
);
|
|
@@ -9124,6 +9220,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9124
9220
|
type: "workers",
|
|
9125
9221
|
configPaths,
|
|
9126
9222
|
persistState,
|
|
9223
|
+
inspectorPort,
|
|
9127
9224
|
workers,
|
|
9128
9225
|
entryWorkerEnvironmentName,
|
|
9129
9226
|
rawConfigs: {
|
|
@@ -9135,8 +9232,9 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9135
9232
|
}
|
|
9136
9233
|
|
|
9137
9234
|
// src/websockets.ts
|
|
9235
|
+
import { coupleWebSocket } from "miniflare";
|
|
9138
9236
|
import { WebSocketServer } from "ws";
|
|
9139
|
-
function handleWebSocket(httpServer, fetcher
|
|
9237
|
+
function handleWebSocket(httpServer, fetcher) {
|
|
9140
9238
|
const nodeWebSocket = new WebSocketServer({ noServer: true });
|
|
9141
9239
|
httpServer.on(
|
|
9142
9240
|
"upgrade",
|
|
@@ -9160,34 +9258,7 @@ function handleWebSocket(httpServer, fetcher, logger) {
|
|
|
9160
9258
|
socket,
|
|
9161
9259
|
head,
|
|
9162
9260
|
async (clientWebSocket) => {
|
|
9163
|
-
workerWebSocket
|
|
9164
|
-
workerWebSocket.addEventListener("message", (event) => {
|
|
9165
|
-
clientWebSocket.send(event.data);
|
|
9166
|
-
});
|
|
9167
|
-
workerWebSocket.addEventListener("error", (event) => {
|
|
9168
|
-
logger.error(
|
|
9169
|
-
`WebSocket error:
|
|
9170
|
-
${event.error?.stack || event.error?.message}`,
|
|
9171
|
-
{ error: event.error }
|
|
9172
|
-
);
|
|
9173
|
-
});
|
|
9174
|
-
workerWebSocket.addEventListener("close", () => {
|
|
9175
|
-
clientWebSocket.close();
|
|
9176
|
-
});
|
|
9177
|
-
clientWebSocket.on("message", (data2, isBinary) => {
|
|
9178
|
-
workerWebSocket.send(
|
|
9179
|
-
isBinary ? Array.isArray(data2) ? Buffer.concat(data2) : data2 : data2.toString()
|
|
9180
|
-
);
|
|
9181
|
-
});
|
|
9182
|
-
clientWebSocket.on("error", (error) => {
|
|
9183
|
-
logger.error(`WebSocket error:
|
|
9184
|
-
${error.stack || error.message}`, {
|
|
9185
|
-
error
|
|
9186
|
-
});
|
|
9187
|
-
});
|
|
9188
|
-
clientWebSocket.on("close", () => {
|
|
9189
|
-
workerWebSocket.close();
|
|
9190
|
-
});
|
|
9261
|
+
coupleWebSocket(clientWebSocket, workerWebSocket);
|
|
9191
9262
|
nodeWebSocket.emit("connection", clientWebSocket, request);
|
|
9192
9263
|
}
|
|
9193
9264
|
);
|
|
@@ -9196,14 +9267,18 @@ ${error.stack || error.message}`, {
|
|
|
9196
9267
|
}
|
|
9197
9268
|
|
|
9198
9269
|
// src/index.ts
|
|
9270
|
+
var workersConfigsWarningShown = false;
|
|
9199
9271
|
function cloudflare2(pluginConfig = {}) {
|
|
9200
9272
|
let resolvedPluginConfig;
|
|
9201
9273
|
let resolvedViteConfig;
|
|
9202
9274
|
let miniflare;
|
|
9203
|
-
|
|
9275
|
+
const additionalModulePaths = /* @__PURE__ */ new Set();
|
|
9276
|
+
let hasClientBuild = false;
|
|
9204
9277
|
return [
|
|
9205
9278
|
{
|
|
9206
9279
|
name: "vite-plugin-cloudflare",
|
|
9280
|
+
// This only applies to this plugin so is safe to use while other plugins migrate to the Environment API
|
|
9281
|
+
sharedDuringBuild: true,
|
|
9207
9282
|
config(userConfig, env2) {
|
|
9208
9283
|
if (env2.isPreview) {
|
|
9209
9284
|
return { appType: "custom" };
|
|
@@ -9260,7 +9335,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9260
9335
|
resolvedPluginConfig.workers
|
|
9261
9336
|
).map((environmentName) => {
|
|
9262
9337
|
const environment = builder.environments[environmentName];
|
|
9263
|
-
|
|
9338
|
+
assert8(
|
|
9264
9339
|
environment,
|
|
9265
9340
|
`${environmentName} environment not found`
|
|
9266
9341
|
);
|
|
@@ -9276,6 +9351,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9276
9351
|
}
|
|
9277
9352
|
};
|
|
9278
9353
|
},
|
|
9354
|
+
buildStart() {
|
|
9355
|
+
workersConfigsWarningShown = false;
|
|
9356
|
+
},
|
|
9279
9357
|
configResolved(config) {
|
|
9280
9358
|
resolvedViteConfig = config;
|
|
9281
9359
|
},
|
|
@@ -9290,18 +9368,27 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9290
9368
|
return;
|
|
9291
9369
|
}
|
|
9292
9370
|
workerConfig.main = entryChunk[0];
|
|
9371
|
+
workerConfig.no_bundle = true;
|
|
9372
|
+
workerConfig.rules = [
|
|
9373
|
+
{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
|
|
9374
|
+
];
|
|
9293
9375
|
const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
|
|
9294
|
-
if (isEntryWorker &&
|
|
9376
|
+
if (isEntryWorker && hasClientBuild) {
|
|
9295
9377
|
const workerOutputDirectory = this.environment.config.build.outDir;
|
|
9296
9378
|
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
9297
|
-
|
|
9379
|
+
assert8(
|
|
9298
9380
|
clientOutputDirectory,
|
|
9299
9381
|
"Unexpected error: client output directory is undefined"
|
|
9300
9382
|
);
|
|
9301
|
-
workerConfig.assets
|
|
9302
|
-
|
|
9303
|
-
path7.
|
|
9304
|
-
|
|
9383
|
+
workerConfig.assets = {
|
|
9384
|
+
...workerConfig.assets,
|
|
9385
|
+
directory: path7.relative(
|
|
9386
|
+
path7.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
9387
|
+
path7.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
9388
|
+
)
|
|
9389
|
+
};
|
|
9390
|
+
} else {
|
|
9391
|
+
workerConfig.assets = void 0;
|
|
9305
9392
|
}
|
|
9306
9393
|
config = workerConfig;
|
|
9307
9394
|
if (workerConfig.configPath) {
|
|
@@ -9319,7 +9406,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9319
9406
|
}
|
|
9320
9407
|
} else if (this.environment.name === "client") {
|
|
9321
9408
|
const assetsOnlyConfig = resolvedPluginConfig.config;
|
|
9322
|
-
assetsOnlyConfig.assets
|
|
9409
|
+
assetsOnlyConfig.assets = {
|
|
9410
|
+
...assetsOnlyConfig.assets,
|
|
9411
|
+
directory: "."
|
|
9412
|
+
};
|
|
9323
9413
|
const filesToAssetsIgnore = ["wrangler.json", ".dev.vars"];
|
|
9324
9414
|
this.emitFile({
|
|
9325
9415
|
type: "asset",
|
|
@@ -9332,8 +9422,6 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9332
9422
|
if (!config) {
|
|
9333
9423
|
return;
|
|
9334
9424
|
}
|
|
9335
|
-
config.no_bundle = true;
|
|
9336
|
-
config.rules = [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }];
|
|
9337
9425
|
if (config.unsafe && Object.keys(config.unsafe).length === 0) {
|
|
9338
9426
|
config.unsafe = void 0;
|
|
9339
9427
|
}
|
|
@@ -9344,6 +9432,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9344
9432
|
});
|
|
9345
9433
|
},
|
|
9346
9434
|
writeBundle() {
|
|
9435
|
+
if (this.environment.name === "client") {
|
|
9436
|
+
hasClientBuild = true;
|
|
9437
|
+
}
|
|
9347
9438
|
if (this.environment.name === (resolvedPluginConfig.type === "assets-only" ? "client" : resolvedPluginConfig.entryWorkerEnvironmentName)) {
|
|
9348
9439
|
writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
|
|
9349
9440
|
}
|
|
@@ -9360,7 +9451,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9360
9451
|
}
|
|
9361
9452
|
},
|
|
9362
9453
|
async configureServer(viteDevServer) {
|
|
9363
|
-
|
|
9454
|
+
assert8(
|
|
9364
9455
|
viteDevServer.httpServer,
|
|
9365
9456
|
"Unexpected error: No Vite HTTP server"
|
|
9366
9457
|
);
|
|
@@ -9368,23 +9459,16 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9368
9459
|
getDevMiniflareOptions(resolvedPluginConfig, viteDevServer)
|
|
9369
9460
|
);
|
|
9370
9461
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
9371
|
-
const
|
|
9372
|
-
resolvedPluginConfig,
|
|
9373
|
-
miniflare
|
|
9374
|
-
);
|
|
9462
|
+
const routerWorker = await getRouterWorker(miniflare);
|
|
9375
9463
|
const middleware = createMiddleware(
|
|
9376
9464
|
({ request }) => {
|
|
9377
|
-
return
|
|
9465
|
+
return routerWorker.fetch(toMiniflareRequest(request), {
|
|
9378
9466
|
redirect: "manual"
|
|
9379
9467
|
});
|
|
9380
9468
|
},
|
|
9381
9469
|
{ alwaysCallNext: false }
|
|
9382
9470
|
);
|
|
9383
|
-
handleWebSocket(
|
|
9384
|
-
viteDevServer.httpServer,
|
|
9385
|
-
entryWorker.fetch,
|
|
9386
|
-
viteDevServer.config.logger
|
|
9387
|
-
);
|
|
9471
|
+
handleWebSocket(viteDevServer.httpServer, routerWorker.fetch);
|
|
9388
9472
|
return () => {
|
|
9389
9473
|
viteDevServer.middlewares.use((req, res, next) => {
|
|
9390
9474
|
middleware(req, res, next);
|
|
@@ -9392,10 +9476,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9392
9476
|
};
|
|
9393
9477
|
},
|
|
9394
9478
|
configurePreviewServer(vitePreviewServer) {
|
|
9479
|
+
const workerConfigs = getWorkerConfigs(vitePreviewServer.config.root);
|
|
9395
9480
|
const miniflare2 = new Miniflare(
|
|
9396
9481
|
getPreviewMiniflareOptions(
|
|
9397
9482
|
vitePreviewServer,
|
|
9398
|
-
|
|
9483
|
+
workerConfigs,
|
|
9484
|
+
pluginConfig.persistState ?? true,
|
|
9485
|
+
pluginConfig.inspectorPort
|
|
9399
9486
|
)
|
|
9400
9487
|
);
|
|
9401
9488
|
const middleware = createMiddleware(
|
|
@@ -9406,58 +9493,80 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9406
9493
|
},
|
|
9407
9494
|
{ alwaysCallNext: false }
|
|
9408
9495
|
);
|
|
9409
|
-
handleWebSocket(
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9496
|
+
handleWebSocket(vitePreviewServer.httpServer, miniflare2.dispatchFetch);
|
|
9497
|
+
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
9498
|
+
middleware(req, res, next);
|
|
9499
|
+
});
|
|
9500
|
+
}
|
|
9501
|
+
},
|
|
9502
|
+
// Plugin to support `.wasm?init` extension
|
|
9503
|
+
{
|
|
9504
|
+
name: "vite-plugin-cloudflare:wasm-helper",
|
|
9505
|
+
enforce: "pre",
|
|
9506
|
+
applyToEnvironment(environment) {
|
|
9507
|
+
return getWorkerConfig2(environment.name) !== void 0;
|
|
9508
|
+
},
|
|
9509
|
+
load(id) {
|
|
9510
|
+
if (!id.endsWith(".wasm?init")) {
|
|
9511
|
+
return;
|
|
9512
|
+
}
|
|
9513
|
+
return `
|
|
9514
|
+
import wasm from "${cleanUrl(id)}";
|
|
9515
|
+
export default function(opts = {}) {
|
|
9516
|
+
return WebAssembly.instantiate(wasm, opts);
|
|
9517
|
+
}
|
|
9518
|
+
`;
|
|
9419
9519
|
}
|
|
9420
9520
|
},
|
|
9421
|
-
// Plugin to support
|
|
9521
|
+
// Plugin to support additional modules
|
|
9422
9522
|
{
|
|
9423
|
-
name: "vite-plugin-cloudflare:modules",
|
|
9523
|
+
name: "vite-plugin-cloudflare:additional-modules",
|
|
9424
9524
|
// We set `enforce: "pre"` so that this plugin runs before the Vite core plugins.
|
|
9425
9525
|
// Otherwise the `vite:wasm-fallback` plugin prevents the `.wasm` extension being used for module imports.
|
|
9426
9526
|
enforce: "pre",
|
|
9427
9527
|
applyToEnvironment(environment) {
|
|
9428
9528
|
return getWorkerConfig2(environment.name) !== void 0;
|
|
9429
9529
|
},
|
|
9430
|
-
async resolveId(source, importer) {
|
|
9431
|
-
|
|
9530
|
+
async resolveId(source, importer, options) {
|
|
9531
|
+
const additionalModuleType = matchAdditionalModule(source);
|
|
9532
|
+
if (!additionalModuleType) {
|
|
9432
9533
|
return;
|
|
9433
9534
|
}
|
|
9434
|
-
const resolved = await this.resolve(
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9535
|
+
const resolved = await this.resolve(
|
|
9536
|
+
cleanUrl(source),
|
|
9537
|
+
importer,
|
|
9538
|
+
options
|
|
9438
9539
|
);
|
|
9540
|
+
if (!resolved) {
|
|
9541
|
+
throw new Error(`Import "${source}" not found. Does the file exist?`);
|
|
9542
|
+
}
|
|
9543
|
+
additionalModulePaths.add(resolved.id);
|
|
9439
9544
|
return {
|
|
9440
9545
|
external: true,
|
|
9441
|
-
id: createModuleReference(
|
|
9546
|
+
id: createModuleReference(additionalModuleType, resolved.id)
|
|
9442
9547
|
};
|
|
9443
9548
|
},
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9549
|
+
hotUpdate(options) {
|
|
9550
|
+
if (additionalModulePaths.has(options.file)) {
|
|
9551
|
+
options.server.restart();
|
|
9552
|
+
}
|
|
9553
|
+
},
|
|
9554
|
+
async renderChunk(code, chunk) {
|
|
9555
|
+
const matches = code.matchAll(additionalModuleGlobalRE);
|
|
9447
9556
|
let magicString;
|
|
9448
|
-
|
|
9557
|
+
for (const match of matches) {
|
|
9449
9558
|
magicString ??= new MagicString(code);
|
|
9450
|
-
const [full,
|
|
9451
|
-
|
|
9559
|
+
const [full, _, modulePath] = match;
|
|
9560
|
+
assert8(
|
|
9452
9561
|
modulePath,
|
|
9453
9562
|
`Unexpected error: module path not found in reference ${full}.`
|
|
9454
9563
|
);
|
|
9455
9564
|
let source;
|
|
9456
9565
|
try {
|
|
9457
|
-
source =
|
|
9566
|
+
source = await fsp2.readFile(modulePath);
|
|
9458
9567
|
} catch (error) {
|
|
9459
9568
|
throw new Error(
|
|
9460
|
-
`Import ${modulePath} not found. Does the file exist?`
|
|
9569
|
+
`Import "${modulePath}" not found. Does the file exist?`
|
|
9461
9570
|
);
|
|
9462
9571
|
}
|
|
9463
9572
|
const referenceId = this.emitFile({
|
|
@@ -9491,8 +9600,8 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9491
9600
|
apply(_config, env2) {
|
|
9492
9601
|
return !env2.isPreview;
|
|
9493
9602
|
},
|
|
9494
|
-
configEnvironment(
|
|
9495
|
-
if (isNodeCompat(getWorkerConfig2(
|
|
9603
|
+
configEnvironment(name) {
|
|
9604
|
+
if (isNodeCompat(getWorkerConfig2(name))) {
|
|
9496
9605
|
return {
|
|
9497
9606
|
resolve: {
|
|
9498
9607
|
builtins: [...nodeCompatExternals]
|
|
@@ -9531,7 +9640,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9531
9640
|
return this.resolve(source, importer, options);
|
|
9532
9641
|
}
|
|
9533
9642
|
if (this.environment.mode === "dev") {
|
|
9534
|
-
|
|
9643
|
+
assert8(
|
|
9535
9644
|
this.environment.depsOptimizer,
|
|
9536
9645
|
"depsOptimizer is required in dev mode"
|
|
9537
9646
|
);
|
|
@@ -9545,16 +9654,63 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9545
9654
|
},
|
|
9546
9655
|
async transform(code, id) {
|
|
9547
9656
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
9548
|
-
|
|
9657
|
+
assert8(workerConfig, "Expected a worker config");
|
|
9549
9658
|
const resolvedId = await this.resolve(workerConfig.main);
|
|
9550
9659
|
if (id === resolvedId?.id) {
|
|
9551
9660
|
return injectGlobalCode(id, code);
|
|
9552
9661
|
}
|
|
9553
9662
|
}
|
|
9663
|
+
},
|
|
9664
|
+
// Plugin that provides an __debug path for debugging the Cloudflare Workers.
|
|
9665
|
+
{
|
|
9666
|
+
name: "vite-plugin-cloudflare:debug",
|
|
9667
|
+
// Note: this plugin needs to run before the main vite-plugin-cloudflare so that
|
|
9668
|
+
// the preview middleware here can take precedence
|
|
9669
|
+
enforce: "pre",
|
|
9670
|
+
configureServer(viteDevServer) {
|
|
9671
|
+
if (resolvedPluginConfig.type === "workers" && resolvedPluginConfig.inspectorPort !== false) {
|
|
9672
|
+
addDebugToVitePrintUrls(viteDevServer);
|
|
9673
|
+
}
|
|
9674
|
+
const workerNames = resolvedPluginConfig.type === "assets-only" ? [] : Object.values(resolvedPluginConfig.workers).map(
|
|
9675
|
+
(worker) => worker.name
|
|
9676
|
+
);
|
|
9677
|
+
viteDevServer.middlewares.use((req, res, next) => {
|
|
9678
|
+
if (req.url === debuggingPath && resolvedPluginConfig.inspectorPort !== false) {
|
|
9679
|
+
const html = getDebugPathHtml(
|
|
9680
|
+
workerNames,
|
|
9681
|
+
resolvedPluginConfig.inspectorPort
|
|
9682
|
+
);
|
|
9683
|
+
res.setHeader("Content-Type", "text/html");
|
|
9684
|
+
return res.end(html);
|
|
9685
|
+
}
|
|
9686
|
+
next();
|
|
9687
|
+
});
|
|
9688
|
+
},
|
|
9689
|
+
configurePreviewServer(vitePreviewServer) {
|
|
9690
|
+
const workerConfigs = getWorkerConfigs(vitePreviewServer.config.root);
|
|
9691
|
+
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
9692
|
+
addDebugToVitePrintUrls(vitePreviewServer);
|
|
9693
|
+
}
|
|
9694
|
+
const workerNames = workerConfigs.map((worker) => {
|
|
9695
|
+
assert8(worker.name);
|
|
9696
|
+
return worker.name;
|
|
9697
|
+
});
|
|
9698
|
+
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
9699
|
+
if (req.url === debuggingPath && pluginConfig.inspectorPort !== false) {
|
|
9700
|
+
const html = getDebugPathHtml(
|
|
9701
|
+
workerNames,
|
|
9702
|
+
pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT
|
|
9703
|
+
);
|
|
9704
|
+
res.setHeader("Content-Type", "text/html");
|
|
9705
|
+
return res.end(html);
|
|
9706
|
+
}
|
|
9707
|
+
next();
|
|
9708
|
+
});
|
|
9709
|
+
}
|
|
9554
9710
|
}
|
|
9555
9711
|
];
|
|
9556
9712
|
function getWorkerConfig2(environmentName) {
|
|
9557
|
-
|
|
9713
|
+
assert8(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
|
|
9558
9714
|
return resolvedPluginConfig.type !== "assets-only" ? resolvedPluginConfig.workers[environmentName] : void 0;
|
|
9559
9715
|
}
|
|
9560
9716
|
}
|
|
@@ -9569,9 +9725,6 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
|
9569
9725
|
}
|
|
9570
9726
|
return null;
|
|
9571
9727
|
}
|
|
9572
|
-
function createModuleReference(type, id) {
|
|
9573
|
-
return `__CLOUDFLARE_MODULE__${type}__${id}__`;
|
|
9574
|
-
}
|
|
9575
9728
|
export {
|
|
9576
9729
|
cloudflare2 as cloudflare
|
|
9577
9730
|
};
|