Skip to content

Commit 8e95c58

Browse files
authored
feat!: run build before deploy (#7195)
This small change updates the `deploy` command to run the configured `build` command before deployment. Users who prefer the previous behavior can opt out by specifying `--no-build` when running `netlify deploy`.
1 parent 0d48c28 commit 8e95c58

File tree

3 files changed

+170
-66
lines changed

3 files changed

+170
-66
lines changed

docs/commands/deploy.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ netlify deploy
8686

8787
- `alias` (*string*) - Specifies the alias for deployment, the string at the beginning of the deploy subdomain. Useful for creating predictable deployment URLs. Avoid setting an alias string to the same value as a deployed branch. `alias` doesn’t create a branch deploy and can’t be used in conjunction with the branch subdomain feature. Maximum 37 characters.
8888
- `branch` (*string*) - Serves the same functionality as --alias. Deprecated and will be removed in future versions
89-
- `build` (*boolean*) - Run build command before deploying
9089
- `context` (*string*) - Specify a deploy context for environment variables read during the build (”production”, ”deploy-preview”, ”branch-deploy”, ”dev”) or `branch:your-branch` where `your-branch` is the name of a branch (default: dev)
9190
- `dir` (*string*) - Specify a folder to deploy
9291
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in
9392
- `functions` (*string*) - Specify a functions folder to deploy
9493
- `json` (*boolean*) - Output deployment data as JSON
9594
- `message` (*string*) - A short message to include in the deploy log
95+
- `no-build` (*boolean*) - Do not run build command before deploying. Only use this if you have no need for a build or your site has already been built.
9696
- `prod-if-unlocked` (*boolean*) - Deploy to production if unlocked, create a draft otherwise
9797
- `debug` (*boolean*) - Print debugging information
9898
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in
@@ -108,13 +108,14 @@ netlify deploy
108108
```bash
109109
netlify deploy
110110
netlify deploy --site my-first-site
111+
netlify deploy --no-build # Deploy without running a build first
111112
netlify deploy --prod
112113
netlify deploy --prod --open
113114
netlify deploy --prod-if-unlocked
114115
netlify deploy --message "A message with an $ENV_VAR"
115116
netlify deploy --auth $NETLIFY_AUTH_TOKEN
116117
netlify deploy --trigger
117-
netlify deploy --build --context deploy-preview
118+
netlify deploy --context deploy-preview
118119
```
119120

120121

src/commands/deploy/index.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { env } from 'process'
33
import { Option } from 'commander'
44

55
import BaseCommand from '../base-command.js'
6-
import { logAndThrowError, warn } from '../../utils/command-helpers.js'
6+
import { chalk, logAndThrowError, warn } from '../../utils/command-helpers.js'
77
import type { DeployOptionValues } from './option_values.js'
88

99
export const createDeployCommand = (program: BaseCommand) =>
@@ -109,7 +109,19 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
109109
'build',
110110
),
111111
)
112-
.option('--build', 'Run build command before deploying', false)
112+
.addOption(
113+
new Option('--build', 'Do not use - this is now the default. Will be removed in future versions.')
114+
.default(true)
115+
.hideHelp(true),
116+
)
117+
/**
118+
* Note that this has special meaning to commander. It negates the above `build` option.
119+
* @see https://github.com/tj/commander.js/tree/83c3f4e391754d2f80b179acc4bccc2d4d0c863d?tab=readme-ov-file#other-option-types-negatable-boolean-and-booleanvalue
120+
*/
121+
.option(
122+
'--no-build',
123+
'Do not run build command before deploying. Only use this if you have no need for a build or your site has already been built.',
124+
)
113125
.option(
114126
'--context <context>',
115127
'Specify a deploy context for environment variables read during the build (”production”, ”deploy-preview”, ”branch-deploy”, ”dev”) or `branch:your-branch` where `your-branch` is the name of a branch (default: dev)',
@@ -122,15 +134,24 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
122134
.addExamples([
123135
'netlify deploy',
124136
'netlify deploy --site my-first-site',
137+
'netlify deploy --no-build # Deploy without running a build first',
125138
'netlify deploy --prod',
126139
'netlify deploy --prod --open',
127140
'netlify deploy --prod-if-unlocked',
128141
'netlify deploy --message "A message with an $ENV_VAR"',
129142
'netlify deploy --auth $NETLIFY_AUTH_TOKEN',
130143
'netlify deploy --trigger',
131-
'netlify deploy --build --context deploy-preview',
144+
'netlify deploy --context deploy-preview',
132145
])
133146
.action(async (options: DeployOptionValues, command: BaseCommand) => {
147+
if (options.build && command.getOptionValueSource('build') === 'cli') {
148+
warn(
149+
`${chalk.cyanBright(
150+
'--build',
151+
)} is now the default and can safely be omitted. This will fail in a future version.`,
152+
)
153+
}
154+
134155
if (options.branch) {
135156
warn('--branch flag has been renamed to --alias and will be removed in future versions')
136157
}

0 commit comments

Comments
 (0)