@cloudflare/vite-plugin 0.0.0-b69fd186b → 0.0.0-b7d6b7dd1
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 +456 -420
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2065 -1900
- package/dist/runner-worker/index.js +55 -22
- package/package.json +11 -10
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} */
|
|
@@ -7936,14 +7237,14 @@ var patternRegEx = /\*/g;
|
|
|
7936
7237
|
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
7937
7238
|
var emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
7938
7239
|
var doubleSlashRegEx = /[/\\]{2}/;
|
|
7939
|
-
function emitInvalidSegmentDeprecation(
|
|
7240
|
+
function emitInvalidSegmentDeprecation(target2, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
7940
7241
|
if (process$1.noDeprecation) {
|
|
7941
7242
|
return;
|
|
7942
7243
|
}
|
|
7943
7244
|
const pjsonPath = fileURLToPath$1(packageJsonUrl);
|
|
7944
|
-
const double = doubleSlashRegEx.exec(isTarget ?
|
|
7245
|
+
const double = doubleSlashRegEx.exec(isTarget ? target2 : request) !== null;
|
|
7945
7246
|
process$1.emitWarning(
|
|
7946
|
-
`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${
|
|
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)}` : ""}.`,
|
|
7947
7248
|
"DeprecationWarning",
|
|
7948
7249
|
"DEP0166"
|
|
7949
7250
|
);
|
|
@@ -7966,7 +7267,7 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
7966
7267
|
"DeprecationWarning",
|
|
7967
7268
|
"DEP0151"
|
|
7968
7269
|
);
|
|
7969
|
-
} else if (
|
|
7270
|
+
} else if (path.resolve(packagePath, main) !== urlPath) {
|
|
7970
7271
|
process$1.emitWarning(
|
|
7971
7272
|
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
7972
7273
|
packagePath.length
|
|
@@ -7979,12 +7280,12 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
7979
7280
|
}
|
|
7980
7281
|
function tryStatSync(path8) {
|
|
7981
7282
|
try {
|
|
7982
|
-
return
|
|
7283
|
+
return statSync(path8);
|
|
7983
7284
|
} catch {
|
|
7984
7285
|
}
|
|
7985
7286
|
}
|
|
7986
7287
|
function fileExists(url) {
|
|
7987
|
-
const stats =
|
|
7288
|
+
const stats = statSync(url, { throwIfNoEntry: false });
|
|
7988
7289
|
const isFile = stats ? stats.isFile() : void 0;
|
|
7989
7290
|
return isFile === null || isFile === void 0 ? false : isFile;
|
|
7990
7291
|
}
|
|
@@ -8012,836 +7313,1641 @@ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
|
8012
7313
|
guess,
|
|
8013
7314
|
packageJsonUrl,
|
|
8014
7315
|
base,
|
|
8015
|
-
packageConfig.main
|
|
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);
|
|
7458
|
+
}
|
|
7459
|
+
}
|
|
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);
|
|
7487
|
+
}
|
|
7488
|
+
}
|
|
7489
|
+
if (pattern) {
|
|
7490
|
+
return new URL$1(
|
|
7491
|
+
RegExpPrototypeSymbolReplace.call(
|
|
7492
|
+
patternRegEx,
|
|
7493
|
+
resolved.href,
|
|
7494
|
+
() => subpath
|
|
7495
|
+
)
|
|
7496
|
+
);
|
|
7497
|
+
}
|
|
7498
|
+
return new URL$1(subpath, resolved);
|
|
7499
|
+
}
|
|
7500
|
+
function isArrayIndex(key) {
|
|
7501
|
+
const keyNumber = Number(key);
|
|
7502
|
+
if (`${keyNumber}` !== key) return false;
|
|
7503
|
+
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
7504
|
+
}
|
|
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
|
|
7517
|
+
);
|
|
7518
|
+
}
|
|
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;
|
|
7559
|
+
}
|
|
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
|
+
}
|
|
7572
|
+
}
|
|
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),
|
|
7624
|
+
base,
|
|
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
7959
|
}
|
|
8297
|
-
if (target === null) {
|
|
8298
|
-
return null;
|
|
8299
|
-
}
|
|
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
|
-
|
|
8157
|
+
function toMiniflareRequest(request) {
|
|
8158
|
+
const secFetchMode = request.headers.get("Sec-Fetch-Mode");
|
|
8159
|
+
if (secFetchMode) {
|
|
8160
|
+
request.headers.set("X-Mf-Sec-Fetch-Mode", secFetchMode);
|
|
8431
8161
|
}
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
|
|
8446
|
-
|
|
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
|
-
}
|
|
8162
|
+
return new MiniflareRequest(request.url, {
|
|
8163
|
+
method: request.method,
|
|
8164
|
+
headers: [["accept-encoding", "identity"], ...request.headers],
|
|
8165
|
+
body: request.body,
|
|
8166
|
+
duplex: "half"
|
|
8167
|
+
});
|
|
8168
|
+
}
|
|
8169
|
+
function nodeHeadersToWebHeaders(nodeHeaders) {
|
|
8170
|
+
const headers = new Headers();
|
|
8171
|
+
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
8172
|
+
if (typeof value === "string") {
|
|
8173
|
+
headers.append(key, value);
|
|
8174
|
+
} else if (Array.isArray(value)) {
|
|
8175
|
+
for (const item of value) {
|
|
8176
|
+
headers.append(key, item);
|
|
8489
8177
|
}
|
|
8490
8178
|
}
|
|
8491
8179
|
}
|
|
8492
|
-
|
|
8180
|
+
return headers;
|
|
8493
8181
|
}
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8503
|
-
|
|
8182
|
+
var postfixRE = /[?#].*$/;
|
|
8183
|
+
function cleanUrl(url) {
|
|
8184
|
+
return url.replace(postfixRE, "");
|
|
8185
|
+
}
|
|
8186
|
+
|
|
8187
|
+
// src/cloudflare-environment.ts
|
|
8188
|
+
var webSocketUndefinedError = "The WebSocket is undefined";
|
|
8189
|
+
function createHotChannel(webSocketContainer) {
|
|
8190
|
+
const listenersMap = /* @__PURE__ */ new Map();
|
|
8191
|
+
const client = {
|
|
8192
|
+
send(payload) {
|
|
8193
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8194
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8195
|
+
webSocket.send(JSON.stringify(payload));
|
|
8196
|
+
}
|
|
8197
|
+
};
|
|
8198
|
+
function onMessage(event) {
|
|
8199
|
+
const payload = JSON.parse(event.data.toString());
|
|
8200
|
+
const listeners = listenersMap.get(payload.event) ?? /* @__PURE__ */ new Set();
|
|
8201
|
+
for (const listener of listeners) {
|
|
8202
|
+
listener(payload.data, client);
|
|
8504
8203
|
}
|
|
8505
8204
|
}
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8205
|
+
return {
|
|
8206
|
+
send(payload) {
|
|
8207
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8208
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8209
|
+
webSocket.send(JSON.stringify(payload));
|
|
8210
|
+
},
|
|
8211
|
+
on(event, listener) {
|
|
8212
|
+
const listeners = listenersMap.get(event) ?? /* @__PURE__ */ new Set();
|
|
8213
|
+
listeners.add(listener);
|
|
8214
|
+
listenersMap.set(event, listeners);
|
|
8215
|
+
},
|
|
8216
|
+
off(event, listener) {
|
|
8217
|
+
listenersMap.get(event)?.delete(listener);
|
|
8218
|
+
},
|
|
8219
|
+
listen() {
|
|
8220
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8221
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8222
|
+
webSocket.addEventListener("message", onMessage);
|
|
8223
|
+
},
|
|
8224
|
+
close() {
|
|
8225
|
+
const webSocket = webSocketContainer.webSocket;
|
|
8226
|
+
assert3(webSocket, webSocketUndefinedError);
|
|
8227
|
+
webSocket.removeEventListener("message", onMessage);
|
|
8228
|
+
}
|
|
8229
|
+
};
|
|
8230
|
+
}
|
|
8231
|
+
var CloudflareDevEnvironment = class extends vite2.DevEnvironment {
|
|
8232
|
+
#webSocketContainer;
|
|
8233
|
+
#worker;
|
|
8234
|
+
constructor(name, config) {
|
|
8235
|
+
const webSocketContainer = {};
|
|
8236
|
+
super(name, config, {
|
|
8237
|
+
hot: true,
|
|
8238
|
+
transport: createHotChannel(webSocketContainer)
|
|
8239
|
+
});
|
|
8240
|
+
this.#webSocketContainer = webSocketContainer;
|
|
8509
8241
|
}
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
|
|
8513
|
-
|
|
8514
|
-
|
|
8242
|
+
async initRunner(worker, root, workerConfig) {
|
|
8243
|
+
this.#worker = worker;
|
|
8244
|
+
const response = await this.#worker.fetch(
|
|
8245
|
+
new URL(INIT_PATH, UNKNOWN_HOST),
|
|
8246
|
+
{
|
|
8247
|
+
headers: {
|
|
8248
|
+
[VITE_DEV_METADATA_HEADER]: JSON.stringify({
|
|
8249
|
+
root,
|
|
8250
|
+
entryPath: workerConfig.main
|
|
8251
|
+
}),
|
|
8252
|
+
upgrade: "websocket"
|
|
8253
|
+
}
|
|
8254
|
+
}
|
|
8255
|
+
);
|
|
8256
|
+
assert3(
|
|
8257
|
+
response.ok,
|
|
8258
|
+
`Failed to initialize module runner, error: ${await response.text()}`
|
|
8515
8259
|
);
|
|
8260
|
+
const webSocket = response.webSocket;
|
|
8261
|
+
assert3(webSocket, "Failed to establish WebSocket");
|
|
8262
|
+
webSocket.accept();
|
|
8263
|
+
this.#webSocketContainer.webSocket = webSocket;
|
|
8516
8264
|
}
|
|
8517
|
-
|
|
8518
|
-
|
|
8265
|
+
};
|
|
8266
|
+
var cloudflareBuiltInModules = [
|
|
8267
|
+
"cloudflare:email",
|
|
8268
|
+
"cloudflare:sockets",
|
|
8269
|
+
"cloudflare:workers",
|
|
8270
|
+
"cloudflare:workflows"
|
|
8271
|
+
];
|
|
8272
|
+
var defaultConditions = ["workerd", "module", "browser"];
|
|
8273
|
+
var target = "es2022";
|
|
8274
|
+
function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmentName) {
|
|
8275
|
+
return {
|
|
8276
|
+
resolve: {
|
|
8277
|
+
// Note: in order for ssr pre-bundling to take effect we need to ask vite to treat all
|
|
8278
|
+
// dependencies as not external
|
|
8279
|
+
noExternal: true,
|
|
8280
|
+
// We want to use `workerd` package exports if available (e.g. for postgres).
|
|
8281
|
+
conditions: [...defaultConditions, "development|production"],
|
|
8282
|
+
// The Cloudflare ones are proper builtins in the environment
|
|
8283
|
+
builtins: [...cloudflareBuiltInModules]
|
|
8284
|
+
},
|
|
8285
|
+
dev: {
|
|
8286
|
+
createEnvironment(name, config) {
|
|
8287
|
+
return new CloudflareDevEnvironment(name, config);
|
|
8288
|
+
}
|
|
8289
|
+
},
|
|
8290
|
+
build: {
|
|
8291
|
+
createEnvironment(name, config) {
|
|
8292
|
+
return new vite2.BuildEnvironment(name, config);
|
|
8293
|
+
},
|
|
8294
|
+
target,
|
|
8295
|
+
// We need to enable `emitAssets` in order to support additional modules defined by `rules`
|
|
8296
|
+
emitAssets: true,
|
|
8297
|
+
outDir: getOutputDirectory(userConfig, environmentName),
|
|
8298
|
+
copyPublicDir: false,
|
|
8299
|
+
ssr: true,
|
|
8300
|
+
rollupOptions: {
|
|
8301
|
+
// Note: vite starts dev pre-bundling crawling from either optimizeDeps.entries or rollupOptions.input
|
|
8302
|
+
// so the input value here serves both as the build input as well as the starting point for
|
|
8303
|
+
// dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
|
|
8304
|
+
// optimizeDeps.entries in the dev config)
|
|
8305
|
+
input: workerConfig.main
|
|
8306
|
+
}
|
|
8307
|
+
},
|
|
8308
|
+
optimizeDeps: {
|
|
8309
|
+
// Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
|
|
8310
|
+
noDiscovery: false,
|
|
8311
|
+
entries: workerConfig.main,
|
|
8312
|
+
exclude: [...cloudflareBuiltInModules],
|
|
8313
|
+
esbuildOptions: {
|
|
8314
|
+
platform: "neutral",
|
|
8315
|
+
target,
|
|
8316
|
+
conditions: [...defaultConditions, "development"],
|
|
8317
|
+
resolveExtensions: [
|
|
8318
|
+
".mjs",
|
|
8319
|
+
".js",
|
|
8320
|
+
".mts",
|
|
8321
|
+
".ts",
|
|
8322
|
+
".jsx",
|
|
8323
|
+
".tsx",
|
|
8324
|
+
".json",
|
|
8325
|
+
".cjs",
|
|
8326
|
+
".cts",
|
|
8327
|
+
".ctx"
|
|
8328
|
+
]
|
|
8329
|
+
}
|
|
8330
|
+
},
|
|
8331
|
+
// if nodeCompat is enabled then let's keep the real process.env so that workerd can manipulate it
|
|
8332
|
+
keepProcessEnv: isNodeCompat(workerConfig)
|
|
8333
|
+
};
|
|
8519
8334
|
}
|
|
8520
|
-
function
|
|
8521
|
-
if (
|
|
8522
|
-
return
|
|
8523
|
-
}
|
|
8524
|
-
const { packageName, packageSubpath, isScoped } = parsePackageName(
|
|
8525
|
-
specifier,
|
|
8526
|
-
base
|
|
8527
|
-
);
|
|
8528
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
8529
|
-
if (packageConfig.exists) {
|
|
8530
|
-
const packageJsonUrl2 = pathToFileURL$1(packageConfig.pjsonPath);
|
|
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
|
-
}
|
|
8335
|
+
function initRunners(resolvedPluginConfig, viteDevServer, miniflare) {
|
|
8336
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
8337
|
+
return;
|
|
8540
8338
|
}
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8339
|
+
return Promise.all(
|
|
8340
|
+
Object.entries(resolvedPluginConfig.workers).map(
|
|
8341
|
+
async ([environmentName, workerConfig]) => {
|
|
8342
|
+
const worker = await miniflare.getWorker(workerConfig.name);
|
|
8343
|
+
return viteDevServer.environments[environmentName].initRunner(worker, viteDevServer.config.root, workerConfig);
|
|
8344
|
+
}
|
|
8345
|
+
)
|
|
8544
8346
|
);
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8347
|
+
}
|
|
8348
|
+
|
|
8349
|
+
// src/debugging.ts
|
|
8350
|
+
import assert4 from "node:assert";
|
|
8351
|
+
import colors from "picocolors";
|
|
8352
|
+
var debuggingPath = "/__debug";
|
|
8353
|
+
function addDebugToVitePrintUrls(server) {
|
|
8354
|
+
const originalPrintUrls = server.printUrls;
|
|
8355
|
+
server.printUrls = () => {
|
|
8356
|
+
originalPrintUrls();
|
|
8357
|
+
const localUrl = server.resolvedUrls?.local[0];
|
|
8358
|
+
if (localUrl) {
|
|
8359
|
+
const { protocol, hostname, port } = new URL(localUrl);
|
|
8360
|
+
const colorDebugUrl = (url) => colors.dim(
|
|
8361
|
+
colors.yellow(
|
|
8362
|
+
url.replace(/:(\d+)\//, (_, port2) => `:${colors.bold(port2)}/`)
|
|
8363
|
+
)
|
|
8554
8364
|
);
|
|
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
|
|
8365
|
+
server.config.logger.info(
|
|
8366
|
+
` ${colors.green("\u279C")} ${colors.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${debuggingPath}`)}`
|
|
8566
8367
|
);
|
|
8567
8368
|
}
|
|
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);
|
|
8369
|
+
};
|
|
8574
8370
|
}
|
|
8575
|
-
function
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8371
|
+
function getDebugPathHtml(workerNames, inspectorPort) {
|
|
8372
|
+
assert4(workerNames.length >= 1, "no workers present to debug");
|
|
8373
|
+
const workerDevtoolsUrls = workerNames.map((workerName) => {
|
|
8374
|
+
const localHost = `localhost:${inspectorPort}/${workerName}`;
|
|
8375
|
+
const searchParams = new URLSearchParams({
|
|
8376
|
+
theme: "systemPreferred",
|
|
8377
|
+
debugger: "true",
|
|
8378
|
+
ws: localHost,
|
|
8379
|
+
domain: workerName
|
|
8380
|
+
});
|
|
8381
|
+
const devtoolsFrontendUrl = `https://devtools.devprod.cloudflare.dev/js_app?${searchParams}`;
|
|
8382
|
+
return devtoolsFrontendUrl;
|
|
8383
|
+
});
|
|
8384
|
+
return `
|
|
8385
|
+
<script>
|
|
8386
|
+
const workerUrls = ${JSON.stringify(workerDevtoolsUrls)};
|
|
8387
|
+
const [firstUrl, ...rest] = workerUrls;
|
|
8388
|
+
for (const workerUrl of rest) {
|
|
8389
|
+
// open new tabs for the devtools of the various workers
|
|
8390
|
+
window.open(workerUrl);
|
|
8391
|
+
}
|
|
8392
|
+
// redirect the current tab to the devtools of the first worker
|
|
8393
|
+
window.location.replace(firstUrl);
|
|
8394
|
+
</script>
|
|
8395
|
+
`;
|
|
8583
8396
|
}
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8397
|
+
|
|
8398
|
+
// src/deploy-config.ts
|
|
8399
|
+
import assert5 from "node:assert";
|
|
8400
|
+
import * as fs2 from "node:fs";
|
|
8401
|
+
import * as path3 from "node:path";
|
|
8402
|
+
import "vite";
|
|
8403
|
+
import { unstable_readConfig } from "wrangler";
|
|
8404
|
+
function getDeployConfigPath(root) {
|
|
8405
|
+
return path3.resolve(root, ".wrangler", "deploy", "config.json");
|
|
8588
8406
|
}
|
|
8589
|
-
function
|
|
8590
|
-
const
|
|
8591
|
-
const
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8598
|
-
|
|
8599
|
-
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8407
|
+
function getWorkerConfigs(root) {
|
|
8408
|
+
const deployConfigPath = getDeployConfigPath(root);
|
|
8409
|
+
const deployConfig = JSON.parse(
|
|
8410
|
+
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
8411
|
+
);
|
|
8412
|
+
return [
|
|
8413
|
+
{ configPath: deployConfig.configPath },
|
|
8414
|
+
...deployConfig.auxiliaryWorkers
|
|
8415
|
+
].map(({ configPath }) => {
|
|
8416
|
+
const resolvedConfigPath = path3.resolve(
|
|
8417
|
+
path3.dirname(deployConfigPath),
|
|
8418
|
+
configPath
|
|
8419
|
+
);
|
|
8420
|
+
return unstable_readConfig({ config: resolvedConfigPath });
|
|
8421
|
+
});
|
|
8422
|
+
}
|
|
8423
|
+
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
8424
|
+
return path3.relative(
|
|
8425
|
+
deployConfigDirectory,
|
|
8426
|
+
path3.resolve(root, outputDirectory, "wrangler.json")
|
|
8427
|
+
);
|
|
8428
|
+
}
|
|
8429
|
+
function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
8430
|
+
const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
|
|
8431
|
+
const deployConfigDirectory = path3.dirname(deployConfigPath);
|
|
8432
|
+
fs2.mkdirSync(deployConfigDirectory, { recursive: true });
|
|
8433
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
8434
|
+
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
8435
|
+
assert5(
|
|
8436
|
+
clientOutputDirectory,
|
|
8437
|
+
"Unexpected error: client environment output directory is undefined"
|
|
8438
|
+
);
|
|
8439
|
+
const deployConfig = {
|
|
8440
|
+
configPath: getRelativePathToWorkerConfig(
|
|
8441
|
+
deployConfigDirectory,
|
|
8442
|
+
resolvedViteConfig.root,
|
|
8443
|
+
clientOutputDirectory
|
|
8444
|
+
),
|
|
8445
|
+
auxiliaryWorkers: []
|
|
8446
|
+
};
|
|
8447
|
+
fs2.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
8604
8448
|
} else {
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8449
|
+
let entryWorkerConfigPath;
|
|
8450
|
+
const auxiliaryWorkers = [];
|
|
8451
|
+
for (const environmentName of Object.keys(resolvedPluginConfig.workers)) {
|
|
8452
|
+
const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
|
|
8453
|
+
assert5(
|
|
8454
|
+
outputDirectory,
|
|
8455
|
+
`Unexpected error: ${environmentName} environment output directory is undefined`
|
|
8456
|
+
);
|
|
8457
|
+
const configPath = getRelativePathToWorkerConfig(
|
|
8458
|
+
deployConfigDirectory,
|
|
8459
|
+
resolvedViteConfig.root,
|
|
8460
|
+
outputDirectory
|
|
8461
|
+
);
|
|
8462
|
+
if (environmentName === resolvedPluginConfig.entryWorkerEnvironmentName) {
|
|
8463
|
+
entryWorkerConfigPath = configPath;
|
|
8464
|
+
} else {
|
|
8465
|
+
auxiliaryWorkers.push({ configPath });
|
|
8612
8466
|
}
|
|
8613
|
-
resolved = packageResolve(specifier, base, conditions);
|
|
8614
8467
|
}
|
|
8468
|
+
assert5(
|
|
8469
|
+
entryWorkerConfigPath,
|
|
8470
|
+
`Unexpected error: entryWorkerConfigPath is undefined`
|
|
8471
|
+
);
|
|
8472
|
+
const deployConfig = {
|
|
8473
|
+
configPath: entryWorkerConfigPath,
|
|
8474
|
+
auxiliaryWorkers
|
|
8475
|
+
};
|
|
8476
|
+
fs2.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
8615
8477
|
}
|
|
8616
|
-
assert5(resolved !== void 0, "expected to be defined");
|
|
8617
|
-
if (resolved.protocol !== "file:") {
|
|
8618
|
-
return resolved;
|
|
8619
|
-
}
|
|
8620
|
-
return finalizeResolution(resolved, base);
|
|
8621
8478
|
}
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8479
|
+
|
|
8480
|
+
// src/miniflare-options.ts
|
|
8481
|
+
import assert6 from "node:assert";
|
|
8482
|
+
import * as fs3 from "node:fs";
|
|
8483
|
+
import * as fsp from "node:fs/promises";
|
|
8484
|
+
import * as path4 from "node:path";
|
|
8485
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
8486
|
+
import {
|
|
8487
|
+
kCurrentWorker,
|
|
8488
|
+
Log,
|
|
8489
|
+
LogLevel,
|
|
8490
|
+
Response as MiniflareResponse
|
|
8491
|
+
} from "miniflare";
|
|
8492
|
+
import { globSync } from "tinyglobby";
|
|
8493
|
+
import "vite";
|
|
8494
|
+
import {
|
|
8495
|
+
unstable_getMiniflareWorkerOptions
|
|
8496
|
+
} from "wrangler";
|
|
8497
|
+
function getPersistence(root, persistState) {
|
|
8498
|
+
if (persistState === false) {
|
|
8499
|
+
return {};
|
|
8625
8500
|
}
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8501
|
+
const defaultPersistPath = ".wrangler/state";
|
|
8502
|
+
const persistPath = path4.resolve(
|
|
8503
|
+
root,
|
|
8504
|
+
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
8505
|
+
"v3"
|
|
8506
|
+
);
|
|
8507
|
+
return {
|
|
8508
|
+
cachePersist: path4.join(persistPath, "cache"),
|
|
8509
|
+
d1Persist: path4.join(persistPath, "d1"),
|
|
8510
|
+
durableObjectsPersist: path4.join(persistPath, "do"),
|
|
8511
|
+
kvPersist: path4.join(persistPath, "kv"),
|
|
8512
|
+
r2Persist: path4.join(persistPath, "r2"),
|
|
8513
|
+
workflowsPersist: path4.join(persistPath, "workflows")
|
|
8514
|
+
};
|
|
8630
8515
|
}
|
|
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));
|
|
8516
|
+
function missingWorkerErrorMessage(workerName) {
|
|
8517
|
+
return `${workerName} does not match a worker name.`;
|
|
8642
8518
|
}
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
if (!NOT_FOUND_ERRORS.has(error?.code)) {
|
|
8656
|
-
throw error;
|
|
8519
|
+
function getWorkerToWorkerEntrypointNamesMap(workers) {
|
|
8520
|
+
const workerToWorkerEntrypointNamesMap = new Map(
|
|
8521
|
+
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
8522
|
+
);
|
|
8523
|
+
for (const worker of workers) {
|
|
8524
|
+
for (const value of Object.values(worker.serviceBindings ?? {})) {
|
|
8525
|
+
if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
|
|
8526
|
+
const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
|
|
8527
|
+
const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
|
|
8528
|
+
assert6(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
|
|
8529
|
+
entrypointNames.add(value.entrypoint);
|
|
8530
|
+
}
|
|
8657
8531
|
}
|
|
8658
8532
|
}
|
|
8533
|
+
return workerToWorkerEntrypointNamesMap;
|
|
8659
8534
|
}
|
|
8660
|
-
function
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8535
|
+
function getWorkerToDurableObjectClassNamesMap(workers) {
|
|
8536
|
+
const workerToDurableObjectClassNamesMap = new Map(
|
|
8537
|
+
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
8538
|
+
);
|
|
8539
|
+
for (const worker of workers) {
|
|
8540
|
+
for (const value of Object.values(worker.durableObjects ?? {})) {
|
|
8541
|
+
if (typeof value === "string") {
|
|
8542
|
+
const classNames = workerToDurableObjectClassNamesMap.get(worker.name);
|
|
8543
|
+
assert6(classNames, missingWorkerErrorMessage(worker.name));
|
|
8544
|
+
classNames.add(value);
|
|
8545
|
+
} else if (typeof value === "object") {
|
|
8546
|
+
if (value.scriptName) {
|
|
8547
|
+
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
8548
|
+
value.scriptName
|
|
8549
|
+
);
|
|
8550
|
+
assert6(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
8551
|
+
classNames.add(value.className);
|
|
8552
|
+
} else {
|
|
8553
|
+
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
8554
|
+
worker.name
|
|
8555
|
+
);
|
|
8556
|
+
assert6(classNames, missingWorkerErrorMessage(worker.name));
|
|
8557
|
+
classNames.add(value.className);
|
|
8558
|
+
}
|
|
8559
|
+
}
|
|
8666
8560
|
}
|
|
8667
8561
|
}
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8562
|
+
return workerToDurableObjectClassNamesMap;
|
|
8563
|
+
}
|
|
8564
|
+
function getWorkerToWorkflowEntrypointClassNamesMap(workers) {
|
|
8565
|
+
const workerToWorkflowEntrypointClassNamesMap = new Map(
|
|
8566
|
+
workers.map((workerOptions) => [workerOptions.name, /* @__PURE__ */ new Set()])
|
|
8567
|
+
);
|
|
8568
|
+
for (const worker of workers) {
|
|
8569
|
+
for (const value of Object.values(worker.workflows ?? {})) {
|
|
8570
|
+
if (value.scriptName) {
|
|
8571
|
+
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
8572
|
+
value.scriptName
|
|
8573
|
+
);
|
|
8574
|
+
assert6(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
8575
|
+
classNames.add(value.className);
|
|
8576
|
+
} else {
|
|
8577
|
+
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
8578
|
+
worker.name
|
|
8579
|
+
);
|
|
8580
|
+
assert6(classNames, missingWorkerErrorMessage(worker.name));
|
|
8581
|
+
classNames.add(value.className);
|
|
8582
|
+
}
|
|
8583
|
+
}
|
|
8673
8584
|
}
|
|
8674
|
-
|
|
8675
|
-
|
|
8585
|
+
return workerToWorkflowEntrypointClassNamesMap;
|
|
8586
|
+
}
|
|
8587
|
+
var miniflareModulesRoot = process.platform === "win32" ? "Z:\\" : "/";
|
|
8588
|
+
var ROUTER_WORKER_PATH = "./asset-workers/router-worker.js";
|
|
8589
|
+
var ASSET_WORKER_PATH = "./asset-workers/asset-worker.js";
|
|
8590
|
+
var WRAPPER_PATH = "__VITE_WORKER_ENTRY__";
|
|
8591
|
+
var RUNNER_PATH = "./runner-worker/index.js";
|
|
8592
|
+
function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
8593
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
8594
|
+
return;
|
|
8676
8595
|
}
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8596
|
+
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
8597
|
+
}
|
|
8598
|
+
function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
8599
|
+
const resolvedViteConfig = viteDevServer.config;
|
|
8600
|
+
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
8601
|
+
const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
|
|
8602
|
+
const compatibilityOptions = resolvedPluginConfig.type === "assets-only" ? {
|
|
8603
|
+
compatibility_date: resolvedPluginConfig.config.compatibility_date,
|
|
8604
|
+
compatibility_flags: resolvedPluginConfig.config.compatibility_flags
|
|
8605
|
+
} : {
|
|
8606
|
+
...entryWorkerConfig?.compatibility_date ? { compatibility_date: entryWorkerConfig?.compatibility_date } : {},
|
|
8607
|
+
...entryWorkerConfig?.compatibility_flags ? { compatibility_flags: entryWorkerConfig?.compatibility_flags } : {}
|
|
8608
|
+
};
|
|
8609
|
+
const assetWorkers = [
|
|
8610
|
+
{
|
|
8611
|
+
name: ROUTER_WORKER_NAME,
|
|
8612
|
+
compatibilityDate: ASSET_WORKERS_COMPATIBILITY_DATE,
|
|
8613
|
+
modulesRoot: miniflareModulesRoot,
|
|
8614
|
+
modules: [
|
|
8615
|
+
{
|
|
8616
|
+
type: "ESModule",
|
|
8617
|
+
path: path4.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
|
|
8618
|
+
contents: fs3.readFileSync(
|
|
8619
|
+
fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
|
|
8620
|
+
)
|
|
8621
|
+
}
|
|
8622
|
+
],
|
|
8623
|
+
bindings: {
|
|
8624
|
+
CONFIG: {
|
|
8625
|
+
has_user_worker: resolvedPluginConfig.type === "workers"
|
|
8626
|
+
}
|
|
8627
|
+
},
|
|
8628
|
+
serviceBindings: {
|
|
8629
|
+
ASSET_WORKER: ASSET_WORKER_NAME,
|
|
8630
|
+
...entryWorkerConfig ? { USER_WORKER: entryWorkerConfig.name } : {}
|
|
8682
8631
|
}
|
|
8683
|
-
}
|
|
8684
|
-
|
|
8685
|
-
|
|
8632
|
+
},
|
|
8633
|
+
{
|
|
8634
|
+
name: ASSET_WORKER_NAME,
|
|
8635
|
+
compatibilityDate: ASSET_WORKERS_COMPATIBILITY_DATE,
|
|
8636
|
+
modulesRoot: miniflareModulesRoot,
|
|
8637
|
+
modules: [
|
|
8638
|
+
{
|
|
8639
|
+
type: "ESModule",
|
|
8640
|
+
path: path4.join(miniflareModulesRoot, ASSET_WORKER_PATH),
|
|
8641
|
+
contents: fs3.readFileSync(
|
|
8642
|
+
fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
|
|
8643
|
+
)
|
|
8644
|
+
}
|
|
8645
|
+
],
|
|
8646
|
+
bindings: {
|
|
8647
|
+
CONFIG: {
|
|
8648
|
+
...compatibilityOptions,
|
|
8649
|
+
...assetsConfig?.html_handling ? { html_handling: assetsConfig.html_handling } : {},
|
|
8650
|
+
...assetsConfig?.not_found_handling ? { not_found_handling: assetsConfig.not_found_handling } : {}
|
|
8651
|
+
}
|
|
8652
|
+
},
|
|
8653
|
+
serviceBindings: {
|
|
8654
|
+
__VITE_ASSET_EXISTS__: async (request) => {
|
|
8655
|
+
const { pathname } = new URL(request.url);
|
|
8656
|
+
const filePath = path4.join(resolvedViteConfig.root, pathname);
|
|
8657
|
+
let exists;
|
|
8658
|
+
try {
|
|
8659
|
+
exists = fs3.statSync(filePath).isFile();
|
|
8660
|
+
} catch (error) {
|
|
8661
|
+
exists = false;
|
|
8662
|
+
}
|
|
8663
|
+
return MiniflareResponse.json(exists);
|
|
8664
|
+
},
|
|
8665
|
+
__VITE_FETCH_ASSET__: async (request) => {
|
|
8666
|
+
const { pathname } = new URL(request.url);
|
|
8667
|
+
const filePath = path4.join(resolvedViteConfig.root, pathname);
|
|
8668
|
+
try {
|
|
8669
|
+
let html = await fsp.readFile(filePath, "utf-8");
|
|
8670
|
+
html = await viteDevServer.transformIndexHtml(pathname, html);
|
|
8671
|
+
return new MiniflareResponse(html, {
|
|
8672
|
+
headers: { "Content-Type": "text/html" }
|
|
8673
|
+
});
|
|
8674
|
+
} catch (error) {
|
|
8675
|
+
throw new Error(`Unexpected error. Failed to load ${pathname}`);
|
|
8676
|
+
}
|
|
8677
|
+
}
|
|
8686
8678
|
}
|
|
8687
8679
|
}
|
|
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)
|
|
8680
|
+
];
|
|
8681
|
+
const workersFromConfig = resolvedPluginConfig.type === "workers" ? Object.entries(resolvedPluginConfig.workers).map(
|
|
8682
|
+
([environmentName, workerConfig]) => {
|
|
8683
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
8684
|
+
{
|
|
8685
|
+
...workerConfig,
|
|
8686
|
+
assets: void 0
|
|
8687
|
+
},
|
|
8688
|
+
resolvedPluginConfig.cloudflareEnv
|
|
8703
8689
|
);
|
|
8690
|
+
const { externalWorkers: externalWorkers2 } = miniflareWorkerOptions;
|
|
8691
|
+
const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
8692
|
+
return {
|
|
8693
|
+
externalWorkers: externalWorkers2,
|
|
8694
|
+
worker: {
|
|
8695
|
+
...workerOptions,
|
|
8696
|
+
name: workerOptions.name ?? workerConfig.name,
|
|
8697
|
+
unsafeInspectorProxy: resolvedPluginConfig.inspectorPort !== false,
|
|
8698
|
+
modulesRoot: miniflareModulesRoot,
|
|
8699
|
+
unsafeEvalBinding: "__VITE_UNSAFE_EVAL__",
|
|
8700
|
+
serviceBindings: {
|
|
8701
|
+
...workerOptions.serviceBindings,
|
|
8702
|
+
...environmentName === resolvedPluginConfig.entryWorkerEnvironmentName && workerConfig.assets?.binding ? {
|
|
8703
|
+
[workerConfig.assets.binding]: ASSET_WORKER_NAME
|
|
8704
|
+
} : {},
|
|
8705
|
+
__VITE_INVOKE_MODULE__: async (request) => {
|
|
8706
|
+
const payload = await request.json();
|
|
8707
|
+
const invokePayloadData = payload.data;
|
|
8708
|
+
assert6(
|
|
8709
|
+
invokePayloadData.name === "fetchModule",
|
|
8710
|
+
`Invalid invoke event: ${invokePayloadData.name}`
|
|
8711
|
+
);
|
|
8712
|
+
const [moduleId] = invokePayloadData.data;
|
|
8713
|
+
if (additionalModuleRE.test(moduleId)) {
|
|
8714
|
+
const result2 = {
|
|
8715
|
+
externalize: moduleId,
|
|
8716
|
+
type: "module"
|
|
8717
|
+
};
|
|
8718
|
+
return MiniflareResponse.json({ result: result2 });
|
|
8719
|
+
}
|
|
8720
|
+
const devEnvironment = viteDevServer.environments[environmentName];
|
|
8721
|
+
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
8722
|
+
return MiniflareResponse.json(result);
|
|
8723
|
+
}
|
|
8724
|
+
}
|
|
8725
|
+
}
|
|
8726
|
+
};
|
|
8704
8727
|
}
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8728
|
+
) : [];
|
|
8729
|
+
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
8730
|
+
const externalWorkers = workersFromConfig.flatMap(
|
|
8731
|
+
(options) => options.externalWorkers
|
|
8732
|
+
);
|
|
8733
|
+
const workerToWorkerEntrypointNamesMap = getWorkerToWorkerEntrypointNamesMap(userWorkers);
|
|
8734
|
+
const workerToDurableObjectClassNamesMap = getWorkerToDurableObjectClassNamesMap(userWorkers);
|
|
8735
|
+
const workerToWorkflowEntrypointClassNamesMap = getWorkerToWorkflowEntrypointClassNamesMap(userWorkers);
|
|
8736
|
+
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
8737
|
+
return {
|
|
8738
|
+
log: logger,
|
|
8739
|
+
inspectorPort: resolvedPluginConfig.inspectorPort || void 0,
|
|
8740
|
+
unsafeInspectorProxy: resolvedPluginConfig.inspectorPort !== false,
|
|
8741
|
+
handleRuntimeStdio(stdout, stderr) {
|
|
8742
|
+
const decoder = new TextDecoder();
|
|
8743
|
+
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
8744
|
+
stderr.forEach(
|
|
8745
|
+
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
8746
|
+
);
|
|
8747
|
+
},
|
|
8748
|
+
...getPersistence(
|
|
8749
|
+
resolvedViteConfig.root,
|
|
8750
|
+
resolvedPluginConfig.persistState
|
|
8751
|
+
),
|
|
8752
|
+
workers: [
|
|
8753
|
+
...assetWorkers,
|
|
8754
|
+
...externalWorkers,
|
|
8755
|
+
...userWorkers.map((workerOptions) => {
|
|
8756
|
+
const wrappers = [
|
|
8757
|
+
`import { createWorkerEntrypointWrapper, createDurableObjectWrapper, createWorkflowEntrypointWrapper } from '${RUNNER_PATH}';`,
|
|
8758
|
+
`export default createWorkerEntrypointWrapper('default');`
|
|
8759
|
+
];
|
|
8760
|
+
const workerEntrypointNames = workerToWorkerEntrypointNamesMap.get(
|
|
8761
|
+
workerOptions.name
|
|
8718
8762
|
);
|
|
8719
|
-
|
|
8720
|
-
|
|
8763
|
+
assert6(
|
|
8764
|
+
workerEntrypointNames,
|
|
8765
|
+
`WorkerEntrypoint names not found for worker ${workerOptions.name}`
|
|
8766
|
+
);
|
|
8767
|
+
for (const entrypointName of [...workerEntrypointNames].sort()) {
|
|
8768
|
+
wrappers.push(
|
|
8769
|
+
`export const ${entrypointName} = createWorkerEntrypointWrapper('${entrypointName}');`
|
|
8770
|
+
);
|
|
8771
|
+
}
|
|
8772
|
+
const durableObjectClassNames = workerToDurableObjectClassNamesMap.get(
|
|
8773
|
+
workerOptions.name
|
|
8774
|
+
);
|
|
8775
|
+
assert6(
|
|
8776
|
+
durableObjectClassNames,
|
|
8777
|
+
`DurableObject class names not found for worker ${workerOptions.name}`
|
|
8778
|
+
);
|
|
8779
|
+
for (const className of [...durableObjectClassNames].sort()) {
|
|
8780
|
+
wrappers.push(
|
|
8781
|
+
`export const ${className} = createDurableObjectWrapper('${className}');`
|
|
8782
|
+
);
|
|
8783
|
+
}
|
|
8784
|
+
const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
|
|
8785
|
+
assert6(
|
|
8786
|
+
workflowEntrypointClassNames,
|
|
8787
|
+
`WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
|
|
8788
|
+
);
|
|
8789
|
+
for (const className of [...workflowEntrypointClassNames].sort()) {
|
|
8790
|
+
wrappers.push(
|
|
8791
|
+
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
8792
|
+
);
|
|
8793
|
+
}
|
|
8794
|
+
return {
|
|
8795
|
+
...workerOptions,
|
|
8796
|
+
modules: [
|
|
8797
|
+
{
|
|
8798
|
+
type: "ESModule",
|
|
8799
|
+
path: path4.join(miniflareModulesRoot, WRAPPER_PATH),
|
|
8800
|
+
contents: wrappers.join("\n")
|
|
8801
|
+
},
|
|
8802
|
+
{
|
|
8803
|
+
type: "ESModule",
|
|
8804
|
+
path: path4.join(miniflareModulesRoot, RUNNER_PATH),
|
|
8805
|
+
contents: fs3.readFileSync(
|
|
8806
|
+
fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
|
|
8807
|
+
)
|
|
8808
|
+
}
|
|
8809
|
+
],
|
|
8810
|
+
unsafeUseModuleFallbackService: true
|
|
8811
|
+
};
|
|
8812
|
+
})
|
|
8813
|
+
],
|
|
8814
|
+
async unsafeModuleFallbackService(request) {
|
|
8815
|
+
const url = new URL(request.url);
|
|
8816
|
+
const rawSpecifier = url.searchParams.get("rawSpecifier");
|
|
8817
|
+
assert6(
|
|
8818
|
+
rawSpecifier,
|
|
8819
|
+
`Unexpected error: no specifier in request to module fallback service.`
|
|
8820
|
+
);
|
|
8821
|
+
const match = additionalModuleRE.exec(rawSpecifier);
|
|
8822
|
+
assert6(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
|
|
8823
|
+
const [full, moduleType, modulePath] = match;
|
|
8824
|
+
assert6(
|
|
8825
|
+
moduleType,
|
|
8826
|
+
`Unexpected error: module type not found in reference: ${full}.`
|
|
8827
|
+
);
|
|
8828
|
+
assert6(
|
|
8829
|
+
modulePath,
|
|
8830
|
+
`Unexpected error: module path not found in reference: ${full}.`
|
|
8831
|
+
);
|
|
8832
|
+
let contents;
|
|
8833
|
+
try {
|
|
8834
|
+
contents = await fsp.readFile(modulePath);
|
|
8835
|
+
} catch (error) {
|
|
8836
|
+
throw new Error(
|
|
8837
|
+
`Import "${modulePath}" not found. Does the file exist?`
|
|
8838
|
+
);
|
|
8839
|
+
}
|
|
8840
|
+
switch (moduleType) {
|
|
8841
|
+
case "CompiledWasm": {
|
|
8842
|
+
return MiniflareResponse.json({ wasm: Array.from(contents) });
|
|
8843
|
+
}
|
|
8844
|
+
case "Data": {
|
|
8845
|
+
return MiniflareResponse.json({ data: Array.from(contents) });
|
|
8846
|
+
}
|
|
8847
|
+
case "Text": {
|
|
8848
|
+
return MiniflareResponse.json({ text: contents.toString() });
|
|
8849
|
+
}
|
|
8850
|
+
default: {
|
|
8851
|
+
return MiniflareResponse.error();
|
|
8721
8852
|
}
|
|
8722
8853
|
}
|
|
8723
|
-
if (resolved) {
|
|
8724
|
-
break;
|
|
8725
|
-
}
|
|
8726
|
-
}
|
|
8727
|
-
if (resolved) {
|
|
8728
|
-
break;
|
|
8729
8854
|
}
|
|
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));
|
|
8855
|
+
};
|
|
8745
8856
|
}
|
|
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;
|
|
8857
|
+
function getPreviewModules(main, modulesRules) {
|
|
8858
|
+
assert6(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
8859
|
+
const rootPath = path4.dirname(main);
|
|
8860
|
+
const entryPath = path4.basename(main);
|
|
8861
|
+
return {
|
|
8862
|
+
rootPath,
|
|
8863
|
+
modules: [
|
|
8864
|
+
{
|
|
8865
|
+
type: "ESModule",
|
|
8866
|
+
path: entryPath
|
|
8867
|
+
},
|
|
8868
|
+
...modulesRules.flatMap(
|
|
8869
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path8) => ({
|
|
8870
|
+
type,
|
|
8871
|
+
path: path8
|
|
8872
|
+
}))
|
|
8873
|
+
)
|
|
8874
|
+
]
|
|
8875
|
+
};
|
|
8772
8876
|
}
|
|
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);
|
|
8877
|
+
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort = DEFAULT_INSPECTOR_PORT) {
|
|
8878
|
+
const resolvedViteConfig = vitePreviewServer.config;
|
|
8879
|
+
const workers = workerConfigs.flatMap((config) => {
|
|
8880
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(config);
|
|
8881
|
+
const { externalWorkers } = miniflareWorkerOptions;
|
|
8882
|
+
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
8883
|
+
return [
|
|
8884
|
+
{
|
|
8885
|
+
...workerOptions,
|
|
8886
|
+
name: workerOptions.name ?? config.name,
|
|
8887
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
8888
|
+
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
8889
|
+
},
|
|
8890
|
+
...externalWorkers
|
|
8891
|
+
];
|
|
8892
|
+
});
|
|
8893
|
+
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
8793
8894
|
return {
|
|
8794
|
-
|
|
8795
|
-
|
|
8895
|
+
log: logger,
|
|
8896
|
+
inspectorPort: inspectorPort || void 0,
|
|
8897
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
8898
|
+
handleRuntimeStdio(stdout, stderr) {
|
|
8899
|
+
const decoder = new TextDecoder();
|
|
8900
|
+
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
8901
|
+
stderr.forEach(
|
|
8902
|
+
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
8903
|
+
);
|
|
8904
|
+
},
|
|
8905
|
+
...getPersistence(resolvedViteConfig.root, persistState),
|
|
8906
|
+
workers
|
|
8796
8907
|
};
|
|
8797
8908
|
}
|
|
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
|
-
};
|
|
8909
|
+
var ViteMiniflareLogger = class extends Log {
|
|
8910
|
+
logger;
|
|
8911
|
+
constructor(config) {
|
|
8912
|
+
super(miniflareLogLevelFromViteLogLevel(config.logLevel));
|
|
8913
|
+
this.logger = config.logger;
|
|
8811
8914
|
}
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
entries.add(globalInject[0]);
|
|
8915
|
+
logWithLevel(level, message) {
|
|
8916
|
+
if (/^Ready on http/.test(message)) {
|
|
8917
|
+
level = LogLevel.DEBUG;
|
|
8918
|
+
}
|
|
8919
|
+
switch (level) {
|
|
8920
|
+
case LogLevel.ERROR:
|
|
8921
|
+
return this.logger.error(message);
|
|
8922
|
+
case LogLevel.WARN:
|
|
8923
|
+
return this.logger.warn(message);
|
|
8924
|
+
case LogLevel.INFO:
|
|
8925
|
+
return this.logger.info(message);
|
|
8824
8926
|
}
|
|
8825
8927
|
}
|
|
8826
|
-
|
|
8827
|
-
|
|
8928
|
+
};
|
|
8929
|
+
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
8930
|
+
switch (level) {
|
|
8931
|
+
case "error":
|
|
8932
|
+
return LogLevel.ERROR;
|
|
8933
|
+
case "warn":
|
|
8934
|
+
return LogLevel.WARN;
|
|
8935
|
+
case "info":
|
|
8936
|
+
return LogLevel.INFO;
|
|
8937
|
+
case "silent":
|
|
8938
|
+
return LogLevel.NONE;
|
|
8939
|
+
}
|
|
8828
8940
|
}
|
|
8829
8941
|
|
|
8830
8942
|
// src/plugin-config.ts
|
|
8831
|
-
import
|
|
8943
|
+
import assert7 from "node:assert";
|
|
8832
8944
|
import * as path6 from "node:path";
|
|
8833
8945
|
import * as vite5 from "vite";
|
|
8834
8946
|
|
|
8835
8947
|
// src/workers-configs.ts
|
|
8836
|
-
import assert7 from "node:assert";
|
|
8837
8948
|
import * as fs4 from "node:fs";
|
|
8838
8949
|
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
|
|
8950
|
+
import { unstable_readConfig as unstable_readConfig3 } from "wrangler";
|
|
8845
8951
|
var nonApplicableWorkerConfigs = {
|
|
8846
8952
|
/**
|
|
8847
8953
|
* Object containing configs that have a vite replacement, the object's field contain details about the config's replacement
|
|
@@ -8870,14 +8976,11 @@ var nonApplicableWorkerConfigs = {
|
|
|
8870
8976
|
"find_additional_modules",
|
|
8871
8977
|
"no_bundle",
|
|
8872
8978
|
"preserve_file_names",
|
|
8979
|
+
"rules",
|
|
8873
8980
|
"site",
|
|
8874
8981
|
"tsconfig",
|
|
8875
8982
|
"upload_source_maps"
|
|
8876
|
-
]
|
|
8877
|
-
/**
|
|
8878
|
-
* All the configs that get overridden by our plugin
|
|
8879
|
-
*/
|
|
8880
|
-
overridden: ["rules"]
|
|
8983
|
+
]
|
|
8881
8984
|
};
|
|
8882
8985
|
var nullableNonApplicable = [
|
|
8883
8986
|
"alias",
|
|
@@ -8893,10 +8996,9 @@ var nullableNonApplicable = [
|
|
|
8893
8996
|
function readWorkerConfig(configPath, env2) {
|
|
8894
8997
|
const nonApplicable = {
|
|
8895
8998
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
8896
|
-
notRelevant: /* @__PURE__ */ new Set()
|
|
8897
|
-
overridden: /* @__PURE__ */ new Set()
|
|
8999
|
+
notRelevant: /* @__PURE__ */ new Set()
|
|
8898
9000
|
};
|
|
8899
|
-
const config =
|
|
9001
|
+
const config = unstable_readConfig3({ config: configPath, env: env2 }, {});
|
|
8900
9002
|
const raw = structuredClone(config);
|
|
8901
9003
|
nullableNonApplicable.forEach((prop) => {
|
|
8902
9004
|
if (config[prop] !== void 0) {
|
|
@@ -8906,9 +9008,6 @@ function readWorkerConfig(configPath, env2) {
|
|
|
8906
9008
|
if (isNotRelevant(prop)) {
|
|
8907
9009
|
nonApplicable.notRelevant.add(prop);
|
|
8908
9010
|
}
|
|
8909
|
-
if (isOverridden(prop)) {
|
|
8910
|
-
nonApplicable.overridden.add(prop);
|
|
8911
|
-
}
|
|
8912
9011
|
}
|
|
8913
9012
|
delete config[prop];
|
|
8914
9013
|
});
|
|
@@ -8921,7 +9020,7 @@ function readWorkerConfig(configPath, env2) {
|
|
|
8921
9020
|
}
|
|
8922
9021
|
delete config["define"];
|
|
8923
9022
|
if (config.rules.length > 0) {
|
|
8924
|
-
nonApplicable.
|
|
9023
|
+
nonApplicable.notRelevant.add("rules");
|
|
8925
9024
|
}
|
|
8926
9025
|
return {
|
|
8927
9026
|
raw,
|
|
@@ -8973,7 +9072,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
8973
9072
|
}
|
|
8974
9073
|
function getWorkerNonApplicableWarnLines(workerConfig, linePrefix) {
|
|
8975
9074
|
const lines = [];
|
|
8976
|
-
const { replacedByVite, notRelevant
|
|
9075
|
+
const { replacedByVite, notRelevant } = workerConfig.nonApplicable;
|
|
8977
9076
|
for (const config of replacedByVite) {
|
|
8978
9077
|
lines.push(
|
|
8979
9078
|
`${linePrefix}\`${config}\` which is replaced by Vite's \`${nonApplicableWorkerConfigs.replacedByVite[config].viteReplacement}\` (docs: ${nonApplicableWorkerConfigs.replacedByVite[config].viteDocs})`
|
|
@@ -8983,10 +9082,6 @@ function getWorkerNonApplicableWarnLines(workerConfig, linePrefix) {
|
|
|
8983
9082
|
lines.push(
|
|
8984
9083
|
`${linePrefix}${[...notRelevant].map((config) => `\`${config}\``).join(", ")} which ${notRelevant.size > 1 ? "are" : "is"} not relevant in the context of a Vite project`
|
|
8985
9084
|
);
|
|
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
9085
|
return lines;
|
|
8991
9086
|
}
|
|
8992
9087
|
function isReplacedByVite(configName) {
|
|
@@ -8995,9 +9090,6 @@ function isReplacedByVite(configName) {
|
|
|
8995
9090
|
function isNotRelevant(configName) {
|
|
8996
9091
|
return nonApplicableWorkerConfigs.notRelevant.includes(configName);
|
|
8997
9092
|
}
|
|
8998
|
-
function isOverridden(configName) {
|
|
8999
|
-
return nonApplicableWorkerConfigs.overridden.includes(configName);
|
|
9000
|
-
}
|
|
9001
9093
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
9002
9094
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
9003
9095
|
}
|
|
@@ -9007,42 +9099,55 @@ function getWorkerConfig(configPath, env2, opts) {
|
|
|
9007
9099
|
}
|
|
9008
9100
|
const { raw, config, nonApplicable } = readWorkerConfig(configPath, env2);
|
|
9009
9101
|
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)
|
|
9102
|
+
if (!config.name) {
|
|
9103
|
+
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
9104
|
+
}
|
|
9105
|
+
if (!config.topLevelName) {
|
|
9106
|
+
throw new Error(
|
|
9107
|
+
missingFieldErrorMessage(`top-level 'name'`, configPath, env2)
|
|
9108
|
+
);
|
|
9109
|
+
}
|
|
9110
|
+
if (!config.compatibility_date) {
|
|
9111
|
+
throw new Error(
|
|
9112
|
+
missingFieldErrorMessage(`'compatibility_date`, configPath, env2)
|
|
9023
9113
|
);
|
|
9114
|
+
}
|
|
9115
|
+
const requiredFields = {
|
|
9116
|
+
topLevelName: config.topLevelName,
|
|
9117
|
+
name: config.name,
|
|
9118
|
+
compatibility_date: config.compatibility_date
|
|
9119
|
+
};
|
|
9120
|
+
if (opts?.isEntryWorker && !config.main) {
|
|
9024
9121
|
return {
|
|
9025
9122
|
type: "assets-only",
|
|
9026
9123
|
raw,
|
|
9027
9124
|
config: {
|
|
9028
9125
|
...config,
|
|
9029
|
-
|
|
9030
|
-
name: config.name,
|
|
9031
|
-
compatibility_date: config.compatibility_date,
|
|
9032
|
-
assets: config.assets
|
|
9126
|
+
...requiredFields
|
|
9033
9127
|
},
|
|
9034
9128
|
nonApplicable
|
|
9035
9129
|
};
|
|
9036
9130
|
}
|
|
9037
|
-
|
|
9131
|
+
if (!config.main) {
|
|
9132
|
+
throw new Error(missingFieldErrorMessage(`'main'`, configPath, env2));
|
|
9133
|
+
}
|
|
9134
|
+
const mainStat = fs4.statSync(config.main, { throwIfNoEntry: false });
|
|
9135
|
+
if (!mainStat) {
|
|
9136
|
+
throw new Error(
|
|
9137
|
+
`The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
|
|
9138
|
+
);
|
|
9139
|
+
}
|
|
9140
|
+
if (mainStat.isDirectory()) {
|
|
9141
|
+
throw new Error(
|
|
9142
|
+
`The provided Wrangler config main field (${config.main}) points to a directory, it needs to point to a file instead`
|
|
9143
|
+
);
|
|
9144
|
+
}
|
|
9038
9145
|
return {
|
|
9039
9146
|
type: "worker",
|
|
9040
9147
|
raw,
|
|
9041
9148
|
config: {
|
|
9042
9149
|
...config,
|
|
9043
|
-
|
|
9044
|
-
name: config.name,
|
|
9045
|
-
compatibility_date: config.compatibility_date,
|
|
9150
|
+
...requiredFields,
|
|
9046
9151
|
main: config.main
|
|
9047
9152
|
},
|
|
9048
9153
|
nonApplicable
|
|
@@ -9064,6 +9169,7 @@ function workerNameToEnvironmentName(workerName) {
|
|
|
9064
9169
|
function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
9065
9170
|
const configPaths = /* @__PURE__ */ new Set();
|
|
9066
9171
|
const persistState = pluginConfig.persistState ?? true;
|
|
9172
|
+
const inspectorPort = pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT;
|
|
9067
9173
|
const root = userConfig.root ? path6.resolve(userConfig.root) : process.cwd();
|
|
9068
9174
|
const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
|
|
9069
9175
|
viteEnv.mode,
|
|
@@ -9072,10 +9178,11 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9072
9178
|
""
|
|
9073
9179
|
);
|
|
9074
9180
|
const configPath = pluginConfig.configPath ? path6.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9181
|
+
if (!configPath) {
|
|
9182
|
+
throw new Error(
|
|
9183
|
+
`Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
|
|
9184
|
+
);
|
|
9185
|
+
}
|
|
9079
9186
|
const entryWorkerResolvedConfig = getWorkerConfig(configPath, cloudflareEnv, {
|
|
9080
9187
|
visitedConfigPaths: configPaths,
|
|
9081
9188
|
isEntryWorker: true
|
|
@@ -9085,6 +9192,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9085
9192
|
type: "assets-only",
|
|
9086
9193
|
config: entryWorkerResolvedConfig.config,
|
|
9087
9194
|
configPaths,
|
|
9195
|
+
inspectorPort,
|
|
9088
9196
|
persistState,
|
|
9089
9197
|
rawConfigs: {
|
|
9090
9198
|
entryWorker: entryWorkerResolvedConfig
|
|
@@ -9107,7 +9215,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9107
9215
|
}
|
|
9108
9216
|
);
|
|
9109
9217
|
auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
|
|
9110
|
-
|
|
9218
|
+
assert7(
|
|
9111
9219
|
workerResolvedConfig.type === "worker",
|
|
9112
9220
|
"Unexpected error: received AssetsOnlyResult with auxiliary workers."
|
|
9113
9221
|
);
|
|
@@ -9124,6 +9232,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9124
9232
|
type: "workers",
|
|
9125
9233
|
configPaths,
|
|
9126
9234
|
persistState,
|
|
9235
|
+
inspectorPort,
|
|
9127
9236
|
workers,
|
|
9128
9237
|
entryWorkerEnvironmentName,
|
|
9129
9238
|
rawConfigs: {
|
|
@@ -9135,8 +9244,9 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9135
9244
|
}
|
|
9136
9245
|
|
|
9137
9246
|
// src/websockets.ts
|
|
9247
|
+
import { coupleWebSocket } from "miniflare";
|
|
9138
9248
|
import { WebSocketServer } from "ws";
|
|
9139
|
-
function handleWebSocket(httpServer, fetcher
|
|
9249
|
+
function handleWebSocket(httpServer, fetcher) {
|
|
9140
9250
|
const nodeWebSocket = new WebSocketServer({ noServer: true });
|
|
9141
9251
|
httpServer.on(
|
|
9142
9252
|
"upgrade",
|
|
@@ -9160,34 +9270,7 @@ function handleWebSocket(httpServer, fetcher, logger) {
|
|
|
9160
9270
|
socket,
|
|
9161
9271
|
head,
|
|
9162
9272
|
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
|
-
});
|
|
9273
|
+
coupleWebSocket(clientWebSocket, workerWebSocket);
|
|
9191
9274
|
nodeWebSocket.emit("connection", clientWebSocket, request);
|
|
9192
9275
|
}
|
|
9193
9276
|
);
|
|
@@ -9196,14 +9279,18 @@ ${error.stack || error.message}`, {
|
|
|
9196
9279
|
}
|
|
9197
9280
|
|
|
9198
9281
|
// src/index.ts
|
|
9282
|
+
var workersConfigsWarningShown = false;
|
|
9199
9283
|
function cloudflare2(pluginConfig = {}) {
|
|
9200
9284
|
let resolvedPluginConfig;
|
|
9201
9285
|
let resolvedViteConfig;
|
|
9202
9286
|
let miniflare;
|
|
9203
|
-
|
|
9287
|
+
const additionalModulePaths = /* @__PURE__ */ new Set();
|
|
9288
|
+
let hasClientBuild = false;
|
|
9204
9289
|
return [
|
|
9205
9290
|
{
|
|
9206
9291
|
name: "vite-plugin-cloudflare",
|
|
9292
|
+
// This only applies to this plugin so is safe to use while other plugins migrate to the Environment API
|
|
9293
|
+
sharedDuringBuild: true,
|
|
9207
9294
|
config(userConfig, env2) {
|
|
9208
9295
|
if (env2.isPreview) {
|
|
9209
9296
|
return { appType: "custom" };
|
|
@@ -9260,7 +9347,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9260
9347
|
resolvedPluginConfig.workers
|
|
9261
9348
|
).map((environmentName) => {
|
|
9262
9349
|
const environment = builder.environments[environmentName];
|
|
9263
|
-
|
|
9350
|
+
assert8(
|
|
9264
9351
|
environment,
|
|
9265
9352
|
`${environmentName} environment not found`
|
|
9266
9353
|
);
|
|
@@ -9276,6 +9363,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9276
9363
|
}
|
|
9277
9364
|
};
|
|
9278
9365
|
},
|
|
9366
|
+
buildStart() {
|
|
9367
|
+
workersConfigsWarningShown = false;
|
|
9368
|
+
},
|
|
9279
9369
|
configResolved(config) {
|
|
9280
9370
|
resolvedViteConfig = config;
|
|
9281
9371
|
},
|
|
@@ -9290,18 +9380,27 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9290
9380
|
return;
|
|
9291
9381
|
}
|
|
9292
9382
|
workerConfig.main = entryChunk[0];
|
|
9383
|
+
workerConfig.no_bundle = true;
|
|
9384
|
+
workerConfig.rules = [
|
|
9385
|
+
{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
|
|
9386
|
+
];
|
|
9293
9387
|
const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
|
|
9294
|
-
if (isEntryWorker &&
|
|
9388
|
+
if (isEntryWorker && hasClientBuild) {
|
|
9295
9389
|
const workerOutputDirectory = this.environment.config.build.outDir;
|
|
9296
9390
|
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
9297
|
-
|
|
9391
|
+
assert8(
|
|
9298
9392
|
clientOutputDirectory,
|
|
9299
9393
|
"Unexpected error: client output directory is undefined"
|
|
9300
9394
|
);
|
|
9301
|
-
workerConfig.assets
|
|
9302
|
-
|
|
9303
|
-
path7.
|
|
9304
|
-
|
|
9395
|
+
workerConfig.assets = {
|
|
9396
|
+
...workerConfig.assets,
|
|
9397
|
+
directory: path7.relative(
|
|
9398
|
+
path7.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
9399
|
+
path7.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
9400
|
+
)
|
|
9401
|
+
};
|
|
9402
|
+
} else {
|
|
9403
|
+
workerConfig.assets = void 0;
|
|
9305
9404
|
}
|
|
9306
9405
|
config = workerConfig;
|
|
9307
9406
|
if (workerConfig.configPath) {
|
|
@@ -9319,7 +9418,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9319
9418
|
}
|
|
9320
9419
|
} else if (this.environment.name === "client") {
|
|
9321
9420
|
const assetsOnlyConfig = resolvedPluginConfig.config;
|
|
9322
|
-
assetsOnlyConfig.assets
|
|
9421
|
+
assetsOnlyConfig.assets = {
|
|
9422
|
+
...assetsOnlyConfig.assets,
|
|
9423
|
+
directory: "."
|
|
9424
|
+
};
|
|
9323
9425
|
const filesToAssetsIgnore = ["wrangler.json", ".dev.vars"];
|
|
9324
9426
|
this.emitFile({
|
|
9325
9427
|
type: "asset",
|
|
@@ -9332,8 +9434,6 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9332
9434
|
if (!config) {
|
|
9333
9435
|
return;
|
|
9334
9436
|
}
|
|
9335
|
-
config.no_bundle = true;
|
|
9336
|
-
config.rules = [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }];
|
|
9337
9437
|
if (config.unsafe && Object.keys(config.unsafe).length === 0) {
|
|
9338
9438
|
config.unsafe = void 0;
|
|
9339
9439
|
}
|
|
@@ -9344,6 +9444,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9344
9444
|
});
|
|
9345
9445
|
},
|
|
9346
9446
|
writeBundle() {
|
|
9447
|
+
if (this.environment.name === "client") {
|
|
9448
|
+
hasClientBuild = true;
|
|
9449
|
+
}
|
|
9347
9450
|
if (this.environment.name === (resolvedPluginConfig.type === "assets-only" ? "client" : resolvedPluginConfig.entryWorkerEnvironmentName)) {
|
|
9348
9451
|
writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
|
|
9349
9452
|
}
|
|
@@ -9360,7 +9463,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9360
9463
|
}
|
|
9361
9464
|
},
|
|
9362
9465
|
async configureServer(viteDevServer) {
|
|
9363
|
-
|
|
9466
|
+
assert8(
|
|
9364
9467
|
viteDevServer.httpServer,
|
|
9365
9468
|
"Unexpected error: No Vite HTTP server"
|
|
9366
9469
|
);
|
|
@@ -9368,23 +9471,16 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9368
9471
|
getDevMiniflareOptions(resolvedPluginConfig, viteDevServer)
|
|
9369
9472
|
);
|
|
9370
9473
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
9371
|
-
const
|
|
9372
|
-
resolvedPluginConfig,
|
|
9373
|
-
miniflare
|
|
9374
|
-
);
|
|
9474
|
+
const routerWorker = await getRouterWorker(miniflare);
|
|
9375
9475
|
const middleware = createMiddleware(
|
|
9376
9476
|
({ request }) => {
|
|
9377
|
-
return
|
|
9477
|
+
return routerWorker.fetch(toMiniflareRequest(request), {
|
|
9378
9478
|
redirect: "manual"
|
|
9379
9479
|
});
|
|
9380
9480
|
},
|
|
9381
9481
|
{ alwaysCallNext: false }
|
|
9382
9482
|
);
|
|
9383
|
-
handleWebSocket(
|
|
9384
|
-
viteDevServer.httpServer,
|
|
9385
|
-
entryWorker.fetch,
|
|
9386
|
-
viteDevServer.config.logger
|
|
9387
|
-
);
|
|
9483
|
+
handleWebSocket(viteDevServer.httpServer, routerWorker.fetch);
|
|
9388
9484
|
return () => {
|
|
9389
9485
|
viteDevServer.middlewares.use((req, res, next) => {
|
|
9390
9486
|
middleware(req, res, next);
|
|
@@ -9392,10 +9488,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9392
9488
|
};
|
|
9393
9489
|
},
|
|
9394
9490
|
configurePreviewServer(vitePreviewServer) {
|
|
9491
|
+
const workerConfigs = getWorkerConfigs(vitePreviewServer.config.root);
|
|
9395
9492
|
const miniflare2 = new Miniflare(
|
|
9396
9493
|
getPreviewMiniflareOptions(
|
|
9397
9494
|
vitePreviewServer,
|
|
9398
|
-
|
|
9495
|
+
workerConfigs,
|
|
9496
|
+
pluginConfig.persistState ?? true,
|
|
9497
|
+
pluginConfig.inspectorPort
|
|
9399
9498
|
)
|
|
9400
9499
|
);
|
|
9401
9500
|
const middleware = createMiddleware(
|
|
@@ -9406,58 +9505,80 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9406
9505
|
},
|
|
9407
9506
|
{ alwaysCallNext: false }
|
|
9408
9507
|
);
|
|
9409
|
-
handleWebSocket(
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9508
|
+
handleWebSocket(vitePreviewServer.httpServer, miniflare2.dispatchFetch);
|
|
9509
|
+
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
9510
|
+
middleware(req, res, next);
|
|
9511
|
+
});
|
|
9512
|
+
}
|
|
9513
|
+
},
|
|
9514
|
+
// Plugin to support `.wasm?init` extension
|
|
9515
|
+
{
|
|
9516
|
+
name: "vite-plugin-cloudflare:wasm-helper",
|
|
9517
|
+
enforce: "pre",
|
|
9518
|
+
applyToEnvironment(environment) {
|
|
9519
|
+
return getWorkerConfig2(environment.name) !== void 0;
|
|
9520
|
+
},
|
|
9521
|
+
load(id) {
|
|
9522
|
+
if (!id.endsWith(".wasm?init")) {
|
|
9523
|
+
return;
|
|
9524
|
+
}
|
|
9525
|
+
return `
|
|
9526
|
+
import wasm from "${cleanUrl(id)}";
|
|
9527
|
+
export default function(opts = {}) {
|
|
9528
|
+
return WebAssembly.instantiate(wasm, opts);
|
|
9529
|
+
}
|
|
9530
|
+
`;
|
|
9419
9531
|
}
|
|
9420
9532
|
},
|
|
9421
|
-
// Plugin to support
|
|
9533
|
+
// Plugin to support additional modules
|
|
9422
9534
|
{
|
|
9423
|
-
name: "vite-plugin-cloudflare:modules",
|
|
9535
|
+
name: "vite-plugin-cloudflare:additional-modules",
|
|
9424
9536
|
// We set `enforce: "pre"` so that this plugin runs before the Vite core plugins.
|
|
9425
9537
|
// Otherwise the `vite:wasm-fallback` plugin prevents the `.wasm` extension being used for module imports.
|
|
9426
9538
|
enforce: "pre",
|
|
9427
9539
|
applyToEnvironment(environment) {
|
|
9428
9540
|
return getWorkerConfig2(environment.name) !== void 0;
|
|
9429
9541
|
},
|
|
9430
|
-
async resolveId(source, importer) {
|
|
9431
|
-
|
|
9542
|
+
async resolveId(source, importer, options) {
|
|
9543
|
+
const additionalModuleType = matchAdditionalModule(source);
|
|
9544
|
+
if (!additionalModuleType) {
|
|
9432
9545
|
return;
|
|
9433
9546
|
}
|
|
9434
|
-
const resolved = await this.resolve(
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9547
|
+
const resolved = await this.resolve(
|
|
9548
|
+
cleanUrl(source),
|
|
9549
|
+
importer,
|
|
9550
|
+
options
|
|
9438
9551
|
);
|
|
9552
|
+
if (!resolved) {
|
|
9553
|
+
throw new Error(`Import "${source}" not found. Does the file exist?`);
|
|
9554
|
+
}
|
|
9555
|
+
additionalModulePaths.add(resolved.id);
|
|
9439
9556
|
return {
|
|
9440
9557
|
external: true,
|
|
9441
|
-
id: createModuleReference(
|
|
9558
|
+
id: createModuleReference(additionalModuleType, resolved.id)
|
|
9442
9559
|
};
|
|
9443
9560
|
},
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9561
|
+
hotUpdate(options) {
|
|
9562
|
+
if (additionalModulePaths.has(options.file)) {
|
|
9563
|
+
options.server.restart();
|
|
9564
|
+
}
|
|
9565
|
+
},
|
|
9566
|
+
async renderChunk(code, chunk) {
|
|
9567
|
+
const matches = code.matchAll(additionalModuleGlobalRE);
|
|
9447
9568
|
let magicString;
|
|
9448
|
-
|
|
9569
|
+
for (const match of matches) {
|
|
9449
9570
|
magicString ??= new MagicString(code);
|
|
9450
|
-
const [full,
|
|
9451
|
-
|
|
9571
|
+
const [full, _, modulePath] = match;
|
|
9572
|
+
assert8(
|
|
9452
9573
|
modulePath,
|
|
9453
9574
|
`Unexpected error: module path not found in reference ${full}.`
|
|
9454
9575
|
);
|
|
9455
9576
|
let source;
|
|
9456
9577
|
try {
|
|
9457
|
-
source =
|
|
9578
|
+
source = await fsp2.readFile(modulePath);
|
|
9458
9579
|
} catch (error) {
|
|
9459
9580
|
throw new Error(
|
|
9460
|
-
`Import ${modulePath} not found. Does the file exist?`
|
|
9581
|
+
`Import "${modulePath}" not found. Does the file exist?`
|
|
9461
9582
|
);
|
|
9462
9583
|
}
|
|
9463
9584
|
const referenceId = this.emitFile({
|
|
@@ -9491,8 +9612,8 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9491
9612
|
apply(_config, env2) {
|
|
9492
9613
|
return !env2.isPreview;
|
|
9493
9614
|
},
|
|
9494
|
-
configEnvironment(
|
|
9495
|
-
if (isNodeCompat(getWorkerConfig2(
|
|
9615
|
+
configEnvironment(name) {
|
|
9616
|
+
if (isNodeCompat(getWorkerConfig2(name))) {
|
|
9496
9617
|
return {
|
|
9497
9618
|
resolve: {
|
|
9498
9619
|
builtins: [...nodeCompatExternals]
|
|
@@ -9531,7 +9652,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9531
9652
|
return this.resolve(source, importer, options);
|
|
9532
9653
|
}
|
|
9533
9654
|
if (this.environment.mode === "dev") {
|
|
9534
|
-
|
|
9655
|
+
assert8(
|
|
9535
9656
|
this.environment.depsOptimizer,
|
|
9536
9657
|
"depsOptimizer is required in dev mode"
|
|
9537
9658
|
);
|
|
@@ -9545,16 +9666,63 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9545
9666
|
},
|
|
9546
9667
|
async transform(code, id) {
|
|
9547
9668
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
9548
|
-
|
|
9669
|
+
assert8(workerConfig, "Expected a worker config");
|
|
9549
9670
|
const resolvedId = await this.resolve(workerConfig.main);
|
|
9550
9671
|
if (id === resolvedId?.id) {
|
|
9551
9672
|
return injectGlobalCode(id, code);
|
|
9552
9673
|
}
|
|
9553
9674
|
}
|
|
9675
|
+
},
|
|
9676
|
+
// Plugin that provides an __debug path for debugging the Cloudflare Workers.
|
|
9677
|
+
{
|
|
9678
|
+
name: "vite-plugin-cloudflare:debug",
|
|
9679
|
+
// Note: this plugin needs to run before the main vite-plugin-cloudflare so that
|
|
9680
|
+
// the preview middleware here can take precedence
|
|
9681
|
+
enforce: "pre",
|
|
9682
|
+
configureServer(viteDevServer) {
|
|
9683
|
+
if (resolvedPluginConfig.type === "workers" && resolvedPluginConfig.inspectorPort !== false) {
|
|
9684
|
+
addDebugToVitePrintUrls(viteDevServer);
|
|
9685
|
+
}
|
|
9686
|
+
const workerNames = resolvedPluginConfig.type === "assets-only" ? [] : Object.values(resolvedPluginConfig.workers).map(
|
|
9687
|
+
(worker) => worker.name
|
|
9688
|
+
);
|
|
9689
|
+
viteDevServer.middlewares.use((req, res, next) => {
|
|
9690
|
+
if (req.url === debuggingPath && resolvedPluginConfig.inspectorPort !== false) {
|
|
9691
|
+
const html = getDebugPathHtml(
|
|
9692
|
+
workerNames,
|
|
9693
|
+
resolvedPluginConfig.inspectorPort
|
|
9694
|
+
);
|
|
9695
|
+
res.setHeader("Content-Type", "text/html");
|
|
9696
|
+
return res.end(html);
|
|
9697
|
+
}
|
|
9698
|
+
next();
|
|
9699
|
+
});
|
|
9700
|
+
},
|
|
9701
|
+
configurePreviewServer(vitePreviewServer) {
|
|
9702
|
+
const workerConfigs = getWorkerConfigs(vitePreviewServer.config.root);
|
|
9703
|
+
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
9704
|
+
addDebugToVitePrintUrls(vitePreviewServer);
|
|
9705
|
+
}
|
|
9706
|
+
const workerNames = workerConfigs.map((worker) => {
|
|
9707
|
+
assert8(worker.name);
|
|
9708
|
+
return worker.name;
|
|
9709
|
+
});
|
|
9710
|
+
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
9711
|
+
if (req.url === debuggingPath && pluginConfig.inspectorPort !== false) {
|
|
9712
|
+
const html = getDebugPathHtml(
|
|
9713
|
+
workerNames,
|
|
9714
|
+
pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT
|
|
9715
|
+
);
|
|
9716
|
+
res.setHeader("Content-Type", "text/html");
|
|
9717
|
+
return res.end(html);
|
|
9718
|
+
}
|
|
9719
|
+
next();
|
|
9720
|
+
});
|
|
9721
|
+
}
|
|
9554
9722
|
}
|
|
9555
9723
|
];
|
|
9556
9724
|
function getWorkerConfig2(environmentName) {
|
|
9557
|
-
|
|
9725
|
+
assert8(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
|
|
9558
9726
|
return resolvedPluginConfig.type !== "assets-only" ? resolvedPluginConfig.workers[environmentName] : void 0;
|
|
9559
9727
|
}
|
|
9560
9728
|
}
|
|
@@ -9569,9 +9737,6 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
|
9569
9737
|
}
|
|
9570
9738
|
return null;
|
|
9571
9739
|
}
|
|
9572
|
-
function createModuleReference(type, id) {
|
|
9573
|
-
return `__CLOUDFLARE_MODULE__${type}__${id}__`;
|
|
9574
|
-
}
|
|
9575
9740
|
export {
|
|
9576
9741
|
cloudflare2 as cloudflare
|
|
9577
9742
|
};
|