Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"is-plain-obj": "^4.0.0",
"keep-func-props": "^6.0.0",
"log-process-errors": "^11.0.0",
"map-obj": "^5.0.0",
"memoize-one": "^6.0.0",
"minimatch": "^9.0.4",
"os-name": "^6.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/build/src/core/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { resolveConfig, restoreConfig, updateConfig } from '@netlify/config'
import mapObj from 'map-obj'

import { getChildEnv } from '../env/main.js'
import { addApiErrorHandlers } from '../error/api.js'
Expand Down Expand Up @@ -95,7 +94,7 @@ const tLoadConfig = async function ({
}

const apiA = addApiErrorHandlers(api)
const envValues = mapObj(env, (key, { value }) => [key, value])
const envValues = Object.fromEntries(Object.entries(env).map(([key, { value }]) => [key, value]))
const childEnv = getChildEnv({ envOpt, env: envValues })
const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)])
return {
Expand Down
7 changes: 3 additions & 4 deletions packages/build/src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { relative, normalize, join } from 'path'

import { getCacheDir } from '@netlify/cache-utils'
import mapObj from 'map-obj'
import { pathExists } from 'path-exists'

import { ROOT_PACKAGE_JSON } from '../utils/json.js'
Expand Down Expand Up @@ -201,14 +200,14 @@ const addDefaultConstant = async function ({ constants, constantName, defaultPat
}

const normalizeConstantsPaths = function (constants: Partial<NetlifyPluginConstants>, buildDir: string) {
return mapObj(constants, (key, path: string) => [key, normalizePath(path, buildDir, key)])
return Object.fromEntries(Object.entries(constants).map(([key, path]) => [key, normalizePath(path, buildDir, key)]))
}

// The current directory is `buildDir`. Most constants are inside this `buildDir`.
// Instead of passing absolute paths, we pass paths relative to `buildDir`, so
// that logs are less verbose.
const normalizePath = function (path: string | undefined, buildDir: string, key: string) {
if (path === undefined || path === '' || !CONSTANT_PATHS.has(key)) {
const normalizePath = function (path: string | undefined | boolean, buildDir: string, key: string) {
if (typeof path !== 'string' || path === '' || !CONSTANT_PATHS.has(key)) {
return path
}

Expand Down
5 changes: 2 additions & 3 deletions packages/build/src/env/changes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { env } from 'process'

import { includeKeys } from 'filter-obj'
import mapObj from 'map-obj'

// If plugins modify `process.env`, this is propagated in other plugins and in
// `build.command`. Since those are different processes, we figure out when they
Expand All @@ -15,15 +14,15 @@ export const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfi
const diffEnv = function (envBefore, envAfter) {
const envChanges = includeKeys(envAfter, (name, value) => value !== envBefore[name])
const deletedEnv = includeKeys(envBefore, (name) => envAfter[name] === undefined)
const deletedEnvA = mapObj(deletedEnv, setToNull)
const deletedEnvA = Object.fromEntries(Object.entries(deletedEnv).map(setToNull))
return { ...envChanges, ...deletedEnvA }
}

// `undefined` is not JSON-serializable (which is used in process IPC), so we
// convert it to `null`
// Note: `process.env[name] = undefined` actually does
// `process.env[name] = 'undefined'` in Node.js.
const setToNull = function (name) {
const setToNull = function ([name]) {
return [name, null]
}

Expand Down
5 changes: 2 additions & 3 deletions packages/build/src/error/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isPlainObj from 'is-plain-obj'
import mapObj from 'map-obj'

import { addErrorInfo } from './info.js'

Expand All @@ -9,10 +8,10 @@ export const addApiErrorHandlers = function (api) {
return
}

return mapObj(api, addErrorHandler)
return Object.fromEntries(Object.entries(api).map(addErrorHandler))
}

const addErrorHandler = function (key, value) {
const addErrorHandler = function ([key, value]) {
if (typeof value !== 'function') {
return [key, value]
}
Expand Down
5 changes: 2 additions & 3 deletions packages/build/src/plugins/child/status.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isPlainObj from 'is-plain-obj'
import mapObj from 'map-obj'

import { addErrorInfo } from '../../error/info.js'

Expand Down Expand Up @@ -62,10 +61,10 @@ const validateShowArgsExtraData = function (extraData) {
}

const removeEmptyStrings = function (showArgs) {
return mapObj(showArgs, removeEmptyString)
return Object.fromEntries(Object.entries(showArgs).map(removeEmptyString))
}

const removeEmptyString = function (key, value) {
const removeEmptyString = function ([key, value]) {
if (typeof value === 'string' && value.trim() === '') {
return [key]
}
Expand Down
33 changes: 20 additions & 13 deletions packages/build/src/plugins_core/frameworks_api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { promises as fs } from 'fs'
import { resolve } from 'path'

import isPlainObject from 'is-plain-obj'
import mapObject, { mapObjectSkip } from 'map-obj'

import type { NetlifyConfig } from '../../index.js'
import { FRAMEWORKS_API_CONFIG_ENDPOINT } from '../../utils/frameworks_api.js'
Expand Down Expand Up @@ -67,20 +66,28 @@ export const filterConfig = (
allowedProperties: string[][],
systemLog: SystemLogger,
): Record<string, unknown> =>
mapObject(obj, (key, value) => {
const keyPath = [...path, key]
Object.fromEntries(
Object.entries(obj)
.filter(([key]) => {
const keyPath = [...path, key]

if (!isAllowedProperty(keyPath, allowedProperties)) {
systemLog(`Discarding property that is not supported by the Deploy Configuration API: ${keyPath.join('.')}`)
if (!isAllowedProperty(keyPath, allowedProperties)) {
systemLog(`Discarding property that is not supported by the Deploy Configuration API: ${keyPath.join('.')}`)

return mapObjectSkip
}
return false
}

if (!isPlainObject(value)) {
systemLog(`Loading property from Deploy Configuration API: ${keyPath.join('.')}`)
return true
})
.map(([key, value]) => {
const keyPath = [...path, key]

return [key, value]
}
if (!isPlainObject(value)) {
systemLog(`Loading property from Deploy Configuration API: ${keyPath.join('.')}`)

return [key, value]
}

return [key, filterConfig(value, keyPath, allowedProperties, systemLog)]
})
return [key, filterConfig(value, keyPath, allowedProperties, systemLog)]
}),
)
11 changes: 6 additions & 5 deletions packages/build/src/plugins_core/functions/zisi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { join, resolve } from 'path'

import { type FunctionConfig, type ZipFunctionsOptions } from '@netlify/zip-it-and-ship-it'
import mapObject from 'map-obj'
import semver from 'semver'

import type { FeatureFlags } from '../../core/feature_flags.js'
Expand Down Expand Up @@ -55,10 +54,12 @@ export const getZisiParameters = ({
}: GetZisiParametersType): ZipFunctionsOptions => {
const nodeVersion = getLambdaNodeVersion(childEnv, userNodeVersion)
const manifest = join(functionsDist, 'manifest.json')
const config = mapObject(functionsConfig, (expression, object) => [
expression,
normalizeFunctionConfig({ buildDir, functionConfig: object, isRunningLocally, nodeVersion }),
])
const config = Object.fromEntries(
Object.entries(functionsConfig).map(([expression, object]) => [
expression,
normalizeFunctionConfig({ buildDir, functionConfig: object, isRunningLocally, nodeVersion }),
]),
)
const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)

// Only the legacy internal functions directory is allowed to have a JSON
Expand Down
Loading