-
Notifications
You must be signed in to change notification settings - Fork 412
feat: run framework detection and run plugins on netlify build #5029
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
Changes from all commits
acc33c1
c6bc044
48d942a
777bf7c
a3577ee
052512c
4fb9d96
0dd120b
ebb71ba
0b0cd55
3c87f58
ee780e5
94a4a4d
10bc1a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ const process = require('process') | |
|
||
const netlifyBuildPromise = import('@netlify/build') | ||
|
||
const { NETLIFYDEVERR, detectServerSettings, error, log } = require('../utils') | ||
|
||
/** | ||
* The buildConfig + a missing cachedConfig | ||
* @typedef BuildConfig | ||
|
@@ -41,11 +43,20 @@ const getBuildOptions = ({ cachedConfig, options: { context, cwd, debug, dry, js | |
|
||
/** | ||
* run the build command | ||
* @param {BuildConfig} options | ||
* @param {BuildConfig} buildOptions | ||
* @param {import('../commands/base-command').BaseCommand} command | ||
* @param {import('commander').OptionValues} commandOptions | ||
* @returns | ||
*/ | ||
const runBuild = async (options) => { | ||
const runBuild = async (buildOptions, command, commandOptions) => { | ||
sarahetter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { default: build } = await netlifyBuildPromise | ||
const { cachedConfig, config, site } = command.netlify | ||
const devConfig = { | ||
framework: '#auto', | ||
...(config.functionsDirectory && { functions: config.functionsDirectory }), | ||
...config.dev, | ||
...commandOptions, | ||
} | ||
|
||
// If netlify NETLIFY_API_URL is set we need to pass this information to @netlify/build | ||
// TODO don't use testOpts, but add real properties to do this. | ||
|
@@ -55,10 +66,52 @@ const runBuild = async (options) => { | |
scheme: apiUrl.protocol.slice(0, -1), | ||
host: apiUrl.host, | ||
} | ||
options = { ...options, testOpts } | ||
buildOptions = { ...buildOptions, testOpts } | ||
} | ||
|
||
/** @type {Partial<import('../../utils/types').ServerSettings>} */ | ||
let settings = {} | ||
try { | ||
settings = await detectServerSettings(devConfig, commandOptions, site.root) | ||
|
||
const defaultConfig = { build: {} } | ||
|
||
if (settings.buildCommand && settings.dist) { | ||
buildOptions.cachedConfig.config.build.command = settings.buildCommand | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the sort of question that is tricky to answer without types in place, but is there a chance that some of these intermediate properties will be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did some chasing here, and found that cachedConfig is created by I'm not sure what I should do to safeguard against that situation popping up if there's a breaking change in But wow, wouldn't this all be so much nicer with Typescript π |
||
defaultConfig.build.command = settings.buildCommand | ||
buildOptions.cachedConfig.config.build.publish = settings.buildCommand | ||
defaultConfig.build.publish = settings.dist | ||
} | ||
|
||
if (defaultConfig.build.command && defaultConfig.build.publish) { | ||
buildOptions.defaultConfig = defaultConfig | ||
} | ||
|
||
// If there are plugins that we should be running for this site, add them | ||
// to the config as if they were declared in netlify.toml. We must check | ||
// whether the plugin has already been added by another source (like the | ||
// TOML file or the UI), as we don't want to run the same plugin twice. | ||
if (settings.plugins) { | ||
const { plugins: existingPlugins = [] } = cachedConfig.config | ||
const existingPluginNames = new Set(existingPlugins.map((plugin) => plugin.package)) | ||
const newPlugins = settings.plugins | ||
.map((pluginName) => { | ||
if (existingPluginNames.has(pluginName)) { | ||
return | ||
} | ||
|
||
return { package: pluginName, origin: 'config', inputs: {} } | ||
}) | ||
.filter(Boolean) | ||
|
||
buildOptions.cachedConfig.config.plugins = [...newPlugins, ...cachedConfig.config.plugins] | ||
} | ||
} catch (detectServerSettingsError) { | ||
log(NETLIFYDEVERR, detectServerSettingsError.message) | ||
error(detectServerSettingsError) | ||
} | ||
|
||
const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(options) | ||
const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(buildOptions) | ||
return { exitCode, newConfig, configMutations } | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.