-
Notifications
You must be signed in to change notification settings - Fork 774
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
feat: support for raw "unsafe bindings" #411
feat: support for raw "unsafe bindings" #411
Conversation
🦋 Changeset detectedLatest commit: 9b5a796 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
2fd9775
to
34c814a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick notes -
- Please add a changeset (https://github.com/cloudflare/wrangler2/blob/main/CONTRIBUTING.md#changesets)
- Please add tests
- Please use the word "unsafe" instead of "raw" everywhere
58a99db
to
a0d88cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me! A couple of nits, and we can merge this.
for (const binding of config.unsafe?.bindings ?? []) { | ||
if (knownBindings.includes(binding.type)) { | ||
console.warn( | ||
`Raw '${binding.type}' bindings are not directly supported by wrangler. Consider migrating to a ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`Raw '${binding.type}' bindings are not directly supported by wrangler. Consider migrating to a ` + | |
`Unsafe '${binding.type}' bindings are not directly supported by wrangler. Consider migrating to a ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking for documentation purposes we'd call these "raw bindings" (because that's what it is) and going forward any experimental features would be placed in the unsafe
table for consistency. I'd be open to writing the warning as Unsafe raw 'x' bindings
though. Just thinking if we take this path that "unsafe bindings" are vague because other binding types could be added to the unsafe table but wouldn't be raw bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're unsafe because we may break this at any point and don't commit to supporting it forever, so the word unsafe should probably be there. If we want to use this for actually stable bindings, then we should add them as first class bindings, regardless of whether they're internal only. We can simply not document them.
expect(std.err).toMatchInlineSnapshot(`""`); | ||
expect(std.warn).toMatchInlineSnapshot(` | ||
"'unsafe' fields are experimental and may change or break at any time. | ||
Raw 'plain_text' bindings are not directly supported by wrangler. Consider migrating to a format for 'plain_text' bindings that is supported by wrangler for optimal support: https://developers.cloudflare.com/workers/cli-wrangler/configuration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raw 'plain_text' bindings are not directly supported by wrangler. Consider migrating to a format for 'plain_text' bindings that is supported by wrangler for optimal support: https://developers.cloudflare.com/workers/cli-wrangler/configuration" | |
Unsafe 'plain_text' bindings are not directly supported by wrangler. Consider migrating to a format for 'plain_text' bindings that is supported by wrangler for optimal support: https://developers.cloudflare.com/workers/cli-wrangler/configuration" |
@@ -28,5 +28,6 @@ | |||
"xxhash" | |||
], | |||
"cSpell.ignoreWords": ["yxxx"], | |||
"eslint.runtime": "node" | |||
"eslint.runtime": "node", | |||
"files.trimTrailingWhitespace": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it configured to trim trailing whitespace on save on VS Code (which makes sense for most projects I work on). But in this project from what I can tell trailing whitespace is necessary for tests that test console output (since they make empty lines).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really like to have all trailing whitespace removed in this project.
Which tests were failing when trimmed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any test with a snapshot with an empty line. It makes an inline snapshot like this
expect(std.out).toMatchInlineSnapshot(`
"Uploaded
test-name
(TIMINGS)
Deployed
test-name
(TIMINGS)
test-name.test-sub-domain.workers.dev"
`);
Which if you have trim whitespace on save enabled will immediately remove the spaces that are actually needed for the snapshot. An alternative solution to this is moving the snapshots to their own files instead and just not editing them manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow, does it trim whitespace inside the snapshot string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there's significant whitespace on this "empty" line
(TIMINGS)
test-name.test-sub-domain.workers.dev"
Remove trailing whitespace would delete all the whitespace on the line, including the significant whitespace required for the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh!!! That's really horrible.
We should fix the std.out
to remove such blank lines, since we are already do other processing on this output for testing.
Either way, we should not allow trailing whitespace in our code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's land this and iterate. Thank you for the PR!
Could you rebase please? |
f8c985e
to
1411ddb
Compare
1411ddb
to
9b5a796
Compare
Ah there we go |
Now that we have `[[unsafe.bindings]]` (as of #411), we should use that for experimental features. This removes support for `[experimental_services]`, and adds a helpful message for how to rewrite their configuration. This error is temporary, until the internal teams that were using this rewrite their configs. We'll remove it before GA. What the error looks like - ``` Error: 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 = "SomeService" type = "service" service = "some-service" environment = "staging" [[unsafe.bindings]] name = "SomeOtherService" type = "service" service = "some-other-service" environment = "qa" ```
Now that we have `[[unsafe.bindings]]` (as of #411), we should use that for experimental features. This removes support for `[experimental_services]`, and adds a helpful message for how to rewrite their configuration. This error is temporary, until the internal teams that were using this rewrite their configs. We'll remove it before GA. What the error looks like - ``` Error: 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 = "SomeService" type = "service" service = "some-service" environment = "staging" [[unsafe.bindings]] name = "SomeOtherService" type = "service" service = "some-other-service" environment = "qa" ```
Now that we have `[[unsafe.bindings]]` (as of #411), we should use that for experimental features. This removes support for `[experimental_services]`, and adds a helpful message for how to rewrite their configuration. This error is temporary, until the internal teams that were using this rewrite their configs. We'll remove it before GA. What the error looks like - ``` Error: 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 = "SomeService" type = "service" service = "some-service" environment = "staging" [[unsafe.bindings]] name = "SomeOtherService" type = "service" service = "some-other-service" environment = "qa" ```
Implements support for raw bindings as described in #358
Raw bindings can be defined in the
unsafe.bindings
table array in wrangler.toml as -[[unsafe.bindings]]
name = "my-binding"
type = "binding-type"
The TOML table will then be directly inserted into the metadata upload for a Worker in JSON format as though it were a binding made by wrangler itself. Note, these bindings cannot be detected by tools like miniflare, so support for specific binding types is sparse and limited.