Skip to content

Commit

Permalink
deprecation migration messaging (#733)
Browse files Browse the repository at this point in the history
* polish: improve visualization of the deprecation messages between serious and warnings with emojis.

This also improves their delineation between messages.
  • Loading branch information
JacobMGEvans authored Apr 4, 2022
1 parent 8e38442 commit 91873e4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-ties-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

polish: improved visualization of the deprecation messages between serious and warnings with emojis. This also improves the delineation between messages.
50 changes: 25 additions & 25 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe("normalizeAndValidateConfig()", () => {
`);
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- DEPRECATION: \\"site.entry-point\\":
- 🚨 NO LONGER SUPPORTED: \\"site.entry-point\\":
The \`site.entry-point\` config field is no longer used.
The entry-point should be specified via the command line or the \`main\` config field."
`);
Expand Down Expand Up @@ -532,12 +532,12 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(true);
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- DEPRECATION: \\"type\\":
DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
- DEPRECATION: \\"webpack_config\\":
DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build."
`);
"Processing wrangler configuration:
- 🦺 DEPRECATION: \\"type\\":
DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
- 🦺 DEPRECATION: \\"webpack_config\\":
DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build."
`);
});
});
});
Expand Down Expand Up @@ -699,15 +699,15 @@ describe("normalizeAndValidateConfig()", () => {
expect(normalizePath(diagnostics.renderWarnings()))
.toMatchInlineSnapshot(`
"Processing project/wrangler.toml configuration:
- DEPRECATION: \\"build.upload.format\\":
- 🦺 DEPRECATION: \\"build.upload.format\\":
The format is inferred automatically from the code.
- DEPRECATION: \\"build.upload.main\\":
- 🦺 DEPRECATION: \\"build.upload.main\\":
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
Then add the top level \`main\` field to your configuration file:
\`\`\`
main = \\"src/index.ts\\"
\`\`\`
- DEPRECATION: \\"build.upload.dir\\":
- 🦺 DEPRECATION: \\"build.upload.dir\\":
Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
- DEPRECATION: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
\`\`\`
Expand Down Expand Up @@ -1448,19 +1448,19 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(true);
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- DEPRECATION: \\"zone_id\\":
This is unnecessary since we can deduce this from routes directly.
- DEPRECATION: \\"experimental_services\\":
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
\`\`\`
[[unsafe.bindings]]
name = \\"NAME\\"
type = \\"service\\"
service = \\"SERVICE\\"
environment = \\"ENV\\"
\`\`\`"
`);
"Processing wrangler configuration:
- 🦺 DEPRECATION: \\"zone_id\\":
This is unnecessary since we can deduce this from routes directly.
- 🦺 DEPRECATION: \\"experimental_services\\":
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
\`\`\`
[[unsafe.bindings]]
name = \\"NAME\\"
type = \\"service\\"
service = \\"SERVICE\\"
environment = \\"ENV\\"
\`\`\`"
`);
});
});

Expand Down Expand Up @@ -2615,9 +2615,9 @@ describe("normalizeAndValidateConfig()", () => {
"Processing wrangler configuration:
- \\"env.ENV1\\" environment configuration
- DEPRECATION: \\"zone_id\\":
- 🦺 DEPRECATION: \\"zone_id\\":
This is unnecessary since we can deduce this from routes directly.
- DEPRECATION: \\"experimental_services\\":
- 🦺 DEPRECATION: \\"experimental_services\\":
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
\`\`\`
[[unsafe.bindings]]
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,14 +845,14 @@ describe("wrangler", () => {
it("should throw an error if the deprecated command is used with positional arguments", async () => {
await expect(runWrangler("preview GET")).rejects
.toThrowErrorMatchingInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
The \`wrangler preview\` command has been deprecated.
Try using \`wrangler dev\` to to try out a worker during development.
"
`);
await expect(runWrangler(`preview GET "SomeBody"`)).rejects
.toThrowErrorMatchingInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
The \`wrangler preview\` command has been deprecated.
Try using \`wrangler dev\` to to try out a worker during development.
"
Expand Down Expand Up @@ -970,15 +970,15 @@ describe("wrangler", () => {
it("should print a deprecation message for 'generate'", async () => {
await runWrangler("generate").catch((err) => {
expect(err.message).toMatchInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
\`wrangler generate\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#generate for alternatives"
`);
});
});
it("should print a deprecation message for 'build'", async () => {
await runWrangler("build").catch((err) => {
expect(err.message).toMatchInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
\`wrangler build\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#build for alternatives"
`);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ describe("publish", () => {
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`
"Processing wrangler.toml configuration:
- DEPRECATION: \\"build.upload.main\\":
- 🦺 DEPRECATION: \\"build.upload.main\\":
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
Then add the top level \`main\` field to your configuration file:
\`\`\`
Expand Down Expand Up @@ -475,13 +475,13 @@ describe("publish", () => {
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`
"Processing ../wrangler.toml configuration:
- DEPRECATION: \\"build.upload.main\\":
- 🦺 DEPRECATION: \\"build.upload.main\\":
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
Then add the top level \`main\` field to your configuration file:
\`\`\`
main = \\"foo/index.js\\"
\`\`\`
- DEPRECATION: \\"build.upload.dir\\":
- 🦺 DEPRECATION: \\"build.upload.dir\\":
Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker."
`);
});
Expand Down Expand Up @@ -655,15 +655,15 @@ export default{
await expect(runWrangler("publish ./index.js")).rejects
.toThrowErrorMatchingInlineSnapshot(`
"Processing wrangler.toml configuration:
- DEPRECATION: \\"site.entry-point\\":
- 🚨 NO LONGER SUPPORTED: \\"site.entry-point\\":
The \`site.entry-point\` config field is no longer used.
The entry-point should be specified via the command line or the \`main\` config field."
`);

expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.err).toMatchInlineSnapshot(`
"Processing wrangler.toml configuration:
- DEPRECATION: \\"site.entry-point\\":
- 🚨 NO LONGER SUPPORTED: \\"site.entry-point\\":
The \`site.entry-point\` config field is no longer used.
The entry-point should be specified via the command line or the \`main\` config field.
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/__tests__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("wrangler route", () => {
it("shows a deprecation notice when `wrangler route` is run", async () => {
await expect(runWrangler("route")).rejects
.toThrowErrorMatchingInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
\`wrangler route\` has been deprecated.
Please use wrangler.toml and/or \`wrangler publish --routes\` to modify routes"
`);
Expand All @@ -18,7 +18,7 @@ describe("wrangler route", () => {
it("shows a deprecation notice when `wrangler route delete` is run", async () => {
await expect(runWrangler("route delete")).rejects
.toThrowErrorMatchingInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
\`wrangler route delete\` has been deprecated.
Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
`);
Expand All @@ -27,7 +27,7 @@ describe("wrangler route", () => {
it("shows a deprecation notice when `wrangler route delete <id>` is run", async () => {
await expect(runWrangler("route delete some-zone-id")).rejects
.toThrowErrorMatchingInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
\`wrangler route delete\` has been deprecated.
Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
`);
Expand All @@ -36,7 +36,7 @@ describe("wrangler route", () => {
it("shows a deprecation notice when `wrangler route list` is run", async () => {
await expect(runWrangler("route list")).rejects
.toThrowErrorMatchingInlineSnapshot(`
"DEPRECATION:
"🦺 DEPRECATION:
\`wrangler route list\` has been deprecated.
Refer to wrangler.toml for a list of routes the worker will be deployed to upon publishing.
Refer to the Cloudflare Dashboard to see the routes this worker is currently running on."
Expand Down
5 changes: 4 additions & 1 deletion packages/wrangler/src/config/validation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export function deprecated<T extends object>(
remove: boolean,
breaking = false
): void {
const diagonsticMessage = breaking
? `🚨 NO LONGER SUPPORTED: "${fieldPath}":\n${message}`
: `🦺 DEPRECATION: "${fieldPath}":\n${message}`;
const result = unwindPropertyPath(config, fieldPath);
if (result !== undefined && result.field in result.container) {
(breaking ? diagnostics.errors : diagnostics.warnings).push(
`DEPRECATION: "${fieldPath}":\n${message}`
diagonsticMessage
);
if (remove) {
delete (result.container as Record<string, unknown>)[result.field];
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class DeprecationError extends Error {
constructor(message: string) {
super(`DEPRECATION:\n${message}`);
super(`🦺 DEPRECATION:\n${message}`);
}
}

Expand Down

0 comments on commit 91873e4

Please sign in to comment.