Description
the __filename
(and so also __dirname
) values do not report the correct paths for files and dirs that have been symlinked/junctioned, given that their behaviour is currently undefined in the API, thus not officialy having a correct behaviour in these cases.
Reading through https://nodejs.org/docs/latest/api/modules.html#modules_filename the only description is that referencing the value will yield an absolute path, but the conventional absolute path for a symlink or junction is that path, as seen locally. Instead, __filename
/__dirname
yield the original resource path, which can be on completely different drives or even network shares.
Given that __filename
's behaviour is currently undefined for symlinks/junctions, and that the actual behaviour that manifests is contrary to normal, expected behaviour for symlink/junction, what it's currently doing is close enough to a bug to merit fixing.
- can we change
__filename
to return the proper absolute path, local to the filesystem path that the file was loaded from, and, - can we update the API documentation to define the behaviour as "this value is symlink/junction-safe"
I know about the https://nodejs.org/api/cli.html#cli_preserve_symlinks flag, but this should not be the exception to the rule: not following a symlink to its original resource unless explicitly told to is the whole reason symlinks and junctions work, where code that checks for locality should not break just because symlinks are suddenly resolved to wildly remote paths ("am I running in a dir parallel to my owner?", "is this resource in a subdir of my dir?", "is this web asset being loaded from the dir that my config says is my asset dir?" etc. etc.)