Skip to content

Commit

Permalink
fix: regression, glob to return posix style paths (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema authored Jan 17, 2024
1 parent 21aa26d commit 473ca82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
9 changes: 4 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"parserOptions": {
"ecmaVersion": 6
"ecmaVersion": 6,
"sourceType": "module",
"allowImportExportEverywhere": true
},
"plugins": ["jest"],
"env": {
Expand All @@ -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,
Expand Down
29 changes: 15 additions & 14 deletions lib/utils/combineJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}

Expand All @@ -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,
});
}
});
Expand All @@ -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;
Expand Down

0 comments on commit 473ca82

Please sign in to comment.