Skip to content

Commit aa25167

Browse files
committed
simplify selection of path-handling implementations
1 parent e408f2b commit aa25167

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

packages/config-array/src/config-array.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,12 @@ function assertExtraConfigTypes(extraConfigTypes) {
487487
}
488488

489489
/**
490-
* Determines if an absolute path is a POSIX path.
490+
* Returns path-handling implementations for Unix or Windows, depending on a given absolute path.
491491
* @param {string} path The absolute path to check.
492-
* @returns {boolean} Whether the specified path is a POSIX path.
492+
* @returns {typeof import("@jsr/std__path")} Path-handling implementations for the specified path.
493493
*/
494-
function isPosixPath(path) {
495-
return path.startsWith("/");
494+
function getPathImpl(path) {
495+
return path.startsWith("/") ? posixPath : windowsPath;
496496
}
497497

498498
//------------------------------------------------------------------------------
@@ -600,11 +600,7 @@ export class ConfigArray extends Array {
600600
// The namespaced base path is useful to make sure that calculated relative paths are always relative.
601601
// On Unix, it is identical to the base path.
602602
this.namespacedBasePath =
603-
basePath &&
604-
(isPosixPath(this.basePath)
605-
? posixPath
606-
: windowsPath
607-
).toNamespacedPath(basePath);
603+
basePath && getPathImpl(this.basePath).toNamespacedPath(basePath);
608604
}
609605

610606
/**
@@ -808,16 +804,14 @@ export class ConfigArray extends Array {
808804
return cache.get(filePath);
809805
}
810806

811-
// Select `path` implementations depending on base path.
812-
// If base path is not specified, relative paths cannot be built.
813-
// In this case, `path` implementations are selected depending on the specified argument.
814-
const path = isPosixPath(this.basePath || filePath)
815-
? posixPath
816-
: windowsPath;
807+
// Select path-handling implementations depending on the specified file path.
808+
const path = getPathImpl(filePath);
817809

818810
// check to see if the file is outside the base path
819811

820812
const namespacedFilePath = path.toNamespacedPath(filePath);
813+
814+
// If base path is not specified, relative paths cannot be built.
821815
const relativeFilePath = (
822816
this.namespacedBasePath
823817
? path.relative(this.namespacedBasePath, namespacedFilePath)
@@ -1038,14 +1032,12 @@ export class ConfigArray extends Array {
10381032
isDirectoryIgnored(directoryPath) {
10391033
assertNormalized(this);
10401034

1041-
// Select `path` implementations depending on base path.
1042-
// If base path is not specified, relative paths cannot be built.
1043-
// In this case, `path` implementations are selected depending on the specified argument.
1044-
const path = isPosixPath(this.basePath || directoryPath)
1045-
? posixPath
1046-
: windowsPath;
1035+
// Select path-handling implementations depending on the specified directory path.
1036+
const path = getPathImpl(directoryPath);
10471037

10481038
const namespacedDirectoryPath = path.toNamespacedPath(directoryPath);
1039+
1040+
// If base path is not specified, relative paths cannot be built.
10491041
const relativeDirectoryPath = (
10501042
this.namespacedBasePath
10511043
? path.relative(

0 commit comments

Comments
 (0)