@@ -172,6 +172,8 @@ export function makePatch({
172
172
writeFileSync(
173
173
tmpRepoPackageJsonPath,
174
174
JSON.stringify({
175
+ // support `corepack` enabled without `.yarn/releases`
176
+ packageManager: appPackageJson.packageManager,
175
177
dependencies: {
176
178
[packageDetails.name]: getPackageResolution({
177
179
packageDetails,
@@ -193,7 +195,14 @@ export function makePatch({
193
195
// copy .npmrc/.yarnrc in case packages are hosted in private registry
194
196
// copy .yarn directory as well to ensure installations work in yarn 2
195
197
// 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) => {
197
206
const rcPath = join(appPath, rcFile)
198
207
if (existsSync(rcPath)) {
199
208
copySync(rcPath, join(tmpRepo.name, rcFile), { dereference: true })
@@ -205,10 +214,19 @@ export function makePatch({
205
214
chalk.grey("•"),
206
215
`Installing ${packageDetails.name}@${packageVersion} with yarn`,
207
216
)
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
+ }
208
226
try {
209
227
// try first without ignoring scripts in case they are required
210
228
// this works in 99.99% of cases
211
- spawnSafeSync(`yarn`, ["install", "--ignore-engines"] , {
229
+ spawnSafeSync(`yarn`, yarnArgs , {
212
230
cwd: tmpRepoNpmRoot,
213
231
logStdErrOnError: false,
214
232
})
@@ -217,7 +235,7 @@ export function makePatch({
217
235
// an implicit context which we haven't reproduced
218
236
spawnSafeSync(
219
237
`yarn`,
220
- ["install", "--ignore-engines", "--ignore-scripts "],
238
+ [...yarnArgs, isYarnV1 ? "--ignore-scripts" : "--mode=skip-build "],
221
239
{
222
240
cwd: tmpRepoNpmRoot,
223
241
},
@@ -338,9 +356,8 @@ export function makePatch({
338
356
try {
339
357
parsePatchFile(diffResult.stdout.toString())
340
358
} 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")) {
344
361
console.log(`
345
362
⛔️ ${chalk.red.bold("ERROR")}
346
363
@@ -358,7 +375,7 @@ export function makePatch({
358
375
outPath,
359
376
gzipSync(
360
377
JSON.stringify({
361
- error: { message: e .message, stack: e .stack },
378
+ error: { message: err .message, stack: err .stack },
362
379
patch: diffResult.stdout.toString(),
363
380
}),
364
381
),
@@ -544,7 +561,12 @@ export function makePatch({
544
561
}
545
562
}
546
563
} 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)
548
570
throw e
549
571
} finally {
550
572
tmpRepo.removeCallback()
0 commit comments