Skip to content

Commit

Permalink
fix(vercel): write vercel.json as a part of setup (#10355)
Browse files Browse the repository at this point in the history
Follow up to #10295. Implements
the strategy suggested in
#10295 (comment).
Still need to validate with deploy target CI.
  • Loading branch information
jtoar committed Apr 9, 2024
1 parent 0a67f19 commit 53888ad
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .changesets/10355.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix(vercel): write `vercel.json` as a part of setup (#10355) by @jtoar

This PR smooths initial deploys to Vercel by writing a `vercel.json` file that specifies an env var that enables Corepack. Users that already successfully deploy to Vercel don't need to introduce this file.
54 changes: 43 additions & 11 deletions packages/cli/src/commands/setup/deploy/providers/vercel.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
// import terminalLink from 'terminal-link'
import path from 'path'

import { Listr } from 'listr2'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
import { errorTelemetry } from '@redwoodjs/telemetry'

import { printSetupNotes } from '../../../../lib'
import { getPaths, printSetupNotes, writeFile } from '../../../../lib'
import c from '../../../../lib/colors'
import { updateApiURLTask } from '../helpers'

export const command = 'vercel'
export const description = 'Setup Vercel deploy'

const notes = [
'You are ready to deploy to Vercel!',
'See: https://redwoodjs.com/docs/deploy#vercel-deploy',
]

export const handler = async () => {
export async function handler(options) {
recordTelemetryAttributes({
command: 'setup deploy vercel',
})
const tasks = new Listr([updateApiURLTask('/api'), printSetupNotes(notes)], {
rendererOptions: { collapseSubtasks: false },
})

const tasks = new Listr(
[
updateApiURLTask('/api'),
writeVercelConfigTask({ overwriteExisting: options.force }),
printSetupNotes(notes),
],
{
rendererOptions: { collapseSubtasks: false },
},

Check warning on line 28 in packages/cli/src/commands/setup/deploy/providers/vercel.js

View workflow job for this annotation

GitHub Actions / 🚒 Publish Release Candidate

Delete `,`

Check warning on line 28 in packages/cli/src/commands/setup/deploy/providers/vercel.js

View workflow job for this annotation

GitHub Actions / πŸ— Build, lint, test / ubuntu-latest / node 20 latest

Delete `,`

Check warning on line 28 in packages/cli/src/commands/setup/deploy/providers/vercel.js

View workflow job for this annotation

GitHub Actions / πŸ— Build, lint, test / windows-latest / node 20 latest

Delete `,`
)

try {
await tasks.run()
} catch (e) {
Expand All @@ -31,3 +36,30 @@ export const handler = async () => {
process.exit(e?.exitCode || 1)
}
}

function writeVercelConfigTask({ overwriteExisting = false } = {}) {
return {
title: 'Writing vercel.json...',
task: (_ctx, task) => {
writeFile(
path.join(getPaths().base, 'vercel.json'),
JSON.stringify(vercelConfig, null, 2),
{ overwriteExisting },
task,

Check warning on line 48 in packages/cli/src/commands/setup/deploy/providers/vercel.js

View workflow job for this annotation

GitHub Actions / 🚒 Publish Release Candidate

Delete `,`

Check warning on line 48 in packages/cli/src/commands/setup/deploy/providers/vercel.js

View workflow job for this annotation

GitHub Actions / πŸ— Build, lint, test / ubuntu-latest / node 20 latest

Delete `,`

Check warning on line 48 in packages/cli/src/commands/setup/deploy/providers/vercel.js

View workflow job for this annotation

GitHub Actions / πŸ— Build, lint, test / windows-latest / node 20 latest

Delete `,`
)
},
}
}

const vercelConfig = {
build: {
env: {
ENABLE_EXPERIMENTAL_COREPACK: 1,
},
},
}

const notes = [
'You are ready to deploy to Vercel!',
'See: https://redwoodjs.com/docs/deploy#vercel-deploy',
]

0 comments on commit 53888ad

Please sign in to comment.