Skip to content

Commit

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

Expand Down

0 comments on commit d218a3c

Please sign in to comment.