@netlify/config 18.0.2 → 18.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/api/site_info.js +10 -2
- package/src/env/envelope.js +24 -0
- package/src/env/main.js +11 -5
- package/src/log/messages.js +2 -0
- package/src/main.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.1.2",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/main.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"is-plain-obj": "^4.0.0",
|
|
65
65
|
"js-yaml": "^4.0.0",
|
|
66
66
|
"map-obj": "^5.0.0",
|
|
67
|
-
"netlify": "^
|
|
67
|
+
"netlify": "^12.0.0",
|
|
68
68
|
"netlify-headers-parser": "^6.0.2",
|
|
69
69
|
"netlify-redirect-parser": "13.0.5",
|
|
70
70
|
"omit.js": "^2.0.2",
|
package/src/api/site_info.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getEnvelope } from '../env/envelope.js'
|
|
1
2
|
import { throwUserError } from '../error.js'
|
|
3
|
+
import { ERROR_CALL_TO_ACTION } from '../log/messages.js'
|
|
2
4
|
|
|
3
5
|
// Retrieve Netlify Site information, if available.
|
|
4
6
|
// Used to retrieve local build environment variables and UI build settings.
|
|
@@ -7,6 +9,7 @@ import { throwUserError } from '../error.js'
|
|
|
7
9
|
// Requires knowing the `siteId` and having the access `token`.
|
|
8
10
|
// Silently ignore API errors. For example the network connection might be down,
|
|
9
11
|
// but local builds should still work regardless.
|
|
12
|
+
// eslint-disable-next-line complexity
|
|
10
13
|
export const getSiteInfo = async function ({ api, siteId, mode, testOpts: { env: testEnv = true } = {} }) {
|
|
11
14
|
if (api === undefined || mode === 'buildbot' || !testEnv) {
|
|
12
15
|
const siteInfo = siteId === undefined ? {} : { id: siteId }
|
|
@@ -18,6 +21,13 @@ export const getSiteInfo = async function ({ api, siteId, mode, testOpts: { env:
|
|
|
18
21
|
getAccounts(api),
|
|
19
22
|
getAddons(api, siteId),
|
|
20
23
|
])
|
|
24
|
+
|
|
25
|
+
if (siteInfo.use_envelope) {
|
|
26
|
+
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId })
|
|
27
|
+
// eslint-disable-next-line fp/no-mutation
|
|
28
|
+
siteInfo.build_settings.env = envelope
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
return { siteInfo, accounts, addons }
|
|
22
32
|
}
|
|
23
33
|
|
|
@@ -55,5 +65,3 @@ const getAddons = async function (api, siteId) {
|
|
|
55
65
|
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const getEnvelope = async function ({ api, accountId, siteId }) {
|
|
2
|
+
if (accountId === undefined) {
|
|
3
|
+
return {}
|
|
4
|
+
}
|
|
5
|
+
try {
|
|
6
|
+
const environmentVariables = await api.getEnvVars({ accountId, siteId })
|
|
7
|
+
// eslint-disable-next-line fp/no-mutating-methods
|
|
8
|
+
const sortedEnvVarsFromDevContext = environmentVariables
|
|
9
|
+
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
|
|
10
|
+
.reduce((acc, cur) => {
|
|
11
|
+
const envVar = cur.values.find((val) => ['dev', 'all'].includes(val.context))
|
|
12
|
+
if (envVar && envVar.value) {
|
|
13
|
+
return {
|
|
14
|
+
...acc,
|
|
15
|
+
[cur.key]: envVar.value,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return acc
|
|
19
|
+
}, {})
|
|
20
|
+
return sortedEnvVarsFromDevContext
|
|
21
|
+
} catch {
|
|
22
|
+
return {}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/env/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import omit from 'omit.js'
|
|
|
2
2
|
|
|
3
3
|
import { removeFalsy } from '../utils/remove_falsy.js'
|
|
4
4
|
|
|
5
|
+
import { getEnvelope } from './envelope.js'
|
|
5
6
|
import { getGitEnv } from './git.js'
|
|
6
7
|
|
|
7
8
|
// Retrieve this site's environment variable. Also take into account team-wide
|
|
@@ -11,6 +12,7 @@ import { getGitEnv } from './git.js'
|
|
|
11
12
|
// TODO: add `netlify.toml` `build.environment`, after normalization
|
|
12
13
|
// TODO: add `CONTEXT` and others
|
|
13
14
|
export const getEnv = async function ({
|
|
15
|
+
api,
|
|
14
16
|
mode,
|
|
15
17
|
config,
|
|
16
18
|
siteInfo,
|
|
@@ -27,7 +29,7 @@ export const getEnv = async function ({
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context })
|
|
30
|
-
const [accountEnv, addonsEnv, uiEnv, configFileEnv] = getUserEnv({ config, siteInfo, accounts, addons })
|
|
32
|
+
const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({ api, config, siteInfo, accounts, addons })
|
|
31
33
|
|
|
32
34
|
// Sources of environment variables, in descending order of precedence.
|
|
33
35
|
const sources = [
|
|
@@ -115,8 +117,8 @@ const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
|
|
|
115
117
|
const DEFAULT_SITE_NAME = 'site-name'
|
|
116
118
|
|
|
117
119
|
// Environment variables specified by the user
|
|
118
|
-
const getUserEnv = function ({ config, siteInfo, accounts, addons }) {
|
|
119
|
-
const accountEnv = getAccountEnv({ siteInfo, accounts })
|
|
120
|
+
const getUserEnv = async function ({ api, config, siteInfo, accounts, addons }) {
|
|
121
|
+
const accountEnv = await getAccountEnv({ api, siteInfo, accounts })
|
|
120
122
|
const addonsEnv = getAddonsEnv(addons)
|
|
121
123
|
const uiEnv = getUiEnv({ siteInfo })
|
|
122
124
|
const configFileEnv = getConfigFileEnv({ config })
|
|
@@ -124,8 +126,12 @@ const getUserEnv = function ({ config, siteInfo, accounts, addons }) {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
// Account-wide environment variables
|
|
127
|
-
const getAccountEnv = function ({ siteInfo
|
|
128
|
-
|
|
129
|
+
const getAccountEnv = async function ({ api, siteInfo, accounts }) {
|
|
130
|
+
if (siteInfo.use_envelope) {
|
|
131
|
+
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug })
|
|
132
|
+
return envelope
|
|
133
|
+
}
|
|
134
|
+
const { site_env: siteEnv = {} } = accounts.find(({ slug }) => slug === siteInfo.account_slug) || {}
|
|
129
135
|
return siteEnv
|
|
130
136
|
}
|
|
131
137
|
|
package/src/log/messages.js
CHANGED
|
@@ -2,6 +2,8 @@ import { throwUserError } from '../error.js'
|
|
|
2
2
|
|
|
3
3
|
import { logWarning } from './logger.js'
|
|
4
4
|
|
|
5
|
+
export const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`
|
|
6
|
+
|
|
5
7
|
export const throwOnInvalidTomlSequence = function (invalidSequence) {
|
|
6
8
|
throwUserError(
|
|
7
9
|
`In netlify.toml, the following backslash should be escaped: ${invalidSequence}
|