Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regression, glob to return posix style paths #1085

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading