* Find which package key contains the given file path. * @param {string} filePath * @returns {string|null}
(filePath)
| 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. |