Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrangler: add metadata to the unsafe binding #2665

Merged
merged 3 commits into from
Feb 27, 2023

Conversation

alankemp
Copy link
Contributor

@alankemp alankemp commented Feb 1, 2023

This allows you to add arbitary fields to the metadata uploaded with a worker.

[unsafe.metadata]
some_key = some_value

What this PR solves / how to test:

Associated docs issues/PR:

  • [insert associated docs issue(s)/PR(s)]

Author has included the following, where applicable:

  • Tests
  • Changeset

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Fixes # [insert issue number].

@alankemp alankemp requested a review from a team as a code owner February 1, 2023 15:51
@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2023

🦋 Changeset detected

Latest commit: 8c6ccf8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4285802836/npm-package-wrangler-2665

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/2665/npm-package-wrangler-2665

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4285802836/npm-package-wrangler-2665 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/4285802836/npm-package-cloudflare-pages-shared-2665

Note that these links will no longer work once the GitHub Actions artifact expires.

@codecov
Copy link

codecov bot commented Feb 1, 2023

Codecov Report

Merging #2665 (606e5b5) into main (6278413) will increase coverage by 0.08%.
The diff coverage is 100.00%.

❗ Current head 606e5b5 differs from pull request most recent head 8c6ccf8. Consider uploading reports for the commit 8c6ccf8 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2665      +/-   ##
==========================================
+ Coverage   73.96%   74.04%   +0.08%     
==========================================
  Files         166      166              
  Lines       10197    10181      -16     
  Branches     2728     2711      -17     
==========================================
- Hits         7542     7539       -3     
+ Misses       2655     2642      -13     
Impacted Files Coverage Δ
packages/wrangler/src/dev.tsx 84.25% <ø> (-0.81%) ⬇️
packages/wrangler/src/index.ts 83.92% <ø> (-0.07%) ⬇️
packages/wrangler/src/publish/publish.ts 86.66% <ø> (-0.17%) ⬇️
packages/wrangler/src/secret/index.ts 86.46% <ø> (ø)
packages/wrangler/src/worker.ts 100.00% <ø> (ø)
packages/wrangler/src/config/index.ts 96.45% <100.00%> (+0.07%) ⬆️
packages/wrangler/src/config/validation-helpers.ts 97.97% <100.00%> (ø)
packages/wrangler/src/config/validation.ts 91.07% <100.00%> (+0.19%) ⬆️
packages/wrangler/src/create-worker-upload-form.ts 90.65% <100.00%> (+0.26%) ⬆️
packages/wrangler/src/init.ts 93.78% <100.00%> (+0.01%) ⬆️
... and 16 more

@@ -1155,6 +1155,7 @@ function normalizeAndValidateEnvironment(
validateBindingsProperty(envName, validateUnsafeBinding),
{
bindings: [],
metadata: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I am not sure about bundling the unsafe metadata and bindings into the same object here... The validateBindingsProperty is really only designed to deal with the original unsafe bindings array of objects...

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - with a couple of nits that you can tidy up as you wish @alankemp

packages/wrangler/src/__tests__/init.test.ts Show resolved Hide resolved
packages/wrangler/src/config/environment.ts Outdated Show resolved Hide resolved
packages/wrangler/src/config/index.ts Outdated Show resolved Hide resolved
@alankemp alankemp force-pushed the add_unsafe_metadata branch 2 times, most recently from 2e770ff to d6185ed Compare February 3, 2023 14:42
@alankemp
Copy link
Contributor Author

alankemp commented Feb 3, 2023

I just tried a wrangler.toml that included unsafe.metadata but not an unsafe.binding and get an error:
- The field "unsafe" is missing the required "bindings" property.

So I need to fix that before this can be merged

@alankemp
Copy link
Contributor Author

alankemp commented Feb 6, 2023

I just tried a wrangler.toml that included unsafe.metadata but not an unsafe.binding and get an error: - The field "unsafe" is missing the required "bindings" property.

So I need to fix that before this can be merged

This is now done.

@petebacondarwin petebacondarwin changed the title Add metadata to the unsafe binding wrangler: add metadata to the unsafe binding Feb 7, 2023
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fixup commit that I think resolves the weirdness you are seeing.

See c445c55

packages/wrangler/src/__tests__/configuration.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/config/validation-helpers.ts Outdated Show resolved Hide resolved
This allows you to add arbitary fields to the metadata uploaded with
a worker.

[unsafe.metadata]
some_key = some_value
@petebacondarwin petebacondarwin merged commit 4756d6a into cloudflare:main Feb 27, 2023
@github-actions github-actions bot mentioned this pull request Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants