Skip to content

Commit

Permalink
fix: display a warning if the user has a miniflare section in their… (
Browse files Browse the repository at this point in the history
#820)

* fix: display a warning if the user has a `miniflare` section in their `wrangler.toml`.

Closes #799
  • Loading branch information
petebacondarwin authored Apr 19, 2022
1 parent 0d14c66 commit 60c409a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/honest-dolphins-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: display a warning if the user has a `miniflare` section in their `wrangler.toml`.

Closes #799
5 changes: 3 additions & 2 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe("normalizeAndValidateConfig()", () => {
`);
});

it("should ignore `miniflare` top level fields", () => {
it("should report a deprecation warning if `miniflare` appears at the top level", () => {
const expectedConfig = {
miniflare: {
host: "localhost",
Expand All @@ -156,7 +156,8 @@ describe("normalizeAndValidateConfig()", () => {
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
"
- 😶 UNUSED: \\"miniflare\\":
Wrangler does not use configuration in the \`miniflare\` section. Unless you are using Miniflare directly you can remove this section."
`);
});

Expand Down
6 changes: 6 additions & 0 deletions packages/wrangler/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ export interface DeprecatedConfigFields {
* @breaking
*/
webpack_config?: string;

/**
* Configuration only used by a standalone use of the miniflare binary.
* @deprecated
*/
miniflare?: unknown;
}

interface EnvironmentMap {
Expand Down
11 changes: 4 additions & 7 deletions packages/wrangler/src/config/validation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ export function deprecated<T extends object>(
fieldPath: DeepKeyOf<T>,
message: string,
remove: boolean,
breaking = false
title = "🦺 DEPRECATION",
type: "warning" | "error" = "warning"
): void {
const diagonsticMessage = breaking
? `🚨 NO LONGER SUPPORTED: "${fieldPath}":\n${message}`
: `🦺 DEPRECATION: "${fieldPath}":\n${message}`;
const diagnosticMessage = `${title}: "${fieldPath}":\n${message}`;
const result = unwindPropertyPath(config, fieldPath);
if (result !== undefined && result.field in result.container) {
(breaking ? diagnostics.errors : diagnostics.warnings).push(
diagonsticMessage
);
diagnostics[`${type}s`].push(diagnosticMessage);
if (remove) {
delete (result.container as Record<string, unknown>)[result.field];
}
Expand Down
14 changes: 12 additions & 2 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export function normalizeAndValidateConfig(
} configuration:`
);

deprecated(
diagnostics,
rawConfig,
"miniflare",
"Wrangler does not use configuration in the `miniflare` section. Unless you are using Miniflare directly you can remove this section.",
true,
"😶 UNUSED"
);

deprecated(
diagnostics,
rawConfig,
Expand All @@ -80,7 +89,8 @@ export function normalizeAndValidateConfig(
`site.entry-point`,
`The \`site.entry-point\` config field is no longer used.\nThe entry-point should be specified via the command line or the \`main\` config field.`,
false,
true
"🚨 NO LONGER SUPPORTED",
"error"
);

validateOptionalProperty(
Expand Down Expand Up @@ -211,7 +221,7 @@ export function normalizeAndValidateConfig(
diagnostics,
"top-level",
Object.keys(rawConfig),
[...Object.keys(config), "env", "miniflare"]
[...Object.keys(config), "env"]
);

return { config, diagnostics };
Expand Down

0 comments on commit 60c409a

Please sign in to comment.