@netlify/config 20.3.2 → 20.3.3
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/lib/files.js +8 -9
- package/lib/main.js +1 -1
- package/lib/mutations/update.js +4 -5
- package/lib/options/base.js +2 -3
- package/lib/parse.js +22 -13
- package/lib/path.js +19 -13
- package/package.json +2 -3
package/lib/files.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
1
2
|
import { resolve, relative, parse } from 'path';
|
|
2
3
|
import { getProperty, setProperty, deleteProperty } from 'dot-prop';
|
|
3
|
-
import { pathExists } from 'path-exists';
|
|
4
4
|
import { throwUserError } from './error.js';
|
|
5
5
|
import { mergeConfigs } from './merge.js';
|
|
6
6
|
import { isTruthy } from './utils/remove_falsy.js';
|
|
7
7
|
// Make configuration paths relative to `buildDir` and converts them to
|
|
8
8
|
// absolute paths
|
|
9
|
-
export const resolveConfigPaths =
|
|
9
|
+
export const resolveConfigPaths = function ({ config, repositoryRoot, buildDir, baseRelDir }) {
|
|
10
10
|
const baseRel = baseRelDir ? buildDir : repositoryRoot;
|
|
11
11
|
const configA = resolvePaths(config, FILE_PATH_CONFIG_PROPS, baseRel, repositoryRoot);
|
|
12
|
-
const configB =
|
|
12
|
+
const configB = addDefaultPaths(configA, repositoryRoot, baseRel);
|
|
13
13
|
return configB;
|
|
14
14
|
};
|
|
15
15
|
// All file paths in the configuration file are are relative to `buildDir`
|
|
@@ -56,10 +56,9 @@ const getWindowsDrive = function (path) {
|
|
|
56
56
|
};
|
|
57
57
|
// Some configuration properties have default values that are only set if a
|
|
58
58
|
// specific directory/file exists in the build directory
|
|
59
|
-
const addDefaultPaths =
|
|
60
|
-
const defaultPathsConfigs =
|
|
61
|
-
|
|
62
|
-
return mergeConfigs([...defaultPathsConfigsA, config]);
|
|
59
|
+
const addDefaultPaths = function (config, repositoryRoot, baseRel) {
|
|
60
|
+
const defaultPathsConfigs = DEFAULT_PATHS.map(({ defaultPath, getConfig, propName }) => addDefaultPath({ repositoryRoot, baseRel, defaultPath, getConfig, propName })).filter(Boolean);
|
|
61
|
+
return mergeConfigs([...defaultPathsConfigs, config]);
|
|
63
62
|
};
|
|
64
63
|
const DEFAULT_PATHS = [
|
|
65
64
|
// @todo Remove once we drop support for the legacy default functions directory.
|
|
@@ -79,9 +78,9 @@ const DEFAULT_PATHS = [
|
|
|
79
78
|
propName: 'build.edge_functions',
|
|
80
79
|
},
|
|
81
80
|
];
|
|
82
|
-
const addDefaultPath =
|
|
81
|
+
const addDefaultPath = function ({ repositoryRoot, baseRel, defaultPath, getConfig, propName }) {
|
|
83
82
|
const absolutePath = resolvePath(repositoryRoot, baseRel, defaultPath, propName);
|
|
84
|
-
if (!(
|
|
83
|
+
if (!existsSync(absolutePath)) {
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
return getConfig(absolutePath);
|
package/lib/main.js
CHANGED
|
@@ -204,7 +204,7 @@ const normalizeConfigAndContext = function (config, origin) {
|
|
|
204
204
|
const resolveFiles = async function ({ config, repositoryRoot, base, baseRelDir }) {
|
|
205
205
|
const baseA = getBase(base, repositoryRoot, config);
|
|
206
206
|
const buildDir = await getBuildDir(repositoryRoot, baseA);
|
|
207
|
-
const configA =
|
|
207
|
+
const configA = resolveConfigPaths({ config, repositoryRoot, buildDir, baseRelDir });
|
|
208
208
|
const configB = addBase(configA, baseA);
|
|
209
209
|
return { config: configB, buildDir, base: baseA };
|
|
210
210
|
};
|
package/lib/mutations/update.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { pathExists } from 'path-exists';
|
|
1
|
+
import { existsSync, promises as fs } from 'fs';
|
|
3
2
|
import { ensureConfigPriority } from '../context.js';
|
|
4
3
|
import { addHeaders } from '../headers.js';
|
|
5
4
|
import { mergeConfigs } from '../merge.js';
|
|
@@ -41,7 +40,7 @@ const saveConfig = async function (configPath, simplifiedConfig) {
|
|
|
41
40
|
// Deletes `_headers/_redirects` since they are merged to `netlify.toml`,
|
|
42
41
|
// to fix any priority problem.
|
|
43
42
|
const deleteSideFile = async function (filePath) {
|
|
44
|
-
if (filePath === undefined || !(
|
|
43
|
+
if (filePath === undefined || !existsSync(filePath)) {
|
|
45
44
|
return;
|
|
46
45
|
}
|
|
47
46
|
await fs.unlink(filePath);
|
|
@@ -76,7 +75,7 @@ const getTempDir = function (buildDir) {
|
|
|
76
75
|
const backupFile = async function (original, backup) {
|
|
77
76
|
// this makes sure we don't restore stale files
|
|
78
77
|
await deleteNoError(backup);
|
|
79
|
-
if (!(
|
|
78
|
+
if (!existsSync(original)) {
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
81
|
await fs.copyFile(original, backup);
|
|
@@ -90,7 +89,7 @@ const deleteNoError = async (path) => {
|
|
|
90
89
|
}
|
|
91
90
|
};
|
|
92
91
|
const copyOrDelete = async function (src, dest) {
|
|
93
|
-
if (
|
|
92
|
+
if (existsSync(src)) {
|
|
94
93
|
await fs.copyFile(src, dest);
|
|
95
94
|
return;
|
|
96
95
|
}
|
package/lib/options/base.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
1
|
+
import { existsSync, promises as fs } from 'fs';
|
|
2
2
|
import { dirname, relative, sep } from 'path';
|
|
3
|
-
import { pathExists } from 'path-exists';
|
|
4
3
|
// Retrieve `base` override.
|
|
5
4
|
// This uses any directory below `repositoryRoot` and above (or equal to)
|
|
6
5
|
// `cwd` that has a `.netlify` or `netlify.toml`. This allows Netlify CLI users
|
|
@@ -47,7 +46,7 @@ const locatePath = async function (paths) {
|
|
|
47
46
|
return path;
|
|
48
47
|
};
|
|
49
48
|
const returnIfExists = async function (path) {
|
|
50
|
-
if (!(
|
|
49
|
+
if (!existsSync(path)) {
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
52
|
return path;
|
package/lib/parse.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { pathExists } from 'path-exists';
|
|
1
|
+
import { existsSync, promises as fs } from 'fs';
|
|
3
2
|
import { throwUserError } from './error.js';
|
|
4
3
|
import { throwOnInvalidTomlSequence } from './log/messages.js';
|
|
5
4
|
import { parseToml } from './utils/toml.js';
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Load the configuration file and parse it (TOML)
|
|
7
|
+
* @param configPath The path to the toml file
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
7
10
|
export const parseConfig = async function (configPath) {
|
|
8
11
|
if (configPath === undefined) {
|
|
9
12
|
return {};
|
|
10
13
|
}
|
|
11
|
-
if (!(
|
|
14
|
+
if (!existsSync(configPath)) {
|
|
12
15
|
throwUserError('Configuration file does not exist');
|
|
13
16
|
}
|
|
14
17
|
return await readConfigPath(configPath);
|
|
15
18
|
};
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Same but `configPath` is required and `configPath` might point to a
|
|
21
|
+
* non-existing file.
|
|
22
|
+
*/
|
|
18
23
|
export const parseOptionalConfig = async function (configPath) {
|
|
19
|
-
if (!(
|
|
24
|
+
if (!existsSync(configPath)) {
|
|
20
25
|
return {};
|
|
21
26
|
}
|
|
22
27
|
return await readConfigPath(configPath);
|
|
@@ -31,7 +36,9 @@ const readConfigPath = async function (configPath) {
|
|
|
31
36
|
throwUserError('Could not parse configuration file', error);
|
|
32
37
|
}
|
|
33
38
|
};
|
|
34
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Reach the configuration file's raw content
|
|
41
|
+
*/
|
|
35
42
|
const readConfig = async function (configPath) {
|
|
36
43
|
try {
|
|
37
44
|
return await fs.readFile(configPath, 'utf8');
|
|
@@ -48,9 +55,11 @@ const validateTomlBlackslashes = function (configString) {
|
|
|
48
55
|
const [, invalidTripleSequence, invalidSequence = invalidTripleSequence] = result;
|
|
49
56
|
throwOnInvalidTomlSequence(invalidSequence);
|
|
50
57
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The TOML specification forbids unrecognized backslash sequences. However,
|
|
60
|
+
* `toml-node` does not respect the specification and do not fail on those.
|
|
61
|
+
* Therefore, we print a warning message.
|
|
62
|
+
* This only applies to " and """ strings, not ' nor '''
|
|
63
|
+
* Also, """ strings can use trailing backslashes.
|
|
64
|
+
*/
|
|
56
65
|
const INVALID_TOML_BLACKSLASH = /\n[a-zA-Z]+ *= *(?:(?:""".*(?<!\\)(\\[^"\\btnfruU\n]).*""")|(?:"(?!")[^\n]*(?<!\\)(\\[^"\\btnfruU])[^\n]*"))/su;
|
package/lib/path.js
CHANGED
|
@@ -1,39 +1,45 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
1
2
|
import { resolve } from 'path';
|
|
2
3
|
import { findUp } from 'find-up';
|
|
3
4
|
import pLocate from 'p-locate';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Configuration location can be:
|
|
7
|
+
* - a local path with the --config CLI flag
|
|
8
|
+
* - a `netlify.*` file in the `repositoryRoot/{base}`
|
|
9
|
+
* - a `netlify.*` file in the `repositoryRoot`
|
|
10
|
+
* - a `netlify.*` file in the current directory or any parent
|
|
11
|
+
*/
|
|
10
12
|
export const getConfigPath = async function ({ configOpt, cwd, repositoryRoot, configBase }) {
|
|
11
13
|
const configPath = await pLocate([
|
|
12
14
|
searchConfigOpt(cwd, configOpt),
|
|
13
|
-
searchBaseConfigFile(
|
|
15
|
+
searchBaseConfigFile(configBase),
|
|
14
16
|
searchConfigFile(repositoryRoot),
|
|
15
17
|
findUp(FILENAME, { cwd }),
|
|
16
18
|
], Boolean);
|
|
17
19
|
return configPath;
|
|
18
20
|
};
|
|
19
|
-
|
|
21
|
+
/** --config CLI flag */
|
|
20
22
|
const searchConfigOpt = function (cwd, configOpt) {
|
|
21
23
|
if (configOpt === undefined) {
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
return resolve(cwd, configOpt);
|
|
25
27
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Look for `repositoryRoot/{base}/netlify.*`
|
|
30
|
+
*/
|
|
31
|
+
const searchBaseConfigFile = function (configBase) {
|
|
28
32
|
if (configBase === undefined) {
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
35
|
return searchConfigFile(configBase);
|
|
32
36
|
};
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Look for several file extensions for `netlify.*`
|
|
39
|
+
*/
|
|
40
|
+
const searchConfigFile = function (cwd) {
|
|
35
41
|
const path = resolve(cwd, FILENAME);
|
|
36
|
-
if (!(
|
|
42
|
+
if (!existsSync(path)) {
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
45
|
return path;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "20.3.
|
|
3
|
+
"version": "20.3.3",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/main.js",
|
|
@@ -75,7 +75,6 @@
|
|
|
75
75
|
"netlify-redirect-parser": "^14.1.1",
|
|
76
76
|
"omit.js": "^2.0.2",
|
|
77
77
|
"p-locate": "^6.0.0",
|
|
78
|
-
"path-exists": "^5.0.0",
|
|
79
78
|
"path-type": "^5.0.0",
|
|
80
79
|
"toml": "^3.0.0",
|
|
81
80
|
"tomlify-j0.4": "^3.0.0",
|
|
@@ -95,5 +94,5 @@
|
|
|
95
94
|
"engines": {
|
|
96
95
|
"node": "^14.16.0 || >=16.0.0"
|
|
97
96
|
},
|
|
98
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "d78a65c209ed987d3475cd1f37cf357693b99e3c"
|
|
99
98
|
}
|