question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support win32 paths

See original GitHub issue

https://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:open
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
streamichcommented, Feb 11, 2019

To write tests for Windows, my first try would be:

  1. Create a separate test suite for Windows.
  2. At the very beginning, before importing anything, set process.platform = 'win32'.
  3. memfs should pick that up and treat all paths as Windows paths.
1reaction
heygradycommented, Feb 11, 2019

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?

// it seems like this would _always_ truthy.
// on my mac, `pathModule === pathModule.posix` and `pathModule !== pathModule.win32`
// however, `!!pathModule.win32 === true`
if (pathModule.posix) {
  const { posix } = pathModule;
  sep = posix.sep;
  relative = posix.relative;
} else {
  // would this even happen? is `path.posix` simply not available on windows?
  sep = pathModule.sep;
  relative = pathModule.relative;
}

const isWin = process.platform === 'win32';
// apparently you can check if the path in question is an absolute path by platform
pathModule.win32.isAbsolute('C:\\') // --> true
pathModule.posix.isAbsolute('C:\\') // --> false
Read more comments on GitHub >

github_iconTop Results From Across the Web

Maximum Path Length Limitation - Win32 apps | Microsoft Learn
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined ......
Read more >
How to Enable Win32 Long Paths in Windows 11/10
Enable Win32 Long Paths through Local Group Policy Editor · Search for gpedit and open it from the Start Menu or Run box...
Read more >
The Definitive Guide on Win32 to NT Path Conversion
How the Win32 APIs process file paths on Windows NT is a tale filled with backwards compatibility hacks, weird behaviour, and beauty†.
Read more >
Windows support for long filenames | Robocorp documentation
Step-by-step guide ... Navigate to Computer Configuration > Administrative Templates > System > Filesystem . On the right, find the "Enable win32 long...
Read more >
How to Enable Support for Long Path in Windows 10 and ...
Fields · 1)In Windows 10/Server 2016, open Group Policy setting by the typing gpedit.msc in the run window · 2)In the Group Policy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found