@netlify/config 17.0.0 → 17.0.4
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/api/client.js +3 -5
- package/src/bin/flags.js +7 -1
- package/src/bin/main.js +3 -7
- package/src/cached_config.js +2 -5
- package/src/env/git.js +1 -1
- package/src/headers.js +2 -4
- package/src/log/serialize.js +1 -1
- package/src/main.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/redirects.js +2 -4
- 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.4",
|
|
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": "^16.0.0"
|
|
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/api/client.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NetlifyAPI } from 'netlify'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const jsClient = import('netlify')
|
|
3
|
+
import { removeUndefined } from '../utils/remove_falsy.js'
|
|
5
4
|
|
|
6
5
|
// Retrieve Netlify API client, if an access token was passed
|
|
7
|
-
export const getApiClient =
|
|
6
|
+
export const getApiClient = function ({ token, offline, testOpts = {}, host, scheme, pathPrefix }) {
|
|
8
7
|
if (!token || offline) {
|
|
9
8
|
return
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
// TODO: find less intrusive way to mock HTTP requests
|
|
13
12
|
const parameters = removeUndefined({ scheme: testOpts.scheme || scheme, host: testOpts.host || host, pathPrefix })
|
|
14
|
-
const { NetlifyAPI } = await jsClient
|
|
15
13
|
const api = new NetlifyAPI(token, parameters)
|
|
16
14
|
return api
|
|
17
15
|
}
|
package/src/bin/flags.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
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)
|
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/headers.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { resolve } from 'path'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { parseAllHeaders } from 'netlify-headers-parser'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const netlifyHeadersParser = import('netlify-headers-parser')
|
|
5
|
+
import { warnHeadersParsing, warnHeadersCaseSensitivity } from './log/messages.js'
|
|
7
6
|
|
|
8
7
|
// Retrieve path to `_headers` file (even if it does not exist yet)
|
|
9
8
|
export const getHeadersPath = function ({ build: { publish } }) {
|
|
@@ -14,7 +13,6 @@ const HEADERS_FILENAME = '_headers'
|
|
|
14
13
|
|
|
15
14
|
// Add `config.headers`
|
|
16
15
|
export const addHeaders = async function ({ headers: configHeaders, ...config }, headersPath, logs) {
|
|
17
|
-
const { parseAllHeaders } = await netlifyHeadersParser
|
|
18
16
|
const { headers, errors } = await parseAllHeaders({
|
|
19
17
|
headersFiles: [headersPath],
|
|
20
18
|
configHeaders,
|
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/main.js
CHANGED
|
@@ -31,7 +31,7 @@ export const resolveConfig = async function (opts) {
|
|
|
31
31
|
const { cachedConfig, cachedConfigPath, host, scheme, pathPrefix, testOpts, token, offline, ...optsA } =
|
|
32
32
|
addDefaultOpts(opts)
|
|
33
33
|
// `api` is not JSON-serializable, so we cannot cache it inside `cachedConfig`
|
|
34
|
-
const api =
|
|
34
|
+
const api = getApiClient({ token, offline, host, scheme, pathPrefix, testOpts })
|
|
35
35
|
|
|
36
36
|
const parsedCachedConfig = await getCachedConfig({ cachedConfig, cachedConfigPath, token, api })
|
|
37
37
|
if (parsedCachedConfig !== undefined) {
|
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
|
}
|
package/src/redirects.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { resolve } from 'path'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { parseAllRedirects } from 'netlify-redirect-parser'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const netlifyRedirectParser = import('netlify-redirect-parser')
|
|
5
|
+
import { warnRedirectsParsing } from './log/messages.js'
|
|
7
6
|
|
|
8
7
|
// Retrieve path to `_redirects` file (even if it does not exist yet)
|
|
9
8
|
export const getRedirectsPath = function ({ build: { publish } }) {
|
|
@@ -14,7 +13,6 @@ const REDIRECTS_FILENAME = '_redirects'
|
|
|
14
13
|
|
|
15
14
|
// Add `config.redirects`
|
|
16
15
|
export const addRedirects = async function ({ redirects: configRedirects, ...config }, redirectsPath, logs) {
|
|
17
|
-
const { parseAllRedirects } = await netlifyRedirectParser
|
|
18
16
|
const { redirects, errors } = await parseAllRedirects({
|
|
19
17
|
redirectsFiles: [redirectsPath],
|
|
20
18
|
configRedirects,
|