5
5
const slash = require ( 'slash' )
6
6
const os = require ( 'os' )
7
7
const path = require ( 'path' )
8
+ const realPathSync = require ( 'fs' ) . realpathSync
8
9
9
10
module . exports = {
10
11
print ( val , serialize ) {
@@ -78,19 +79,26 @@ function normalizePaths (value) {
78
79
79
80
}
80
81
82
+ // Follow symlinks using realPathSync (NOT TESTED)
81
83
const cwd = process . cwd ( )
84
+ const cwdReal = getRealPath ( cwd )
82
85
const homeDir = os . homedir ( )
86
+ const homeDirReal = getRealPath ( homeDir )
83
87
const tempDir = os . tmpdir ( )
88
+ const tempDirReal = getRealPath ( tempDir )
84
89
85
90
const homeRelativeToTemp = path . relative ( tempDir , homeDir )
86
91
87
92
const runner = [
88
93
// Replace process.cwd with <PROJECT_ROOT>
89
94
val => val . split ( cwd ) . join ( '<PROJECT_ROOT>' ) ,
95
+ val => val . split ( cwdReal ) . join ( '<PROJECT_ROOT>' ) ,
90
96
// Replace home directory with <TEMP_DIR>
91
97
val => val . split ( tempDir ) . join ( '<TEMP_DIR>' ) ,
98
+ val => val . split ( tempDirReal ) . join ( '<TEMP_DIR>' ) ,
92
99
// Replace home directory with <HOME_DIR>
93
100
val => val . split ( homeDir ) . join ( '<HOME_DIR>' ) ,
101
+ val => val . split ( homeDirReal ) . join ( '<HOME_DIR>' ) ,
94
102
// handle HOME_DIR nested inside TEMP_DIR
95
103
val => val . split ( `<TEMP_DIR>${ path . sep + homeRelativeToTemp } ` ) . join ( '<HOME_DIR>' ) ,
96
104
// Remove win32 drive letters, C:\ -> \
@@ -116,3 +124,20 @@ function shouldUpdate (value) {
116
124
return normalizePaths ( value ) !== value
117
125
118
126
}
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