@netlify/config 16.0.4 → 17.0.0

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.
Files changed (55) hide show
  1. package/README.md +4 -4
  2. package/package.json +7 -6
  3. package/src/api/build_settings.js +2 -6
  4. package/src/api/client.js +5 -7
  5. package/src/api/site_info.js +2 -6
  6. package/src/base.js +4 -8
  7. package/src/bin/flags.js +5 -8
  8. package/src/bin/main.js +12 -13
  9. package/src/build_dir.js +3 -7
  10. package/src/cached_config.js +3 -7
  11. package/src/case.js +1 -5
  12. package/src/context.js +9 -13
  13. package/src/default.js +3 -7
  14. package/src/env/git.js +3 -7
  15. package/src/env/main.js +5 -9
  16. package/src/error.js +2 -6
  17. package/src/events.js +1 -5
  18. package/src/files.js +11 -15
  19. package/src/functions_config.js +6 -10
  20. package/src/headers.js +7 -9
  21. package/src/inline_config.js +3 -7
  22. package/src/log/cleanup.js +4 -8
  23. package/src/log/logger.js +9 -13
  24. package/src/log/main.js +7 -11
  25. package/src/log/messages.js +9 -21
  26. package/src/log/options.js +4 -8
  27. package/src/log/serialize.js +2 -6
  28. package/src/log/theme.js +6 -15
  29. package/src/main.js +24 -33
  30. package/src/merge.js +5 -9
  31. package/src/merge_normalize.js +8 -15
  32. package/src/mutations/apply.js +6 -10
  33. package/src/mutations/config_prop_name.js +1 -5
  34. package/src/mutations/update.js +14 -18
  35. package/src/normalize.js +5 -9
  36. package/src/options/base.js +5 -9
  37. package/src/options/branch.js +2 -6
  38. package/src/options/feature_flags.js +2 -6
  39. package/src/options/main.js +13 -17
  40. package/src/options/repository_root.js +3 -7
  41. package/src/origin.js +6 -10
  42. package/src/parse.js +8 -12
  43. package/src/path.js +5 -9
  44. package/src/redirects.js +7 -9
  45. package/src/simplify.js +6 -10
  46. package/src/utils/group.js +1 -5
  47. package/src/utils/remove_falsy.js +5 -9
  48. package/src/utils/set.js +2 -6
  49. package/src/utils/toml.js +4 -8
  50. package/src/validate/context.js +3 -7
  51. package/src/validate/example.js +4 -8
  52. package/src/validate/helpers.js +6 -16
  53. package/src/validate/identical.js +2 -6
  54. package/src/validate/main.js +10 -20
  55. package/src/validate/validations.js +10 -19
package/README.md CHANGED
@@ -16,16 +16,16 @@ npm install @netlify/config
16
16
 
17
17
  # Usage (Node.js)
18
18
 
19
- ## getNetlifyConfig(options?)
19
+ ## resolveConfig(options?)
20
20
 
21
21
  `options`: `object?`\
22
22
  _Return value_: `Promise<object>`
23
23
 
24
24
  ```js
25
- const getNetlifyConfig = require('@netlify/config')
25
+ import { resolveConfig } from '@netlify/config'
26
26
 
27
27
  const exampleFunction = async function () {
28
- const { config, configPath, buildDir, context, branch, token, siteInfo } = await getNetlifyConfig(options)
28
+ const { config, configPath, buildDir, context, branch, token, siteInfo } = await resolveConfig(options)
29
29
  // {
30
30
  // "siteInfo": {
31
31
  // "id": "418b94bc-93cd-411a-937a-ae4c734f17c4",
@@ -375,6 +375,6 @@ Site's environment variables. Each environment variable value is an object with
375
375
  $ netlify-config
376
376
  ```
377
377
 
378
- Like [`getNetlifyConfig()`](getnetlifyconfigoptions), but in the CLI. The return value is printed on `stdout`.
378
+ Like [`resolveConfig()`](resolveconfig), but in the CLI. The return value is printed on `stdout`.
379
379
 
380
380
  The CLI flags use the same options.
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@netlify/config",
3
- "version": "16.0.4",
3
+ "version": "17.0.0",
4
4
  "description": "Netlify config module",
5
- "main": "src/main.js",
5
+ "type": "module",
6
+ "exports": "./src/main.js",
7
+ "main": "./src/main.js",
6
8
  "bin": {
7
9
  "netlify-config": "src/bin/main.js"
8
10
  },
@@ -63,9 +65,9 @@
63
65
  "js-yaml": "^4.0.0",
64
66
  "make-dir": "^3.1.0",
65
67
  "map-obj": "^4.0.0",
66
- "netlify": "^9.0.0",
67
- "netlify-headers-parser": "^5.0.0",
68
- "netlify-redirect-parser": "^12.0.0",
68
+ "netlify": "^10.0.0",
69
+ "netlify-headers-parser": "^6.0.0",
70
+ "netlify-redirect-parser": "^13.0.0",
69
71
  "omit.js": "^2.0.2",
70
72
  "p-locate": "^5.0.0",
71
73
  "path-exists": "^4.0.0",
@@ -78,7 +80,6 @@
78
80
  "devDependencies": {
79
81
  "ava": "^3.15.0",
80
82
  "del": "^5.1.0",
81
- "get-bin-path": "^5.1.0",
82
83
  "has-ansi": "^4.0.0",
83
84
  "is-ci": "^3.0.0",
84
85
  "tmp-promise": "^3.0.2"
@@ -1,12 +1,10 @@
1
- 'use strict'
2
-
3
- const { removeFalsy } = require('../utils/remove_falsy')
1
+ import { removeFalsy } from '../utils/remove_falsy.js'
4
2
 
5
3
  // Netlify UI build settings are used as default configuration values in
6
4
  // production. In local builds, we retrieve them with `getSite` (`siteInfo`)
7
5
  // instead.
8
6
  // This also includes UI-installed plugins.
9
- const addBuildSettings = function ({
7
+ export const addBuildSettings = function ({
10
8
  defaultConfig,
11
9
  baseRelDir,
12
10
  siteInfo: { build_settings: buildSettings, plugins },
@@ -41,5 +39,3 @@ const normalizeUiPlugin = function ({ package: packageName, inputs, pinned_versi
41
39
  const getBaseRelDir = function ({ base_rel_dir: siteBaseRelDir }, baseRelDir = siteBaseRelDir) {
42
40
  return Boolean(baseRelDir)
43
41
  }
44
-
45
- module.exports = { addBuildSettings }
package/src/api/client.js CHANGED
@@ -1,19 +1,17 @@
1
- 'use strict'
1
+ import { removeUndefined } from '../utils/remove_falsy.js'
2
2
 
3
- const NetlifyAPI = require('netlify')
4
-
5
- const { removeUndefined } = require('../utils/remove_falsy')
3
+ // TODO: use static `import` after migrating `@netlify/config` to pure ES modules
4
+ const jsClient = import('netlify')
6
5
 
7
6
  // Retrieve Netlify API client, if an access token was passed
8
- const getApiClient = function ({ token, offline, testOpts = {}, host, scheme, pathPrefix }) {
7
+ export const getApiClient = async function ({ token, offline, testOpts = {}, host, scheme, pathPrefix }) {
9
8
  if (!token || offline) {
10
9
  return
11
10
  }
12
11
 
13
12
  // TODO: find less intrusive way to mock HTTP requests
14
13
  const parameters = removeUndefined({ scheme: testOpts.scheme || scheme, host: testOpts.host || host, pathPrefix })
14
+ const { NetlifyAPI } = await jsClient
15
15
  const api = new NetlifyAPI(token, parameters)
16
16
  return api
17
17
  }
18
-
19
- module.exports = { getApiClient }
@@ -1,6 +1,4 @@
1
- 'use strict'
2
-
3
- const { throwUserError } = require('../error')
1
+ import { throwUserError } from '../error.js'
4
2
 
5
3
  // Retrieve Netlify Site information, if available.
6
4
  // Used to retrieve local build environment variables and UI build settings.
@@ -9,7 +7,7 @@ const { throwUserError } = require('../error')
9
7
  // Requires knowing the `siteId` and having the access `token`.
10
8
  // Silently ignore API errors. For example the network connection might be down,
11
9
  // but local builds should still work regardless.
12
- const getSiteInfo = async function ({ api, siteId, mode, testOpts: { env: testEnv = true } = {} }) {
10
+ export const getSiteInfo = async function ({ api, siteId, mode, testOpts: { env: testEnv = true } = {} }) {
13
11
  if (api === undefined || mode === 'buildbot' || !testEnv) {
14
12
  const siteInfo = siteId === undefined ? {} : { id: siteId }
15
13
  return { siteInfo, accounts: [], addons: [] }
@@ -59,5 +57,3 @@ const getAddons = async function (api, siteId) {
59
57
  }
60
58
 
61
59
  const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`
62
-
63
- module.exports = { getSiteInfo }
package/src/base.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict'
2
-
3
- const { resolvePath } = require('./files')
1
+ import { resolvePath } from './files.js'
4
2
 
5
3
  // Retrieve the first `base` directory used to load the first config file.
6
- const getInitialBase = function ({
4
+ export const getInitialBase = function ({
7
5
  repositoryRoot,
8
6
  defaultConfig: { build: { base: defaultBase } = {} },
9
7
  inlineConfig: { build: { base: initialBase = defaultBase } = {} },
@@ -22,7 +20,7 @@ const getInitialBase = function ({
22
20
  // - To resolve file paths
23
21
  // If the second file has a `base` property, it is ignored, i.e. it is not
24
22
  // recursive.
25
- const getBase = function (base, repositoryRoot, config) {
23
+ export const getBase = function (base, repositoryRoot, config) {
26
24
  return base === undefined ? resolveBase(repositoryRoot, config.build.base) : base
27
25
  }
28
26
 
@@ -31,8 +29,6 @@ const resolveBase = function (repositoryRoot, base) {
31
29
  }
32
30
 
33
31
  // Also `config.build.base`.
34
- const addBase = function (config, base) {
32
+ export const addBase = function (config, base) {
35
33
  return { ...config, build: { ...config.build, base } }
36
34
  }
37
-
38
- module.exports = { getInitialBase, getBase, addBase }
package/src/bin/flags.js CHANGED
@@ -1,13 +1,12 @@
1
1
  /* eslint-disable max-lines */
2
- 'use strict'
3
2
 
4
- const filterObj = require('filter-obj')
5
- const yargs = require('yargs')
3
+ import filterObj from 'filter-obj'
4
+ import yargs from 'yargs'
6
5
 
7
- const { normalizeCliFeatureFlags } = require('../options/feature_flags')
6
+ import { normalizeCliFeatureFlags } from '../options/feature_flags.js'
8
7
 
9
8
  // Parse CLI flags
10
- const parseFlags = function () {
9
+ export const parseFlags = function () {
11
10
  const { featureFlags: cliFeatureFlags = '', ...flags } = yargs.options(FLAGS).usage(USAGE).parse()
12
11
  const featureFlags = normalizeCliFeatureFlags(cliFeatureFlags)
13
12
  const flagsA = { ...flags, featureFlags }
@@ -133,7 +132,7 @@ Default: true`,
133
132
  describe: `Environment in which this is loaded. Can be:
134
133
  - 'buildbot': within Netlify Buildbot
135
134
  - 'cli': within Netlify CLI
136
- - 'require': through require('@netlify/config')`,
135
+ - 'require': through import('@netlify/config')`,
137
136
  hidden: true,
138
137
  },
139
138
  debug: {
@@ -172,6 +171,4 @@ const isUserFlag = function (key, value) {
172
171
  }
173
172
 
174
173
  const INTERNAL_KEYS = new Set(['help', 'version', '_', '$0'])
175
-
176
- module.exports = { parseFlags }
177
174
  /* eslint-enable max-lines */
package/src/bin/main.js CHANGED
@@ -1,19 +1,18 @@
1
1
  #!/usr/bin/env node
2
- 'use strict'
3
2
 
4
- const { writeFile } = require('fs')
5
- const { dirname } = require('path')
6
- const process = require('process')
7
- const { promisify } = require('util')
3
+ import { writeFile } from 'fs'
4
+ import { dirname } from 'path'
5
+ import process from 'process'
6
+ import { promisify } from 'util'
8
7
 
9
- const { stableStringify } = require('fast-safe-stringify')
10
- const makeDir = require('make-dir')
11
- const omit = require('omit.js').default
8
+ import fastSafeStringify from 'fast-safe-stringify'
9
+ import makeDir from 'make-dir'
10
+ import omit from 'omit.js'
12
11
 
13
- const { isUserError } = require('../error')
14
- const resolveConfig = require('../main')
12
+ import { isUserError } from '../error.js'
13
+ import { resolveConfig } from '../main.js'
15
14
 
16
- const { parseFlags } = require('./flags')
15
+ import { parseFlags } from './flags.js'
17
16
 
18
17
  const pWriteFile = promisify(writeFile)
19
18
 
@@ -33,8 +32,8 @@ const DEFAULT_OUTPUT = '-'
33
32
  // The result is output as JSON on success (exit code 0)
34
33
  const handleCliSuccess = async function (result, stable, output) {
35
34
  const resultA = serializeApi(result)
36
- const resultB = omit(resultA, SECRET_PROPERTIES)
37
- const stringifyFunc = stable ? stableStringify : JSON.stringify
35
+ const resultB = omit.default(resultA, SECRET_PROPERTIES)
36
+ const stringifyFunc = stable ? fastSafeStringify.stableStringify : JSON.stringify
38
37
  const resultJson = stringifyFunc(resultB, null, 2)
39
38
  await outputResult(resultJson, output)
40
39
  process.exitCode = 0
package/src/build_dir.js CHANGED
@@ -1,15 +1,13 @@
1
- 'use strict'
1
+ import { isDirectory } from 'path-type'
2
2
 
3
- const { isDirectory } = require('path-type')
4
-
5
- const { throwUserError } = require('./error')
3
+ import { throwUserError } from './error.js'
6
4
 
7
5
  // Retrieve the build directory used to resolve most paths.
8
6
  // This is (in priority order):
9
7
  // - `build.base`
10
8
  // - `--repositoryRoot`
11
9
  // - the current directory (default value of `--repositoryRoot`)
12
- const getBuildDir = async function (repositoryRoot, base) {
10
+ export const getBuildDir = async function (repositoryRoot, base) {
13
11
  const buildDir = base === undefined ? repositoryRoot : base
14
12
  await checkBuildDir(buildDir, repositoryRoot)
15
13
  return buildDir
@@ -26,5 +24,3 @@ const checkBuildDir = async function (buildDir, repositoryRoot) {
26
24
 
27
25
  throwUserError(`Base directory does not exist: ${buildDir}`)
28
26
  }
29
-
30
- module.exports = { getBuildDir }
@@ -1,7 +1,5 @@
1
- 'use strict'
2
-
3
- const { readFile } = require('fs')
4
- const { promisify } = require('util')
1
+ import { readFile } from 'fs'
2
+ import { promisify } from 'util'
5
3
 
6
4
  const pReadFile = promisify(readFile)
7
5
 
@@ -11,7 +9,7 @@ const pReadFile = promisify(readFile)
11
9
  // - first calls @netlify/config since it needs configuration property
12
10
  // - later calls @netlify/build, which runs @netlify/config under the hood
13
11
  // This is also used by Netlify CLI.
14
- const getCachedConfig = async function ({ cachedConfig, cachedConfigPath, token, api }) {
12
+ export const getCachedConfig = async function ({ cachedConfig, cachedConfigPath, token, api }) {
15
13
  const parsedCachedConfig = await parseCachedConfig(cachedConfig, cachedConfigPath)
16
14
  // The CLI does not print some properties when they are not serializable or
17
15
  // are confidential. Those will be missing from `cachedConfig`. The caller
@@ -32,5 +30,3 @@ const parseCachedConfig = async function (cachedConfig, cachedConfigPath) {
32
30
  return JSON.parse(await pReadFile(cachedConfigPath, 'utf8'))
33
31
  }
34
32
  }
35
-
36
- module.exports = { getCachedConfig }
package/src/case.js CHANGED
@@ -1,7 +1,5 @@
1
- 'use strict'
2
-
3
1
  // Some properties can be optionally capitalized. We normalize them to lowercase
4
- const normalizeConfigCase = function ({ Build, build = Build, ...config }) {
2
+ export const normalizeConfigCase = function ({ Build, build = Build, ...config }) {
5
3
  const buildA = normalizeBuildCase(build)
6
4
  return { ...config, build: buildA }
7
5
  }
@@ -37,5 +35,3 @@ const normalizeBuildCase = function ({
37
35
  publish,
38
36
  }
39
37
  }
40
-
41
- module.exports = { normalizeConfigCase }
package/src/context.js CHANGED
@@ -1,15 +1,13 @@
1
- 'use strict'
1
+ import isPlainObj from 'is-plain-obj'
2
+ import mapObj from 'map-obj'
2
3
 
3
- const isPlainObj = require('is-plain-obj')
4
- const mapObj = require('map-obj')
5
-
6
- const { mergeConfigs } = require('./merge')
7
- const { normalizeBeforeConfigMerge } = require('./merge_normalize')
8
- const { validateContextsPluginsConfig } = require('./validate/context')
9
- const { validatePreContextConfig } = require('./validate/main')
4
+ import { mergeConfigs } from './merge.js'
5
+ import { normalizeBeforeConfigMerge } from './merge_normalize.js'
6
+ import { validateContextsPluginsConfig } from './validate/context.js'
7
+ import { validatePreContextConfig } from './validate/main.js'
10
8
 
11
9
  // Validate and normalize `config.context.*`
12
- const normalizeContextProps = function ({ config, config: { context: contextProps }, origin }) {
10
+ export const normalizeContextProps = function ({ config, config: { context: contextProps }, origin }) {
13
11
  if (contextProps === undefined) {
14
12
  return config
15
13
  }
@@ -27,7 +25,7 @@ const normalizeContextProps = function ({ config, config: { context: contextProp
27
25
  // Merge `config.context.{CONTEXT|BRANCH}.*` to `config.build.*` or `config.*`
28
26
  // CONTEXT is the `--context` CLI flag.
29
27
  // BRANCH is the `--branch` CLI flag.
30
- const mergeContext = function ({
28
+ export const mergeContext = function ({
31
29
  config: { context: contextProps, ...config },
32
30
  config: { plugins },
33
31
  context,
@@ -88,7 +86,7 @@ const isEdgeHandlersConfig = function (key, value) {
88
86
  // some properties are not handled context-sensitively by the API.
89
87
  // Takes into account that `context.{context}.build.*` is the same as
90
88
  // `context.{context}.*`
91
- const ensureConfigPriority = function ({ build = {}, ...config }, context, branch) {
89
+ export const ensureConfigPriority = function ({ build = {}, ...config }, context, branch) {
92
90
  return {
93
91
  ...config,
94
92
  build,
@@ -99,5 +97,3 @@ const ensureConfigPriority = function ({ build = {}, ...config }, context, branc
99
97
  },
100
98
  }
101
99
  }
102
-
103
- module.exports = { normalizeContextProps, mergeContext, ensureConfigPriority }
package/src/default.js CHANGED
@@ -1,11 +1,9 @@
1
- 'use strict'
2
-
3
- const { addBuildSettings } = require('./api/build_settings')
4
- const { logDefaultConfig } = require('./log/main')
1
+ import { addBuildSettings } from './api/build_settings.js'
2
+ import { logDefaultConfig } from './log/main.js'
5
3
 
6
4
  // Retrieve default configuration file. It has less priority and it also does
7
5
  // not get normalized, merged with contexts, etc.
8
- const parseDefaultConfig = function ({ defaultConfig, base, baseRelDir, siteInfo, logs, debug }) {
6
+ export const parseDefaultConfig = function ({ defaultConfig, base, baseRelDir, siteInfo, logs, debug }) {
9
7
  const defaultConfigB = addDefaultConfigBase(defaultConfig, base)
10
8
  const { defaultConfig: defaultConfigC, baseRelDir: baseRelDirA = DEFAULT_BASE_REL_DIR } = addBuildSettings({
11
9
  defaultConfig: defaultConfigB,
@@ -31,5 +29,3 @@ const addDefaultConfigBase = function (defaultConfig, base) {
31
29
  // it could be retrieved from the `siteInfo`, which is why the default value
32
30
  // is assigned later than other properties.
33
31
  const DEFAULT_BASE_REL_DIR = true
34
-
35
- module.exports = { parseDefaultConfig }
package/src/env/git.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict'
1
+ import execa from 'execa'
2
2
 
3
- const execa = require('execa')
4
-
5
- const { removeFalsy } = require('../utils/remove_falsy')
3
+ import { removeFalsy } from '../utils/remove_falsy.js'
6
4
 
7
5
  // Retrieve git-related information for use in environment variables.
8
6
  // git is optional and there might be not git repository.
9
7
  // We purposely keep this decoupled from the git utility.
10
- const getGitEnv = async function (buildDir, branch) {
8
+ export const getGitEnv = async function (buildDir, branch) {
11
9
  const [COMMIT_REF, CACHED_COMMIT_REF] = await Promise.all([
12
10
  git(['rev-parse', 'HEAD'], buildDir),
13
11
  git(['rev-parse', 'HEAD^'], buildDir),
@@ -23,5 +21,3 @@ const git = async function (args, cwd) {
23
21
  return stdout
24
22
  } catch (error) {}
25
23
  }
26
-
27
- module.exports = { getGitEnv }
package/src/env/main.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
1
+ import omit from 'omit.js'
2
2
 
3
- const omit = require('omit.js').default
3
+ import { removeFalsy } from '../utils/remove_falsy.js'
4
4
 
5
- const { removeFalsy } = require('../utils/remove_falsy')
6
-
7
- const { getGitEnv } = require('./git')
5
+ import { getGitEnv } from './git.js'
8
6
 
9
7
  // Retrieve this site's environment variable. Also take into account team-wide
10
8
  // environment variables and addons.
@@ -12,7 +10,7 @@ const { getGitEnv } = require('./git')
12
10
  // meant so that local builds can mimic production builds
13
11
  // TODO: add `netlify.toml` `build.environment`, after normalization
14
12
  // TODO: add `CONTEXT` and others
15
- const getEnv = async function ({
13
+ export const getEnv = async function ({
16
14
  mode,
17
15
  config,
18
16
  siteInfo,
@@ -138,7 +136,7 @@ const getConfigFileEnv = function ({
138
136
 
139
137
  // Some environment variables cannot be overridden by configuration
140
138
  const cleanUserEnv = function (userEnv) {
141
- return omit(userEnv, READONLY_ENV)
139
+ return omit.default(userEnv, READONLY_ENV)
142
140
  }
143
141
 
144
142
  const READONLY_ENV = [
@@ -170,5 +168,3 @@ const READONLY_ENV = [
170
168
  'PULL_REQUEST',
171
169
  'REVIEW_ID',
172
170
  ]
173
-
174
- module.exports = { getEnv }
package/src/error.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
2
-
3
1
  // We distinguish between errors thrown intentionally and uncaught exceptions
4
2
  // (such as bugs) with a `customErrorInfo.type` property.
5
- const throwUserError = function (messageOrError, error) {
3
+ export const throwUserError = function (messageOrError, error) {
6
4
  const errorA = getError(messageOrError, error)
7
5
  errorA[CUSTOM_ERROR_KEY] = { type: USER_ERROR_TYPE }
8
6
  throw errorA
@@ -22,7 +20,7 @@ const getError = function (messageOrError, error) {
22
20
  return error
23
21
  }
24
22
 
25
- const isUserError = function (error) {
23
+ export const isUserError = function (error) {
26
24
  return (
27
25
  canHaveErrorInfo(error) && error[CUSTOM_ERROR_KEY] !== undefined && error[CUSTOM_ERROR_KEY].type === USER_ERROR_TYPE
28
26
  )
@@ -36,5 +34,3 @@ const canHaveErrorInfo = function (error) {
36
34
 
37
35
  const CUSTOM_ERROR_KEY = 'customErrorInfo'
38
36
  const USER_ERROR_TYPE = 'resolveConfig'
39
-
40
- module.exports = { throwUserError, isUserError }
package/src/events.js CHANGED
@@ -1,7 +1,5 @@
1
- 'use strict'
2
-
3
1
  // List of build plugins events
4
- const EVENTS = [
2
+ export const EVENTS = [
5
3
  // Before build command
6
4
  'onPreBuild',
7
5
  // After build command, before Functions bundling
@@ -15,5 +13,3 @@ const EVENTS = [
15
13
  // After build error or success
16
14
  'onEnd',
17
15
  ]
18
-
19
- module.exports = { EVENTS }
package/src/files.js CHANGED
@@ -1,17 +1,15 @@
1
- 'use strict'
1
+ import { resolve, relative, parse } from 'path'
2
2
 
3
- const { resolve, relative, parse } = require('path')
3
+ import dotProp from 'dot-prop'
4
+ import pathExists from 'path-exists'
4
5
 
5
- const { get, set, delete: deleteProp } = require('dot-prop')
6
- const pathExists = require('path-exists')
7
-
8
- const { throwUserError } = require('./error')
9
- const { mergeConfigs } = require('./merge')
10
- const { isTruthy } = require('./utils/remove_falsy')
6
+ import { throwUserError } from './error.js'
7
+ import { mergeConfigs } from './merge.js'
8
+ import { isTruthy } from './utils/remove_falsy.js'
11
9
 
12
10
  // Make configuration paths relative to `buildDir` and converts them to
13
11
  // absolute paths
14
- const resolveConfigPaths = async function ({ config, repositoryRoot, buildDir, baseRelDir }) {
12
+ export const resolveConfigPaths = async function ({ config, repositoryRoot, buildDir, baseRelDir }) {
15
13
  const baseRel = baseRelDir ? buildDir : repositoryRoot
16
14
  const configA = resolvePaths(config, FILE_PATH_CONFIG_PROPS, baseRel, repositoryRoot)
17
15
  const configB = await addDefaultPaths(configA, repositoryRoot, baseRel)
@@ -27,17 +25,17 @@ const resolvePaths = function (config, propNames, baseRel, repositoryRoot) {
27
25
  }
28
26
 
29
27
  const resolvePathProp = function (config, propName, baseRel, repositoryRoot) {
30
- const path = get(config, propName)
28
+ const path = dotProp.get(config, propName)
31
29
 
32
30
  if (!isTruthy(path)) {
33
- deleteProp(config, propName)
31
+ dotProp.delete(config, propName)
34
32
  return config
35
33
  }
36
34
 
37
- return set(config, propName, resolvePath(repositoryRoot, baseRel, path, propName))
35
+ return dotProp.set(config, propName, resolvePath(repositoryRoot, baseRel, path, propName))
38
36
  }
39
37
 
40
- const resolvePath = function (repositoryRoot, baseRel, originalPath, propName) {
38
+ export const resolvePath = function (repositoryRoot, baseRel, originalPath, propName) {
41
39
  if (!isTruthy(originalPath)) {
42
40
  return
43
41
  }
@@ -107,5 +105,3 @@ const addDefaultPath = async function ({ repositoryRoot, baseRel, defaultPath, g
107
105
 
108
106
  return getConfig(absolutePath)
109
107
  }
110
-
111
- module.exports = { resolveConfigPaths, resolvePath }
@@ -1,16 +1,14 @@
1
- 'use strict'
1
+ import isPlainObj from 'is-plain-obj'
2
2
 
3
- const isPlainObj = require('is-plain-obj')
3
+ import { isDefined } from './utils/remove_falsy.js'
4
4
 
5
- const { isDefined } = require('./utils/remove_falsy')
6
-
7
- const bundlers = ['esbuild', 'nft', 'zisi']
8
- const WILDCARD_ALL = '*'
5
+ export const bundlers = ['esbuild', 'nft', 'zisi']
6
+ export const WILDCARD_ALL = '*'
9
7
 
10
8
  // Removing the legacy `functions` from the `build` block.
11
9
  // Looking for a default directory in the `functions` block, separating it
12
10
  // from the rest of the configuration if it exists.
13
- const normalizeFunctionsProps = function (
11
+ export const normalizeFunctionsProps = function (
14
12
  { functions: v1FunctionsDirectory, ...build },
15
13
  { [WILDCARD_ALL]: wildcardProps, ...functions },
16
14
  ) {
@@ -49,7 +47,7 @@ const isConfigLeaf = (functionConfig) =>
49
47
 
50
48
  const isConfigProperty = (propName) => FUNCTION_CONFIG_PROPERTIES.has(propName)
51
49
 
52
- const FUNCTION_CONFIG_PROPERTIES = new Set([
50
+ export const FUNCTION_CONFIG_PROPERTIES = new Set([
53
51
  'directory',
54
52
  'external_node_modules',
55
53
  'ignored_node_modules',
@@ -83,5 +81,3 @@ const getFunctionsDirectoryProps = ({ functionsDirectory, v1FunctionsDirectory }
83
81
 
84
82
  return {}
85
83
  }
86
-
87
- module.exports = { normalizeFunctionsProps, bundlers, WILDCARD_ALL, FUNCTION_CONFIG_PROPERTIES }
package/src/headers.js CHANGED
@@ -1,20 +1,20 @@
1
- 'use strict'
1
+ import { resolve } from 'path'
2
2
 
3
- const { resolve } = require('path')
3
+ import { warnHeadersParsing, warnHeadersCaseSensitivity } from './log/messages.js'
4
4
 
5
- const { parseAllHeaders } = require('netlify-headers-parser')
6
-
7
- const { warnHeadersParsing, warnHeadersCaseSensitivity } = require('./log/messages')
5
+ // TODO: use static `import` after migrating this repository to pure ES modules
6
+ const netlifyHeadersParser = import('netlify-headers-parser')
8
7
 
9
8
  // Retrieve path to `_headers` file (even if it does not exist yet)
10
- const getHeadersPath = function ({ build: { publish } }) {
9
+ export const getHeadersPath = function ({ build: { publish } }) {
11
10
  return resolve(publish, HEADERS_FILENAME)
12
11
  }
13
12
 
14
13
  const HEADERS_FILENAME = '_headers'
15
14
 
16
15
  // Add `config.headers`
17
- const addHeaders = async function ({ headers: configHeaders, ...config }, headersPath, logs) {
16
+ export const addHeaders = async function ({ headers: configHeaders, ...config }, headersPath, logs) {
17
+ const { parseAllHeaders } = await netlifyHeadersParser
18
18
  const { headers, errors } = await parseAllHeaders({
19
19
  headersFiles: [headersPath],
20
20
  configHeaders,
@@ -24,5 +24,3 @@ const addHeaders = async function ({ headers: configHeaders, ...config }, header
24
24
  warnHeadersCaseSensitivity(logs, headers)
25
25
  return { ...config, headers }
26
26
  }
27
-
28
- module.exports = { getHeadersPath, addHeaders }
@@ -1,13 +1,9 @@
1
- 'use strict'
2
-
3
- const { logInlineConfig } = require('./log/main')
4
- const { applyMutations } = require('./mutations/apply')
1
+ import { logInlineConfig } from './log/main.js'
2
+ import { applyMutations } from './mutations/apply.js'
5
3
 
6
4
  // Retrieve the `--inlineConfig` CLI flag
7
- const getInlineConfig = function ({ inlineConfig, configMutations, logs, debug }) {
5
+ export const getInlineConfig = function ({ inlineConfig, configMutations, logs, debug }) {
8
6
  const mutatedInlineConfig = applyMutations(inlineConfig, configMutations)
9
7
  logInlineConfig(mutatedInlineConfig, { logs, debug })
10
8
  return mutatedInlineConfig
11
9
  }
12
-
13
- module.exports = { getInlineConfig }
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import filterObj from 'filter-obj'
2
2
 
3
- const filterObj = require('filter-obj')
4
-
5
- const { simplifyConfig } = require('../simplify')
3
+ import { simplifyConfig } from '../simplify.js'
6
4
 
7
5
  // Make sure we are not printing secret values. Use an allow list.
8
- const cleanupConfig = function ({
6
+ export const cleanupConfig = function ({
9
7
  build: {
10
8
  base,
11
9
  command,
@@ -53,7 +51,7 @@ const cleanupConfig = function ({
53
51
  return netlifyConfig
54
52
  }
55
53
 
56
- const cleanupEnvironment = function (environment) {
54
+ export const cleanupEnvironment = function (environment) {
57
55
  return Object.keys(environment).filter((key) => !BUILDBOT_ENVIRONMENT.has(key))
58
56
  }
59
57
 
@@ -79,5 +77,3 @@ const cleanupPlugin = function ({ package: packageName, origin, inputs = {} }) {
79
77
  const isPublicInput = function (key, input) {
80
78
  return typeof input === 'boolean'
81
79
  }
82
-
83
- module.exports = { cleanupConfig, cleanupEnvironment }