From 020916c781d420fa71c28957714677595ca8b642 Mon Sep 17 00:00:00 2001 From: Lukas Siemon Date: Tue, 25 Jun 2019 22:33:13 -0700 Subject: [PATCH 1/9] amend: wip --- .idea/jsLinters/eslint.xml | 7 --- package.json | 3 +- src/index.js | 110 +++++++++++++++++++++---------------- 3 files changed, 64 insertions(+), 56 deletions(-) delete mode 100644 .idea/jsLinters/eslint.xml diff --git a/.idea/jsLinters/eslint.xml b/.idea/jsLinters/eslint.xml deleted file mode 100644 index 34c798cb..00000000 --- a/.idea/jsLinters/eslint.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/package.json b/package.json index 4d08bd82..85f2bd3c 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,8 @@ "js-yaml": "3.13.1", "lodash.get": "4.4.2", "lodash.mergewith": "4.6.1", - "lodash.set": "4.3.2" + "lodash.set": "4.3.2", + "object-scan": "10.0.3" }, "peerDependencies": {}, "nyc": { diff --git a/src/index.js b/src/index.js index 48d8b6ab..7d84c6aa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,65 +1,79 @@ const fs = require('fs'); const path = require('path'); +const objectScan = require('object-scan'); const get = require('lodash.get'); -const set = require('lodash.set'); const mergeWith = require('lodash.mergewith'); const yaml = require('js-yaml'); const concatArrays = (objValue, srcValue) => ([objValue, srcValue] .every(Array.isArray) ? objValue.concat(srcValue) : undefined); -const loadRecursive = (dir, relDir, data, vars) => { - let result = data; - if (typeof result === 'string' || result instanceof String) { - // replace yaml variables with defaults - result = result.replace( - /\${opt:([a-zA-Z0-9]+?)(?:, ["']([a-zA-Z0-9\-.]+?)["'])?}/g, - (match, k, v) => get(vars, k, v || match) - ); - // load requires - const match = ( - /^\${(require|file|fileFn)\(([~^]?[a-zA-Z\d._\-@/]+?)\)(?::([a-zA-Z\d.]+?))?(?:, ([a-zA-Z\d=\-&/.:[\],]+?))?}$/g - ).exec(result); - if (match) { - const varsNew = Object.assign({}, vars, match[4] ? JSON - .parse(`{"${match[4].replace(/&/g, '","').replace(/=/g, '":"')}"}`) : {}); +module.exports.load = (filePath, vars = {}) => { + const result = yaml.safeLoad(fs.readFileSync(filePath, 'utf8')); + const rootDir = path.dirname(filePath); + const relDirStack = [rootDir]; + const varStack = [vars]; - let loaded; - let newRelDir = relDir; - if (['file', 'fileFn'].includes(match[1])) { - const filePath = match[2].startsWith('^') - ? path.join(relDir, match[2].substring(1)) - : path.join(dir, match[2]); - newRelDir = path.dirname(filePath); - loaded = (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) - ? yaml.safeLoad(fs.readFileSync(filePath, 'utf8')) - // eslint-disable-next-line global-require, import/no-dynamic-require - : require(filePath); - if (match[1] === 'fileFn') { - loaded = loaded(varsNew); + objectScan(['**'], { + joined: false, + breakFn: (key, value, { parents }) => { + if (key[key.length - 1] !== '<<<' && Array.isArray(value)) { + return true; + } + relDirStack.length = Math.max(1, key.length); + varStack.length = Math.max(1, key.length); + const relDir = relDirStack[relDirStack.length - 1]; + const vars = varStack[varStack.length - 1]; + + if (typeof value === 'string' || value instanceof String) { + let valueNew = value; + // replace yaml variables with defaults + valueNew = valueNew.replace( + /\${opt:([a-zA-Z0-9]+?)(?:, ["']([a-zA-Z0-9\-.]+?)["'])?}/g, + (match, k, v) => get(vars, k, v || match) + ); + // load requires + const match = ( + /^\${(require|file|fileFn)\(([~^]?[a-zA-Z\d._\-@/]+?)\)(?::([a-zA-Z\d.]+?))?(?:, ([a-zA-Z\d=\-&/.:[\],]+?))?}$/g + ).exec(valueNew); + if (match) { + const varsNew = Object.assign({}, vars, match[4] ? JSON + .parse(`{"${match[4].replace(/&/g, '","').replace(/=/g, '":"')}"}`) : {}); + varStack.push(varsNew); + + let loaded; + if (['file', 'fileFn'].includes(match[1])) { + const filePath = match[2].startsWith('^') + ? path.join(relDir, match[2].substring(1)) + : path.join(rootDir, match[2]); + relDirStack.push(path.dirname(filePath)); + loaded = (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) + ? yaml.safeLoad(fs.readFileSync(filePath, 'utf8')) + // eslint-disable-next-line global-require, import/no-dynamic-require + : require(filePath); + if (match[1] === 'fileFn') { + loaded = loaded(varsNew); + } + } else { + // eslint-disable-next-line global-require, import/no-dynamic-require + loaded = require(match[2]); + } + const target = match[3] ? get(loaded, match[3]) : loaded; + valueNew = typeof target === 'function' ? target() : target; } - } else { - // eslint-disable-next-line global-require, import/no-dynamic-require - loaded = require(match[2]); + parents[0][key[key.length - 1]] = valueNew } - const target = match[3] ? get(loaded, match[3]) : loaded; - result = loadRecursive(dir, newRelDir, typeof target === 'function' ? target() : target, varsNew); + return false; + }, + filterFn: (key, value, { parents }) => { + if (key[key.length - 1] === '<<<' && Array.isArray(value)) { + value.reduce((prev, cur) => mergeWith(prev, cur, concatArrays), parents[0]); + delete parents[0]['<<<']; + } + return true; } - } - if (result instanceof Object) { - const toMerge = get(result, '<<<', []).map(e => loadRecursive(dir, relDir, e, vars)); - delete result['<<<']; - Object.keys(result).forEach(key => set(result, key, loadRecursive(dir, relDir, get(result, key), vars))); - result = toMerge.reduce((prev, cur) => mergeWith(prev, cur, concatArrays), result); - } + })(result); return result; }; -module.exports.load = (filePath, vars = {}) => loadRecursive( - path.dirname(filePath), - path.dirname(filePath), - yaml.safeLoad(fs.readFileSync(filePath, 'utf8')), - vars -); - module.exports.dump = yaml.safeDump; From f4161398001985826cf20d67805d01fdb03a8a33 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 18 Sep 2020 03:04:15 +0000 Subject: [PATCH 2/9] chore(deps-dev): bump semantic-release from 17.1.1 to 17.1.2 Bumps [semantic-release](https://github.com/semantic-release/semantic-release) from 17.1.1 to 17.1.2. - [Release notes](https://github.com/semantic-release/semantic-release/releases) - [Commits](https://github.com/semantic-release/semantic-release/compare/v17.1.1...v17.1.2) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3422f4ec..30c5329d 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "eslint-plugin-mocha": "8.0.0", "js-gardener": "2.0.175", "nyc": "15.1.0", - "semantic-release": "17.1.1", + "semantic-release": "17.1.2", "babel-preset-latest-node": "4.1.0" }, "keywords": [ diff --git a/yarn.lock b/yarn.lock index 02f6b3f7..8f395887 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6580,10 +6580,10 @@ sax@^1.2.4: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== -semantic-release@17.1.1: - version "17.1.1" - resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-17.1.1.tgz#d9775968e841b2b7c5020559e4481aea8520ca75" - integrity sha512-9H+207eynBJElrQBHySZm+sIEoJeUhPA2zU4cdlY1QSInd2lnE8GRD2ALry9EassE22c9WW+aCREwBhro5AIIg== +semantic-release@17.1.2: + version "17.1.2" + resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-17.1.2.tgz#7d77555185722012b34e3ca74e4d13f813daf3cd" + integrity sha512-szYBXm10QjQO5Tb1S2PSkvOBW3MajWJat5EWtx+MzaVT/jquuxf9o+Zn8FC1j157xvJ5p9r1d/MZGslgs7oQQg== dependencies: "@semantic-release/commit-analyzer" "^8.0.0" "@semantic-release/error" "^2.2.0" From 42c48010aac254bac5a20fb0c2cf1d7067a4676c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sat, 19 Sep 2020 18:22:34 +0000 Subject: [PATCH 3/9] chore(deps-dev): bump babel-preset-latest-node from 4.1.0 to 5.0.0 Bumps [babel-preset-latest-node](https://github.com/christophehurpeau/babel-preset-latest-node) from 4.1.0 to 5.0.0. - [Release notes](https://github.com/christophehurpeau/babel-preset-latest-node/releases) - [Changelog](https://github.com/christophehurpeau/babel-preset-latest-node/blob/master/CHANGELOG.md) - [Commits](https://github.com/christophehurpeau/babel-preset-latest-node/compare/v4.1.0...v5.0.0) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 49 ++++++++++++++++++++++++------------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 30c5329d..5d9b9216 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "js-gardener": "2.0.175", "nyc": "15.1.0", "semantic-release": "17.1.2", - "babel-preset-latest-node": "4.1.0" + "babel-preset-latest-node": "5.0.0" }, "keywords": [ "yaml", diff --git a/yarn.lock b/yarn.lock index 8f395887..c8083a48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -194,7 +194,7 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.11.5.tgz#c7ff6303df71080ec7a4f5b8c003c58f1cf51037" integrity sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q== -"@babel/plugin-proposal-nullish-coalescing-operator@^7.8.3": +"@babel/plugin-proposal-nullish-coalescing-operator@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.10.4.tgz#02a7e961fc32e6d5b2db0649e01bf80ddee7e04a" integrity sha512-wq5n1M3ZUlHl9sqT2ok1T2/MTt6AXE0e1Lz4WzWBr95LsAZ5qDXe4KnFuauYyEyLiohvXFMdbsOTMyLZs91Zlw== @@ -202,7 +202,7 @@ "@babel/helper-plugin-utils" "^7.10.4" "@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.0" -"@babel/plugin-proposal-optional-catch-binding@^7.8.3": +"@babel/plugin-proposal-optional-catch-binding@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.10.4.tgz#31c938309d24a78a49d68fdabffaa863758554dd" integrity sha512-LflT6nPh+GK2MnFiKDyLiqSqVHkQnVf7hdoAvyTnnKj9xB3docGRsdPuxp6qqqW19ifK3xgc9U5/FwrSaCNX5g== @@ -210,7 +210,7 @@ "@babel/helper-plugin-utils" "^7.10.4" "@babel/plugin-syntax-optional-catch-binding" "^7.8.0" -"@babel/plugin-proposal-optional-chaining@^7.9.0": +"@babel/plugin-proposal-optional-chaining@^7.10.4": version "7.11.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.11.0.tgz#de5866d0646f6afdaab8a566382fe3a221755076" integrity sha512-v9fZIu3Y8562RRwhm1BbMRxtqZNFmFA2EG+pT2diuU8PT3H6T/KXoZ54KgYisfOFZHV6PfvAiBIZ9Rcz+/JCxA== @@ -219,7 +219,7 @@ "@babel/helper-skip-transparent-expression-wrappers" "^7.11.0" "@babel/plugin-syntax-optional-chaining" "^7.8.0" -"@babel/plugin-proposal-unicode-property-regex@^7.8.8": +"@babel/plugin-proposal-unicode-property-regex@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.10.4.tgz#4483cda53041ce3413b7fe2f00022665ddfaa75d" integrity sha512-H+3fOgPnEXFL9zGYtKQe4IDOPKYlZdF1kqFDQRRb8PK4B8af1vAGK04tF5iQAAsui+mHNBQSAtd2/ndEDe9wuA== @@ -227,13 +227,6 @@ "@babel/helper-create-regexp-features-plugin" "^7.10.4" "@babel/helper-plugin-utils" "^7.10.4" -"@babel/plugin-syntax-json-strings@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz#01ca21b668cd8218c9e640cb6dd88c5412b2c96a" - integrity sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA== - dependencies: - "@babel/helper-plugin-utils" "^7.8.0" - "@babel/plugin-syntax-nullish-coalescing-operator@^7.8.0": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz#167ed70368886081f74b5c36c65a88c03b66d1a9" @@ -241,7 +234,14 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-optional-catch-binding@^7.8.0", "@babel/plugin-syntax-optional-catch-binding@^7.8.3": +"@babel/plugin-syntax-numeric-separator@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.10.4.tgz#b9b070b3e33570cd9fd07ba7fa91c0dd37b9af97" + integrity sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug== + dependencies: + "@babel/helper-plugin-utils" "^7.10.4" + +"@babel/plugin-syntax-optional-catch-binding@^7.8.0": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.8.3.tgz#6111a265bcfb020eb9efd0fdfd7d26402b9ed6c1" integrity sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q== @@ -255,7 +255,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-transform-modules-commonjs@^7.9.0": +"@babel/plugin-transform-modules-commonjs@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.10.4.tgz#66667c3eeda1ebf7896d41f1f16b17105a2fbca0" integrity sha512-Xj7Uq5o80HDLlW64rVfDBhao6OX89HKUmb+9vWYaLXBZOma4gA6tw4Ni1O5qVDoZWUV0fxMYA0aYzOawz0l+1w== @@ -1020,18 +1020,17 @@ babel-plugin-dynamic-import-node@^2.3.3: dependencies: object.assign "^4.1.0" -babel-preset-latest-node@4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/babel-preset-latest-node/-/babel-preset-latest-node-4.1.0.tgz#b5696cf19b0106b515890a427274f67ac009e8c8" - integrity sha512-LOdNzg2qtx+rHE0++hPjhIEJy8X3jkuhfV0oe8peVeXUjTY4jUEo18263WKNSqyn/Vg6ym9LK0rCywc51e/okQ== - dependencies: - "@babel/plugin-proposal-nullish-coalescing-operator" "^7.8.3" - "@babel/plugin-proposal-optional-catch-binding" "^7.8.3" - "@babel/plugin-proposal-optional-chaining" "^7.9.0" - "@babel/plugin-proposal-unicode-property-regex" "^7.8.8" - "@babel/plugin-syntax-json-strings" "^7.8.3" - "@babel/plugin-syntax-optional-catch-binding" "^7.8.3" - "@babel/plugin-transform-modules-commonjs" "^7.9.0" +babel-preset-latest-node@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/babel-preset-latest-node/-/babel-preset-latest-node-5.0.0.tgz#1c776799455889585ce7a731184b4964fc54e1df" + integrity sha512-FxabAzGKRkD6oFB10RrYoyS2Nuk/NNU+aJPVTOkX164EZvOF8r/5P3RaM0ed/1Iv7uugoPpSVW024ANEaHisCg== + dependencies: + "@babel/plugin-proposal-nullish-coalescing-operator" "^7.10.4" + "@babel/plugin-proposal-optional-catch-binding" "^7.10.4" + "@babel/plugin-proposal-optional-chaining" "^7.10.4" + "@babel/plugin-proposal-unicode-property-regex" "^7.10.4" + "@babel/plugin-syntax-numeric-separator" "^7.10.4" + "@babel/plugin-transform-modules-commonjs" "^7.10.4" babel-runtime@^6.6.1: version "6.26.0" From aef261522e19518bb2f7b29fa0752222908d69ff Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 25 Sep 2020 20:00:57 +0000 Subject: [PATCH 4/9] chore(deps-dev): bump @blackflux/robo-config-plugin Bumps [@blackflux/robo-config-plugin](https://github.com/blackflux/robo-config-plugin) from 3.10.3 to 3.10.4. - [Release notes](https://github.com/blackflux/robo-config-plugin/releases) - [Changelog](https://github.com/blackflux/robo-config-plugin/blob/master/.releaserc.json) - [Commits](https://github.com/blackflux/robo-config-plugin/compare/v3.10.3...v3.10.4) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5d9b9216..637dccd7 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@babel/core": "7.11.6", "@babel/register": "7.11.5", "@blackflux/eslint-plugin-rules": "1.3.40", - "@blackflux/robo-config-plugin": "3.10.3", + "@blackflux/robo-config-plugin": "3.10.4", "babel-eslint": "10.1.0", "chai": "4.2.0", "coveralls": "3.1.0", diff --git a/yarn.lock b/yarn.lock index c8083a48..17beeca0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -316,10 +316,10 @@ dependencies: smart-fs "1.11.21" -"@blackflux/robo-config-plugin@3.10.3": - version "3.10.3" - resolved "https://registry.yarnpkg.com/@blackflux/robo-config-plugin/-/robo-config-plugin-3.10.3.tgz#512e4d3ba21a01fb1bca67a0b6f027d810b65a88" - integrity sha512-KSSXK/1ypJN2CVkR8c0sVX8iBhKE5U374KyVivNxFAnocgf8eiYzbJLqVeZmGGVrRAExCp65uQTY/GNkkaVDNQ== +"@blackflux/robo-config-plugin@3.10.4": + version "3.10.4" + resolved "https://registry.yarnpkg.com/@blackflux/robo-config-plugin/-/robo-config-plugin-3.10.4.tgz#c6aac6404d9a941f8f4d8fd6338e5b57967f1606" + integrity sha512-JJ15rbH3kIihJTv9S8zjr+c6rB6f2lxLwZAmOn+v5ffeuasIsRuowCUpcugNbIrY/7e4FBu+Wd5kg05nWQh+cg== "@eslint/eslintrc@^0.1.3": version "0.1.3" From 9de77423d32be23338a44a37cc1802ff2ad9eb40 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sat, 26 Sep 2020 22:03:21 +0000 Subject: [PATCH 5/9] chore(deps-dev): bump eslint from 7.9.0 to 7.10.0 Bumps [eslint](https://github.com/eslint/eslint) from 7.9.0 to 7.10.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v7.9.0...v7.10.0) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 637dccd7..3fe28534 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "babel-eslint": "10.1.0", "chai": "4.2.0", "coveralls": "3.1.0", - "eslint": "7.9.0", + "eslint": "7.10.0", "eslint-config-airbnb-base": "14.2.0", "eslint-plugin-import": "2.22.0", "eslint-plugin-json": "2.1.2", diff --git a/yarn.lock b/yarn.lock index 17beeca0..a653540f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2334,12 +2334,12 @@ eslint-plugin-mocha@8.0.0: eslint-utils "^2.1.0" ramda "^0.27.1" -eslint-scope@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5" - integrity sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w== +eslint-scope@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" + integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== dependencies: - esrecurse "^4.1.0" + esrecurse "^4.3.0" estraverse "^4.1.1" eslint-utils@^2.1.0: @@ -2354,10 +2354,10 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3 resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== -eslint@7.9.0: - version "7.9.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.9.0.tgz#522aeccc5c3a19017cf0cb46ebfd660a79acf337" - integrity sha512-V6QyhX21+uXp4T+3nrNfI3hQNBDa/P8ga7LoQOenwrlEFXrEnUEE+ok1dMtaS3b6rmLXhT1TkTIsG75HMLbknA== +eslint@7.10.0: + version "7.10.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.10.0.tgz#494edb3e4750fb791133ca379e786a8f648c72b9" + integrity sha512-BDVffmqWl7JJXqCjAK6lWtcQThZB/aP1HXSH1JKwGwv0LQEdvpR7qzNrUT487RM39B5goWuboFad5ovMBmD8yA== dependencies: "@babel/code-frame" "^7.0.0" "@eslint/eslintrc" "^0.1.3" @@ -2367,7 +2367,7 @@ eslint@7.9.0: debug "^4.0.1" doctrine "^3.0.0" enquirer "^2.3.5" - eslint-scope "^5.1.0" + eslint-scope "^5.1.1" eslint-utils "^2.1.0" eslint-visitor-keys "^1.3.0" espree "^7.3.0" @@ -2418,7 +2418,7 @@ esquery@^1.2.0: dependencies: estraverse "^5.1.0" -esrecurse@^4.1.0: +esrecurse@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.3.0.tgz#7ad7964d679abb28bee72cec63758b1c5d2c9921" integrity sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag== From 85f1523545ef525b3eab5b44549cf4c1c280655e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sun, 27 Sep 2020 23:12:18 +0000 Subject: [PATCH 6/9] chore(deps-dev): bump eslint-plugin-import from 2.22.0 to 2.22.1 Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.22.0 to 2.22.1. - [Release notes](https://github.com/benmosher/eslint-plugin-import/releases) - [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md) - [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.22.0...v2.22.1) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 3fe28534..af2218af 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "coveralls": "3.1.0", "eslint": "7.10.0", "eslint-config-airbnb-base": "14.2.0", - "eslint-plugin-import": "2.22.0", + "eslint-plugin-import": "2.22.1", "eslint-plugin-json": "2.1.2", "eslint-plugin-markdown": "1.0.2", "eslint-plugin-mocha": "8.0.0", diff --git a/yarn.lock b/yarn.lock index a653540f..4a46ad02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2274,7 +2274,7 @@ eslint-config-airbnb-base@14.2.0: object.assign "^4.1.0" object.entries "^1.1.2" -eslint-import-resolver-node@^0.3.3: +eslint-import-resolver-node@^0.3.4: version "0.3.4" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz#85ffa81942c25012d8231096ddf679c03042c717" integrity sha512-ogtf+5AB/O+nM6DIeBUNr2fuT7ot9Qg/1harBfBtaP13ekEWFQEEMP94BCB7zaNW3gyY+8SHYF00rnqYwXKWOA== @@ -2290,17 +2290,17 @@ eslint-module-utils@^2.6.0: debug "^2.6.9" pkg-dir "^2.0.0" -eslint-plugin-import@2.22.0: - version "2.22.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.22.0.tgz#92f7736fe1fde3e2de77623c838dd992ff5ffb7e" - integrity sha512-66Fpf1Ln6aIS5Gr/55ts19eUuoDhAbZgnr6UxK5hbDx6l/QgQgx61AePq+BV4PP2uXQFClgMVzep5zZ94qqsxg== +eslint-plugin-import@2.22.1: + version "2.22.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.22.1.tgz#0896c7e6a0cf44109a2d97b95903c2bb689d7702" + integrity sha512-8K7JjINHOpH64ozkAhpT3sd+FswIZTfMZTjdx052pnWrgRCVfp8op9tbjpAk3DdUeI/Ba4C8OjdC0r90erHEOw== dependencies: array-includes "^3.1.1" array.prototype.flat "^1.2.3" contains-path "^0.1.0" debug "^2.6.9" doctrine "1.5.0" - eslint-import-resolver-node "^0.3.3" + eslint-import-resolver-node "^0.3.4" eslint-module-utils "^2.6.0" has "^1.0.3" minimatch "^3.0.4" From f581fb93e73db720b832bf62fc34859437ae376d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2020 08:13:51 +0000 Subject: [PATCH 7/9] chore(deps-dev): bump @blackflux/robo-config-plugin Bumps [@blackflux/robo-config-plugin](https://github.com/blackflux/robo-config-plugin) from 3.10.4 to 3.10.7. - [Release notes](https://github.com/blackflux/robo-config-plugin/releases) - [Changelog](https://github.com/blackflux/robo-config-plugin/blob/master/.releaserc.json) - [Commits](https://github.com/blackflux/robo-config-plugin/compare/v3.10.4...v3.10.7) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index af2218af..be0d889b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@babel/core": "7.11.6", "@babel/register": "7.11.5", "@blackflux/eslint-plugin-rules": "1.3.40", - "@blackflux/robo-config-plugin": "3.10.4", + "@blackflux/robo-config-plugin": "3.10.7", "babel-eslint": "10.1.0", "chai": "4.2.0", "coveralls": "3.1.0", diff --git a/yarn.lock b/yarn.lock index 4a46ad02..de3bdaf1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -316,10 +316,10 @@ dependencies: smart-fs "1.11.21" -"@blackflux/robo-config-plugin@3.10.4": - version "3.10.4" - resolved "https://registry.yarnpkg.com/@blackflux/robo-config-plugin/-/robo-config-plugin-3.10.4.tgz#c6aac6404d9a941f8f4d8fd6338e5b57967f1606" - integrity sha512-JJ15rbH3kIihJTv9S8zjr+c6rB6f2lxLwZAmOn+v5ffeuasIsRuowCUpcugNbIrY/7e4FBu+Wd5kg05nWQh+cg== +"@blackflux/robo-config-plugin@3.10.7": + version "3.10.7" + resolved "https://registry.yarnpkg.com/@blackflux/robo-config-plugin/-/robo-config-plugin-3.10.7.tgz#a54da9838ee3d98c1b8ac210de9760a423327e0a" + integrity sha512-8yfJ6I/eTon65SDmUSDX6EuoQQvwjEbTafuas839sOYfkHIkg5PBfqxVzWghSW5n1WzOnnwtvOhqT8YI8SA6cw== "@eslint/eslintrc@^0.1.3": version "0.1.3" From 171cd4bd006021debbbf6b3d2d5c8dcb1dde7a85 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2020 21:50:50 +0000 Subject: [PATCH 8/9] chore(deps-dev): bump js-gardener from 2.0.175 to 2.0.176 Bumps [js-gardener](https://github.com/blackflux/js-gardener) from 2.0.175 to 2.0.176. - [Release notes](https://github.com/blackflux/js-gardener/releases) - [Changelog](https://github.com/blackflux/js-gardener/blob/master/.releaserc.json) - [Commits](https://github.com/blackflux/js-gardener/compare/v2.0.175...v2.0.176) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index be0d889b..c487ad1e 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "eslint-plugin-json": "2.1.2", "eslint-plugin-markdown": "1.0.2", "eslint-plugin-mocha": "8.0.0", - "js-gardener": "2.0.175", + "js-gardener": "2.0.176", "nyc": "15.1.0", "semantic-release": "17.1.2", "babel-preset-latest-node": "5.0.0" diff --git a/yarn.lock b/yarn.lock index de3bdaf1..07090af9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3943,10 +3943,10 @@ joi-strict@1.2.5: dependencies: "@hapi/joi" "17.1.1" -js-gardener@2.0.175: - version "2.0.175" - resolved "https://registry.yarnpkg.com/js-gardener/-/js-gardener-2.0.175.tgz#fc90ffaa13e4cfd04ee471a98f61e7b191bb1458" - integrity sha512-W3bRxleK7pEN2sPm/N4SEj7M33QwFjXOC8G5CGDB8HqEyxwYSw/gUm2qUzoxRUZGdYYObv2wScvPzfyqgz1N7g== +js-gardener@2.0.176: + version "2.0.176" + resolved "https://registry.yarnpkg.com/js-gardener/-/js-gardener-2.0.176.tgz#a172e51110fa81dabbafed83acd4c7edc8103783" + integrity sha512-61yKYbTwkXIXxKPktPaWgos4wIthp/T7wnFHY99lnrTny5C+/H0X1WzR6Di6UkQHZFtHe+5sjBWjKJZ9fuc6sQ== dependencies: chalk "4.1.0" fancy-log "1.3.3" @@ -3957,7 +3957,7 @@ js-gardener@2.0.175: lodash.get "4.4.2" mocha "8.1.3" npm-check "5.9.2" - robo-config "3.8.14" + robo-config "3.9.0" js-tokens@^3.0.0: version "3.0.2" @@ -6512,10 +6512,10 @@ rimraf@^3.0.0: dependencies: glob "^7.1.3" -robo-config@3.8.14: - version "3.8.14" - resolved "https://registry.yarnpkg.com/robo-config/-/robo-config-3.8.14.tgz#ff5d5f20da3860c410ef7ceeb2e307d1bea51902" - integrity sha512-6HGQiZzGUXL/pogaBGmxvxNCYoP0EMc4X0uDUnSDWs64zYDDFEj+F+iI1pKBqmQ71r2SRDwTuxCAUxZafU6pEA== +robo-config@3.9.0: + version "3.9.0" + resolved "https://registry.yarnpkg.com/robo-config/-/robo-config-3.9.0.tgz#647bca313a925dcac7544bf9029c7f3e2596b6a5" + integrity sha512-66jcHYAODIJM+fMBLPobRfuw9ZdTGBvj16g5Bt4EHOQc/bCOqY6Z9RAbGyXrEvdgebxNYJDF6pfPBL2qpwoytg== dependencies: app-root-path "3.0.0" deepmerge "4.2.2" From 72fbba15cf6d9d9c74d5434a0cd9fe3ac2938bfe Mon Sep 17 00:00:00 2001 From: Lukas Siemon Date: Thu, 8 Oct 2020 12:12:54 -0700 Subject: [PATCH 9/9] feat: added "resolve" method --- .idea/codeStyles/codeStyleConfig.xml | 5 +++++ README.md | 16 +++++++++++++++- src/index.js | 11 ++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/README.md b/README.md index 61677daf..c46a3155 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,20 @@ Useful for loading improved [serverless](https://serverless.com/) configuration. $ npm install --save yaml-boost +## Api + +### resolve(refPath, content, vars) + +Resolve content with variables at given refPath. + +### load(filePath, vars = {}) + +Load filePath with given variables. + +### dump + +As provided by `js-yaml` through `safeDump` + ## Usage @@ -84,7 +98,7 @@ Once can reference files relative to the current file by using `^` as a prefix l ```yaml ${file(^/subfolder/of/current/file.yml)} -``` +``` ##### Deep Merge diff --git a/src/index.js b/src/index.js index 7964ae65..f455b882 100644 --- a/src/index.js +++ b/src/index.js @@ -58,9 +58,14 @@ const loadRecursive = (dir, relDir, data, vars) => { return result; }; -module.exports.load = (filePath, vars = {}) => loadRecursive( - path.dirname(filePath), - path.dirname(filePath), +const resolve = (refPath, content, vars) => { + const dirname = path.dirname(refPath); + return loadRecursive(dirname, dirname, content, vars); +}; +module.exports.resolve = resolve; + +module.exports.load = (filePath, vars = {}) => resolve( + filePath, yaml.safeLoad(fs.readFileSync(filePath, 'utf8')), vars );