Skip to content

Commit 009c644

Browse files
committed
Enhance package configuration by adding '@types/bun' and 'node-hdiffpatch' as optional dependencies, and update the prepublish script to utilize 'bun' commands for improved build process.
1 parent 6ce6c9e commit 009c644

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

bun.lock

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

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"files": ["lib", "src", "proto", "cli.json"],
1111
"scripts": {
1212
"build": "swc src -d lib --strip-leading-paths",
13-
"prepublishOnly": "npm run build && chmod +x lib/index.js",
13+
"prepublishOnly": "bun scripts/prepublish.js && bun run build && chmod +x lib/index.js",
1414
"lint": "tsc --noEmit & biome check --write ."
1515
},
1616
"repository": {
@@ -61,6 +61,7 @@
6161
"@biomejs/biome": "^1.9.4",
6262
"@swc/cli": "0.7.7",
6363
"@swc/core": "^1.11.24",
64+
"@types/bun": "^1.3.8",
6465
"@types/filesize-parser": "^1.5.3",
6566
"@types/fs-extra": "^11.0.4",
6667
"@types/node": "^22.15.18",
@@ -72,5 +73,8 @@
7273
"@types/yazl": "^2.4.6",
7374
"typescript": "^5.8.3"
7475
},
75-
"trustedDependencies": ["@biomejs/biome", "@swc/core"]
76+
"optionalDependencies": {
77+
"node-hdiffpatch": "^1.2.1"
78+
},
79+
"trustedDependencies": ["@biomejs/biome", "@swc/core", "node-hdiffpatch"]
7680
}

scripts/prepublish.ts

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

src/bundle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ const loadDiffModule = (pkgName: string): Diff | undefined => {
3838
return undefined;
3939
};
4040

41-
let bsdiff: Diff | undefined;
4241
let hdiff: Diff | undefined;
42+
hdiff = (loadDiffModule('node-hdiffpatch') as any)?.diff;
43+
let bsdiff: Diff | undefined;
4344
let diff: Diff;
4445
bsdiff = loadDiffModule('node-bsdiff');
45-
hdiff = loadDiffModule('node-hdiffpatch');
4646

4747
async function runReactNativeBundleCommand({
4848
bundleName,

0 commit comments

Comments
 (0)