From 66efca2cbb82a5a49df6af2e14c4b58d53b0e266 Mon Sep 17 00:00:00 2001 From: Maximo Guk <62088388+Maximo-Guk@users.noreply.github.com> Date: Sat, 15 Jun 2024 23:22:47 -0500 Subject: [PATCH] Invoke wrangler to check if it's installed, but don't auto-install through npx/bunx --- .changeset/brown-spies-grab.md | 5 +++ package-lock.json | 4 +- src/index.ts | 3 +- src/packageManagers.test.ts | 67 +++++++++++++++++++--------------- src/packageManagers.ts | 5 +++ 5 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 .changeset/brown-spies-grab.md diff --git a/.changeset/brown-spies-grab.md b/.changeset/brown-spies-grab.md new file mode 100644 index 0000000..bfda189 --- /dev/null +++ b/.changeset/brown-spies-grab.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 480fe9d..908cf86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wrangler-action", - "version": "3.5.0", + "version": "3.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "wrangler-action", - "version": "3.5.0", + "version": "3.6.1", "license": "MIT OR Apache-2.0", "dependencies": { "@actions/core": "^1.10.1", diff --git a/src/index.ts b/src/index.ts index e864fff..3e2df44 100755 --- a/src/index.ts +++ b/src/index.ts @@ -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"], diff --git a/src/packageManagers.test.ts b/src/packageManagers.test.ts index 1653cb5..6a71fc5 100644 --- a/src/packageManagers.test.ts +++ b/src/packageManagers.test.ts @@ -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", } `); @@ -31,6 +34,7 @@ describe("getPackageManager", () => { .toMatchInlineSnapshot(` { "exec": "bunx", + "execNoInstall": "bun run", "install": "bun i", } `); @@ -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", () => { diff --git a/src/packageManagers.ts b/src/packageManagers.ts index 6eaaf12..4f19bae 100644 --- a/src/packageManagers.ts +++ b/src/packageManagers.ts @@ -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>;