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 1854cb3 commit ef0c842
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 },
},
)

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,
)
},
}
}

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 ef0c842

Please sign in to comment.