MCPcopy Index your code
hub / github.com/nodejs/node / #getKeyForPath

Method #getKeyForPath

lib/internal/modules/package_map.js:142–161  ·  view source on GitHub ↗

* Find which package key contains the given file path. * @param {string} filePath * @returns {string|null}

(filePath)

Source from the content-addressed store, hash-verified

140 * @returns {string|null}
141 */
142 #getKeyForPath(filePath) {
143 const cached = this.#pathToKeyCache.get(filePath);
144 if (cached !== undefined) { return cached; }
145
146 // Walk up to find containing package
147 let checkPath = filePath;
148 while (true) {
149 const key = this.#pathToKey.get(checkPath);
150 if (key !== undefined) {
151 this.#pathToKeyCache.set(filePath, key);
152 return key;
153 }
154 const parent = dirname(checkPath);
155 if (parent === checkPath) { break; }
156 checkPath = parent;
157 }
158
159 this.#pathToKeyCache.set(filePath, null);
160 return null;
161 }
162
163 /**
164 * Main resolution method.

Callers 1

resolveMethod · 0.95

Calls 3

dirnameFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected