Skip to content

Commit

Permalink
Deprecate "deployment" in metadata binding (#5818)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed May 16, 2024
1 parent 3a65060 commit df2daf2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .changeset/smart-actors-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"wrangler": minor
---

chore: Deprecate usage of the deployment object on the unsafe metadata binding in favor of the new version_metadata binding.

If you're currently using the old binding, please move over to the new version_metadata binding by adding:

```toml
[version_metadata]
binding = "CF_VERSION_METADATA"
```

and updating your usage accordingly. You can find the docs for the new binding here: https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata
42 changes: 42 additions & 0 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,48 @@ describe("normalizeAndValidateConfig()", () => {
`);
});
});

it("should warn on unsafe binding metadata usage", () => {
const expectedConfig: RawConfig = {
unsafe: {
bindings: [
{
type: "metadata",
name: "METADATA",
},
],
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
expectedConfig,
"project/wrangler.toml",
{ env: undefined }
);

expect(config).toEqual(
expect.objectContaining({
unsafe: {
bindings: [
{
type: "metadata",
name: "METADATA",
},
],
},
})
);
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(true);

expect(normalizeSlashes(diagnostics.renderWarnings()))
.toMatchInlineSnapshot(`
"Processing project/wrangler.toml configuration:
- \\"unsafe\\" fields are experimental and may change or break at any time.
- \\"unsafe.bindings[0]\\": {\\"type\\":\\"metadata\\",\\"name\\":\\"METADATA\\"}
- The deployment object in the metadata binding is now deprecated. Please switch using the version_metadata binding for access to version specific fields: https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata"
`);
});
});

describe("top-level environment configuration", () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,17 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
"For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration"
);
}

if (
value.type === "metadata" &&
isRequiredProperty(value, "name", "string")
) {
diagnostics.warnings.push(
"The deployment object in the metadata binding is now deprecated. " +
"Please switch using the version_metadata binding for access to version specific fields: " +
"https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata"
);
}
} else {
diagnostics.errors.push(`binding should have a string "type" field.`);
isValid = false;
Expand Down

0 comments on commit df2daf2

Please sign in to comment.