fix-cwd
v0.1.0
Published
Fix the current working directory by resolving it to its OS-canonical path before running a command.
Maintainers
Readme
fix-cwd
Fix the current working directory by resolving it to its OS-canonical path before running a command.
Some tools incorrectly set process.cwd() to a path with a lowercase drive letter on Windows (e.g. c:\project instead of C:\Project). This causes issues with require.resolve, import.meta.url, import.meta.dirname, and other path-sensitive APIs. fix-cwd resolves the cwd to its true path using fs.realpathSync.native() before spawning your command.
Install
npm install --save-dev fix-cwdUsage
Prefix your scripts with fix-cwd:
{
"scripts": {
"dev": "fix-cwd vitest",
"build": "fix-cwd vite build"
}
}How it works
- Calls
fs.realpathSync.native(".")to get the OS-canonical path of the current directory - Spawns your command with the corrected cwd
- Forwards signals and exit codes transparently
On Windows, realpathSync.native calls GetFinalPathNameByHandle, which returns the true-cased path (uppercase drive letter, correct directory casing). On Linux/macOS, it's effectively a no-op.
License
MIT
