Skip to content

Commit

Permalink
Merge pull request #8 from fryorcraken/pull-origin
Browse files Browse the repository at this point in the history
  • Loading branch information
fryorcraken authored Oct 31, 2022
2 parents d3044be + 9cbaa09 commit 5e77857
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ with:
directory: client/
```

### Customizing the Package Manager

By default, the action will attempt to autodetect which package manager to use, but in some cases
like those who are using a monorepo and the directory option, this may not detect the correct
manager. You can manually specify the package manager with the `package_manager` option.

```yaml
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: packages/client/
package_manager: yarn
```

## Feedback

Pull requests, feature ideas and bug reports are very welcome. We highly appreciate any feedback.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ inputs:
required: false
default: "npx size-limit --json"
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`."
runs:
using: 'node16'
main: 'dist/index.js'
23 changes: 15 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10430,13 +10430,19 @@ const exec_1 = __nccwpck_require__(1514);
const has_yarn_1 = __importDefault(__nccwpck_require__(3472));
const has_pnpm_1 = __importDefault(__nccwpck_require__(3974));
class Term {
execSizeLimit(script, buildScript, skipInstall, skipBuild, windowsVerbatimArguments, branch, cleanScript, directory) {
/**
* Autodetects and gets the current package manager for the current directory, either yarn, pnpm,
* or npm. Default is `npm`.
*
* @param directory The current directory
* @returns The detected package manager in use, one of `yarn`, `pnpm`, `npm`
*/
getPackageManager(directory) {
return (0, has_yarn_1.default)(directory) ? "yarn" : (0, has_pnpm_1.default)(directory) ? "pnpm" : "npm";
}
execSizeLimit(script, buildScript, skipInstall, skipBuild, windowsVerbatimArguments, branch, cleanScript, directory, packageManager) {
return __awaiter(this, void 0, void 0, function* () {
const manager = (0, has_yarn_1.default)(directory)
? "yarn"
: (0, has_pnpm_1.default)(directory)
? "pnpm"
: "npm";
const manager = packageManager || this.getPackageManager(directory);
let output = "";
if (branch) {
try {
Expand Down Expand Up @@ -10534,11 +10540,12 @@ function run() {
const cleanScript = (0, core_1.getInput)("clean_script");
const directory = (0, core_1.getInput)("directory") || process.cwd();
const windowsVerbatimArguments = (0, core_1.getInput)("windows_verbatim_arguments") === "true";
const packageManager = (0, core_1.getInput)("package_manager");
const octokit = (0, github_1.getOctokit)(token);
const term = new Term_1.default();
const limit = new SizeLimit_1.default();
const { status, output } = yield term.execSizeLimit(script, buildScript, skipInstall, skipBuild, windowsVerbatimArguments, null, cleanScript, directory);
const { output: baseOutput } = yield term.execSizeLimit(script, buildScript, skipInstall, skipBuild, windowsVerbatimArguments, pr.base.ref, cleanScript, directory);
const { status, output } = yield term.execSizeLimit(script, buildScript, skipInstall, skipBuild, windowsVerbatimArguments, null, cleanScript, directory, packageManager);
const { output: baseOutput } = yield term.execSizeLimit(script, buildScript, skipInstall, skipBuild, windowsVerbatimArguments, pr.base.ref, cleanScript, directory, packageManager);
let base;
let current;
try {
Expand Down
22 changes: 15 additions & 7 deletions src/Term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ import hasYarn from "has-yarn";
import hasPNPM from "has-pnpm";

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

async execSizeLimit(
script: string,
buildScript: string,
skipInstall: boolean,
skipBuild: boolean,
windowsVerbatimArguments: boolean,
windowsVerbatimArguments?: boolean,
branch?: string,
cleanScript?: string,
directory?: string
directory?: string,
packageManager?: string
): Promise<{ status: number; output: string }> {
const manager = hasYarn(directory)
? "yarn"
: hasPNPM(directory)
? "pnpm"
: "npm";
const manager = packageManager || this.getPackageManager(directory);
let output = "";

if (branch) {
Expand Down
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async function run() {
const directory = getInput("directory") || process.cwd();
const windowsVerbatimArguments =
getInput("windows_verbatim_arguments") === "true";
const packageManager = getInput("package_manager");

const octokit = getOctokit(token);
const term = new Term();
const limit = new SizeLimit();
Expand All @@ -55,7 +57,8 @@ async function run() {
windowsVerbatimArguments,
null,
cleanScript,
directory
directory,
packageManager
);
const { output: baseOutput } = await term.execSizeLimit(
script,
Expand All @@ -65,7 +68,8 @@ async function run() {
windowsVerbatimArguments,
pr.base.ref,
cleanScript,
directory
directory,
packageManager
);

let base;
Expand Down

0 comments on commit 5e77857

Please sign in to comment.