Skip to content

Commit e8b9c70

Browse files
author
Yuri Yakovlev
authored
feat: cli deployment target from Now.sh to Vercel (#910)
BREAKING CHANGE: The flag `--deployment` now accepts "vercel" instead of "now".
1 parent 7177d07 commit e8b9c70

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

docs/references/recipes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ If you don't want to use a docker, here are some links to alternative approaches
140140
+ "start": "node .nexus/build"
141141
```
142142

143-
3. In many cases this will be enough. Many deployment platforms will call into these scripts by default. You can customize where `build` outputs to if your deployment platform requires it. There are built in guides for `zeit` and `heroku` which will check your project is prepared for deployment to those respective platforms. Take advantage of them if applicable:
143+
3. In many cases this will be enough. Many deployment platforms will call into these scripts by default. You can customize where `build` outputs to if your deployment platform requires it. There are built in guides for `vercel` and `heroku` which will check your project is prepared for deployment to those respective platforms. Take advantage of them if applicable:
144144

145145
```diff
146146
+++ package.json
147-
+ "build": "nexus build --deployment now"
147+
+ "build": "nexus build --deployment vercel"
148148
```
149149

150150
```diff

src/lib/build/deploy-target.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const log = rootLogger.child('build')
1313
/**
1414
* If you add a new deploy target, please start by adding a new item to the `SUPPORTED_DEPLOY_TARGETS`
1515
*/
16-
const SUPPORTED_DEPLOY_TARGETS = ['now', 'heroku'] as const
16+
const SUPPORTED_DEPLOY_TARGETS = ['vercel', 'heroku'] as const
1717

1818
export const formattedSupportedDeployTargets = SUPPORTED_DEPLOY_TARGETS.map((t) => `"${t}"`).join(', ')
1919

@@ -40,7 +40,7 @@ export function normalizeTarget(inputDeployTarget: string | undefined): Supporte
4040
}
4141

4242
const TARGET_TO_BUILD_OUTPUT: Record<SupportedTargets, string> = {
43-
now: 'dist',
43+
vercel: 'dist',
4444
heroku: DEFAULT_BUILD_FOLDER_PATH_RELATIVE_TO_PROJECT_ROOT,
4545
}
4646

@@ -54,7 +54,7 @@ export function computeBuildOutputFromTarget(target: SupportedTargets | null) {
5454

5555
type ValidatorResult = { valid: boolean }
5656
const TARGET_VALIDATORS: Record<SupportedTargets, (layout: Layout) => ValidatorResult> = {
57-
now: validateNow,
57+
vercel: validateVercel,
5858
heroku: validateHeroku,
5959
}
6060

@@ -63,30 +63,29 @@ export function validateTarget(target: SupportedTargets, layout: Layout): Valida
6363
return validator(layout)
6464
}
6565

66-
interface NowJson {
66+
interface VercelJson {
6767
version: 1 | 2
6868
name: string
6969
builds?: Array<{ src: string; use: string }>
7070
routes?: Array<{ src: string; dest: string }>
7171
}
7272

7373
/**
74-
* Validate the user's now configuration file.
74+
* Validate the user's vercel configuration file.
7575
*/
76-
function validateNow(layout: Layout): ValidatorResult {
77-
const maybeNowJson = findFileRecurisvelyUpwardSync('now.json', { cwd: layout.projectRoot })
76+
function validateVercel(layout: Layout): ValidatorResult {
77+
const maybeVercelJson = findFileRecurisvelyUpwardSync('vercel.json', { cwd: layout.projectRoot })
7878
const startModulePath = `${layout.build.tsOutputDir}/${START_MODULE_NAME}.js`
7979
let isValid = true
8080

81-
// Make sure there's a now.json file
82-
if (!maybeNowJson) {
83-
log.trace('creating now.json because none exists yet')
81+
// Make sure there's a vercel.json file
82+
if (!maybeVercelJson) {
83+
log.trace('creating vercel.json because none exists yet')
8484
const projectName = layout.packageJson?.content.name ?? 'now_rename_me'
8585

86-
const nowJsonContent = stripIndent`
86+
const vercelJsonContent = stripIndent`
8787
{
8888
"version": 2,
89-
"name": "${projectName}",
9089
"builds": [
9190
{
9291
"src": "${startModulePath}",
@@ -96,38 +95,38 @@ function validateNow(layout: Layout): ValidatorResult {
9695
"routes": [{ "src": "/.*", "dest": "${startModulePath}" }]
9796
}
9897
`
99-
const nowJsonPath = Path.join(layout.projectRoot, 'now.json')
100-
fs.write(nowJsonPath, nowJsonContent)
101-
log.warn(`No \`now.json\` file were found. We scaffolded one for you in ${nowJsonPath}`)
98+
const vercelJsonPath = Path.join(layout.projectRoot, 'vercel.json')
99+
fs.write(vercelJsonPath, vercelJsonContent)
100+
log.warn(`No \`vercel.json\` file were found. We scaffolded one for you in ${vercelJsonPath}`)
102101
} else {
103-
const nowJson: NowJson = fs.read(maybeNowJson.path, 'json')
102+
const vercelJson: VercelJson = fs.read(maybeVercelJson.path, 'json')
104103

105-
// Make sure the now.json file has the right `builds` values
104+
// Make sure the vercel.json file has the right `builds` values
106105
if (
107-
!nowJson.builds ||
108-
!nowJson.builds.find(
109-
(build) => Path.join(maybeNowJson.dir, build.src) === startModulePath && build.use === '@now/node'
106+
!vercelJson.builds ||
107+
!vercelJson.builds.find(
108+
(build) => Path.join(maybeVercelJson.dir, build.src) === startModulePath && build.use === '@now/node'
110109
)
111110
) {
112-
log.error(`We could not find a proper builder in your \`now.json\` file`)
113-
log.error(`Found: "builds": ${JSON.stringify(nowJson.builds)}`)
111+
log.error(`We could not find a proper builder in your \`vercel.json\` file`)
112+
log.error(`Found: "builds": ${JSON.stringify(vercelJson.builds)}`)
114113
log.error(`Expected: "builds": [{ src: "${startModulePath}", use: '@now/node' }, ...]`)
115114
console.log('\n')
116115
isValid = false
117116
}
118117

119-
// Make sure the now.json file has a `routes` property
120-
if (!nowJson.routes) {
121-
log.error(`We could not find a \`routes\` property in your \`now.json\` file.`)
118+
// Make sure the vercel.json file has a `routes` property
119+
if (!vercelJson.routes) {
120+
log.error(`We could not find a \`routes\` property in your \`vercel.json\` file.`)
122121
log.error(`Expected: "routes": [{ "src": "/.*", "dest": "${startModulePath}" }]`)
123122
console.log('\n')
124123
isValid = false
125124
}
126125

127-
// Make sure the now.json file has the right `routes` values
128-
if (!nowJson.routes?.find((route) => Path.join(maybeNowJson.dir, route.dest) === startModulePath)) {
129-
log.error(`We could not find a route property that redirects to your api in your \`now.json\` file.`)
130-
log.error(`Found: "routes": ${JSON.stringify(nowJson.routes)}`)
126+
// Make sure the vercel.json file has the right `routes` values
127+
if (!vercelJson.routes?.find((route) => Path.join(maybeVercelJson.dir, route.dest) === startModulePath)) {
128+
log.error(`We could not find a route property that redirects to your api in your \`vercel.json\` file.`)
129+
log.error(`Found: "routes": ${JSON.stringify(vercelJson.routes)}`)
131130
log.error(`Expected: "routes": [{ src: '/.*', dest: "${startModulePath}" }, ...]`)
132131
console.log('\n')
133132
isValid = false
@@ -216,7 +215,7 @@ function validateHeroku(layout: Layout): ValidatorResult {
216215
}
217216

218217
const TARGET_TO_POST_BUILD_MESSAGE: Record<SupportedTargets, string> = {
219-
now: `Please run \`now\` to deploy your nexus server. Your endpoint will be available at http://<id>.now.sh/graphql`,
218+
vercel: `Please run \`vercel\` or \`vc\` to deploy your nexus server. Your endpoint will be available at http://<id>.now.sh/graphql`,
220219
heroku: `\
221220
Please run the following commands to deploy to heroku:
222221

0 commit comments

Comments
 (0)