@@ -172,6 +172,8 @@ export function makePatch({
172172    writeFileSync ( 
173173      tmpRepoPackageJsonPath , 
174174      JSON . stringify ( { 
175+         // support `corepack` enabled without `.yarn/releases` 
176+         packageManager : appPackageJson . packageManager , 
175177        dependencies : { 
176178          [ packageDetails . name ] : getPackageResolution ( { 
177179            packageDetails, 
@@ -193,7 +195,14 @@ export function makePatch({
193195    // copy .npmrc/.yarnrc in case packages are hosted in private registry 
194196    // copy .yarn directory as well to ensure installations work in yarn 2 
195197    // tslint:disable-next-line:align 
196-     ; [ ".npmrc" ,  ".yarnrc" ,  ".yarn" ] . forEach ( ( rcFile )  =>  { 
198+     ; [ 
199+       ".npmrc" , 
200+       ".yarnrc" , 
201+       ".yarnrc.yml" , 
202+       // don't include the whole `.yarn` directory which could contain huge `cache` 
203+       ".yarn/plugins" , 
204+       ".yarn/releases" , 
205+     ] . forEach ( ( rcFile )  =>  { 
197206      const  rcPath  =  join ( appPath ,  rcFile ) 
198207      if  ( existsSync ( rcPath ) )  { 
199208        copySync ( rcPath ,  join ( tmpRepo . name ,  rcFile ) ,  {  dereference : true  } ) 
@@ -205,10 +214,19 @@ export function makePatch({
205214        chalk . grey ( "•" ) , 
206215        `Installing ${ packageDetails . name } ${ packageVersion }  , 
207216      ) 
217+       const  yarnArgs  =  [ "install" ] 
218+       const  yarnVersionCmd  =  spawnSafeSync ( `yarn` ,  [ "--version" ] ,  { 
219+         cwd : tmpRepoNpmRoot , 
220+         logStdErrOnError : false , 
221+       } ) 
222+       const  isYarnV1  =  yarnVersionCmd . stdout . toString ( ) . startsWith ( "1." ) 
223+       if  ( isYarnV1 )  { 
224+         yarnArgs . push ( "--ignore-engines" ) 
225+       } 
208226      try  { 
209227        // try first without ignoring scripts in case they are required 
210228        // this works in 99.99% of cases 
211-         spawnSafeSync ( `yarn` ,  [ "install" ,   "--ignore-engines" ] ,  { 
229+         spawnSafeSync ( `yarn` ,  yarnArgs ,  { 
212230          cwd : tmpRepoNpmRoot , 
213231          logStdErrOnError : false , 
214232        } ) 
@@ -217,7 +235,7 @@ export function makePatch({
217235        // an implicit context which we haven't reproduced 
218236        spawnSafeSync ( 
219237          `yarn` , 
220-           [ "install" ,   "--ignore-engines"  ,   "--ignore-scripts " ] , 
238+           [ ... yarnArgs ,   isYarnV1  ?  "--ignore-scripts"   :  "--mode=skip-build " ] , 
221239          { 
222240            cwd : tmpRepoNpmRoot , 
223241          } , 
@@ -338,9 +356,8 @@ export function makePatch({
338356    try  { 
339357      parsePatchFile ( diffResult . stdout . toString ( ) ) 
340358    }  catch  ( e )  { 
341-       if  ( 
342-         ( e  as  Error ) . message . includes ( "Unexpected file mode string: 120000" ) 
343-       )  { 
359+       const  err  =  e  as  Error 
360+       if  ( err . message . includes ( "Unexpected file mode string: 120000" ) )  { 
344361        console . log ( ` 
345362⛔️ ${ chalk . red . bold ( "ERROR" ) }  
346363
@@ -358,7 +375,7 @@ export function makePatch({
358375          outPath , 
359376          gzipSync ( 
360377            JSON . stringify ( { 
361-               error : {  message : e . message ,  stack : e . stack  } , 
378+               error : {  message : err . message ,  stack : err . stack  } , 
362379              patch : diffResult . stdout . toString ( ) , 
363380            } ) , 
364381          ) , 
@@ -544,7 +561,12 @@ export function makePatch({
544561      } 
545562    } 
546563  }  catch  ( e )  { 
547-     console . log ( e ) 
564+     const  err  =  e  as  Error  &  { 
565+       stdout ?: Buffer 
566+       stderr ?: Buffer 
567+     } 
568+     // try to log more useful error message 
569+     console . log ( err . stderr ?. toString ( )  ||  err . stdout ?. toString ( )  ||  e ) 
548570    throw  e 
549571  }  finally  { 
550572    tmpRepo . removeCallback ( ) 
0 commit comments