Skip to content

Commit fe6208c

Browse files
ldnvnblCopilot
andauthored
fix(desktop): strip leading '--' so --publish reaches electron-builder (#1199)
When invoked as `pnpm package -- --mac --arm64 --publish always`, the bare `--` separator that pnpm inserts was forwarded into electron-builder's argv. This terminated option parsing, causing `--publish always` to be treated as positional arguments instead of a named flag. As a result electron-builder built locally but never uploaded artifacts to the GitHub Release (isPublish: false). Add `stripLeadingSeparator()` to remove the leading `--` before passing args through. Includes unit tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 336f90f commit fe6208c

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

apps/desktop/scripts/package.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ function sh(cmd) {
3939
}
4040
}
4141

42+
/**
43+
* Strip the leading `--` that npm/pnpm insert to separate their own
44+
* flags from the ones meant for the underlying script. Without this,
45+
* `pnpm package -- --mac --arm64 --publish always` forwards the bare
46+
* `--` into electron-builder's argv, which terminates option parsing
47+
* and turns `--publish always` into ignored positional arguments.
48+
*/
49+
export function stripLeadingSeparator(argv) {
50+
if (argv.length > 0 && argv[0] === "--") return argv.slice(1);
51+
return argv;
52+
}
53+
4254
/**
4355
* Pure transformation from the `git describe --tags --always --dirty`
4456
* output to the value we feed into electron-builder's extraMetadata.version.
@@ -102,7 +114,7 @@ function main() {
102114
}
103115

104116
// Step 4: assemble electron-builder args.
105-
const passthrough = process.argv.slice(2);
117+
const passthrough = stripLeadingSeparator(process.argv.slice(2));
106118
const builderArgs = [];
107119
if (version) builderArgs.push(`-c.extraMetadata.version=${version}`);
108120

apps/desktop/scripts/package.test.mjs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import { normalizeGitVersion } from "./package.mjs";
2+
import { normalizeGitVersion, stripLeadingSeparator } from "./package.mjs";
33

44
describe("normalizeGitVersion", () => {
55
it("returns null for empty / nullish input", () => {
@@ -37,3 +37,25 @@ describe("normalizeGitVersion", () => {
3737
expect(normalizeGitVersion("abc1234")).toBe("0.0.0-abc1234");
3838
});
3939
});
40+
41+
describe("stripLeadingSeparator", () => {
42+
it("removes the leading -- inserted by npm/pnpm", () => {
43+
expect(stripLeadingSeparator(["--", "--mac", "--arm64", "--publish", "always"])).toEqual([
44+
"--mac", "--arm64", "--publish", "always",
45+
]);
46+
});
47+
48+
it("leaves args untouched when there is no leading --", () => {
49+
expect(stripLeadingSeparator(["--mac", "--arm64"])).toEqual(["--mac", "--arm64"]);
50+
});
51+
52+
it("does not strip a -- that appears mid-argv", () => {
53+
expect(stripLeadingSeparator(["--mac", "--", "--arm64"])).toEqual([
54+
"--mac", "--", "--arm64",
55+
]);
56+
});
57+
58+
it("handles an empty array", () => {
59+
expect(stripLeadingSeparator([])).toEqual([]);
60+
});
61+
});

0 commit comments

Comments
 (0)