@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
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
// From CLI `--featureFlags=a,b,c` to programmatic `{ a: true, b: true, c: true }`
|
|
2
2
|
export const normalizeCliFeatureFlags = function (cliFeatureFlags) {
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
3
|
+
return Object.assign({}, ...cliFeatureFlags.split(',').filter(isNotEmpty).map(getFeatureFlag));
|
|
4
|
+
};
|
|
6
5
|
const isNotEmpty = function (name) {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
6
|
+
return name.trim() !== '';
|
|
7
|
+
};
|
|
10
8
|
const getFeatureFlag = function (name) {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
9
|
+
return { [name]: true };
|
|
10
|
+
};
|
|
14
11
|
// Default values for feature flags
|
|
15
|
-
export const DEFAULT_FEATURE_FLAGS = {}
|
|
12
|
+
export const DEFAULT_FEATURE_FLAGS = {};
|
package/lib/options/main.js
CHANGED
|
@@ -1,111 +1,91 @@
|
|
|
1
|
-
import { resolve } from 'path'
|
|
2
|
-
import process from 'process'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import { getBranch } from './branch.js'
|
|
13
|
-
import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
|
|
14
|
-
import { getRepositoryRoot } from './repository_root.js'
|
|
15
|
-
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import process from 'process';
|
|
3
|
+
import { isDirectory } from 'path-type';
|
|
4
|
+
import { throwUserError } from '../error.js';
|
|
5
|
+
import { getBufferLogs } from '../log/logger.js';
|
|
6
|
+
import { logOpts } from '../log/main.js';
|
|
7
|
+
import { removeFalsy } from '../utils/remove_falsy.js';
|
|
8
|
+
import { getBaseOverride } from './base.js';
|
|
9
|
+
import { getBranch } from './branch.js';
|
|
10
|
+
import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js';
|
|
11
|
+
import { getRepositoryRoot } from './repository_root.js';
|
|
16
12
|
// Assign default options
|
|
17
13
|
export const addDefaultOpts = function (opts = {}) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
logOpts(rawOpts, normalizedOptsA)
|
|
32
|
-
|
|
33
|
-
return normalizedOptsA
|
|
34
|
-
}
|
|
35
|
-
|
|
14
|
+
const rawOpts = removeFalsy(opts);
|
|
15
|
+
const defaultOpts = getDefaultOpts(rawOpts);
|
|
16
|
+
const mergedOpts = {
|
|
17
|
+
...defaultOpts,
|
|
18
|
+
...rawOpts,
|
|
19
|
+
featureFlags: { ...defaultOpts.featureFlags, ...rawOpts.featureFlags },
|
|
20
|
+
};
|
|
21
|
+
const normalizedOpts = removeFalsy(mergedOpts);
|
|
22
|
+
const logs = getBufferLogs(normalizedOpts);
|
|
23
|
+
const normalizedOptsA = { ...normalizedOpts, logs };
|
|
24
|
+
logOpts(rawOpts, normalizedOptsA);
|
|
25
|
+
return normalizedOptsA;
|
|
26
|
+
};
|
|
36
27
|
const getDefaultOpts = function ({ env: envOpt = {}, cwd: cwdOpt, defaultConfig = {} }) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
28
|
+
const combinedEnv = { ...process.env, ...envOpt };
|
|
29
|
+
return {
|
|
30
|
+
defaultConfig,
|
|
31
|
+
...getDefaultCwd(cwdOpt),
|
|
32
|
+
env: envOpt,
|
|
33
|
+
context: combinedEnv.CONTEXT || 'production',
|
|
34
|
+
branch: combinedEnv.BRANCH,
|
|
35
|
+
host: combinedEnv.NETLIFY_API_HOST,
|
|
36
|
+
token: combinedEnv.NETLIFY_AUTH_TOKEN,
|
|
37
|
+
siteId: combinedEnv.NETLIFY_SITE_ID,
|
|
38
|
+
deployId: combinedEnv.DEPLOY_ID || DEFAULT_DEPLOY_ID,
|
|
39
|
+
buildId: combinedEnv.BUILD_ID || DEFAULT_BUILD_ID,
|
|
40
|
+
mode: 'require',
|
|
41
|
+
offline: false,
|
|
42
|
+
debug: getDefaultDebug(combinedEnv, defaultConfig),
|
|
43
|
+
buffer: false,
|
|
44
|
+
featureFlags: DEFAULT_FEATURE_FLAGS,
|
|
45
|
+
inlineConfig: {},
|
|
46
|
+
configMutations: [],
|
|
47
|
+
};
|
|
48
|
+
};
|
|
59
49
|
// Local builds do not have any deploys, so some dummy ids are used instead
|
|
60
|
-
const DEFAULT_DEPLOY_ID = '0'
|
|
61
|
-
const DEFAULT_BUILD_ID = '0'
|
|
62
|
-
|
|
50
|
+
const DEFAULT_DEPLOY_ID = '0';
|
|
51
|
+
const DEFAULT_BUILD_ID = '0';
|
|
63
52
|
// --debug can be set using an environment variable `NETLIFY_BUILD_DEBUG` either
|
|
64
53
|
// locally or in the UI build settings
|
|
65
54
|
const getDefaultDebug = function (combinedEnv, { build: { environment = {} } = {} }) {
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
55
|
+
return Boolean(combinedEnv.NETLIFY_BUILD_DEBUG || environment.NETLIFY_BUILD_DEBUG);
|
|
56
|
+
};
|
|
69
57
|
// `process.cwd()` can throw, so only call it when needed
|
|
70
58
|
const getDefaultCwd = function (cwdOpt) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
59
|
+
if (cwdOpt !== undefined) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
const cwd = process.cwd();
|
|
63
|
+
return { cwd };
|
|
64
|
+
};
|
|
79
65
|
// Normalize options
|
|
80
66
|
export const normalizeOpts = async function (opts) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const optsE = { ...baseOverride, ...optsD }
|
|
92
|
-
return optsE
|
|
93
|
-
}
|
|
94
|
-
|
|
67
|
+
const repositoryRoot = await getRepositoryRoot(opts);
|
|
68
|
+
const optsA = { ...opts, repositoryRoot };
|
|
69
|
+
const branch = await getBranch(optsA);
|
|
70
|
+
const optsB = { ...optsA, branch };
|
|
71
|
+
const optsC = removeFalsy(optsB);
|
|
72
|
+
const optsD = await normalizeDirs(optsC);
|
|
73
|
+
const baseOverride = await getBaseOverride(optsD);
|
|
74
|
+
const optsE = { ...baseOverride, ...optsD };
|
|
75
|
+
return optsE;
|
|
76
|
+
};
|
|
95
77
|
// Verify that options point to existing directories.
|
|
96
78
|
// Also resolve them to absolute file paths.
|
|
97
79
|
const normalizeDirs = async function (opts) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const DIR_OPTIONS = ['cwd', 'repositoryRoot']
|
|
103
|
-
|
|
80
|
+
const dirOpts = await Promise.all(DIR_OPTIONS.map((optName) => normalizeDir(opts, optName)));
|
|
81
|
+
return Object.assign({}, opts, ...dirOpts);
|
|
82
|
+
};
|
|
83
|
+
const DIR_OPTIONS = ['cwd', 'repositoryRoot'];
|
|
104
84
|
const normalizeDir = async function (opts, optName) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
85
|
+
const path = opts[optName];
|
|
86
|
+
const resolvedPath = resolve(path);
|
|
87
|
+
if (!(await isDirectory(path))) {
|
|
88
|
+
throwUserError(`Option '${optName}' points to a non-existing directory: ${resolvedPath}`);
|
|
89
|
+
}
|
|
90
|
+
return { [optName]: resolvedPath };
|
|
91
|
+
};
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { dirname } from 'path'
|
|
2
|
-
|
|
3
|
-
import { findUp } from 'find-up'
|
|
4
|
-
|
|
1
|
+
import { dirname } from 'path';
|
|
2
|
+
import { findUp } from 'find-up';
|
|
5
3
|
// Find out repository root among (in priority order):
|
|
6
4
|
// - `repositoryRoot` option
|
|
7
5
|
// - find a `.git` directory up from `cwd`
|
|
8
6
|
// - `cwd` (fallback)
|
|
9
7
|
export const getRepositoryRoot = async function ({ repositoryRoot, cwd }) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return dirname(repositoryRootA)
|
|
21
|
-
}
|
|
8
|
+
if (repositoryRoot !== undefined) {
|
|
9
|
+
return repositoryRoot;
|
|
10
|
+
}
|
|
11
|
+
const repositoryRootA = await findUp('.git', { cwd, type: 'directory' });
|
|
12
|
+
if (repositoryRootA === undefined) {
|
|
13
|
+
return cwd;
|
|
14
|
+
}
|
|
15
|
+
return dirname(repositoryRootA);
|
|
16
|
+
};
|
package/lib/origin.js
CHANGED
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
import { isTruthy } from './utils/remove_falsy.js'
|
|
2
|
-
|
|
1
|
+
import { isTruthy } from './utils/remove_falsy.js';
|
|
3
2
|
// `build.commandOrigin`, `build.publishOrigin` and `plugins[*].origin` constants
|
|
4
|
-
export const UI_ORIGIN = 'ui'
|
|
5
|
-
export const CONFIG_ORIGIN = 'config'
|
|
6
|
-
export const DEFAULT_ORIGIN = 'default'
|
|
7
|
-
export const INLINE_ORIGIN = 'inline'
|
|
8
|
-
|
|
3
|
+
export const UI_ORIGIN = 'ui';
|
|
4
|
+
export const CONFIG_ORIGIN = 'config';
|
|
5
|
+
export const DEFAULT_ORIGIN = 'default';
|
|
6
|
+
export const INLINE_ORIGIN = 'inline';
|
|
9
7
|
// Add `build.commandOrigin`, `build.publishOrigin` and `plugins[*].origin`.
|
|
10
8
|
// This shows whether those properties came from the `ui` or from the `config`.
|
|
11
9
|
export const addOrigins = function (config, origin) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
10
|
+
const configA = addBuildCommandOrigin({ config, origin });
|
|
11
|
+
const configB = addBuildPublishOrigin({ config: configA, origin });
|
|
12
|
+
const configC = addConfigPluginOrigin({ config: configB, origin });
|
|
13
|
+
const configD = addHeadersOrigin({ config: configC, origin });
|
|
14
|
+
const configE = addRedirectsOrigin({ config: configD, origin });
|
|
15
|
+
return configE;
|
|
16
|
+
};
|
|
20
17
|
const addBuildCommandOrigin = function ({ config, config: { build = {} }, origin }) {
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
18
|
+
return isTruthy(build.command) ? { ...config, build: { ...build, commandOrigin: origin } } : config;
|
|
19
|
+
};
|
|
24
20
|
const addBuildPublishOrigin = function ({ config, config: { build = {} }, origin }) {
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
21
|
+
return isTruthy(build.publish) ? { ...config, build: { ...build, publishOrigin: origin } } : config;
|
|
22
|
+
};
|
|
28
23
|
const addConfigPluginOrigin = function ({ config, config: { plugins }, origin }) {
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
24
|
+
return Array.isArray(plugins) ? { ...config, plugins: plugins.map((plugin) => ({ ...plugin, origin })) } : config;
|
|
25
|
+
};
|
|
32
26
|
const addHeadersOrigin = function ({ config, config: { headers }, origin }) {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
27
|
+
return isTruthy(headers) ? { ...config, headersOrigin: origin } : config;
|
|
28
|
+
};
|
|
36
29
|
const addRedirectsOrigin = function ({ config, config: { redirects }, origin }) {
|
|
37
|
-
|
|
38
|
-
}
|
|
30
|
+
return isTruthy(redirects) ? { ...config, redirectsOrigin: origin } : config;
|
|
31
|
+
};
|
package/lib/parse.js
CHANGED
|
@@ -1,69 +1,56 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { throwOnInvalidTomlSequence } from './log/messages.js'
|
|
7
|
-
import { parseToml } from './utils/toml.js'
|
|
8
|
-
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { pathExists } from 'path-exists';
|
|
3
|
+
import { throwUserError } from './error.js';
|
|
4
|
+
import { throwOnInvalidTomlSequence } from './log/messages.js';
|
|
5
|
+
import { parseToml } from './utils/toml.js';
|
|
9
6
|
// Load the configuration file and parse it (TOML)
|
|
10
7
|
export const parseConfig = async function (configPath) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return await readConfigPath(configPath)
|
|
20
|
-
}
|
|
21
|
-
|
|
8
|
+
if (configPath === undefined) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
if (!(await pathExists(configPath))) {
|
|
12
|
+
throwUserError('Configuration file does not exist');
|
|
13
|
+
}
|
|
14
|
+
return await readConfigPath(configPath);
|
|
15
|
+
};
|
|
22
16
|
// Same but `configPath` is required and `configPath` might point to a
|
|
23
17
|
// non-existing file.
|
|
24
18
|
export const parseOptionalConfig = async function (configPath) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
19
|
+
if (!(await pathExists(configPath))) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
return await readConfigPath(configPath);
|
|
23
|
+
};
|
|
32
24
|
const readConfigPath = async function (configPath) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
25
|
+
const configString = await readConfig(configPath);
|
|
26
|
+
validateTomlBlackslashes(configString);
|
|
27
|
+
try {
|
|
28
|
+
return parseToml(configString);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throwUserError('Could not parse configuration file', error);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
44
34
|
// Reach the configuration file's raw content
|
|
45
35
|
const readConfig = async function (configPath) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
36
|
+
try {
|
|
37
|
+
return await fs.readFile(configPath, 'utf8');
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throwUserError('Could not read configuration file', error);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
53
43
|
const validateTomlBlackslashes = function (configString) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
44
|
+
const result = INVALID_TOML_BLACKSLASH.exec(configString);
|
|
45
|
+
if (result === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const [, invalidTripleSequence, invalidSequence = invalidTripleSequence] = result;
|
|
49
|
+
throwOnInvalidTomlSequence(invalidSequence);
|
|
50
|
+
};
|
|
63
51
|
// The TOML specification forbids unrecognized backslash sequences. However,
|
|
64
52
|
// `toml-node` does not respect the specification and do not fail on those.
|
|
65
53
|
// Therefore, we print a warning message.
|
|
66
54
|
// This only applies to " and """ strings, not ' nor '''
|
|
67
55
|
// Also, """ strings can use trailing backslashes.
|
|
68
|
-
const INVALID_TOML_BLACKSLASH =
|
|
69
|
-
/\n[a-zA-Z]+ *= *(?:(?:""".*(?<!\\)(\\[^"\\btnfruU\n]).*""")|(?:"(?!")[^\n]*(?<!\\)(\\[^"\\btnfruU])[^\n]*"))/su
|
|
56
|
+
const INVALID_TOML_BLACKSLASH = /\n[a-zA-Z]+ *= *(?:(?:""".*(?<!\\)(\\[^"\\btnfruU\n]).*""")|(?:"(?!")[^\n]*(?<!\\)(\\[^"\\btnfruU])[^\n]*"))/su;
|
package/lib/path.js
CHANGED
|
@@ -1,52 +1,41 @@
|
|
|
1
|
-
import { resolve } from 'path'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { pathExists } from 'path-exists'
|
|
6
|
-
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { findUp } from 'find-up';
|
|
3
|
+
import pLocate from 'p-locate';
|
|
4
|
+
import { pathExists } from 'path-exists';
|
|
7
5
|
// Configuration location can be:
|
|
8
6
|
// - a local path with the --config CLI flag
|
|
9
7
|
// - a `netlify.*` file in the `repositoryRoot/{base}`
|
|
10
8
|
// - a `netlify.*` file in the `repositoryRoot`
|
|
11
9
|
// - a `netlify.*` file in the current directory or any parent
|
|
12
10
|
export const getConfigPath = async function ({ configOpt, cwd, repositoryRoot, configBase }) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
return configPath
|
|
23
|
-
}
|
|
24
|
-
|
|
11
|
+
const configPath = await pLocate([
|
|
12
|
+
searchConfigOpt(cwd, configOpt),
|
|
13
|
+
searchBaseConfigFile(repositoryRoot, configBase),
|
|
14
|
+
searchConfigFile(repositoryRoot),
|
|
15
|
+
findUp(FILENAME, { cwd }),
|
|
16
|
+
], Boolean);
|
|
17
|
+
return configPath;
|
|
18
|
+
};
|
|
25
19
|
// --config CLI flag
|
|
26
20
|
const searchConfigOpt = function (cwd, configOpt) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
21
|
+
if (configOpt === undefined) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return resolve(cwd, configOpt);
|
|
25
|
+
};
|
|
34
26
|
// Look for `repositoryRoot/{base}/netlify.*`
|
|
35
27
|
const searchBaseConfigFile = function (repositoryRoot, configBase) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
28
|
+
if (configBase === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return searchConfigFile(configBase);
|
|
32
|
+
};
|
|
43
33
|
// Look for several file extensions for `netlify.*`
|
|
44
34
|
const searchConfigFile = async function (cwd) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const FILENAME = 'netlify.toml'
|
|
35
|
+
const path = resolve(cwd, FILENAME);
|
|
36
|
+
if (!(await pathExists(path))) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return path;
|
|
40
|
+
};
|
|
41
|
+
const FILENAME = 'netlify.toml';
|
package/lib/redirects.js
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import { resolve } from 'path'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { warnRedirectsParsing } from './log/messages.js'
|
|
6
|
-
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { parseAllRedirects } from 'netlify-redirect-parser';
|
|
3
|
+
import { warnRedirectsParsing } from './log/messages.js';
|
|
7
4
|
// Retrieve path to `_redirects` file (even if it does not exist yet)
|
|
8
5
|
export const getRedirectsPath = function ({ build: { publish } }) {
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const REDIRECTS_FILENAME = '_redirects'
|
|
13
|
-
|
|
6
|
+
return resolve(publish, REDIRECTS_FILENAME);
|
|
7
|
+
};
|
|
8
|
+
const REDIRECTS_FILENAME = '_redirects';
|
|
14
9
|
// Add `config.redirects`
|
|
15
|
-
export const addRedirects = async function ({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
featureFlags,
|
|
26
|
-
})
|
|
27
|
-
warnRedirectsParsing(logs, errors)
|
|
28
|
-
return { ...config, redirects }
|
|
29
|
-
}
|
|
10
|
+
export const addRedirects = async function ({ config: { redirects: configRedirects, ...config }, redirectsPath, logs, featureFlags, }) {
|
|
11
|
+
const { redirects, errors } = await parseAllRedirects({
|
|
12
|
+
redirectsFiles: [redirectsPath],
|
|
13
|
+
configRedirects,
|
|
14
|
+
minimal: true,
|
|
15
|
+
featureFlags,
|
|
16
|
+
});
|
|
17
|
+
warnRedirectsParsing(logs, errors);
|
|
18
|
+
return { ...config, redirects };
|
|
19
|
+
};
|