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