From cbe5f5b52361b3ea80dbd727cfcc8af4fc8840c4 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 04:27:58 +0900 Subject: [PATCH 01/15] Add detect package manager util function --- src/utils.test.ts | 31 +++++++++++++++++++++++++++-- src/utils.ts | 17 ++++++++++++++++ test/fixtures/empty/.gitkeep | 0 test/fixtures/npm/package-lock.json | 0 test/fixtures/pnpm/pnpm-lock.yaml | 0 test/fixtures/yarn/yarn.lock | 0 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/empty/.gitkeep create mode 100644 test/fixtures/npm/package-lock.json create mode 100644 test/fixtures/pnpm/pnpm-lock.yaml create mode 100644 test/fixtures/yarn/yarn.lock diff --git a/src/utils.test.ts b/src/utils.test.ts index cfe65cfd..6c2604ad 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -1,6 +1,11 @@ -import { expect, test, describe } from "vitest"; -import { checkWorkingDirectory, getNpxCmd, semverCompare } from "./utils"; import path from "node:path"; +import { describe, expect, test } from "vitest"; +import { + checkWorkingDirectory, + detectPackageManager, + getNpxCmd, + semverCompare, +} from "./utils"; test("getNpxCmd ", async () => { process.env.RUNNER_OS = "Windows"; @@ -43,3 +48,25 @@ describe("checkWorkingDirectory", () => { ); }); }); + +describe("detectPackageManager", () => { + test("should return name of package manager for current workspace", () => { + expect(detectPackageManager()).toBe("npm"); + }); + + test("should return npm if package-lock.json exists", () => { + expect(detectPackageManager("test/fixtures/npm")).toBe("npm"); + }); + + test("should return yarn if yarn.lock exists", () => { + expect(detectPackageManager("test/fixtures/yarn")).toBe("yarn"); + }); + + test("should return pnpm if pnpm-lock.yaml exists", () => { + expect(detectPackageManager("test/fixtures/pnpm")).toBe("pnpm"); + }); + + test("should return null if no package manager is detected", () => { + expect(detectPackageManager("test/fixtures/empty")).toBe(null); + }); +}); diff --git a/src/utils.ts b/src/utils.ts index ab6d0d28..4ce5de70 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -33,3 +33,20 @@ export function checkWorkingDirectory(workingDirectory = ".") { throw new Error(`Directory ${workingDirectory} does not exist.`); } } + +export type PackageManager = "npm" | "yarn" | "pnpm"; + +export function detectPackageManager( + workingDirectory = ".", +): PackageManager | null { + if (existsSync(path.join(workingDirectory, "package-lock.json"))) { + return "npm"; + } + if (existsSync(path.join(workingDirectory, "yarn.lock"))) { + return "yarn"; + } + if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) { + return "pnpm"; + } + return null; +} diff --git a/test/fixtures/empty/.gitkeep b/test/fixtures/empty/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/npm/package-lock.json b/test/fixtures/npm/package-lock.json new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/pnpm/pnpm-lock.yaml b/test/fixtures/pnpm/pnpm-lock.yaml new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/yarn/yarn.lock b/test/fixtures/yarn/yarn.lock new file mode 100644 index 00000000..e69de29b From f4f2e854d748523cd014f01f1aed2560dec3fa35 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 06:26:28 +0900 Subject: [PATCH 02/15] Add isValidPackcageManager() util --- src/utils.test.ts | 10 ++++++++++ src/utils.ts | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/utils.test.ts b/src/utils.test.ts index 6c2604ad..e7c8c9c4 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -4,6 +4,7 @@ import { checkWorkingDirectory, detectPackageManager, getNpxCmd, + isValidPackageManager, semverCompare, } from "./utils"; @@ -70,3 +71,12 @@ describe("detectPackageManager", () => { expect(detectPackageManager("test/fixtures/empty")).toBe(null); }); }); + +test("isValidPackageManager", () => { + expect(isValidPackageManager("npm")).toBe(true); + expect(isValidPackageManager("pnpm")).toBe(true); + expect(isValidPackageManager("yarn")).toBe(true); + + expect(isValidPackageManager("")).toBe(false); + expect(isValidPackageManager("ppnpm")).toBe(false); +}); diff --git a/src/utils.ts b/src/utils.ts index 4ce5de70..9ba5ab37 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -50,3 +50,7 @@ export function detectPackageManager( } return null; } + +export function isValidPackageManager(name: string): name is PackageManager { + return name === "npm" || name === "yarn" || name === "pnpm"; +} From f2e4cda4dd2fec98a3fd0c5404d283cb2d3b6877 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 06:33:25 +0900 Subject: [PATCH 03/15] Detect package manager and uses its commands Fix #156 --- src/index.ts | 68 +++++++++++++++++++++++------- test/base/package-lock.json | 10 +++++ test/environment/package-lock.json | 10 +++++ 3 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 test/base/package-lock.json create mode 100644 test/environment/package-lock.json diff --git a/src/index.ts b/src/index.ts index 927c727c..fd68e9ca 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,20 +1,45 @@ import { + getBooleanInput, getInput, getMultilineInput, - setFailed, - info as originalInfo, - error as originalError, endGroup as originalEndGroup, + error as originalError, + info as originalInfo, startGroup as originalStartGroup, - getBooleanInput, + setFailed, } from "@actions/core"; -import { execSync, exec } from "node:child_process"; -import { checkWorkingDirectory, getNpxCmd, semverCompare } from "./utils"; +import { exec, execSync } from "node:child_process"; import * as util from "node:util"; +import { + PackageManager, + checkWorkingDirectory, + detectPackageManager, + semverCompare, +} from "./utils"; const execAsync = util.promisify(exec); const DEFAULT_WRANGLER_VERSION = "3.5.1"; +interface PackageManagerCommands { + install: string; + exec: string; +} + +const PACKAGE_MANAGER_COMMANDS = { + npm: { + install: "npm i", + exec: "npm exec", + }, + yarn: { + install: "yarn add", + exec: "yarn exec", + }, + pnpm: { + install: "pnpm add", + exec: "pnpm exec", + }, +} as const satisfies Readonly>; + /** * A configuration object that contains all the inputs & immutable state for the action. */ @@ -30,6 +55,17 @@ const config = { QUIET_MODE: getBooleanInput("quiet"), } as const; +function realPackageManager(): PackageManager { + const packageManager = detectPackageManager(config.workingDirectory); + if (packageManager !== null) { + return packageManager; + } + + throw new Error("Package manager is not detected"); +} + +const pkgManagerCmd = PACKAGE_MANAGER_COMMANDS[realPackageManager()]; + function info(message: string, bypass?: boolean): void { if (!config.QUIET_MODE || bypass) { originalInfo(message); @@ -94,7 +130,7 @@ function installWrangler() { ); } startGroup("📥 Installing Wrangler"); - const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`; + const command = `${pkgManagerCmd.install} wrangler@${config["WRANGLER_VERSION"]}`; info(`Running command: ${command}`); execSync(command, { cwd: config["workingDirectory"], env: process.env }); info(`✅ Wrangler installed`, true); @@ -115,7 +151,7 @@ async function execCommands(commands: string[], cmdType: string) { try { const arrPromises = commands.map(async (command) => { const cmd = command.startsWith("wrangler") - ? `${getNpxCmd()} ${command}` + ? `${pkgManagerCmd.exec} ${command}` : command; info(`🚀 Executing command: ${cmd}`); @@ -155,9 +191,9 @@ async function legacyUploadSecrets( ) { const arrPromises = secrets .map((secret) => { - const command = `echo ${getSecret( - secret, - )} | ${getNpxCmd()} wrangler secret put ${secret}`; + const command = `echo ${getSecret(secret)} | ${ + pkgManagerCmd.exec + } wrangler secret put ${secret}`; return environment ? command.concat(` --env ${environment}`) : command; }) .map( @@ -198,7 +234,7 @@ async function uploadSecrets() { const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll( '"', '\\"', - )}" | ${getNpxCmd()} wrangler secret:bulk ${environmentSuffix}`; + )}" | ${pkgManagerCmd.exec} wrangler secret:bulk ${environmentSuffix}`; execSync(secretCmd, { cwd: workingDirectory, @@ -247,7 +283,7 @@ async function wranglerCommands() { command = command.concat(` --env ${environment}`); } - const cmd = `${getNpxCmd()} wrangler ${command} ${ + const cmd = `${pkgManagerCmd.exec} wrangler ${command} ${ (command.startsWith("deploy") || command.startsWith("publish")) && !command.includes(`--var`) ? getVarArgs() @@ -271,9 +307,9 @@ async function wranglerCommands() { main(); export { - wranglerCommands, - execCommands, - uploadSecrets, authenticationSetup, + execCommands, installWrangler, + uploadSecrets, + wranglerCommands, }; diff --git a/test/base/package-lock.json b/test/base/package-lock.json new file mode 100644 index 00000000..5a28ad0a --- /dev/null +++ b/test/base/package-lock.json @@ -0,0 +1,10 @@ +{ + "name": "wrangler-action-test", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "wrangler-action-test" + } + } +} diff --git a/test/environment/package-lock.json b/test/environment/package-lock.json new file mode 100644 index 00000000..62bfd8b2 --- /dev/null +++ b/test/environment/package-lock.json @@ -0,0 +1,10 @@ +{ + "name": "wrangler-action-environment-test", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "wrangler-action-environment-test" + } + } +} From a009342d77cfc031867fcd5bef2304798398780d Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 06:34:18 +0900 Subject: [PATCH 04/15] Add packageManager setting --- action.yml | 3 +++ src/index.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/action.yml b/action.yml index 7a6cfeea..b05fd454 100644 --- a/action.yml +++ b/action.yml @@ -41,3 +41,6 @@ inputs: vars: description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow." required: false + packageManager: + description: "The name of the package manager to install and run wrangler. If not provided, it will be detected via the lock file. Valid values: [npm, pnpm, yarn]" + required: false diff --git a/src/index.ts b/src/index.ts index fd68e9ca..68eced8e 100755 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,7 @@ import { PackageManager, checkWorkingDirectory, detectPackageManager, + isValidPackageManager, semverCompare, } from "./utils"; const execAsync = util.promisify(exec); @@ -53,9 +54,14 @@ const config = { VARS: getMultilineInput("vars"), COMMANDS: getMultilineInput("command"), QUIET_MODE: getBooleanInput("quiet"), + PACKAGE_MANAGER: getInput("packageManager"), } as const; function realPackageManager(): PackageManager { + if (isValidPackageManager(config.PACKAGE_MANAGER)) { + return config.PACKAGE_MANAGER; + } + const packageManager = detectPackageManager(config.workingDirectory); if (packageManager !== null) { return packageManager; From 868dbd9a405b11db2319d127efd2d13cfb8e6621 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 06:35:04 +0900 Subject: [PATCH 05/15] Remove unused function --- src/utils.test.ts | 14 -------------- src/utils.ts | 4 ---- 2 files changed, 18 deletions(-) diff --git a/src/utils.test.ts b/src/utils.test.ts index e7c8c9c4..812e2c89 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -3,24 +3,10 @@ import { describe, expect, test } from "vitest"; import { checkWorkingDirectory, detectPackageManager, - getNpxCmd, isValidPackageManager, semverCompare, } from "./utils"; -test("getNpxCmd ", async () => { - process.env.RUNNER_OS = "Windows"; - expect(getNpxCmd()).toBe("npx.cmd"); - - process.env.RUNNER_OS = "Mac"; - expect(getNpxCmd()).toBe("npx"); - - process.env.RUNNER_OS = "Linux"; - expect(getNpxCmd()).toBe("npx"); - - delete process.env.RUNNER_OS; -}); - describe("semverCompare", () => { test("should return false if the second argument is equal to the first argument", () => { const isVersion1LessThanVersion2 = semverCompare("1.2.3", "1.2.3"); diff --git a/src/utils.ts b/src/utils.ts index 9ba5ab37..c644425a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,10 +1,6 @@ import { existsSync } from "node:fs"; import * as path from "node:path"; -export function getNpxCmd() { - return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx"; -} - /** * A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true. */ From 11f981cea409de4e5055121cf8794b06053b48e6 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 06:43:35 +0900 Subject: [PATCH 06/15] Add tests for package managers support --- .github/workflows/deploy.yml | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2050e36b..b1ae2f84 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -111,4 +111,37 @@ jobs: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: delete --name wrangler-action-test --force - # END Setup and teardown of Workers w/ Secrets Tests + # END Setup and teardown of Workers w/ Secrets Tests + + - name: Support packageManager variable + uses: ./ + with: + workingDirectory: "./test/fixtures/empty" + packageManager: "npm" + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: deploy --dry-run + + - name: Support npm package manager + uses: ./ + with: + workingDirectory: "./test/fixtures/npm" + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: deploy --dry-run + + - name: Support yarn package manager + uses: ./ + with: + workingDirectory: "./test/fixtures/yarn" + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: deploy --dry-run + + - name: Support pnpm package manager + uses: ./ + with: + workingDirectory: "./test/fixtures/pnpm" + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: deploy --dry-run From 2375787b23d45760fba937cd2445612a60a6e8e8 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sat, 2 Sep 2023 06:49:03 +0900 Subject: [PATCH 07/15] Move test fixtures to parent directory --- .github/workflows/deploy.yml | 8 ++++---- src/utils.test.ts | 8 ++++---- test/empty/package.json | 3 +++ test/fixtures/empty/.gitkeep | 0 test/fixtures/npm/package-lock.json | 0 test/fixtures/pnpm/pnpm-lock.yaml | 0 test/fixtures/yarn/yarn.lock | 0 test/npm/package-lock.json | 10 ++++++++++ test/npm/package.json | 3 +++ test/pnpm/package.json | 3 +++ test/pnpm/pnpm-lock.yaml | 5 +++++ test/yarn/package.json | 3 +++ test/yarn/yarn.lock | 4 ++++ 13 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 test/empty/package.json delete mode 100644 test/fixtures/empty/.gitkeep delete mode 100644 test/fixtures/npm/package-lock.json delete mode 100644 test/fixtures/pnpm/pnpm-lock.yaml delete mode 100644 test/fixtures/yarn/yarn.lock create mode 100644 test/npm/package-lock.json create mode 100644 test/npm/package.json create mode 100644 test/pnpm/package.json create mode 100644 test/pnpm/pnpm-lock.yaml create mode 100644 test/yarn/package.json create mode 100644 test/yarn/yarn.lock diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b1ae2f84..0aa60bfd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -116,7 +116,7 @@ jobs: - name: Support packageManager variable uses: ./ with: - workingDirectory: "./test/fixtures/empty" + workingDirectory: "./test/empty" packageManager: "npm" apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} @@ -125,7 +125,7 @@ jobs: - name: Support npm package manager uses: ./ with: - workingDirectory: "./test/fixtures/npm" + workingDirectory: "./test/npm" apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: deploy --dry-run @@ -133,7 +133,7 @@ jobs: - name: Support yarn package manager uses: ./ with: - workingDirectory: "./test/fixtures/yarn" + workingDirectory: "./test/yarn" apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: deploy --dry-run @@ -141,7 +141,7 @@ jobs: - name: Support pnpm package manager uses: ./ with: - workingDirectory: "./test/fixtures/pnpm" + workingDirectory: "./test/pnpm" apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: deploy --dry-run diff --git a/src/utils.test.ts b/src/utils.test.ts index 812e2c89..e02c84d5 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -42,19 +42,19 @@ describe("detectPackageManager", () => { }); test("should return npm if package-lock.json exists", () => { - expect(detectPackageManager("test/fixtures/npm")).toBe("npm"); + expect(detectPackageManager("test/npm")).toBe("npm"); }); test("should return yarn if yarn.lock exists", () => { - expect(detectPackageManager("test/fixtures/yarn")).toBe("yarn"); + expect(detectPackageManager("test/yarn")).toBe("yarn"); }); test("should return pnpm if pnpm-lock.yaml exists", () => { - expect(detectPackageManager("test/fixtures/pnpm")).toBe("pnpm"); + expect(detectPackageManager("test/pnpm")).toBe("pnpm"); }); test("should return null if no package manager is detected", () => { - expect(detectPackageManager("test/fixtures/empty")).toBe(null); + expect(detectPackageManager("test/empty")).toBe(null); }); }); diff --git a/test/empty/package.json b/test/empty/package.json new file mode 100644 index 00000000..b9137722 --- /dev/null +++ b/test/empty/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-detect-package-manager-test" +} diff --git a/test/fixtures/empty/.gitkeep b/test/fixtures/empty/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/npm/package-lock.json b/test/fixtures/npm/package-lock.json deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/pnpm/pnpm-lock.yaml b/test/fixtures/pnpm/pnpm-lock.yaml deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/yarn/yarn.lock b/test/fixtures/yarn/yarn.lock deleted file mode 100644 index e69de29b..00000000 diff --git a/test/npm/package-lock.json b/test/npm/package-lock.json new file mode 100644 index 00000000..d7687e49 --- /dev/null +++ b/test/npm/package-lock.json @@ -0,0 +1,10 @@ +{ + "name": "wrangler-action-npm-test", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "wrangler-action-npm-test" + } + } +} diff --git a/test/npm/package.json b/test/npm/package.json new file mode 100644 index 00000000..85a46478 --- /dev/null +++ b/test/npm/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-npm-test" +} diff --git a/test/pnpm/package.json b/test/pnpm/package.json new file mode 100644 index 00000000..4c2f9150 --- /dev/null +++ b/test/pnpm/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-pnpm-test" +} diff --git a/test/pnpm/pnpm-lock.yaml b/test/pnpm/pnpm-lock.yaml new file mode 100644 index 00000000..2b9f1883 --- /dev/null +++ b/test/pnpm/pnpm-lock.yaml @@ -0,0 +1,5 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false diff --git a/test/yarn/package.json b/test/yarn/package.json new file mode 100644 index 00000000..f10de0aa --- /dev/null +++ b/test/yarn/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-yarn-test" +} diff --git a/test/yarn/yarn.lock b/test/yarn/yarn.lock new file mode 100644 index 00000000..fb57ccd1 --- /dev/null +++ b/test/yarn/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + From c3b99e2c1867390665a0451c8692178ba3c7889d Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Wed, 13 Sep 2023 08:26:05 +0900 Subject: [PATCH 08/15] Ignore to pnpm-lock.yaml in formatting --- .prettierignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..bd5535a6 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +pnpm-lock.yaml From d1073d57bac21e1b0b5b270b72b8d1f8f8848250 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Wed, 13 Sep 2023 08:27:33 +0900 Subject: [PATCH 09/15] Run format --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b05fd454..e9e9b1da 100644 --- a/action.yml +++ b/action.yml @@ -43,4 +43,4 @@ inputs: required: false packageManager: description: "The name of the package manager to install and run wrangler. If not provided, it will be detected via the lock file. Valid values: [npm, pnpm, yarn]" - required: false + required: false From 7d7b98826e14e9ad422870a7263b7074b40bf16f Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Tue, 19 Sep 2023 01:27:00 +0900 Subject: [PATCH 10/15] Add changeset --- .changeset/two-rocks-hope.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/two-rocks-hope.md diff --git a/.changeset/two-rocks-hope.md b/.changeset/two-rocks-hope.md new file mode 100644 index 00000000..44fa9c00 --- /dev/null +++ b/.changeset/two-rocks-hope.md @@ -0,0 +1,5 @@ +--- +"wrangler-action": minor +--- + +Support for package managers other than npm, such as pnpm and yarn. Maybe fix #156 From 4ae0557f8d0b99c786f6a9371e61c967933e108a Mon Sep 17 00:00:00 2001 From: Jacob M-G Evans <27247160+JacobMGEvans@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:33:50 -0500 Subject: [PATCH 11/15] Update two-rocks-hope.md --- .changeset/two-rocks-hope.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.changeset/two-rocks-hope.md b/.changeset/two-rocks-hope.md index 44fa9c00..8b24cfff 100644 --- a/.changeset/two-rocks-hope.md +++ b/.changeset/two-rocks-hope.md @@ -2,4 +2,6 @@ "wrangler-action": minor --- -Support for package managers other than npm, such as pnpm and yarn. Maybe fix #156 +Support for package managers other than npm, such as pnpm and yarn. + +fixes #156 From 677167581516bef506eb83df0066cb58b2282115 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Tue, 19 Sep 2023 01:37:01 +0900 Subject: [PATCH 12/15] Run format --- .changeset/two-rocks-hope.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/two-rocks-hope.md b/.changeset/two-rocks-hope.md index 8b24cfff..e3c8d01b 100644 --- a/.changeset/two-rocks-hope.md +++ b/.changeset/two-rocks-hope.md @@ -2,6 +2,6 @@ "wrangler-action": minor --- -Support for package managers other than npm, such as pnpm and yarn. +Support for package managers other than npm, such as pnpm and yarn. fixes #156 From 50b529e7b821032018c05963d7c33d53665aa584 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Tue, 19 Sep 2023 03:50:54 +0900 Subject: [PATCH 13/15] Fix pass arg issue --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 68eced8e..251a594e 100755 --- a/src/index.ts +++ b/src/index.ts @@ -29,11 +29,11 @@ interface PackageManagerCommands { const PACKAGE_MANAGER_COMMANDS = { npm: { install: "npm i", - exec: "npm exec", + exec: "npx", }, yarn: { install: "yarn add", - exec: "yarn exec", + exec: "yarn", }, pnpm: { install: "pnpm add", From f0cc3efccfc8303fa8b610c8359766170a9e61af Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Tue, 19 Sep 2023 03:51:27 +0900 Subject: [PATCH 14/15] Install yarn and pnpm on test --- .github/workflows/deploy.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0aa60bfd..cdabf991 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -130,6 +130,9 @@ jobs: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: deploy --dry-run + - name: Install yarn + run: npm i -g yarn + - name: Support yarn package manager uses: ./ with: @@ -138,6 +141,9 @@ jobs: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: deploy --dry-run + - name: Install pnpm + run: npm i -g pnpm + - name: Support pnpm package manager uses: ./ with: From aec73ae744363c09555ef0325adf0132c34496c7 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Tue, 19 Sep 2023 03:52:00 +0900 Subject: [PATCH 15/15] Add wangler files in fixtures --- test/empty/index.ts | 1 + test/empty/wrangler.toml | 4 ++++ test/npm/index.ts | 26 ++++++++++++++++++++++++++ test/npm/wrangler.toml | 4 ++++ test/pnpm/index.ts | 26 ++++++++++++++++++++++++++ test/pnpm/wrangler.toml | 4 ++++ test/yarn/index.ts | 26 ++++++++++++++++++++++++++ test/yarn/wrangler.toml | 4 ++++ 8 files changed, 95 insertions(+) create mode 100644 test/empty/index.ts create mode 100644 test/empty/wrangler.toml create mode 100644 test/npm/index.ts create mode 100644 test/npm/wrangler.toml create mode 100644 test/pnpm/index.ts create mode 100644 test/pnpm/wrangler.toml create mode 100644 test/yarn/index.ts create mode 100644 test/yarn/wrangler.toml diff --git a/test/empty/index.ts b/test/empty/index.ts new file mode 100644 index 00000000..ff8b4c56 --- /dev/null +++ b/test/empty/index.ts @@ -0,0 +1 @@ +export default {}; diff --git a/test/empty/wrangler.toml b/test/empty/wrangler.toml new file mode 100644 index 00000000..4c09785b --- /dev/null +++ b/test/empty/wrangler.toml @@ -0,0 +1,4 @@ +name = "wrangler-action-test" +main = "./index.ts" +compatibility_date = "2023-07-07" +workers_dev = true diff --git a/test/npm/index.ts b/test/npm/index.ts new file mode 100644 index 00000000..a3305575 --- /dev/null +++ b/test/npm/index.ts @@ -0,0 +1,26 @@ +type Env = { + SECRET1?: string; + SECRET2?: string; +}; + +export default { + fetch(request: Request, env: Env) { + const url = new URL(request.url); + + if (url.pathname === "/secret-health-check") { + const { SECRET1, SECRET2 } = env; + + if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") { + throw new Error("SECRET1 or SECRET2 is not defined"); + } + + return new Response("OK"); + } + + // @ts-expect-error + return Response.json({ + ...request, + headers: Object.fromEntries(request.headers), + }); + }, +}; diff --git a/test/npm/wrangler.toml b/test/npm/wrangler.toml new file mode 100644 index 00000000..4c09785b --- /dev/null +++ b/test/npm/wrangler.toml @@ -0,0 +1,4 @@ +name = "wrangler-action-test" +main = "./index.ts" +compatibility_date = "2023-07-07" +workers_dev = true diff --git a/test/pnpm/index.ts b/test/pnpm/index.ts new file mode 100644 index 00000000..a3305575 --- /dev/null +++ b/test/pnpm/index.ts @@ -0,0 +1,26 @@ +type Env = { + SECRET1?: string; + SECRET2?: string; +}; + +export default { + fetch(request: Request, env: Env) { + const url = new URL(request.url); + + if (url.pathname === "/secret-health-check") { + const { SECRET1, SECRET2 } = env; + + if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") { + throw new Error("SECRET1 or SECRET2 is not defined"); + } + + return new Response("OK"); + } + + // @ts-expect-error + return Response.json({ + ...request, + headers: Object.fromEntries(request.headers), + }); + }, +}; diff --git a/test/pnpm/wrangler.toml b/test/pnpm/wrangler.toml new file mode 100644 index 00000000..4c09785b --- /dev/null +++ b/test/pnpm/wrangler.toml @@ -0,0 +1,4 @@ +name = "wrangler-action-test" +main = "./index.ts" +compatibility_date = "2023-07-07" +workers_dev = true diff --git a/test/yarn/index.ts b/test/yarn/index.ts new file mode 100644 index 00000000..a3305575 --- /dev/null +++ b/test/yarn/index.ts @@ -0,0 +1,26 @@ +type Env = { + SECRET1?: string; + SECRET2?: string; +}; + +export default { + fetch(request: Request, env: Env) { + const url = new URL(request.url); + + if (url.pathname === "/secret-health-check") { + const { SECRET1, SECRET2 } = env; + + if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") { + throw new Error("SECRET1 or SECRET2 is not defined"); + } + + return new Response("OK"); + } + + // @ts-expect-error + return Response.json({ + ...request, + headers: Object.fromEntries(request.headers), + }); + }, +}; diff --git a/test/yarn/wrangler.toml b/test/yarn/wrangler.toml new file mode 100644 index 00000000..4c09785b --- /dev/null +++ b/test/yarn/wrangler.toml @@ -0,0 +1,4 @@ +name = "wrangler-action-test" +main = "./index.ts" +compatibility_date = "2023-07-07" +workers_dev = true