Skip to content

Commit 7c44533

Browse files
43081jmrstork
andauthored
fix: drop map-obj (#6577)
* chore: drop map-obj Drops the map-obj dependency and uses a basic `Object.entries` map instead. * fix: handle undefined paths * chore: drop map-obj * chore: split filter and map into two functions --------- Co-authored-by: Mateusz Bocian <[email protected]>
1 parent 79c24fe commit 7c44533

File tree

9 files changed

+36
-35
lines changed

9 files changed

+36
-35
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"is-plain-obj": "^4.0.0",
9191
"keep-func-props": "^6.0.0",
9292
"log-process-errors": "^11.0.0",
93-
"map-obj": "^5.0.0",
9493
"memoize-one": "^6.0.0",
9594
"minimatch": "^9.0.4",
9695
"os-name": "^6.0.0",

packages/build/src/core/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { resolveConfig, restoreConfig, updateConfig } from '@netlify/config'
2-
import mapObj from 'map-obj'
32

43
import { getChildEnv } from '../env/main.js'
54
import { addApiErrorHandlers } from '../error/api.js'
@@ -95,7 +94,7 @@ const tLoadConfig = async function ({
9594
}
9695

9796
const apiA = addApiErrorHandlers(api)
98-
const envValues = mapObj(env, (key, { value }) => [key, value])
97+
const envValues = Object.fromEntries(Object.entries(env).map(([key, { value }]) => [key, value]))
9998
const childEnv = getChildEnv({ envOpt, env: envValues })
10099
const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)])
101100
return {

packages/build/src/core/constants.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { relative, normalize, join } from 'path'
22

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

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

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

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

packages/build/src/env/changes.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { env } from 'process'
22

33
import { includeKeys } from 'filter-obj'
4-
import mapObj from 'map-obj'
54

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

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

packages/build/src/error/api.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import isPlainObj from 'is-plain-obj'
2-
import mapObj from 'map-obj'
32

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

@@ -9,10 +8,10 @@ export const addApiErrorHandlers = function (api) {
98
return
109
}
1110

12-
return mapObj(api, addErrorHandler)
11+
return Object.fromEntries(Object.entries(api).map(addErrorHandler))
1312
}
1413

15-
const addErrorHandler = function (key, value) {
14+
const addErrorHandler = function ([key, value]) {
1615
if (typeof value !== 'function') {
1716
return [key, value]
1817
}

packages/build/src/plugins/child/status.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import isPlainObj from 'is-plain-obj'
2-
import mapObj from 'map-obj'
32

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

@@ -62,10 +61,10 @@ const validateShowArgsExtraData = function (extraData) {
6261
}
6362

6463
const removeEmptyStrings = function (showArgs) {
65-
return mapObj(showArgs, removeEmptyString)
64+
return Object.fromEntries(Object.entries(showArgs).map(removeEmptyString))
6665
}
6766

68-
const removeEmptyString = function (key, value) {
67+
const removeEmptyString = function ([key, value]) {
6968
if (typeof value === 'string' && value.trim() === '') {
7069
return [key]
7170
}

packages/build/src/plugins_core/frameworks_api/util.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { promises as fs } from 'fs'
22
import { resolve } from 'path'
33

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

76
import type { NetlifyConfig } from '../../index.js'
87
import { FRAMEWORKS_API_CONFIG_ENDPOINT } from '../../utils/frameworks_api.js'
@@ -67,20 +66,28 @@ export const filterConfig = (
6766
allowedProperties: string[][],
6867
systemLog: SystemLogger,
6968
): Record<string, unknown> =>
70-
mapObject(obj, (key, value) => {
71-
const keyPath = [...path, key]
69+
Object.fromEntries(
70+
Object.entries(obj)
71+
.filter(([key]) => {
72+
const keyPath = [...path, key]
7273

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

76-
return mapObjectSkip
77-
}
77+
return false
78+
}
7879

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

82-
return [key, value]
83-
}
85+
if (!isPlainObject(value)) {
86+
systemLog(`Loading property from Deploy Configuration API: ${keyPath.join('.')}`)
87+
88+
return [key, value]
89+
}
8490

85-
return [key, filterConfig(value, keyPath, allowedProperties, systemLog)]
86-
})
91+
return [key, filterConfig(value, keyPath, allowedProperties, systemLog)]
92+
}),
93+
)

packages/build/src/plugins_core/functions/zisi.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { join, resolve } from 'path'
22

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

76
import type { FeatureFlags } from '../../core/feature_flags.js'
@@ -55,10 +54,12 @@ export const getZisiParameters = ({
5554
}: GetZisiParametersType): ZipFunctionsOptions => {
5655
const nodeVersion = getLambdaNodeVersion(childEnv, userNodeVersion)
5756
const manifest = join(functionsDist, 'manifest.json')
58-
const config = mapObject(functionsConfig, (expression, object) => [
59-
expression,
60-
normalizeFunctionConfig({ buildDir, functionConfig: object, isRunningLocally, nodeVersion }),
61-
])
57+
const config = Object.fromEntries(
58+
Object.entries(functionsConfig).map(([expression, object]) => [
59+
expression,
60+
normalizeFunctionConfig({ buildDir, functionConfig: object, isRunningLocally, nodeVersion }),
61+
]),
62+
)
6263
const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
6364

6465
// Only the legacy internal functions directory is allowed to have a JSON

0 commit comments

Comments
 (0)