Skip to content

Commit b742684

Browse files
committed
Separate npm and binary builds - publish JS bundle to npm, binaries to GitHub releases
1 parent 0d6f8f2 commit b742684

File tree

4 files changed

+70
-62
lines changed

4 files changed

+70
-62
lines changed

.github/workflows/release.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- 'src/**'
88
- 'package.json'
99
- 'build.ts'
10+
- 'build-npm.ts'
1011
- 'bun.lock'
1112
workflow_dispatch:
1213

@@ -32,7 +33,10 @@ jobs:
3233
- name: Install dependencies
3334
run: bun install --frozen-lockfile
3435

35-
- name: Build all platforms
36+
- name: Build for npm (JavaScript bundle)
37+
run: bun run build:npm
38+
39+
- name: Build binaries for all platforms
3640
run: bun run build
3741

3842
- name: Get version from package.json
@@ -47,13 +51,24 @@ jobs:
4751
body: |
4852
## Effect DevTools Terminal UI
4953
50-
### Installation
54+
### Installation via npm
5155
```bash
5256
npm install -g effect-devtui
5357
effect-devtools
58+
```
59+
60+
### Or download binary directly
61+
Download the binary for your platform below and run it directly.
62+
63+
```bash
64+
# Linux x64
65+
./effect-devtools-linux-x64
66+
67+
# macOS (Intel)
68+
./effect-devtools-darwin-x64
5469
55-
# Or run directly with bunx
56-
bunx effect-devtui
70+
# Windows
71+
effect-devtools-windows-x64.exe
5772
```
5873
5974
Built from commit ${{ github.sha }}
@@ -74,6 +89,6 @@ jobs:
7489
registry-url: 'https://registry.npmjs.org'
7590

7691
- name: Publish to npm
77-
run: npm publish --access public
92+
run: npm publish --access public --provenance
7893
env:
7994
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

bin/effect-devtools

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,13 @@
11
#!/usr/bin/env node
22

3-
// Installer script for effect-devtools
4-
// Downloads the appropriate binary for the current platform
3+
// Entry point for effect-devtools npm package
4+
// Runs the bundled JavaScript version
55

6-
import { createRequire } from "module";
7-
import { platform, arch } from "os";
8-
import { existsSync } from "fs";
9-
import { join, dirname } from "path";
106
import { fileURLToPath } from "url";
7+
import { dirname, join } from "path";
118

129
const __filename = fileURLToPath(import.meta.url);
1310
const __dirname = dirname(__filename);
1411

15-
const require = createRequire(import.meta.url);
16-
const pkg = require("../package.json");
17-
18-
// Map platform/arch to binary names
19-
const PLATFORMS = {
20-
darwin: {
21-
x64: "effect-devtools-darwin-x64",
22-
arm64: "effect-devtools-darwin-arm64",
23-
},
24-
linux: {
25-
x64: "effect-devtools-linux-x64",
26-
arm64: "effect-devtools-linux-arm64",
27-
},
28-
win32: {
29-
x64: "effect-devtools-windows-x64.exe",
30-
},
31-
};
32-
33-
const currentPlatform = platform();
34-
const currentArch = arch();
35-
36-
const binaryName = PLATFORMS[currentPlatform]?.[currentArch];
37-
38-
if (!binaryName) {
39-
console.error(
40-
`Unsupported platform: ${currentPlatform} ${currentArch}`
41-
);
42-
console.error("Supported platforms:");
43-
console.error(JSON.stringify(PLATFORMS, null, 2));
44-
process.exit(1);
45-
}
46-
47-
const binaryPath = join(__dirname, "..", "dist", binaryName.replace(".exe", ""), binaryName);
48-
49-
if (!existsSync(binaryPath)) {
50-
console.error(`Binary not found: ${binaryPath}`);
51-
console.error("Please report this issue at:");
52-
console.error(pkg.bugs.url);
53-
process.exit(1);
54-
}
55-
56-
// Re-export the binary
57-
import { spawn } from "child_process";
58-
59-
const child = spawn(binaryPath, process.argv.slice(2), {
60-
stdio: "inherit",
61-
});
62-
63-
child.on("exit", (code) => {
64-
process.exit(code || 0);
65-
});
12+
// Import and run the bundled app
13+
await import(join(__dirname, "..", "dist", "index.js"));

build-npm.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bun
2+
3+
import solidPlugin from "@opentui/solid/bun-plugin"
4+
import path from "path"
5+
import { fileURLToPath } from "url"
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
10+
process.chdir(__dirname)
11+
12+
import pkg from "./package.json"
13+
14+
console.log("Building for npm publish...")
15+
16+
await Bun.$`rm -rf dist`
17+
await Bun.$`mkdir -p dist`
18+
19+
// Build a JavaScript bundle for npm (not a binary)
20+
const result = await Bun.build({
21+
conditions: ["browser"],
22+
tsconfig: "./tsconfig.json",
23+
plugins: [solidPlugin],
24+
sourcemap: "external",
25+
target: "node",
26+
minify: false,
27+
entrypoints: ["./src/index.tsx"],
28+
outdir: "./dist",
29+
format: "esm",
30+
define: {
31+
VERSION: `'${pkg.version}'`,
32+
},
33+
})
34+
35+
if (!result.success) {
36+
console.error("Build failed:")
37+
for (const log of result.logs) {
38+
console.error(log)
39+
}
40+
process.exit(1)
41+
}
42+
43+
console.log("NPM build complete!")
44+
console.log("Output: dist/index.js")

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"scripts": {
2222
"dev": "bun --watch --conditions=browser src/index.tsx",
2323
"build": "./build.ts",
24+
"build:npm": "./build-npm.ts",
2425
"build:single": "./build.ts --single",
2526
"start": "bun --conditions=browser src/index.tsx"
2627
},

0 commit comments

Comments
 (0)