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

Function transformPath

test/common/assertSnapshot.js:103–121  ·  view source on GitHub ↗
(dirname, replacement)

Source from the content-addressed store, hash-verified

101// Replaces a path with a placeholder. The path can be a platform specific path
102// or a file URL.
103function 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.

Callers 1

transformProjectRootFunction · 0.85

Calls 3

replaceWindowsPathsFunction · 0.85
pathToFileURLFunction · 0.50
escapeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…