From 64c43fb815e71124e4073c81b074fff32ea6a11b Mon Sep 17 00:00:00 2001 From: verytactical <186486509+verytactical@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:10:18 +0400 Subject: [PATCH] fix: do not normalize node fs path --- src/vfs/createNodeFileSystem.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/vfs/createNodeFileSystem.ts b/src/vfs/createNodeFileSystem.ts index c5d019081..40fdeb097 100644 --- a/src/vfs/createNodeFileSystem.ts +++ b/src/vfs/createNodeFileSystem.ts @@ -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); @@ -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}'`, ); }