Skip to content

Commit 7eb53af

Browse files
committed
try prebuild
1 parent 304b1c6 commit 7eb53af

File tree

7 files changed

+189
-3
lines changed

7 files changed

+189
-3
lines changed

.github/workflows/publish.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish Package to npmjs
2+
on:
3+
release:
4+
types: [published]
5+
6+
permissions:
7+
id-token: write # Required for OIDC
8+
contents: read
9+
10+
jobs:
11+
prebuilds:
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- os: ubuntu-latest
17+
arch: x64
18+
- os: ubuntu-24.04-arm
19+
arch: arm64
20+
- os: macos-15-intel
21+
arch: x64
22+
- os: macos-latest
23+
arch: arm64
24+
- os: windows-latest
25+
arch: x64
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
- uses: actions/checkout@v5
29+
with:
30+
submodules: recursive
31+
- uses: actions/setup-node@v6
32+
with:
33+
node-version: 24
34+
- uses: oven-sh/setup-bun@v2
35+
with:
36+
bun-version: latest
37+
- run: bun install
38+
- run: bun run prebuild
39+
- uses: actions/upload-artifact@v6
40+
with:
41+
name: prebuilds-${{ matrix.os }}-${{ matrix.arch }}
42+
path: prebuilds
43+
44+
publish:
45+
needs: prebuilds
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v5
50+
with:
51+
fetch-depth: 0
52+
- uses: actions/setup-node@v6
53+
with:
54+
node-version: 24
55+
registry-url: 'https://registry.npmjs.org'
56+
- uses: oven-sh/setup-bun@v2
57+
with:
58+
bun-version: latest
59+
- uses: actions/download-artifact@v7
60+
with:
61+
path: .
62+
merge-multiple: true
63+
- run: bun scripts/prepublish.ts
64+
- run: bun publish --access public --tag latest
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bower_components
3737
# Compiled binary addons (https://nodejs.org/api/addons.html)
3838
build/Release
3939
build/Debug
40+
prebuilds/
4041

4142
# Dependency directories
4243
node_modules/

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ Patch compatible with HDiffPatch -SD
77
## Installation
88

99
```bash
10-
npm install --save node-hdiffpatch
10+
bun add node-hdiffpatch
11+
```
12+
13+
## Prebuilds
14+
15+
Prebuilds are generated per target platform/arch. Build them on each target OS:
16+
17+
```bash
18+
bun run prebuild
1119
```
1220

1321
## Usage

bun.lock

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const native = require('./build/Release/hdiffpatch');
1+
const native = require('node-gyp-build')(__dirname);
22

33
exports.native = native;
44

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88
},
99
"scripts": {
1010
"test": "node test/test.js",
11+
"prepublishOnly": "bun scripts/prepublish.ts",
1112
"benchmark": "node --expose-gc test/benchmark.js",
13+
"prebuild": "prebuildify --napi --strip",
14+
"install": "node-gyp-build",
1215
"prepack": "git submodule update --init --recursive"
1316
},
1417
"gypfile": true,
1518
"author": "housisong, sunnylqm",
1619
"license": "MIT",
1720
"dependencies": {
18-
"node-addon-api": "^8.5.0"
21+
"node-addon-api": "^8.5.0",
22+
"node-gyp-build": "^4.8.1"
23+
},
24+
"devDependencies": {
25+
"prebuildify": "^6.0.0"
1926
},
2027
"repository": {
2128
"type": "git",

scripts/prepublish.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bun
2+
3+
import { access, readFile, writeFile } from 'node:fs/promises';
4+
import path from 'node:path';
5+
6+
async function modifyPackageJson({
7+
version,
8+
}: {
9+
version: string;
10+
}): Promise<void> {
11+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
12+
13+
try {
14+
await access(packageJsonPath);
15+
} catch {
16+
throw new Error(`package.json not found at ${packageJsonPath}`);
17+
}
18+
19+
console.log('Reading package.json...');
20+
const packageJsonContent = await readFile(packageJsonPath, 'utf-8');
21+
const packageJson = JSON.parse(packageJsonContent);
22+
23+
packageJson.version = version;
24+
25+
console.log('Writing modified package.json...');
26+
27+
await writeFile(
28+
packageJsonPath,
29+
JSON.stringify(packageJson, null, 2),
30+
'utf-8',
31+
);
32+
33+
console.log('package.json has been modified for publishing');
34+
}
35+
36+
async function main(): Promise<void> {
37+
const version = (await $`git describe --tags --always`.text())
38+
.replace('v', '')
39+
.trim();
40+
try {
41+
await modifyPackageJson({ version });
42+
console.log('✅ Prepublish script completed successfully');
43+
} catch (error) {
44+
console.error('❌ Prepublish script failed:', error);
45+
process.exit(1);
46+
}
47+
48+
}
49+
50+
main();

0 commit comments

Comments
 (0)