From 02a0e1e186706eaec46048252068713f04698384 Mon Sep 17 00:00:00 2001 From: Taylor <1628134+taylorlee@users.noreply.github.com> Date: Tue, 26 Nov 2024 04:54:32 -0800 Subject: [PATCH] Separate config for preview_urls (#7227) * feat(wrangler): create separate config for workers_dev_previews The current Preview URLs (beta) feature routes to version preview urls based on the status of the `workers_dev` config value. Beta users have requested the ability to enable deployment urls and preview urls separately on `workers.dev`, and the new `previews_enabled` field of the enable-subdomain API will allow that. This change separates the `workers_dev` and `workers_dev_previews` behavior during `wrangler triggers deploy` and `wrangler versions upload`. `preview_urls` defaults to true, and does not implicitly depend on routes the way `workers_dev` does. * Rename to preview_urls * Update .changeset/famous-mayflies-knock.md Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com> --------- Co-authored-by: Daniel Walsh Co-authored-by: Daniel Walsh Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com> --- .changeset/famous-mayflies-knock.md | 7 + .../src/__tests__/configuration.test.ts | 1 + .../wrangler/src/__tests__/deploy.test.ts | 94 ++++++++++- .../helpers/mock-workers-subdomain.ts | 14 +- .../versions/versions.upload.test.ts | 6 +- packages/wrangler/src/config/config.ts | 1 + packages/wrangler/src/config/environment.ts | 9 + packages/wrangler/src/config/validation.ts | 10 ++ packages/wrangler/src/init.ts | 2 + packages/wrangler/src/triggers/deploy.ts | 156 ++++++++++-------- packages/wrangler/src/versions/upload.ts | 9 +- 11 files changed, 224 insertions(+), 85 deletions(-) create mode 100644 .changeset/famous-mayflies-knock.md diff --git a/.changeset/famous-mayflies-knock.md b/.changeset/famous-mayflies-knock.md new file mode 100644 index 000000000000..98e7210b31f3 --- /dev/null +++ b/.changeset/famous-mayflies-knock.md @@ -0,0 +1,7 @@ +--- +"wrangler": minor +--- + +Add `preview_urls` toggle to `wrangler.toml` + +The current Preview URLs (beta) feature routes to version preview urls based on the status of the `workers_dev` config value. Beta users have requested the ability to enable deployment urls and preview urls separately on `workers.dev`, and the new `previews_enabled` field of the enable-subdomain API will allow that. This change separates the `workers_dev` and `preview_urls` behavior during `wrangler triggers deploy` and `wrangler versions upload`. `preview_urls` defaults to true, and does not implicitly depend on routes the way `workers_dev` does. diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 6979789b260c..f785bf2a0637 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -120,6 +120,7 @@ describe("normalizeAndValidateConfig()", () => { wasm_modules: undefined, data_blobs: undefined, workers_dev: undefined, + preview_urls: true, zone_id: undefined, no_bundle: undefined, minify: undefined, diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index a59768f8d4ba..c99ddd44e334 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -5135,7 +5135,7 @@ addEventListener('fetch', event => {});` expect(std.err).toMatchInlineSnapshot(`""`); }); - it("should not try to enable the workers.dev domain if it has been enabled before", async () => { + it("should not try to enable the workers.dev domain if it has been enabled before and previews are in sync", async () => { writeWranglerConfig({ workers_dev: true, }); @@ -5157,6 +5157,53 @@ addEventListener('fetch', event => {});` expect(std.err).toMatchInlineSnapshot(`""`); }); + it("should sync the workers.dev domain if it has been enabled before but previews should be enabled", async () => { + writeWranglerConfig({ + workers_dev: true, + }); + writeWorkerSource(); + mockUploadWorkerRequest(); + mockGetWorkerSubdomain({ enabled: true, previews_enabled: false }); + mockSubDomainRequest(); + mockUpdateWorkerSubdomain({ enabled: true, previews_enabled: true }); + + await runWrangler("deploy ./index"); + + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + Deployed test-name triggers (TIMINGS) + https://test-name.test-sub-domain.workers.dev + Current Version ID: Galaxy-Class" + `); + expect(std.err).toMatchInlineSnapshot(`""`); + }); + + it("should sync the workers.dev domain if it has been enabled before but previews should be enabled", async () => { + writeWranglerConfig({ + workers_dev: true, + preview_urls: false, + }); + writeWorkerSource(); + mockUploadWorkerRequest(); + mockGetWorkerSubdomain({ enabled: true, previews_enabled: true }); + mockSubDomainRequest(); + mockUpdateWorkerSubdomain({ enabled: true, previews_enabled: false }); + + await runWrangler("deploy ./index"); + + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + Deployed test-name triggers (TIMINGS) + https://test-name.test-sub-domain.workers.dev + Current Version ID: Galaxy-Class" + `); + expect(std.err).toMatchInlineSnapshot(`""`); + }); + it("should disable the workers.dev domain if workers_dev is `false`", async () => { writeWranglerConfig({ workers_dev: false, @@ -5178,7 +5225,7 @@ addEventListener('fetch', event => {});` expect(std.err).toMatchInlineSnapshot(`""`); }); - it("should not try to disable the workers.dev domain if it is not already available", async () => { + it("should not try to disable the workers.dev domain if it is not already available and previews are in sync", async () => { writeWranglerConfig({ workers_dev: false, }); @@ -5200,6 +5247,49 @@ addEventListener('fetch', event => {});` expect(std.err).toMatchInlineSnapshot(`""`); }); + it("should sync the workers.dev domain if it is not available but previews should be enabled", async () => { + writeWranglerConfig({ + workers_dev: false, + }); + writeWorkerSource(); + mockUploadWorkerRequest(); + mockGetWorkerSubdomain({ enabled: false, previews_enabled: false }); + mockUpdateWorkerSubdomain({ enabled: false, previews_enabled: true }); + + await runWrangler("deploy ./index"); + + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + No deploy targets for test-name (TIMINGS) + Current Version ID: Galaxy-Class" + `); + expect(std.err).toMatchInlineSnapshot(`""`); + }); + + it("should sync the workers.dev domain if it is not available but previews should be disabled", async () => { + writeWranglerConfig({ + workers_dev: false, + preview_urls: false, + }); + writeWorkerSource(); + mockUploadWorkerRequest(); + mockGetWorkerSubdomain({ enabled: false, previews_enabled: true }); + mockUpdateWorkerSubdomain({ enabled: false, previews_enabled: false }); + + await runWrangler("deploy ./index"); + + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + No deploy targets for test-name (TIMINGS) + Current Version ID: Galaxy-Class" + `); + expect(std.err).toMatchInlineSnapshot(`""`); + }); + it("should disable the workers.dev domain if workers_dev is undefined but overwritten to `false` in environment", async () => { writeWranglerConfig({ env: { diff --git a/packages/wrangler/src/__tests__/helpers/mock-workers-subdomain.ts b/packages/wrangler/src/__tests__/helpers/mock-workers-subdomain.ts index c96c9f7e14cc..3185346ba6d8 100644 --- a/packages/wrangler/src/__tests__/helpers/mock-workers-subdomain.ts +++ b/packages/wrangler/src/__tests__/helpers/mock-workers-subdomain.ts @@ -36,11 +36,13 @@ export function mockSubDomainRequest( /** Create a mock handler to fetch the