* The names of the project's own packages: the `name` of every package.json * at or above a directory the index holds files in, and every dependency * one of them takes from the project (`workspace:`, `file:`, `link:`, * `portal:`, which can install it under another name). An installed copy
()
| 5023 | * count as installed. |
| 5024 | */ |
| 5025 | private projectPackageNames(): Set<string> { |
| 5026 | if (this.ownPackageNames) return this.ownPackageNames; |
| 5027 | const names = new Set<string>(); |
| 5028 | const dirs = new Set<string>(); |
| 5029 | for (const file of this.knownFiles ?? this.queries.getAllFilePaths()) { |
| 5030 | let dir = file.replace(/\\/g, '/'); |
| 5031 | do { |
| 5032 | dir = dir.includes('/') ? dir.slice(0, dir.lastIndexOf('/')) : ''; |
| 5033 | if (dirs.has(dir)) break; |
| 5034 | dirs.add(dir); |
| 5035 | } while (dir !== ''); |
| 5036 | } |
| 5037 | for (const dir of dirs) { |
| 5038 | // Read directly: a sweep of every directory would push source text out of the read cache. |
| 5039 | const json = readPackageJson(path.join(this.projectRoot, dir, 'package.json')); |
| 5040 | if (!json) continue; |
| 5041 | if (typeof json.name === 'string') names.add(json.name); |
| 5042 | for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) { |
| 5043 | const deps = json[field]; |
| 5044 | if (!deps || typeof deps !== 'object') continue; |
| 5045 | for (const [dep, version] of Object.entries(deps)) { |
| 5046 | if (typeof version === 'string' && LOCAL_DEPENDENCY_SPEC.test(version)) names.add(dep); |
| 5047 | } |
| 5048 | } |
| 5049 | } |
| 5050 | this.ownPackageNames = names; |
| 5051 | return names; |
| 5052 | } |
| 5053 | |
| 5054 | /** |
| 5055 | * The `node_modules` folders Node would search from project directory |
no test coverage detected