UNPKG

1.33 kBJavaScriptView Raw
1'use strict'
2
3const { resolvePath } = require('./files')
4
5// Retrieve the first `base` directory used to load the first config file.
6const getInitialBase = function ({
7 repositoryRoot,
8 defaultConfig: { build: { base: defaultBase } = {} },
9 inlineConfig: { build: { base: initialBase = defaultBase } = {} },
10}) {
11 return resolveBase(repositoryRoot, initialBase)
12}
13
14// Two config files can be used:
15// - The first one, using the `config` property or doing a default lookup
16// of `netlify.toml`
17// - If the first one has a `base` property pointing to a directory with
18// another `netlify.toml`, that second config file is used instead.
19// This retrieves the final `base` directory used:
20// - To load the second config file
21// - As the `buildDir`
22// - To resolve file paths
23// If the second file has a `base` property, it is ignored, i.e. it is not
24// recursive.
25const getBase = function (base, repositoryRoot, config) {
26 return base === undefined ? resolveBase(repositoryRoot, config.build.base) : base
27}
28
29const resolveBase = function (repositoryRoot, base) {
30 return resolvePath(repositoryRoot, repositoryRoot, base, 'build.base')
31}
32
33// Also `config.build.base`.
34const addBase = function (config, base) {
35 return { ...config, build: { ...config.build, base } }
36}
37
38module.exports = { getInitialBase, getBase, addBase }