From f6e0108084f7f89713e40100e5399fd4676e44b1 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Tue, 9 Apr 2024 10:10:03 -0700 Subject: [PATCH] fix(vercel): write `vercel.json` as a part of setup (#10355) Follow up to https://github.com/redwoodjs/redwood/pull/10295. Implements the strategy suggested in https://github.com/redwoodjs/redwood/pull/10295#issuecomment-2021545553. Still need to validate with deploy target CI. --- .changesets/10355.md | 3 ++ .../commands/setup/deploy/providers/vercel.js | 54 +++++++++++++++---- 2 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 .changesets/10355.md diff --git a/.changesets/10355.md b/.changesets/10355.md new file mode 100644 index 000000000000..88c13b6d30a9 --- /dev/null +++ b/.changesets/10355.md @@ -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. diff --git a/packages/cli/src/commands/setup/deploy/providers/vercel.js b/packages/cli/src/commands/setup/deploy/providers/vercel.js index d648dab3c4f2..2706c86a2b61 100644 --- a/packages/cli/src/commands/setup/deploy/providers/vercel.js +++ b/packages/cli/src/commands/setup/deploy/providers/vercel.js @@ -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) { @@ -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', +]