Skip to content

Commit

Permalink
Invoke wrangler to check if it's installed, but don't auto-install th…
Browse files Browse the repository at this point in the history
…rough npx/bunx
  • Loading branch information
Maximo-Guk committed Jun 16, 2024
1 parent aa5d18d commit 66efca2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-spies-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler-action": minor
---

This unreverts #235 ensuring wrangler-action will re-use existing wrangler installations, thanks @AdiRishi! and ensures we don't automatically install wrangler when checking if it present
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ async function installWrangler() {
let installedVersionSatisfiesRequirement = false;
try {
const { stdout } = await getExecOutput(
packageManager.exec,
// We want to simply invoke wrangler to check if it's installed, but don't want to auto-install it at this stage
packageManager.execNoInstall,
["wrangler", "--version"],
{
cwd: config["workingDirectory"],
Expand Down
67 changes: 38 additions & 29 deletions src/packageManagers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ describe("getPackageManager", () => {
.toMatchInlineSnapshot(`
{
"exec": "npx",
"execNoInstall": "npx --no-install",
"install": "npm i",
}
`);

expect(getPackageManager("yarn", { workingDirectory: "test/npm" }))
.toMatchInlineSnapshot(`
{
"exec": "yarn",
"install": "yarn add",
}
`);
{
"exec": "yarn",
"execNoInstall": "yarn",
"install": "yarn add",
}
`);

expect(getPackageManager("pnpm", { workingDirectory: "test/npm" }))
.toMatchInlineSnapshot(`
{
"exec": "pnpm exec",
"execNoInstall": "pnpm exec",
"install": "pnpm add",
}
`);
Expand All @@ -31,6 +34,7 @@ describe("getPackageManager", () => {
.toMatchInlineSnapshot(`
{
"exec": "bunx",
"execNoInstall": "bun run",
"install": "bun i",
}
`);
Expand All @@ -39,51 +43,56 @@ describe("getPackageManager", () => {
test("should use npm if no value provided and package-lock.json exists", () => {
expect(getPackageManager("", { workingDirectory: "test/npm" }))
.toMatchInlineSnapshot(`
{
"exec": "npx",
"install": "npm i",
}
`);
{
"exec": "npx",
"execNoInstall": "npx --no-install",
"install": "npm i",
}
`);
});

test("should use yarn if no value provided and yarn.lock exists", () => {
expect(getPackageManager("", { workingDirectory: "test/yarn" }))
.toMatchInlineSnapshot(`
{
"exec": "yarn",
"install": "yarn add",
}
`);
{
"exec": "yarn",
"execNoInstall": "yarn",
"install": "yarn add",
}
`);
});

test("should use pnpm if no value provided and pnpm-lock.yaml exists", () => {
expect(getPackageManager("", { workingDirectory: "test/pnpm" }))
.toMatchInlineSnapshot(`
{
"exec": "pnpm exec",
"install": "pnpm add",
}
`);
{
"exec": "pnpm exec",
"execNoInstall": "pnpm exec",
"install": "pnpm add",
}
`);
});

test("should use bun if no value provided and bun.lockb exists", () => {
expect(getPackageManager("", { workingDirectory: "test/bun" }))
.toMatchInlineSnapshot(`
{
"exec": "bunx",
"install": "bun i",
}
{
"exec": "bunx",
"execNoInstall": "bun run",
"install": "bun i",
}
`);
});

test("should use npm if no value provided and no lockfile is present", () => {
expect(getPackageManager("", { workingDirectory: "test/empty" }))
.toMatchInlineSnapshot(`
{
"exec": "npx",
"install": "npm i",
}
`);
{
"exec": "npx",
"execNoInstall": "npx --no-install",
"install": "npm i",
}
`);
});

test("should throw if an invalid value is provided", () => {
Expand Down
5 changes: 5 additions & 0 deletions src/packageManagers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@ import * as path from "node:path";
interface PackageManager {
install: string;
exec: string;
execNoInstall: string;
}

const PACKAGE_MANAGERS = {
npm: {
install: "npm i",
exec: "npx",
execNoInstall: "npx --no-install",
},
yarn: {
install: "yarn add",
exec: "yarn",
execNoInstall: "yarn",
},
pnpm: {
install: "pnpm add",
exec: "pnpm exec",
execNoInstall: "pnpm exec",
},
bun: {
install: "bun i",
exec: "bunx",
execNoInstall: "bun run",
},
} as const satisfies Readonly<Record<string, PackageManager>>;

Expand Down

0 comments on commit 66efca2

Please sign in to comment.