wrangler 2.0.6 → 2.0.9
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 +1 -1
- package/bin/wrangler.js +16 -4
- package/package.json +6 -4
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +13 -0
- package/src/__tests__/configuration.test.ts +132 -60
- package/src/__tests__/dev.test.tsx +168 -67
- package/src/__tests__/helpers/mock-dialogs.ts +41 -1
- package/src/__tests__/index.test.ts +25 -10
- package/src/__tests__/init.test.ts +252 -131
- package/src/__tests__/kv.test.ts +16 -16
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +442 -38
- package/src/__tests__/parse.test.ts +5 -1
- package/src/__tests__/publish.test.ts +377 -84
- package/src/__tests__/secret.test.ts +4 -4
- package/src/__tests__/whoami.test.tsx +34 -0
- package/src/abort.d.ts +3 -0
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +20 -18
- package/src/config/config.ts +1 -1
- package/src/config/index.ts +162 -0
- package/src/config/validation.ts +77 -29
- package/src/create-worker-preview.ts +32 -22
- package/src/dev/dev.tsx +6 -16
- package/src/dev/remote.tsx +40 -16
- package/src/dialogs.tsx +48 -0
- package/src/durable.ts +102 -0
- package/src/index.tsx +291 -207
- package/src/inspect.ts +39 -0
- package/src/kv.ts +74 -25
- package/src/open-in-browser.ts +5 -12
- package/src/package-manager.ts +50 -3
- package/src/pages.tsx +218 -61
- package/src/parse.ts +21 -4
- package/src/proxy.ts +38 -22
- package/src/publish.ts +166 -108
- package/src/sites.tsx +8 -8
- package/src/user.tsx +12 -1
- package/src/whoami.tsx +3 -2
- package/src/worker.ts +2 -1
- package/src/zones.ts +73 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/wrangler-dist/cli.js +33066 -20052
|
@@ -2,14 +2,20 @@ 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";
|
|
9
9
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
mockConfirm,
|
|
12
|
+
clearConfirmMocks,
|
|
13
|
+
mockSelect,
|
|
14
|
+
clearSelectMocks,
|
|
15
|
+
} from "./helpers/mock-dialogs";
|
|
11
16
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
12
17
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
18
|
+
import type { RawConfig } from "../config";
|
|
13
19
|
import type { PackageManager } from "../package-manager";
|
|
14
20
|
|
|
15
21
|
describe("init", () => {
|
|
@@ -29,6 +35,7 @@ describe("init", () => {
|
|
|
29
35
|
|
|
30
36
|
afterEach(() => {
|
|
31
37
|
clearConfirmMocks();
|
|
38
|
+
clearSelectMocks();
|
|
32
39
|
});
|
|
33
40
|
|
|
34
41
|
const std = mockConsoleMethods();
|
|
@@ -46,11 +53,12 @@ describe("init", () => {
|
|
|
46
53
|
"✨ Created wrangler.toml
|
|
47
54
|
✨ Initialized git repository
|
|
48
55
|
✨ Created package.json
|
|
49
|
-
✨ Created tsconfig.json
|
|
56
|
+
✨ Created tsconfig.json
|
|
50
57
|
✨ Created src/index.ts
|
|
58
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
51
59
|
|
|
52
60
|
To start developing your Worker, run \`npm start\`
|
|
53
|
-
To publish your Worker to the Internet, run \`npm run
|
|
61
|
+
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
54
62
|
`);
|
|
55
63
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
56
64
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -72,11 +80,12 @@ describe("init", () => {
|
|
|
72
80
|
"✨ Created my-worker/wrangler.toml
|
|
73
81
|
✨ Initialized git repository at my-worker
|
|
74
82
|
✨ Created my-worker/package.json
|
|
75
|
-
✨ Created my-worker/tsconfig.json
|
|
83
|
+
✨ Created my-worker/tsconfig.json
|
|
76
84
|
✨ Created my-worker/src/index.ts
|
|
85
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
77
86
|
|
|
78
87
|
To start developing your Worker, run \`cd my-worker && npm start\`
|
|
79
|
-
To publish your Worker to the Internet, run \`npm run
|
|
88
|
+
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
80
89
|
`);
|
|
81
90
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
82
91
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -97,11 +106,12 @@ describe("init", () => {
|
|
|
97
106
|
"out": "✨ Created wrangler.toml
|
|
98
107
|
✨ Initialized git repository
|
|
99
108
|
✨ Created package.json
|
|
100
|
-
✨ Created tsconfig.json
|
|
109
|
+
✨ Created tsconfig.json
|
|
101
110
|
✨ Created src/index.ts
|
|
111
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
102
112
|
|
|
103
113
|
To start developing your Worker, run \`npm start\`
|
|
104
|
-
To publish your Worker to the Internet, run \`npm run
|
|
114
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
105
115
|
"warn": "",
|
|
106
116
|
}
|
|
107
117
|
`);
|
|
@@ -284,13 +294,14 @@ describe("init", () => {
|
|
|
284
294
|
{
|
|
285
295
|
text: "Would you like to use TypeScript?",
|
|
286
296
|
result: true,
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
290
|
-
result: true,
|
|
291
297
|
}
|
|
292
298
|
);
|
|
293
299
|
|
|
300
|
+
mockSelect({
|
|
301
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
302
|
+
result: "fetch",
|
|
303
|
+
});
|
|
304
|
+
|
|
294
305
|
await runWrangler("init");
|
|
295
306
|
expect(fs.readFileSync("./wrangler.toml", "utf-8")).toMatchInlineSnapshot(
|
|
296
307
|
`"compatibility_date=\\"something-else\\""`
|
|
@@ -332,6 +343,72 @@ describe("init", () => {
|
|
|
332
343
|
}
|
|
333
344
|
`);
|
|
334
345
|
});
|
|
346
|
+
|
|
347
|
+
it("should not add a Cron Trigger to wrangler.toml when creating a Scheduled Worker if wrangler.toml already exists", async () => {
|
|
348
|
+
fs.writeFileSync(
|
|
349
|
+
"./wrangler.toml",
|
|
350
|
+
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
351
|
+
"utf-8"
|
|
352
|
+
);
|
|
353
|
+
mockConfirm(
|
|
354
|
+
{
|
|
355
|
+
text: "Would you like to use git to manage this Worker?",
|
|
356
|
+
result: true,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
text: "Do you want to continue initializing this project?",
|
|
360
|
+
result: true,
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
text: "No package.json found. Would you like to create one?",
|
|
364
|
+
result: true,
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
text: "Would you like to use TypeScript?",
|
|
368
|
+
result: true,
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
mockSelect({
|
|
373
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
374
|
+
result: "scheduled",
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
await runWrangler("init");
|
|
378
|
+
expect(fs.readFileSync("./wrangler.toml", "utf-8")).toMatchInlineSnapshot(
|
|
379
|
+
`"compatibility_date=\\"something-else\\""`
|
|
380
|
+
);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("should add a Cron Trigger to wrangler.toml when creating a Scheduled Worker, but only if wrangler.toml is being created during init", async () => {
|
|
384
|
+
mockConfirm(
|
|
385
|
+
{
|
|
386
|
+
text: "Would you like to use git to manage this Worker?",
|
|
387
|
+
result: true,
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
text: "No package.json found. Would you like to create one?",
|
|
391
|
+
result: true,
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
text: "Would you like to use TypeScript?",
|
|
395
|
+
result: true,
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
mockSelect({
|
|
400
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
401
|
+
result: "scheduled",
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
await runWrangler("init");
|
|
405
|
+
const parsed = TOML.parse(
|
|
406
|
+
await fsp.readFile("./wrangler.toml", "utf-8")
|
|
407
|
+
) as RawConfig;
|
|
408
|
+
expect(typeof parsed.compatibility_date).toBe("string");
|
|
409
|
+
expect(parsed.name).toContain("wrangler-tests");
|
|
410
|
+
expect(parsed?.triggers?.crons[0]).toEqual("1 * * * *");
|
|
411
|
+
});
|
|
335
412
|
});
|
|
336
413
|
|
|
337
414
|
describe("git init", () => {
|
|
@@ -358,6 +435,9 @@ describe("init", () => {
|
|
|
358
435
|
`);
|
|
359
436
|
expect(fs.lstatSync(".git").isDirectory()).toBe(true);
|
|
360
437
|
expect(fs.lstatSync(".gitignore").isFile()).toBe(true);
|
|
438
|
+
expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
|
|
439
|
+
"main"
|
|
440
|
+
);
|
|
361
441
|
});
|
|
362
442
|
|
|
363
443
|
it("should not offer to initialize a git repo if it's already inside one", async () => {
|
|
@@ -373,11 +453,12 @@ describe("init", () => {
|
|
|
373
453
|
"err": "",
|
|
374
454
|
"out": "✨ Created wrangler.toml
|
|
375
455
|
✨ Created package.json
|
|
376
|
-
✨ Created tsconfig.json
|
|
456
|
+
✨ Created tsconfig.json
|
|
377
457
|
✨ Created src/index.ts
|
|
458
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
378
459
|
|
|
379
460
|
To start developing your Worker, run \`npm start\`
|
|
380
|
-
To publish your Worker to the Internet, run \`npm run
|
|
461
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
381
462
|
"warn": "",
|
|
382
463
|
}
|
|
383
464
|
`);
|
|
@@ -397,20 +478,48 @@ describe("init", () => {
|
|
|
397
478
|
"err": "",
|
|
398
479
|
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
399
480
|
✨ Created path/to/worker/my-worker/package.json
|
|
400
|
-
✨ Created path/to/worker/my-worker/tsconfig.json
|
|
481
|
+
✨ Created path/to/worker/my-worker/tsconfig.json
|
|
401
482
|
✨ Created path/to/worker/my-worker/src/index.ts
|
|
483
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
402
484
|
|
|
403
485
|
To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
|
|
404
|
-
To publish your Worker to the Internet, run \`npm run
|
|
486
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
405
487
|
"warn": "",
|
|
406
488
|
}
|
|
407
489
|
`);
|
|
408
490
|
});
|
|
409
491
|
|
|
492
|
+
// I... don't know how to test this lol
|
|
410
493
|
it.todo(
|
|
411
494
|
"should not offer to initialize a git repo if git is not installed"
|
|
412
495
|
);
|
|
413
|
-
|
|
496
|
+
|
|
497
|
+
it("should initialize git repo with `main` default branch", async () => {
|
|
498
|
+
mockConfirm(
|
|
499
|
+
{
|
|
500
|
+
text: "Would you like to use git to manage this Worker?",
|
|
501
|
+
result: true,
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
text: "No package.json found. Would you like to create one?",
|
|
505
|
+
result: false,
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
await runWrangler("init");
|
|
509
|
+
expect(std).toMatchInlineSnapshot(`
|
|
510
|
+
Object {
|
|
511
|
+
"debug": "",
|
|
512
|
+
"err": "",
|
|
513
|
+
"out": "✨ Created wrangler.toml
|
|
514
|
+
✨ Initialized git repository",
|
|
515
|
+
"warn": "",
|
|
516
|
+
}
|
|
517
|
+
`);
|
|
518
|
+
|
|
519
|
+
expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
|
|
520
|
+
"refs/heads/main"
|
|
521
|
+
);
|
|
522
|
+
});
|
|
414
523
|
});
|
|
415
524
|
|
|
416
525
|
describe("package.json", () => {
|
|
@@ -427,12 +536,12 @@ describe("init", () => {
|
|
|
427
536
|
{
|
|
428
537
|
text: "Would you like to use TypeScript?",
|
|
429
538
|
result: false,
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
433
|
-
result: false,
|
|
434
539
|
}
|
|
435
540
|
);
|
|
541
|
+
mockSelect({
|
|
542
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
543
|
+
result: "none",
|
|
544
|
+
});
|
|
436
545
|
await runWrangler("init");
|
|
437
546
|
expect(fs.existsSync("./package.json")).toBe(true);
|
|
438
547
|
const packageJson = JSON.parse(
|
|
@@ -469,12 +578,12 @@ describe("init", () => {
|
|
|
469
578
|
{
|
|
470
579
|
text: "Would you like to use TypeScript?",
|
|
471
580
|
result: false,
|
|
472
|
-
},
|
|
473
|
-
{
|
|
474
|
-
text: "Would you like to create a Worker at my-worker/src/index.js?",
|
|
475
|
-
result: false,
|
|
476
581
|
}
|
|
477
582
|
);
|
|
583
|
+
mockSelect({
|
|
584
|
+
text: "Would you like to create a Worker at my-worker/src/index.js?",
|
|
585
|
+
result: "none",
|
|
586
|
+
});
|
|
478
587
|
await runWrangler("init my-worker");
|
|
479
588
|
const packageJson = JSON.parse(
|
|
480
589
|
fs.readFileSync("./my-worker/package.json", "utf-8")
|
|
@@ -504,12 +613,12 @@ describe("init", () => {
|
|
|
504
613
|
{
|
|
505
614
|
text: "Would you like to use TypeScript?",
|
|
506
615
|
result: false,
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
510
|
-
result: false,
|
|
511
616
|
}
|
|
512
617
|
);
|
|
618
|
+
mockSelect({
|
|
619
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
620
|
+
result: "none",
|
|
621
|
+
});
|
|
513
622
|
|
|
514
623
|
fs.writeFileSync(
|
|
515
624
|
"./package.json",
|
|
@@ -546,13 +655,14 @@ describe("init", () => {
|
|
|
546
655
|
{
|
|
547
656
|
text: "Would you like to use TypeScript?",
|
|
548
657
|
result: false,
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
552
|
-
result: false,
|
|
553
658
|
}
|
|
554
659
|
);
|
|
555
660
|
|
|
661
|
+
mockSelect({
|
|
662
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
663
|
+
result: "none",
|
|
664
|
+
});
|
|
665
|
+
|
|
556
666
|
fs.mkdirSync("path/to/worker", { recursive: true });
|
|
557
667
|
fs.writeFileSync(
|
|
558
668
|
"path/to/worker/package.json",
|
|
@@ -589,13 +699,14 @@ describe("init", () => {
|
|
|
589
699
|
{
|
|
590
700
|
text: "Would you like to use TypeScript?",
|
|
591
701
|
result: false,
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
595
|
-
result: false,
|
|
596
702
|
}
|
|
597
703
|
);
|
|
598
704
|
|
|
705
|
+
mockSelect({
|
|
706
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
707
|
+
result: "none",
|
|
708
|
+
});
|
|
709
|
+
|
|
599
710
|
fs.writeFileSync(
|
|
600
711
|
"./package.json",
|
|
601
712
|
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
@@ -616,7 +727,7 @@ describe("init", () => {
|
|
|
616
727
|
"debug": "",
|
|
617
728
|
"err": "",
|
|
618
729
|
"out": "✨ Created wrangler.toml
|
|
619
|
-
✨ Installed wrangler",
|
|
730
|
+
✨ Installed wrangler into devDependencies",
|
|
620
731
|
"warn": "",
|
|
621
732
|
}
|
|
622
733
|
`);
|
|
@@ -635,13 +746,14 @@ describe("init", () => {
|
|
|
635
746
|
{
|
|
636
747
|
text: "Would you like to use TypeScript?",
|
|
637
748
|
result: false,
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
641
|
-
result: false,
|
|
642
749
|
}
|
|
643
750
|
);
|
|
644
751
|
|
|
752
|
+
mockSelect({
|
|
753
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
754
|
+
result: "none",
|
|
755
|
+
});
|
|
756
|
+
|
|
645
757
|
fs.mkdirSync("path/to/worker", { recursive: true });
|
|
646
758
|
fs.writeFileSync(
|
|
647
759
|
"path/to/worker/package.json",
|
|
@@ -664,7 +776,7 @@ describe("init", () => {
|
|
|
664
776
|
"debug": "",
|
|
665
777
|
"err": "",
|
|
666
778
|
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
667
|
-
✨ Installed wrangler",
|
|
779
|
+
✨ Installed wrangler into devDependencies",
|
|
668
780
|
"warn": "",
|
|
669
781
|
}
|
|
670
782
|
`);
|
|
@@ -683,13 +795,14 @@ describe("init", () => {
|
|
|
683
795
|
{
|
|
684
796
|
text: "Would you like to use TypeScript?",
|
|
685
797
|
result: false,
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
689
|
-
result: false,
|
|
690
798
|
}
|
|
691
799
|
);
|
|
692
800
|
|
|
801
|
+
mockSelect({
|
|
802
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
803
|
+
result: "none",
|
|
804
|
+
});
|
|
805
|
+
|
|
693
806
|
fs.writeFileSync(
|
|
694
807
|
"./package.json",
|
|
695
808
|
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
@@ -737,13 +850,14 @@ describe("init", () => {
|
|
|
737
850
|
{
|
|
738
851
|
text: "Would you like to use TypeScript?",
|
|
739
852
|
result: false,
|
|
740
|
-
},
|
|
741
|
-
{
|
|
742
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
743
|
-
result: true,
|
|
744
853
|
}
|
|
745
854
|
);
|
|
746
855
|
|
|
856
|
+
mockSelect({
|
|
857
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
858
|
+
result: "fetch",
|
|
859
|
+
});
|
|
860
|
+
|
|
747
861
|
fs.writeFileSync(
|
|
748
862
|
"./package.json",
|
|
749
863
|
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
@@ -780,13 +894,14 @@ describe("init", () => {
|
|
|
780
894
|
{
|
|
781
895
|
text: "Would you like to use TypeScript?",
|
|
782
896
|
result: true,
|
|
783
|
-
},
|
|
784
|
-
{
|
|
785
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
786
|
-
result: true,
|
|
787
897
|
}
|
|
788
898
|
);
|
|
789
899
|
|
|
900
|
+
mockSelect({
|
|
901
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
902
|
+
result: "fetch",
|
|
903
|
+
});
|
|
904
|
+
|
|
790
905
|
fs.writeFileSync(
|
|
791
906
|
"./package.json",
|
|
792
907
|
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
@@ -801,8 +916,9 @@ describe("init", () => {
|
|
|
801
916
|
"debug": "",
|
|
802
917
|
"err": "",
|
|
803
918
|
"out": "✨ Created wrangler.toml
|
|
804
|
-
✨ Created tsconfig.json
|
|
919
|
+
✨ Created tsconfig.json
|
|
805
920
|
✨ Created src/index.ts
|
|
921
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
806
922
|
|
|
807
923
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
808
924
|
To publish your Worker to the Internet, run \`npx wrangler publish\`",
|
|
@@ -828,12 +944,12 @@ describe("init", () => {
|
|
|
828
944
|
{
|
|
829
945
|
text: "Would you like to use TypeScript?",
|
|
830
946
|
result: true,
|
|
831
|
-
},
|
|
832
|
-
{
|
|
833
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
834
|
-
result: true,
|
|
835
947
|
}
|
|
836
948
|
);
|
|
949
|
+
mockSelect({
|
|
950
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
951
|
+
result: "fetch",
|
|
952
|
+
});
|
|
837
953
|
await runWrangler("init");
|
|
838
954
|
|
|
839
955
|
expect(fs.existsSync("./package.json")).toBe(true);
|
|
@@ -845,17 +961,18 @@ describe("init", () => {
|
|
|
845
961
|
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
846
962
|
|
|
847
963
|
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
848
|
-
expect(packageJson.scripts.
|
|
964
|
+
expect(packageJson.scripts.deploy).toBe("wrangler publish");
|
|
849
965
|
expect(packageJson.name).toContain("wrangler-tests");
|
|
850
966
|
expect(packageJson.version).toEqual("0.0.0");
|
|
851
967
|
expect(std.out).toMatchInlineSnapshot(`
|
|
852
968
|
"✨ Created wrangler.toml
|
|
853
969
|
✨ Created package.json
|
|
854
|
-
✨ Created tsconfig.json
|
|
970
|
+
✨ Created tsconfig.json
|
|
855
971
|
✨ Created src/index.ts
|
|
972
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
856
973
|
|
|
857
974
|
To start developing your Worker, run \`npm start\`
|
|
858
|
-
To publish your Worker to the Internet, run \`npm run
|
|
975
|
+
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
859
976
|
`);
|
|
860
977
|
});
|
|
861
978
|
|
|
@@ -872,18 +989,18 @@ describe("init", () => {
|
|
|
872
989
|
{
|
|
873
990
|
text: "Would you like to use TypeScript?",
|
|
874
991
|
result: true,
|
|
875
|
-
},
|
|
876
|
-
{
|
|
877
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
878
|
-
result: true,
|
|
879
992
|
}
|
|
880
993
|
);
|
|
994
|
+
mockSelect({
|
|
995
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
996
|
+
result: "fetch",
|
|
997
|
+
});
|
|
881
998
|
await fsp.writeFile(
|
|
882
999
|
"./package.json",
|
|
883
1000
|
JSON.stringify({
|
|
884
1001
|
scripts: {
|
|
885
1002
|
start: "test-start",
|
|
886
|
-
|
|
1003
|
+
deploy: "test-publish",
|
|
887
1004
|
},
|
|
888
1005
|
})
|
|
889
1006
|
);
|
|
@@ -896,11 +1013,12 @@ describe("init", () => {
|
|
|
896
1013
|
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
897
1014
|
|
|
898
1015
|
expect(packageJson.scripts.start).toBe("test-start");
|
|
899
|
-
expect(packageJson.scripts.
|
|
1016
|
+
expect(packageJson.scripts.deploy).toBe("test-publish");
|
|
900
1017
|
expect(std.out).toMatchInlineSnapshot(`
|
|
901
1018
|
"✨ Created wrangler.toml
|
|
902
|
-
✨ Created tsconfig.json
|
|
1019
|
+
✨ Created tsconfig.json
|
|
903
1020
|
✨ Created src/index.ts
|
|
1021
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
904
1022
|
|
|
905
1023
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
906
1024
|
To publish your Worker to the Internet, run \`npx wrangler publish\`"
|
|
@@ -940,7 +1058,8 @@ describe("init", () => {
|
|
|
940
1058
|
"debug": "",
|
|
941
1059
|
"err": "",
|
|
942
1060
|
"out": "✨ Created wrangler.toml
|
|
943
|
-
✨ Created tsconfig.json
|
|
1061
|
+
✨ Created tsconfig.json
|
|
1062
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
944
1063
|
"warn": "",
|
|
945
1064
|
}
|
|
946
1065
|
`);
|
|
@@ -981,7 +1100,8 @@ describe("init", () => {
|
|
|
981
1100
|
"debug": "",
|
|
982
1101
|
"err": "",
|
|
983
1102
|
"out": "✨ Created my-worker/wrangler.toml
|
|
984
|
-
✨ Created my-worker/tsconfig.json
|
|
1103
|
+
✨ Created my-worker/tsconfig.json
|
|
1104
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
985
1105
|
"warn": "",
|
|
986
1106
|
}
|
|
987
1107
|
`);
|
|
@@ -1000,12 +1120,12 @@ describe("init", () => {
|
|
|
1000
1120
|
{
|
|
1001
1121
|
text: "Would you like to use TypeScript?",
|
|
1002
1122
|
result: true,
|
|
1003
|
-
},
|
|
1004
|
-
{
|
|
1005
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
1006
|
-
result: false,
|
|
1007
1123
|
}
|
|
1008
1124
|
);
|
|
1125
|
+
mockSelect({
|
|
1126
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1127
|
+
result: "none",
|
|
1128
|
+
});
|
|
1009
1129
|
await runWrangler("init");
|
|
1010
1130
|
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
1011
1131
|
const { config: tsconfigJson, error: tsConfigParseError } =
|
|
@@ -1027,7 +1147,8 @@ describe("init", () => {
|
|
|
1027
1147
|
"err": "",
|
|
1028
1148
|
"out": "✨ Created wrangler.toml
|
|
1029
1149
|
✨ Created package.json
|
|
1030
|
-
✨ Created tsconfig.json
|
|
1150
|
+
✨ Created tsconfig.json
|
|
1151
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies",
|
|
1031
1152
|
"warn": "",
|
|
1032
1153
|
}
|
|
1033
1154
|
`);
|
|
@@ -1052,16 +1173,15 @@ describe("init", () => {
|
|
|
1052
1173
|
"utf-8"
|
|
1053
1174
|
);
|
|
1054
1175
|
|
|
1055
|
-
mockConfirm(
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
);
|
|
1176
|
+
mockConfirm({
|
|
1177
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1178
|
+
result: false,
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
mockSelect({
|
|
1182
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1183
|
+
result: "fetch",
|
|
1184
|
+
});
|
|
1065
1185
|
|
|
1066
1186
|
await runWrangler("init");
|
|
1067
1187
|
const tsconfigJson = JSON.parse(
|
|
@@ -1102,16 +1222,15 @@ describe("init", () => {
|
|
|
1102
1222
|
"utf-8"
|
|
1103
1223
|
);
|
|
1104
1224
|
|
|
1105
|
-
mockConfirm(
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
);
|
|
1225
|
+
mockConfirm({
|
|
1226
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1227
|
+
result: false,
|
|
1228
|
+
});
|
|
1229
|
+
|
|
1230
|
+
mockSelect({
|
|
1231
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.ts?",
|
|
1232
|
+
result: "fetch",
|
|
1233
|
+
});
|
|
1115
1234
|
|
|
1116
1235
|
await runWrangler("init path/to/worker/my-worker");
|
|
1117
1236
|
const tsconfigJson = JSON.parse(
|
|
@@ -1145,12 +1264,12 @@ describe("init", () => {
|
|
|
1145
1264
|
{
|
|
1146
1265
|
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
1147
1266
|
result: true,
|
|
1148
|
-
},
|
|
1149
|
-
{
|
|
1150
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
1151
|
-
result: false,
|
|
1152
1267
|
}
|
|
1153
1268
|
);
|
|
1269
|
+
mockSelect({
|
|
1270
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1271
|
+
result: "none",
|
|
1272
|
+
});
|
|
1154
1273
|
fs.writeFileSync(
|
|
1155
1274
|
"./package.json",
|
|
1156
1275
|
JSON.stringify({
|
|
@@ -1179,8 +1298,8 @@ describe("init", () => {
|
|
|
1179
1298
|
"debug": "",
|
|
1180
1299
|
"err": "",
|
|
1181
1300
|
"out": "✨ Created wrangler.toml
|
|
1182
|
-
✨ Installed @cloudflare/workers-types
|
|
1183
|
-
Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
|
|
1301
|
+
✨ Installed @cloudflare/workers-types into devDependencies
|
|
1302
|
+
🚨 Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
|
|
1184
1303
|
"warn": "",
|
|
1185
1304
|
}
|
|
1186
1305
|
`);
|
|
@@ -1205,16 +1324,15 @@ describe("init", () => {
|
|
|
1205
1324
|
"utf-8"
|
|
1206
1325
|
);
|
|
1207
1326
|
|
|
1208
|
-
mockConfirm(
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
);
|
|
1327
|
+
mockConfirm({
|
|
1328
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1329
|
+
result: false,
|
|
1330
|
+
});
|
|
1331
|
+
|
|
1332
|
+
mockSelect({
|
|
1333
|
+
text: "Would you like to create a Worker at src/index.ts?",
|
|
1334
|
+
result: "fetch",
|
|
1335
|
+
});
|
|
1218
1336
|
|
|
1219
1337
|
fs.mkdirSync("./sub-1/sub-2", { recursive: true });
|
|
1220
1338
|
process.chdir("./sub-1/sub-2");
|
|
@@ -1261,12 +1379,12 @@ describe("init", () => {
|
|
|
1261
1379
|
{
|
|
1262
1380
|
text: "Would you like to use TypeScript?",
|
|
1263
1381
|
result: false,
|
|
1264
|
-
},
|
|
1265
|
-
{
|
|
1266
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
1267
|
-
result: true,
|
|
1268
1382
|
}
|
|
1269
1383
|
);
|
|
1384
|
+
mockSelect({
|
|
1385
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
1386
|
+
result: "fetch",
|
|
1387
|
+
});
|
|
1270
1388
|
await runWrangler("init");
|
|
1271
1389
|
|
|
1272
1390
|
expect(fs.existsSync("./package.json")).toBe(true);
|
|
@@ -1278,7 +1396,7 @@ describe("init", () => {
|
|
|
1278
1396
|
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
1279
1397
|
|
|
1280
1398
|
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
1281
|
-
expect(packageJson.scripts.
|
|
1399
|
+
expect(packageJson.scripts.deploy).toBe("wrangler publish");
|
|
1282
1400
|
expect(packageJson.name).toContain("wrangler-tests");
|
|
1283
1401
|
expect(packageJson.version).toEqual("0.0.0");
|
|
1284
1402
|
expect(std.out).toMatchInlineSnapshot(`
|
|
@@ -1287,7 +1405,7 @@ describe("init", () => {
|
|
|
1287
1405
|
✨ Created src/index.js
|
|
1288
1406
|
|
|
1289
1407
|
To start developing your Worker, run \`npm start\`
|
|
1290
|
-
To publish your Worker to the Internet, run \`npm run
|
|
1408
|
+
To publish your Worker to the Internet, run \`npm run deploy\`"
|
|
1291
1409
|
`);
|
|
1292
1410
|
});
|
|
1293
1411
|
|
|
@@ -1304,18 +1422,18 @@ describe("init", () => {
|
|
|
1304
1422
|
{
|
|
1305
1423
|
text: "Would you like to use TypeScript?",
|
|
1306
1424
|
result: false,
|
|
1307
|
-
},
|
|
1308
|
-
{
|
|
1309
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
1310
|
-
result: true,
|
|
1311
1425
|
}
|
|
1312
1426
|
);
|
|
1427
|
+
mockSelect({
|
|
1428
|
+
text: "Would you like to create a Worker at src/index.js?",
|
|
1429
|
+
result: "fetch",
|
|
1430
|
+
});
|
|
1313
1431
|
await fsp.writeFile(
|
|
1314
1432
|
"./package.json",
|
|
1315
1433
|
JSON.stringify({
|
|
1316
1434
|
scripts: {
|
|
1317
1435
|
start: "test-start",
|
|
1318
|
-
|
|
1436
|
+
deploy: "test-publish",
|
|
1319
1437
|
},
|
|
1320
1438
|
})
|
|
1321
1439
|
);
|
|
@@ -1328,7 +1446,7 @@ describe("init", () => {
|
|
|
1328
1446
|
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
1329
1447
|
|
|
1330
1448
|
expect(packageJson.scripts.start).toBe("test-start");
|
|
1331
|
-
expect(packageJson.scripts.
|
|
1449
|
+
expect(packageJson.scripts.deploy).toBe("test-publish");
|
|
1332
1450
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1333
1451
|
"✨ Created wrangler.toml
|
|
1334
1452
|
✨ Created src/index.js
|
|
@@ -1445,11 +1563,12 @@ describe("init", () => {
|
|
|
1445
1563
|
"out": "✨ Created wrangler.toml
|
|
1446
1564
|
✨ Initialized git repository
|
|
1447
1565
|
✨ Created package.json
|
|
1448
|
-
✨ Created tsconfig.json
|
|
1566
|
+
✨ Created tsconfig.json
|
|
1449
1567
|
✨ Created src/index.ts
|
|
1568
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1450
1569
|
|
|
1451
1570
|
To start developing your Worker, run \`npm start\`
|
|
1452
|
-
To publish your Worker to the Internet, run \`npm run
|
|
1571
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
1453
1572
|
"warn": "",
|
|
1454
1573
|
}
|
|
1455
1574
|
`);
|
|
@@ -1473,11 +1592,12 @@ describe("init", () => {
|
|
|
1473
1592
|
"out": "✨ Created path/to/worker/wrangler.toml
|
|
1474
1593
|
✨ Initialized git repository at path/to/worker
|
|
1475
1594
|
✨ Created path/to/worker/package.json
|
|
1476
|
-
✨ Created path/to/worker/tsconfig.json
|
|
1595
|
+
✨ Created path/to/worker/tsconfig.json
|
|
1477
1596
|
✨ Created path/to/worker/src/index.ts
|
|
1597
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1478
1598
|
|
|
1479
1599
|
To start developing your Worker, run \`cd path/to/worker && npm start\`
|
|
1480
|
-
To publish your Worker to the Internet, run \`npm run
|
|
1600
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
1481
1601
|
"warn": "",
|
|
1482
1602
|
}
|
|
1483
1603
|
`);
|
|
@@ -1503,11 +1623,12 @@ describe("init", () => {
|
|
|
1503
1623
|
"out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
|
|
1504
1624
|
✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
|
|
1505
1625
|
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
|
|
1506
|
-
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
|
|
1626
|
+
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
|
|
1507
1627
|
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
|
|
1628
|
+
✨ Installed @cloudflare/workers-types and typescript into devDependencies
|
|
1508
1629
|
|
|
1509
1630
|
To start developing your Worker, run \`cd WEIRD_w0rkr_N4m3.js.tsx.tar.gz && npm start\`
|
|
1510
|
-
To publish your Worker to the Internet, run \`npm run
|
|
1631
|
+
To publish your Worker to the Internet, run \`npm run deploy\`",
|
|
1511
1632
|
"warn": "",
|
|
1512
1633
|
}
|
|
1513
1634
|
`);
|