Filter module graph based on source(…)

This commit is contained in:
Jordan Pittman 2024-10-28 17:13:37 -04:00
parent 938b3c5f94
commit d2be2152ea
2 changed files with 117 additions and 0 deletions

View file

@ -439,9 +439,24 @@ class Root {
if (!this.compiler) return new Set()
if (this.compiler.root === 'none') return new Set()
let root = this.compiler.root
let basePath = root ? path.resolve(root.base, root.pattern) : null
function moduleIdIsAllowed(id: string) {
if (basePath === null) return true
// This a virtual module that's not on the file system
// TODO: What should we do here?
if (!id.startsWith('/')) return true
return id.startsWith(basePath)
}
let shared = new Set<string>()
for (let [id, candidates] of this.getSharedCandidates()) {
if (!moduleIdIsAllowed(id)) continue
for (let candidate of candidates) {
shared.add(candidate)
}