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

feat: support for raw "unsafe bindings" #411

Merged
merged 2 commits into from
Feb 10, 2022

Conversation

ObsidianMinor
Copy link
Contributor

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.

@changeset-bot
Copy link

changeset-bot bot commented Feb 8, 2022

🦋 Changeset detected

Latest commit: 9b5a796

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

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

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

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

Some quick notes -

packages/wrangler/src/api/form_data.ts Outdated Show resolved Hide resolved
packages/wrangler/src/api/form_data.ts Outdated Show resolved Hide resolved
@ObsidianMinor ObsidianMinor force-pushed the feat/unsafe-bindings branch 2 times, most recently from 58a99db to a0d88cf Compare February 8, 2022 20:59
Copy link
Contributor

@threepointone threepointone left a 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 ` +
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`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 ` +

Copy link
Contributor Author

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.

Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

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).

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@threepointone threepointone left a 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!

@threepointone
Copy link
Contributor

Could you rebase please?

@ObsidianMinor ObsidianMinor force-pushed the feat/unsafe-bindings branch 2 times, most recently from f8c985e to 1411ddb Compare February 10, 2022 21:36
@ObsidianMinor
Copy link
Contributor Author

Ah there we go

@threepointone threepointone merged commit a52f0e0 into cloudflare:main Feb 10, 2022
@github-actions github-actions bot mentioned this pull request Feb 10, 2022
threepointone added a commit that referenced this pull request Feb 11, 2022
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"
```
threepointone added a commit that referenced this pull request Feb 11, 2022
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"
```
threepointone added a commit that referenced this pull request Feb 11, 2022
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"
```
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