Skip to content

Commit

Permalink
fix: do not normalize node fs path
Browse files Browse the repository at this point in the history
  • Loading branch information
verytactical committed Jan 15, 2025
1 parent 37e9a18 commit 64c43fb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/vfs/createNodeFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ export function createNodeFileSystem(
root: string,
readonly: boolean = true,
): VirtualFileSystem {
let normalizedRoot = path.normalize(root);
if (!normalizedRoot.endsWith(path.sep)) {
normalizedRoot += path.sep;
if (!root.endsWith(path.sep)) {
root += path.sep;
}
return {
root: normalizedRoot,
root: root,
exists(filePath: string): boolean {
if (!filePath.startsWith(normalizedRoot)) {
if (!filePath.startsWith(root)) {
throw new Error(
`Path '${filePath}' is outside of the root directory '${normalizedRoot}'`,
`Path '${filePath}' is outside of the root directory '${root}'`,
);
}
return fs.existsSync(filePath);
},
resolve(...filePath) {
return path.normalize(path.resolve(normalizedRoot, ...filePath));
return path.normalize(path.resolve(root, ...filePath));
},
readFile(filePath) {
if (!filePath.startsWith(normalizedRoot)) {
if (!filePath.startsWith(root)) {
throw new Error(
`Path '${filePath}' is outside of the root directory '${normalizedRoot}'`,
`Path '${filePath}' is outside of the root directory '${root}'`,
);
}
return fs.readFileSync(filePath);
Expand All @@ -36,9 +35,9 @@ export function createNodeFileSystem(
if (readonly) {
throw new Error("File system is readonly");
}
if (!filePath.startsWith(normalizedRoot)) {
if (!filePath.startsWith(root)) {
throw new Error(
`Path '${filePath}' is outside of the root directory '${normalizedRoot}'`,
`Path '${filePath}' is outside of the root directory '${root}'`,
);
}

Expand Down

0 comments on commit 64c43fb

Please sign in to comment.