Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(desktop): strip leading '--' so --publish reaches electron-builder (#1199)

LinYushenfe6208c61f65
diff --git a/apps/desktop/scripts/package.mjs b/apps/desktop/scripts/package.mjs
index 2f288ed3ca..f7a6e401b5 100644
--- a/apps/desktop/scripts/package.mjs
+++ b/apps/desktop/scripts/package.mjs
@@ -39,6 +39,18 @@ function sh(cmd) {
}
}
+/**
+ * Strip the leading `--` that npm/pnpm insert to separate their own
+ * flags from the ones meant for the underlying script. Without this,
+ * `pnpm package -- --mac --arm64 --publish always` forwards the bare
+ * `--` into electron-builder's argv, which terminates option parsing
+ * and turns `--publish always` into ignored positional arguments.
+ */
+export function stripLeadingSeparator(argv) {
+ if (argv.length > 0 && argv[0] === "--") return argv.slice(1);
+ return argv;
+}
+
/**
* Pure transformation from the `git describe --tags --always --dirty`
* output to the value we feed into electron-builder's extraMetadata.version.
@@ -102,7 +114,7 @@ function main() {
}
// Step 4: assemble electron-builder args.
- const passthrough = process.argv.slice(2);
+ const passthrough = stripLeadingSeparator(process.argv.slice(2));
const builderArgs = [];
if (version) builderArgs.push(`-c.extraMetadata.version=${version}`);
diff --git a/apps/desktop/scripts/package.test.mjs b/apps/desktop/scripts/package.test.mjs
index 9fc5e391f7..763b9663d9 100644
--- a/apps/desktop/scripts/package.test.mjs
+++ b/apps/desktop/scripts/package.test.mjs
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
-import { normalizeGitVersion } from "./package.mjs";
+import { normalizeGitVersion, stripLeadingSeparator } from "./package.mjs";
describe("normalizeGitVersion", () => {
it("returns null for empty / nullish input", () => {
@@ -37,3 +37,25 @@ describe("normalizeGitVersion", () => {
expect(normalizeGitVersion("abc1234")).toBe("0.0.0-abc1234");
});
});
+
+describe("stripLeadingSeparator", () => {
+ it("removes the leading -- inserted by npm/pnpm", () => {
+ expect(stripLeadingSeparator(["--", "--mac", "--arm64", "--publish", "always"])).toEqual([
+ "--mac", "--arm64", "--publish", "always",
+ ]);
+ });
+
+ it("leaves args untouched when there is no leading --", () => {
+ expect(stripLeadingSeparator(["--mac", "--arm64"])).toEqual(["--mac", "--arm64"]);
+ });
+
+ it("does not strip a -- that appears mid-argv", () => {
+ expect(stripLeadingSeparator(["--mac", "--", "--arm64"])).toEqual([
+ "--mac", "--", "--arm64",
+ ]);
+ });
+
+ it("handles an empty array", () => {
+ expect(stripLeadingSeparator([])).toEqual([]);
+ });
+});