You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interactively handle `wrangler deploy`s that are probably assets-only, where there is no config file and flags are incorrect or missing.
6
+
7
+
For example:
8
+
9
+
`npx wrangler deploy ./public` will now ask if you meant to deploy a folder of assets only, ask for a name, set the compat date and then ask whether to write your choices out to `wrangler.json` for subsequent deployments.
10
+
11
+
`npx wrangler deploy --assets=./public` will now ask for a name, set the compat date and then ask whether to write your choices out to `wrangler.json` for subsequent deployments.
12
+
13
+
In non-interactive contexts, Wrangler will error as it currently does.
text: "It looks like you are trying to deploy a directory of static assets only. Is this correct?",
2757
+
result: true,
2758
+
});
2759
+
mockPrompt({
2760
+
text: "What do you want to name your project?",
2761
+
options: {defaultValue: "my-site"},
2762
+
result: "test-name",
2763
+
});
2764
+
mockConfirm({
2765
+
text: "Do you want Wrangler to write a wrangler.json config file to store this configuration?\nThis will allow you to simply run `wrangler deploy` on future deployments.",
2766
+
result: true,
2767
+
});
2768
+
2769
+
constbodies: AssetManifest[]=[];
2770
+
awaitmockAUSRequest(bodies);
2771
+
2772
+
awaitrunWrangler("deploy ./assets");
2773
+
expect(bodies.length).toBe(1);
2774
+
expect(bodies[0]).toEqual({
2775
+
manifest: {
2776
+
"/index.html": {
2777
+
hash: "8308ce789f3d08668ce87176838d59d0",
2778
+
size: 17,
2779
+
},
2780
+
},
2781
+
});
2782
+
expect(fs.readFileSync("wrangler.jsonc","utf-8"))
2783
+
.toMatchInlineSnapshot(`
2784
+
"{
2785
+
\\"name\\": \\"test-name\\",
2786
+
\\"compatibility_date\\": \\"2024-01-01\\",
2787
+
\\"assets\\": {
2788
+
\\"directory\\": \\"./assets\\"
2789
+
}
2790
+
}"
2791
+
`);
2792
+
expect(std.out).toMatchInlineSnapshot(`
2793
+
"
2794
+
2795
+
2796
+
No compatibility date found Defaulting to today: 2024-01-01
2797
+
2798
+
Wrote
2799
+
{
2800
+
\\"name\\": \\"test-name\\",
2801
+
\\"compatibility_date\\": \\"2024-01-01\\",
2802
+
\\"assets\\": {
2803
+
\\"directory\\": \\"./assets\\"
2804
+
}
2805
+
}
2806
+
to <cwd>/wrangler.jsonc.
2807
+
Please run \`wrangler deploy\` instead of \`wrangler deploy ./assets\` next time. Wrangler will automatically use the configuration saved to wrangler.jsonc.
2808
+
2809
+
Proceeding with deployment...
2810
+
2811
+
Total Upload: xx KiB / gzip: xx KiB
2812
+
Worker Startup Time: 100 ms
2813
+
Uploaded test-name (TIMINGS)
2814
+
Deployed test-name triggers (TIMINGS)
2815
+
https://test-name.test-sub-domain.workers.dev
2816
+
Current Version ID: Galaxy-Class"
2817
+
`);
2818
+
});
2819
+
2820
+
it("should handle `wrangler deploy --assets` without name or compat date",async()=>{
2821
+
// if the user has used --assets flag and args.script is not set, we just need to prompt for the name and add compat date
2822
+
mockPrompt({
2823
+
text: "What do you want to name your project?",
2824
+
options: {defaultValue: "my-site"},
2825
+
result: "test-name",
2826
+
});
2827
+
mockConfirm({
2828
+
text: "Do you want Wrangler to write a wrangler.json config file to store this configuration?\nThis will allow you to simply run `wrangler deploy` on future deployments.",
2829
+
result: true,
2830
+
});
2831
+
2832
+
constbodies: AssetManifest[]=[];
2833
+
awaitmockAUSRequest(bodies);
2834
+
2835
+
awaitrunWrangler("deploy --assets ./assets");
2836
+
expect(bodies.length).toBe(1);
2837
+
expect(bodies[0]).toEqual({
2838
+
manifest: {
2839
+
"/index.html": {
2840
+
hash: "8308ce789f3d08668ce87176838d59d0",
2841
+
size: 17,
2842
+
},
2843
+
},
2844
+
});
2845
+
expect(fs.readFileSync("wrangler.jsonc","utf-8"))
2846
+
.toMatchInlineSnapshot(`
2847
+
"{
2848
+
\\"name\\": \\"test-name\\",
2849
+
\\"compatibility_date\\": \\"2024-01-01\\",
2850
+
\\"assets\\": {
2851
+
\\"directory\\": \\"./assets\\"
2852
+
}
2853
+
}"
2854
+
`);
2855
+
expect(std.out).toMatchInlineSnapshot(`
2856
+
"
2857
+
2858
+
No compatibility date found Defaulting to today: 2024-01-01
2859
+
2860
+
Wrote
2861
+
{
2862
+
\\"name\\": \\"test-name\\",
2863
+
\\"compatibility_date\\": \\"2024-01-01\\",
2864
+
\\"assets\\": {
2865
+
\\"directory\\": \\"./assets\\"
2866
+
}
2867
+
}
2868
+
to <cwd>/wrangler.jsonc.
2869
+
Please run \`wrangler deploy\` instead of \`wrangler deploy ./assets\` next time. Wrangler will automatically use the configuration saved to wrangler.jsonc.
2870
+
2871
+
Proceeding with deployment...
2872
+
2873
+
Total Upload: xx KiB / gzip: xx KiB
2874
+
Worker Startup Time: 100 ms
2875
+
Uploaded test-name (TIMINGS)
2876
+
Deployed test-name triggers (TIMINGS)
2877
+
https://test-name.test-sub-domain.workers.dev
2878
+
Current Version ID: Galaxy-Class"
2879
+
`);
2880
+
});
2881
+
2882
+
it("should suggest 'my-project' if the default name from the cwd is invalid",async()=>{
2883
+
process.chdir("../");
2884
+
fs.renameSync("my-site","[blah]");
2885
+
process.chdir("[blah]");
2886
+
// if the user has used --assets flag and args.script is not set, we just need to prompt for the name and add compat date
2887
+
mockPrompt({
2888
+
text: "What do you want to name your project?",
2889
+
// not [blah] because it is an invalid worker name
2890
+
options: {defaultValue: "my-project"},
2891
+
result: "test-name",
2892
+
});
2893
+
mockConfirm({
2894
+
text: "Do you want Wrangler to write a wrangler.json config file to store this configuration?\nThis will allow you to simply run `wrangler deploy` on future deployments.",
2895
+
result: true,
2896
+
});
2897
+
2898
+
constbodies: AssetManifest[]=[];
2899
+
awaitmockAUSRequest(bodies);
2900
+
2901
+
awaitrunWrangler("deploy --assets ./assets");
2902
+
expect(bodies.length).toBe(1);
2903
+
expect(bodies[0]).toEqual({
2904
+
manifest: {
2905
+
"/index.html": {
2906
+
hash: "8308ce789f3d08668ce87176838d59d0",
2907
+
size: 17,
2908
+
},
2909
+
},
2910
+
});
2911
+
expect(fs.readFileSync("wrangler.jsonc","utf-8"))
2912
+
.toMatchInlineSnapshot(`
2913
+
"{
2914
+
\\"name\\": \\"test-name\\",
2915
+
\\"compatibility_date\\": \\"2024-01-01\\",
2916
+
\\"assets\\": {
2917
+
\\"directory\\": \\"./assets\\"
2918
+
}
2919
+
}"
2920
+
`);
2921
+
});
2922
+
2923
+
it("should bail if the user denies that they are trying to deploy a directory",async()=>{
2924
+
mockConfirm({
2925
+
text: "It looks like you are trying to deploy a directory of static assets only. Is this correct?",
[Error: The entry-point file at "assets" was not found.
2932
+
The provided entry-point path, "assets", points to a directory, rather than a file.
2933
+
2934
+
If you want to deploy a directory of static assets, you can do so by using the \`--assets\` flag. For example:
2935
+
2936
+
wrangler deploy --assets=./assets
2937
+
]
2938
+
`);
2939
+
});
2940
+
2941
+
it("does not write out a wrangler config file if the user says no",async()=>{
2942
+
mockPrompt({
2943
+
text: "What do you want to name your project?",
2944
+
options: {defaultValue: "my-site"},
2945
+
result: "test-name",
2946
+
});
2947
+
mockConfirm({
2948
+
text: "Do you want Wrangler to write a wrangler.json config file to store this configuration?\nThis will allow you to simply run `wrangler deploy` on future deployments.",
No compatibility date found Defaulting to today: 2024-01-01
2970
+
2971
+
You should run wrangler deploy --name test-name --compatibility-date 2024-01-01 --assets ./assets next time to deploy this Worker without going through this flow again.
0 commit comments