Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/fix-self-contained-cli-bundles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@khaale/gitlab-cli": patch
"@khaale/kaiten-cli": patch
"@khaale/postgres-cli": patch
---

Fix self-contained CLI bundles so CommonJS dependencies load correctly in Node.js.
2 changes: 1 addition & 1 deletion packages/gitlab-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:pack": "node ../../scripts/build-self-contained-cli.mjs packages/gitlab-cli glc",
"lint": "node --check ./bin/glc.js && node --check ./src/cli.js",
"test": "node --test test/*.test.js",
"pack:check": "pnpm build:pack && npm pack --dry-run --cache ./.npm-cache",
"pack:check": "pnpm build:pack && node ../../scripts/test-self-contained-cli.mjs packages/gitlab-cli glc && npm pack --dry-run --cache ./.npm-cache",
"prepublishOnly": "pnpm lint && pnpm test && pnpm pack:check"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kaiten-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build:pack": "node ../../scripts/build-self-contained-cli.mjs packages/kaiten-cli ktc",
"lint": "node --check ./bin/ktc.js && node --check ./src/cli.js",
"test": "node --test test/*.test.js",
"pack:check": "pnpm build:pack && npm pack --dry-run --cache ./.npm-cache",
"pack:check": "pnpm build:pack && node ../../scripts/test-self-contained-cli.mjs packages/kaiten-cli ktc && npm pack --dry-run --cache ./.npm-cache",
"prepublishOnly": "pnpm lint && pnpm test && pnpm pack:check"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/postgres-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:pack": "node ../../scripts/build-self-contained-cli.mjs packages/postgres-cli pgc",
"lint": "node --check ./bin/pgc.js && node --check ./src/cli.js",
"test": "node --test test/*.test.js",
"pack:check": "pnpm build:pack && npm pack --dry-run --cache ./.npm-cache",
"pack:check": "pnpm build:pack && node ../../scripts/test-self-contained-cli.mjs packages/postgres-cli pgc && npm pack --dry-run --cache ./.npm-cache",
"prepublishOnly": "pnpm lint && pnpm test && pnpm pack:check"
},
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions scripts/build-self-contained-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ await build({
platform: "node",
target: "node22",
packages: "bundle",
banner: {
js: "import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);"
},
logLevel: "silent"
});

Expand Down
45 changes: 45 additions & 0 deletions scripts/test-self-contained-cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { spawn } from "node:child_process";
import path from "node:path";
import { fileURLToPath } from "node:url";

const [, , packageDirArg, binNameArg] = process.argv;

if (!packageDirArg || !binNameArg) {
console.error("usage: node scripts/test-self-contained-cli.mjs <package-dir> <bin-name>");
process.exit(1);
}

const scriptDir = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(scriptDir, "..");
const binPath = path.join(repoRoot, packageDirArg, "dist", "bin", `${binNameArg}.js`);

const result = await run(binPath, ["--help"]);
if (result.code !== 0 || !result.stdout.includes(binNameArg)) {
console.error(`self-contained ${binNameArg} smoke test failed`);
if (result.stdout) {
console.error(`stdout:\n${result.stdout}`);
}
if (result.stderr) {
console.error(`stderr:\n${result.stderr}`);
}
process.exit(1);
}

function run(command, args) {
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, [command, ...args], {
stdio: ["ignore", "pipe", "pipe"]
});
let stdout = "";
let stderr = "";

child.stdout.on("data", (chunk) => {
stdout += chunk;
});
child.stderr.on("data", (chunk) => {
stderr += chunk;
});
child.on("error", reject);
child.on("close", (code, signal) => resolve({ code: code ?? 1, signal, stdout, stderr }));
});
}
Loading