Repository navigation
Conversation
`netlify deploy --prod` and `--prod-if-unlocked` resolved the CLI config and deployed function env vars with the `dev` context, so `[context.production]` overrides were ignored (e.g. `--no-build --prod` deployed the base publish directory). An explicit `--context` or the `CONTEXT` env var still take precedence. Fixes netlify#5875 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efault Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
Note 🤖 Claude Opus 5.5 responding on behalf of RealDoc06 @netlify/pod-experience could someone approve the workflow runs? All checks are waiting on "action required" because this is a first-time contribution. Locally, typecheck, lint, format, the deploy unit tests (35) and the deploy integration tests (90) pass. The one known failure, the |
Summary
Fixes #5875
netlify deploy --prodignored[context.production]settings because the CLI resolved its config with thedevcontext. Production deploys now default toproduction, while--contextandCONTEXTstill win.Problem
netlify deploy --prod(and--prod-if-unlocked) resolved the CLI's config with thedevcontext. As a result,[context.production]overrides innetlify.tomlwere ignored wherever the CLI used its own config. For example, with this config:netlify deploy --no-build --proddeployedpublic, notpublic-production.Root cause:
BaseCommand.getConfigresolves config with--context || CONTEXT || getDefaultContext()(src/commands/base-command.ts).getDefaultContext()returnedproductiononly forserve, so--prodnever affected it. That config is resolved in thepreActionhook, before the deploy action runs.--no-builddeploys (publish and functions dirs, edge functions, headers and redirects), framework detection andcachedConfig.env.options.context(src/commands/deploy/deploy.ts). That falls back todevingetEnvelopeEnvunless--contextis passed, soAWS_LAMBDA_JS_RUNTIMEcame fromdev.The build step from the original report (
--build --prodloggingContext: dev) no longer reproduces on main. Deploy always passesdefaultConfigto@netlify/build, so@netlify/configre-resolves config with its own default ofCONTEXT || 'production'(@netlify/config/lib/options/main.js). The CLI-side resolution is what was still wrong.Fix
getDefaultContext()returnsproductionfordeploywhen--prodor--prod-if-unlockedis set. The precedence moves intoBaseCommand.getContext():--context, thenCONTEXT, then the default. An explicit--contextor theCONTEXTenv var still wins.command.netlify.cachedConfig.context, the same context the config was resolved with.--contexthelp text anddocs/commands/deploy.mdsaid the default wasdev, which was never true for the build step. Since--contextonly works with--build, the text now describes the build default, matchingnetlify build:value of CONTEXT or "production".eslint-suppressions.jsondrops oneno-unsafe-assignment, because the inlineflags.contextread (any) is now typed.--prod-if-unlockedIt defaults to
production, whether or not the site is locked. Config is resolved before the site and its lock state are known, and the lock only decides whether the deploy is published, not what gets built. This matches Netlify itself: a locked production branch still builds in the production context, it just isn't auto-published. So a locked--prod-if-unlockeddeploy uploads the production artifact as a draft.Behavior notes
CONTEXTare unchanged. The CLI-side config and functions env lookup still usedev, and the build still usesproductionthrough@netlify/build. That inconsistency is older than this PR and left out of scope, because changing draft builds would change the env vars existing users get.CONTEXTset now uses that context for the functions env lookup (previouslydev). This matches the config the CLI already resolved fromCONTEXT.--remoteand--triggerdon't read the CLI's resolved context, so they're unaffected.Testing
tests/unit/commands/deploy/context.test.tsparses the real deploy command and checks precedence:--draftresolve todev--prodand--prod-if-unlockedresolve toproduction--contextwins over--prodCONTEXTwins over the default--contextwins overCONTEXTtests/integration/commands/deploy/deploy.test.ts:--no-build --prodpublishes[context.production].publish, and a draft publishes the basepublish. It fails against main'sbase-command.tsand needs no Netlify token.--prod,--prod-if-unlockedand--prod --context deploy-preview, before and after the change.npm run typecheck,npm run lintandnpm run format:checkpass. The deploy unit tests pass (35), and so do all deploy integration tests under--retry=3(90). Integration tests that need a real Netlify token were not run.tests/unit/lib/completion/generate-autocompletion.test.tsfails on main under Node 26 (option ordering in the snapshot). This PR doesn't cause it.For us to review and ship your PR efficiently, please perform the following steps:
can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
something that`s on fire 🔥 (e.g. incident related), you can skip this step.
passes our tests.
Council review
Rounds: 4
Created with Claude Opus 5.5 in Claude Code (T3 Code).
🤖 Generated with Claude Code