MCPcopy Index your code
hub / github.com/nodejs/node / resolve

Function resolve

lib/path.js:190–344  ·  view source on GitHub ↗

* path.resolve([from ...], to) * @param {...string} args * @returns {string}

(...args)

Source from the content-addressed store, hash-verified

188 * @returns {string}
189 */
190 resolve(...args) {
191 let resolvedDevice = '';
192 let resolvedTail = '';
193 let resolvedAbsolute = false;
194
195 for (let i = args.length - 1; i >= -1; i--) {
196 let path;
197 if (i >= 0) {
198 path = args[i];
199 validateString(path, `paths[${i}]`);
200
201 // Skip empty entries
202 if (path.length === 0) {
203 continue;
204 }
205 } else if (resolvedDevice.length === 0) {
206 path = process.cwd();
207 // Fast path for current directory
208 if (args.length === 0 || ((args.length === 1 && (args[0] === '' || args[0] === '.')) &&
209 isPathSeparator(StringPrototypeCharCodeAt(path, 0)))) {
210 if (!isWindows) {
211 path = StringPrototypeReplace(path, forwardSlashRegExp, '\\');
212 }
213 return path;
214 }
215 } else {
216 // Windows has the concept of drive-specific current working
217 // directories. If we've resolved a drive letter but not yet an
218 // absolute path, get cwd for that drive, or the process cwd if
219 // the drive cwd is not available. We're sure the device is not
220 // a UNC path at this points, because UNC paths are always absolute.
221 path = process.env[`=${resolvedDevice}`] || process.cwd();
222
223 // Verify that a cwd was found and that it actually points
224 // to our drive. If not, default to the drive's root.
225 if (path === undefined ||
226 (StringPrototypeToLowerCase(StringPrototypeSlice(path, 0, 2)) !==
227 StringPrototypeToLowerCase(resolvedDevice) &&
228 StringPrototypeCharCodeAt(path, 2) === CHAR_BACKWARD_SLASH)) {
229 path = `${resolvedDevice}\\`;
230 }
231 }
232
233 const len = path.length;
234 let rootEnd = 0;
235 let device = '';
236 let isAbsolute = false;
237 const code = StringPrototypeCharCodeAt(path, 0);
238
239 // Try to match a root
240 if (len === 1) {
241 if (isPathSeparator(code)) {
242 // `path` contains just a path separator
243 rootEnd = 1;
244 isAbsolute = true;
245 }
246 } else if (isPathSeparator(code)) {
247 // Possible UNC root

Callers 10

readline.jsFile · 0.70
resolverFunction · 0.70
runBenchmarkFunction · 0.50
runBenchmarkFunction · 0.50
mainFunction · 0.50
runFunction · 0.50
readFunction · 0.50
callbackFunction · 0.50
runClassicFunction · 0.50

Calls 3

isPathSeparatorFunction · 0.85
isWindowsDeviceRootFunction · 0.85
normalizeStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…