Support win32 paths
See original GitHub issuehttps://github.com/webpack/webpack-dev-middleware/pull/366#issuecomment-462072465
memfs
does not handle win32 paths starting with C:\
(unless you are actually on a windows machine). Probably not on your roadmap but it’s a blocker for a personal pipe dream of replacing memory-fs
with memfs
.
const {vol} = require('memfs')
// treated as relative
vol.mkdirpSync("C:\\test") // <-- creates a folder in my current working directory.
console.log(vol.toJSON())
// { '/Users/username/my-test/C:\\test': null }
const {vol} = require('memfs')
// treated as relative (and throws errors as expected)
// https://github.com/streamich/memfs/blob/master/docs/relative-paths.md
vol.mkdirSync("C:\\test"); // <-- throws Error: ENOENT: no such file or directory
vol.mkdirSync("C:\\"); // <-- throws Error: ENOENT: no such file or directory
By comparison, memory-fs
treats paths starting with a /
as probably posix and starting with [A-Z]:
as probably win32. In the examples above, the presence of C:
would be enough to convince memory-fs
that it was an absolute win32 path.
memory-fs
has no support for relative paths and throws if it encounters one. The relative path compromise that memfs
makes is probably preferred as it’s more similar to what fs
does. But in the case of a win32 path prefix, memory-fs
makes the more flexible choice.
FWIW, on my machine (a Mac), the following works exactly as memfs
does. I don’t know what it does on a Windows machine.
const fs = require('fs')
// treated as relative
fs.mkdirSync("C:\\test") // <-- creates a folder in my current working directory.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:15 (3 by maintainers)
Top GitHub Comments
To write tests for Windows, my first try would be:
process.platform = 'win32'
.memfs
should pick that up and treat all paths as Windows paths.I looked deeper. Seems like you handle win32 correctly but only when
process.platform === 'win32'
.Is there a way to temporarily enable win32 mode? Would it be possible to inspect paths to see if there are absolute win32 paths? Or, can you recommend a way to write tests for win32 mode?