Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/cleanup-flags
Browse files Browse the repository at this point in the history
eduardoboucas committed Jun 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents a217851 + ec3bcc8 commit dc7e08a
Showing 83 changed files with 989 additions and 226 deletions.
6 changes: 3 additions & 3 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"packages/build-info": "7.13.2",
"packages/build": "29.48.1",
"packages/build": "29.48.2",
"packages/edge-bundler": "12.0.1",
"packages/cache-utils": "5.1.5",
"packages/config": "20.15.3",
"packages/framework-info": "9.8.13",
"packages/functions-utils": "5.2.68",
"packages/functions-utils": "5.2.69",
"packages/git-utils": "5.1.1",
"packages/headers-parser": "7.1.4",
"packages/js-client": "13.1.19",
@@ -14,5 +14,5 @@
"packages/run-utils": "5.1.1",
"packages/opentelemetry-sdk-setup": "1.1.3",
"packages/opentelemetry-utils": "1.2.1",
"packages/zip-it-and-ship-it": "9.37.0"
"packages/zip-it-and-ship-it": "9.37.1"
}
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -105,6 +105,16 @@
* dependencies
* @netlify/config bumped from ^20.8.0 to ^20.8.1

## [29.48.2](https://github.com/netlify/build/compare/build-v29.48.1...build-v29.48.2) (2024-06-18)


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @netlify/functions-utils bumped from ^5.2.68 to ^5.2.69
* @netlify/zip-it-and-ship-it bumped from 9.37.0 to 9.37.1

## [29.48.1](https://github.com/netlify/build/compare/build-v29.48.0...build-v29.48.1) (2024-06-17)


6 changes: 3 additions & 3 deletions packages/build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@netlify/build",
"version": "29.48.1",
"version": "29.48.2",
"description": "Netlify build module",
"type": "module",
"exports": "./lib/index.js",
@@ -73,12 +73,12 @@
"@netlify/config": "^20.15.3",
"@netlify/edge-bundler": "12.0.1",
"@netlify/framework-info": "^9.8.13",
"@netlify/functions-utils": "^5.2.68",
"@netlify/functions-utils": "^5.2.69",
"@netlify/git-utils": "^5.1.1",
"@netlify/opentelemetry-utils": "^1.2.1",
"@netlify/plugins-list": "^6.80.0",
"@netlify/run-utils": "^5.1.1",
"@netlify/zip-it-and-ship-it": "9.37.0",
"@netlify/zip-it-and-ship-it": "9.37.1",
"@sindresorhus/slugify": "^2.0.0",
"ansi-escapes": "^6.0.0",
"chalk": "^5.0.0",
2 changes: 1 addition & 1 deletion packages/build/src/core/build.ts
Original file line number Diff line number Diff line change
@@ -637,7 +637,7 @@ const runBuild = async function ({
timeline === 'dev' ? getDevSteps(devCommand, pluginsSteps, eventHandlers) : getSteps(pluginsSteps, eventHandlers)

if (dry) {
await doDryRun({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs })
await doDryRun({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs, featureFlags })
return { netlifyConfig }
}

28 changes: 18 additions & 10 deletions packages/build/src/core/dry.js
Original file line number Diff line number Diff line change
@@ -4,22 +4,28 @@ import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry
import { runsOnlyOnBuildFailure } from '../plugins/events.js'

// If the `dry` flag is specified, do a dry run
export const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
export const doDryRun = async function ({
buildDir,
steps,
netlifyConfig,
constants,
buildbotServerSocket,
logs,
featureFlags,
}) {
const successSteps = await pFilter(steps, ({ event, condition }) =>
shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket }),
shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket, featureFlags }),
)
const eventWidth = Math.max(...successSteps.map(getEventLength))
const stepsCount = successSteps.length

logDryRunStart({ logs, eventWidth, stepsCount })

successSteps.forEach((step, index) => {
if (step.quiet) {
return
}

logDryRunStep({ logs, step, index, netlifyConfig, eventWidth, stepsCount })
})
successSteps
.filter((step) => !step.quiet)
.forEach((step, index) => {
logDryRunStep({ logs, step, index, netlifyConfig, eventWidth, stepsCount })
})

logDryRunEnd(logs)
}
@@ -31,10 +37,12 @@ const shouldIncludeStep = async function ({
netlifyConfig,
constants,
buildbotServerSocket,
featureFlags,
}) {
return (
!runsOnlyOnBuildFailure(event) &&
(condition === undefined || (await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket })))
(condition === undefined ||
(await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket, featureFlags })))
)
}

1 change: 1 addition & 0 deletions packages/build/src/core/feature_flags.ts
Original file line number Diff line number Diff line change
@@ -19,5 +19,6 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
buildbot_zisi_esbuild_parser: false,
netlify_build_reduced_output: false,
netlify_build_updated_plugin_compatibility: false,
netlify_build_frameworks_api: false,
netlify_build_plugin_system_log: false,
}
12 changes: 11 additions & 1 deletion packages/build/src/log/messages/core_steps.js
Original file line number Diff line number Diff line change
@@ -59,13 +59,23 @@ export const logFunctionsToBundle = function ({
userFunctionsSrcExists,
internalFunctions,
internalFunctionsSrc,
frameworkFunctions,
type = 'Functions',
}) {
if (internalFunctions.length !== 0) {
log(logs, `Packaging ${type} from ${THEME.highlightWords(internalFunctionsSrc)} directory:`)
logArray(logs, internalFunctions, { indent: false })
}

if (frameworkFunctions.length !== 0) {
if (internalFunctions.length !== 0) {
log(logs, '')
}

log(logs, `Packaging ${type} generated by your framework:`)
logArray(logs, frameworkFunctions, { indent: false })
}

if (!userFunctionsSrcExists) {
return
}
@@ -76,7 +86,7 @@ export const logFunctionsToBundle = function ({
return
}

if (internalFunctions.length !== 0) {
if (internalFunctions.length !== 0 || frameworkFunctions.length !== 0) {
log(logs, '')
}

20 changes: 11 additions & 9 deletions packages/build/src/plugins_core/blobs_upload/index.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import semver from 'semver'
import { DEFAULT_API_HOST } from '../../core/normalize_flags.js'
import { logError } from '../../log/logger.js'
import { getFileWithMetadata, getKeysToUpload, scanForBlobs } from '../../utils/blobs.js'
import { getBlobs } from '../../utils/frameworks_api.js'
import { type CoreStep, type CoreStepCondition, type CoreStepFunction } from '../types.js'

const coreStep: CoreStepFunction = async function ({
@@ -46,30 +47,31 @@ const coreStep: CoreStepFunction = async function ({
return {}
}

// If using the deploy config API, configure the store to use the region that
// was configured for the deploy.
if (!blobs.isLegacyDirectory) {
// If using the deploy config API or the Frameworks API, configure the store
// to use the region that was configured for the deploy. We don't do it for
// the legacy file-based upload API since that would be a breaking change.
if (blobs.apiVersion > 1) {
storeOpts.experimentalRegion = 'auto'
}

const blobStore = getDeployStore(storeOpts)
const keys = await getKeysToUpload(blobs.directory)
const blobsToUpload = blobs.apiVersion >= 3 ? await getBlobs(blobs.directory) : await getKeysToUpload(blobs.directory)

if (keys.length === 0) {
if (blobsToUpload.length === 0) {
systemLog('No blobs to upload to deploy store.')

return {}
}

systemLog(`Uploading ${keys.length} blobs to deploy store`)
systemLog(`Uploading ${blobsToUpload.length} blobs to deploy store...`)

try {
await pMap(
keys,
async (key: string) => {
blobsToUpload,
async ({ key, contentPath, metadataPath }) => {
systemLog(`Uploading blob ${key}`)

const { data, metadata } = await getFileWithMetadata(blobs.directory, key)
const { data, metadata } = await getFileWithMetadata(key, contentPath, metadataPath)
await blobStore.set(key, data, { metadata })
},
{ concurrency: 10 },
65 changes: 44 additions & 21 deletions packages/build/src/plugins_core/deploy_config/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { promises as fs } from 'fs'
import { resolve } from 'path'

import { mergeConfigs } from '@netlify/config'

import type { NetlifyConfig } from '../../index.js'
import { getConfigMutations } from '../../plugins/child/diff.js'
import { CoreStep, CoreStepFunction } from '../types.js'

import { filterConfig } from './util.js'
import { filterConfig, loadConfigFile } from './util.js'

// The properties that can be set using this API. Each element represents a
// path using dot-notation — e.g. `["build", "functions"]` represents the
// `build.functions` property.
const ALLOWED_PROPERTIES = [['images', 'remote_images']]
const ALLOWED_PROPERTIES = [
['build', 'functions'],
['build', 'publish'],
['functions', '*'],
['functions', '*', '*'],
['headers'],
['images', 'remote_images'],
['redirects'],
]

// For array properties, any values set in this API will be merged with the
// main configuration file in such a way that user-defined values always take
// precedence. The exception are these properties that let frameworks set
// values that should be evaluated before any user-defined values. They use
// a special notation where `redirects!` represents "forced redirects", etc.
const OVERRIDE_PROPERTIES = new Set(['redirects!'])

const coreStep: CoreStepFunction = async function ({
buildDir,
@@ -22,30 +34,42 @@ const coreStep: CoreStepFunction = async function ({
// no-op
},
}) {
const configPath = resolve(buildDir, packagePath ?? '', '.netlify/deploy/v1/config.json')

let config: Partial<NetlifyConfig> = {}
let config: Partial<NetlifyConfig> | undefined

try {
const data = await fs.readFile(configPath, 'utf8')

config = JSON.parse(data) as Partial<NetlifyConfig>
config = await loadConfigFile(buildDir, packagePath)
} catch (err) {
// If the file doesn't exist, this is a non-error.
if (err.code === 'ENOENT') {
return {}
}

systemLog(`Failed to read Deploy Configuration API: ${err.message}`)
systemLog(`Failed to read Frameworks API: ${err.message}`)

throw new Error('An error occured while processing the platform configurarion defined by your framework')
}

if (!config) {
return {}
}

const configOverrides: Partial<NetlifyConfig> = {}

for (const key in config) {
// If the key uses the special notation for defining mutations that should
// take precedence over user-defined properties, extract the canonical
// property, set it on a different object, and delete it from the main one.
if (OVERRIDE_PROPERTIES.has(key)) {
const canonicalKey = key.slice(0, -1)

configOverrides[canonicalKey] = config[key]

delete config[key]
}
}

// Filtering out any properties that can't be mutated using this API.
const filteredConfig = filterConfig(config, [], ALLOWED_PROPERTIES, systemLog)

// Merging the config extracted from the API with the initial config.
const newConfig = mergeConfigs([filteredConfig, netlifyConfig], { concatenateArrays: true }) as Partial<NetlifyConfig>
const newConfig = mergeConfigs([filteredConfig, netlifyConfig, configOverrides], {
concatenateArrays: true,
}) as Partial<NetlifyConfig>

// Diffing the initial and the new configs to compute the mutations (what
// changed between them).
@@ -59,9 +83,8 @@ const coreStep: CoreStepFunction = async function ({
export const applyDeployConfig: CoreStep = {
event: 'onBuild',
coreStep,
coreStepId: 'deploy_config',
coreStepName: 'Applying Deploy Configuration',
coreStepId: 'frameworks_api_config',
coreStepName: 'Applying configuration from Frameworks API',
coreStepDescription: () => '',
condition: ({ featureFlags }) => featureFlags?.netlify_build_deploy_configuration_api,
quiet: true,
}
Loading

0 comments on commit dc7e08a

Please sign in to comment.