@netlify/config 17.0.1 → 17.0.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/package.json +6 -7
- package/src/bin/flags.js +15 -5
- package/src/bin/main.js +3 -7
- package/src/cached_config.js +2 -5
- package/src/env/git.js +1 -1
- package/src/log/serialize.js +1 -1
- package/src/mutations/update.js +8 -14
- package/src/options/base.js +2 -5
- package/src/options/branch.js +1 -1
- package/src/parse.js +2 -5
- package/src/validate/validations.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.5",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/main.js",
|
|
@@ -63,11 +63,10 @@
|
|
|
63
63
|
"indent-string": "^4.0.0",
|
|
64
64
|
"is-plain-obj": "^3.0.0",
|
|
65
65
|
"js-yaml": "^4.0.0",
|
|
66
|
-
"make-dir": "^3.1.0",
|
|
67
66
|
"map-obj": "^4.0.0",
|
|
68
|
-
"netlify": "^10.
|
|
69
|
-
"netlify-headers-parser": "^6.0.
|
|
70
|
-
"netlify-redirect-parser": "^13.0.
|
|
67
|
+
"netlify": "^10.1.2",
|
|
68
|
+
"netlify-headers-parser": "^6.0.1",
|
|
69
|
+
"netlify-redirect-parser": "^13.0.1",
|
|
71
70
|
"omit.js": "^2.0.2",
|
|
72
71
|
"p-locate": "^5.0.0",
|
|
73
72
|
"path-exists": "^4.0.0",
|
|
@@ -75,11 +74,11 @@
|
|
|
75
74
|
"toml": "^3.0.0",
|
|
76
75
|
"tomlify-j0.4": "^3.0.0",
|
|
77
76
|
"validate-npm-package-name": "^3.0.0",
|
|
78
|
-
"yargs": "^
|
|
77
|
+
"yargs": "^17.3.1"
|
|
79
78
|
},
|
|
80
79
|
"devDependencies": {
|
|
81
80
|
"ava": "^3.15.0",
|
|
82
|
-
"del": "^
|
|
81
|
+
"del": "^6.0.0",
|
|
83
82
|
"has-ansi": "^4.0.0",
|
|
84
83
|
"is-ci": "^3.0.0",
|
|
85
84
|
"tmp-promise": "^3.0.2"
|
package/src/bin/flags.js
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
|
|
3
|
+
import process from 'process'
|
|
4
|
+
|
|
3
5
|
import filterObj from 'filter-obj'
|
|
4
6
|
import yargs from 'yargs'
|
|
7
|
+
import { hideBin } from 'yargs/helpers'
|
|
5
8
|
|
|
6
9
|
import { normalizeCliFeatureFlags } from '../options/feature_flags.js'
|
|
7
10
|
|
|
8
11
|
// Parse CLI flags
|
|
9
12
|
export const parseFlags = function () {
|
|
10
|
-
const { featureFlags: cliFeatureFlags = '', ...flags } = yargs
|
|
13
|
+
const { featureFlags: cliFeatureFlags = '', ...flags } = yargs(hideBin(process.argv))
|
|
14
|
+
.options(FLAGS)
|
|
15
|
+
.usage(USAGE)
|
|
16
|
+
.parse()
|
|
11
17
|
const featureFlags = normalizeCliFeatureFlags(cliFeatureFlags)
|
|
12
18
|
const flagsA = { ...flags, featureFlags }
|
|
13
19
|
const flagsB = filterObj(flagsA, isUserFlag)
|
|
14
20
|
return flagsB
|
|
15
21
|
}
|
|
16
22
|
|
|
23
|
+
const jsonParse = function (value) {
|
|
24
|
+
return value === undefined ? undefined : JSON.parse(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
// List of CLI flags
|
|
18
28
|
const FLAGS = {
|
|
19
29
|
config: {
|
|
@@ -26,7 +36,7 @@ Defaults to any netlify.toml in the git repository root directory or the base di
|
|
|
26
36
|
describe: `JSON configuration object containing default values.
|
|
27
37
|
Each configuration default value is used unless overriden through the main configuration file.
|
|
28
38
|
Default: none.`,
|
|
29
|
-
coerce:
|
|
39
|
+
coerce: jsonParse,
|
|
30
40
|
hidden: true,
|
|
31
41
|
},
|
|
32
42
|
cachedConfig: {
|
|
@@ -35,7 +45,7 @@ Default: none.`,
|
|
|
35
45
|
or when using @netlify/config programmatically.
|
|
36
46
|
This is done as a performance optimization to cache the configuration loading logic.
|
|
37
47
|
Default: none.`,
|
|
38
|
-
coerce:
|
|
48
|
+
coerce: jsonParse,
|
|
39
49
|
hidden: true,
|
|
40
50
|
},
|
|
41
51
|
cachedConfigPath: {
|
|
@@ -50,7 +60,7 @@ Default: none.`,
|
|
|
50
60
|
string: true,
|
|
51
61
|
describe: `JSON configuration object overriding the configuration file and other settings.
|
|
52
62
|
Default: none.`,
|
|
53
|
-
coerce:
|
|
63
|
+
coerce: jsonParse,
|
|
54
64
|
hidden: true,
|
|
55
65
|
},
|
|
56
66
|
configMutations: {
|
|
@@ -61,7 +71,7 @@ Each change must be an object with three properties:
|
|
|
61
71
|
- "value": new value of that property
|
|
62
72
|
- "event": build event when this change was applied, e.g. "onPreBuild"
|
|
63
73
|
Default: empty array.`,
|
|
64
|
-
coerce:
|
|
74
|
+
coerce: jsonParse,
|
|
65
75
|
hidden: true,
|
|
66
76
|
},
|
|
67
77
|
cwd: {
|
package/src/bin/main.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { promises as fs } from 'fs'
|
|
4
4
|
import { dirname } from 'path'
|
|
5
5
|
import process from 'process'
|
|
6
|
-
import { promisify } from 'util'
|
|
7
6
|
|
|
8
7
|
import fastSafeStringify from 'fast-safe-stringify'
|
|
9
|
-
import makeDir from 'make-dir'
|
|
10
8
|
import omit from 'omit.js'
|
|
11
9
|
|
|
12
10
|
import { isUserError } from '../error.js'
|
|
@@ -14,8 +12,6 @@ import { resolveConfig } from '../main.js'
|
|
|
14
12
|
|
|
15
13
|
import { parseFlags } from './flags.js'
|
|
16
14
|
|
|
17
|
-
const pWriteFile = promisify(writeFile)
|
|
18
|
-
|
|
19
15
|
// CLI entry point
|
|
20
16
|
const runCli = async function () {
|
|
21
17
|
try {
|
|
@@ -45,8 +41,8 @@ const outputResult = async function (resultJson, output) {
|
|
|
45
41
|
return
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
await
|
|
49
|
-
await
|
|
44
|
+
await fs.mkdir(dirname(output), { recursive: true })
|
|
45
|
+
await fs.writeFile(output, resultJson)
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
// `api` is not JSON-serializable, so we remove it
|
package/src/cached_config.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
|
|
4
|
-
const pReadFile = promisify(readFile)
|
|
1
|
+
import { promises as fs } from 'fs'
|
|
5
2
|
|
|
6
3
|
// Performance optimization when @netlify/config caller has already previously
|
|
7
4
|
// called it and cached the result.
|
|
@@ -27,6 +24,6 @@ const parseCachedConfig = async function (cachedConfig, cachedConfigPath) {
|
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
if (cachedConfigPath !== undefined) {
|
|
30
|
-
return JSON.parse(await
|
|
27
|
+
return JSON.parse(await fs.readFile(cachedConfigPath))
|
|
31
28
|
}
|
|
32
29
|
}
|
package/src/env/git.js
CHANGED
package/src/log/serialize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dump } from 'js-yaml'
|
|
2
2
|
|
|
3
3
|
export const serializeObject = function (object) {
|
|
4
|
-
return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).
|
|
4
|
+
return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimEnd()
|
|
5
5
|
}
|
package/src/mutations/update.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from 'util'
|
|
1
|
+
import { promises as fs } from 'fs'
|
|
3
2
|
|
|
4
|
-
import makeDir from 'make-dir'
|
|
5
3
|
import pathExists from 'path-exists'
|
|
6
4
|
|
|
7
5
|
import { ensureConfigPriority } from '../context.js'
|
|
@@ -14,10 +12,6 @@ import { serializeToml } from '../utils/toml.js'
|
|
|
14
12
|
|
|
15
13
|
import { applyMutations } from './apply.js'
|
|
16
14
|
|
|
17
|
-
const pWriteFile = promisify(writeFile)
|
|
18
|
-
const pUnlink = promisify(unlink)
|
|
19
|
-
const pCopyFile = promisify(copyFile)
|
|
20
|
-
|
|
21
15
|
// Persist configuration changes to `netlify.toml`.
|
|
22
16
|
// If `netlify.toml` does not exist, creates it. Otherwise, merges the changes.
|
|
23
17
|
export const updateConfig = async function (
|
|
@@ -52,7 +46,7 @@ const mergeWithConfig = async function (normalizedInlineConfig, configPath) {
|
|
|
52
46
|
// Serialize the changes to `netlify.toml`
|
|
53
47
|
const saveConfig = async function (configPath, simplifiedConfig) {
|
|
54
48
|
const serializedConfig = serializeToml(simplifiedConfig)
|
|
55
|
-
await
|
|
49
|
+
await fs.writeFile(configPath, serializedConfig)
|
|
56
50
|
}
|
|
57
51
|
|
|
58
52
|
// Deletes `_headers/_redirects` since they are merged to `netlify.toml`,
|
|
@@ -62,7 +56,7 @@ const deleteSideFile = async function (filePath) {
|
|
|
62
56
|
return
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
await
|
|
59
|
+
await fs.unlink(filePath)
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
// Modifications to `netlify.toml` and `_headers/_redirects` are only meant for
|
|
@@ -71,7 +65,7 @@ const deleteSideFile = async function (filePath) {
|
|
|
71
65
|
// We do this by backing them up inside some sibling directory.
|
|
72
66
|
const backupConfig = async function ({ buildDir, configPath, headersPath, redirectsPath }) {
|
|
73
67
|
const tempDir = getTempDir(buildDir)
|
|
74
|
-
await
|
|
68
|
+
await fs.mkdir(tempDir, { recursive: true })
|
|
75
69
|
await Promise.all([
|
|
76
70
|
backupFile(configPath, `${tempDir}/netlify.toml`),
|
|
77
71
|
backupFile(headersPath, `${tempDir}/_headers`),
|
|
@@ -104,18 +98,18 @@ const backupFile = async function (original, backup) {
|
|
|
104
98
|
return
|
|
105
99
|
}
|
|
106
100
|
|
|
107
|
-
await
|
|
101
|
+
await fs.copyFile(original, backup)
|
|
108
102
|
}
|
|
109
103
|
|
|
110
104
|
const deleteNoError = async (path) => {
|
|
111
105
|
try {
|
|
112
|
-
await
|
|
113
|
-
} catch
|
|
106
|
+
await fs.unlink(path)
|
|
107
|
+
} catch {}
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
const copyOrDelete = async function (src, dest) {
|
|
117
111
|
if (await pathExists(src)) {
|
|
118
|
-
await
|
|
112
|
+
await fs.copyFile(src, dest)
|
|
119
113
|
return
|
|
120
114
|
}
|
|
121
115
|
|
package/src/options/base.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { promises as fs } from 'fs'
|
|
2
2
|
import { dirname, relative, sep } from 'path'
|
|
3
|
-
import { promisify } from 'util'
|
|
4
3
|
|
|
5
4
|
import pathExists from 'path-exists'
|
|
6
5
|
|
|
7
|
-
const pRealpath = promisify(realpath)
|
|
8
|
-
|
|
9
6
|
// Retrieve `base` override.
|
|
10
7
|
// This uses any directory below `repositoryRoot` and above (or equal to)
|
|
11
8
|
// `cwd` that has a `.netlify` or `netlify.toml`. This allows Netlify CLI users
|
|
@@ -17,7 +14,7 @@ export const getBaseOverride = async function ({ repositoryRoot, cwd }) {
|
|
|
17
14
|
return {}
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
const [repositoryRootA, cwdA] = await Promise.all([
|
|
17
|
+
const [repositoryRootA, cwdA] = await Promise.all([fs.realpath(repositoryRoot), fs.realpath(cwd)])
|
|
21
18
|
const basePaths = getBasePaths(repositoryRootA, cwdA)
|
|
22
19
|
const basePath = await locatePath(basePaths)
|
|
23
20
|
|
package/src/options/branch.js
CHANGED
|
@@ -28,7 +28,7 @@ const getGitBranch = async function (repositoryRoot, gitRef) {
|
|
|
28
28
|
try {
|
|
29
29
|
const { stdout } = await execa.command(`git rev-parse --abbrev-ref ${gitRef}`, { cwd: repositoryRoot })
|
|
30
30
|
return stdout
|
|
31
|
-
} catch
|
|
31
|
+
} catch {}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const FALLBACK_BRANCH = 'master'
|
package/src/parse.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from 'util'
|
|
1
|
+
import { promises as fs } from 'fs'
|
|
3
2
|
|
|
4
3
|
import pathExists from 'path-exists'
|
|
5
4
|
|
|
@@ -7,8 +6,6 @@ import { throwUserError } from './error.js'
|
|
|
7
6
|
import { throwOnInvalidTomlSequence } from './log/messages.js'
|
|
8
7
|
import { parseToml } from './utils/toml.js'
|
|
9
8
|
|
|
10
|
-
const pReadFile = promisify(readFile)
|
|
11
|
-
|
|
12
9
|
// Load the configuration file and parse it (TOML)
|
|
13
10
|
export const parseConfig = async function (configPath) {
|
|
14
11
|
if (configPath === undefined) {
|
|
@@ -47,7 +44,7 @@ const readConfigPath = async function (configPath) {
|
|
|
47
44
|
// Reach the configuration file's raw content
|
|
48
45
|
const readConfig = async function (configPath) {
|
|
49
46
|
try {
|
|
50
|
-
return await
|
|
47
|
+
return await fs.readFile(configPath, 'utf8')
|
|
51
48
|
} catch (error) {
|
|
52
49
|
throwUserError('Could not read configuration file', error)
|
|
53
50
|
}
|