Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/bright-owls-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

Improve `wrangler preview` onboarding guidance

Wrangler now displays placeholder replacement guidance directly beneath the suggested Preview configuration instead of as a separate warning. JSON output continues to include the guidance in its structured onboarding messages.
12 changes: 7 additions & 5 deletions packages/wrangler/src/__tests__/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,10 @@ describe("wrangler preview", () => {
expect((thrown as Error).message).toContain("IMPORTANT_BINDING");
expect((thrown as Error).message).toContain('"id": "<REPLACE_ME>"');
expect((thrown as Error).message).not.toContain("kv-id-123");
expect(std.warn).toContain(
expect((thrown as Error).message).toMatch(
/}\n\nReplace each <REPLACE_ME> placeholder with a Preview-safe value\. Do not use production resources unless you intend for this Preview to access them\.$/
);
expect(std.warn).not.toContain(
"Replace each <REPLACE_ME> placeholder with a Preview-safe value. Do not use production resources unless you intend for this Preview to access them."
);
});
Expand Down Expand Up @@ -2285,12 +2288,11 @@ describe("wrangler preview", () => {
.filter(
(message) =>
typeof message === "string" &&
(message.startsWith(
message.startsWith(
"These settings have limitations in Worker Previews"
) ||
message.startsWith("Replace each <REPLACE_ME>"))
)
);
expect(conversionWarnings).toHaveLength(2);
expect(conversionWarnings).toHaveLength(1);
});

test("should not warn about top-level bindings when they are present in local previews config", async ({
Expand Down
14 changes: 8 additions & 6 deletions packages/wrangler/src/preview/ensure-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export async function ensurePreviewsConfig(
...selectedConversion.blockingDeploymentMessages,
]),
];
if (!hasPreviewBase && containsGeneratedPlaceholder(proposedConfig)) {
conversionMessages.push(
"Replace each <REPLACE_ME> placeholder with a Preview-safe value. Do not use production resources unless you intend for this Preview to access them."
);
}

const hasEmptyProposedConfig = Object.keys(proposedConfig).length === 0;
const hasBlockingDeploymentMessages =
selectedConversion.blockingDeploymentMessages.length > 0;
Expand All @@ -160,6 +154,14 @@ export async function ensurePreviewsConfig(
: "Your Wrangler configuration is missing a `previews` block. Add the following to your configuration file:",
formattedProposedConfig,
];
if (!hasPreviewBase && containsGeneratedPlaceholder(proposedConfig)) {
const replacementMessage =
"Replace each <REPLACE_ME> placeholder with a Preview-safe value. Do not use production resources unless you intend for this Preview to access them.";
missingPreviewsConfigParagraphs.push(`\n${replacementMessage}`);
if (args.json) {
conversionMessages.push(replacementMessage);
}
}
if (hasEmptyProposedConfig && conversionMessages.length === 0) {
missingPreviewsConfigParagraphs.push(
"To create or update a Preview with `npx wrangler preview`, your Wrangler configuration must include a `previews` block. The block can be empty. Assets, compatibility settings, migrations, and placement stay at the top level and do not need to be added to `previews`.\nLearn more: https://developers.cloudflare.com/workers/previews/configuration/#wrangler-configuration-file"
Expand Down
Loading