-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix local builds with plugins and build settings from the ui #4929
Conversation
@@ -20,6 +22,7 @@ const netlifyBuildPromise = import('@netlify/build') | |||
*/ | |||
const getBuildOptions = ({ cachedConfig, options: { context, cwd, debug, dry, json, offline, silent }, token }) => ({ | |||
cachedConfig, | |||
siteId: cachedConfig.siteInfo.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, and this only is the fix, the rest is for the tests.
📊 Benchmark resultsComparing with f1d1d91 Package size: 222 MB(no change)
Legend
|
host: apiUrl.host, | ||
} | ||
options = { ...options, testOpts } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not nice,.
The host
could be supplied by setting apiHost
but the scheme cannot be changed besides the testOpts.
I'm also not sure if NETLIFY_API_URL
is only for tests or if that is meant to be used by users?
Should I add apiScheme
to @netlify/build
? Or is it okay this way?
@@ -9,7 +9,6 @@ const { withSiteBuilder } = require('./utils/site-builder') | |||
|
|||
const defaultEnvs = { | |||
NETLIFY_AUTH_TOKEN: 'fake-token', | |||
NETLIFY_SITE_ID: 'site_id', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to not set it for every test here, because it does not really reflect real world scenarios.
If NETLIFY_SITE_ID
is set this bug I'm fixing here never surfaces, because @netlify/build
and @netlify/config
both also read it.
But most users never set it probably.
I instead opted to add a new method to the site-builder withStateFile
, which mimics netlify link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite the journey to get this bug sorted. Thanks for the detailed summary and the fix, this LGTM 🚀
Summary
This is a long story. I was debugging yesterday for hours.
Problem
The initial problem was that I tried deploying a nextjs site from the cli and it did not work. The setup is as following:
netlify.toml
)netlify link
doneWhen I tried deploying this site, the nextjs-plugin would be installed automatically, but during the build at first the
onPreBuild
would run for the nextjs-plugin. Next theonBuild
for the nextjs-plugin woudl run and this fails because the build command was not triggered at all.Investigation
After hours of trying to understand
@netlify/build
and it's connection to the cli and to@netlify/config
I found out what is happening. Let me try to summarize:@netlify/config
for the config and gets the correct config back (including ui settings)@netlify/build
is called with the config supplied from the cliresolveInitialConfig
is called in@netlify/build
which respects the passed in config from the cli. all fine so faronPreBuild
event is triggered for the build plugin and the plugin makes changes to the config.@netlify/build
computes a config changeset calledconfigMutation
. This details exactly what the plugin changed in the config, in order to be able to print the changes to the output but also to be always able to reapply these changes again to a config object.@netlify/config
to get a fresh copy of the config and with theconfigMutations
applied. Because we didn't suppliedsiteId
in the first place this now failed to grab anything from the API which is site related. So at this point we basically revert the config to some default values (no build command, publish directory = root directory, etc.) and this is the reason that my build command is never run.By adding the
siteId
to the input Options it all starts working again, and this is now inline with buildbot, which also supplies thesiteId
.