Closed AdiRishi closed 5 months ago
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 --no-install
flag, I tried it out on a reproduction repository here and it seemed to work as expected.
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 https://github.com/cloudflare/wrangler-action/pull/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 --no-install
was not present in each package manager and figured I'd need a different approach.
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 node_modules/.bin
. But again, I think your PR does it in a much better way.
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 --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: