@@ -26,7 +26,8 @@ const winNormalize = path.win32.normalize;
2626const PathType = Object . freeze ( {
2727 Empty : 0 ,
2828 Normal : 1 ,
29- Relative : 2 ,
29+ RelativeWin : 6 ,
30+ RelativePosix : 2 ,
3031 AbsoluteWin : 3 ,
3132 AbsolutePosix : 4 ,
3233 Internal : 5
@@ -45,7 +46,9 @@ const getType = p => {
4546 const c0 = p . charCodeAt ( 0 ) ;
4647 switch ( c0 ) {
4748 case CHAR_DOT :
48- return PathType . Relative ;
49+ return path . sep . charCodeAt ( 0 ) === CHAR_SLASH
50+ ? PathType . RelativePosix
51+ : PathType . RelativeWin ;
4952 case CHAR_SLASH :
5053 return PathType . AbsolutePosix ;
5154 case CHAR_HASH :
@@ -60,8 +63,13 @@ const getType = p => {
6063 const c1 = p . charCodeAt ( 1 ) ;
6164 switch ( c1 ) {
6265 case CHAR_DOT :
66+ return path . sep . charCodeAt ( 0 ) === CHAR_SLASH
67+ ? PathType . RelativePosix
68+ : PathType . RelativeWin ;
6369 case CHAR_SLASH :
64- return PathType . Relative ;
70+ return PathType . RelativePosix ;
71+ case CHAR_BACKSLASH :
72+ return PathType . RelativeWin ;
6573 }
6674 return PathType . Normal ;
6775 }
@@ -88,10 +96,15 @@ const getType = p => {
8896 const c1 = p . charCodeAt ( 1 ) ;
8997 switch ( c1 ) {
9098 case CHAR_SLASH :
91- return PathType . Relative ;
99+ return PathType . RelativePosix ;
100+ case CHAR_BACKSLASH :
101+ return PathType . RelativeWin ;
92102 case CHAR_DOT : {
93103 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+
95108 return PathType . Normal ;
96109 }
97110 }
@@ -127,12 +140,16 @@ const normalize = p => {
127140 return p ;
128141 case PathType . AbsoluteWin :
129142 return winNormalize ( p ) ;
130- case PathType . Relative : {
143+ case PathType . RelativePosix : {
131144 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 } ` ;
133150 }
134151 }
135- return posixNormalize ( p ) ;
152+ return path . normalize ( p ) ;
136153} ;
137154exports . normalize = normalize ;
138155
@@ -152,21 +169,29 @@ const join = (rootPath, request) => {
152169 }
153170 switch ( getType ( rootPath ) ) {
154171 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 :
156176 case PathType . AbsolutePosix :
157177 return posixNormalize ( `${ rootPath } /${ request } ` ) ;
178+ case PathType . RelativeWin :
158179 case PathType . AbsoluteWin :
159180 return winNormalize ( `${ rootPath } \\${ request } ` ) ;
160181 }
161182 switch ( requestType ) {
162183 case PathType . Empty :
163184 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 : {
165190 const r = posixNormalize ( rootPath ) ;
166- return getType ( r ) === PathType . Relative ? r : `./ ${ r } ` ;
191+ return getType ( r ) === PathType . RelativeWin ? r : `.\\ ${ r } ` ;
167192 }
168193 }
169- return posixNormalize ( rootPath ) ;
194+ return path . normalize ( rootPath ) ;
170195} ;
171196exports . join = join ;
172197
0 commit comments