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

fix(wrangler): avoid path collisions between performance and Performance polyfills #6025

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

IgorMinar
Copy link
Contributor

@IgorMinar IgorMinar commented Jun 13, 2024

It turns out that ESBuild paths are case insensitive, which can result in path collisions between polyfills for globalThis.performance and globalThis.Performance.

This change ensures that we encode all global names to lowercase and decode them appropriately.

The version of unenv used at HEAD currently doesn't suffer from this path collision, but if not fixed the change introduced in https://github.com/unjs/unenv/pull/257/files would result in Node.js API coverage regressions. This change prevents those regressions from happening.

What this PR solves / how to test

Fixes #[insert GH or internal issue number(s)].

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required / Maybe required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Not necessary because:
…nce polyfills

It turns out that ESBuild paths are case insensitive, which can result in
path collisions between polyfills for globalThis.performance and globalThis.Performance.

This change ensures that we encode all global names to lowercase and decode them appropriately.

The version of unenv used at HEAD currently doesn't suffer from this path collision,
but if not fixed the change introduced in https://github.com/unjs/unenv/pull/257/files
would result in Node.js API coverage regressions. This change prevents those regressions
from happening.
@IgorMinar IgorMinar requested a review from a team as a code owner June 13, 2024 05:07
Copy link

changeset-bot bot commented Jun 13, 2024

🦋 Changeset detected

Latest commit: 6effdba

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

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers 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

github-actions bot commented Jun 13, 2024

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/9498249323/npm-package-wrangler-6025

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9498249323/npm-package-wrangler-6025 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9498249323/npm-package-create-cloudflare-6025 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9498249323/npm-package-cloudflare-kv-asset-handler-6025
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9498249323/npm-package-miniflare-6025
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9498249323/npm-package-cloudflare-pages-shared-6025
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9498249323/npm-package-cloudflare-vitest-pool-workers-6025

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


wrangler@3.60.2 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240605.0
workerd 1.20240605.0 1.20240605.0
workerd --version 1.20240605.0 2024-06-05

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

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.

This fix looks fine to land.
But I think that actually this is not the best approach for these virtual files.
Rather than using virtual fake paths (which in extreme cases could collide with real paths), I think the correct approach is to use esbuild namespaces here to filter these resolves to loaders.
We might still need to encode/decode upper case letters from globals to distinguish between globals that only differ in case, but we could avoid having to use getBasePath() and the concern of path collision.

@petebacondarwin petebacondarwin added the e2e Run e2e tests on a PR label Jun 13, 2024
@petebacondarwin
Copy link
Contributor

It needs a changeset before I merge...

@petebacondarwin petebacondarwin merged commit 122ef06 into main Jun 13, 2024
21 checks passed
@petebacondarwin petebacondarwin deleted the fix/node_compat_v2-inject-case-insensitive branch June 13, 2024 11:26
@workers-devprod workers-devprod added the contribution [Holopin] Recognizes an open-source contribution, big or small label Jun 13, 2024
Copy link

holopin-bot bot commented Jun 13, 2024

Congratulations @IgorMinar, you just earned a holobyte! Here it is: https://holopin.io/holobyte/clxd6dfbz31420cmgnkzuoc3x

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

IgorMinar added a commit that referenced this pull request Jun 14, 2024
Follow up on  #6025 that makes
the code a bit more resilient.
IgorMinar added a commit that referenced this pull request Jun 15, 2024
Follow up on  #6025 that makes
the code a bit more resilient.
petebacondarwin pushed a commit that referenced this pull request Jun 15, 2024
Follow up on  #6025 that makes
the code a bit more resilient.
petebacondarwin added a commit that referenced this pull request Jun 17, 2024
* fix(node_compat): support $ characters in unenv inject preset

Follow up on  #6025 that makes
the code a bit more resilient.

* fixup! fix(node_compat): support $ characters in unenv inject preset

* fixup! fix(node_compat): support $ characters in unenv inject preset

* fixup! fix(node_compat): support $ characters in unenv inject preset

---------

Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution [Holopin] Recognizes an open-source contribution, big or small e2e Run e2e tests on a PR
3 participants