Skip to content

Commit

Permalink
feat: added bun to package managers (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams authored Nov 2, 2023
1 parent f338c35 commit 35ea3c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ inputs:
description: "The script used to generate size-limit results"
package_manager:
required: false
description: "The package manager used to run the build and install commands. If not provided, the manager will be auto detected. Example values: `yarn`, `npm`, `pnpm`."
description: "The package manager used to run the build and install commands. If not provided, the manager will be auto detected. Example values: `yarn`, `npm`, `pnpm`, `bun`."
runs:
using: 'node20'
main: 'dist/index.js'
14 changes: 11 additions & 3 deletions src/Term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@ import { exec } from "@actions/exec";
import hasYarn from "has-yarn";
import hasPNPM from "has-pnpm";

import process from 'node:process';
import path from 'node:path';
import fs from 'node:fs';

function hasBun(cwd = process.cwd()) {
return fs.existsSync(path.resolve(cwd, 'bun.lockb'));
}

const INSTALL_STEP = "install";
const BUILD_STEP = "build";

class Term {
/**
* Autodetects and gets the current package manager for the current directory, either yarn, pnpm,
* Autodetects and gets the current package manager for the current directory, either yarn, pnpm, bun,
* or npm. Default is `npm`.
*
* @param directory The current directory
* @returns The detected package manager in use, one of `yarn`, `pnpm`, `npm`
* @returns The detected package manager in use, one of `yarn`, `pnpm`, `npm`, `bun`
*/
getPackageManager(directory?: string): string {
return hasYarn(directory) ? "yarn" : hasPNPM(directory) ? "pnpm" : "npm";
return hasYarn(directory) ? "yarn" : hasPNPM(directory) ? "pnpm" : hasBun(directory) ? "bun" : "npm";
}

async execSizeLimit(
Expand Down

0 comments on commit 35ea3c7

Please sign in to comment.