Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PNPM & monorepo #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ You can configure the action further with the following options:
- `build_script_name`: Name of the optional NPM build script which is executed before `electron-builder` (default: `"build"`)
- `skip_build`: Whether the action should execute the NPM build script before running `electron-builder`
- `use_vue_cli`: Whether to run `electron-builder` using the [Vue CLI plugin](https://nklayman.github.io/vue-cli-plugin-electron-builder) instead of calling the command directly
- `is_monorepo`: Whether the package is in a monorepo (will look for lockfiles in parent directories)
- `args`: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides (default: `""`)
- `max_attempts`: Maximum number of attempts for completing the build and release step (default: `1`)

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ inputs:
description: Whether to run `electron-builder` using the Vue CLI plugin instead of calling the command directly
required: false
default: false
is_monorepo:
description: Whether the package is in a monorepo (will look for lockfiles in parent directories)
required: false
default: false
args:
description: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides
required: false
Expand Down
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const runAction = () => {
const buildScriptName = getInput("build_script_name", true);
const skipBuild = getInput("skip_build") === "true";
const useVueCli = getInput("use_vue_cli") === "true";
const isMonorepo = getInput("is_monorepo") === "true";
const args = getInput("args") || "";
const maxAttempts = Number(getInput("max_attempts") || "1");

Expand All @@ -78,11 +79,14 @@ const runAction = () => {
const appRoot = getInput("app_root") || pkgRoot;

const pkgJsonPath = join(pkgRoot, "package.json");
const pkgLockPath = join(pkgRoot, "package-lock.json");
const pkgLockPath = join(pkgRoot, `${isMonorepo ? "../../" : ""}package-lock.json`);
const pnpmLockPath = join(pkgRoot, `${isMonorepo ? "../../" : ""}pnpm-lock.yaml`)

// Determine whether NPM should be used to run commands (instead of Yarn, which is the default)
// Determine whether NPM or PNPM should be used to run commands (instead of Yarn, which is the default)
const useNpm = existsSync(pkgLockPath);
log(`Will run ${useNpm ? "NPM" : "Yarn"} commands in directory "${pkgRoot}"`);
const usePnpm = existsSync(pnpmLockPath);
const scriptRunner = useNpm ? "npm" : usePnpm ? "pnpm" : "yarn"
log(`Will run ${scriptRunner} commands in directory "${pkgRoot}"`);

// Make sure `package.json` file exists
if (!existsSync(pkgJsonPath)) {
Expand All @@ -105,8 +109,8 @@ const runAction = () => {
// Disable console advertisements during install phase
setEnv("ADBLOCK", true);

log(`Installing dependencies using ${useNpm ? "NPM" : "Yarn"}…`);
run(useNpm ? "npm install" : "yarn", pkgRoot);
log(`Installing dependencies using ${scriptRunner}…`);
run(`${scriptRunner} install`, pkgRoot);

// Run NPM build script if it exists
if (skipBuild) {
Expand All @@ -115,6 +119,8 @@ const runAction = () => {
log("Running the build script…");
if (useNpm) {
run(`npm run ${buildScriptName} --if-present`, pkgRoot);
} else if (usePnpm) {
run(`pnpm run --if-present ${buildScriptName}`, pkgRoot);
} else {
// TODO: Use `yarn run ${buildScriptName} --if-present` once supported
// https://github.com/yarnpkg/yarn/issues/6894
Expand All @@ -130,7 +136,7 @@ const runAction = () => {
for (let i = 0; i < maxAttempts; i += 1) {
try {
run(
`${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${
`${useNpm ? "npx --no-install" : usePnpm ? "pnpm exec" : "yarn run"} ${cmd} --${platform} ${
release ? "--publish always" : ""
} ${args}`,
appRoot,
Expand Down