Skip to content

Commit

Permalink
test pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
feychenie committed Jul 26, 2023
1 parent a584e03 commit a8b732d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ inputs:
command:
description: 'The Wrangler command you wish to run. For example: "publish" - this will publish your Worker'
required: false
packageManager:
description: 'The package manager you wish to use to install Wrangler (default: npm). Supported values: npm, yarn, pnpm, bun'
required: false
2 changes: 1 addition & 1 deletion compiled/index.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Easy-to-use GitHub Action to use [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/). Makes deploying Workers, Pages or modifying R2 easy to do.",
"type": "module",
"scripts": {
"build": "npx ncc build src/index.ts --v8-cache --minify --target es2023 --out compiled",
"build.types": "tsc --incremental",
"build.types:watch": "npm run build.types -- --watch"
},
Expand All @@ -23,6 +24,7 @@
"devDependencies": {
"@demosjarco/prettier-config": "^1.0.0",
"@types/node": "^16.18.38",
"@vercel/ncc": "^0.36.1",
"prettier": "^3.0.0",
"typescript": "^5.1.6"
}
Expand Down
28 changes: 25 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as core from '@actions/core';
import path from 'node:path';
import { exec, spawn } from 'node:child_process';

const packageManagers = ['npm', 'pnpm', 'yarn', 'bun'] as const;
type PackageManager = (typeof packageManagers)[number];

class Wrangler {
private API_CREDENTIALS: string = '';
private workingDirectory: string = this.setupWorkingDirectory(core.getInput('workingDirectory'));
Expand All @@ -16,7 +19,7 @@ class Wrangler {
private CLOUDFLARE_ACCOUNT_ID?: string;

public async main() {
await this.installWrangler(core.getInput('wranglerVersion'));
await this.installWrangler(core.getInput('wranglerVersion'), core.getInput('packageManager'));
this.authenticationSetup(core.getInput('apiToken'), core.getInput('apiKey'), core.getInput('email'), core.getInput('accountId'));
await this.execute_commands(core.getMultilineInput('preCommands'));
await this.putSecrets(core.getMultilineInput('secrets'), core.getInput('environment'));
Expand All @@ -37,7 +40,11 @@ class Wrangler {
return normalizedPath;
}

private installWrangler(INPUT_WRANGLERVERSION: string): Promise<void> {
// # npm i @types/node -D
// # yarn add @types/node -D
// # pnpm add -D @types/node
// # bun add -d @types/node
private installWrangler(INPUT_WRANGLERVERSION: string, INPUT_PACKAGE_MANAGER: string = 'npm'): Promise<void> {
let packageName = 'wrangler';
let versionToUse = '';

Expand All @@ -54,7 +61,22 @@ class Wrangler {
this.WRANGLER_VERSION = Number(INPUT_WRANGLERVERSION[0]);
}

const command = `npm install --save-dev ${packageName}${versionToUse}`;
const command = (() => {
const pm = INPUT_PACKAGE_MANAGER as PackageManager;
switch (pm) {
case 'npm':
return `npm i ${packageName}${versionToUse} -D`;
case 'yarn':
return `yarn add ${packageName}${versionToUse} -D`;
case 'pnpm':
return `pnpm add -D ${packageName}${versionToUse}`;
case 'bun':
return `bun add -d ${packageName}${versionToUse}`;
default:
const unsupportedPM: never = pm; // TS error if
throw `Unsupported package manager ${unsupportedPM}, pick one of ${packageManagers.join(', ')}.`;
}
})();
console.info(command);
return new Promise((resolve, reject) => {
exec(command, { cwd: this.workingDirectory, env: process.env }, (error, stdout, stderr) => {
Expand Down

0 comments on commit a8b732d

Please sign in to comment.