Skip to content

Commit 1e6a84a

Browse files
committed
Fix FsVirtual on Windows due to path.resolve converting "/" into "C:\".
1 parent d66d6b8 commit 1e6a84a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

webworker/fs-virtual.js

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const dirent = (path, directory) => {
1818
};
1919
};
2020

21+
const normalize = (path) => path.replace(/^[A-Za-z]:/u, "").replaceAll("\\", "/");
22+
23+
/* eslint-disable no-param-reassign */
24+
2125
class FsVirtual {
2226
constructor(files) {
2327

@@ -26,13 +30,15 @@ class FsVirtual {
2630
this.promises = {};
2731

2832
this.promises.access = (path) => {
33+
path = normalize(path);
2934
if (this.files.has(path)) {
3035
return Promise.resolve();
3136
}
3237
return Promise.reject(new Error(`fs-virtual:promises.access(${path})`));
3338
};
3439

3540
this.promises.readFile = (path) => {
41+
path = normalize(path);
3642
const content = this.files.get(path);
3743
if (content) {
3844
return Promise.resolve(content);
@@ -41,31 +47,36 @@ class FsVirtual {
4147
};
4248

4349
this.promises.stat = (path) => {
50+
path = normalize(path);
4451
if (this.files.has(path)) {
4552
return Promise.resolve(dirent(path));
4653
}
4754
return Promise.reject(new Error(`fs-virtual:promises.stat(${path})`));
4855
};
4956

5057
this.promises.writeFile = (path, data) => {
58+
path = normalize(path);
5159
this.files.set(path, data);
5260
};
5361

5462
this.access = (path, mode, callback) => {
63+
path = normalize(path);
5564
if (this.files.has(path)) {
5665
return (callback || mode)();
5766
}
5867
return (callback || mode)(new Error(`fs-virtual:access(${path})`));
5968
};
6069

6170
this.lstat = (path, callback) => {
71+
path = normalize(path);
6272
if (this.files.has(path)) {
6373
return callback(null, dirent(path, false));
6474
}
6575
return callback(null, dirent(path, true));
6676
};
6777

6878
this.readdir = (path, options, callback) => {
79+
path = normalize(path);
6980
const names = [];
7081
for (const file of this.files.keys()) {
7182
if (file.startsWith(path)) {
@@ -79,6 +90,7 @@ class FsVirtual {
7990
};
8091

8192
this.readFile = (path, options, callback) => {
93+
path = normalize(path);
8294
const content = this.files.get(path);
8395
if (content) {
8496
return callback(null, content);

0 commit comments

Comments
 (0)