@netlify/config 19.0.0-rc → 19.0.0

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.
Files changed (100) hide show
  1. package/bin.js +5 -0
  2. package/lib/api/build_settings.js +28 -0
  3. package/lib/api/client.js +12 -0
  4. package/lib/api/site_info.js +59 -0
  5. package/{src → lib}/base.js +10 -18
  6. package/lib/bin/flags.js +173 -0
  7. package/lib/bin/main.js +59 -0
  8. package/{src → lib}/build_dir.js +11 -15
  9. package/{src → lib}/cached_config.js +14 -17
  10. package/lib/case.js +18 -0
  11. package/lib/context.js +86 -0
  12. package/lib/default.js +27 -0
  13. package/lib/env/envelope.js +24 -0
  14. package/lib/env/git.js +23 -0
  15. package/lib/env/main.js +150 -0
  16. package/lib/error.js +28 -0
  17. package/lib/events.js +21 -0
  18. package/lib/files.js +83 -0
  19. package/{src → lib}/functions_config.js +36 -52
  20. package/lib/headers.js +20 -0
  21. package/lib/inline_config.js +8 -0
  22. package/lib/log/cleanup.js +64 -0
  23. package/lib/log/logger.js +36 -0
  24. package/lib/log/main.js +39 -0
  25. package/{src → lib}/log/messages.js +56 -95
  26. package/lib/log/options.js +29 -0
  27. package/lib/log/serialize.js +4 -0
  28. package/lib/log/theme.js +13 -0
  29. package/lib/main.js +210 -0
  30. package/{src → lib}/merge.js +25 -35
  31. package/lib/merge_normalize.js +24 -0
  32. package/lib/mutations/apply.js +66 -0
  33. package/{src → lib}/mutations/config_prop_name.js +6 -8
  34. package/lib/mutations/update.js +98 -0
  35. package/lib/normalize.js +32 -0
  36. package/lib/options/base.js +54 -0
  37. package/lib/options/branch.js +31 -0
  38. package/{src → lib}/options/feature_flags.js +7 -10
  39. package/lib/options/main.js +91 -0
  40. package/lib/options/repository_root.js +16 -0
  41. package/lib/origin.js +31 -0
  42. package/lib/parse.js +56 -0
  43. package/lib/path.js +41 -0
  44. package/lib/redirects.js +19 -0
  45. package/lib/simplify.js +77 -0
  46. package/{src → lib}/utils/group.js +5 -6
  47. package/lib/utils/remove_falsy.js +14 -0
  48. package/lib/utils/set.js +27 -0
  49. package/lib/utils/toml.js +20 -0
  50. package/lib/validate/context.js +38 -0
  51. package/lib/validate/example.js +30 -0
  52. package/lib/validate/helpers.js +25 -0
  53. package/{src → lib}/validate/identical.js +8 -12
  54. package/lib/validate/main.js +99 -0
  55. package/lib/validate/validations.js +275 -0
  56. package/package.json +21 -12
  57. package/src/api/build_settings.js +0 -41
  58. package/src/api/client.js +0 -15
  59. package/src/api/site_info.js +0 -67
  60. package/src/bin/flags.js +0 -181
  61. package/src/bin/main.js +0 -73
  62. package/src/case.js +0 -37
  63. package/src/context.js +0 -99
  64. package/src/default.js +0 -31
  65. package/src/env/envelope.js +0 -24
  66. package/src/env/git.js +0 -23
  67. package/src/env/main.js +0 -198
  68. package/src/error.js +0 -36
  69. package/src/events.js +0 -22
  70. package/src/files.js +0 -107
  71. package/src/headers.js +0 -30
  72. package/src/inline_config.js +0 -9
  73. package/src/log/cleanup.js +0 -92
  74. package/src/log/logger.js +0 -47
  75. package/src/log/main.js +0 -48
  76. package/src/log/options.js +0 -43
  77. package/src/log/serialize.js +0 -5
  78. package/src/log/theme.js +0 -14
  79. package/src/main.js +0 -285
  80. package/src/merge_normalize.js +0 -31
  81. package/src/mutations/apply.js +0 -78
  82. package/src/mutations/update.js +0 -117
  83. package/src/normalize.js +0 -36
  84. package/src/options/base.js +0 -66
  85. package/src/options/branch.js +0 -34
  86. package/src/options/main.js +0 -111
  87. package/src/options/repository_root.js +0 -21
  88. package/src/origin.js +0 -38
  89. package/src/parse.js +0 -69
  90. package/src/path.js +0 -52
  91. package/src/redirects.js +0 -29
  92. package/src/simplify.js +0 -103
  93. package/src/utils/remove_falsy.js +0 -18
  94. package/src/utils/set.js +0 -33
  95. package/src/utils/toml.js +0 -23
  96. package/src/validate/context.js +0 -57
  97. package/src/validate/example.js +0 -37
  98. package/src/validate/helpers.js +0 -31
  99. package/src/validate/main.js +0 -143
  100. package/src/validate/validations.js +0 -289
package/src/env/main.js DELETED
@@ -1,198 +0,0 @@
1
- import omit from 'omit.js'
2
-
3
- import { removeFalsy } from '../utils/remove_falsy.js'
4
-
5
- import { getEnvelope } from './envelope.js'
6
- import { getGitEnv } from './git.js'
7
-
8
- // Retrieve this site's environment variable. Also take into account team-wide
9
- // environment variables and addons.
10
- // The buildbot already has the right environment variables. This is mostly
11
- // meant so that local builds can mimic production builds
12
- // TODO: add `netlify.toml` `build.environment`, after normalization
13
- // TODO: add `CONTEXT` and others
14
- export const getEnv = async function ({
15
- api,
16
- mode,
17
- config,
18
- siteInfo,
19
- accounts,
20
- addons,
21
- buildDir,
22
- branch,
23
- deployId,
24
- buildId,
25
- context,
26
- }) {
27
- if (mode === 'buildbot') {
28
- return {}
29
- }
30
-
31
- const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context })
32
- const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({ api, config, siteInfo, accounts, addons })
33
-
34
- // Sources of environment variables, in descending order of precedence.
35
- const sources = [
36
- { key: 'configFile', values: configFileEnv },
37
- { key: 'ui', values: uiEnv },
38
- { key: 'addons', values: addonsEnv },
39
- { key: 'account', values: accountEnv },
40
- { key: 'general', values: generalEnv },
41
- ]
42
-
43
- // A hash mapping names of environment variables to objects containing the following properties:
44
- // - sources: List of sources where the environment variable was found. The first element is the source that
45
- // actually provided the variable (i.e. the one with the highest precedence).
46
- // - value: The value of the environment variable.
47
- const env = new Map()
48
-
49
- sources.forEach((source) => {
50
- Object.keys(source.values).forEach((key) => {
51
- if (env.has(key)) {
52
- const { sources: envSources, value } = env.get(key)
53
-
54
- env.set(key, {
55
- sources: [...envSources, source.key],
56
- value: convertToString(value),
57
- })
58
- } else {
59
- env.set(key, {
60
- sources: [source.key],
61
- value: convertToString(source.values[key]),
62
- })
63
- }
64
- })
65
- })
66
-
67
- return Object.fromEntries(env)
68
- }
69
-
70
- const convertToString = (value) => {
71
- if (typeof value === 'string') {
72
- return value
73
- }
74
-
75
- return value.toString()
76
- }
77
-
78
- // Environment variables not set by users, but meant to mimic the production
79
- // environment.
80
- const getGeneralEnv = async function ({
81
- siteInfo,
82
- siteInfo: { id, name },
83
- buildDir,
84
- branch,
85
- deployId,
86
- buildId,
87
- context,
88
- }) {
89
- const gitEnv = await getGitEnv(buildDir, branch)
90
- const deployUrls = getDeployUrls({ siteInfo, branch, deployId })
91
- return removeFalsy({
92
- SITE_ID: id,
93
- SITE_NAME: name,
94
- DEPLOY_ID: deployId,
95
- BUILD_ID: buildId,
96
- ...deployUrls,
97
- CONTEXT: context,
98
- NETLIFY_LOCAL: 'true',
99
- ...gitEnv,
100
- // Localization
101
- LANG: 'en_US.UTF-8',
102
- LANGUAGE: 'en_US:en',
103
- LC_ALL: 'en_US.UTF-8',
104
- // Disable telemetry of some tools
105
- GATSBY_TELEMETRY_DISABLED: '1',
106
- NEXT_TELEMETRY_DISABLED: '1',
107
- })
108
- }
109
-
110
- const getDeployUrls = function ({
111
- siteInfo: { name = DEFAULT_SITE_NAME, ssl_url: sslUrl, build_settings: { repo_url: REPOSITORY_URL } = {} },
112
- branch,
113
- deployId,
114
- }) {
115
- return {
116
- URL: sslUrl,
117
- REPOSITORY_URL,
118
- DEPLOY_PRIME_URL: `https://${branch}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
119
- DEPLOY_URL: `https://${deployId}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
120
- }
121
- }
122
-
123
- const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
124
- // `site.name` is `undefined` when there is no token or siteId
125
- const DEFAULT_SITE_NAME = 'site-name'
126
-
127
- // Environment variables specified by the user
128
- const getUserEnv = async function ({ api, config, siteInfo, accounts, addons }) {
129
- const accountEnv = await getAccountEnv({ api, siteInfo, accounts })
130
- const addonsEnv = getAddonsEnv(addons)
131
- const uiEnv = getUiEnv({ siteInfo })
132
- const configFileEnv = getConfigFileEnv({ config })
133
- return [accountEnv, addonsEnv, uiEnv, configFileEnv].map(cleanUserEnv)
134
- }
135
-
136
- // Account-wide environment variables
137
- const getAccountEnv = async function ({ api, siteInfo, accounts }) {
138
- if (siteInfo.use_envelope) {
139
- const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug })
140
- return envelope
141
- }
142
- const { site_env: siteEnv = {} } = accounts.find(({ slug }) => slug === siteInfo.account_slug) || {}
143
- return siteEnv
144
- }
145
-
146
- // Environment variables from addons
147
- const getAddonsEnv = function (addons) {
148
- return Object.assign({}, ...addons.map(getAddonEnv))
149
- }
150
-
151
- const getAddonEnv = function ({ env }) {
152
- return env
153
- }
154
-
155
- // Site-specific environment variables set in the UI
156
- const getUiEnv = function ({ siteInfo: { build_settings: { env = {} } = {} } }) {
157
- return env
158
- }
159
-
160
- // Site-specific environment variables set in netlify.toml
161
- const getConfigFileEnv = function ({
162
- config: {
163
- build: { environment = {} },
164
- },
165
- }) {
166
- return environment
167
- }
168
-
169
- // Some environment variables cannot be overridden by configuration
170
- const cleanUserEnv = function (userEnv) {
171
- return omit.default(userEnv, READONLY_ENV)
172
- }
173
-
174
- const READONLY_ENV = [
175
- // Set in local builds
176
- 'BRANCH',
177
- 'CACHED_COMMIT_REF',
178
- 'COMMIT_REF',
179
- 'CONTEXT',
180
- 'HEAD',
181
- 'REPOSITORY_URL',
182
- 'URL',
183
-
184
- // CI builds set NETLIFY=true while CLI and programmatic builds set
185
- // NETLIFY_LOCAL=true
186
- 'NETLIFY',
187
- 'NETLIFY_LOCAL',
188
-
189
- // Not set in local builds because there is no CI build/deploy, incoming hooks nor PR
190
- 'INCOMING_HOOK_BODY',
191
- 'INCOMING_HOOK_TITLE',
192
- 'INCOMING_HOOK_URL',
193
- 'NETLIFY_BUILD_BASE',
194
- 'NETLIFY_BUILD_LIFECYCLE_TRIAL',
195
- 'NETLIFY_IMAGES_CDN_DOMAIN',
196
- 'PULL_REQUEST',
197
- 'REVIEW_ID',
198
- ]
package/src/error.js DELETED
@@ -1,36 +0,0 @@
1
- // We distinguish between errors thrown intentionally and uncaught exceptions
2
- // (such as bugs) with a `customErrorInfo.type` property.
3
- export const throwUserError = function (messageOrError, error) {
4
- const errorA = getError(messageOrError, error)
5
- errorA[CUSTOM_ERROR_KEY] = { type: USER_ERROR_TYPE }
6
- throw errorA
7
- }
8
-
9
- // Can pass either `message`, `error` or `message, error`
10
- const getError = function (messageOrError, error) {
11
- if (messageOrError instanceof Error) {
12
- return messageOrError
13
- }
14
-
15
- if (error === undefined) {
16
- return new Error(messageOrError)
17
- }
18
-
19
- error.message = `${messageOrError}\n${error.message}`
20
- return error
21
- }
22
-
23
- export const isUserError = function (error) {
24
- return (
25
- canHaveErrorInfo(error) && error[CUSTOM_ERROR_KEY] !== undefined && error[CUSTOM_ERROR_KEY].type === USER_ERROR_TYPE
26
- )
27
- }
28
-
29
- // Exceptions that are not objects (including `Error` instances) cannot have an
30
- // `CUSTOM_ERROR_KEY` property
31
- const canHaveErrorInfo = function (error) {
32
- return error != null
33
- }
34
-
35
- const CUSTOM_ERROR_KEY = 'customErrorInfo'
36
- const USER_ERROR_TYPE = 'resolveConfig'
package/src/events.js DELETED
@@ -1,22 +0,0 @@
1
- // List of build plugins events
2
- export const EVENTS = [
3
- // Before build command
4
- 'onPreBuild',
5
- // After build command, before Functions bundling
6
- 'onBuild',
7
- // After Functions bundling
8
- 'onPostBuild',
9
- // After build success
10
- 'onSuccess',
11
- // After build error
12
- 'onError',
13
- // After build error or success
14
- 'onEnd',
15
- ]
16
-
17
- export const DEV_EVENTS = [
18
- // Before dev command
19
- 'onPreDev',
20
- // The dev command
21
- 'onDev',
22
- ]
package/src/files.js DELETED
@@ -1,107 +0,0 @@
1
- import { resolve, relative, parse } from 'path'
2
-
3
- import { getProperty, setProperty, deleteProperty } from 'dot-prop'
4
- import { pathExists } from 'path-exists'
5
-
6
- import { throwUserError } from './error.js'
7
- import { mergeConfigs } from './merge.js'
8
- import { isTruthy } from './utils/remove_falsy.js'
9
-
10
- // Make configuration paths relative to `buildDir` and converts them to
11
- // absolute paths
12
- export const resolveConfigPaths = async function ({ config, repositoryRoot, buildDir, baseRelDir }) {
13
- const baseRel = baseRelDir ? buildDir : repositoryRoot
14
- const configA = resolvePaths(config, FILE_PATH_CONFIG_PROPS, baseRel, repositoryRoot)
15
- const configB = await addDefaultPaths(configA, repositoryRoot, baseRel)
16
- return configB
17
- }
18
-
19
- // All file paths in the configuration file are are relative to `buildDir`
20
- // (if `baseRelDir` is `true`).
21
- const FILE_PATH_CONFIG_PROPS = ['functionsDirectory', 'build.publish', 'build.edge_functions']
22
-
23
- const resolvePaths = function (config, propNames, baseRel, repositoryRoot) {
24
- return propNames.reduce((configA, propName) => resolvePathProp(configA, propName, baseRel, repositoryRoot), config)
25
- }
26
-
27
- const resolvePathProp = function (config, propName, baseRel, repositoryRoot) {
28
- const path = getProperty(config, propName)
29
-
30
- if (!isTruthy(path)) {
31
- deleteProperty(config, propName)
32
- return config
33
- }
34
-
35
- return setProperty(config, propName, resolvePath(repositoryRoot, baseRel, path, propName))
36
- }
37
-
38
- export const resolvePath = function (repositoryRoot, baseRel, originalPath, propName) {
39
- if (!isTruthy(originalPath)) {
40
- return
41
- }
42
-
43
- const path = originalPath.replace(LEADING_SLASH_REGEXP, '')
44
- const pathA = resolve(baseRel, path)
45
- validateInsideRoot(originalPath, pathA, repositoryRoot, propName)
46
- return pathA
47
- }
48
-
49
- // We allow paths in configuration file to start with /
50
- // In that case, those are actually relative paths not absolute.
51
- const LEADING_SLASH_REGEXP = /^\/+/
52
-
53
- // We ensure all file paths are within the repository root directory.
54
- // However we allow file paths to be outside of the build directory, since this
55
- // can be convenient in monorepo setups.
56
- const validateInsideRoot = function (originalPath, path, repositoryRoot, propName) {
57
- if (relative(repositoryRoot, path).startsWith('..') || getWindowsDrive(repositoryRoot) !== getWindowsDrive(path)) {
58
- throwUserError(
59
- `Configuration property "${propName}" "${originalPath}" must be inside the repository root directory.`,
60
- )
61
- }
62
- }
63
-
64
- const getWindowsDrive = function (path) {
65
- return parse(path).root
66
- }
67
-
68
- // Some configuration properties have default values that are only set if a
69
- // specific directory/file exists in the build directory
70
- const addDefaultPaths = async function (config, repositoryRoot, baseRel) {
71
- const defaultPathsConfigs = await Promise.all(
72
- DEFAULT_PATHS.map(({ defaultPath, getConfig, propName }) =>
73
- addDefaultPath({ repositoryRoot, baseRel, defaultPath, getConfig, propName }),
74
- ),
75
- )
76
- const defaultPathsConfigsA = defaultPathsConfigs.filter(Boolean)
77
- return mergeConfigs([...defaultPathsConfigsA, config])
78
- }
79
-
80
- const DEFAULT_PATHS = [
81
- // @todo Remove once we drop support for the legacy default functions directory.
82
- {
83
- getConfig: (directory) => ({ functionsDirectory: directory, functionsDirectoryOrigin: 'default-v1' }),
84
- defaultPath: 'netlify-automatic-functions',
85
- propName: 'functions.directory',
86
- },
87
- {
88
- getConfig: (directory) => ({ functionsDirectory: directory, functionsDirectoryOrigin: 'default' }),
89
- defaultPath: 'netlify/functions',
90
- propName: 'functions.directory',
91
- },
92
- {
93
- getConfig: (directory) => ({ build: { edge_functions: directory } }),
94
- defaultPath: 'netlify/edge-functions',
95
- propName: 'build.edge_functions',
96
- },
97
- ]
98
-
99
- const addDefaultPath = async function ({ repositoryRoot, baseRel, defaultPath, getConfig, propName }) {
100
- const absolutePath = resolvePath(repositoryRoot, baseRel, defaultPath, propName)
101
-
102
- if (!(await pathExists(absolutePath))) {
103
- return
104
- }
105
-
106
- return getConfig(absolutePath)
107
- }
package/src/headers.js DELETED
@@ -1,30 +0,0 @@
1
- import { resolve } from 'path'
2
-
3
- import { parseAllHeaders } from 'netlify-headers-parser'
4
-
5
- import { warnHeadersParsing, warnHeadersCaseSensitivity } from './log/messages.js'
6
-
7
- // Retrieve path to `_headers` file (even if it does not exist yet)
8
- export const getHeadersPath = function ({ build: { publish } }) {
9
- return resolve(publish, HEADERS_FILENAME)
10
- }
11
-
12
- const HEADERS_FILENAME = '_headers'
13
-
14
- // Add `config.headers`
15
- export const addHeaders = async function ({
16
- config: { headers: configHeaders, ...config },
17
- headersPath,
18
- logs,
19
- featureFlags,
20
- }) {
21
- const { headers, errors } = await parseAllHeaders({
22
- headersFiles: [headersPath],
23
- configHeaders,
24
- minimal: true,
25
- featureFlags,
26
- })
27
- warnHeadersParsing(logs, errors)
28
- warnHeadersCaseSensitivity(logs, headers)
29
- return { ...config, headers }
30
- }
@@ -1,9 +0,0 @@
1
- import { logInlineConfig } from './log/main.js'
2
- import { applyMutations } from './mutations/apply.js'
3
-
4
- // Retrieve the `--inlineConfig` CLI flag
5
- export const getInlineConfig = function ({ inlineConfig, configMutations, logs, debug }) {
6
- const mutatedInlineConfig = applyMutations(inlineConfig, configMutations)
7
- logInlineConfig(mutatedInlineConfig, { logs, debug })
8
- return mutatedInlineConfig
9
- }
@@ -1,92 +0,0 @@
1
- import filterObj from 'filter-obj'
2
-
3
- import { simplifyConfig } from '../simplify.js'
4
-
5
- // Make sure we are not printing secret values. Use an allow list.
6
- export const cleanupConfig = function ({
7
- build: {
8
- base,
9
- command,
10
- commandOrigin,
11
- environment = {},
12
- edge_functions: edgeFunctions,
13
- ignore,
14
- processing,
15
- publish,
16
- publishOrigin,
17
- } = {},
18
- headers,
19
- headersOrigin,
20
- plugins = [],
21
- redirects,
22
- redirectsOrigin,
23
- baseRelDir,
24
- functions,
25
- functionsDirectory,
26
- }) {
27
- const environmentA = cleanupEnvironment(environment)
28
- const build = {
29
- base,
30
- command,
31
- commandOrigin,
32
- environment: environmentA,
33
- edge_functions: edgeFunctions,
34
- ignore,
35
- processing,
36
- publish,
37
- publishOrigin,
38
- }
39
- const pluginsA = plugins.map(cleanupPlugin)
40
- const netlifyConfig = simplifyConfig({
41
- build,
42
- plugins: pluginsA,
43
- headers,
44
- headersOrigin,
45
- redirects,
46
- redirectsOrigin,
47
- baseRelDir,
48
- functions,
49
- functionsDirectory,
50
- })
51
- const netlifyConfigA = truncateArray(netlifyConfig, 'headers')
52
- const netlifyConfigB = truncateArray(netlifyConfigA, 'redirects')
53
- return netlifyConfigB
54
- }
55
-
56
- export const cleanupEnvironment = function (environment) {
57
- return Object.keys(environment).filter((key) => !BUILDBOT_ENVIRONMENT.has(key))
58
- }
59
-
60
- // Added by the buildbot. We only want to print environment variables specified
61
- // by the user.
62
- const BUILDBOT_ENVIRONMENT = new Set([
63
- 'BRANCH',
64
- 'CONTEXT',
65
- 'DEPLOY_PRIME_URL',
66
- 'DEPLOY_URL',
67
- 'GO_VERSION',
68
- 'NETLIFY_IMAGES_CDN_DOMAIN',
69
- 'SITE_ID',
70
- 'SITE_NAME',
71
- 'URL',
72
- ])
73
-
74
- const cleanupPlugin = function ({ package: packageName, origin, inputs = {} }) {
75
- const inputsA = filterObj(inputs, isPublicInput)
76
- return { package: packageName, origin, inputs: inputsA }
77
- }
78
-
79
- const isPublicInput = function (key, input) {
80
- return typeof input === 'boolean'
81
- }
82
-
83
- // `headers` and `redirects` can be very long, which can take several minutes
84
- // to print in the build logs. We truncate them before logging.
85
- const truncateArray = function (netlifyConfig, propName) {
86
- const array = netlifyConfig[propName]
87
- return Array.isArray(array) && array.length > MAX_ARRAY_LENGTH
88
- ? { ...netlifyConfig, [propName]: array.slice(0, MAX_ARRAY_LENGTH) }
89
- : netlifyConfig
90
- }
91
-
92
- const MAX_ARRAY_LENGTH = 100
package/src/log/logger.js DELETED
@@ -1,47 +0,0 @@
1
- import figures from 'figures'
2
-
3
- import { serializeObject } from './serialize.js'
4
- import { THEME } from './theme.js'
5
-
6
- // When the `buffer` option is true, we return logs instead of printing them
7
- // on the console. The logs are accumulated in a `logs` array variable.
8
- export const getBufferLogs = function ({ buffer }) {
9
- if (!buffer) {
10
- return
11
- }
12
-
13
- return { stdout: [], stderr: [] }
14
- }
15
-
16
- // This should be used instead of `console.log()`
17
- // Printed on stderr because stdout is reserved for the JSON output
18
- export const log = function (logs, string, { color } = {}) {
19
- const stringA = String(string).replace(EMPTY_LINES_REGEXP, EMPTY_LINE)
20
- const stringB = color === undefined ? stringA : color(stringA)
21
-
22
- if (logs !== undefined) {
23
- // `logs` is a stateful variable
24
- // eslint-disable-next-line fp/no-mutating-methods
25
- logs.stderr.push(stringB)
26
- return
27
- }
28
-
29
- console.warn(stringB)
30
- }
31
-
32
- // We need to add a zero width space character in empty lines. Otherwise the
33
- // buildbot removes those due to a bug: https://github.com/netlify/buildbot/issues/595
34
- const EMPTY_LINES_REGEXP = /^\s*$/gm
35
- const EMPTY_LINE = '\u{200B}'
36
-
37
- export const logWarning = function (logs, string, opts) {
38
- log(logs, string, { color: THEME.warningLine, ...opts })
39
- }
40
-
41
- export const logObject = function (logs, object, opts) {
42
- log(logs, serializeObject(object), opts)
43
- }
44
-
45
- export const logSubHeader = function (logs, string, opts) {
46
- log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts })
47
- }
package/src/log/main.js DELETED
@@ -1,48 +0,0 @@
1
- import { cleanupConfig, cleanupEnvironment } from './cleanup.js'
2
- import { logObject, logSubHeader } from './logger.js'
3
- import { cleanupConfigOpts } from './options.js'
4
-
5
- // Log options in debug mode.
6
- export const logOpts = function (opts, { logs, debug, cachedConfig, cachedConfigPath }) {
7
- // In production, print those in the first call to `@netlify/config`, not the
8
- // second one done inside `@netlify/build`
9
- if (!debug || cachedConfig !== undefined || cachedConfigPath !== undefined) {
10
- return
11
- }
12
-
13
- logSubHeader(logs, 'Initial build environment')
14
- logObject(logs, cleanupConfigOpts(opts))
15
- }
16
-
17
- // Log `defaultConfig` option in debug mode
18
- export const logDefaultConfig = function (defaultConfig, { logs, debug, baseRelDir }) {
19
- if (!debug || defaultConfig === undefined) {
20
- return
21
- }
22
-
23
- logSubHeader(logs, 'UI build settings')
24
- logObject(logs, cleanupConfig({ ...defaultConfig, baseRelDir }))
25
- }
26
-
27
- // Log `inlineConfig` option in debug mode
28
- export const logInlineConfig = function (initialConfig, { logs, debug }) {
29
- if (!debug || Object.keys(initialConfig).length === 0) {
30
- return
31
- }
32
-
33
- logSubHeader(logs, 'Configuration override')
34
- logObject(logs, cleanupConfig(initialConfig))
35
- }
36
-
37
- // Log return value of `@netlify/config` in debug mode
38
- export const logResult = function ({ configPath, buildDir, config, context, branch, env }, { logs, debug }) {
39
- if (!debug) {
40
- return
41
- }
42
-
43
- logSubHeader(logs, 'Resolved build environment')
44
- logObject(logs, { configPath, buildDir, context, branch, env: cleanupEnvironment(env) })
45
-
46
- logSubHeader(logs, 'Resolved config')
47
- logObject(logs, cleanupConfig(config))
48
- }
@@ -1,43 +0,0 @@
1
- import { DEFAULT_FEATURE_FLAGS } from '../options/feature_flags.js'
2
- import { removeEmptyArray } from '../simplify.js'
3
- import { removeFalsy } from '../utils/remove_falsy.js'
4
-
5
- // Use an allowlist to prevent printing confidential values.
6
- export const cleanupConfigOpts = function ({
7
- config,
8
- cwd,
9
- context,
10
- branch,
11
- mode,
12
- repositoryRoot,
13
- siteId,
14
- baseRelDir,
15
- env = {},
16
- featureFlags = {},
17
- }) {
18
- const envA = Object.keys(env)
19
- return removeFalsy({
20
- config,
21
- cwd,
22
- context,
23
- branch,
24
- mode,
25
- repositoryRoot,
26
- siteId,
27
- baseRelDir,
28
- ...removeEmptyArray(envA, 'env'),
29
- featureFlags: cleanFeatureFlags(featureFlags),
30
- })
31
- }
32
-
33
- // We only show feature flags related to `@netlify/config`.
34
- // Also, we only print enabled feature flags.
35
- const cleanFeatureFlags = function (featureFlags) {
36
- return Object.entries(featureFlags)
37
- .filter(shouldPrintFeatureFlag)
38
- .map(([featureFlagName]) => featureFlagName)
39
- }
40
-
41
- const shouldPrintFeatureFlag = function ([featureFlagName, enabled]) {
42
- return enabled && featureFlagName in DEFAULT_FEATURE_FLAGS
43
- }
@@ -1,5 +0,0 @@
1
- import { dump } from 'js-yaml'
2
-
3
- export const serializeObject = function (object) {
4
- return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimEnd()
5
- }
package/src/log/theme.js DELETED
@@ -1,14 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- // Color theme. Please use this instead of requiring chalk directly, to ensure
4
- // consistent colors.
5
- export const THEME = {
6
- // Single lines used as subheaders
7
- subHeader: chalk.cyan.bold,
8
- // Single lines used as subheaders indicating an error
9
- errorSubHeader: chalk.red.bold,
10
- // Same for warnings
11
- warningLine: chalk.yellowBright,
12
- // One of several words that should be highlighted inside a line
13
- highlightWords: chalk.cyan,
14
- }