File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 100100 }
101101 },
102102 "files" : [
103- " packages/node-renderer/dist"
103+ " packages/node-renderer/dist" ,
104+ " script/preinstall.js"
104105 ],
105106 "scripts" : {
106- "preinstall" : " yarn run link-source && yalc add --link react-on-rails " ,
107+ "preinstall" : " node ./script/preinstall.js " ,
107108 "postinstall" : " test -f post-yarn-install.local && ./post-yarn-install.local || true" ,
108109 "link-source" : " cd ../packages/react-on-rails && yarn && yalc publish" ,
109110 "test" : " nps test" ,
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ const path = require ( 'path' ) ;
4+ const cp = require ( 'child_process' ) ;
5+
6+ const inNodeModules = __dirname . split ( path . sep ) . includes ( 'node_modules' ) ;
7+
8+ if ( inNodeModules ) {
9+ console . log ( 'preinstall: running inside node_modules — skipping link steps.' ) ;
10+ process . exit ( 0 ) ;
11+ }
12+
13+ function runCommand ( cmd , args ) {
14+ const res = cp . spawnSync ( cmd , args , { stdio : 'inherit' } ) ;
15+ if ( res . error ) throw res . error ;
16+ if ( res . status !== 0 ) throw new Error ( `${ cmd } ${ args . join ( ' ' ) } exited with status ${ res . status } ` ) ;
17+ }
18+
19+ try {
20+ // Run the original optional link steps sequentially in a cross-platform way.
21+ // First run the package script `link-source` via yarn, which will run any shell ops inside the script
22+ // (yarn itself will handle invoking a shell for the script body), then call yalc.
23+ runCommand ( 'yarn' , [ 'run' , 'link-source' ] ) ;
24+ runCommand ( 'yalc' , [ 'add' , '--link' , 'react-on-rails' ] ) ;
25+ } catch ( err ) {
26+ // Don't fail the overall install if these optional commands aren't available or fail,
27+ // just log the error.
28+ console . error ( 'preinstall: optional link steps failed or are unavailable — continuing.' , err ) ;
29+ // Keep the exit code 0 so the install doesn't fail.
30+ process . exit ( 0 ) ;
31+ }
You can’t perform that action at this time.
0 commit comments