Skip to content

Commit af87ced

Browse files
committed
handle directory symlinks via fs.realPathSync
1 parent 8d18c11 commit af87ced

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const slash = require('slash')
66
const os = require('os')
77
const path = require('path')
8+
const realPathSync = require('fs').realpathSync
89

910
module.exports = {
1011
print (val, serialize) {
@@ -78,19 +79,26 @@ function normalizePaths (value) {
7879

7980
}
8081

82+
// Follow symlinks using realPathSync (NOT TESTED)
8183
const cwd = process.cwd()
84+
const cwdReal = getRealPath(cwd)
8285
const homeDir = os.homedir()
86+
const homeDirReal = getRealPath(homeDir)
8387
const tempDir = os.tmpdir()
88+
const tempDirReal = getRealPath(tempDir)
8489

8590
const homeRelativeToTemp = path.relative(tempDir, homeDir)
8691

8792
const runner = [
8893
// Replace process.cwd with <PROJECT_ROOT>
8994
val => val.split(cwd).join('<PROJECT_ROOT>'),
95+
val => val.split(cwdReal).join('<PROJECT_ROOT>'),
9096
// Replace home directory with <TEMP_DIR>
9197
val => val.split(tempDir).join('<TEMP_DIR>'),
98+
val => val.split(tempDirReal).join('<TEMP_DIR>'),
9299
// Replace home directory with <HOME_DIR>
93100
val => val.split(homeDir).join('<HOME_DIR>'),
101+
val => val.split(homeDirReal).join('<HOME_DIR>'),
94102
// handle HOME_DIR nested inside TEMP_DIR
95103
val => val.split(`<TEMP_DIR>${path.sep + homeRelativeToTemp}`).join('<HOME_DIR>'),
96104
// Remove win32 drive letters, C:\ -> \
@@ -116,3 +124,20 @@ function shouldUpdate (value) {
116124
return normalizePaths(value) !== value
117125

118126
}
127+
128+
function getRealPath (pathname) {
129+
130+
try {
131+
132+
const realPath = realPathSync(pathname)
133+
134+
return realPath
135+
136+
}
137+
catch (error) {
138+
139+
return pathname
140+
141+
}
142+
143+
}

0 commit comments

Comments
 (0)