wrangler 2.5.0 → 2.6.1
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/miniflare-dist/index.mjs +99 -56
- package/package.json +3 -3
- package/src/__tests__/configuration.test.ts +211 -0
- package/src/__tests__/dev.test.tsx +17 -0
- package/src/__tests__/init.test.ts +18 -3
- package/src/__tests__/metrics.test.ts +88 -43
- package/src/__tests__/pages-deployment-tail.test.ts +165 -101
- package/src/__tests__/publish.test.ts +94 -7
- package/src/__tests__/pubsub.test.ts +208 -88
- package/src/__tests__/tail.test.ts +1 -1
- package/src/__tests__/type-generation.test.ts +7 -0
- package/src/config/environment.ts +16 -0
- package/src/config/index.ts +31 -8
- package/src/config/validation.ts +49 -0
- package/src/create-worker-upload-form.ts +9 -0
- package/src/dev/local.tsx +48 -18
- package/src/dev/start-server.ts +1 -5
- package/src/dev.tsx +23 -2
- package/src/git-client.ts +15 -4
- package/src/index.tsx +1 -0
- package/src/init.ts +8 -0
- package/src/miniflare-cli/assets.ts +55 -29
- package/src/miniflare-cli/index.ts +1 -0
- package/src/pages/dev.tsx +7 -0
- package/src/publish/publish.ts +1 -0
- package/src/secret/index.ts +1 -0
- package/src/type-generation.ts +10 -2
- package/src/worker.ts +6 -0
- package/wrangler-dist/cli.d.ts +15 -0
- package/wrangler-dist/cli.js +1844 -473
package/miniflare-dist/index.mjs
CHANGED
|
@@ -128,23 +128,45 @@ var init_environment_polyfills = __esm({
|
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
+
// ../pages-shared/environment-polyfills/miniflare-tre.ts
|
|
132
|
+
var miniflare_tre_exports = {};
|
|
133
|
+
__export(miniflare_tre_exports, {
|
|
134
|
+
default: () => miniflare_tre_default
|
|
135
|
+
});
|
|
136
|
+
var miniflare_tre_default;
|
|
137
|
+
var init_miniflare_tre = __esm({
|
|
138
|
+
"../pages-shared/environment-polyfills/miniflare-tre.ts"() {
|
|
139
|
+
init_environment_polyfills();
|
|
140
|
+
miniflare_tre_default = async () => {
|
|
141
|
+
const mf = await import("@miniflare/tre");
|
|
142
|
+
polyfill({
|
|
143
|
+
fetch: mf.fetch,
|
|
144
|
+
Headers: mf.Headers,
|
|
145
|
+
Request: mf.Request,
|
|
146
|
+
Response: mf.Response
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
131
152
|
// ../pages-shared/environment-polyfills/miniflare.ts
|
|
132
153
|
var miniflare_exports = {};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
Response as MiniflareResponse
|
|
138
|
-
} from "@miniflare/core";
|
|
154
|
+
__export(miniflare_exports, {
|
|
155
|
+
default: () => miniflare_default
|
|
156
|
+
});
|
|
157
|
+
var miniflare_default;
|
|
139
158
|
var init_miniflare = __esm({
|
|
140
159
|
"../pages-shared/environment-polyfills/miniflare.ts"() {
|
|
141
160
|
init_environment_polyfills();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
miniflare_default = async () => {
|
|
162
|
+
const mf = await import("@miniflare/core");
|
|
163
|
+
polyfill({
|
|
164
|
+
fetch: mf.fetch,
|
|
165
|
+
Headers: mf.Headers,
|
|
166
|
+
Request: mf.Request,
|
|
167
|
+
Response: mf.Response
|
|
168
|
+
});
|
|
169
|
+
};
|
|
148
170
|
}
|
|
149
171
|
});
|
|
150
172
|
|
|
@@ -329,6 +351,15 @@ var init_rulesEngine = __esm({
|
|
|
329
351
|
}
|
|
330
352
|
});
|
|
331
353
|
|
|
354
|
+
// ../pages-shared/asset-server/url.ts
|
|
355
|
+
function stringifyURLToRootRelativePathname(url) {
|
|
356
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
357
|
+
}
|
|
358
|
+
var init_url = __esm({
|
|
359
|
+
"../pages-shared/asset-server/url.ts"() {
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
332
363
|
// ../pages-shared/asset-server/handler.ts
|
|
333
364
|
var handler_exports = {};
|
|
334
365
|
__export(handler_exports, {
|
|
@@ -339,6 +370,7 @@ __export(handler_exports, {
|
|
|
339
370
|
HEADERS_VERSION_V1: () => HEADERS_VERSION_V1,
|
|
340
371
|
REDIRECTS_VERSION: () => REDIRECTS_VERSION2,
|
|
341
372
|
generateHandler: () => generateHandler,
|
|
373
|
+
getResponseFromMatch: () => getResponseFromMatch,
|
|
342
374
|
normaliseHeaders: () => normaliseHeaders,
|
|
343
375
|
parseQualityWeightedList: () => parseQualityWeightedList
|
|
344
376
|
});
|
|
@@ -409,22 +441,7 @@ async function generateHandler({
|
|
|
409
441
|
async function generateResponse() {
|
|
410
442
|
const match = staticRedirectsMatcher() || generateRedirectsMatcher()({ request })[0];
|
|
411
443
|
if (match) {
|
|
412
|
-
|
|
413
|
-
const destination = new URL(to, request.url);
|
|
414
|
-
const location = destination.origin === new URL(request.url).origin ? `${destination.pathname}${destination.search || search}${destination.hash}` : `${destination.href}${destination.search ? "" : search}${destination.hash}`;
|
|
415
|
-
switch (status) {
|
|
416
|
-
case 301:
|
|
417
|
-
return new MovedPermanentlyResponse(location);
|
|
418
|
-
case 303:
|
|
419
|
-
return new SeeOtherResponse(location);
|
|
420
|
-
case 307:
|
|
421
|
-
return new TemporaryRedirectResponse(location);
|
|
422
|
-
case 308:
|
|
423
|
-
return new PermanentRedirectResponse(location);
|
|
424
|
-
case 302:
|
|
425
|
-
default:
|
|
426
|
-
return new FoundResponse(location);
|
|
427
|
-
}
|
|
444
|
+
return getResponseFromMatch(match, url);
|
|
428
445
|
}
|
|
429
446
|
if (!request.method.match(/^(get|head)$/i)) {
|
|
430
447
|
return new MethodNotAllowedResponse();
|
|
@@ -703,6 +720,27 @@ async function generateHandler({
|
|
|
703
720
|
);
|
|
704
721
|
}
|
|
705
722
|
}
|
|
723
|
+
function getResponseFromMatch({
|
|
724
|
+
status,
|
|
725
|
+
to
|
|
726
|
+
}, requestUrl) {
|
|
727
|
+
const destination = new URL(to, requestUrl);
|
|
728
|
+
destination.search = destination.search || requestUrl.search;
|
|
729
|
+
const location = destination.origin === requestUrl.origin ? stringifyURLToRootRelativePathname(destination) : destination.toString();
|
|
730
|
+
switch (status) {
|
|
731
|
+
case 301:
|
|
732
|
+
return new MovedPermanentlyResponse(location);
|
|
733
|
+
case 303:
|
|
734
|
+
return new SeeOtherResponse(location);
|
|
735
|
+
case 307:
|
|
736
|
+
return new TemporaryRedirectResponse(location);
|
|
737
|
+
case 308:
|
|
738
|
+
return new PermanentRedirectResponse(location);
|
|
739
|
+
case 302:
|
|
740
|
+
default:
|
|
741
|
+
return new FoundResponse(location);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
706
744
|
function parseQualityWeightedList(list = "") {
|
|
707
745
|
const items = {};
|
|
708
746
|
list.replace(/\s/g, "").split(",").forEach((el) => {
|
|
@@ -728,6 +766,7 @@ var init_handler = __esm({
|
|
|
728
766
|
"../pages-shared/asset-server/handler.ts"() {
|
|
729
767
|
init_responses();
|
|
730
768
|
init_rulesEngine();
|
|
769
|
+
init_url();
|
|
731
770
|
ASSET_PRESERVATION_CACHE = "assetPreservationCache";
|
|
732
771
|
CACHE_CONTROL_PRESERVATION = "public, s-maxage=604800";
|
|
733
772
|
CACHE_CONTROL_BROWSER = "public, max-age=0, must-revalidate";
|
|
@@ -749,8 +788,8 @@ import {
|
|
|
749
788
|
Log as MiniflareLog,
|
|
750
789
|
LogLevel as MiniflareLogLevel,
|
|
751
790
|
Miniflare,
|
|
752
|
-
Request as
|
|
753
|
-
Response as
|
|
791
|
+
Request as MiniflareRequest,
|
|
792
|
+
Response as MiniflareResponse
|
|
754
793
|
} from "miniflare";
|
|
755
794
|
|
|
756
795
|
// ../../node_modules/yargs/lib/platform-shims/esm.mjs
|
|
@@ -5632,7 +5671,11 @@ function constructRedirects({
|
|
|
5632
5671
|
for (const rule of redirects.rules) {
|
|
5633
5672
|
if (!rule.from.match(SPLAT_REGEX) && !rule.from.match(PLACEHOLDER_REGEX)) {
|
|
5634
5673
|
if (canCreateStaticRule) {
|
|
5635
|
-
staticRedirects[rule.from] = {
|
|
5674
|
+
staticRedirects[rule.from] = {
|
|
5675
|
+
status: rule.status,
|
|
5676
|
+
to: rule.to,
|
|
5677
|
+
lineNumber: rule.lineNumber
|
|
5678
|
+
};
|
|
5636
5679
|
continue;
|
|
5637
5680
|
} else {
|
|
5638
5681
|
logger(
|
|
@@ -5974,11 +6017,6 @@ function parseRedirects(input) {
|
|
|
5974
6017
|
|
|
5975
6018
|
// src/miniflare-cli/assets.ts
|
|
5976
6019
|
var import_mime = __toESM(require_mime());
|
|
5977
|
-
import {
|
|
5978
|
-
Response as MiniflareResponse2,
|
|
5979
|
-
Request as MiniflareRequest2
|
|
5980
|
-
} from "@miniflare/core";
|
|
5981
|
-
import { upgradingFetch as miniflareFetch2 } from "@miniflare/web-sockets";
|
|
5982
6020
|
import { watch } from "chokidar";
|
|
5983
6021
|
|
|
5984
6022
|
// src/pages/hash.tsx
|
|
@@ -5994,33 +6032,34 @@ var hashFile = (filepath) => {
|
|
|
5994
6032
|
|
|
5995
6033
|
// src/miniflare-cli/assets.ts
|
|
5996
6034
|
async function generateASSETSBinding(options) {
|
|
5997
|
-
const assetsFetch = options.directory !== void 0 ? await generateAssetsFetch(options.directory, options.log) : invalidAssetsFetch;
|
|
6035
|
+
const assetsFetch = options.directory !== void 0 ? await generateAssetsFetch(options.directory, options.log, options.tre) : invalidAssetsFetch;
|
|
6036
|
+
const miniflare = options.tre ? await import("@miniflare/tre") : await import("@miniflare/core");
|
|
6037
|
+
const Request = miniflare.Request;
|
|
6038
|
+
const Response2 = miniflare.Response;
|
|
6039
|
+
const fetch2 = options.tre ? miniflare.fetch : (await import("@miniflare/web-sockets")).upgradingFetch;
|
|
5998
6040
|
return async function(miniflareRequest) {
|
|
5999
6041
|
if (options.proxyPort) {
|
|
6000
6042
|
try {
|
|
6001
6043
|
const url = new URL(miniflareRequest.url);
|
|
6002
6044
|
url.host = `localhost:${options.proxyPort}`;
|
|
6003
|
-
const proxyRequest = new
|
|
6045
|
+
const proxyRequest = new Request(url, miniflareRequest);
|
|
6004
6046
|
if (proxyRequest.headers.get("Upgrade") === "websocket") {
|
|
6005
6047
|
proxyRequest.headers.delete("Sec-WebSocket-Accept");
|
|
6006
6048
|
proxyRequest.headers.delete("Sec-WebSocket-Key");
|
|
6007
6049
|
}
|
|
6008
|
-
return await
|
|
6050
|
+
return await fetch2(proxyRequest);
|
|
6009
6051
|
} catch (thrown) {
|
|
6010
6052
|
options.log.error(new Error(`Could not proxy request: ${thrown}`));
|
|
6011
|
-
return new
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
status: 502
|
|
6015
|
-
}
|
|
6016
|
-
);
|
|
6053
|
+
return new Response2(`[wrangler] Could not proxy request: ${thrown}`, {
|
|
6054
|
+
status: 502
|
|
6055
|
+
});
|
|
6017
6056
|
}
|
|
6018
6057
|
} else {
|
|
6019
6058
|
try {
|
|
6020
6059
|
return await assetsFetch(miniflareRequest);
|
|
6021
6060
|
} catch (thrown) {
|
|
6022
6061
|
options.log.error(new Error(`Could not serve static asset: ${thrown}`));
|
|
6023
|
-
return new
|
|
6062
|
+
return new Response2(
|
|
6024
6063
|
`[wrangler] Could not serve static asset: ${thrown}`,
|
|
6025
6064
|
{ status: 502 }
|
|
6026
6065
|
);
|
|
@@ -6028,8 +6067,11 @@ async function generateASSETSBinding(options) {
|
|
|
6028
6067
|
}
|
|
6029
6068
|
};
|
|
6030
6069
|
}
|
|
6031
|
-
async function generateAssetsFetch(directory, log) {
|
|
6032
|
-
await Promise.resolve().then(() => (init_miniflare(), miniflare_exports));
|
|
6070
|
+
async function generateAssetsFetch(directory, log, tre) {
|
|
6071
|
+
const polyfill2 = tre ? (await Promise.resolve().then(() => (init_miniflare_tre(), miniflare_tre_exports))).default : (await Promise.resolve().then(() => (init_miniflare(), miniflare_exports))).default;
|
|
6072
|
+
await polyfill2();
|
|
6073
|
+
const miniflare = tre ? await import("@miniflare/tre") : await import("@miniflare/core");
|
|
6074
|
+
const Request = miniflare.Request;
|
|
6033
6075
|
const { generateHandler: generateHandler2, parseQualityWeightedList: parseQualityWeightedList2 } = await Promise.resolve().then(() => (init_handler(), handler_exports));
|
|
6034
6076
|
const headersFile = join(directory, "_headers");
|
|
6035
6077
|
const redirectsFile = join(directory, "_redirects");
|
|
@@ -6123,7 +6165,7 @@ async function generateAssetsFetch(directory, log) {
|
|
|
6123
6165
|
});
|
|
6124
6166
|
};
|
|
6125
6167
|
return async (input, init) => {
|
|
6126
|
-
const request = new
|
|
6168
|
+
const request = new Request(input, init);
|
|
6127
6169
|
return await generateResponse(request);
|
|
6128
6170
|
};
|
|
6129
6171
|
}
|
|
@@ -6191,12 +6233,12 @@ async function main() {
|
|
|
6191
6233
|
namespace.get = (id) => {
|
|
6192
6234
|
const stub = new DurableObjectStub(factory, id);
|
|
6193
6235
|
stub.fetch = (...reqArgs) => {
|
|
6194
|
-
const requestFromArgs = new
|
|
6236
|
+
const requestFromArgs = new MiniflareRequest(...reqArgs);
|
|
6195
6237
|
const url = new URL(requestFromArgs.url);
|
|
6196
6238
|
url.host = host;
|
|
6197
6239
|
if (port !== void 0)
|
|
6198
6240
|
url.port = port.toString();
|
|
6199
|
-
const request = new
|
|
6241
|
+
const request = new MiniflareRequest(
|
|
6200
6242
|
url.toString(),
|
|
6201
6243
|
requestFromArgs
|
|
6202
6244
|
);
|
|
@@ -6229,7 +6271,8 @@ async function main() {
|
|
|
6229
6271
|
const options = {
|
|
6230
6272
|
log: config.log,
|
|
6231
6273
|
proxyPort: opts.proxyPort,
|
|
6232
|
-
directory: opts.directory
|
|
6274
|
+
directory: opts.directory,
|
|
6275
|
+
tre: false
|
|
6233
6276
|
};
|
|
6234
6277
|
config.serviceBindings = {
|
|
6235
6278
|
...config.serviceBindings,
|
|
@@ -6255,7 +6298,7 @@ async function main() {
|
|
|
6255
6298
|
}`,
|
|
6256
6299
|
serviceBindings: {
|
|
6257
6300
|
DO: async (request) => {
|
|
6258
|
-
request = new
|
|
6301
|
+
request = new MiniflareRequest(request);
|
|
6259
6302
|
const name = request.headers.get("x-miniflare-durable-object-name");
|
|
6260
6303
|
const idString = request.headers.get(
|
|
6261
6304
|
"x-miniflare-durable-object-id"
|
|
@@ -6263,7 +6306,7 @@ async function main() {
|
|
|
6263
6306
|
request.headers.delete("x-miniflare-durable-object-name");
|
|
6264
6307
|
request.headers.delete("x-miniflare-durable-object-id");
|
|
6265
6308
|
if (!name || !idString) {
|
|
6266
|
-
return new
|
|
6309
|
+
return new MiniflareResponse(
|
|
6267
6310
|
"[durable-object-proxy-err] Missing `x-miniflare-durable-object-name` or `x-miniflare-durable-object-id` headers.",
|
|
6268
6311
|
{ status: 400 }
|
|
6269
6312
|
);
|
|
@@ -6271,14 +6314,14 @@ async function main() {
|
|
|
6271
6314
|
const namespace = await mf?.getDurableObjectNamespace(name);
|
|
6272
6315
|
const id = namespace?.idFromString(idString);
|
|
6273
6316
|
if (!id) {
|
|
6274
|
-
return new
|
|
6317
|
+
return new MiniflareResponse(
|
|
6275
6318
|
"[durable-object-proxy-err] Could not generate an ID. Possibly due to a mismatched DO name and ID?",
|
|
6276
6319
|
{ status: 500 }
|
|
6277
6320
|
);
|
|
6278
6321
|
}
|
|
6279
6322
|
const stub = namespace?.get(id);
|
|
6280
6323
|
if (!stub) {
|
|
6281
|
-
return new
|
|
6324
|
+
return new MiniflareResponse(
|
|
6282
6325
|
"[durable-object-proxy-err] Could not generate a stub. Possibly due to a mismatched DO name and ID?",
|
|
6283
6326
|
{ status: 500 }
|
|
6284
6327
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"@databases/sql": "^3.2.0",
|
|
120
120
|
"@iarna/toml": "^3.0.0",
|
|
121
121
|
"@microsoft/api-extractor": "^7.28.3",
|
|
122
|
-
"@miniflare/tre": "^3.0.0-next.
|
|
122
|
+
"@miniflare/tre": "^3.0.0-next.8",
|
|
123
123
|
"@types/better-sqlite3": "^7.6.0",
|
|
124
124
|
"@types/busboy": "^1.5.0",
|
|
125
125
|
"@types/command-exists": "^1.2.0",
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"jest-websocket-mock": "^2.3.0",
|
|
163
163
|
"mime": "^3.0.0",
|
|
164
164
|
"minimatch": "^5.1.0",
|
|
165
|
-
"msw": "^0.
|
|
165
|
+
"msw": "^0.49.1",
|
|
166
166
|
"npx-import": "^1.1.3",
|
|
167
167
|
"open": "^8.4.0",
|
|
168
168
|
"p-queue": "^7.2.0",
|
|
@@ -55,6 +55,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
55
55
|
},
|
|
56
56
|
r2_buckets: [],
|
|
57
57
|
services: [],
|
|
58
|
+
analytics_engine_datasets: [],
|
|
58
59
|
route: undefined,
|
|
59
60
|
routes: undefined,
|
|
60
61
|
rules: [],
|
|
@@ -915,6 +916,15 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
915
916
|
environment: "SERVICE_BINDING_ENVIRONMENT_1",
|
|
916
917
|
},
|
|
917
918
|
],
|
|
919
|
+
analytics_engine_datasets: [
|
|
920
|
+
{
|
|
921
|
+
binding: "AE_BINDING_1",
|
|
922
|
+
dataset: "DATASET_1",
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
binding: "AE_BINDING_2",
|
|
926
|
+
},
|
|
927
|
+
],
|
|
918
928
|
unsafe: {
|
|
919
929
|
bindings: [
|
|
920
930
|
{ name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
|
|
@@ -2028,6 +2038,92 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2028
2038
|
});
|
|
2029
2039
|
});
|
|
2030
2040
|
|
|
2041
|
+
describe("[analytics_engine_datasets]", () => {
|
|
2042
|
+
it("should error if analytics_engine_datasets is an object", () => {
|
|
2043
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2044
|
+
{ analytics_engine_datasets: {} } as unknown as RawConfig,
|
|
2045
|
+
undefined,
|
|
2046
|
+
{ env: undefined }
|
|
2047
|
+
);
|
|
2048
|
+
|
|
2049
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2050
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2051
|
+
"Processing wrangler configuration:
|
|
2052
|
+
- The field \\"analytics_engine_datasets\\" should be an array but got {}."
|
|
2053
|
+
`);
|
|
2054
|
+
});
|
|
2055
|
+
|
|
2056
|
+
it("should error if analytics_engine_datasets is a string", () => {
|
|
2057
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2058
|
+
{ analytics_engine_datasets: "BAD" } as unknown as RawConfig,
|
|
2059
|
+
undefined,
|
|
2060
|
+
{ env: undefined }
|
|
2061
|
+
);
|
|
2062
|
+
|
|
2063
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2064
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2065
|
+
"Processing wrangler configuration:
|
|
2066
|
+
- The field \\"analytics_engine_datasets\\" should be an array but got \\"BAD\\"."
|
|
2067
|
+
`);
|
|
2068
|
+
});
|
|
2069
|
+
|
|
2070
|
+
it("should error if analytics_engine_datasets is a number", () => {
|
|
2071
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2072
|
+
{ analytics_engine_datasets: 999 } as unknown as RawConfig,
|
|
2073
|
+
undefined,
|
|
2074
|
+
{ env: undefined }
|
|
2075
|
+
);
|
|
2076
|
+
|
|
2077
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2078
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2079
|
+
"Processing wrangler configuration:
|
|
2080
|
+
- The field \\"analytics_engine_datasets\\" should be an array but got 999."
|
|
2081
|
+
`);
|
|
2082
|
+
});
|
|
2083
|
+
|
|
2084
|
+
it("should error if analytics_engine_datasets is null", () => {
|
|
2085
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2086
|
+
{ analytics_engine_datasets: null } as unknown as RawConfig,
|
|
2087
|
+
undefined,
|
|
2088
|
+
{ env: undefined }
|
|
2089
|
+
);
|
|
2090
|
+
|
|
2091
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2092
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2093
|
+
"Processing wrangler configuration:
|
|
2094
|
+
- The field \\"analytics_engine_datasets\\" should be an array but got null."
|
|
2095
|
+
`);
|
|
2096
|
+
});
|
|
2097
|
+
|
|
2098
|
+
it("should error if analytics_engine_datasets.bindings are not valid", () => {
|
|
2099
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2100
|
+
{
|
|
2101
|
+
analytics_engine_datasets: [
|
|
2102
|
+
{},
|
|
2103
|
+
{ binding: 2333, dataset: 2444 },
|
|
2104
|
+
{
|
|
2105
|
+
binding: "AE_BINDING_2",
|
|
2106
|
+
dataset: 2555,
|
|
2107
|
+
},
|
|
2108
|
+
{ binding: "AE_BINDING_1", dataset: "" },
|
|
2109
|
+
],
|
|
2110
|
+
} as unknown as RawConfig,
|
|
2111
|
+
undefined,
|
|
2112
|
+
{ env: undefined }
|
|
2113
|
+
);
|
|
2114
|
+
|
|
2115
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2116
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2117
|
+
"Processing wrangler configuration:
|
|
2118
|
+
- \\"analytics_engine_datasets[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
2119
|
+
- \\"analytics_engine_datasets[1]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"dataset\\":2444}.
|
|
2120
|
+
- \\"analytics_engine_datasets[1]\\" bindings should, optionally, have a string \\"dataset\\" field but got {\\"binding\\":2333,\\"dataset\\":2444}.
|
|
2121
|
+
- \\"analytics_engine_datasets[2]\\" bindings should, optionally, have a string \\"dataset\\" field but got {\\"binding\\":\\"AE_BINDING_2\\",\\"dataset\\":2555}.
|
|
2122
|
+
- \\"analytics_engine_datasets[3]\\" bindings should, optionally, have a string \\"dataset\\" field but got {\\"binding\\":\\"AE_BINDING_1\\",\\"dataset\\":\\"\\"}."
|
|
2123
|
+
`);
|
|
2124
|
+
});
|
|
2125
|
+
});
|
|
2126
|
+
|
|
2031
2127
|
describe("[dispatch_namespaces]", () => {
|
|
2032
2128
|
it("should log an experimental warning when dispatch_namespaces is used", () => {
|
|
2033
2129
|
const { diagnostics } = normalizeAndValidateConfig(
|
|
@@ -2697,6 +2793,8 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2697
2793
|
};
|
|
2698
2794
|
const kv_namespaces: RawConfig["kv_namespaces"] = [];
|
|
2699
2795
|
const r2_buckets: RawConfig["r2_buckets"] = [];
|
|
2796
|
+
const analytics_engine_datasets: RawConfig["analytics_engine_datasets"] =
|
|
2797
|
+
[];
|
|
2700
2798
|
const unsafe: RawConfig["unsafe"] = { bindings: [] };
|
|
2701
2799
|
const rawConfig: RawConfig = {
|
|
2702
2800
|
define,
|
|
@@ -2704,6 +2802,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2704
2802
|
durable_objects,
|
|
2705
2803
|
kv_namespaces,
|
|
2706
2804
|
r2_buckets,
|
|
2805
|
+
analytics_engine_datasets,
|
|
2707
2806
|
unsafe,
|
|
2708
2807
|
env: {
|
|
2709
2808
|
ENV1: {},
|
|
@@ -2723,6 +2822,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2723
2822
|
durable_objects,
|
|
2724
2823
|
kv_namespaces,
|
|
2725
2824
|
r2_buckets,
|
|
2825
|
+
analytics_engine_datasets,
|
|
2726
2826
|
unsafe,
|
|
2727
2827
|
})
|
|
2728
2828
|
);
|
|
@@ -2746,6 +2846,9 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2746
2846
|
- \\"r2_buckets\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
2747
2847
|
This is not what you probably want, since \\"r2_buckets\\" is not inherited by environments.
|
|
2748
2848
|
Please add \\"r2_buckets\\" to \\"env.ENV1\\".
|
|
2849
|
+
- \\"analytics_engine_datasets\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
2850
|
+
This is not what you probably want, since \\"analytics_engine_datasets\\" is not inherited by environments.
|
|
2851
|
+
Please add \\"analytics_engine_datasets\\" to \\"env.ENV1\\".
|
|
2749
2852
|
- \\"unsafe\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
2750
2853
|
This is not what you probably want, since \\"unsafe\\" is not inherited by environments.
|
|
2751
2854
|
Please add \\"unsafe\\" to \\"env.ENV1\\"."
|
|
@@ -3447,6 +3550,114 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
3447
3550
|
});
|
|
3448
3551
|
});
|
|
3449
3552
|
|
|
3553
|
+
describe("[analytics_engine_datasets]", () => {
|
|
3554
|
+
it("should error if analytics_engine_datasets is an object", () => {
|
|
3555
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
3556
|
+
{
|
|
3557
|
+
env: { ENV1: { analytics_engine_datasets: {} } },
|
|
3558
|
+
} as unknown as RawConfig,
|
|
3559
|
+
undefined,
|
|
3560
|
+
{ env: "ENV1" }
|
|
3561
|
+
);
|
|
3562
|
+
|
|
3563
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
3564
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
3565
|
+
"Processing wrangler configuration:
|
|
3566
|
+
|
|
3567
|
+
- \\"env.ENV1\\" environment configuration
|
|
3568
|
+
- The field \\"env.ENV1.analytics_engine_datasets\\" should be an array but got {}."
|
|
3569
|
+
`);
|
|
3570
|
+
});
|
|
3571
|
+
|
|
3572
|
+
it("should error if analytics_engine_datasets is a string", () => {
|
|
3573
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
3574
|
+
{
|
|
3575
|
+
env: { ENV1: { analytics_engine_datasets: "BAD" } },
|
|
3576
|
+
} as unknown as RawConfig,
|
|
3577
|
+
undefined,
|
|
3578
|
+
{ env: "ENV1" }
|
|
3579
|
+
);
|
|
3580
|
+
|
|
3581
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
3582
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
3583
|
+
"Processing wrangler configuration:
|
|
3584
|
+
|
|
3585
|
+
- \\"env.ENV1\\" environment configuration
|
|
3586
|
+
- The field \\"env.ENV1.analytics_engine_datasets\\" should be an array but got \\"BAD\\"."
|
|
3587
|
+
`);
|
|
3588
|
+
});
|
|
3589
|
+
|
|
3590
|
+
it("should error if analytics_engine_datasets is a number", () => {
|
|
3591
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
3592
|
+
{
|
|
3593
|
+
env: { ENV1: { analytics_engine_datasets: 999 } },
|
|
3594
|
+
} as unknown as RawConfig,
|
|
3595
|
+
undefined,
|
|
3596
|
+
{ env: "ENV1" }
|
|
3597
|
+
);
|
|
3598
|
+
|
|
3599
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
3600
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
3601
|
+
"Processing wrangler configuration:
|
|
3602
|
+
|
|
3603
|
+
- \\"env.ENV1\\" environment configuration
|
|
3604
|
+
- The field \\"env.ENV1.analytics_engine_datasets\\" should be an array but got 999."
|
|
3605
|
+
`);
|
|
3606
|
+
});
|
|
3607
|
+
|
|
3608
|
+
it("should error if analytics_engine_datasets is null", () => {
|
|
3609
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
3610
|
+
{
|
|
3611
|
+
env: { ENV1: { analytics_engine_datasets: null } },
|
|
3612
|
+
} as unknown as RawConfig,
|
|
3613
|
+
undefined,
|
|
3614
|
+
{ env: "ENV1" }
|
|
3615
|
+
);
|
|
3616
|
+
|
|
3617
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
3618
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
3619
|
+
"Processing wrangler configuration:
|
|
3620
|
+
|
|
3621
|
+
- \\"env.ENV1\\" environment configuration
|
|
3622
|
+
- The field \\"env.ENV1.analytics_engine_datasets\\" should be an array but got null."
|
|
3623
|
+
`);
|
|
3624
|
+
});
|
|
3625
|
+
|
|
3626
|
+
it("should error if analytics_engine_datasets.bindings are not valid", () => {
|
|
3627
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
3628
|
+
{
|
|
3629
|
+
env: {
|
|
3630
|
+
ENV1: {
|
|
3631
|
+
analytics_engine_datasets: [
|
|
3632
|
+
{},
|
|
3633
|
+
{ binding: 2333, dataset: 2444 },
|
|
3634
|
+
{
|
|
3635
|
+
binding: "AE_BINDING_2",
|
|
3636
|
+
dataset: 2555,
|
|
3637
|
+
},
|
|
3638
|
+
{ binding: "AE_BINDING_1", dataset: "" },
|
|
3639
|
+
],
|
|
3640
|
+
},
|
|
3641
|
+
},
|
|
3642
|
+
} as unknown as RawConfig,
|
|
3643
|
+
undefined,
|
|
3644
|
+
{ env: "ENV1" }
|
|
3645
|
+
);
|
|
3646
|
+
|
|
3647
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
3648
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
3649
|
+
"Processing wrangler configuration:
|
|
3650
|
+
|
|
3651
|
+
- \\"env.ENV1\\" environment configuration
|
|
3652
|
+
- \\"env.ENV1.analytics_engine_datasets[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
3653
|
+
- \\"env.ENV1.analytics_engine_datasets[1]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"dataset\\":2444}.
|
|
3654
|
+
- \\"env.ENV1.analytics_engine_datasets[1]\\" bindings should, optionally, have a string \\"dataset\\" field but got {\\"binding\\":2333,\\"dataset\\":2444}.
|
|
3655
|
+
- \\"env.ENV1.analytics_engine_datasets[2]\\" bindings should, optionally, have a string \\"dataset\\" field but got {\\"binding\\":\\"AE_BINDING_2\\",\\"dataset\\":2555}.
|
|
3656
|
+
- \\"env.ENV1.analytics_engine_datasets[3]\\" bindings should, optionally, have a string \\"dataset\\" field but got {\\"binding\\":\\"AE_BINDING_1\\",\\"dataset\\":\\"\\"}."
|
|
3657
|
+
`);
|
|
3658
|
+
});
|
|
3659
|
+
});
|
|
3660
|
+
|
|
3450
3661
|
describe("[unsafe.bindings]", () => {
|
|
3451
3662
|
it("should error if unsafe is an array", () => {
|
|
3452
3663
|
const { diagnostics } = normalizeAndValidateConfig(
|
|
@@ -3,6 +3,7 @@ import getPort from "get-port";
|
|
|
3
3
|
import patchConsole from "patch-console";
|
|
4
4
|
import dedent from "ts-dedent";
|
|
5
5
|
import Dev from "../dev/dev";
|
|
6
|
+
import { CI } from "../is-ci";
|
|
6
7
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
7
8
|
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
8
9
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
@@ -35,6 +36,22 @@ describe("wrangler dev", () => {
|
|
|
35
36
|
unsetAllMocks();
|
|
36
37
|
});
|
|
37
38
|
|
|
39
|
+
describe("authorization", () => {
|
|
40
|
+
mockApiToken({ apiToken: null });
|
|
41
|
+
const isCISpy = jest.spyOn(CI, "isCI").mockReturnValue(true);
|
|
42
|
+
|
|
43
|
+
it("should kick you to the login flow when running wrangler dev in remote mode without authorization", async () => {
|
|
44
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
45
|
+
await expect(
|
|
46
|
+
runWrangler("dev index.js")
|
|
47
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
48
|
+
`"You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local."`
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
isCISpy.mockClear();
|
|
53
|
+
});
|
|
54
|
+
|
|
38
55
|
describe("compatibility-date", () => {
|
|
39
56
|
it("should not warn if there is no wrangler.toml and no compatibility-date specified", async () => {
|
|
40
57
|
fs.writeFileSync("index.js", `export default {};`);
|
|
@@ -529,7 +529,7 @@ describe("init", () => {
|
|
|
529
529
|
}
|
|
530
530
|
`);
|
|
531
531
|
expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
|
|
532
|
-
|
|
532
|
+
getDefaultBranchName()
|
|
533
533
|
);
|
|
534
534
|
});
|
|
535
535
|
|
|
@@ -598,7 +598,7 @@ describe("init", () => {
|
|
|
598
598
|
"should not offer to initialize a git repo if git is not installed"
|
|
599
599
|
);
|
|
600
600
|
|
|
601
|
-
it("should initialize git repo with
|
|
601
|
+
it("should initialize git repo with the user's default branch", async () => {
|
|
602
602
|
mockConfirm(
|
|
603
603
|
{
|
|
604
604
|
text: "Would you like to use git to manage this Worker?",
|
|
@@ -621,7 +621,7 @@ describe("init", () => {
|
|
|
621
621
|
`);
|
|
622
622
|
|
|
623
623
|
expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
|
|
624
|
-
|
|
624
|
+
`refs/heads/${getDefaultBranchName()}`
|
|
625
625
|
);
|
|
626
626
|
});
|
|
627
627
|
});
|
|
@@ -2810,6 +2810,21 @@ describe("init", () => {
|
|
|
2810
2810
|
});
|
|
2811
2811
|
});
|
|
2812
2812
|
|
|
2813
|
+
function getDefaultBranchName() {
|
|
2814
|
+
try {
|
|
2815
|
+
const { stdout: defaultBranchName } = execaSync("git", [
|
|
2816
|
+
"config",
|
|
2817
|
+
"--get",
|
|
2818
|
+
"init.defaultBranch",
|
|
2819
|
+
]);
|
|
2820
|
+
|
|
2821
|
+
return defaultBranchName;
|
|
2822
|
+
} catch {
|
|
2823
|
+
// ew
|
|
2824
|
+
return "master";
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2813
2828
|
/**
|
|
2814
2829
|
* Change the current working directory, ensuring that this exists.
|
|
2815
2830
|
*/
|