GeezerVison is showing github.com — path: remove repetitive conditional operator in `posix.resolve` · nodejs/node@3a682cc
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/path.js +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1164,8 +1164,8 @@ const posix = { |
1164 | 1164 | let resolvedPath = ''; |
1165 | 1165 | let resolvedAbsolute = false; |
1166 | 1166 |
|
1167 | | - for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) { |
1168 | | - const path = i >= 0 ? args[i] : posixCwd(); |
| 1167 | + for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) { |
| 1168 | + const path = args[i]; |
1169 | 1169 | validateString(path, `paths[${i}]`); |
1170 | 1170 |
|
1171 | 1171 | // Skip empty entries |
@@ -1178,6 +1178,13 @@ const posix = { |
1178 | 1178 | StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH; |
1179 | 1179 | } |
1180 | 1180 |
|
| 1181 | + if (!resolvedAbsolute) { |
| 1182 | + const cwd = posixCwd(); |
| 1183 | + resolvedPath = `${cwd}/${resolvedPath}`; |
| 1184 | + resolvedAbsolute = |
| 1185 | + StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH; |
| 1186 | + } |
| 1187 | + |
1181 | 1188 | // At this point the path should be resolved to a full absolute path, but |
1182 | 1189 | // handle relative paths to be safe (might happen when process.cwd() fails) |
1183 | 1190 |
|
|