@@ -26,7 +26,8 @@ const winNormalize = path.win32.normalize;
26
26
const PathType = Object . freeze ( {
27
27
Empty : 0 ,
28
28
Normal : 1 ,
29
- Relative : 2 ,
29
+ RelativeWin : 6 ,
30
+ RelativePosix : 2 ,
30
31
AbsoluteWin : 3 ,
31
32
AbsolutePosix : 4 ,
32
33
Internal : 5
@@ -45,7 +46,9 @@ const getType = p => {
45
46
const c0 = p . charCodeAt ( 0 ) ;
46
47
switch ( c0 ) {
47
48
case CHAR_DOT :
48
- return PathType . Relative ;
49
+ return path . sep . charCodeAt ( 0 ) === CHAR_SLASH
50
+ ? PathType . RelativePosix
51
+ : PathType . RelativeWin ;
49
52
case CHAR_SLASH :
50
53
return PathType . AbsolutePosix ;
51
54
case CHAR_HASH :
@@ -60,8 +63,13 @@ const getType = p => {
60
63
const c1 = p . charCodeAt ( 1 ) ;
61
64
switch ( c1 ) {
62
65
case CHAR_DOT :
66
+ return path . sep . charCodeAt ( 0 ) === CHAR_SLASH
67
+ ? PathType . RelativePosix
68
+ : PathType . RelativeWin ;
63
69
case CHAR_SLASH :
64
- return PathType . Relative ;
70
+ return PathType . RelativePosix ;
71
+ case CHAR_BACKSLASH :
72
+ return PathType . RelativeWin ;
65
73
}
66
74
return PathType . Normal ;
67
75
}
@@ -88,10 +96,15 @@ const getType = p => {
88
96
const c1 = p . charCodeAt ( 1 ) ;
89
97
switch ( c1 ) {
90
98
case CHAR_SLASH :
91
- return PathType . Relative ;
99
+ return PathType . RelativePosix ;
100
+ case CHAR_BACKSLASH :
101
+ return PathType . RelativeWin ;
92
102
case CHAR_DOT : {
93
103
const c2 = p . charCodeAt ( 2 ) ;
94
- if ( c2 === CHAR_SLASH ) return PathType . Relative ;
104
+
105
+ if ( c2 === CHAR_SLASH ) return PathType . RelativePosix ;
106
+ if ( c2 === CHAR_BACKSLASH ) return PathType . RelativeWin ;
107
+
95
108
return PathType . Normal ;
96
109
}
97
110
}
@@ -127,12 +140,16 @@ const normalize = p => {
127
140
return p ;
128
141
case PathType . AbsoluteWin :
129
142
return winNormalize ( p ) ;
130
- case PathType . Relative : {
143
+ case PathType . RelativePosix : {
131
144
const r = posixNormalize ( p ) ;
132
- return getType ( r ) === PathType . Relative ? r : `./${ r } ` ;
145
+ return getType ( r ) === PathType . RelativePosix ? r : `./${ r } ` ;
146
+ }
147
+ case PathType . RelativeWin : {
148
+ const r = winNormalize ( p ) ;
149
+ return getType ( r ) === PathType . RelativeWin ? r : `.\\${ r } ` ;
133
150
}
134
151
}
135
- return posixNormalize ( p ) ;
152
+ return path . normalize ( p ) ;
136
153
} ;
137
154
exports . normalize = normalize ;
138
155
@@ -152,21 +169,29 @@ const join = (rootPath, request) => {
152
169
}
153
170
switch ( getType ( rootPath ) ) {
154
171
case PathType . Normal :
155
- case PathType . Relative :
172
+ return path . sep . charCodeAt ( 0 ) === CHAR_SLASH
173
+ ? posixNormalize ( `${ rootPath } /${ request } ` )
174
+ : winNormalize ( `${ rootPath } \\${ request } ` ) ;
175
+ case PathType . RelativePosix :
156
176
case PathType . AbsolutePosix :
157
177
return posixNormalize ( `${ rootPath } /${ request } ` ) ;
178
+ case PathType . RelativeWin :
158
179
case PathType . AbsoluteWin :
159
180
return winNormalize ( `${ rootPath } \\${ request } ` ) ;
160
181
}
161
182
switch ( requestType ) {
162
183
case PathType . Empty :
163
184
return rootPath ;
164
- case PathType . Relative : {
185
+ case PathType . RelativePosix : {
186
+ const r = posixNormalize ( rootPath ) ;
187
+ return getType ( r ) === PathType . RelativePosix ? r : `./${ r } ` ;
188
+ }
189
+ case PathType . RelativeWin : {
165
190
const r = posixNormalize ( rootPath ) ;
166
- return getType ( r ) === PathType . Relative ? r : `./ ${ r } ` ;
191
+ return getType ( r ) === PathType . RelativeWin ? r : `.\\ ${ r } ` ;
167
192
}
168
193
}
169
- return posixNormalize ( rootPath ) ;
194
+ return path . normalize ( rootPath ) ;
170
195
} ;
171
196
exports . join = join ;
172
197
0 commit comments