|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
21 | 21 |
|
22 | 22 |
|
23 | | -var isWindows = process.platform === 'win32'; |
24 | 23 | var util = require('util'); |
25 | 24 |
|
26 | 25 |
|
@@ -55,216 +54,6 @@ function normalizeArray(parts, allowAboveRoot) { |
55 | 54 | } |
56 | 55 |
|
57 | 56 |
|
58 | | -if (isWindows) { |
59 | | - // Regex to split a windows path into three parts: [*, device, slash, |
60 | | - // tail] windows-only |
61 | | - var splitDeviceRe = |
62 | | - /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?([\\\/])?([\s\S]*?)$/; |
63 | | - |
64 | | - // Regex to split the tail part of the above into [*, dir, basename, ext] |
65 | | - var splitTailRe = |
66 | | - /^([\s\S]+[\\\/](?!$)|[\\\/])?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/\\]*)?)$/; |
67 | | - |
68 | | - // Function to split a filename into [root, dir, basename, ext] |
69 | | - // windows version |
70 | | - var splitPath = function(filename) { |
71 | | - // Separate device+slash from tail |
72 | | - var result = splitDeviceRe.exec(filename), |
73 | | - device = (result[1] || '') + (result[2] || ''), |
74 | | - tail = result[3] || ''; |
75 | | - // Split the tail into dir, basename and extension |
76 | | - var result2 = splitTailRe.exec(tail), |
77 | | - dir = result2[1] || '', |
78 | | - basename = result2[2] || '', |
79 | | - ext = result2[3] || ''; |
80 | | - return [device, dir, basename, ext]; |
81 | | - }; |
82 | | - |
83 | | - // path.resolve([from ...], to) |
84 | | - // windows version |
85 | | - exports.resolve = function() { |
86 | | - var resolvedDevice = '', |
87 | | - resolvedTail = '', |
88 | | - resolvedAbsolute = false; |
89 | | - |
90 | | - for (var i = arguments.length - 1; i >= -1; i--) { |
91 | | - var path; |
92 | | - if (i >= 0) { |
93 | | - path = arguments[i]; |
94 | | - } else if (!resolvedDevice) { |
95 | | - path = process.cwd(); |
96 | | - } else { |
97 | | - // Windows has the concept of drive-specific current working |
98 | | - // directories. If we've resolved a drive letter but not yet an |
99 | | - // absolute path, get cwd for that drive. We're sure the device is not |
100 | | - // an unc path at this points, because unc paths are always absolute. |
101 | | - path = process.env['=' + resolvedDevice]; |
102 | | - // Verify that a drive-local cwd was found and that it actually points |
103 | | - // to our drive. If not, default to the drive's root. |
104 | | - if (!path || path.slice(0, 3).toLowerCase() !== |
105 | | - resolvedDevice.toLowerCase() + '\\') { |
106 | | - path = resolvedDevice + '\\'; |
107 | | - } |
108 | | - } |
109 | | - |
110 | | - // Skip empty and invalid entries |
111 | | - if (typeof path !== 'string' || !path) { |
112 | | - continue; |
113 | | - } |
114 | | - |
115 | | - var result = splitDeviceRe.exec(path), |
116 | | - device = result[1] || '', |
117 | | - isUnc = device && device.charAt(1) !== ':', |
118 | | - isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute |
119 | | - tail = result[3]; |
120 | | - |
121 | | - if (device && |
122 | | - resolvedDevice && |
123 | | - device.toLowerCase() !== resolvedDevice.toLowerCase()) { |
124 | | - // This path points to another device so it is not applicable |
125 | | - continue; |
126 | | - } |
127 | | - |
128 | | - if (!resolvedDevice) { |
129 | | - resolvedDevice = device; |
130 | | - } |
131 | | - if (!resolvedAbsolute) { |
132 | | - resolvedTail = tail + '\\' + resolvedTail; |
133 | | - resolvedAbsolute = isAbsolute; |
134 | | - } |
135 | | - |
136 | | - if (resolvedDevice && resolvedAbsolute) { |
137 | | - break; |
138 | | - } |
139 | | - } |
140 | | - |
141 | | - // Replace slashes (in UNC share name) by backslashes |
142 | | - resolvedDevice = resolvedDevice.replace(/\//g, '\\'); |
143 | | - |
144 | | - // At this point the path should be resolved to a full absolute path, |
145 | | - // but handle relative paths to be safe (might happen when process.cwd() |
146 | | - // fails) |
147 | | - |
148 | | - // Normalize the tail path |
149 | | - |
150 | | - function f(p) { |
151 | | - return !!p; |
152 | | - } |
153 | | - |
154 | | - resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(f), |
155 | | - !resolvedAbsolute).join('\\'); |
156 | | - |
157 | | - return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) || |
158 | | - '.'; |
159 | | - }; |
160 | | - |
161 | | - // windows version |
162 | | - exports.normalize = function(path) { |
163 | | - var result = splitDeviceRe.exec(path), |
164 | | - device = result[1] || '', |
165 | | - isUnc = device && device.charAt(1) !== ':', |
166 | | - isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute |
167 | | - tail = result[3], |
168 | | - trailingSlash = /[\\\/]$/.test(tail); |
169 | | - |
170 | | - // Normalize the tail path |
171 | | - tail = normalizeArray(tail.split(/[\\\/]+/).filter(function(p) { |
172 | | - return !!p; |
173 | | - }), !isAbsolute).join('\\'); |
174 | | - |
175 | | - if (!tail && !isAbsolute) { |
176 | | - tail = '.'; |
177 | | - } |
178 | | - if (tail && trailingSlash) { |
179 | | - tail += '\\'; |
180 | | - } |
181 | | - |
182 | | - // Convert slashes to backslashes when `device` points to an UNC root. |
183 | | - device = device.replace(/\//g, '\\'); |
184 | | - |
185 | | - return device + (isAbsolute ? '\\' : '') + tail; |
186 | | - }; |
187 | | - |
188 | | - // windows version |
189 | | - exports.join = function() { |
190 | | - function f(p) { |
191 | | - return p && typeof p === 'string'; |
192 | | - } |
193 | | - |
194 | | - var paths = Array.prototype.slice.call(arguments, 0).filter(f); |
195 | | - var joined = paths.join('\\'); |
196 | | - |
197 | | - // Make sure that the joined path doesn't start with two slashes |
198 | | - // - it will be mistaken for an unc path by normalize() - |
199 | | - // unless the paths[0] also starts with two slashes |
200 | | - if (/^[\\\/]{2}/.test(joined) && !/^[\\\/]{2}/.test(paths[0])) { |
201 | | - joined = joined.slice(1); |
202 | | - } |
203 | | - |
204 | | - return exports.normalize(joined); |
205 | | - }; |
206 | | - |
207 | | - // path.relative(from, to) |
208 | | - // it will solve the relative path from 'from' to 'to', for instance: |
209 | | - // from = 'C:\\orandea\\test\\aaa' |
210 | | - // to = 'C:\\orandea\\impl\\bbb' |
211 | | - // The output of the function should be: '..\\..\\impl\\bbb' |
212 | | - // windows version |
213 | | - exports.relative = function(from, to) { |
214 | | - from = exports.resolve(from); |
215 | | - to = exports.resolve(to); |
216 | | - |
217 | | - // windows is not case sensitive |
218 | | - var lowerFrom = from.toLowerCase(); |
219 | | - var lowerTo = to.toLowerCase(); |
220 | | - |
221 | | - function trim(arr) { |
222 | | - var start = 0; |
223 | | - for (; start < arr.length; start++) { |
224 | | - if (arr[start] !== '') break; |
225 | | - } |
226 | | - |
227 | | - var end = arr.length - 1; |
228 | | - for (; end >= 0; end--) { |
229 | | - if (arr[end] !== '') break; |
230 | | - } |
231 | | - |
232 | | - if (start > end) return []; |
233 | | - return arr.slice(start, end - start + 1); |
234 | | - } |
235 | | - |
236 | | - var toParts = trim(to.split('\\')); |
237 | | - |
238 | | - var lowerFromParts = trim(lowerFrom.split('\\')); |
239 | | - var lowerToParts = trim(lowerTo.split('\\')); |
240 | | - |
241 | | - var length = Math.min(lowerFromParts.length, lowerToParts.length); |
242 | | - var samePartsLength = length; |
243 | | - for (var i = 0; i < length; i++) { |
244 | | - if (lowerFromParts[i] !== lowerToParts[i]) { |
245 | | - samePartsLength = i; |
246 | | - break; |
247 | | - } |
248 | | - } |
249 | | - |
250 | | - if (samePartsLength == 0) { |
251 | | - return to; |
252 | | - } |
253 | | - |
254 | | - var outputParts = []; |
255 | | - for (var i = samePartsLength; i < lowerFromParts.length; i++) { |
256 | | - outputParts.push('..'); |
257 | | - } |
258 | | - |
259 | | - outputParts = outputParts.concat(toParts.slice(samePartsLength)); |
260 | | - |
261 | | - return outputParts.join('\\'); |
262 | | - }; |
263 | | - |
264 | | - exports.sep = '\\'; |
265 | | - |
266 | | -} else /* posix */ { |
267 | | - |
268 | 57 | // Split a filename into [root, dir, basename, ext], unix version |
269 | 58 | // 'root' is just a slash, or nothing. |
270 | 59 | var splitPathRe = |
@@ -378,8 +167,6 @@ if (isWindows) { |
378 | 167 | }; |
379 | 168 |
|
380 | 169 | exports.sep = '/'; |
381 | | -} |
382 | | - |
383 | 170 |
|
384 | 171 | exports.dirname = function(path) { |
385 | 172 | var result = splitPath(path), |
@@ -425,29 +212,6 @@ exports.existsSync = util.deprecate(function(path) { |
425 | 212 | }, 'path.existsSync is now called `fs.existsSync`.'); |
426 | 213 | */ |
427 | 214 |
|
428 | | -if (isWindows) { |
429 | | - exports._makeLong = function(path) { |
430 | | - path = '' + path; |
431 | | - if (!path) { |
432 | | - return ''; |
433 | | - } |
434 | | - |
435 | | - var resolvedPath = exports.resolve(path); |
436 | | - |
437 | | - if (resolvedPath.match(/^[a-zA-Z]\:\\/)) { |
438 | | - // path is local filesystem path, which needs to be converted |
439 | | - // to long UNC path. |
440 | | - return '\\\\?\\' + resolvedPath; |
441 | | - } else if (resolvedPath.match(/^\\\\[^?.]/)) { |
442 | | - // path is network UNC path, which needs to be converted |
443 | | - // to long UNC path. |
444 | | - return '\\\\?\\UNC\\' + resolvedPath.substring(2); |
445 | | - } |
446 | | - |
447 | | - return path; |
448 | | - }; |
449 | | -} else { |
450 | 215 | exports._makeLong = function(path) { |
451 | 216 | return path; |
452 | 217 | }; |
453 | | -} |
0 commit comments