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] Make wrangler dev --experimental-local the default 🎉 #3224

Merged
merged 2 commits into from
May 17, 2023

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented May 16, 2023

Closes #2821
Closes DEVX-605
Closes DEVX-625
Closes DEVX-626
Closes DEVX-634

What this PR solves / how to test:

This PR...

  1. Removes the existing --local implementation powered by Miniflare 2
  2. Graduates the new --experimental-local implementation powered by Miniflare 3 to --local
  3. Makes --local the default
  4. Deprecates the --local/--experimental-local flags
  5. Adds a new --remote flag to restore the old behaviour

Previously, the --experimental-local implementation was built on-top of the previous --local one. As we're removing --local, this meant there was a lot of untangling to do. We're planning some architectural improvements to wrangler dev soon. To see what these might look like, the new Miniflare 3 implementation has been implemented using the proposed approach, and integrated with the existing system to demonstrate incremental adoptability.

This PR also adds a few missing features/fixes to the --experimental-local implementation:

  • Fix source mapping of service worker workers
  • Allow use of Durable Objects defined in other workers
  • Add support for custom upstreams

In terms of other breaking changes, remote KV storage in local mode has been removed as this is incompatible with Miniflare's new storage system. This was an experimental feature we'll need to rethink. This new storage system also changed the persistence format, invalidating all previously persisted data. To avoid loading invalid data, the default persistence directory has been changed.

Still TODO (wanted to get this PR up so we can start testing the pre-release):

  • Add more tests
  • Add warning if we detect old persistence directory
  • Add message that wrangler dev is now using local mode on first run
  • Update changeset with other breaking changes and features

Associated docs issue(s)/PR(s):

Author has included the following, where applicable:

Reviewer is to perform the following, as 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

@mrbbot mrbbot requested review from a team as code owners May 16, 2023 13:44
@changeset-bot
Copy link

changeset-bot bot commented May 16, 2023

🦋 Changeset detected

Latest commit: 78720c2

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

This PR includes changesets to release 2 packages
Name Type
wrangler Major
news-feed-app 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

@github-actions
Copy link
Contributor

github-actions bot commented May 16, 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/5003291085/npm-package-wrangler-3224

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

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

Or you can use npx with this latest build directly:

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

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

package.json Show resolved Hide resolved
Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

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

Looks great (for a mammoth PR 😆 ), have some questions before approving

packages/wrangler/scripts/bundle.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/api.test.ts Show resolved Hide resolved
packages/wrangler/src/__tests__/tail.test.ts Show resolved Hide resolved
packages/wrangler/src/api/dev.ts Show resolved Hide resolved
packages/wrangler/src/bundle.ts Show resolved Hide resolved
packages/wrangler/src/d1/execute.tsx Show resolved Hide resolved
packages/wrangler/src/dev.tsx Show resolved Hide resolved
Comment on lines +687 to +710
// Our inspector proxy server will be binding to the result of
// `getInspectorPort`. If we attempted to bind workerd to the same inspector
// port, we'd get a port already in use error. Therefore, generate a new port
// for our runtime to bind its inspector service to.
const getRuntimeInspectorPort = memoizeGetPort();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we certain these Node processes are getting cleaned up after use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure. You can't have two processes listening on the same port, so we definitely need separate ports for Wrangler's inspector proxy server and the runtime's inspector server.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is creating tons of zombie Node processes holding onto more and more ports.

@mrbbot mrbbot changed the title Make wrangler dev --experimental-local the default 🎉 [wrangler] Make wrangler dev --experimental-local the default 🎉 May 16, 2023
packages/pages-shared/package.json Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/dev.test.tsx Show resolved Hide resolved
packages/wrangler/src/__tests__/dev.test.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Merging #3224 (d688927) into v3 (3050ce7) will increase coverage by 0.73%.
The diff coverage is 58.04%.

❗ Current head d688927 differs from pull request most recent head 26bab6b. Consider uploading reports for the commit 26bab6b to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##               v3    #3224      +/-   ##
==========================================
+ Coverage   74.55%   75.29%   +0.73%     
==========================================
  Files         179      180       +1     
  Lines       10969    10895      -74     
  Branches     2922     2851      -71     
==========================================
+ Hits         8178     8203      +25     
+ Misses       2791     2692      -99     
Impacted Files Coverage Δ
...ges/wrangler/src/dev/get-local-persistence-path.ts 85.71% <ø> (+19.04%) ⬆️
packages/wrangler/src/entry.ts 98.41% <ø> (ø)
...ages/wrangler/src/metrics/metrics-usage-headers.ts 87.50% <ø> (ø)
...ckages/wrangler/src/pages/functions/buildPlugin.ts 19.35% <0.00%> (ø)
packages/wrangler/src/pages/projects.tsx 80.88% <ø> (ø)
packages/wrangler/src/update-check.ts 25.00% <0.00%> (-5.00%) ⬇️
packages/wrangler/src/d1/execute.tsx 52.81% <5.00%> (-4.44%) ⬇️
packages/wrangler/src/index.ts 82.24% <10.00%> (-2.46%) ⬇️
packages/wrangler/src/dev/local.tsx 22.91% <22.72%> (+1.30%) ⬆️
packages/wrangler/src/pages/dev.ts 18.29% <33.33%> (+0.15%) ⬆️
... and 19 more

... and 5 files with indirect coverage changes

@JacobMGEvans JacobMGEvans dismissed their stale review May 16, 2023 19:41

Won't block, questions and concerns resolved.

Copy link
Member

@GregBrimble GregBrimble left a comment

Choose a reason for hiding this comment

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

general vibe check for the code from Pages looks good. I want to actually test it a bunch tonight still though.

Copy link
Member

@GregBrimble GregBrimble left a comment

Choose a reason for hiding this comment

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

the rare double approval. gave the Pages functionality a whirl. Looks good to me in practice too ✅✅

@@ -94902,7 +92549,7 @@
"version": "0.1.0"
},
"yoga-layout": {
"version": "file:../../vendor/yoga-layout-2.0.0-beta.1.tgz",
"version": "file:..\\..\\vendor\\yoga-layout-2.0.0-beta.1.tgz",
Copy link
Member

Choose a reason for hiding this comment

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

Refresh by running npm i on unix machine

@GregBrimble
Copy link
Member

Consider adding .wrangler to the .gitignore root of workers-sdk.

...and make `--local` the default and add `--remote` flag
This reverts commit 13abe44.
@mrbbot mrbbot force-pushed the bcoll/graduate-experimental-local branch from 26bab6b to 78720c2 Compare May 17, 2023 12:39
@mrbbot mrbbot merged commit c9f3526 into v3 May 17, 2023
5 of 9 checks passed
@mrbbot mrbbot deleted the bcoll/graduate-experimental-local branch May 17, 2023 12:40
petebacondarwin pushed a commit that referenced this pull request May 17, 2023
)

* Use Miniflare 3 for `--local` and deprecate `--experimental-local`

...and make `--local` the default and add `--remote` flag

* Revert "fix: c3 arguments"

This reverts commit 13abe44.
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

5 participants