(Attempt 2) - Use existing wrangler installation when appropriate #269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR attempts to bring back #235 and fix the fatal flaw that caused it to be reverted.
Summary of what went wrong with the last PR
The code which checks for an existing installation runs
npx wrangler --version
to determine if wrangler is installed (or the equivilent command for other package managers). What I missed was that this command will automatically install the latest version of wrangler if no version is installed 🙃This means that by accident
wrangler-action
now always will install the latest wrangler if you don't specifywranglerVersion
in the config. This is a breaking change and bug, since we meant for it to keep it's old behavior and install version3.13.2
by default.Strategies to fix the bug
This is where things get tricky. Our task is as follows
Goal: Find out two key pieces of information
We need to do the above while supporting 6 different package managers which all have different sets of CLI commands
I've looked through several options, and all of them have their pros and cons. I'm going to list down the various strategies from the most simple implementation to the most difficult. I would love to have a dicsussion on which one we should pick before I go and implement something.
Naively check package.json for version
This involves simply loading the
package.json
file in code and checking thedependencies
anddevDependencies
objects for wrangler.Pros: Simply to implement
Cons:
^
or~
.Execute wrangler directly from
node_modules/.bin
If wrangler is sucessfully installed, in all package managers* we will find it's executable linked to
node_modules/.bin
. We can then run it directly from here and do the same checks as before.Pros: Simple to implement
Cons:
nodeLinker: node-modules
to be enabledUse various package manager commands to determine installation
Package managers have various commands that list installed packages. npm and pnpm and bun have
ls
, yarn haswhy
.These commands could be executed and we can capture and parse the output to figure out what wrangler version is installed.
Pros: 100% assurance that installation was successful
Cons: