Skip to content

Commit 29b119e

Browse files
Fix npm CLI package: use Node.js launcher shim instead of postinstall
The bin/lightshell file is now a Node.js shim that finds and executes the platform-specific binary at runtime (like esbuild). This replaces the broken postinstall approach where the binary wasn't included in the published package. Also updates README with scoped package names.
1 parent 3887169 commit 29b119e

4 files changed

Lines changed: 61 additions & 56 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ Build desktop apps with JavaScript. Ship them under 5MB.
77
## Quick Start
88

99
```bash
10-
npm create lightshell@latest my-app
10+
npx @lightshell/create my-app
11+
cd my-app
12+
npx @lightshell/cli dev
13+
```
14+
15+
Or install globally:
16+
17+
```bash
18+
npm install -g @lightshell/cli
19+
lightshell init my-app
1120
cd my-app
1221
lightshell dev
1322
```

npm/lightshell/bin/lightshell

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
// This shim finds the platform-specific binary and executes it.
4+
// The actual binary lives in @lightshell/{platform} optional dependency.
5+
6+
const { platform, arch } = process;
7+
const { execFileSync } = require("child_process");
8+
const path = require("path");
9+
10+
const platformMap = { darwin: "darwin", linux: "linux" };
11+
const archMap = { arm64: "arm64", x64: "x64", x86_64: "x64" };
12+
13+
const os = platformMap[platform];
14+
const cpu = archMap[arch];
15+
16+
if (!os || !cpu) {
17+
console.error(
18+
`lightshell: unsupported platform ${platform}-${cpu || arch}. Only macOS and Linux (arm64, x64) are supported.`
19+
);
20+
process.exit(1);
21+
}
22+
23+
const pkgName = `@lightshell/${os}-${cpu}`;
24+
25+
let binaryPath;
26+
try {
27+
binaryPath = require.resolve(`${pkgName}/lightshell`);
28+
} catch {
29+
console.error(
30+
`lightshell: could not find ${pkgName}.\n` +
31+
`This usually means optional dependencies were not installed.\n` +
32+
`Try: npm install @lightshell/cli --include=optional`
33+
);
34+
process.exit(1);
35+
}
36+
37+
try {
38+
const result = execFileSync(binaryPath, process.argv.slice(2), {
39+
stdio: "inherit",
40+
env: process.env,
41+
});
42+
} catch (err) {
43+
if (err.status !== null) {
44+
process.exit(err.status);
45+
}
46+
console.error(`lightshell: failed to run binary: ${err.message}`);
47+
process.exit(1);
48+
}

npm/lightshell/install.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

npm/lightshell/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"bin": {
1313
"lightshell": "bin/lightshell"
1414
},
15-
"scripts": {
16-
"postinstall": "node install.js"
17-
},
15+
"files": [
16+
"bin/"
17+
],
1818
"optionalDependencies": {
1919
"@lightshell/darwin-arm64": "0.1.0",
2020
"@lightshell/darwin-x64": "0.1.0",

0 commit comments

Comments
 (0)