Skip to content

Commit 35c76f7

Browse files
author
Lukas Holzer
authored
fix: expose apply mutation to API surface (#4932)
* fix: expose apply mutation to API surface * chore: fix import location
1 parent 235f979 commit 35c76f7

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

packages/config/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "20.3.3",
44
"description": "Netlify config module",
55
"type": "module",
6-
"exports": "./lib/main.js",
7-
"main": "./lib/main.js",
8-
"types": "./lib/main.d.ts",
6+
"exports": "./lib/index.js",
7+
"main": "./lib/index.js",
8+
"types": "./lib/index.d.ts",
99
"bin": {
1010
"netlify-config": "./bin.js"
1111
},

packages/config/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { DEV_EVENTS, EVENTS } from './events.js'
2+
export { cleanupConfig } from './log/cleanup.js'
3+
export { resolveConfig } from './main.js'
4+
export { applyMutations } from './mutations/apply.js'
5+
export { restoreConfig, updateConfig } from './mutations/update.js'

packages/config/src/main.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import { parseConfig } from './parse.js'
1818
import { getConfigPath } from './path.js'
1919
import { getRedirectsPath, addRedirects } from './redirects.js'
2020

21-
export { DEV_EVENTS, EVENTS } from './events.js'
22-
export { cleanupConfig } from './log/cleanup.js'
23-
24-
export { updateConfig, restoreConfig } from './mutations/update.js'
25-
2621
// Load the configuration file.
2722
// Takes an optional configuration file path as input and return the resolved
2823
// `config` together with related properties such as the `configPath`.

packages/config/src/mutations/config_prop_name.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** Properties with dynamic children */
2+
const DYNAMIC_OBJECT_PROPS = new Set(['build.services', 'build.environment', 'functions', 'functions.*'])
3+
4+
/** Retrieve normalized property name */
5+
export const getPropName = function (keys: string[]) {
6+
// Some properties are user-defined, i.e. we need to replace them with a "*" token
7+
// Check if a property name is dynamic, such as `functions.{functionName}`, or
8+
// is an array index.
9+
// In those cases, we replace it by "*".
10+
return keys.reduce((propName, key) => {
11+
const normalizedKey = Number.isInteger(key) || DYNAMIC_OBJECT_PROPS.has(propName) ? '*' : String(key)
12+
return propName === '' ? normalizedKey : `${propName}.${normalizedKey}`
13+
}, '')
14+
}

packages/config/tests/mutate/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Fixture, normalizeOutput } from '@netlify/testing'
55
import test from 'ava'
66
import del from 'del'
77

8-
import { updateConfig } from '../../lib/main.js'
8+
import { updateConfig } from '../../lib/index.js'
99

1010
const FIXTURES_DIR = fileURLToPath(new URL('fixtures', import.meta.url))
1111

0 commit comments

Comments
 (0)