Resolve file path resolution on Mac/Linux.
This commit is contained in:
@@ -8,13 +8,17 @@ const findFileCaseInsensitive = async (
|
||||
): Promise<string | null> => {
|
||||
const directory: string = path.dirname(extensionlessFilePath);
|
||||
try {
|
||||
const matchingFiles = fs
|
||||
.readdirSync(directory)
|
||||
.filter((file: string) =>
|
||||
const matchingFiles = fs.readdirSync(directory).filter((file: string) => {
|
||||
return (
|
||||
extensions.some((ext) =>
|
||||
file.toLowerCase().endsWith(ext.toLowerCase()),
|
||||
),
|
||||
) &&
|
||||
path
|
||||
.basename(file, path.extname(file))
|
||||
.toLowerCase()
|
||||
.startsWith(path.basename(extensionlessFilePath).toLowerCase())
|
||||
);
|
||||
});
|
||||
const files: string[] = [];
|
||||
matchingFiles.forEach((file) => {
|
||||
const fullPath = path.join(directory, file);
|
||||
@@ -33,4 +37,11 @@ const findFileCaseInsensitive = async (
|
||||
return null;
|
||||
};
|
||||
|
||||
const getFilePathWithoutExtension = (filePath: string): string => {
|
||||
return path.join(
|
||||
path.dirname(filePath),
|
||||
path.basename(filePath, path.extname(filePath)),
|
||||
);
|
||||
};
|
||||
|
||||
export { findFileCaseInsensitive };
|
||||
|
||||
Reference in New Issue
Block a user