diff --git a/.eslintrc.json b/.eslintrc.json index a32eb0a2e..15341b5db 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,8 @@ { "parserOptions": { - "ecmaVersion": 6 + "ecmaVersion": 6, + "sourceType": "module", + "allowImportExportEverywhere": true }, "plugins": ["jest"], "env": { @@ -12,10 +14,7 @@ "Buffer": true, "escape": true }, - "extends": [ - "eslint:recommended", - "plugin:jest/recommended" - ], + "extends": ["eslint:recommended", "plugin:jest/recommended"], "rules": { "no-console": 0, "no-unused-vars": 1, diff --git a/lib/utils/combineJSON.js b/lib/utils/combineJSON.js index d1d2e4c15..714fa9792 100644 --- a/lib/utils/combineJSON.js +++ b/lib/utils/combineJSON.js @@ -11,18 +11,18 @@ * and limitations under the License. */ -require('json5/lib/register'); +require("json5/lib/register"); require.extensions[".jsonc"] = require("./jsonc").register; -var { globSync }= require('glob'), - deepExtend = require('./deepExtend'), - path = require('path'), - fs = require('fs'); +var { globSync } = require("glob"), + deepExtend = require("./deepExtend"), + path = require("path"), + fs = require("fs"); function traverseObj(obj, fn) { for (let key in obj) { fn.apply(null, [obj, key, obj[key]]); - if (obj[key] && typeof obj[key] === 'object') { + if (obj[key] && typeof obj[key] === "object") { traverseObj(obj[key], fn); } } @@ -39,13 +39,14 @@ function traverseObj(obj, fn) { * @param {Object[]} [parsers=[]] - Custom file parsers * @returns {Object} */ -function combineJSON(arr, deep, collision, source, parsers=[]) { - var i, files = [], +function combineJSON(arr, deep, collision, source, parsers = []) { + var i, + files = [], to_ret = {}; for (i = 0; i < arr.length; i++) { // Reverse to avoid introducing a breaking change - var new_files = globSync(arr[i], {}).reverse(); + var new_files = globSync(arr[i], { posix: true }).reverse(); files = files.concat(new_files); } @@ -62,11 +63,11 @@ function combineJSON(arr, deep, collision, source, parsers=[]) { // Iterate over custom parsers, if the file path matches the parser's // pattern regex, use it's parse function to generate the object - parsers.forEach(({pattern, parse}) => { + parsers.forEach(({ pattern, parse }) => { if (resolvedPath.match(pattern)) { file_content = parse({ - contents: fs.readFileSync(resolvedPath, {encoding:'UTF-8'}), - filePath: resolvedPath + contents: fs.readFileSync(resolvedPath, { encoding: "UTF-8" }), + filePath: resolvedPath, }); } }); @@ -76,13 +77,13 @@ function combineJSON(arr, deep, collision, source, parsers=[]) { file_content = deepExtend([file_content, require(resolvedPath)]); } } catch (e) { - e.message = 'Failed to load or parse JSON or JS Object: ' + e.message; + e.message = "Failed to load or parse JSON or JS Object: " + e.message; throw e; } // Add some side data on each property to make filtering easier traverseObj(file_content, (obj) => { - if (obj.hasOwnProperty('value') && !obj.filePath) { + if (obj.hasOwnProperty("value") && !obj.filePath) { obj.filePath = filePath; obj.isSource = source || source === undefined ? true : false;