Skip to content
Closed
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
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
return expandedPath ? findWithExpandedPath(expandedPath) : null;
}

function expandPath(pathObj, defaultObj) {

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on ubuntu-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on macos-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on windows-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on windows-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on ubuntu-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on windows-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on macos-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on ubuntu-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30

Check warning on line 12 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on macos-latest

Function 'expandPath' has too many statements (33). Maximum allowed is 30
if (!isObject(defaultObj)) {
defaultObj = {};
}
Expand Down Expand Up @@ -59,7 +59,9 @@
basedir = path.resolve(parsed.root);
}

if (parsed.ext) {
var isExtensionEmpty = extArr.length <= 1 && !extArr[0];

if (parsed.ext && isExtensionEmpty) {
filePath = filePath.slice(0, -parsed.ext.length);
// This ensures that only the original extension is matched.
extArr = [parsed.ext];
Expand Down Expand Up @@ -151,7 +153,7 @@

function defaults(userObj, defaultObj) {
var filteredEntries = Object.entries(userObj).filter(
([_, value]) => value != null,

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on ubuntu-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on macos-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on windows-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on windows-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on ubuntu-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on windows-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on macos-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on ubuntu-latest

'_' is defined but never used

Check warning on line 156 in index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on macos-latest

'_' is defined but never used
);
var filteredObj = Object.fromEntries(filteredEntries);
return Object.assign({}, defaultObj, filteredObj);
Expand Down
Empty file added test/fixtures/fined/app.json.js
Empty file.
85 changes: 70 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,69 @@
assert.deepStrictEqual(result, expected);
});

it("accepts paths with extensions already", function () {
it("doesn't accept paths with extensions already if `extensions` property is not empty", function () {
var pathObj = {
path: "test/fixtures/fined/app.js",
cwd: cwd,
extensions: [".json", ".js"],
};

var result = fined(pathObj);

assert.deepStrictEqual(result, null);
});

it("accepts paths with extensions already if `extensions` property of 1st argument is empty", function () {
var pathObj = {
path: "test/fixtures/fined/app.js",
cwd: cwd,
extensions: "",
};

var defaultObj = {
extensions: [".json", ".js"],
};

var expected = {
path: path.resolve(cwd, "test/fixtures/fined/app.js"),
extension: ".js",
};

var result = fined(pathObj, defaultObj);

assert.deepStrictEqual(result, expected);
});

it("accepts paths with extensions already if `extensions` property of 1st argument is neither nullish, a string, an array nor an object", function (done) {

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on ubuntu-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on macos-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on windows-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 24 on windows-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on ubuntu-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on windows-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 22 on macos-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on ubuntu-latest

'done' is defined but never used

Check warning on line 179 in test/index.js

View workflow job for this annotation

GitHub Actions / Tests for Node 26 on macos-latest

'done' is defined but never used
var pathObj = {
path: "test/fixtures/fined/app.js",
cwd: cwd,
extensions: false,
};

var defaultObj = {
extensions: [".json", ".js"],
};

var expected = {
path: path.resolve(cwd, "test/fixtures/fined", "app.js"),
extension: ".js",
};

var result = fined(pathObj);
var result = fined(pathObj, defaultObj);

assert.deepStrictEqual(result, expected);
});

it("only matches the extension specified in path", function () {
it("treats path with dots only as a path without an extension if `extensions` property is not emtpy", function () {
var pathObj = {
path: "test/fixtures/fined/appfile.js",
path: "test/fixtures/fined/app.json",
cwd: cwd,
extensions: [".json", ".js"],
};

var expected = {
path: path.resolve(cwd, "test/fixtures/fined", "appfile.js"),
path: path.resolve(cwd, "test/fixtures/fined/app.json.js"),
extension: ".js",
};

Expand All @@ -177,19 +214,31 @@
assert.deepStrictEqual(result, expected);
});

it("accepts name with extensions already", function () {
it("don't accept name with extensions already if `extensions` property is not empty", function () {
var pathObj = {
path: "test/fixtures/fined",
extensions: [".json", ".js"],
};

var result = fined(pathObj);

assert.deepStrictEqual(result, null);
});

it("accepts name with extensions already if `extensions` property is empty", function () {
var pathObj = {
path: "test/fixtures/fined",
extensions: "",
};

var defaultObj = {
name: "app.js",
cwd: cwd,
extensions: [".json", ".js"],
};

var expected = {
path: path.resolve(cwd, "test/fixtures/fined", "app.js"),
path: path.resolve(cwd, "test/fixtures/fined/app.js"),
extension: ".js",
};

Expand All @@ -198,19 +247,20 @@
assert.deepStrictEqual(result, expected);
});

it("only matches the extension specified in name", function () {
it("accepts name with extensions already if `extensions` property is neither nullish, a string, an array nor an object", function () {
var pathObj = {
path: "test/fixtures/fined",
extensions: [".json", ".js"],
extensions: false,
};

var defaultObj = {
name: "appfile.js",
name: "app.js",
cwd: cwd,
extensions: [".json", ".js"],
};

var expected = {
path: path.resolve(cwd, "test/fixtures/fined", "appfile.js"),
path: path.resolve(cwd, "test/fixtures/fined/app.js"),
extension: ".js",
};

Expand All @@ -219,19 +269,24 @@
assert.deepStrictEqual(result, expected);
});

it("only ignores the extension at the end of the path", function () {
it("treats name with dots only as a name without an extension if `extensions` property is not empty", function () {
var pathObj = {
path: "test/fixtures/fined/.js/app.js",
path: "test/fixtures/fined/",
cwd: cwd,
};

var defaultObj = {
name: "app.json",
cwd: cwd,
extensions: [".json", ".js"],
};

var expected = {
path: path.resolve(cwd, "test/fixtures/fined/.js", "app.js"),
path: path.resolve(cwd, "test/fixtures/fined/app.json.js"),
extension: ".js",
};

var result = fined(pathObj);
var result = fined(pathObj, defaultObj);

assert.deepStrictEqual(result, expected);
});
Expand Down
Loading