Skip to content

Commit 9de87c3

Browse files
committed
fix(cli): harden sea release assets
1 parent 4dd6a7c commit 9de87c3

4 files changed

Lines changed: 49 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"check": "vp check .",
3535
"coverage": "vp test --coverage",
3636
"dev": "vp pack --watch",
37-
"prepare": "./scripts/prepare-effect.sh",
37+
"prepare": "node ./scripts/prepare-effect.mts",
3838
"prepack": "vp pack",
3939
"smoke:pack": "node ./scripts/smoke-packed-install.mts",
4040
"test": "vp test",

scripts/prepare-effect.mts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { execFileSync } from "node:child_process";
2+
import { existsSync, mkdirSync } from "node:fs";
3+
4+
if (process.env.CI || process.env.GITHUB_ACTIONS) {
5+
process.exit(0);
6+
}
7+
8+
const repoDir = ".repos/effect";
9+
const repoUrl = "https://github.com/Effect-TS/effect-smol";
10+
11+
if (existsSync(`${repoDir}/.git`)) {
12+
process.exit(0);
13+
}
14+
15+
mkdirSync(".repos", { recursive: true });
16+
execFileSync("git", ["clone", repoUrl, repoDir], { stdio: "inherit" });

src/cli.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ describe("cli argv parsing", () => {
123123
expect(stdout).toBe(`putio v${packageJson.version}`);
124124
});
125125

126+
it("accepts SEA argv that repeats the CLI binary path", async () => {
127+
const { result, stdout } = await runProcessArgv([
128+
"/opt/putio/bin/putio",
129+
"/opt/putio/bin/putio",
130+
"--version",
131+
]);
132+
133+
expect(result._tag).toBe("Success");
134+
expect(stdout).toBe(`putio v${packageJson.version}`);
135+
});
136+
126137
it("renders describe as machine-readable json", async () => {
127138
const { result, stdout } = await runCli(["putio", "describe"]);
128139

src/cli.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,36 @@ const executableName = (value: string) => {
101101
return normalized.slice(normalized.lastIndexOf("/") + 1).toLowerCase();
102102
};
103103

104+
const isNodeExecutable = (value: string) => {
105+
const name = executableName(value);
106+
return name === "node" || name === "node.exe";
107+
};
108+
109+
const isPutioExecutable = (value: string) => {
110+
const name = executableName(value);
111+
return name === "putio" || name === "putio.exe" || name === "bin.mjs";
112+
};
113+
114+
const stripLeadingPutioExecutables = (args: ReadonlyArray<string>) => {
115+
let start = 0;
116+
while (isPutioExecutable(args[start] ?? "")) {
117+
start++;
118+
}
119+
return args.slice(start);
120+
};
121+
104122
const commandArgsFromArgv = (args: ReadonlyArray<string>) => {
105123
const [first] = args;
106124

107125
if (first === undefined) {
108126
return args;
109127
}
110128

111-
const firstName = executableName(first);
112-
113-
if (firstName === "node" || firstName === "node.exe") {
114-
return args.slice(2);
115-
}
116-
117-
if (firstName === "putio" || firstName === "putio.exe" || firstName === "bin.mjs") {
118-
return args.slice(1);
129+
if (isNodeExecutable(first)) {
130+
return stripLeadingPutioExecutables(args.slice(2));
119131
}
120132

121-
return args;
133+
return stripLeadingPutioExecutables(args);
122134
};
123135

124136
type CliCommandEnvironment =

0 commit comments

Comments
 (0)