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

chore(wrangler): use the unenv preset from @cloudflare/unenv-preset #7720

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Jan 10, 2025

The cloudflare preset was migrated to this mono-repo (@cloudflare/unenv-preset)

This PR is switching to using this version

To do before merging:

  • diff the output of a wrangler build before/after
  • test the pre-release version of wrangler
  • [ ] make sure the Vite plugin works with @cloudflare/unenv-preset (from discussion with @vicb and @petebacondarwin : not actually needed for this PR as it doesn't touch vite plugin)
  • publish @cloudflare/unenv-preset@1.0.0 and use that version

/cc @petebacondarwin @pi0 @dario-piotrowicz


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because: preset is tested, will do a diff test
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: no user facing change

@vicb vicb requested a review from a team as a code owner January 10, 2025 09:49
Copy link

changeset-bot bot commented Jan 10, 2025

🦋 Changeset detected

Latest commit: 8523cbf

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

@vicb vicb added the e2e Run e2e tests on a PR label Jan 10, 2025
Copy link
Contributor

github-actions bot commented Jan 10, 2025

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/12788368201/npm-package-wrangler-7720

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-wrangler-7720 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-workers-bindings-extension-7720 -O ./cloudflare-workers-bindings-extension.0.0.0-v4bec158fa.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v4bec158fa.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-create-cloudflare-7720 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-kv-asset-handler-7720

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-miniflare-7720

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-pages-shared-7720

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-unenv-preset-7720

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-vitest-pool-workers-7720

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-workers-editor-shared-7720

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-workers-shared-7720

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12788368201/npm-package-cloudflare-workflows-shared-7720

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


wrangler@3.102.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241230.2
workerd 1.20241230.0 1.20241230.0
workerd --version 1.20241230.0 2024-12-30

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

@vicb vicb force-pushed the use-cf-preset branch 5 times, most recently from 16f9044 to 4506f5b Compare January 14, 2025 08:55
@vicb
Copy link
Contributor Author

vicb commented Jan 14, 2025

I generated https://github.com/opennextjs/opennextjs-cloudflare/tree/main/examples/vercel-blog-starter with both wrangler 3.101.0 and a dev version of wrangler built from this PR to see if there are any differences.

The differences are:

Better names

// stable
// ../../../../../.nvm/versions/node/v22.11.0/lib/node_modules/wrangler/_virtual_unenv_global_polyfill-clear$immediate.js
var init_virtual_unenv_global_polyfill_clear_immediate = __esm({
  "../../../../../.nvm/versions/node/v22.11.0/lib/node_modules/wrangler/_virtual_unenv_global_polyfill-clear$immediate.js"() {
    init_cloudflare();
    globalThis.clearImmediate = clearImmediateFallback;
  }
});

// dev
// ../../../workers-sdk/packages/wrangler/_virtual_unenv_global_polyfill-clear$immediate.js
var init_virtual_unenv_global_polyfill_clear_immediate = __esm({
  "../../../workers-sdk/packages/wrangler/_virtual_unenv_global_polyfill-clear$immediate.js"() {
    init_timers();
    globalThis.clearImmediate = clearImmediateFallback;
  }
});

init_timers is better than init_cloudflare (we end up having init_cloudflare2, init_cloudflare3, init_cloudflare4, ... for all the $cloudflare.ts file

Path are different (expected)

// Stable
// ../../../../../.nvm/versions/node/v22.11.0/lib/node_modules/wrangler/node_modules/unenv/runtime/node/timers/internal/immediate.mjs
var Immediate;
var init_immediate = __esm({
  "../../../../../.nvm/versions/node/v22.11.0/lib/node_modules/wrangler/node_modules/unenv/runtime/node/timers/internal/immediate.mjs"() {
    init_virtual_unenv_global_polyfill_process();
    
// Dev
// ../../../workers-sdk/node_modules/.pnpm/unenv-nightly@2.0.0-20241218-183400-5d6aec3/node_modules/unenv-nightly/runtime/node/timers/internal/immediate.mjs
var Immediate;
var init_immediate = __esm({
  "../../../workers-sdk/node_modules/.pnpm/unenv-nightly@2.0.0-20241218-183400-5d6aec3/node_modules/unenv-nightly/runtime/node/timers/internal/immediate.mjs"() {

So no functional changes between the current (stable) and PR state.

.changeset/cuddly-pets-smell.md Outdated Show resolved Hide resolved
packages/wrangler/scripts/deps.ts Outdated Show resolved Hide resolved
packages/wrangler/package.json Outdated Show resolved Hide resolved
@petebacondarwin
Copy link
Contributor

It is pleasing that you didn't need to change much inside Wrangler to get this to work.

.changeset/cuddly-pets-smell.md Outdated Show resolved Hide resolved
@vicb
Copy link
Contributor Author

vicb commented Jan 15, 2025

It is pleasing that you didn't need to change much inside Wrangler to get this to work.

True - but this change was prepared in #7721, #7697, #7685, #7625, #7522, and a few other PRs :)

@vicb vicb force-pushed the use-cf-preset branch 3 times, most recently from 709191c to ebd9626 Compare January 15, 2025 11:37
@vicb vicb requested review from a team as code owners January 15, 2025 11:37
@vicb vicb force-pushed the use-cf-preset branch 2 times, most recently from eaa9fc9 to 7540513 Compare January 15, 2025 11:40
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
@vicb vicb requested a review from petebacondarwin January 15, 2025 13:03
@vicb vicb changed the title [WIP] chore(wrangler): use the unenv preset from @cloudflare/unenv-preset chore(wrangler): use the unenv preset from @cloudflare/unenv-preset Jan 15, 2025
@@ -70,6 +70,7 @@
},
"dependencies": {
"@cloudflare/kv-asset-handler": "workspace:*",
"@cloudflare/unenv-preset": "1.x",
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want to lock this down to a specific version?
Similar to the unenv, miniflare and workerd versions we want to explicitly lock these into Wrangler, and then bump them all at the same time, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want the latest version of the preset.
I hope that the peerDep on workerd in the preset will constrain the version (via the local workerd)
Maybe we can pin to 1.0.x or even 1.0.0 until we make sure that works correctly?

Copy link
Contributor

Choose a reason for hiding this comment

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

I hope that the peerDep on workerd in the preset will constrain the version (via the local workerd)

Interesting... I hope it works that way (for all package managers.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try not pinning for now and then see if it works as expected for our first few releases.

@vicb vicb merged commit 902e3af into main Jan 15, 2025
33 checks passed
@vicb vicb deleted the use-cf-preset branch January 15, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants