Skip to content

Commit 72fd558

Browse files
committed
fix dist script
1 parent e70ba50 commit 72fd558

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

.github/workflows/npm.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
with:
1717
bun-version: latest
1818
- run: bun i
19+
- run: bun run dist
1920
- run: npm publish
21+
working-directory: dist
2022
env:
2123
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,5 @@ dist
175175
.DS_Store
176176

177177

178-
example/.build
178+
example/.build
179+
dist

bun.lockb

7.25 KB
Binary file not shown.

hydrate.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Suspense } from "react";
21
import { hydrateRoot } from "react-dom/client";
32
import { RouterHost } from "./router";
43
import { getRouteMatcher } from "./router/utils/get-route-matcher";

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bun-react-ssr",
33
"module": "index.tsx",
4-
"version": "0.0.6",
4+
"private": "true",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/codehz/bun-react-ssr"
@@ -17,6 +17,7 @@
1717
"@types/react": "^18.2.37",
1818
"@types/react-dom": "^18.2.15",
1919
"@types/web": "^0.0.119",
20+
"bun-plugin-dts": "^0.2.1",
2021
"bun-types": "latest"
2122
},
2223
"peerDependencies": {
@@ -26,5 +27,8 @@
2627
},
2728
"dependencies": {
2829
"next-json": "^0.2.2"
30+
},
31+
"scripts": {
32+
"dist": "bun run scripts/dist.ts"
2933
}
3034
}

scripts/dist.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import dts from "bun-plugin-dts";
2+
import { spawnSync } from "node:child_process";
3+
import { cp, readFile, rm } from "node:fs/promises";
4+
5+
async function glob(pattern: string) {
6+
const result: string[] = [];
7+
for await (const path of new Bun.Glob(pattern).scan({ onlyFiles: true })) {
8+
result.push(path);
9+
}
10+
return result;
11+
}
12+
13+
await rm("dist", { recursive: true });
14+
15+
await Bun.build({
16+
target: "bun",
17+
outdir: "dist",
18+
minify: true,
19+
splitting: true,
20+
sourcemap: "inline",
21+
external: ["react", "react-dom"],
22+
entrypoints: [...(await glob("*.ts"))],
23+
plugins: [dts({})],
24+
});
25+
26+
for (const file of [
27+
...(await glob("*.tsx")),
28+
...(await glob("router/*.{ts,tsx}")),
29+
"LICENSE",
30+
"README.md",
31+
]) {
32+
await cp(file, `dist/${file}`);
33+
}
34+
35+
const contents = JSON.parse(await readFile("package.json", "utf-8"));
36+
delete contents["private"];
37+
contents.version = spawnSync("git", ["describe", "--tags", "--dirty"], {
38+
encoding: "utf-8",
39+
})
40+
.stdout.trim()
41+
.replace(/-[[:digit:]]\+-g/, "+");
42+
delete contents.devDependencies["bun-plugin-dts"];
43+
await Bun.write("dist/package.json", JSON.stringify(contents, null, 2));

0 commit comments

Comments
 (0)