(Attempt 2) - Use existing wrangler installation when appropriate#269
(Attempt 2) - Use existing wrangler installation when appropriate#269AdiRishi wants to merge 1 commit intocloudflare:mainfrom
Conversation
…priate (cloudflare#235)"" This reverts commit 2d275a8.
|
Hey @AdiRishi 👋! I think it may be as simple as simply disabling the auto-installation behaviour of npx to at least have this work with the npm package manager. npx has the Only tricky thing is I'm not sure if all the package managers have similar options, I assume that they do, but need to look into it further! |
|
Added a PR #271 which does the above! Let me know what you think! |
|
@Maximo-Guk I was definitely going down a much more complex route. I saw that However. you did the smart thing, which was use slightly different execution strategies for each package manager. I think your way is much better than what I was suggesting haha 😅 The only option from the one I wrote out I would possibly consider is executing the binary directly from I'll close this one out in favor of yours. |
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 --versionto 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-actionnow always will install the latest wrangler if you don't specifywranglerVersionin the config. This is a breaking change and bug, since we meant for it to keep it's old behavior and install version3.13.2by 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.jsonfile in code and checking thedependenciesanddevDependenciesobjects for wrangler.Pros: Simply to implement
Cons:
^or~.Execute wrangler directly from
node_modules/.binIf 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-modulesto 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: