Skip to content

Delegate to local installs of wrangler when possible #1270

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

Merged
merged 5 commits into from
Jun 21, 2022
Merged

Conversation

caass
Copy link
Contributor

@caass caass commented Jun 15, 2022

Delegate to a local install of wrangler if one exists.

Users will frequently install wrangler globally to run commands like wrangler init, but we also recommend pinning a specific version of wrangler in a project's package.json. Now, when a user invokes a global install of wrangler, we'll check to see if they also have a local installation. If they do, we'll delegate to that version.

Closes #955

Here's a recording of this in action, with a couple console.logs indicating if a global or local installation is running:

asciicast

@changeset-bot
Copy link

changeset-bot bot commented Jun 15, 2022

🦋 Changeset detected

Latest commit: 4f4c50a

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

@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2536345365/npm-package-wrangler-1270

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

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1270/npm-package-wrangler-1270

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2536345365/npm-package-wrangler-1270 dev path/to/script.js

@caass caass force-pushed the delegate-to-local branch 2 times, most recently from a749166 to 8cc6fbf Compare June 20, 2022 21:17
Users will frequently install `wrangler` globally to run commands like
`wrangler init`, but we also recommend pinning a specific version of
`wrangler` in a project's `package.json`. Now, when a user invokes a
global install of `wrangler`, we'll check to see if they also have a
local installation. If they do, we'll delegate to that version.

This requires that we define a `main` (maybe `module` would work too?)
field in `package.json` so that `require.resolve` can find `"wrangler"`,
but it's something of an implementation detail.
@caass caass force-pushed the delegate-to-local branch from 4af4e7e to f839466 Compare June 21, 2022 12:00
@caass caass marked this pull request as ready for review June 21, 2022 12:04
@caass caass changed the title [DRAFT] Delegate to local installs of wrangler when possible Delegate to local installs of wrangler when possible Jun 21, 2022
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.

Approved with the following NITS:

  • Add a warning message when we do actually delegate (inside runDelegatedWrangler()?).
  • Move the node version check inside runWrangler().
  • Make shouldDelegate a function and then we can call it like:
wranglerProcess = shouldDelegate() ? runDelegatedWrangler() : runWrangler();

@caass caass force-pushed the delegate-to-local branch from 5b7b878 to 4f4c50a Compare June 21, 2022 15:01
@caass caass merged commit 7ed5e1a into main Jun 21, 2022
@caass caass deleted the delegate-to-local branch June 21, 2022 17:06
@github-actions github-actions bot mentioned this pull request Jun 21, 2022
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.

💬 RFC: Installation Path & Priority
2 participants