- v7.4.0:
- macOS Sierra 10.12.3:
- os:
os.tmpdir() returns a path like /var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T. Per
|
path = process.env.TMPDIR || |
that's the same path as the
$TMPDIR environment variable. However on macOS this is a symlink. The real path is
/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T:
❯ node -pe 'os.tmpdir()'
/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
❯ node -pe 'fs.realpathSync(os.tmpdir())'
/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
On the face of it the current behavior seems correct, and it's just macOS that is annoying. On the other hand it makes for surprising failures when writing cross-platform code. See sindresorhus/temp-write#8 for example.
At the very least I think this pitfall should be documented (happy to open a PR), but that just means users need to always wrap os.tmpdir() with fs.realpathSync(). Should os.tmpdir() do this by itself? On macOS only, or all platforms?
(Note that this is different from #7545. When your shell is in a directory like /var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T then process.env.PWD is correctly set to that path.)
os.tmpdir()returns a path like/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T. Pernode/lib/os.js
Line 43 in 00c86cc
$TMPDIRenvironment variable. However on macOS this is a symlink. The real path is/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T:On the face of it the current behavior seems correct, and it's just macOS that is annoying. On the other hand it makes for surprising failures when writing cross-platform code. See sindresorhus/temp-write#8 for example.
At the very least I think this pitfall should be documented (happy to open a PR), but that just means users need to always wrap
os.tmpdir()withfs.realpathSync(). Shouldos.tmpdir()do this by itself? On macOS only, or all platforms?(Note that this is different from #7545. When your shell is in a directory like
/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/Tthenprocess.env.PWDis correctly set to that path.)