(dirname, replacement)
| 101 | // Replaces a path with a placeholder. The path can be a platform specific path |
| 102 | // or a file URL. |
| 103 | function transformPath(dirname, replacement) { |
| 104 | // Handles output already processed by `replaceWindowsPaths`. |
| 105 | const winPath = replaceWindowsPaths(dirname); |
| 106 | // Handles URL encoded path in file URL strings as well. |
| 107 | const urlEncoded = pathToFileURL(dirname).pathname; |
| 108 | // On Windows, paths are case-insensitive, so we need to use case-insensitive |
| 109 | // regex replacement to handle cases where the drive letter case differs. |
| 110 | const flags = common.isWindows ? 'gi' : 'g'; |
| 111 | const urlEncodedRegex = new RegExp(RegExp.escape(urlEncoded), flags); |
| 112 | const dirnameRegex = new RegExp(RegExp.escape(dirname), flags); |
| 113 | const winPathRegex = new RegExp(RegExp.escape(winPath), flags); |
| 114 | return (str) => { |
| 115 | return str.replaceAll('\\\'', "'") |
| 116 | // Replace fileUrl first as `winPath` could be a substring of the fileUrl. |
| 117 | .replaceAll(urlEncodedRegex, replacement) |
| 118 | .replaceAll(dirnameRegex, replacement) |
| 119 | .replaceAll(winPathRegex, replacement); |
| 120 | }; |
| 121 | } |
| 122 | |
| 123 | // Replaces path strings representing the nodejs/node repo full project root with |
| 124 | // `<project-root>`. Also replaces file URLs containing the full project root path. |
no test coverage detected
searching dependent graphs…