Skip to content

Commit f6e0108

Browse files
committed
fix(vercel): write vercel.json as a part of setup (#10355)
Follow up to #10295. Implements the strategy suggested in #10295 (comment). Still need to validate with deploy target CI.
1 parent 0a67f19 commit f6e0108

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

.changesets/10355.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- fix(vercel): write `vercel.json` as a part of setup (#10355) by @jtoar
2+
3+
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.
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
// import terminalLink from 'terminal-link'
1+
import path from 'path'
2+
23
import { Listr } from 'listr2'
34

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

7-
import { printSetupNotes } from '../../../../lib'
8+
import { getPaths, printSetupNotes, writeFile } from '../../../../lib'
89
import c from '../../../../lib/colors'
910
import { updateApiURLTask } from '../helpers'
1011

1112
export const command = 'vercel'
1213
export const description = 'Setup Vercel deploy'
1314

14-
const notes = [
15-
'You are ready to deploy to Vercel!',
16-
'See: https://redwoodjs.com/docs/deploy#vercel-deploy',
17-
]
18-
19-
export const handler = async () => {
15+
export async function handler(options) {
2016
recordTelemetryAttributes({
2117
command: 'setup deploy vercel',
2218
})
23-
const tasks = new Listr([updateApiURLTask('/api'), printSetupNotes(notes)], {
24-
rendererOptions: { collapseSubtasks: false },
25-
})
19+
20+
const tasks = new Listr(
21+
[
22+
updateApiURLTask('/api'),
23+
writeVercelConfigTask({ overwriteExisting: options.force }),
24+
printSetupNotes(notes),
25+
],
26+
{
27+
rendererOptions: { collapseSubtasks: false },
28+
},
29+
)
30+
2631
try {
2732
await tasks.run()
2833
} catch (e) {
@@ -31,3 +36,30 @@ export const handler = async () => {
3136
process.exit(e?.exitCode || 1)
3237
}
3338
}
39+
40+
function writeVercelConfigTask({ overwriteExisting = false } = {}) {
41+
return {
42+
title: 'Writing vercel.json...',
43+
task: (_ctx, task) => {
44+
writeFile(
45+
path.join(getPaths().base, 'vercel.json'),
46+
JSON.stringify(vercelConfig, null, 2),
47+
{ overwriteExisting },
48+
task,
49+
)
50+
},
51+
}
52+
}
53+
54+
const vercelConfig = {
55+
build: {
56+
env: {
57+
ENABLE_EXPERIMENTAL_COREPACK: 1,
58+
},
59+
},
60+
}
61+
62+
const notes = [
63+
'You are ready to deploy to Vercel!',
64+
'See: https://redwoodjs.com/docs/deploy#vercel-deploy',
65+
]

0 commit comments

Comments
 (0)