@netlify/config
Advanced tools
Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "@netlify/config", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Netlify config module", | ||
@@ -29,3 +29,2 @@ "main": "src/index.js", | ||
"js-yaml": "^3.13.1", | ||
"make-dir": "^3.0.2", | ||
"map-obj": "^4.1.0", | ||
@@ -32,0 +31,0 @@ "omit.js": "^1.0.2", |
const { resolve } = require('path') | ||
const { get, set, delete: deleteProp } = require('dot-prop') | ||
const pathExists = require('path-exists') | ||
const makeDir = require('make-dir') | ||
// Normalize and validate configuration properties that refer to directories | ||
const handleFiles = async function(config, baseDir) { | ||
const files = await Promise.all(FILES.map(location => handleFile(config, baseDir, location))) | ||
const handleFiles = function(config, baseDir) { | ||
const files = FILES.map(location => handleFile(config, baseDir, location)) | ||
return files.reduce(setProp, config) | ||
@@ -16,8 +14,5 @@ } | ||
const handleFile = async function(config, baseDir, location) { | ||
const handleFile = function(config, baseDir, location) { | ||
const path = get(config, location) | ||
const pathA = normalizePath(path, baseDir) | ||
await ensurePath(pathA) | ||
return { location, path: pathA } | ||
@@ -36,11 +31,2 @@ } | ||
// Create directory if it does not already exists | ||
const ensurePath = async function(path) { | ||
if (path === undefined || (await pathExists(path))) { | ||
return | ||
} | ||
await makeDir(path) | ||
} | ||
// Set new value back to the configuration object | ||
@@ -47,0 +33,0 @@ const setProp = function(config, { location, path }) { |
@@ -1,6 +0,1 @@ | ||
const { | ||
cwd: getCwd, | ||
env: { CONTEXT }, | ||
} = require('process') | ||
const { getConfigPath } = require('./path') | ||
@@ -14,4 +9,7 @@ const { getBaseDir } = require('./base_dir') | ||
const { parseConfig } = require('./parse/main') | ||
const { normalizeOpts } = require('./options') | ||
const resolveConfig = async function(configFile, { cwd = getCwd(), context = CONTEXT || 'production' } = {}) { | ||
const resolveConfig = async function(configFile, options) { | ||
const { cwd, context } = await normalizeOpts(options) | ||
const configPath = await getConfigPath(configFile, cwd) | ||
@@ -29,3 +27,3 @@ | ||
const configB = normalizeConfig(configA) | ||
const configC = await handleFiles(configB, baseDir) | ||
const configC = handleFiles(configB, baseDir) | ||
return { configPath, baseDir, config: configC, context } | ||
@@ -32,0 +30,0 @@ } catch (error) { |
@@ -0,1 +1,3 @@ | ||
const { normalize } = require('path') | ||
const isString = function(value) { | ||
@@ -54,2 +56,20 @@ return typeof value === 'string' | ||
module.exports = { isString, isBoolean, validProperties, deprecatedProperties } | ||
// Ensure paths specified by users in the configuration file are not targetting | ||
// files outside the repository root directory. | ||
const isInsideRoot = function(path) { | ||
return !normalize(path).startsWith('..') | ||
} | ||
const insideRootCheck = { | ||
check: isInsideRoot, | ||
message: 'must be inside the root directory.', | ||
} | ||
// Used in examples to show how to fix the above check | ||
const removeParentDots = function(path) { | ||
return normalize(path).replace(PARENT_DOTS_REGEXP, '') | ||
} | ||
const PARENT_DOTS_REGEXP = /\.\.[/\\]/g | ||
module.exports = { isString, isBoolean, validProperties, deprecatedProperties, insideRootCheck, removeParentDots } |
@@ -7,3 +7,10 @@ const isPlainObj = require('is-plain-obj') | ||
const { isString, isBoolean, validProperties, deprecatedProperties } = require('./helpers') | ||
const { | ||
isString, | ||
isBoolean, | ||
validProperties, | ||
deprecatedProperties, | ||
insideRootCheck, | ||
removeParentDots, | ||
} = require('./helpers') | ||
@@ -86,2 +93,13 @@ // List of validations performed on the configuration file. | ||
{ | ||
property: 'build.base', | ||
check: isString, | ||
message: 'must be a string.', | ||
example: (base, key, build) => ({ build: { ...build, base: 'packages/project' } }), | ||
}, | ||
{ | ||
property: 'build.base', | ||
...insideRootCheck, | ||
example: (base, key, build) => ({ build: { ...build, base: removeParentDots(base) } }), | ||
}, | ||
{ | ||
property: 'build.publish', | ||
@@ -93,2 +111,7 @@ check: isString, | ||
{ | ||
property: 'build.publish', | ||
...insideRootCheck, | ||
example: (publish, key, build) => ({ build: { ...build, publish: removeParentDots(publish) } }), | ||
}, | ||
{ | ||
property: 'build.functions', | ||
@@ -100,2 +123,7 @@ check: isString, | ||
{ | ||
property: 'build.functions', | ||
...insideRootCheck, | ||
example: (functions, key, build) => ({ build: { ...build, functions: removeParentDots(functions) } }), | ||
}, | ||
{ | ||
property: 'build.command', | ||
@@ -102,0 +130,0 @@ check: value => isString(value) || (Array.isArray(value) && value.every(isString)), |
30269
12
19
800
- Removedmake-dir@^3.0.2
- Removedmake-dir@3.1.0(transitive)
- Removedsemver@6.3.1(transitive)