@@ -118,7 +118,23 @@ function main() {
118118 odir = meta [ i ] [ 1 ] ;
119119
120120 debug ( 'Moving: %s...' , path . basename ( odir ) ) ;
121- fs . linkSync ( odir , ndir ) ;
121+ try { // eslint-disable-line max-depth
122+ fs . linkSync ( odir , ndir ) ;
123+ } catch ( error ) {
124+ debug ( 'Error: %s' , error . message ) ;
125+ fs . renameSync ( odir , ndir ) ;
126+ }
127+ }
128+ } else if ( action === 'move' ) {
129+ ndir = meta [ i ] [ 2 ] ;
130+ if ( fs . existsSync ( ndir ) ) {
131+ debug ( 'Directory exists: %s' , ndir ) ;
132+ } else {
133+ FLG = true ;
134+ odir = meta [ i ] [ 1 ] ;
135+
136+ debug ( 'Moving: %s...' , path . basename ( odir ) ) ;
137+ fs . renameSync ( odir , ndir ) ;
122138 }
123139 }
124140 }
@@ -156,8 +172,14 @@ function main() {
156172 console . warn ( 'WARNING: path conflict. node_modules directory already exists.' ) ;
157173 } else {
158174 debug ( 'Moving node_modules directory...' ) ;
159- fs . linkSync ( odir , ndir ) ;
160- out . push ( [ 'link' , odir , ndir ] ) ;
175+ try {
176+ fs . linkSync ( odir , ndir ) ;
177+ out . push ( [ 'link' , odir , ndir ] ) ;
178+ } catch ( error ) {
179+ debug ( 'Error: %s' , error . message ) ;
180+ fs . renameSync ( odir , ndir ) ;
181+ out . push ( [ 'move' , odir , ndir ] ) ;
182+ }
161183 }
162184 } else {
163185 debug ( 'Creating root node_modules directory...' ) ;
@@ -171,8 +193,14 @@ function main() {
171193 console . warn ( 'WARNING: path conflict. node_modules directory already exists.' ) ;
172194 } else {
173195 debug ( 'Moving node_modules directory...' ) ;
174- fs . linkSync ( odir , ndir ) ;
175- out . push ( [ 'link' , odir , ndir ] ) ;
196+ try {
197+ fs . linkSync ( odir , ndir ) ;
198+ out . push ( [ 'link' , odir , ndir ] ) ;
199+ } catch ( error ) {
200+ debug ( 'Error: %s' , error . message ) ;
201+ fs . renameSync ( odir , ndir ) ;
202+ out . push ( [ 'move' , odir , ndir ] ) ;
203+ }
176204 }
177205 }
178206
@@ -213,8 +241,14 @@ function main() {
213241 console . warn ( 'WARNING: package conflict. Package directory already exists: %s.' , f ) ;
214242 } else {
215243 debug ( 'Moving: %s...' , f ) ;
216- fs . linkSync ( odir , ndir ) ;
217- out . push ( [ 'link' , odir , ndir ] ) ;
244+ try {
245+ fs . linkSync ( odir , ndir ) ;
246+ out . push ( [ 'link' , odir , ndir ] ) ;
247+ } catch ( error ) {
248+ debug ( 'Error: %s' , error . message ) ;
249+ fs . renameSync ( odir , ndir ) ;
250+ out . push ( [ 'move' , odir , ndir ] ) ;
251+ }
218252 }
219253 }
220254 debug ( 'Finished post-install sequence.' ) ;
0 commit comments