wrangler 0.0.33 → 0.0.34
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/package.json +1 -1
- package/src/__tests__/helpers/mock-dialogs.ts +2 -1
- package/src/__tests__/init.test.ts +359 -39
- package/src/index.tsx +68 -21
- package/wrangler-dist/cli.js +15 -16
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { confirm, prompt } from "../../dialogs";
|
|
2
|
+
import { normalizeSlashes } from "./mock-console";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The expected values for a confirmation request.
|
|
@@ -20,7 +21,7 @@ export interface ConfirmExpectation {
|
|
|
20
21
|
export function mockConfirm(...expectations: ConfirmExpectation[]) {
|
|
21
22
|
(confirm as jest.Mock).mockImplementation((text: string) => {
|
|
22
23
|
for (const { text: expectedText, result } of expectations) {
|
|
23
|
-
if (text === expectedText) {
|
|
24
|
+
if (normalizeSlashes(text) === normalizeSlashes(expectedText)) {
|
|
24
25
|
return Promise.resolve(result);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -43,7 +43,7 @@ describe("init", () => {
|
|
|
43
43
|
expect(fs.existsSync("./package.json")).toBe(true);
|
|
44
44
|
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
45
45
|
expect(std.out).toMatchInlineSnapshot(`
|
|
46
|
-
"✨
|
|
46
|
+
"✨ Created wrangler.toml
|
|
47
47
|
✨ Initialized git repository
|
|
48
48
|
✨ Created package.json
|
|
49
49
|
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
@@ -69,11 +69,11 @@ describe("init", () => {
|
|
|
69
69
|
);
|
|
70
70
|
expect(parsedWranglerToml.main).toEqual("src/index.ts");
|
|
71
71
|
expect(std.out).toMatchInlineSnapshot(`
|
|
72
|
-
"✨
|
|
73
|
-
✨ Initialized git repository
|
|
74
|
-
✨ Created package.json
|
|
75
|
-
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
76
|
-
✨ Created src/index.ts
|
|
72
|
+
"✨ Created my-worker/wrangler.toml
|
|
73
|
+
✨ Initialized git repository at my-worker
|
|
74
|
+
✨ Created my-worker/package.json
|
|
75
|
+
✨ Created my-worker/tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
76
|
+
✨ Created my-worker/src/index.ts
|
|
77
77
|
|
|
78
78
|
To start developing your Worker, run \`cd my-worker && npm start\`
|
|
79
79
|
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
@@ -94,7 +94,7 @@ describe("init", () => {
|
|
|
94
94
|
Object {
|
|
95
95
|
"debug": "",
|
|
96
96
|
"err": "",
|
|
97
|
-
"out": "✨
|
|
97
|
+
"out": "✨ Created wrangler.toml
|
|
98
98
|
✨ Initialized git repository
|
|
99
99
|
✨ Created package.json
|
|
100
100
|
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
@@ -166,6 +166,14 @@ describe("init", () => {
|
|
|
166
166
|
expect(parsed.name).toContain("wrangler-tests");
|
|
167
167
|
expect(fs.existsSync("./package.json")).toBe(false);
|
|
168
168
|
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
169
|
+
expect(std).toMatchInlineSnapshot(`
|
|
170
|
+
Object {
|
|
171
|
+
"debug": "",
|
|
172
|
+
"err": "",
|
|
173
|
+
"out": "✨ Created wrangler.toml",
|
|
174
|
+
"warn": "",
|
|
175
|
+
}
|
|
176
|
+
`);
|
|
169
177
|
});
|
|
170
178
|
|
|
171
179
|
it("should create a wrangler.toml and a directory for a named Worker ", async () => {
|
|
@@ -187,6 +195,15 @@ describe("init", () => {
|
|
|
187
195
|
expect(parsed.name).toBe("my-worker");
|
|
188
196
|
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
189
197
|
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
198
|
+
|
|
199
|
+
expect(std).toMatchInlineSnapshot(`
|
|
200
|
+
Object {
|
|
201
|
+
"debug": "",
|
|
202
|
+
"err": "",
|
|
203
|
+
"out": "✨ Created my-worker/wrangler.toml",
|
|
204
|
+
"warn": "",
|
|
205
|
+
}
|
|
206
|
+
`);
|
|
190
207
|
});
|
|
191
208
|
|
|
192
209
|
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
@@ -200,9 +217,20 @@ describe("init", () => {
|
|
|
200
217
|
result: false,
|
|
201
218
|
});
|
|
202
219
|
await runWrangler("init");
|
|
203
|
-
expect(std.warn).toContain("wrangler.toml
|
|
220
|
+
expect(std.warn).toContain("wrangler.toml already exists!");
|
|
204
221
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
205
222
|
expect(parsed.compatibility_date).toBe("something-else");
|
|
223
|
+
|
|
224
|
+
expect(std).toMatchInlineSnapshot(`
|
|
225
|
+
Object {
|
|
226
|
+
"debug": "",
|
|
227
|
+
"err": "",
|
|
228
|
+
"out": "",
|
|
229
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mwrangler.toml already exists![0m
|
|
230
|
+
|
|
231
|
+
",
|
|
232
|
+
}
|
|
233
|
+
`);
|
|
206
234
|
});
|
|
207
235
|
|
|
208
236
|
it("should display warning when wrangler.toml already exists in the target directory, and exit if user does not want to carry on", async () => {
|
|
@@ -217,11 +245,21 @@ describe("init", () => {
|
|
|
217
245
|
result: false,
|
|
218
246
|
});
|
|
219
247
|
await runWrangler("init path/to/worker");
|
|
220
|
-
expect(std.warn).toContain("wrangler.toml
|
|
248
|
+
expect(std.warn).toContain("wrangler.toml already exists!");
|
|
221
249
|
const parsed = TOML.parse(
|
|
222
250
|
await fsp.readFile("path/to/worker/wrangler.toml", "utf-8")
|
|
223
251
|
);
|
|
224
252
|
expect(parsed.compatibility_date).toBe("something-else");
|
|
253
|
+
expect(std).toMatchInlineSnapshot(`
|
|
254
|
+
Object {
|
|
255
|
+
"debug": "",
|
|
256
|
+
"err": "",
|
|
257
|
+
"out": "",
|
|
258
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mpath/to/worker/wrangler.toml already exists![0m
|
|
259
|
+
|
|
260
|
+
",
|
|
261
|
+
}
|
|
262
|
+
`);
|
|
225
263
|
});
|
|
226
264
|
|
|
227
265
|
it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
|
|
@@ -280,9 +318,19 @@ describe("init", () => {
|
|
|
280
318
|
}
|
|
281
319
|
);
|
|
282
320
|
await runWrangler("init");
|
|
283
|
-
expect(std.warn).toContain("wrangler.toml
|
|
321
|
+
expect(std.warn).toContain("wrangler.toml already exists!");
|
|
284
322
|
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
285
323
|
expect(parsed.compatibility_date).toBe("something-else");
|
|
324
|
+
expect(std).toMatchInlineSnapshot(`
|
|
325
|
+
Object {
|
|
326
|
+
"debug": "",
|
|
327
|
+
"err": "",
|
|
328
|
+
"out": "",
|
|
329
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mwrangler.toml already exists![0m
|
|
330
|
+
|
|
331
|
+
",
|
|
332
|
+
}
|
|
333
|
+
`);
|
|
286
334
|
});
|
|
287
335
|
});
|
|
288
336
|
|
|
@@ -303,7 +351,7 @@ describe("init", () => {
|
|
|
303
351
|
Object {
|
|
304
352
|
"debug": "",
|
|
305
353
|
"err": "",
|
|
306
|
-
"out": "✨
|
|
354
|
+
"out": "✨ Created wrangler.toml
|
|
307
355
|
✨ Initialized git repository",
|
|
308
356
|
"warn": "",
|
|
309
357
|
}
|
|
@@ -323,7 +371,7 @@ describe("init", () => {
|
|
|
323
371
|
Object {
|
|
324
372
|
"debug": "",
|
|
325
373
|
"err": "",
|
|
326
|
-
"out": "✨
|
|
374
|
+
"out": "✨ Created wrangler.toml
|
|
327
375
|
✨ Created package.json
|
|
328
376
|
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
329
377
|
✨ Created src/index.ts
|
|
@@ -347,10 +395,10 @@ describe("init", () => {
|
|
|
347
395
|
Object {
|
|
348
396
|
"debug": "",
|
|
349
397
|
"err": "",
|
|
350
|
-
"out": "✨
|
|
351
|
-
✨ Created package.json
|
|
352
|
-
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
353
|
-
✨ Created src/index.ts
|
|
398
|
+
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
399
|
+
✨ Created path/to/worker/my-worker/package.json
|
|
400
|
+
✨ Created path/to/worker/my-worker/tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
401
|
+
✨ Created path/to/worker/my-worker/src/index.ts
|
|
354
402
|
|
|
355
403
|
To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
|
|
356
404
|
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
@@ -397,6 +445,15 @@ describe("init", () => {
|
|
|
397
445
|
});
|
|
398
446
|
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
399
447
|
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
448
|
+
expect(std).toMatchInlineSnapshot(`
|
|
449
|
+
Object {
|
|
450
|
+
"debug": "",
|
|
451
|
+
"err": "",
|
|
452
|
+
"out": "✨ Created wrangler.toml
|
|
453
|
+
✨ Created package.json",
|
|
454
|
+
"warn": "",
|
|
455
|
+
}
|
|
456
|
+
`);
|
|
400
457
|
});
|
|
401
458
|
|
|
402
459
|
it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
|
|
@@ -414,7 +471,7 @@ describe("init", () => {
|
|
|
414
471
|
result: false,
|
|
415
472
|
},
|
|
416
473
|
{
|
|
417
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
474
|
+
text: "Would you like to create a Worker at my-worker/src/index.js?",
|
|
418
475
|
result: false,
|
|
419
476
|
}
|
|
420
477
|
);
|
|
@@ -423,6 +480,15 @@ describe("init", () => {
|
|
|
423
480
|
fs.readFileSync("./my-worker/package.json", "utf-8")
|
|
424
481
|
);
|
|
425
482
|
expect(packageJson.name).toBe("my-worker");
|
|
483
|
+
expect(std).toMatchInlineSnapshot(`
|
|
484
|
+
Object {
|
|
485
|
+
"debug": "",
|
|
486
|
+
"err": "",
|
|
487
|
+
"out": "✨ Created my-worker/wrangler.toml
|
|
488
|
+
✨ Created my-worker/package.json",
|
|
489
|
+
"warn": "",
|
|
490
|
+
}
|
|
491
|
+
`);
|
|
426
492
|
});
|
|
427
493
|
|
|
428
494
|
it("should not touch an existing package.json in the same directory", async () => {
|
|
@@ -432,7 +498,7 @@ describe("init", () => {
|
|
|
432
498
|
result: false,
|
|
433
499
|
},
|
|
434
500
|
{
|
|
435
|
-
text: "Would you like to install wrangler into
|
|
501
|
+
text: "Would you like to install wrangler into package.json?",
|
|
436
502
|
result: false,
|
|
437
503
|
},
|
|
438
504
|
{
|
|
@@ -457,6 +523,14 @@ describe("init", () => {
|
|
|
457
523
|
);
|
|
458
524
|
expect(packageJson.name).toEqual("test");
|
|
459
525
|
expect(packageJson.version).toEqual("1.0.0");
|
|
526
|
+
expect(std).toMatchInlineSnapshot(`
|
|
527
|
+
Object {
|
|
528
|
+
"debug": "",
|
|
529
|
+
"err": "",
|
|
530
|
+
"out": "✨ Created wrangler.toml",
|
|
531
|
+
"warn": "",
|
|
532
|
+
}
|
|
533
|
+
`);
|
|
460
534
|
});
|
|
461
535
|
|
|
462
536
|
it("should not touch an existing package.json in a target directory", async () => {
|
|
@@ -466,7 +540,7 @@ describe("init", () => {
|
|
|
466
540
|
result: false,
|
|
467
541
|
},
|
|
468
542
|
{
|
|
469
|
-
text: "Would you like to install wrangler into
|
|
543
|
+
text: "Would you like to install wrangler into path/to/worker/package.json?",
|
|
470
544
|
result: false,
|
|
471
545
|
},
|
|
472
546
|
{
|
|
@@ -474,7 +548,7 @@ describe("init", () => {
|
|
|
474
548
|
result: false,
|
|
475
549
|
},
|
|
476
550
|
{
|
|
477
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
551
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
478
552
|
result: false,
|
|
479
553
|
}
|
|
480
554
|
);
|
|
@@ -492,6 +566,14 @@ describe("init", () => {
|
|
|
492
566
|
);
|
|
493
567
|
expect(packageJson.name).toEqual("test");
|
|
494
568
|
expect(packageJson.version).toEqual("1.0.0");
|
|
569
|
+
expect(std).toMatchInlineSnapshot(`
|
|
570
|
+
Object {
|
|
571
|
+
"debug": "",
|
|
572
|
+
"err": "",
|
|
573
|
+
"out": "✨ Created path/to/worker/my-worker/wrangler.toml",
|
|
574
|
+
"warn": "",
|
|
575
|
+
}
|
|
576
|
+
`);
|
|
495
577
|
});
|
|
496
578
|
|
|
497
579
|
it("should offer to install wrangler into an existing package.json", async () => {
|
|
@@ -501,7 +583,7 @@ describe("init", () => {
|
|
|
501
583
|
result: false,
|
|
502
584
|
},
|
|
503
585
|
{
|
|
504
|
-
text: "Would you like to install wrangler into
|
|
586
|
+
text: "Would you like to install wrangler into package.json?",
|
|
505
587
|
result: true,
|
|
506
588
|
},
|
|
507
589
|
{
|
|
@@ -529,6 +611,15 @@ describe("init", () => {
|
|
|
529
611
|
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
530
612
|
`wrangler@${wranglerVersion}`
|
|
531
613
|
);
|
|
614
|
+
expect(std).toMatchInlineSnapshot(`
|
|
615
|
+
Object {
|
|
616
|
+
"debug": "",
|
|
617
|
+
"err": "",
|
|
618
|
+
"out": "✨ Created wrangler.toml
|
|
619
|
+
✨ Installed wrangler",
|
|
620
|
+
"warn": "",
|
|
621
|
+
}
|
|
622
|
+
`);
|
|
532
623
|
});
|
|
533
624
|
|
|
534
625
|
it("should offer to install wrangler into a package.json relative to the target directory", async () => {
|
|
@@ -538,7 +629,7 @@ describe("init", () => {
|
|
|
538
629
|
result: false,
|
|
539
630
|
},
|
|
540
631
|
{
|
|
541
|
-
text: "Would you like to install wrangler into
|
|
632
|
+
text: "Would you like to install wrangler into path/to/worker/package.json?",
|
|
542
633
|
result: true,
|
|
543
634
|
},
|
|
544
635
|
{
|
|
@@ -546,7 +637,7 @@ describe("init", () => {
|
|
|
546
637
|
result: false,
|
|
547
638
|
},
|
|
548
639
|
{
|
|
549
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
640
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.js?",
|
|
550
641
|
result: false,
|
|
551
642
|
}
|
|
552
643
|
);
|
|
@@ -568,6 +659,15 @@ describe("init", () => {
|
|
|
568
659
|
`wrangler@${wranglerVersion}`
|
|
569
660
|
);
|
|
570
661
|
expect(mockPackageManager.cwd).toBe(process.cwd());
|
|
662
|
+
expect(std).toMatchInlineSnapshot(`
|
|
663
|
+
Object {
|
|
664
|
+
"debug": "",
|
|
665
|
+
"err": "",
|
|
666
|
+
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
667
|
+
✨ Installed wrangler",
|
|
668
|
+
"warn": "",
|
|
669
|
+
}
|
|
670
|
+
`);
|
|
571
671
|
});
|
|
572
672
|
|
|
573
673
|
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
@@ -577,7 +677,7 @@ describe("init", () => {
|
|
|
577
677
|
result: false,
|
|
578
678
|
},
|
|
579
679
|
{
|
|
580
|
-
text: "Would you like to install wrangler into
|
|
680
|
+
text: "Would you like to install wrangler into ../../package.json?",
|
|
581
681
|
result: false,
|
|
582
682
|
},
|
|
583
683
|
{
|
|
@@ -612,6 +712,14 @@ describe("init", () => {
|
|
|
612
712
|
"version": "1.0.0",
|
|
613
713
|
}
|
|
614
714
|
`);
|
|
715
|
+
expect(std).toMatchInlineSnapshot(`
|
|
716
|
+
Object {
|
|
717
|
+
"debug": "",
|
|
718
|
+
"err": "",
|
|
719
|
+
"out": "✨ Created wrangler.toml",
|
|
720
|
+
"warn": "",
|
|
721
|
+
}
|
|
722
|
+
`);
|
|
615
723
|
});
|
|
616
724
|
});
|
|
617
725
|
|
|
@@ -623,7 +731,7 @@ describe("init", () => {
|
|
|
623
731
|
result: false,
|
|
624
732
|
},
|
|
625
733
|
{
|
|
626
|
-
text: "Would you like to install wrangler into
|
|
734
|
+
text: "Would you like to install wrangler into package.json?",
|
|
627
735
|
result: false,
|
|
628
736
|
},
|
|
629
737
|
{
|
|
@@ -645,6 +753,18 @@ describe("init", () => {
|
|
|
645
753
|
await runWrangler("init");
|
|
646
754
|
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
647
755
|
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
756
|
+
expect(std).toMatchInlineSnapshot(`
|
|
757
|
+
Object {
|
|
758
|
+
"debug": "",
|
|
759
|
+
"err": "",
|
|
760
|
+
"out": "✨ Created wrangler.toml
|
|
761
|
+
✨ Created src/index.js
|
|
762
|
+
|
|
763
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
764
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`",
|
|
765
|
+
"warn": "",
|
|
766
|
+
}
|
|
767
|
+
`);
|
|
648
768
|
});
|
|
649
769
|
|
|
650
770
|
it("should offer to create a worker in a typescript project", async () => {
|
|
@@ -654,7 +774,7 @@ describe("init", () => {
|
|
|
654
774
|
result: false,
|
|
655
775
|
},
|
|
656
776
|
{
|
|
657
|
-
text: "Would you like to install wrangler into
|
|
777
|
+
text: "Would you like to install wrangler into package.json?",
|
|
658
778
|
result: false,
|
|
659
779
|
},
|
|
660
780
|
{
|
|
@@ -676,6 +796,19 @@ describe("init", () => {
|
|
|
676
796
|
await runWrangler("init");
|
|
677
797
|
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
678
798
|
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
799
|
+
expect(std).toMatchInlineSnapshot(`
|
|
800
|
+
Object {
|
|
801
|
+
"debug": "",
|
|
802
|
+
"err": "",
|
|
803
|
+
"out": "✨ Created wrangler.toml
|
|
804
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
805
|
+
✨ Created src/index.ts
|
|
806
|
+
|
|
807
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
808
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`",
|
|
809
|
+
"warn": "",
|
|
810
|
+
}
|
|
811
|
+
`);
|
|
679
812
|
});
|
|
680
813
|
|
|
681
814
|
it("should add scripts for a typescript project with .ts extension", async () => {
|
|
@@ -689,7 +822,7 @@ describe("init", () => {
|
|
|
689
822
|
result: true,
|
|
690
823
|
},
|
|
691
824
|
{
|
|
692
|
-
text: "Would you like to install wrangler into
|
|
825
|
+
text: "Would you like to install wrangler into package.json?",
|
|
693
826
|
result: false,
|
|
694
827
|
},
|
|
695
828
|
{
|
|
@@ -716,7 +849,7 @@ describe("init", () => {
|
|
|
716
849
|
expect(packageJson.name).toContain("wrangler-tests");
|
|
717
850
|
expect(packageJson.version).toEqual("0.0.0");
|
|
718
851
|
expect(std.out).toMatchInlineSnapshot(`
|
|
719
|
-
"✨
|
|
852
|
+
"✨ Created wrangler.toml
|
|
720
853
|
✨ Created package.json
|
|
721
854
|
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
722
855
|
✨ Created src/index.ts
|
|
@@ -733,7 +866,7 @@ describe("init", () => {
|
|
|
733
866
|
result: false,
|
|
734
867
|
},
|
|
735
868
|
{
|
|
736
|
-
text: "Would you like to install wrangler into
|
|
869
|
+
text: "Would you like to install wrangler into package.json?",
|
|
737
870
|
result: false,
|
|
738
871
|
},
|
|
739
872
|
{
|
|
@@ -765,7 +898,7 @@ describe("init", () => {
|
|
|
765
898
|
expect(packageJson.scripts.start).toBe("test-start");
|
|
766
899
|
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
767
900
|
expect(std.out).toMatchInlineSnapshot(`
|
|
768
|
-
"✨
|
|
901
|
+
"✨ Created wrangler.toml
|
|
769
902
|
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
770
903
|
✨ Created src/index.ts
|
|
771
904
|
|
|
@@ -781,7 +914,7 @@ describe("init", () => {
|
|
|
781
914
|
result: false,
|
|
782
915
|
},
|
|
783
916
|
{
|
|
784
|
-
text: "Would you like to install wrangler into
|
|
917
|
+
text: "Would you like to install wrangler into package.json?",
|
|
785
918
|
result: false,
|
|
786
919
|
},
|
|
787
920
|
{
|
|
@@ -802,6 +935,56 @@ describe("init", () => {
|
|
|
802
935
|
await runWrangler("init");
|
|
803
936
|
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
804
937
|
expect(fs.readFileSync("./src/index.ts", "utf-8")).toBe(PLACEHOLDER);
|
|
938
|
+
expect(std).toMatchInlineSnapshot(`
|
|
939
|
+
Object {
|
|
940
|
+
"debug": "",
|
|
941
|
+
"err": "",
|
|
942
|
+
"out": "✨ Created wrangler.toml
|
|
943
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies",
|
|
944
|
+
"warn": "",
|
|
945
|
+
}
|
|
946
|
+
`);
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
it("should not offer to create a worker in a ts project for a named worker if a file already exists at the location", async () => {
|
|
950
|
+
mockConfirm(
|
|
951
|
+
{
|
|
952
|
+
text: "Would you like to use git to manage this Worker?",
|
|
953
|
+
result: false,
|
|
954
|
+
},
|
|
955
|
+
{
|
|
956
|
+
text: "Would you like to install wrangler into package.json?",
|
|
957
|
+
result: false,
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
text: "Would you like to use TypeScript?",
|
|
961
|
+
result: true,
|
|
962
|
+
}
|
|
963
|
+
);
|
|
964
|
+
|
|
965
|
+
fs.writeFileSync(
|
|
966
|
+
"./package.json",
|
|
967
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
968
|
+
"utf-8"
|
|
969
|
+
);
|
|
970
|
+
fs.mkdirSync("./my-worker/src", { recursive: true });
|
|
971
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
972
|
+
fs.writeFileSync("./my-worker/src/index.ts", PLACEHOLDER, "utf-8");
|
|
973
|
+
|
|
974
|
+
await runWrangler("init my-worker");
|
|
975
|
+
expect(fs.existsSync("./my-worker/src/index.js")).toBe(false);
|
|
976
|
+
expect(fs.readFileSync("./my-worker/src/index.ts", "utf-8")).toBe(
|
|
977
|
+
PLACEHOLDER
|
|
978
|
+
);
|
|
979
|
+
expect(std).toMatchInlineSnapshot(`
|
|
980
|
+
Object {
|
|
981
|
+
"debug": "",
|
|
982
|
+
"err": "",
|
|
983
|
+
"out": "✨ Created my-worker/wrangler.toml
|
|
984
|
+
✨ Created my-worker/tsconfig.json, installed @cloudflare/workers-types into devDependencies",
|
|
985
|
+
"warn": "",
|
|
986
|
+
}
|
|
987
|
+
`);
|
|
805
988
|
});
|
|
806
989
|
|
|
807
990
|
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
@@ -838,6 +1021,16 @@ describe("init", () => {
|
|
|
838
1021
|
"@cloudflare/workers-types",
|
|
839
1022
|
"typescript"
|
|
840
1023
|
);
|
|
1024
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1025
|
+
Object {
|
|
1026
|
+
"debug": "",
|
|
1027
|
+
"err": "",
|
|
1028
|
+
"out": "✨ Created wrangler.toml
|
|
1029
|
+
✨ Created package.json
|
|
1030
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies",
|
|
1031
|
+
"warn": "",
|
|
1032
|
+
}
|
|
1033
|
+
`);
|
|
841
1034
|
});
|
|
842
1035
|
|
|
843
1036
|
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
@@ -875,6 +1068,18 @@ describe("init", () => {
|
|
|
875
1068
|
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
876
1069
|
);
|
|
877
1070
|
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
1071
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1072
|
+
Object {
|
|
1073
|
+
"debug": "",
|
|
1074
|
+
"err": "",
|
|
1075
|
+
"out": "✨ Created wrangler.toml
|
|
1076
|
+
✨ Created src/index.ts
|
|
1077
|
+
|
|
1078
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
1079
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`",
|
|
1080
|
+
"warn": "",
|
|
1081
|
+
}
|
|
1082
|
+
`);
|
|
878
1083
|
});
|
|
879
1084
|
|
|
880
1085
|
it("should not touch an existing tsconfig.json in the ancestor of a target directory", async () => {
|
|
@@ -903,7 +1108,7 @@ describe("init", () => {
|
|
|
903
1108
|
result: false,
|
|
904
1109
|
},
|
|
905
1110
|
{
|
|
906
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
1111
|
+
text: "Would you like to create a Worker at path/to/worker/my-worker/src/index.ts?",
|
|
907
1112
|
result: true,
|
|
908
1113
|
}
|
|
909
1114
|
);
|
|
@@ -913,6 +1118,18 @@ describe("init", () => {
|
|
|
913
1118
|
fs.readFileSync("path/to/worker/tsconfig.json", "utf-8")
|
|
914
1119
|
);
|
|
915
1120
|
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
1121
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1122
|
+
Object {
|
|
1123
|
+
"debug": "",
|
|
1124
|
+
"err": "",
|
|
1125
|
+
"out": "✨ Created path/to/worker/my-worker/wrangler.toml
|
|
1126
|
+
✨ Created path/to/worker/my-worker/src/index.ts
|
|
1127
|
+
|
|
1128
|
+
To start developing your Worker, run \`npx wrangler dev\`
|
|
1129
|
+
To publish your Worker to the Internet, run \`npx wrangler publish\`",
|
|
1130
|
+
"warn": "",
|
|
1131
|
+
}
|
|
1132
|
+
`);
|
|
916
1133
|
});
|
|
917
1134
|
|
|
918
1135
|
it("should offer to install type definitions in an existing typescript project", async () => {
|
|
@@ -922,7 +1139,7 @@ describe("init", () => {
|
|
|
922
1139
|
result: false,
|
|
923
1140
|
},
|
|
924
1141
|
{
|
|
925
|
-
text: "Would you like to install wrangler into
|
|
1142
|
+
text: "Would you like to install wrangler into package.json?",
|
|
926
1143
|
result: false,
|
|
927
1144
|
},
|
|
928
1145
|
{
|
|
@@ -957,6 +1174,16 @@ describe("init", () => {
|
|
|
957
1174
|
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
958
1175
|
"@cloudflare/workers-types"
|
|
959
1176
|
);
|
|
1177
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1178
|
+
Object {
|
|
1179
|
+
"debug": "",
|
|
1180
|
+
"err": "",
|
|
1181
|
+
"out": "✨ Created wrangler.toml
|
|
1182
|
+
✨ Installed @cloudflare/workers-types.
|
|
1183
|
+
Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
|
|
1184
|
+
"warn": "",
|
|
1185
|
+
}
|
|
1186
|
+
`);
|
|
960
1187
|
});
|
|
961
1188
|
|
|
962
1189
|
it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
|
|
@@ -1005,7 +1232,7 @@ describe("init", () => {
|
|
|
1005
1232
|
Object {
|
|
1006
1233
|
"debug": "",
|
|
1007
1234
|
"err": "",
|
|
1008
|
-
"out": "✨
|
|
1235
|
+
"out": "✨ Created wrangler.toml
|
|
1009
1236
|
✨ Created src/index.ts
|
|
1010
1237
|
|
|
1011
1238
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
@@ -1028,7 +1255,7 @@ describe("init", () => {
|
|
|
1028
1255
|
result: true,
|
|
1029
1256
|
},
|
|
1030
1257
|
{
|
|
1031
|
-
text: "Would you like to install wrangler into
|
|
1258
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1032
1259
|
result: false,
|
|
1033
1260
|
},
|
|
1034
1261
|
{
|
|
@@ -1055,7 +1282,7 @@ describe("init", () => {
|
|
|
1055
1282
|
expect(packageJson.name).toContain("wrangler-tests");
|
|
1056
1283
|
expect(packageJson.version).toEqual("0.0.0");
|
|
1057
1284
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1058
|
-
"✨
|
|
1285
|
+
"✨ Created wrangler.toml
|
|
1059
1286
|
✨ Created package.json
|
|
1060
1287
|
✨ Created src/index.js
|
|
1061
1288
|
|
|
@@ -1071,7 +1298,7 @@ describe("init", () => {
|
|
|
1071
1298
|
result: false,
|
|
1072
1299
|
},
|
|
1073
1300
|
{
|
|
1074
|
-
text: "Would you like to install wrangler into
|
|
1301
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1075
1302
|
result: false,
|
|
1076
1303
|
},
|
|
1077
1304
|
{
|
|
@@ -1103,7 +1330,7 @@ describe("init", () => {
|
|
|
1103
1330
|
expect(packageJson.scripts.start).toBe("test-start");
|
|
1104
1331
|
expect(packageJson.scripts.publish).toBe("test-publish");
|
|
1105
1332
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1106
|
-
"✨
|
|
1333
|
+
"✨ Created wrangler.toml
|
|
1107
1334
|
✨ Created src/index.js
|
|
1108
1335
|
|
|
1109
1336
|
To start developing your Worker, run \`npx wrangler dev\`
|
|
@@ -1118,7 +1345,7 @@ describe("init", () => {
|
|
|
1118
1345
|
result: false,
|
|
1119
1346
|
},
|
|
1120
1347
|
{
|
|
1121
|
-
text: "Would you like to install wrangler into
|
|
1348
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1122
1349
|
result: false,
|
|
1123
1350
|
},
|
|
1124
1351
|
{
|
|
@@ -1139,6 +1366,54 @@ describe("init", () => {
|
|
|
1139
1366
|
await runWrangler("init");
|
|
1140
1367
|
expect(fs.readFileSync("./src/index.js", "utf-8")).toBe(PLACEHOLDER);
|
|
1141
1368
|
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
1369
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1370
|
+
Object {
|
|
1371
|
+
"debug": "",
|
|
1372
|
+
"err": "",
|
|
1373
|
+
"out": "✨ Created wrangler.toml",
|
|
1374
|
+
"warn": "",
|
|
1375
|
+
}
|
|
1376
|
+
`);
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
it("should not offer to create a worker in a non-ts named worker project if a file already exists at the location", async () => {
|
|
1380
|
+
mockConfirm(
|
|
1381
|
+
{
|
|
1382
|
+
text: "Would you like to use git to manage this Worker?",
|
|
1383
|
+
result: false,
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
text: "Would you like to install wrangler into package.json?",
|
|
1387
|
+
result: false,
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
text: "Would you like to use TypeScript?",
|
|
1391
|
+
result: false,
|
|
1392
|
+
}
|
|
1393
|
+
);
|
|
1394
|
+
|
|
1395
|
+
fs.writeFileSync(
|
|
1396
|
+
"./package.json",
|
|
1397
|
+
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
1398
|
+
"utf-8"
|
|
1399
|
+
);
|
|
1400
|
+
fs.mkdirSync("./my-worker/src", { recursive: true });
|
|
1401
|
+
const PLACEHOLDER = "/* placeholder text */";
|
|
1402
|
+
fs.writeFileSync("./my-worker/src/index.js", PLACEHOLDER, "utf-8");
|
|
1403
|
+
|
|
1404
|
+
await runWrangler("init my-worker");
|
|
1405
|
+
expect(fs.readFileSync("./my-worker/src/index.js", "utf-8")).toBe(
|
|
1406
|
+
PLACEHOLDER
|
|
1407
|
+
);
|
|
1408
|
+
expect(fs.existsSync("./my-worker/src/index.ts")).toBe(false);
|
|
1409
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1410
|
+
Object {
|
|
1411
|
+
"debug": "",
|
|
1412
|
+
"err": "",
|
|
1413
|
+
"out": "✨ Created my-worker/wrangler.toml",
|
|
1414
|
+
"warn": "",
|
|
1415
|
+
}
|
|
1416
|
+
`);
|
|
1142
1417
|
});
|
|
1143
1418
|
});
|
|
1144
1419
|
|
|
@@ -1163,6 +1438,21 @@ describe("init", () => {
|
|
|
1163
1438
|
expect(parsed.name).toBe(path.basename(process.cwd()).toLowerCase());
|
|
1164
1439
|
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
1165
1440
|
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
1441
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1442
|
+
Object {
|
|
1443
|
+
"debug": "",
|
|
1444
|
+
"err": "",
|
|
1445
|
+
"out": "✨ Created wrangler.toml
|
|
1446
|
+
✨ Initialized git repository
|
|
1447
|
+
✨ Created package.json
|
|
1448
|
+
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
1449
|
+
✨ Created src/index.ts
|
|
1450
|
+
|
|
1451
|
+
To start developing your Worker, run \`npm start\`
|
|
1452
|
+
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
1453
|
+
"warn": "",
|
|
1454
|
+
}
|
|
1455
|
+
`);
|
|
1166
1456
|
});
|
|
1167
1457
|
|
|
1168
1458
|
it('should create a worker in a nested directory if "name" is path/to/worker', async () => {
|
|
@@ -1176,6 +1466,21 @@ describe("init", () => {
|
|
|
1176
1466
|
expect(parsed.name).toBe("worker");
|
|
1177
1467
|
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
1178
1468
|
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
1469
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1470
|
+
Object {
|
|
1471
|
+
"debug": "",
|
|
1472
|
+
"err": "",
|
|
1473
|
+
"out": "✨ Created path/to/worker/wrangler.toml
|
|
1474
|
+
✨ Initialized git repository at path/to/worker
|
|
1475
|
+
✨ Created path/to/worker/package.json
|
|
1476
|
+
✨ Created path/to/worker/tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
1477
|
+
✨ Created path/to/worker/src/index.ts
|
|
1478
|
+
|
|
1479
|
+
To start developing your Worker, run \`cd path/to/worker && npm start\`
|
|
1480
|
+
To publish your Worker to the Internet, run \`npm run publish\`",
|
|
1481
|
+
"warn": "",
|
|
1482
|
+
}
|
|
1483
|
+
`);
|
|
1179
1484
|
});
|
|
1180
1485
|
|
|
1181
1486
|
it("should normalize characters that aren't lowercase alphanumeric, underscores, or dashes", async () => {
|
|
@@ -1191,6 +1496,21 @@ describe("init", () => {
|
|
|
1191
1496
|
expect(parsed.name).toBe("weird_w0rkr_n4m3-js-tsx-tar-gz");
|
|
1192
1497
|
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
1193
1498
|
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
1499
|
+
expect(std).toMatchInlineSnapshot(`
|
|
1500
|
+
Object {
|
|
1501
|
+
"debug": "",
|
|
1502
|
+
"err": "",
|
|
1503
|
+
"out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
|
|
1504
|
+
✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
|
|
1505
|
+
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
|
|
1506
|
+
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
1507
|
+
✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
|
|
1508
|
+
|
|
1509
|
+
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 publish\`",
|
|
1511
|
+
"warn": "",
|
|
1512
|
+
}
|
|
1513
|
+
`);
|
|
1194
1514
|
});
|
|
1195
1515
|
});
|
|
1196
1516
|
});
|
package/src/index.tsx
CHANGED
|
@@ -359,7 +359,12 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
359
359
|
let justCreatedWranglerToml = false;
|
|
360
360
|
|
|
361
361
|
if (fs.existsSync(wranglerTomlDestination)) {
|
|
362
|
-
logger.warn(
|
|
362
|
+
logger.warn(
|
|
363
|
+
`${path.relative(
|
|
364
|
+
process.cwd(),
|
|
365
|
+
wranglerTomlDestination
|
|
366
|
+
)} already exists!`
|
|
367
|
+
);
|
|
363
368
|
const shouldContinue = await confirm(
|
|
364
369
|
"Do you want to continue initializing this project?"
|
|
365
370
|
);
|
|
@@ -379,11 +384,19 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
379
384
|
}) + "\n"
|
|
380
385
|
);
|
|
381
386
|
|
|
382
|
-
logger.log(
|
|
387
|
+
logger.log(
|
|
388
|
+
`✨ Created ${path.relative(
|
|
389
|
+
process.cwd(),
|
|
390
|
+
wranglerTomlDestination
|
|
391
|
+
)}`
|
|
392
|
+
);
|
|
383
393
|
justCreatedWranglerToml = true;
|
|
384
394
|
} catch (err) {
|
|
385
395
|
throw new Error(
|
|
386
|
-
`Failed to create
|
|
396
|
+
`Failed to create ${path.relative(
|
|
397
|
+
process.cwd(),
|
|
398
|
+
wranglerTomlDestination
|
|
399
|
+
)}.\n${(err as Error).message ?? err}`
|
|
387
400
|
);
|
|
388
401
|
}
|
|
389
402
|
}
|
|
@@ -404,7 +417,14 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
404
417
|
path.join(creationDirectory, ".gitignore"),
|
|
405
418
|
readFileSync(path.join(__dirname, "../templates/gitignore"))
|
|
406
419
|
);
|
|
407
|
-
logger.log(
|
|
420
|
+
logger.log(
|
|
421
|
+
args.name && args.name !== "."
|
|
422
|
+
? `✨ Initialized git repository at ${path.relative(
|
|
423
|
+
process.cwd(),
|
|
424
|
+
creationDirectory
|
|
425
|
+
)}`
|
|
426
|
+
: `✨ Initialized git repository`
|
|
427
|
+
);
|
|
408
428
|
}
|
|
409
429
|
}
|
|
410
430
|
|
|
@@ -439,8 +459,10 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
439
459
|
);
|
|
440
460
|
|
|
441
461
|
await packageManager.install();
|
|
442
|
-
logger.log(`✨ Created package.json`);
|
|
443
462
|
pathToPackageJson = path.join(creationDirectory, "package.json");
|
|
463
|
+
logger.log(
|
|
464
|
+
`✨ Created ${path.relative(process.cwd(), pathToPackageJson)}`
|
|
465
|
+
);
|
|
444
466
|
} else {
|
|
445
467
|
return;
|
|
446
468
|
}
|
|
@@ -460,7 +482,10 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
460
482
|
const shouldInstall =
|
|
461
483
|
yesFlag ||
|
|
462
484
|
(await confirm(
|
|
463
|
-
|
|
485
|
+
`Would you like to install wrangler into ${path.relative(
|
|
486
|
+
process.cwd(),
|
|
487
|
+
pathToPackageJson
|
|
488
|
+
)}?`
|
|
464
489
|
));
|
|
465
490
|
if (shouldInstall) {
|
|
466
491
|
await packageManager.addDevDeps(`wrangler@${wranglerVersion}`);
|
|
@@ -486,11 +511,13 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
486
511
|
"@cloudflare/workers-types",
|
|
487
512
|
"typescript"
|
|
488
513
|
);
|
|
489
|
-
|
|
514
|
+
pathToTSConfig = path.join(creationDirectory, "tsconfig.json");
|
|
490
515
|
logger.log(
|
|
491
|
-
`✨ Created
|
|
516
|
+
`✨ Created ${path.relative(
|
|
517
|
+
process.cwd(),
|
|
518
|
+
pathToTSConfig
|
|
519
|
+
)}, installed @cloudflare/workers-types into devDependencies`
|
|
492
520
|
);
|
|
493
|
-
pathToTSConfig = path.join(creationDirectory, "tsconfig.json");
|
|
494
521
|
}
|
|
495
522
|
} else {
|
|
496
523
|
isTypescriptProject = true;
|
|
@@ -516,7 +543,10 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
516
543
|
// and we don't want to break them. Instead, we simply
|
|
517
544
|
// tell the user that they need to update their tsconfig.json
|
|
518
545
|
logger.log(
|
|
519
|
-
`✨ Installed @cloudflare/workers-types.\nPlease add "@cloudflare/workers-types" to compilerOptions.types in
|
|
546
|
+
`✨ Installed @cloudflare/workers-types.\nPlease add "@cloudflare/workers-types" to compilerOptions.types in ${path.relative(
|
|
547
|
+
process.cwd(),
|
|
548
|
+
pathToTSConfig
|
|
549
|
+
)}`
|
|
520
550
|
);
|
|
521
551
|
}
|
|
522
552
|
}
|
|
@@ -598,12 +628,13 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
598
628
|
|
|
599
629
|
if (isTypescriptProject) {
|
|
600
630
|
if (!fs.existsSync(path.join(creationDirectory, "./src/index.ts"))) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
shouldCreateSource =
|
|
631
|
+
const shouldCreateSource =
|
|
604
632
|
yesFlag ||
|
|
605
633
|
(await confirm(
|
|
606
|
-
`Would you like to create a Worker at
|
|
634
|
+
`Would you like to create a Worker at ${path.relative(
|
|
635
|
+
process.cwd(),
|
|
636
|
+
path.join(creationDirectory, "./src/index.ts")
|
|
637
|
+
)}?`
|
|
607
638
|
));
|
|
608
639
|
|
|
609
640
|
if (shouldCreateSource) {
|
|
@@ -615,7 +646,12 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
615
646
|
readFileSync(path.join(__dirname, "../templates/new-worker.ts"))
|
|
616
647
|
);
|
|
617
648
|
|
|
618
|
-
logger.log(
|
|
649
|
+
logger.log(
|
|
650
|
+
`✨ Created ${path.relative(
|
|
651
|
+
process.cwd(),
|
|
652
|
+
path.join(creationDirectory, "./src/index.ts")
|
|
653
|
+
)}`
|
|
654
|
+
);
|
|
619
655
|
|
|
620
656
|
await writePackageJsonScriptsAndUpdateWranglerToml(
|
|
621
657
|
shouldWritePackageJsonScripts,
|
|
@@ -626,20 +662,31 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
626
662
|
}
|
|
627
663
|
}
|
|
628
664
|
} else {
|
|
629
|
-
if (!fs.existsSync("./src/index.js")) {
|
|
630
|
-
const shouldCreateSource =
|
|
631
|
-
|
|
632
|
-
|
|
665
|
+
if (!fs.existsSync(path.join(creationDirectory, "./src/index.js"))) {
|
|
666
|
+
const shouldCreateSource =
|
|
667
|
+
yesFlag ||
|
|
668
|
+
(await confirm(
|
|
669
|
+
`Would you like to create a Worker at ${path.relative(
|
|
670
|
+
process.cwd(),
|
|
671
|
+
path.join(creationDirectory, "./src/index.js")
|
|
672
|
+
)}?`
|
|
673
|
+
));
|
|
674
|
+
|
|
633
675
|
if (shouldCreateSource) {
|
|
634
676
|
await mkdir(path.join(creationDirectory, "./src"), {
|
|
635
677
|
recursive: true,
|
|
636
678
|
});
|
|
637
679
|
await writeFile(
|
|
638
|
-
path.join(
|
|
680
|
+
path.join(creationDirectory, "./src/index.js"),
|
|
639
681
|
readFileSync(path.join(__dirname, "../templates/new-worker.js"))
|
|
640
682
|
);
|
|
641
683
|
|
|
642
|
-
logger.log(
|
|
684
|
+
logger.log(
|
|
685
|
+
`✨ Created ${path.relative(
|
|
686
|
+
process.cwd(),
|
|
687
|
+
path.join(creationDirectory, "./src/index.js")
|
|
688
|
+
)}`
|
|
689
|
+
);
|
|
643
690
|
|
|
644
691
|
await writePackageJsonScriptsAndUpdateWranglerToml(
|
|
645
692
|
shouldWritePackageJsonScripts,
|
package/wrangler-dist/cli.js
CHANGED
|
@@ -104810,7 +104810,7 @@ var yargs_default = Yargs;
|
|
|
104810
104810
|
|
|
104811
104811
|
// package.json
|
|
104812
104812
|
var name = "wrangler";
|
|
104813
|
-
var version = "0.0.
|
|
104813
|
+
var version = "0.0.34";
|
|
104814
104814
|
var author = "wrangler@cloudflare.com";
|
|
104815
104815
|
var description = "Command-line interface for all things Cloudflare Workers";
|
|
104816
104816
|
var bin = {
|
|
@@ -111787,7 +111787,7 @@ Have you considered using Cloudflare Pages instead? See https://pages.cloudflare
|
|
|
111787
111787
|
const wranglerTomlDestination = import_node_path21.default.join(creationDirectory, "./wrangler.toml");
|
|
111788
111788
|
let justCreatedWranglerToml = false;
|
|
111789
111789
|
if (fs8.existsSync(wranglerTomlDestination)) {
|
|
111790
|
-
logger.warn(`${wranglerTomlDestination}
|
|
111790
|
+
logger.warn(`${import_node_path21.default.relative(process.cwd(), wranglerTomlDestination)} already exists!`);
|
|
111791
111791
|
const shouldContinue = await confirm("Do you want to continue initializing this project?");
|
|
111792
111792
|
if (!shouldContinue) {
|
|
111793
111793
|
return;
|
|
@@ -111800,10 +111800,10 @@ Have you considered using Cloudflare Pages instead? See https://pages.cloudflare
|
|
|
111800
111800
|
name: workerName,
|
|
111801
111801
|
compatibility_date: compatibilityDate
|
|
111802
111802
|
}) + "\n");
|
|
111803
|
-
logger.log(`\u2728
|
|
111803
|
+
logger.log(`\u2728 Created ${import_node_path21.default.relative(process.cwd(), wranglerTomlDestination)}`);
|
|
111804
111804
|
justCreatedWranglerToml = true;
|
|
111805
111805
|
} catch (err2) {
|
|
111806
|
-
throw new Error(`Failed to create
|
|
111806
|
+
throw new Error(`Failed to create ${import_node_path21.default.relative(process.cwd(), wranglerTomlDestination)}.
|
|
111807
111807
|
${err2.message ?? err2}`);
|
|
111808
111808
|
}
|
|
111809
111809
|
}
|
|
@@ -111815,7 +111815,7 @@ ${err2.message ?? err2}`);
|
|
|
111815
111815
|
if (shouldInitGit) {
|
|
111816
111816
|
await execa("git", ["init"], { cwd: creationDirectory });
|
|
111817
111817
|
await (0, import_promises10.writeFile)(import_node_path21.default.join(creationDirectory, ".gitignore"), readFileSync5(import_node_path21.default.join(__dirname, "../templates/gitignore")));
|
|
111818
|
-
logger.log(`\u2728 Initialized git repository`);
|
|
111818
|
+
logger.log(args.name && args.name !== "." ? `\u2728 Initialized git repository at ${import_node_path21.default.relative(process.cwd(), creationDirectory)}` : `\u2728 Initialized git repository`);
|
|
111819
111819
|
}
|
|
111820
111820
|
}
|
|
111821
111821
|
let pathToPackageJson = await findUp("package.json", {
|
|
@@ -111834,15 +111834,15 @@ ${err2.message ?? err2}`);
|
|
|
111834
111834
|
private: true
|
|
111835
111835
|
}, null, " ") + "\n");
|
|
111836
111836
|
await packageManager.install();
|
|
111837
|
-
logger.log(`\u2728 Created package.json`);
|
|
111838
111837
|
pathToPackageJson = import_node_path21.default.join(creationDirectory, "package.json");
|
|
111838
|
+
logger.log(`\u2728 Created ${import_node_path21.default.relative(process.cwd(), pathToPackageJson)}`);
|
|
111839
111839
|
} else {
|
|
111840
111840
|
return;
|
|
111841
111841
|
}
|
|
111842
111842
|
} else {
|
|
111843
111843
|
const packageJson = parseJSON(readFileSync5(pathToPackageJson), pathToPackageJson);
|
|
111844
111844
|
if (!(packageJson.devDependencies?.wrangler || packageJson.dependencies?.wrangler)) {
|
|
111845
|
-
const shouldInstall = yesFlag || await confirm(
|
|
111845
|
+
const shouldInstall = yesFlag || await confirm(`Would you like to install wrangler into ${import_node_path21.default.relative(process.cwd(), pathToPackageJson)}?`);
|
|
111846
111846
|
if (shouldInstall) {
|
|
111847
111847
|
await packageManager.addDevDeps(`wrangler@${version}`);
|
|
111848
111848
|
logger.log(`\u2728 Installed wrangler`);
|
|
@@ -111858,8 +111858,8 @@ ${err2.message ?? err2}`);
|
|
|
111858
111858
|
isTypescriptProject = true;
|
|
111859
111859
|
await (0, import_promises10.writeFile)(import_node_path21.default.join(creationDirectory, "./tsconfig.json"), readFileSync5(import_node_path21.default.join(__dirname, "../templates/tsconfig.json")));
|
|
111860
111860
|
await packageManager.addDevDeps("@cloudflare/workers-types", "typescript");
|
|
111861
|
-
logger.log(`\u2728 Created tsconfig.json, installed @cloudflare/workers-types into devDependencies`);
|
|
111862
111861
|
pathToTSConfig = import_node_path21.default.join(creationDirectory, "tsconfig.json");
|
|
111862
|
+
logger.log(`\u2728 Created ${import_node_path21.default.relative(process.cwd(), pathToTSConfig)}, installed @cloudflare/workers-types into devDependencies`);
|
|
111863
111863
|
}
|
|
111864
111864
|
} else {
|
|
111865
111865
|
isTypescriptProject = true;
|
|
@@ -111869,7 +111869,7 @@ ${err2.message ?? err2}`);
|
|
|
111869
111869
|
if (shouldInstall) {
|
|
111870
111870
|
await packageManager.addDevDeps("@cloudflare/workers-types");
|
|
111871
111871
|
logger.log(`\u2728 Installed @cloudflare/workers-types.
|
|
111872
|
-
Please add "@cloudflare/workers-types" to compilerOptions.types in
|
|
111872
|
+
Please add "@cloudflare/workers-types" to compilerOptions.types in ${import_node_path21.default.relative(process.cwd(), pathToTSConfig)}`);
|
|
111873
111873
|
}
|
|
111874
111874
|
}
|
|
111875
111875
|
}
|
|
@@ -111905,26 +111905,25 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
|
|
|
111905
111905
|
}
|
|
111906
111906
|
if (isTypescriptProject) {
|
|
111907
111907
|
if (!fs8.existsSync(import_node_path21.default.join(creationDirectory, "./src/index.ts"))) {
|
|
111908
|
-
|
|
111909
|
-
shouldCreateSource = yesFlag || await confirm(`Would you like to create a Worker at src/index.ts?`);
|
|
111908
|
+
const shouldCreateSource = yesFlag || await confirm(`Would you like to create a Worker at ${import_node_path21.default.relative(process.cwd(), import_node_path21.default.join(creationDirectory, "./src/index.ts"))}?`);
|
|
111910
111909
|
if (shouldCreateSource) {
|
|
111911
111910
|
await (0, import_promises10.mkdir)(import_node_path21.default.join(creationDirectory, "./src"), {
|
|
111912
111911
|
recursive: true
|
|
111913
111912
|
});
|
|
111914
111913
|
await (0, import_promises10.writeFile)(import_node_path21.default.join(creationDirectory, "./src/index.ts"), readFileSync5(import_node_path21.default.join(__dirname, "../templates/new-worker.ts")));
|
|
111915
|
-
logger.log(`\u2728 Created src/index.ts`);
|
|
111914
|
+
logger.log(`\u2728 Created ${import_node_path21.default.relative(process.cwd(), import_node_path21.default.join(creationDirectory, "./src/index.ts"))}`);
|
|
111916
111915
|
await writePackageJsonScriptsAndUpdateWranglerToml(shouldWritePackageJsonScripts, justCreatedWranglerToml, pathToPackageJson, "src/index.ts");
|
|
111917
111916
|
}
|
|
111918
111917
|
}
|
|
111919
111918
|
} else {
|
|
111920
|
-
if (!fs8.existsSync("./src/index.js")) {
|
|
111921
|
-
const shouldCreateSource = await confirm(`Would you like to create a Worker at src/index.js?`);
|
|
111919
|
+
if (!fs8.existsSync(import_node_path21.default.join(creationDirectory, "./src/index.js"))) {
|
|
111920
|
+
const shouldCreateSource = yesFlag || await confirm(`Would you like to create a Worker at ${import_node_path21.default.relative(process.cwd(), import_node_path21.default.join(creationDirectory, "./src/index.js"))}?`);
|
|
111922
111921
|
if (shouldCreateSource) {
|
|
111923
111922
|
await (0, import_promises10.mkdir)(import_node_path21.default.join(creationDirectory, "./src"), {
|
|
111924
111923
|
recursive: true
|
|
111925
111924
|
});
|
|
111926
|
-
await (0, import_promises10.writeFile)(import_node_path21.default.join(
|
|
111927
|
-
logger.log(`\u2728 Created src/index.js`);
|
|
111925
|
+
await (0, import_promises10.writeFile)(import_node_path21.default.join(creationDirectory, "./src/index.js"), readFileSync5(import_node_path21.default.join(__dirname, "../templates/new-worker.js")));
|
|
111926
|
+
logger.log(`\u2728 Created ${import_node_path21.default.relative(process.cwd(), import_node_path21.default.join(creationDirectory, "./src/index.js"))}`);
|
|
111928
111927
|
await writePackageJsonScriptsAndUpdateWranglerToml(shouldWritePackageJsonScripts, justCreatedWranglerToml, pathToPackageJson, "src/index.js");
|
|
111929
111928
|
}
|
|
111930
111929
|
}
|