wrangler 2.0.3 → 2.0.7
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/bin/wrangler.js +2 -2
- package/package.json +5 -3
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +13 -0
- package/src/__tests__/configuration.test.ts +217 -29
- package/src/__tests__/dev.test.tsx +71 -9
- package/src/__tests__/index.test.ts +30 -16
- package/src/__tests__/init.test.ts +61 -20
- package/src/__tests__/kv.test.ts +109 -103
- package/src/__tests__/pages.test.ts +363 -33
- package/src/__tests__/parse.test.ts +5 -1
- package/src/__tests__/publish.test.ts +486 -72
- package/src/__tests__/r2.test.ts +47 -24
- package/src/__tests__/secret.test.ts +35 -0
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +32 -1
- package/src/cfetch/index.ts +4 -2
- package/src/cfetch/internal.ts +11 -9
- package/src/config/environment.ts +40 -14
- package/src/config/index.ts +162 -0
- package/src/config/validation.ts +126 -37
- package/src/create-worker-preview.ts +17 -7
- package/src/create-worker-upload-form.ts +22 -8
- package/src/dev/dev.tsx +5 -4
- package/src/dev/local.tsx +6 -0
- package/src/dev/remote.tsx +15 -1
- package/src/durable.ts +102 -0
- package/src/index.tsx +185 -98
- package/src/inspect.ts +39 -0
- package/src/kv.ts +111 -24
- package/src/open-in-browser.ts +5 -12
- package/src/pages.tsx +206 -65
- package/src/parse.ts +21 -4
- package/src/proxy.ts +38 -22
- package/src/publish.ts +227 -113
- package/src/sites.tsx +13 -16
- package/src/worker.ts +8 -0
- package/templates/new-worker.ts +16 -1
- package/wrangler-dist/cli.js +32273 -19295
|
@@ -2,6 +2,8 @@ import { getPackageManager } from "../package-manager";
|
|
|
2
2
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
3
3
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
4
4
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
5
|
+
import { writeWorkerSource } from "./helpers/write-worker-source";
|
|
6
|
+
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
5
7
|
import type { PackageManager } from "../package-manager";
|
|
6
8
|
|
|
7
9
|
describe("wrangler", () => {
|
|
@@ -63,10 +65,7 @@ describe("wrangler", () => {
|
|
|
63
65
|
|
|
64
66
|
expect(std.out).toMatchInlineSnapshot(`
|
|
65
67
|
"
|
|
66
|
-
|
|
67
|
-
`);
|
|
68
|
-
expect(std.err).toMatchInlineSnapshot(`
|
|
69
|
-
"wrangler
|
|
68
|
+
wrangler
|
|
70
69
|
|
|
71
70
|
Commands:
|
|
72
71
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
@@ -86,8 +85,10 @@ describe("wrangler", () => {
|
|
|
86
85
|
Flags:
|
|
87
86
|
-c, --config Path to .toml configuration file [string]
|
|
88
87
|
-h, --help Show help [boolean]
|
|
89
|
-
-v, --version Show version number [boolean]
|
|
90
|
-
|
|
88
|
+
-v, --version Show version number [boolean]"
|
|
89
|
+
`);
|
|
90
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
91
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown argument: invalid-command[0m
|
|
91
92
|
|
|
92
93
|
"
|
|
93
94
|
`);
|
|
@@ -114,9 +115,6 @@ describe("wrangler", () => {
|
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
describe("subcommand implicit help ran on incomplete command execution", () => {
|
|
117
|
-
function endEventLoop() {
|
|
118
|
-
return new Promise((resolve) => setImmediate(resolve));
|
|
119
|
-
}
|
|
120
118
|
it("no subcommand for 'secret' should display a list of available subcommands", async () => {
|
|
121
119
|
await runWrangler("secret");
|
|
122
120
|
await endEventLoop();
|
|
@@ -196,6 +194,7 @@ describe("wrangler", () => {
|
|
|
196
194
|
-v, --version Show version number [boolean]"
|
|
197
195
|
`);
|
|
198
196
|
});
|
|
197
|
+
|
|
199
198
|
it("no subcommand 'r2' should display a list of available subcommands", async () => {
|
|
200
199
|
await runWrangler("r2");
|
|
201
200
|
await endEventLoop();
|
|
@@ -214,6 +213,7 @@ describe("wrangler", () => {
|
|
|
214
213
|
`);
|
|
215
214
|
});
|
|
216
215
|
});
|
|
216
|
+
|
|
217
217
|
describe("Deprecated commands", () => {
|
|
218
218
|
it("should print a deprecation message for 'generate'", async () => {
|
|
219
219
|
await runWrangler("generate").catch((err) => {
|
|
@@ -230,13 +230,27 @@ describe("wrangler", () => {
|
|
|
230
230
|
`);
|
|
231
231
|
});
|
|
232
232
|
});
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
`);
|
|
239
|
-
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("should print a deprecation message for 'build' and then try to run `publish --dry-run --outdir`", async () => {
|
|
236
|
+
writeWranglerToml({
|
|
237
|
+
main: "index.js",
|
|
240
238
|
});
|
|
239
|
+
writeWorkerSource();
|
|
240
|
+
await runWrangler("build");
|
|
241
|
+
await endEventLoop();
|
|
242
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
243
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mDeprecation: \`wrangler build\` has been deprecated.[0m
|
|
244
|
+
|
|
245
|
+
Please refer to [4mhttps://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build[0m for more information.
|
|
246
|
+
Attempting to run \`wrangler publish --dry-run --outdir=dist\` for you instead:
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
--dry-run: exiting now."
|
|
250
|
+
`);
|
|
241
251
|
});
|
|
242
252
|
});
|
|
253
|
+
|
|
254
|
+
function endEventLoop() {
|
|
255
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
256
|
+
}
|
|
@@ -2,7 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as fsp from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import * as TOML from "@iarna/toml";
|
|
5
|
-
import { execa } from "execa";
|
|
5
|
+
import { execa, execaSync } from "execa";
|
|
6
6
|
import { parseConfigFileTextToJson } from "typescript";
|
|
7
7
|
import { version as wranglerVersion } from "../../package.json";
|
|
8
8
|
import { getPackageManager } from "../package-manager";
|
|
@@ -46,8 +46,9 @@ describe("init", () => {
|
|
|
46
46
|
"✨ Created wrangler.toml
|
|
47
47
|
✨ Initialized git repository
|
|
48
48
|
✨ Created package.json
|
|
49
|
-
✨ Created tsconfig.json
|
|
49
|
+
✨ Created tsconfig.json
|
|
50
50
|
✨ Created src/index.ts
|
|
51
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
51
52
|
|
|
52
53
|
To start developing your Worker, run \`npm start\`
|
|
53
54
|
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
@@ -72,8 +73,9 @@ describe("init", () => {
|
|
|
72
73
|
"✨ Created my-worker/wrangler.toml
|
|
73
74
|
✨ Initialized git repository at my-worker
|
|
74
75
|
✨ Created my-worker/package.json
|
|
75
|
-
✨ Created my-worker/tsconfig.json
|
|
76
|
+
✨ Created my-worker/tsconfig.json
|
|
76
77
|
✨ Created my-worker/src/index.ts
|
|
78
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
77
79
|
|
|
78
80
|
To start developing your Worker, run \`cd my-worker && npm start\`
|
|
79
81
|
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
@@ -97,8 +99,9 @@ describe("init", () => {
|
|
|
97
99
|
"out": "✨ Created wrangler.toml
|
|
98
100
|
✨ Initialized git repository
|
|
99
101
|
✨ Created package.json
|
|
100
|
-
✨ Created tsconfig.json
|
|
102
|
+
✨ Created tsconfig.json
|
|
101
103
|
✨ Created src/index.ts
|
|
104
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
102
105
|
|
|
103
106
|
To start developing your Worker, run \`npm start\`
|
|
104
107
|
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
@@ -373,8 +376,9 @@ describe("init", () => {
|
|
|
373
376
|
"err": "",
|
|
374
377
|
"out": "✨ Created wrangler.toml
|
|
375
378
|
✨ Created package.json
|
|
376
|
-
✨ Created tsconfig.json
|
|
379
|
+
✨ Created tsconfig.json
|
|
377
380
|
✨ Created src/index.ts
|
|
381
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
378
382
|
|
|
379
383
|
To start developing your Worker, run \`npm start\`
|
|
380
384
|
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
@@ -397,8 +401,9 @@ describe("init", () => {
|
|
|
397
401
|
"err": "",
|
|
398
402
|
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
399
403
|
✨ Created path/to/worker/my-worker/package.json
|
|
400
|
-
✨ Created path/to/worker/my-worker/tsconfig.json
|
|
404
|
+
✨ Created path/to/worker/my-worker/tsconfig.json
|
|
401
405
|
✨ Created path/to/worker/my-worker/src/index.ts
|
|
406
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
402
407
|
|
|
403
408
|
To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
|
|
404
409
|
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
@@ -407,10 +412,37 @@ describe("init", () => {
|
|
|
407
412
|
`);
|
|
408
413
|
});
|
|
409
414
|
|
|
415
|
+
// I... don't know how to test this lol
|
|
410
416
|
it.todo(
|
|
411
417
|
"should not offer to initialize a git repo if git is not installed"
|
|
412
418
|
);
|
|
413
|
-
|
|
419
|
+
|
|
420
|
+
it("should initialize git repo with `main` default branch", async () => {
|
|
421
|
+
mockConfirm(
|
|
422
|
+
{
|
|
423
|
+
text: "Would you like to use git to manage this Worker?",
|
|
424
|
+
result: true,
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
text: "No package.json found. Would you like to create one?",
|
|
428
|
+
result: false,
|
|
429
|
+
}
|
|
430
|
+
);
|
|
431
|
+
await runWrangler("init");
|
|
432
|
+
expect(std).toMatchInlineSnapshot(`
|
|
433
|
+
Object {
|
|
434
|
+
"debug": "",
|
|
435
|
+
"err": "",
|
|
436
|
+
"out": "✨ Created wrangler.toml
|
|
437
|
+
✨ Initialized git repository",
|
|
438
|
+
"warn": "",
|
|
439
|
+
}
|
|
440
|
+
`);
|
|
441
|
+
|
|
442
|
+
expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
|
|
443
|
+
"refs/heads/main"
|
|
444
|
+
);
|
|
445
|
+
});
|
|
414
446
|
});
|
|
415
447
|
|
|
416
448
|
describe("package.json", () => {
|
|
@@ -616,7 +648,7 @@ describe("init", () => {
|
|
|
616
648
|
"debug": "",
|
|
617
649
|
"err": "",
|
|
618
650
|
"out": "✨ Created wrangler.toml
|
|
619
|
-
✨ Installed wrangler",
|
|
651
|
+
✨ Installed wrangler into devDependencies",
|
|
620
652
|
"warn": "",
|
|
621
653
|
}
|
|
622
654
|
`);
|
|
@@ -664,7 +696,7 @@ describe("init", () => {
|
|
|
664
696
|
"debug": "",
|
|
665
697
|
"err": "",
|
|
666
698
|
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
667
|
-
✨ Installed wrangler",
|
|
699
|
+
✨ Installed wrangler into devDependencies",
|
|
668
700
|
"warn": "",
|
|
669
701
|
}
|
|
670
702
|
`);
|
|
@@ -801,8 +833,9 @@ describe("init", () => {
|
|
|
801
833
|
"debug": "",
|
|
802
834
|
"err": "",
|
|
803
835
|
"out": "✨ Created wrangler.toml
|
|
804
|
-
✨ Created tsconfig.json
|
|
836
|
+
✨ Created tsconfig.json
|
|
805
837
|
✨ Created src/index.ts
|
|
838
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
806
839
|
|
|
807
840
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
808
841
|
To publish your Worker to the Internet, run \`npx wrangler publish\`",
|
|
@@ -851,8 +884,9 @@ describe("init", () => {
|
|
|
851
884
|
expect(std.out).toMatchInlineSnapshot(`
|
|
852
885
|
"✨ Created wrangler.toml
|
|
853
886
|
✨ Created package.json
|
|
854
|
-
✨ Created tsconfig.json
|
|
887
|
+
✨ Created tsconfig.json
|
|
855
888
|
✨ Created src/index.ts
|
|
889
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
856
890
|
|
|
857
891
|
To start developing your Worker, run \`npm start\`
|
|
858
892
|
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
@@ -899,8 +933,9 @@ describe("init", () => {
|
|
|
899
933
|
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
900
934
|
expect(std.out).toMatchInlineSnapshot(`
|
|
901
935
|
"✨ Created wrangler.toml
|
|
902
|
-
✨ Created tsconfig.json
|
|
936
|
+
✨ Created tsconfig.json
|
|
903
937
|
✨ Created src/index.ts
|
|
938
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
904
939
|
|
|
905
940
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
906
941
|
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
@@ -940,7 +975,8 @@ describe("init", () => {
|
|
|
940
975
|
"debug": "",
|
|
941
976
|
"err": "",
|
|
942
977
|
"out": "✨ Created wrangler.toml
|
|
943
|
-
✨ Created tsconfig.json
|
|
978
|
+
✨ Created tsconfig.json
|
|
979
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
944
980
|
"warn": "",
|
|
945
981
|
}
|
|
946
982
|
`);
|
|
@@ -981,7 +1017,8 @@ describe("init", () => {
|
|
|
981
1017
|
"debug": "",
|
|
982
1018
|
"err": "",
|
|
983
1019
|
"out": "✨ Created my-worker/wrangler.toml
|
|
984
|
-
✨ Created my-worker/tsconfig.json
|
|
1020
|
+
✨ Created my-worker/tsconfig.json
|
|
1021
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
985
1022
|
"warn": "",
|
|
986
1023
|
}
|
|
987
1024
|
`);
|
|
@@ -1027,7 +1064,8 @@ describe("init", () => {
|
|
|
1027
1064
|
"err": "",
|
|
1028
1065
|
"out": "✨ Created wrangler.toml
|
|
1029
1066
|
✨ Created package.json
|
|
1030
|
-
✨ Created tsconfig.json
|
|
1067
|
+
✨ Created tsconfig.json
|
|
1068
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
1031
1069
|
"warn": "",
|
|
1032
1070
|
}
|
|
1033
1071
|
`);
|
|
@@ -1179,8 +1217,8 @@ describe("init", () => {
|
|
|
1179
1217
|
"debug": "",
|
|
1180
1218
|
"err": "",
|
|
1181
1219
|
"out": "✨ Created wrangler.toml
|
|
1182
|
-
✨ Installed @cloudflare/workers-types
|
|
1183
|
-
Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
|
|
1220
|
+
✨ Installed @cloudflare/workers-types into devDependencies
|
|
1221
|
+
🚨 Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
|
|
1184
1222
|
"warn": "",
|
|
1185
1223
|
}
|
|
1186
1224
|
`);
|
|
@@ -1445,8 +1483,9 @@ describe("init", () => {
|
|
|
1445
1483
|
"out": "✨ Created wrangler.toml
|
|
1446
1484
|
✨ Initialized git repository
|
|
1447
1485
|
✨ Created package.json
|
|
1448
|
-
✨ Created tsconfig.json
|
|
1486
|
+
✨ Created tsconfig.json
|
|
1449
1487
|
✨ Created src/index.ts
|
|
1488
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1450
1489
|
|
|
1451
1490
|
To start developing your Worker, run \`npm start\`
|
|
1452
1491
|
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
@@ -1473,8 +1512,9 @@ describe("init", () => {
|
|
|
1473
1512
|
"out": "✨ Created path/to/worker/wrangler.toml
|
|
1474
1513
|
✨ Initialized git repository at path/to/worker
|
|
1475
1514
|
✨ Created path/to/worker/package.json
|
|
1476
|
-
✨ Created path/to/worker/tsconfig.json
|
|
1515
|
+
✨ Created path/to/worker/tsconfig.json
|
|
1477
1516
|
✨ Created path/to/worker/src/index.ts
|
|
1517
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1478
1518
|
|
|
1479
1519
|
To start developing your Worker, run \`cd path/to/worker && npm start\`
|
|
1480
1520
|
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
@@ -1503,8 +1543,9 @@ describe("init", () => {
|
|
|
1503
1543
|
"out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
|
|
1504
1544
|
✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
|
|
1505
1545
|
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
|
|
1506
|
-
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
|
|
1546
|
+
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
|
|
1507
1547
|
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
|
|
1548
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1508
1549
|
|
|
1509
1550
|
To start developing your Worker, run \`cd WEIRD_w0rkr_N4m3.js.tsx.tar.gz && npm start\`
|
|
1510
1551
|
To publish your Worker to the Internet, run \`npm run publish\`",
|