wrangler 2.0.11 → 2.0.12
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/kv-asset-handler.js +1 -0
- package/package.json +3 -1
- package/src/__tests__/configuration.test.ts +221 -142
- package/src/__tests__/dev.test.tsx +27 -0
- package/src/__tests__/index.test.ts +2 -1
- package/src/__tests__/kv.test.ts +23 -2
- package/src/__tests__/publish.test.ts +173 -54
- package/src/bundle.ts +9 -5
- package/src/config/environment.ts +1 -1
- package/src/config/validation.ts +22 -13
- package/src/dev/dev.tsx +29 -45
- package/src/dev/local.tsx +10 -7
- package/src/dev/remote.tsx +4 -1
- package/src/dev/use-esbuild.ts +1 -4
- package/src/index.tsx +236 -180
- package/src/kv.ts +1 -1
- package/src/parse.ts +21 -1
- package/src/proxy.ts +19 -6
- package/src/publish.ts +6 -1
- package/src/sites.tsx +1 -3
- package/templates/static-asset-facade.js +1 -5
- package/wrangler-dist/cli.js +73310 -73243
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { setTimeout } from "node:timers/promises";
|
|
5
5
|
import TOML from "@iarna/toml";
|
|
6
6
|
import chalk from "chalk";
|
|
7
|
+
import { watch } from "chokidar";
|
|
7
8
|
import { execa } from "execa";
|
|
8
9
|
import { findUp } from "find-up";
|
|
9
10
|
import getPort from "get-port";
|
|
@@ -47,6 +48,7 @@ import {
|
|
|
47
48
|
parsePackageJSON,
|
|
48
49
|
parseTOML,
|
|
49
50
|
readFileSync,
|
|
51
|
+
readFileSyncToBuffer,
|
|
50
52
|
} from "./parse";
|
|
51
53
|
import publish from "./publish";
|
|
52
54
|
import { createR2Bucket, deleteR2Bucket, listR2Buckets } from "./r2";
|
|
@@ -1035,197 +1037,235 @@ function createCLIParser(argv: string[]) {
|
|
|
1035
1037
|
});
|
|
1036
1038
|
},
|
|
1037
1039
|
async (args) => {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
(
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
)
|
|
1054
|
-
.
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
"Passing --inspect is unnecessary, now you can always connect to devtools."
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1040
|
+
let watcher: ReturnType<typeof watch> | undefined;
|
|
1041
|
+
try {
|
|
1042
|
+
await printWranglerBanner();
|
|
1043
|
+
const configPath =
|
|
1044
|
+
(args.config as ConfigPath) ||
|
|
1045
|
+
((args.script &&
|
|
1046
|
+
findWranglerToml(path.dirname(args.script))) as ConfigPath);
|
|
1047
|
+
let config = readConfig(configPath, args);
|
|
1048
|
+
|
|
1049
|
+
if (config.configPath) {
|
|
1050
|
+
watcher = watch(config.configPath, {
|
|
1051
|
+
persistent: true,
|
|
1052
|
+
}).on("change", async (_event) => {
|
|
1053
|
+
// TODO: Do we need to handle different `_event` types differently?
|
|
1054
|
+
// e.g. what if the file is deleted, or added?
|
|
1055
|
+
config = readConfig(configPath, args);
|
|
1056
|
+
if (config.configPath) {
|
|
1057
|
+
logger.log(`${path.basename(config.configPath)} changed...`);
|
|
1058
|
+
rerender(await getDevReactElement(config));
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1063
1062
|
|
|
1064
|
-
|
|
1065
|
-
logger.warn(
|
|
1066
|
-
"The --experimental-public field is experimental and will change in the future."
|
|
1067
|
-
);
|
|
1068
|
-
}
|
|
1063
|
+
const entry = await getEntry(args, config, "dev");
|
|
1069
1064
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1065
|
+
if (config.services && config.services.length > 0) {
|
|
1066
|
+
logger.warn(
|
|
1067
|
+
`This worker is bound to live services: ${config.services
|
|
1068
|
+
.map(
|
|
1069
|
+
(service) =>
|
|
1070
|
+
`${service.binding} (${service.service}${
|
|
1071
|
+
service.environment ? `@${service.environment}` : ""
|
|
1072
|
+
})`
|
|
1073
|
+
)
|
|
1074
|
+
.join(", ")}`
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1075
1077
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
"If this is required in your project, please add your use case to the following issue:\n" +
|
|
1082
|
-
"https://github.com/cloudflare/wrangler2/issues/583."
|
|
1083
|
-
);
|
|
1084
|
-
}
|
|
1078
|
+
if (args.inspect) {
|
|
1079
|
+
logger.warn(
|
|
1080
|
+
"Passing --inspect is unnecessary, now you can always connect to devtools."
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1085
1083
|
|
|
1086
|
-
|
|
1084
|
+
if (args["experimental-public"]) {
|
|
1085
|
+
logger.warn(
|
|
1086
|
+
"The --experimental-public field is experimental and will change in the future."
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1087
1089
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1090
|
+
if (args["experimental-public"] && (args.site || config.site)) {
|
|
1091
|
+
throw new Error(
|
|
1092
|
+
"Cannot use --experimental-public and a Site configuration together."
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1091
1095
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1096
|
+
if (args.public) {
|
|
1097
|
+
throw new Error(
|
|
1098
|
+
"The --public field has been renamed to --experimental-public, and will change behaviour in the future."
|
|
1099
|
+
);
|
|
1095
1100
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1101
|
+
|
|
1102
|
+
const upstreamProtocol =
|
|
1103
|
+
args["upstream-protocol"] || config.dev.upstream_protocol;
|
|
1104
|
+
if (upstreamProtocol === "http") {
|
|
1105
|
+
logger.warn(
|
|
1106
|
+
"Setting upstream-protocol to http is not currently implemented.\n" +
|
|
1107
|
+
"If this is required in your project, please add your use case to the following issue:\n" +
|
|
1108
|
+
"https://github.com/cloudflare/wrangler2/issues/583."
|
|
1109
|
+
);
|
|
1104
1110
|
}
|
|
1105
|
-
}
|
|
1106
1111
|
|
|
1107
|
-
|
|
1108
|
-
if (nodeCompat) {
|
|
1109
|
-
logger.warn(
|
|
1110
|
-
"Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1112
|
+
// TODO: if worker_dev = false and no routes, then error (only for dev)
|
|
1113
1113
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
// This whole block of code will be obsoleted in the future
|
|
1122
|
-
// when we have copy-on-write for previews on edge workers.
|
|
1123
|
-
if (!preview_id) {
|
|
1124
|
-
// TODO: This error has to be a _lot_ better, ideally just asking
|
|
1125
|
-
// to create a preview namespace for the user automatically
|
|
1126
|
-
throw new Error(
|
|
1127
|
-
`In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your wrangler.toml`
|
|
1128
|
-
); // Ugh, I really don't like this message very much
|
|
1129
|
-
}
|
|
1130
|
-
return {
|
|
1131
|
-
binding,
|
|
1132
|
-
id: preview_id,
|
|
1133
|
-
};
|
|
1114
|
+
// Compute zone info from the `host` and `route` args and config;
|
|
1115
|
+
let host = args.host || config.dev.host;
|
|
1116
|
+
let zoneId: string | undefined;
|
|
1117
|
+
|
|
1118
|
+
if (!args.local) {
|
|
1119
|
+
if (host) {
|
|
1120
|
+
zoneId = await getZoneIdFromHost(host);
|
|
1134
1121
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
r2_buckets: config.r2_buckets?.map(
|
|
1143
|
-
({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
|
|
1144
|
-
// same idea as kv namespace preview id,
|
|
1145
|
-
// same copy-on-write TODO
|
|
1146
|
-
if (!preview_bucket_name) {
|
|
1147
|
-
throw new Error(
|
|
1148
|
-
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
|
|
1149
|
-
);
|
|
1122
|
+
const routes = args.routes || config.route || config.routes;
|
|
1123
|
+
if (!zoneId && routes) {
|
|
1124
|
+
const firstRoute = Array.isArray(routes) ? routes[0] : routes;
|
|
1125
|
+
const zone = await getZoneForRoute(firstRoute);
|
|
1126
|
+
if (zone) {
|
|
1127
|
+
zoneId = zone.id;
|
|
1128
|
+
host = zone.host;
|
|
1150
1129
|
}
|
|
1151
|
-
return {
|
|
1152
|
-
binding,
|
|
1153
|
-
bucket_name: preview_bucket_name,
|
|
1154
|
-
};
|
|
1155
1130
|
}
|
|
1156
|
-
|
|
1157
|
-
services: config.services,
|
|
1158
|
-
unsafe: config.unsafe?.bindings,
|
|
1159
|
-
};
|
|
1131
|
+
}
|
|
1160
1132
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
// This means it was overridden in .dev.vars
|
|
1167
|
-
// so let's mask it
|
|
1168
|
-
maskedVars[key] = "(hidden)";
|
|
1133
|
+
const nodeCompat = args.nodeCompat ?? config.node_compat;
|
|
1134
|
+
if (nodeCompat) {
|
|
1135
|
+
logger.warn(
|
|
1136
|
+
"Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
|
|
1137
|
+
);
|
|
1169
1138
|
}
|
|
1170
|
-
}
|
|
1171
1139
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1140
|
+
// eslint-disable-next-line no-inner-declarations
|
|
1141
|
+
async function getBindings(configParam: Config) {
|
|
1142
|
+
return {
|
|
1143
|
+
kv_namespaces: configParam.kv_namespaces?.map(
|
|
1144
|
+
({ binding, preview_id, id: _id }) => {
|
|
1145
|
+
// In `dev`, we make folks use a separate kv namespace called
|
|
1146
|
+
// `preview_id` instead of `id` so that they don't
|
|
1147
|
+
// break production data. So here we check that a `preview_id`
|
|
1148
|
+
// has actually been configured.
|
|
1149
|
+
// This whole block of code will be obsoleted in the future
|
|
1150
|
+
// when we have copy-on-write for previews on edge workers.
|
|
1151
|
+
if (!preview_id) {
|
|
1152
|
+
// TODO: This error has to be a _lot_ better, ideally just asking
|
|
1153
|
+
// to create a preview namespace for the user automatically
|
|
1154
|
+
throw new Error(
|
|
1155
|
+
`In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your wrangler.toml`
|
|
1156
|
+
); // Ugh, I really don't like this message very much
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
binding,
|
|
1160
|
+
id: preview_id,
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
),
|
|
1164
|
+
// Use a copy of combinedVars since we're modifying it later
|
|
1165
|
+
vars: getVarsForDev(configParam),
|
|
1166
|
+
wasm_modules: configParam.wasm_modules,
|
|
1167
|
+
text_blobs: configParam.text_blobs,
|
|
1168
|
+
data_blobs: configParam.data_blobs,
|
|
1169
|
+
durable_objects: configParam.durable_objects,
|
|
1170
|
+
r2_buckets: configParam.r2_buckets?.map(
|
|
1171
|
+
({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
|
|
1172
|
+
// same idea as kv namespace preview id,
|
|
1173
|
+
// same copy-on-write TODO
|
|
1174
|
+
if (!preview_bucket_name) {
|
|
1175
|
+
throw new Error(
|
|
1176
|
+
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
return {
|
|
1180
|
+
binding,
|
|
1181
|
+
bucket_name: preview_bucket_name,
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
),
|
|
1185
|
+
services: configParam.services,
|
|
1186
|
+
unsafe: configParam.unsafe?.bindings,
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1177
1189
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
upstreamProtocol={upstreamProtocol}
|
|
1195
|
-
localProtocol={args["local-protocol"] || config.dev.local_protocol}
|
|
1196
|
-
enableLocalPersistence={
|
|
1197
|
-
args["experimental-enable-local-persistence"] || false
|
|
1198
|
-
}
|
|
1199
|
-
accountId={config.account_id}
|
|
1200
|
-
assetPaths={getAssetPaths(
|
|
1201
|
-
config,
|
|
1202
|
-
args.site,
|
|
1203
|
-
args.siteInclude,
|
|
1204
|
-
args.siteExclude
|
|
1205
|
-
)}
|
|
1206
|
-
port={
|
|
1207
|
-
args.port ||
|
|
1208
|
-
config.dev.port ||
|
|
1209
|
-
(await getPort({ port: DEFAULT_LOCAL_PORT }))
|
|
1210
|
-
}
|
|
1211
|
-
ip={args.ip || config.dev.ip}
|
|
1212
|
-
inspectorPort={
|
|
1213
|
-
args["inspector-port"] ?? (await getPort({ port: 9229 }))
|
|
1214
|
-
}
|
|
1215
|
-
public={args["experimental-public"]}
|
|
1216
|
-
compatibilityDate={getDevCompatibilityDate(
|
|
1217
|
-
config,
|
|
1218
|
-
args["compatibility-date"]
|
|
1219
|
-
)}
|
|
1220
|
-
compatibilityFlags={
|
|
1221
|
-
args["compatibility-flags"] || config.compatibility_flags
|
|
1190
|
+
const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
|
|
1191
|
+
const getInspectorPort = memoizeGetPort(9229);
|
|
1192
|
+
|
|
1193
|
+
// eslint-disable-next-line no-inner-declarations
|
|
1194
|
+
async function getDevReactElement(configParam: Config) {
|
|
1195
|
+
// now log all available bindings into the terminal
|
|
1196
|
+
const bindings = await getBindings(configParam);
|
|
1197
|
+
// mask anything that was overridden in .dev.vars
|
|
1198
|
+
// so that we don't log potential secrets into the terminal
|
|
1199
|
+
const maskedVars = { ...bindings.vars };
|
|
1200
|
+
for (const key of Object.keys(maskedVars)) {
|
|
1201
|
+
if (maskedVars[key] !== configParam.vars[key]) {
|
|
1202
|
+
// This means it was overridden in .dev.vars
|
|
1203
|
+
// so let's mask it
|
|
1204
|
+
maskedVars[key] = "(hidden)";
|
|
1205
|
+
}
|
|
1222
1206
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1207
|
+
|
|
1208
|
+
printBindings({
|
|
1209
|
+
...bindings,
|
|
1210
|
+
vars: maskedVars,
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
return (
|
|
1214
|
+
<Dev
|
|
1215
|
+
name={getScriptName(args, config)}
|
|
1216
|
+
entry={entry}
|
|
1217
|
+
env={args.env}
|
|
1218
|
+
zone={zoneId}
|
|
1219
|
+
host={host}
|
|
1220
|
+
rules={getRules(config)}
|
|
1221
|
+
legacyEnv={isLegacyEnv(config)}
|
|
1222
|
+
minify={args.minify ?? config.minify}
|
|
1223
|
+
nodeCompat={nodeCompat}
|
|
1224
|
+
build={config.build || {}}
|
|
1225
|
+
initialMode={args.local ? "local" : "remote"}
|
|
1226
|
+
jsxFactory={args["jsx-factory"] || config.jsx_factory}
|
|
1227
|
+
jsxFragment={args["jsx-fragment"] || config.jsx_fragment}
|
|
1228
|
+
tsconfig={args.tsconfig ?? config.tsconfig}
|
|
1229
|
+
upstreamProtocol={upstreamProtocol}
|
|
1230
|
+
localProtocol={
|
|
1231
|
+
args["local-protocol"] || config.dev.local_protocol
|
|
1232
|
+
}
|
|
1233
|
+
enableLocalPersistence={
|
|
1234
|
+
args["experimental-enable-local-persistence"] || false
|
|
1235
|
+
}
|
|
1236
|
+
accountId={config.account_id}
|
|
1237
|
+
assetPaths={getAssetPaths(
|
|
1238
|
+
config,
|
|
1239
|
+
args["experimental-public"] || args.site,
|
|
1240
|
+
args.siteInclude,
|
|
1241
|
+
args.siteExclude
|
|
1242
|
+
)}
|
|
1243
|
+
port={args.port || config.dev.port || (await getLocalPort())}
|
|
1244
|
+
ip={args.ip || config.dev.ip}
|
|
1245
|
+
inspectorPort={
|
|
1246
|
+
args["inspector-port"] ?? (await getInspectorPort())
|
|
1247
|
+
}
|
|
1248
|
+
public={args["experimental-public"]}
|
|
1249
|
+
compatibilityDate={getDevCompatibilityDate(
|
|
1250
|
+
config,
|
|
1251
|
+
args["compatibility-date"]
|
|
1252
|
+
)}
|
|
1253
|
+
compatibilityFlags={
|
|
1254
|
+
args["compatibility-flags"] || config.compatibility_flags
|
|
1255
|
+
}
|
|
1256
|
+
usageModel={config.usage_model}
|
|
1257
|
+
bindings={bindings}
|
|
1258
|
+
crons={config.triggers.crons}
|
|
1259
|
+
/>
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
const { waitUntilExit, rerender } = render(
|
|
1263
|
+
await getDevReactElement(config)
|
|
1264
|
+
);
|
|
1265
|
+
await waitUntilExit();
|
|
1266
|
+
} finally {
|
|
1267
|
+
await watcher?.close();
|
|
1268
|
+
}
|
|
1229
1269
|
}
|
|
1230
1270
|
);
|
|
1231
1271
|
|
|
@@ -1351,23 +1391,29 @@ function createCLIParser(argv: string[]) {
|
|
|
1351
1391
|
},
|
|
1352
1392
|
async (args) => {
|
|
1353
1393
|
await printWranglerBanner();
|
|
1394
|
+
|
|
1395
|
+
const configPath =
|
|
1396
|
+
(args.config as ConfigPath) ||
|
|
1397
|
+
(args.script && findWranglerToml(path.dirname(args.script)));
|
|
1398
|
+
const config = readConfig(configPath, args);
|
|
1399
|
+
const entry = await getEntry(args, config, "publish");
|
|
1400
|
+
|
|
1354
1401
|
if (args["experimental-public"]) {
|
|
1355
1402
|
logger.warn(
|
|
1356
1403
|
"The --experimental-public field is experimental and will change in the future."
|
|
1357
1404
|
);
|
|
1358
1405
|
}
|
|
1406
|
+
if (args["experimental-public"] && (args.site || config.site)) {
|
|
1407
|
+
throw new Error(
|
|
1408
|
+
"Cannot use --experimental-public and a Site configuration together."
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1359
1411
|
if (args.public) {
|
|
1360
1412
|
throw new Error(
|
|
1361
1413
|
"The --public field has been renamed to --experimental-public, and will change behaviour in the future."
|
|
1362
1414
|
);
|
|
1363
1415
|
}
|
|
1364
1416
|
|
|
1365
|
-
const configPath =
|
|
1366
|
-
(args.config as ConfigPath) ||
|
|
1367
|
-
(args.script && findWranglerToml(path.dirname(args.script)));
|
|
1368
|
-
const config = readConfig(configPath, args);
|
|
1369
|
-
const entry = await getEntry(args, config, "publish");
|
|
1370
|
-
|
|
1371
1417
|
if (args.latest) {
|
|
1372
1418
|
logger.warn(
|
|
1373
1419
|
"Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml.\n"
|
|
@@ -2227,7 +2273,7 @@ function createCLIParser(argv: string[]) {
|
|
|
2227
2273
|
const namespaceId = getKVNamespaceId(args, config);
|
|
2228
2274
|
// One of `args.path` and `args.value` must be defined
|
|
2229
2275
|
const value = args.path
|
|
2230
|
-
?
|
|
2276
|
+
? readFileSyncToBuffer(args.path)
|
|
2231
2277
|
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2232
2278
|
args.value!;
|
|
2233
2279
|
|
|
@@ -2801,3 +2847,13 @@ function getDevCompatibilityDate(
|
|
|
2801
2847
|
}
|
|
2802
2848
|
return compatibilityDate ?? currentDate;
|
|
2803
2849
|
}
|
|
2850
|
+
|
|
2851
|
+
/**
|
|
2852
|
+
* Avoiding calling `getPort()` multiple times by memoizing the first result.
|
|
2853
|
+
*/
|
|
2854
|
+
function memoizeGetPort(defaultPort: number) {
|
|
2855
|
+
let portValue: number;
|
|
2856
|
+
return async () => {
|
|
2857
|
+
return portValue || (portValue = await getPort({ port: defaultPort }));
|
|
2858
|
+
};
|
|
2859
|
+
}
|
package/src/kv.ts
CHANGED
package/src/parse.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import TOML from "@iarna/toml";
|
|
4
4
|
import { formatMessagesSync } from "esbuild";
|
|
5
|
+
import { logger } from "./logger";
|
|
5
6
|
|
|
6
7
|
export type Message = {
|
|
7
8
|
text: string;
|
|
@@ -38,7 +39,7 @@ export function formatMessage(
|
|
|
38
39
|
const lines = formatMessagesSync([input], {
|
|
39
40
|
color,
|
|
40
41
|
kind: kind,
|
|
41
|
-
terminalWidth:
|
|
42
|
+
terminalWidth: logger.columns,
|
|
42
43
|
});
|
|
43
44
|
return lines.join("\n");
|
|
44
45
|
}
|
|
@@ -138,6 +139,25 @@ export function parseJSON<T>(input: string, file?: string): T {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Reads a file into a node Buffer.
|
|
144
|
+
*/
|
|
145
|
+
export function readFileSyncToBuffer(file: string): Buffer {
|
|
146
|
+
try {
|
|
147
|
+
return fs.readFileSync(file);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
const { message } = err as Error;
|
|
150
|
+
throw new ParseError({
|
|
151
|
+
text: `Could not read file: ${file}`,
|
|
152
|
+
notes: [
|
|
153
|
+
{
|
|
154
|
+
text: message.replace(file, resolve(file)),
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
141
161
|
/**
|
|
142
162
|
* Reads a file and parses it based on its type.
|
|
143
163
|
*/
|
package/src/proxy.ts
CHANGED
|
@@ -100,7 +100,10 @@ export function usePreviewServer({
|
|
|
100
100
|
.then((server) => {
|
|
101
101
|
setProxy({
|
|
102
102
|
server,
|
|
103
|
-
terminator: createHttpTerminator({
|
|
103
|
+
terminator: createHttpTerminator({
|
|
104
|
+
server,
|
|
105
|
+
gracefulTerminationTimeout: 0,
|
|
106
|
+
}),
|
|
104
107
|
});
|
|
105
108
|
})
|
|
106
109
|
.catch(async (err) => {
|
|
@@ -330,7 +333,9 @@ export function usePreviewServer({
|
|
|
330
333
|
abortController.abort();
|
|
331
334
|
// Running `proxy.server.close()` does not close open connections, preventing the process from exiting.
|
|
332
335
|
// So we use this `terminator` to close all the connections and force the server to shutdown.
|
|
333
|
-
proxy.terminator
|
|
336
|
+
proxy.terminator
|
|
337
|
+
.terminate()
|
|
338
|
+
.catch(() => logger.error("Failed to terminate the proxy server."));
|
|
334
339
|
};
|
|
335
340
|
}, [port, ip, proxy, localProtocol]);
|
|
336
341
|
}
|
|
@@ -450,16 +455,24 @@ export async function waitForPortToBeAvailable(
|
|
|
450
455
|
// trying to make a server listen on that port, and retrying
|
|
451
456
|
// until it succeeds.
|
|
452
457
|
const server = createHttpServer();
|
|
458
|
+
const terminator = createHttpTerminator({
|
|
459
|
+
server,
|
|
460
|
+
gracefulTerminationTimeout: 0, // default 1000
|
|
461
|
+
});
|
|
462
|
+
|
|
453
463
|
server.on("error", (err) => {
|
|
454
464
|
// @ts-expect-error non standard property on Error
|
|
455
465
|
if (err.code !== "EADDRINUSE") {
|
|
456
466
|
doReject(err);
|
|
457
467
|
}
|
|
458
468
|
});
|
|
459
|
-
server.listen(port, () =>
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
469
|
+
server.listen(port, () =>
|
|
470
|
+
terminator
|
|
471
|
+
.terminate()
|
|
472
|
+
.then(doResolve, () =>
|
|
473
|
+
logger.error("Failed to terminate the port checker.")
|
|
474
|
+
)
|
|
475
|
+
);
|
|
463
476
|
}
|
|
464
477
|
});
|
|
465
478
|
}
|
package/src/publish.ts
CHANGED
|
@@ -430,7 +430,12 @@ export default async function publish(props: Props): Promise<void> {
|
|
|
430
430
|
method: "PUT",
|
|
431
431
|
body: createWorkerUploadForm(worker),
|
|
432
432
|
},
|
|
433
|
-
new URLSearchParams({
|
|
433
|
+
new URLSearchParams({
|
|
434
|
+
include_subdomain_availability: "true",
|
|
435
|
+
// pass excludeScript so the whole body of the
|
|
436
|
+
// script doesn't get included in the response
|
|
437
|
+
excludeScript: "true",
|
|
438
|
+
})
|
|
434
439
|
)
|
|
435
440
|
).available_on_subdomain;
|
|
436
441
|
}
|
package/src/sites.tsx
CHANGED
|
@@ -200,9 +200,7 @@ export async function syncAssets(
|
|
|
200
200
|
namespaceKeys.delete(assetKey);
|
|
201
201
|
|
|
202
202
|
// Prevent different manifest keys on windows
|
|
203
|
-
const manifestKey = urlSafe(
|
|
204
|
-
path.relative(siteAssets.assetDirectory, absAssetFile)
|
|
205
|
-
);
|
|
203
|
+
const manifestKey = urlSafe(path.relative(assetDirectory, absAssetFile));
|
|
206
204
|
manifest[manifestKey] = assetKey;
|
|
207
205
|
}
|
|
208
206
|
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
// DO NOT IMPORT THIS DIRECTLY
|
|
2
2
|
import worker from "__ENTRY_POINT__";
|
|
3
|
-
import { getAssetFromKV } from "
|
|
3
|
+
import { getAssetFromKV } from "__KV_ASSET_HANDLER__";
|
|
4
4
|
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
5
5
|
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
6
6
|
|
|
7
|
-
// TODO: remove this
|
|
8
|
-
globalThis.__STATIC_CONTENT = undefined;
|
|
9
|
-
globalThis.__STATIC_CONTENT_MANIFEST = undefined;
|
|
10
|
-
|
|
11
7
|
export default {
|
|
12
8
|
async fetch(request, env, ctx) {
|
|
13
9
|
let options = {
|