Skip to content

Commit

Permalink
Merge branch 'main' into 572-add-index-resolution-for-configuration-f…
Browse files Browse the repository at this point in the history
…iles-v2
  • Loading branch information
basmasking committed Dec 30, 2024
1 parent 34c5e3b commit 7a682a0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/sourcing/src/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export default class FileManager
return this.#fileSystem.exists(location);
}

isDirectory(filename: string): boolean
{
const location = this.getAbsoluteLocation(filename);

return this.#fileSystem.isDirectory(location);
}

async read(filename: string): Promise<File>
{
const absoluteFilename = this.getAbsoluteLocation(filename);
Expand Down
21 changes: 21 additions & 0 deletions packages/sourcing/src/LocalFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ export default class LocalFileSystem implements FileSystem
return fs.exists(location);
}

// This method is synchronous because it's used in the
// LocationRewriter. This class uses a replacer function
// in a replaceAll method that only accepts synchronous functions.
isDirectory(location: string): boolean
{
try
{
const stats = fs.statSync(location);

return stats.isDirectory();
}
catch
{
// We might reference a locations that doesn't exist
// because it's a file without an extension and that
// is not a reason to throw an error.

return false;
}
}

filter(location: string, pattern: string): Promise<string[]>
{
return glob(`${location}/${pattern}`);
Expand Down
2 changes: 2 additions & 0 deletions packages/sourcing/src/interfaces/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface FileSystem

filter(location: string, pattern: string): Promise<string[]>;

isDirectory(location: string): boolean;

join(...paths: string[]): string;

read(location: string): Promise<Buffer>;
Expand Down

0 comments on commit 7a682a0

Please sign in to comment.