File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 6
6
"scripts" : {
7
7
"copy-src" : " node nursery.js copy" ,
8
8
"build" : " tree-sitter build -o parser.so" ,
9
- "postinstall" : " npm run build " ,
9
+ "postinstall" : " node postinstall.js " ,
10
10
"test" : " node nursery.js test"
11
11
},
12
12
"files" : [
13
13
" index.js" ,
14
+ " postinstall.js" ,
14
15
" src" ,
15
16
" prebuilds"
16
17
],
Original file line number Diff line number Diff line change
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 ( )
You can’t perform that action at this time.
0 commit comments