Skip to content

Commit 5ff4088

Browse files
feat: change postinstall hook
1 parent 4a17f48 commit 5ff4088

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/toml/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"scripts": {
77
"copy-src": "node nursery.js copy",
88
"build": "tree-sitter build -o parser.so",
9-
"postinstall": "npm run build",
9+
"postinstall": "node postinstall.js",
1010
"test": "node nursery.js test"
1111
},
1212
"files": [
1313
"index.js",
14+
"postinstall.js",
1415
"src",
1516
"prebuilds"
1617
],

packages/toml/postinstall.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const dir = __dirname
2+
3+
const { execSync } = require('child_process')
4+
const fs = require('fs')
5+
const path = require('path')
6+
7+
async function postinstall() {
8+
const parser = path.join(dir, 'parser.so')
9+
if (fs.existsSync(parser)) {
10+
return
11+
}
12+
// resolve parser path
13+
const prebuild = resolvePrebuild()
14+
if (prebuild) {
15+
fs.copyFileSync(prebuild, parser)
16+
} else {
17+
// build parser
18+
execSync('npm run build')
19+
}
20+
}
21+
22+
function resolvePrebuild() {
23+
const os = process.platform
24+
const arch = process.arch
25+
throw new Error(`TODO: ${os} ${arch}`)
26+
}
27+
28+
postinstall()

0 commit comments

Comments
 (0)