Skip to content

Commit e17eece

Browse files
authored
Merge pull request #49 from echohello-dev/codex/issue-21-npm-npx-bunx
feat(release): add npm package flow for npx and bunx
2 parents 701c660 + 9e1a319 commit e17eece

7 files changed

Lines changed: 95 additions & 5 deletions

File tree

‎.mise.toml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ run = "mise run install && bun scripts/render-winget-manifest.ts"
2727

2828
[tasks.docker-smoke]
2929
run = "mise run build -- --targets=linux-x64-musl,linux-arm64-musl && docker build --platform=linux/amd64 -t skillet:local . && docker run --rm --platform=linux/amd64 skillet:local --help"
30+
31+
[tasks.build-npm]
32+
run = "mise run install && bun scripts/build-npm-cli.ts"
33+
34+
[tasks.npm-smoke]
35+
run = "mise run build-npm && npm pack >/tmp/skillet-npm-pack.log && PACKAGE=$(tail -n 1 /tmp/skillet-npm-pack.log) && npx --yes --package \"./$PACKAGE\" skillet --help && REPO_DIR=\"$PWD\" && TMP_DIR=$(mktemp -d) && (cd \"$TMP_DIR\" && bun init -y >/dev/null 2>&1 && bun add \"$REPO_DIR/$PACKAGE\" >/dev/null && bunx --bun skillet --help) && rm -rf \"$TMP_DIR\" \"$PACKAGE\""

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Skillet installs, discovers, and updates `SKILL.md`-based skills across supporte
1212
| Homebrew | `brew install skillet` | Configured |
1313
| Chocolatey | `choco install skillet` | Configured |
1414
| winget | `winget install skillet` | Configured |
15-
| npm / npx | `npx skillet ...` | Planned |
15+
| npm / npx | `npx skillet ...` | Configured |
1616
| Docker | `docker run ... skillet ...` | Configured |
1717
| Local dev | `mise run dev -- --help` | Available |
1818

@@ -145,3 +145,4 @@ Distribution docs:
145145
- Chocolatey: `docs/distribution/chocolatey.md`
146146
- winget: `docs/distribution/winget.md`
147147
- Docker: `docs/distribution/docker.md`
148+
- npm: `docs/distribution/npm.md`

‎docs/distribution/npm.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# npm Distribution
2+
3+
Skillet publishes an npm package so users can run:
4+
5+
- `npx skillet ...`
6+
- `bunx skillet ...`
7+
8+
## Packaging Model
9+
10+
- `src/cli.ts` is bundled to `dist/npm/cli.js` targeting Node.
11+
- `package.json` `bin.skillet` points to `dist/npm/cli.js`.
12+
- `prepack` rebuilds the npm CLI bundle automatically.
13+
14+
## Local Validation
15+
16+
```bash
17+
mise run build-npm
18+
npm pack
19+
npx --yes --package ./skillet-<version>.tgz skillet --help
20+
bunx --bun --package ./skillet-<version>.tgz skillet --help
21+
```
22+
23+
## Publish
24+
25+
```bash
26+
npm publish --access public
27+
```

‎package.json‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
{
22
"name": "skillet",
33
"version": "0.0.0",
4-
"private": true,
4+
"private": false,
55
"type": "module",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"files": [
10+
"dist/npm",
11+
"README.md"
12+
],
613
"bin": {
7-
"skillet": "src/cli.ts"
14+
"skillet": "dist/npm/cli.js"
815
},
916
"scripts": {
1017
"dev": "bun src/cli.ts",
1118
"test": "vitest run",
1219
"build": "bun scripts/build-release.ts",
20+
"build:npm": "bun scripts/build-npm-cli.ts",
1321
"render:homebrew": "bun scripts/render-homebrew-formula.ts",
1422
"render:choco": "bun scripts/render-chocolatey-package.ts",
1523
"render:winget": "bun scripts/render-winget-manifest.ts",
16-
"docker:smoke": "mise run docker-smoke"
24+
"docker:smoke": "mise run docker-smoke",
25+
"prepack": "bun scripts/build-npm-cli.ts"
1726
},
1827
"dependencies": {
1928
"cac": "^6.7.14",

‎scripts/build-npm-cli.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import { execFileSync } from "node:child_process";
4+
5+
function main(): void {
6+
const repoRoot = process.cwd();
7+
const outputPath = path.join(repoRoot, "dist", "npm", "cli.js");
8+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
9+
10+
execFileSync(
11+
"bun",
12+
["build", "src/cli.ts", "--bundle", "--target=node", `--outfile=${outputPath}`],
13+
{ cwd: repoRoot, stdio: ["ignore", "inherit", "inherit"] },
14+
);
15+
16+
const output = fs.readFileSync(outputPath, "utf8");
17+
if (!output.startsWith("#!/usr/bin/env node")) {
18+
fs.writeFileSync(outputPath, `#!/usr/bin/env node\n${output}`);
19+
}
20+
21+
fs.chmodSync(outputPath, 0o755);
22+
console.log(`Wrote npm CLI bundle to ${outputPath}`);
23+
}
24+
25+
main();

‎src/cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bun
1+
#!/usr/bin/env node
22
import { cac } from "cac";
33
import { BUILD_INFO, buildMetadataString } from "./build-info";
44
import { runAddCommand } from "./commands/add";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { execFileSync, spawnSync } from "node:child_process";
2+
import path from "node:path";
3+
import { describe, expect, it } from "vitest";
4+
5+
describe("npm package bundle", () => {
6+
it("builds a node-compatible cli bundle", () => {
7+
execFileSync("bun", ["scripts/build-npm-cli.ts"], {
8+
cwd: process.cwd(),
9+
stdio: ["ignore", "pipe", "pipe"],
10+
});
11+
12+
const bundledCli = path.resolve(process.cwd(), "dist/npm/cli.js");
13+
const result = spawnSync("node", [bundledCli, "--help"], {
14+
cwd: process.cwd(),
15+
encoding: "utf8",
16+
});
17+
18+
expect(result.status).toBe(0);
19+
expect(result.stdout).toContain("Usage:");
20+
expect(result.stdout).toContain("$ skillet <command> [options]");
21+
});
22+
});

0 commit comments

Comments
 (0)