Skip to content

Commit

Permalink
fix(upgrade): Download yarn patches (redwoodjs#10491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Apr 22, 2024
1 parent d78968c commit 958efee
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => {
updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }),
enabled: (ctx) => ctx.versionToUpgradeTo?.includes('canary'),
},
{
title: 'Downloading yarn patches',
task: (ctx) => downloadYarnPatches(ctx, { dryRun, verbose }),
enabled: (ctx) => ctx.versionToUpgradeTo?.includes('canary'),
},
{
title: 'Running yarn install',
task: (ctx) => yarnInstall(ctx, { dryRun, verbose }),
Expand Down Expand Up @@ -355,6 +360,58 @@ async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
)
}

async function downloadYarnPatches(ctx, { dryRun, verbose }) {
if (!ctx.versionToUpgradeTo) {
throw new Error('Failed to upgrade')
}

const res = await fetch(
'https://api.github.com/repos/redwoodjs/redwood/git/trees/main?recursive=1',
)
const json = await res.json()
const patches = json.tree.filter((patchInfo) =>
patchInfo.path.startsWith(
'packages/create-redwood-app/templates/ts/.yarn/patches/',
),
)

const patchDir = path.join(getPaths().base, '.yarn', 'patches')

if (verbose) {
console.log('Creating patch directory', patchDir)
}

if (!dryRun) {
fs.mkdirSync(patchDir, { recursive: true })
}

return new Listr(
patches.map((patch) => {
return {
title: `Downloading ${patch.path}`,
task: async () => {
const res = await fetch(patch.url)
const patchMeta = await res.json()
const patchPath = path.join(
getPaths().base,
'.yarn',
'patches',
path.basename(patch.path),
)

if (verbose) {
console.log('Writing patch', patchPath)
}

if (!dryRun) {
await fs.writeFile(patchPath, patchMeta.content, 'base64')
}
},
}
}),
)
}

async function refreshPrismaClient(task, { verbose }) {
/** Relates to prisma/client issue, @see: https://github.com/redwoodjs/redwood/issues/1083 */
try {
Expand Down

0 comments on commit 958efee

Please sign in to comment.