Skip to content

Commit

Permalink
Rename to preview_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Nov 14, 2024
1 parent a7a2da0 commit 01f04ea
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .changeset/famous-mayflies-knock.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"wrangler": minor
---

Add `workers_dev_previews` toggle to `wrangler.toml`
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 `workers_dev_previews` behavior during `wrangler triggers deploy` and `wrangler versions upload`. `wrangler_dev_previews` defaults to true, and does not implicitly depend on routes the way `wrangler_dev` does.
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`. `wrangler_dev_previews` defaults to true, and does not implicitly depend on routes the way `wrangler_dev` does.
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe("normalizeAndValidateConfig()", () => {
wasm_modules: undefined,
data_blobs: undefined,
workers_dev: undefined,
workers_dev_previews: true,
preview_urls: true,
zone_id: undefined,
no_bundle: undefined,
minify: undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5073,7 +5073,7 @@ addEventListener('fetch', event => {});`
it("should sync the workers.dev domain if it has been enabled before but previews should be enabled", async () => {
writeWranglerToml({
workers_dev: true,
workers_dev_previews: false,
preview_urls: false,
});
writeWorkerSource();
mockUploadWorkerRequest();
Expand Down Expand Up @@ -5161,7 +5161,7 @@ addEventListener('fetch', event => {});`
it("should sync the workers.dev domain if it is not available but previews should be disabled", async () => {
writeWranglerToml({
workers_dev: false,
workers_dev_previews: false,
preview_urls: false,
});
writeWorkerSource();
mockUploadWorkerRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("versions upload", () => {
`);
});

it("should not print preview url when workers_dev_previews is false", async () => {
it("should not print preview url when preview_urls is false", async () => {
mockGetScript();
mockUploadVersion(true);
mockGetWorkerSubdomain({ enabled: true, previews_enabled: false });
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export const defaultWranglerConfig: Config = {
preserve_file_names: undefined,
base_dir: undefined,
workers_dev: undefined,
workers_dev_previews: true,
preview_urls: true,
route: undefined,
routes: undefined,
tsconfig: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ interface EnvironmentInheritable {
* @default `true`
* @inheritable
*/
workers_dev_previews: boolean | undefined;
preview_urls: boolean | undefined;

/**
* A list of routes that your Worker should be published to.
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,11 @@ function normalizeAndValidateEnvironment(
undefined
);

const workers_dev_previews = inheritable(
const preview_urls = inheritable(
diagnostics,
topLevelEnv,
rawEnv,
"workers_dev_previews",
"preview_urls",
isBoolean,
true
);
Expand Down Expand Up @@ -1264,7 +1264,7 @@ function normalizeAndValidateEnvironment(
placement: normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv),
build,
workers_dev,
workers_dev_previews,
preview_urls,
// Not inherited fields
vars: notInheritable(
diagnostics,
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ async function getWorkerConfig(
name: workerName,
main: entrypoint,
workers_dev: workersDev.enabled,
workers_dev_previews: workersDev.previews_enabled,
preview_urls: workersDev.previews_enabled,
compatibility_date:
serviceEnvMetadata.script.compatibility_date ??
new Date().toISOString().substring(0, 10),
Expand Down
18 changes: 4 additions & 14 deletions packages/wrangler/src/triggers/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
publishCustomDomains,
publishRoutes,
renderRoute,
sleep,
updateQueueConsumers,
updateQueueProducers,
validateRoutes,
Expand Down Expand Up @@ -96,7 +95,7 @@ export default async function triggersDeploy(

const deploymentInSync = deployToWorkersDev === available_on_subdomain;
const previewsInSync =
config.workers_dev_previews === previews_available_on_subdomain;
config.preview_urls === previews_available_on_subdomain;

if (deployToWorkersDev) {
// Deploy to a subdomain of `workers.dev`
Expand All @@ -116,21 +115,12 @@ export default async function triggersDeploy(
method: "POST",
body: JSON.stringify({
enabled: true,
previews_enabled: config.workers_dev_previews,
previews_enabled: config.preview_urls,
}),
headers: {
"Content-Type": "application/json",
},
})
.then(() => [deploymentURL])
// Add a delay when the subdomain is first created.
// This is to prevent an issue where a negative cache-hit
// causes the subdomain to be unavailable for 30 seconds.
// This is a temporary measure until we fix this on the edge.
.then(async (url) => {
await sleep(3000);
return url;
})
}).then(() => [deploymentURL])
);
}
}
Expand All @@ -140,7 +130,7 @@ export default async function triggersDeploy(
method: "POST",
body: JSON.stringify({
enabled: false,
previews_enabled: config.workers_dev_previews,
previews_enabled: config.preview_urls,
}),
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 01f04ea

Please sign in to comment.