Skip to content

Commit

Permalink
Fix MemoryFS path normalizing on Windows
Browse files Browse the repository at this point in the history
This uses the `path.sep` as the default `cwd`, which fixes
errors on Windows like `FSError: ENOENT: \ does not exist`.

Additionally, it normalizes filepaths to the fully resolved `cwd`,
which on Windows resembles `C:\foo\bar`.
  • Loading branch information
lettertwo committed Jun 30, 2023
1 parent bf638c2 commit fb39c4f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/fs/src/MemoryFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export class MemoryFS implements FileSystem {

constructor(workerFarm: WorkerFarm) {
this.farm = workerFarm;
this.dirs = new Map([['/', new Directory()]]);
this._cwd = path.resolve(path.sep);
this.dirs = new Map([[this._cwd, new Directory()]]);
this.files = new Map();
this.symlinks = new Map();
this.watchers = new Map();
this.events = [];
this.id = id++;
this._cwd = '/';
this._workerHandles = [];
this._eventQueue = [];
instances.set(this.id, this);
Expand Down Expand Up @@ -134,7 +134,10 @@ export class MemoryFS implements FileSystem {
}

_normalizePath(filePath: FilePath, realpath: boolean = true): FilePath {
filePath = path.normalize(path.join(this.cwd(), filePath));
filePath = path.normalize(filePath);
if (!filePath.startsWith(this.cwd())) {
filePath = path.join(this.cwd(), filePath);
}

// get realpath by following symlinks
if (realpath) {
Expand Down

0 comments on commit fb39c4f

Please sign in to comment.