Skip to content

Commit f88ee70

Browse files
jtoarTobbe
authored andcommitted
feat(CLI): add check node version middleware, rm .nvmrc, yarn engines (#9728)
Continuation of #8907. Following up on our meeting today (@Tobbe, @thedavidprice; this PR doesn't implement the configurable engines functionality yet). This PR - removes the `.nvmrc` file from CRWA and test project fixtures Setup deploy commands should add node version files if they need them, preferably something nvm agnostic like Netlify's `.node-version` - removes yarn from engines in CRWA's root package.json since it doesn't do anything and just creates confusion - adds a node version check to build and dev This piece of middleware is lightweight; it doesn't involve a child process or the file system, it just checks against `process.version`. I also removed the babel check because it's been ages since we've made that change and original concerns against checking for the node version were about adding overhead tot he CLI. So let's remove unnecessary middleware if we're going to add more Right now, the node version check just emits a warning. Should it error out? (I should've taken better notes.) Build: ![image](https://github.com/redwoodjs/redwood/assets/32992335/e0d2ced6-7b52-448e-96a1-08a45aac64e0) Dev: ![image](https://github.com/redwoodjs/redwood/assets/32992335/d78069eb-bd6c-4ac9-b936-b90f704b5c5c) - [ ] research deploy providers and update `yarn rw setup deploy` commands - [x] settle on warning or error for build and dev - [x] settle on the contents of the message - [x] update CRWA - [x] baremetal Pretty sure it's completely up to you. - [x] coherence Via Nixpacks, `engines.node` in the root package.json: https://nixpacks.com/docs/providers/node#setup. - [x] flightcontrol Via Nixpacks, `engines.node` in the root package.json: https://www.flightcontrol.dev/docs/getting-started/javascript/setting-node-version#using-the-packagejson-file. - [x] netlify Via the `.node-version` file, or via in `netlify.toml`; see https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript, https://docs.netlify.com/configure-builds/file-based-configuration/#sample-netlify-toml-file. - [ ] vercel Takes its cue from engines.node in the root package.json: https://vercel.com/docs/functions/serverless-functions/runtimes/node-js#version-overrides-in-package.json. - [x] render Same as netlify more or less, but also respects `engines.node` in the root package.json: https://docs.render.com/docs/node-version.
1 parent ad20084 commit f88ee70

File tree

19 files changed

+147
-129
lines changed

19 files changed

+147
-129
lines changed

__fixtures__/test-project/.nvmrc

-1
This file was deleted.

__fixtures__/test-project/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"root": true
1515
},
1616
"engines": {
17-
"node": "=20.x",
18-
"yarn": ">=1.22.21"
17+
"node": "=20.x"
1918
},
2019
"prisma": {
2120
"seed": "yarn rw exec seed"

docs/docs/tutorial/chapter1/prerequisites.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You could definitely learn them all at once, but it will be harder to determine
1717

1818
### Redwood Versions
1919

20-
You will want to be on at least version 5.0.0 to complete the tutorial. If this is your first time using Redwood then no worries: the latest version will be installed automatically when you create your app skeleton!
20+
You will want to be on at least version 7.0.0 to complete the tutorial. If this is your first time using Redwood then no worries: the latest version will be installed automatically when you create your app skeleton!
2121

2222
If you have an existing site created with a prior version, you'll need to upgrade and (most likely) apply code modifications. Follow this two step process:
2323

docs/docs/tutorial/foreword.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ It's usually something that goes into more detail about a specific point, refers
4040

4141
:::info
4242

43-
This tutorial assumes you are using version 5.0.0 or greater of RedwoodJS.
43+
This tutorial assumes you are using version 7.0.0 or greater of RedwoodJS.
4444

4545
:::
4646

packages/cli/src/commands/build.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import terminalLink from 'terminal-link'
22

3+
import c from '../lib/colors'
4+
import { exitWithError } from '../lib/exit'
35
import { sides } from '../lib/project'
4-
import checkForBabelConfig from '../middleware/checkForBabelConfig'
6+
import { checkNodeVersion } from '../middleware/checkNodeVersion'
57

68
export const command = 'build [side..]'
79
export const description = 'Build for production'
@@ -47,7 +49,18 @@ export const builder = (yargs) => {
4749
default: false,
4850
description: 'Measure build performance',
4951
})
50-
.middleware(checkForBabelConfig)
52+
.middleware(() => {
53+
const check = checkNodeVersion()
54+
55+
if (check.ok) {
56+
return
57+
}
58+
59+
exitWithError(undefined, {
60+
message: `${c.error('Error')}: ${check.message}`,
61+
includeEpilogue: false,
62+
})
63+
})
5164
.epilogue(
5265
`Also see the ${terminalLink(
5366
'Redwood CLI Reference',

packages/cli/src/commands/dev.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import terminalLink from 'terminal-link'
22

3-
import checkForBabelConfig from '../middleware/checkForBabelConfig'
3+
import c from '../lib/colors'
4+
import { checkNodeVersion } from '../middleware/checkNodeVersion'
45

56
export const command = 'dev [side..]'
67
export const description = 'Start development servers for api, and web'
8+
79
export const builder = (yargs) => {
810
yargs
911
.positional('side', {
@@ -32,7 +34,15 @@ export const builder = (yargs) => {
3234
description:
3335
'Port on which to expose API server debugger. If you supply the flag with no value it defaults to 18911.',
3436
})
35-
.middleware(checkForBabelConfig)
37+
.middleware(() => {
38+
const check = checkNodeVersion()
39+
40+
if (check.ok) {
41+
return
42+
}
43+
44+
console.warn(`${c.warning('Warning')}: ${check.message}\n`)
45+
})
3646
.epilogue(
3747
`Also see the ${terminalLink(
3848
'Redwood CLI Reference',

packages/cli/src/commands/setup/deploy/__tests__/__snapshots__/netlify.test.js.snap

+32-22
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ exports[`netlify should add netlify.toml 1`] = `
66
publish = "web/dist"
77
functions = "api/dist/functions"
88
9-
[dev]
10-
# To use [Netlify Dev](https://www.netlify.com/products/dev/),
11-
# install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
12-
# and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
13-
# to connect your local project to a site already on Netlify
14-
# then run netlify dev and our app will be accessible on the port specified below
15-
framework = "redwoodjs"
16-
# Set targetPort to the [web] side port as defined in redwood.toml
17-
targetPort = 8910
18-
# Point your browser to this port to access your RedwoodJS app
19-
port = 8888
9+
[build.environment]
10+
NODE_VERSION = "20"
2011
2112
[[redirects]]
2213
from = "/*"
2314
to = "/200.html"
2415
status = 200
16+
17+
# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use \`netlify link\`
18+
# to connect your local project to a site on Netlify. Then run \`netlify dev\`.
19+
#
20+
# Quick links to the docs:
21+
# - Netlfy Dev https://www.netlify.com/products/dev
22+
# - Netlify's CLI https://docs.netlify.com/cli/get-started/#installation
23+
# - \`netlify link\` https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
24+
[dev]
25+
framework = "redwoodjs"
26+
# Make sure \`targetPort\` matches \`web.port\` in the \`redwood.toml\`:
27+
targetPort = 8910
28+
# Point your browser to this port to access your app:
29+
port = 8888
2530
"
2631
`;
2732

@@ -31,21 +36,26 @@ exports[`netlify should call the handler without error 1`] = `
3136
publish = "web/dist"
3237
functions = "api/dist/functions"
3338
34-
[dev]
35-
# To use [Netlify Dev](https://www.netlify.com/products/dev/),
36-
# install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
37-
# and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
38-
# to connect your local project to a site already on Netlify
39-
# then run netlify dev and our app will be accessible on the port specified below
40-
framework = "redwoodjs"
41-
# Set targetPort to the [web] side port as defined in redwood.toml
42-
targetPort = 8910
43-
# Point your browser to this port to access your RedwoodJS app
44-
port = 8888
39+
[build.environment]
40+
NODE_VERSION = "20"
4541
4642
[[redirects]]
4743
from = "/*"
4844
to = "/200.html"
4945
status = 200
46+
47+
# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use \`netlify link\`
48+
# to connect your local project to a site on Netlify. Then run \`netlify dev\`.
49+
#
50+
# Quick links to the docs:
51+
# - Netlfy Dev https://www.netlify.com/products/dev
52+
# - Netlify's CLI https://docs.netlify.com/cli/get-started/#installation
53+
# - \`netlify link\` https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
54+
[dev]
55+
framework = "redwoodjs"
56+
# Make sure \`targetPort\` matches \`web.port\` in the \`redwood.toml\`:
57+
targetPort = 8910
58+
# Point your browser to this port to access your app:
59+
port = 8888
5060
"
5161
`;

packages/cli/src/commands/setup/deploy/templates/netlify.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ import { getConfig } from '../../../../lib'
22

33
const config = getConfig()
44

5-
export const NETLIFY_TOML = `[build]
5+
export const NETLIFY_TOML = `\
6+
[build]
67
command = "yarn rw deploy netlify"
78
publish = "web/dist"
89
functions = "api/dist/functions"
910
10-
[dev]
11-
# To use [Netlify Dev](https://www.netlify.com/products/dev/),
12-
# install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
13-
# and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
14-
# to connect your local project to a site already on Netlify
15-
# then run netlify dev and our app will be accessible on the port specified below
16-
framework = "redwoodjs"
17-
# Set targetPort to the [web] side port as defined in redwood.toml
18-
targetPort = ${config.web.port}
19-
# Point your browser to this port to access your RedwoodJS app
20-
port = 8888
11+
[build.environment]
12+
NODE_VERSION = "20"
2113
2214
[[redirects]]
2315
from = "/*"
2416
to = "/200.html"
2517
status = 200
18+
19+
# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use \`netlify link\`
20+
# to connect your local project to a site on Netlify. Then run \`netlify dev\`.
21+
#
22+
# Quick links to the docs:
23+
# - Netlfy Dev https://www.netlify.com/products/dev
24+
# - Netlify's CLI https://docs.netlify.com/cli/get-started/#installation
25+
# - \`netlify link\` https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
26+
[dev]
27+
framework = "redwoodjs"
28+
# Make sure \`targetPort\` matches \`web.port\` in the \`redwood.toml\`:
29+
targetPort = ${config.web.port}
30+
# Point your browser to this port to access your app:
31+
port = 8888
2632
`

packages/cli/src/commands/setup/deploy/templates/render.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@ import { getPaths } from '../../../../lib'
55
export const PROJECT_NAME = path.basename(getPaths().base)
66

77
export const RENDER_YAML = (database) => {
8-
return `#####
9-
# Documentation
10-
# Redwood: https://render.com/docs/deploy-redwood
11-
# YAML (all config values): https://render.com/docs/yaml-spec
12-
#####
8+
return `# Quick links to the docs:
9+
# - Redwood on Render: https://render.com/docs/deploy-redwood
10+
# - Render's Blueprint spec: https://render.com/docs/yaml-spec
1311
1412
services:
1513
- name: ${PROJECT_NAME}-web
1614
type: web
1715
env: static
18-
buildCommand: yarn install && yarn rw deploy render web
16+
buildCommand: corepack enable && yarn install && yarn rw deploy render web
1917
staticPublishPath: ./web/dist
18+
2019
envVars:
21-
- key: NODE_VERSION
22-
value: 18
2320
- key: SKIP_INSTALL_DEPS
2421
value: true
22+
2523
routes:
2624
- type: rewrite
2725
source: /.redwood/functions/*
28-
#####
29-
# NOTE: replace destination api url after first deploy to Render
30-
# example:
31-
# destination: https://myredwoodproject-api.onrender.com/*
32-
#####
26+
# Replace \`destination\` here after your first deploy:
27+
#
28+
# \`\`\`
29+
# destination: https://my-redwood-project-api.onrender.com/*
30+
# \`\`\`
3331
destination: replace_with_api_url/*
3432
- type: rewrite
3533
source: /*
@@ -40,35 +38,37 @@ services:
4038
plan: free
4139
env: node
4240
region: oregon
43-
buildCommand: yarn && yarn rw build api
41+
buildCommand: corepack enable && yarn && yarn rw build api
4442
startCommand: yarn rw deploy render api
43+
4544
envVars:
46-
- key: NODE_VERSION
47-
value: 18
4845
${database}
4946
`
5047
}
5148

52-
export const POSTGRES_YAML = ` - key: DATABASE_URL
49+
export const POSTGRES_YAML = `\
50+
- key: DATABASE_URL
5351
fromDatabase:
5452
name: ${PROJECT_NAME}-db
5553
property: connectionString
5654
5755
databases:
5856
- name: ${PROJECT_NAME}-db
59-
region: oregon
60-
`
57+
region: oregon`
6158

62-
export const SQLITE_YAML = ` - key: DATABASE_URL
59+
export const SQLITE_YAML = `\
60+
- key: DATABASE_URL
6361
value: file:./data/sqlite.db
6462
disk:
6563
name: sqlite-data
6664
mountPath: /opt/render/project/src/api/db/data
6765
sizeGB: 1`
6866

69-
export const RENDER_HEALTH_CHECK = `// render-health-check
67+
export const RENDER_HEALTH_CHECK = `\
68+
// render-health-check
7069
export const handler = async () => {
7170
return {
7271
statusCode: 200,
7372
}
74-
}`
73+
}
74+
`

packages/cli/src/lib/exit.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@ export function exitWithError(
3939
const line = chalk.red('-'.repeat(process.stderr.columns))
4040

4141
// Generate and print a nice message to the user
42-
const content = [
43-
line,
44-
message,
45-
includeEpilogue && `\n${line}`,
46-
includeEpilogue && epilogue,
47-
includeReferenceCode &&
48-
` - Here's your unique error reference to quote: '${errorReferenceCode}'`,
49-
line,
50-
]
51-
.filter(Boolean)
52-
.join('\n')
53-
54-
console.error()
42+
const content = !includeEpilogue
43+
? message
44+
: [
45+
'',
46+
line,
47+
message,
48+
`\n${line}`,
49+
epilogue,
50+
includeReferenceCode &&
51+
` - Here's your unique error reference to quote: '${errorReferenceCode}'`,
52+
line,
53+
]
54+
.filter(Boolean)
55+
.join('\n')
56+
5557
console.error(content)
5658

5759
// Record the error in telemetry

packages/cli/src/middleware/checkForBabelConfig.js

-41
This file was deleted.

0 commit comments

Comments
 (0)