@netlify/config 18.2.4 → 18.2.5
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/bin.js +5 -0
- package/lib/api/build_settings.js +20 -33
- package/lib/api/client.js +10 -13
- package/lib/api/site_info.js +48 -56
- package/lib/base.js +10 -18
- package/lib/bin/flags.js +134 -142
- package/lib/bin/main.js +49 -63
- package/lib/build_dir.js +11 -15
- package/lib/cached_config.js +14 -17
- package/lib/case.js +16 -35
- package/lib/context.js +62 -84
- package/lib/default.js +18 -22
- package/lib/env/envelope.js +23 -23
- package/lib/env/git.js +18 -18
- package/lib/env/main.js +127 -179
- package/lib/error.js +19 -27
- package/lib/events.js +18 -19
- package/lib/files.js +63 -87
- package/lib/functions_config.js +36 -52
- package/lib/headers.js +17 -27
- package/lib/inline_config.js +6 -7
- package/lib/log/cleanup.js +54 -82
- package/lib/log/logger.js +25 -36
- package/lib/log/main.js +31 -40
- package/lib/log/messages.js +56 -95
- package/lib/log/options.js +24 -38
- package/lib/log/serialize.js +3 -4
- package/lib/log/theme.js +10 -11
- package/lib/main.js +188 -263
- package/lib/merge.js +25 -35
- package/lib/merge_normalize.js +17 -24
- package/lib/mutations/apply.js +53 -65
- package/lib/mutations/config_prop_name.js +6 -8
- package/lib/mutations/update.js +79 -98
- package/lib/normalize.js +24 -28
- package/lib/options/base.js +39 -51
- package/lib/options/branch.js +23 -26
- package/lib/options/feature_flags.js +7 -10
- package/lib/options/main.js +76 -96
- package/lib/options/repository_root.js +11 -16
- package/lib/origin.js +22 -29
- package/lib/parse.js +42 -55
- package/lib/path.js +29 -40
- package/lib/redirects.js +16 -26
- package/lib/simplify.js +66 -92
- package/lib/utils/group.js +5 -6
- package/lib/utils/remove_falsy.js +9 -13
- package/lib/utils/set.js +19 -25
- package/lib/utils/toml.js +13 -16
- package/lib/validate/context.js +24 -43
- package/lib/validate/example.js +20 -27
- package/lib/validate/helpers.js +17 -23
- package/lib/validate/identical.js +8 -12
- package/lib/validate/main.js +83 -127
- package/lib/validate/validations.js +243 -257
- package/package.json +13 -8
package/lib/bin/main.js
CHANGED
|
@@ -1,73 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { isUserError } from '../error.js'
|
|
11
|
-
import { resolveConfig } from '../main.js'
|
|
12
|
-
|
|
13
|
-
import { parseFlags } from './flags.js'
|
|
14
|
-
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
import process from 'process';
|
|
5
|
+
import fastSafeStringify from 'fast-safe-stringify';
|
|
6
|
+
import omit from 'omit.js';
|
|
7
|
+
import { isUserError } from '../error.js';
|
|
8
|
+
import { resolveConfig } from '../main.js';
|
|
9
|
+
import { parseFlags } from './flags.js';
|
|
15
10
|
// CLI entry point
|
|
16
11
|
const runCli = async function () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const DEFAULT_OUTPUT = '-'
|
|
27
|
-
|
|
12
|
+
try {
|
|
13
|
+
const { stable, output = DEFAULT_OUTPUT, ...flags } = parseFlags();
|
|
14
|
+
const result = await resolveConfig(flags);
|
|
15
|
+
await handleCliSuccess(result, stable, output);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
handleCliError(error);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const DEFAULT_OUTPUT = '-';
|
|
28
22
|
// The result is output as JSON on success (exit code 0)
|
|
29
23
|
const handleCliSuccess = async function (result, stable, output) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
24
|
+
const resultA = serializeApi(result);
|
|
25
|
+
const resultB = omit.default(resultA, SECRET_PROPERTIES);
|
|
26
|
+
const stringifyFunc = stable ? fastSafeStringify.stableStringify : JSON.stringify;
|
|
27
|
+
const resultJson = stringifyFunc(resultB, null, 2);
|
|
28
|
+
await outputResult(resultJson, output);
|
|
29
|
+
process.exitCode = 0;
|
|
30
|
+
};
|
|
38
31
|
const outputResult = async function (resultJson, output) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
32
|
+
if (output === '-') {
|
|
33
|
+
console.log(resultJson);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await fs.mkdir(dirname(output), { recursive: true });
|
|
37
|
+
await fs.writeFile(output, resultJson);
|
|
38
|
+
};
|
|
48
39
|
// `api` is not JSON-serializable, so we remove it
|
|
49
40
|
// We still indicate it as a boolean
|
|
50
41
|
const serializeApi = function ({ api, ...result }) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const SECRET_PROPERTIES = ['token']
|
|
59
|
-
|
|
42
|
+
if (api === undefined) {
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
return { ...result, hasApi: true };
|
|
46
|
+
};
|
|
47
|
+
const SECRET_PROPERTIES = ['token'];
|
|
60
48
|
const handleCliError = function (error) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
runCli()
|
|
49
|
+
// Errors caused by users do not show stack traces and have exit code 1
|
|
50
|
+
if (isUserError(error)) {
|
|
51
|
+
console.error(error.message);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Internal errors / bugs have exit code 2
|
|
56
|
+
console.error(error.stack);
|
|
57
|
+
process.exitCode = 2;
|
|
58
|
+
};
|
|
59
|
+
runCli();
|
package/lib/build_dir.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { isDirectory } from 'path-type'
|
|
2
|
-
|
|
3
|
-
import { throwUserError } from './error.js'
|
|
4
|
-
|
|
1
|
+
import { isDirectory } from 'path-type';
|
|
2
|
+
import { throwUserError } from './error.js';
|
|
5
3
|
// Retrieve the build directory used to resolve most paths.
|
|
6
4
|
// This is (in priority order):
|
|
7
5
|
// - `build.base`
|
|
8
6
|
// - `--repositoryRoot`
|
|
9
7
|
// - the current directory (default value of `--repositoryRoot`)
|
|
10
8
|
export const getBuildDir = async function (repositoryRoot, base) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
9
|
+
const buildDir = base === undefined ? repositoryRoot : base;
|
|
10
|
+
await checkBuildDir(buildDir, repositoryRoot);
|
|
11
|
+
return buildDir;
|
|
12
|
+
};
|
|
16
13
|
// The build directory is used as the current directory of build commands and
|
|
17
14
|
// build plugins. Therefore it must exist.
|
|
18
15
|
// We already check `repositoryRoot` earlier in the code, so only need to check
|
|
19
16
|
// `buildDir` when it is the base directory instead.
|
|
20
17
|
const checkBuildDir = async function (buildDir, repositoryRoot) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
18
|
+
if (buildDir === repositoryRoot || (await isDirectory(buildDir))) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
throwUserError(`Base directory does not exist: ${buildDir}`);
|
|
22
|
+
};
|
package/lib/cached_config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
3
2
|
// Performance optimization when @netlify/config caller has already previously
|
|
4
3
|
// called it and cached the result.
|
|
5
4
|
// This is used by the buildbot which:
|
|
@@ -7,23 +6,21 @@ import { promises as fs } from 'fs'
|
|
|
7
6
|
// - later calls @netlify/build, which runs @netlify/config under the hood
|
|
8
7
|
// This is also used by Netlify CLI.
|
|
9
8
|
export const getCachedConfig = async function ({ cachedConfig, cachedConfigPath, token, api }) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
9
|
+
const parsedCachedConfig = await parseCachedConfig(cachedConfig, cachedConfigPath);
|
|
10
|
+
// The CLI does not print some properties when they are not serializable or
|
|
11
|
+
// are confidential. Those will be missing from `cachedConfig`. The caller
|
|
12
|
+
// must supply them again when using `cachedConfig`.
|
|
13
|
+
return parsedCachedConfig === undefined ? undefined : { token, ...parsedCachedConfig, api };
|
|
14
|
+
};
|
|
17
15
|
// `cachedConfig` is a plain object while `cachedConfigPath` is a file path to
|
|
18
16
|
// a JSON file. The former is useful in programmatic usage while the second one
|
|
19
17
|
// is useful in CLI usage, to avoid hitting the OS limits if the configuration
|
|
20
18
|
// file is too big.
|
|
21
19
|
const parseCachedConfig = async function (cachedConfig, cachedConfigPath) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
20
|
+
if (cachedConfig !== undefined) {
|
|
21
|
+
return cachedConfig;
|
|
22
|
+
}
|
|
23
|
+
if (cachedConfigPath !== undefined) {
|
|
24
|
+
return JSON.parse(await fs.readFile(cachedConfigPath));
|
|
25
|
+
}
|
|
26
|
+
};
|
package/lib/case.js
CHANGED
|
@@ -1,37 +1,18 @@
|
|
|
1
1
|
// Some properties can be optionally capitalized. We normalize them to lowercase
|
|
2
2
|
export const normalizeConfigCase = function ({ Build, build = Build, ...config }) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ignore = Ignore,
|
|
20
|
-
Processing,
|
|
21
|
-
processing = Processing,
|
|
22
|
-
Publish,
|
|
23
|
-
publish = Publish,
|
|
24
|
-
...build
|
|
25
|
-
} = {}) {
|
|
26
|
-
return {
|
|
27
|
-
...build,
|
|
28
|
-
base,
|
|
29
|
-
command,
|
|
30
|
-
edge_functions: edgeFunctions,
|
|
31
|
-
environment,
|
|
32
|
-
functions,
|
|
33
|
-
ignore,
|
|
34
|
-
processing,
|
|
35
|
-
publish,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
3
|
+
const buildA = normalizeBuildCase(build);
|
|
4
|
+
return { ...config, build: buildA };
|
|
5
|
+
};
|
|
6
|
+
const normalizeBuildCase = function ({ Base, base = Base, Command, command = Command, Edge_functions: EdgeFunctions, edge_functions: edgeFunctions = EdgeFunctions, Environment, environment = Environment, Functions, functions = Functions, Ignore, ignore = Ignore, Processing, processing = Processing, Publish, publish = Publish, ...build } = {}) {
|
|
7
|
+
return {
|
|
8
|
+
...build,
|
|
9
|
+
base,
|
|
10
|
+
command,
|
|
11
|
+
edge_functions: edgeFunctions,
|
|
12
|
+
environment,
|
|
13
|
+
functions,
|
|
14
|
+
ignore,
|
|
15
|
+
processing,
|
|
16
|
+
publish,
|
|
17
|
+
};
|
|
18
|
+
};
|
package/lib/context.js
CHANGED
|
@@ -1,108 +1,86 @@
|
|
|
1
|
-
import isPlainObj from 'is-plain-obj'
|
|
2
|
-
import mapObj from 'map-obj'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { validatePreContextConfig } from './validate/main.js'
|
|
8
|
-
|
|
1
|
+
import isPlainObj from 'is-plain-obj';
|
|
2
|
+
import mapObj from 'map-obj';
|
|
3
|
+
import { mergeConfigs } from './merge.js';
|
|
4
|
+
import { normalizeBeforeConfigMerge } from './merge_normalize.js';
|
|
5
|
+
import { validateContextsPluginsConfig } from './validate/context.js';
|
|
6
|
+
import { validatePreContextConfig } from './validate/main.js';
|
|
9
7
|
// Validate and normalize `config.context.*`
|
|
10
8
|
export const normalizeContextProps = function ({ config, config: { context: contextProps }, origin }) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return { ...config, context: normalizedContextProps }
|
|
23
|
-
}
|
|
24
|
-
|
|
9
|
+
if (contextProps === undefined) {
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
validatePreContextConfig(config);
|
|
13
|
+
const allContextProps = mapObj(contextProps, (key, contextConfig) => [key, addNamespace(contextConfig)]);
|
|
14
|
+
const normalizedContextProps = mapObj(allContextProps, (key, contextConfig) => [
|
|
15
|
+
key,
|
|
16
|
+
normalizeBeforeConfigMerge(contextConfig, origin),
|
|
17
|
+
]);
|
|
18
|
+
return { ...config, context: normalizedContextProps };
|
|
19
|
+
};
|
|
25
20
|
// Merge `config.context.{CONTEXT|BRANCH}.*` to `config.build.*` or `config.*`
|
|
26
21
|
// CONTEXT is the `--context` CLI flag.
|
|
27
22
|
// BRANCH is the `--branch` CLI flag.
|
|
28
|
-
export const mergeContext = function ({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const contexts = [context, branch]
|
|
40
|
-
validateContextsPluginsConfig({ contextProps, plugins, contexts, logs })
|
|
41
|
-
const filteredContextProps = contexts.map((key) => contextProps[key]).filter(Boolean)
|
|
42
|
-
return mergeConfigs([config, ...filteredContextProps])
|
|
43
|
-
}
|
|
44
|
-
|
|
23
|
+
export const mergeContext = function ({ config: { context: contextProps, ...config }, config: { plugins }, context, branch, logs, }) {
|
|
24
|
+
if (contextProps === undefined) {
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
const contexts = [context, branch];
|
|
28
|
+
validateContextsPluginsConfig({ contextProps, plugins, contexts, logs });
|
|
29
|
+
const filteredContextProps = contexts.map((key) => contextProps[key]).filter(Boolean);
|
|
30
|
+
return mergeConfigs([config, ...filteredContextProps]);
|
|
31
|
+
};
|
|
45
32
|
// `config.context.{context}.*` properties are merged either to `config.*` or
|
|
46
33
|
// to `config.build.*`. We distinguish between both by checking the property
|
|
47
34
|
// name.
|
|
48
|
-
const addNamespace = (contextConfig) => Object.entries(contextConfig).reduce(addNamespacedProperty, {})
|
|
49
|
-
|
|
35
|
+
const addNamespace = (contextConfig) => Object.entries(contextConfig).reduce(addNamespacedProperty, {});
|
|
50
36
|
const addNamespacedProperty = function (contextConfig, [key, value]) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
37
|
+
return isBuildProperty(key, value)
|
|
38
|
+
? { ...contextConfig, build: { ...contextConfig.build, [key]: value } }
|
|
39
|
+
: { ...contextConfig, [key]: value };
|
|
40
|
+
};
|
|
56
41
|
const isBuildProperty = function (key, value) {
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
42
|
+
return BUILD_PROPERTIES.has(key) && !isFunctionsConfig(key, value) && !isEdgeFunctionsConfig(key, value);
|
|
43
|
+
};
|
|
60
44
|
// All properties in `config.build.*`
|
|
61
45
|
const BUILD_PROPERTIES = new Set([
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
])
|
|
71
|
-
|
|
46
|
+
'base',
|
|
47
|
+
'command',
|
|
48
|
+
'edge_functions',
|
|
49
|
+
'environment',
|
|
50
|
+
'functions',
|
|
51
|
+
'ignore',
|
|
52
|
+
'processing',
|
|
53
|
+
'publish',
|
|
54
|
+
]);
|
|
72
55
|
// `config.functions` is a plain object while `config.build.functions` is a
|
|
73
56
|
// string.
|
|
74
57
|
const isFunctionsConfig = function (key, value) {
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
58
|
+
return key === 'functions' && isPlainObj(value);
|
|
59
|
+
};
|
|
78
60
|
// `config.edge_functions` is an array of objects while
|
|
79
61
|
// `config.build.edge_functions` is a string.
|
|
80
62
|
const isEdgeFunctionsConfig = function (key, value) {
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
63
|
+
return key === 'edge_functions' && Array.isArray(value);
|
|
64
|
+
};
|
|
84
65
|
// Ensure that `inlineConfig` has higher priority than context properties by
|
|
85
66
|
// assigining it to `context.*`. Still keep it at the top-level as well since
|
|
86
67
|
// some properties are not handled context-sensitively by the API.
|
|
87
68
|
// Takes into account that `context.{context}.build.*` is the same as
|
|
88
69
|
// `context.{context}.*`
|
|
89
70
|
export const ensureConfigPriority = function ({ build = {}, ...config }, context, branch) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
}
|
|
71
|
+
const base = {
|
|
72
|
+
...config,
|
|
73
|
+
build,
|
|
74
|
+
};
|
|
75
|
+
// remove the redirects to not have context specific redirects.
|
|
76
|
+
// The redirects should be only on the root level.
|
|
77
|
+
delete config.redirects;
|
|
78
|
+
return {
|
|
79
|
+
...base,
|
|
80
|
+
context: {
|
|
81
|
+
...config.context,
|
|
82
|
+
[context]: { ...config, ...build, build },
|
|
83
|
+
[branch]: { ...config, ...build, build },
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
package/lib/default.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import { addBuildSettings } from './api/build_settings.js'
|
|
2
|
-
import { logDefaultConfig } from './log/main.js'
|
|
3
|
-
|
|
1
|
+
import { addBuildSettings } from './api/build_settings.js';
|
|
2
|
+
import { logDefaultConfig } from './log/main.js';
|
|
4
3
|
// Retrieve default configuration file. It has less priority and it also does
|
|
5
4
|
// not get normalized, merged with contexts, etc.
|
|
6
5
|
export const parseDefaultConfig = function ({ defaultConfig, base, baseRelDir, siteInfo, logs, debug }) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
6
|
+
const defaultConfigB = addDefaultConfigBase(defaultConfig, base);
|
|
7
|
+
const { defaultConfig: defaultConfigC, baseRelDir: baseRelDirA = DEFAULT_BASE_REL_DIR } = addBuildSettings({
|
|
8
|
+
defaultConfig: defaultConfigB,
|
|
9
|
+
baseRelDir,
|
|
10
|
+
siteInfo,
|
|
11
|
+
});
|
|
12
|
+
logDefaultConfig(defaultConfigC, { logs, debug, baseRelDir: baseRelDirA });
|
|
13
|
+
return { defaultConfig: defaultConfigC, baseRelDir: baseRelDirA };
|
|
14
|
+
};
|
|
17
15
|
// When the `base` was overridden, add it to `defaultConfig` so it behaves
|
|
18
16
|
// as if it had been specified in the UI settings
|
|
19
17
|
const addDefaultConfigBase = function (defaultConfig, base) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
18
|
+
if (base === undefined) {
|
|
19
|
+
return defaultConfig;
|
|
20
|
+
}
|
|
21
|
+
const { build = {} } = defaultConfig;
|
|
22
|
+
return { ...defaultConfig, build: { ...build, base } };
|
|
23
|
+
};
|
|
28
24
|
// `baseRelDir` should default to `true` only if the option was not passed and
|
|
29
25
|
// it could be retrieved from the `siteInfo`, which is why the default value
|
|
30
26
|
// is assigned later than other properties.
|
|
31
|
-
const DEFAULT_BASE_REL_DIR = true
|
|
27
|
+
const DEFAULT_BASE_REL_DIR = true;
|
package/lib/env/envelope.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export const getEnvelope = async function ({ api, accountId, siteId }) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
2
|
+
if (accountId === undefined) {
|
|
3
|
+
return {};
|
|
4
|
+
}
|
|
5
|
+
try {
|
|
6
|
+
const environmentVariables = await api.getEnvVars({ accountId, siteId });
|
|
7
|
+
const sortedEnvVarsFromDevContext = environmentVariables
|
|
8
|
+
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
|
|
9
|
+
.reduce((acc, cur) => {
|
|
10
|
+
const envVar = cur.values.find((val) => ['dev', 'all'].includes(val.context));
|
|
11
|
+
if (envVar && envVar.value) {
|
|
12
|
+
return {
|
|
13
|
+
...acc,
|
|
14
|
+
[cur.key]: envVar.value,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
return sortedEnvVarsFromDevContext;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
};
|
package/lib/env/git.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { execa } from 'execa'
|
|
2
|
-
|
|
3
|
-
import { removeFalsy } from '../utils/remove_falsy.js'
|
|
4
|
-
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { removeFalsy } from '../utils/remove_falsy.js';
|
|
5
3
|
// Retrieve git-related information for use in environment variables.
|
|
6
4
|
// git is optional and there might be not git repository.
|
|
7
5
|
// We purposely keep this decoupled from the git utility.
|
|
8
6
|
export const getGitEnv = async function (buildDir, branch) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
7
|
+
const [COMMIT_REF, CACHED_COMMIT_REF] = await Promise.all([
|
|
8
|
+
git(['rev-parse', 'HEAD'], buildDir),
|
|
9
|
+
git(['rev-parse', 'HEAD^'], buildDir),
|
|
10
|
+
]);
|
|
11
|
+
const gitEnv = { BRANCH: branch, HEAD: branch, COMMIT_REF, CACHED_COMMIT_REF, PULL_REQUEST: 'false' };
|
|
12
|
+
const gitEnvA = removeFalsy(gitEnv);
|
|
13
|
+
return gitEnvA;
|
|
14
|
+
};
|
|
18
15
|
const git = async function (args, cwd) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
try {
|
|
17
|
+
const { stdout } = await execa('git', args, { cwd });
|
|
18
|
+
return stdout;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// continue regardless error
|
|
22
|
+
}
|
|
23
|
+
};
|