-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Ensure our project references include transitive references #55339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
91512a9
a8e9714
0b4602a
3764c82
3b82b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import assert from "assert"; | ||
import fs from "fs"; | ||
import glob from "glob"; | ||
import JSONC from "jsonc-parser"; | ||
import path from "path"; | ||
import url from "url"; | ||
|
||
|
||
const __filename = url.fileURLToPath(new URL(import.meta.url)); | ||
const __dirname = path.dirname(__filename); | ||
|
||
|
||
// This script checks that we list all transitive references in all tsconfig.json files. | ||
// See: https://github.com/microsoft/TypeScript/issues/30608 | ||
|
||
|
||
/** | ||
* @param {string} p | ||
*/ | ||
function getTsconfigPath(p) { | ||
if (fs.statSync(p).isDirectory()) { | ||
p += "/tsconfig.json"; | ||
} | ||
else if (!p.endsWith(".json")) { | ||
p += ".json"; | ||
} | ||
return p; | ||
} | ||
|
||
/** | ||
* @param {string} p | ||
*/ | ||
function getReferences(p) { | ||
const result = getReferencesWorker(p, new Set()); | ||
assert(result); | ||
return result; | ||
|
||
/** | ||
* @param {string} p | ||
* @param {Set<string>} seen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor quibble: there's no reason to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I had it like that before but switched it to this. I'm not picky but I'm too not sure if this PR is still needed. |
||
*/ | ||
function getReferencesWorker(p, seen) { | ||
const tsconfigPath = getTsconfigPath(p); | ||
if (seen.has(tsconfigPath)) { | ||
return undefined; | ||
} | ||
seen.add(tsconfigPath); | ||
|
||
const dir = path.dirname(tsconfigPath); | ||
const contents = JSONC.parse(fs.readFileSync(tsconfigPath, "utf8")); | ||
const references = new Set(); | ||
for (const r of contents.references || []) { | ||
references.add(path.resolve(dir, r.path)); | ||
} | ||
|
||
const transitiveReferences = new Set(); | ||
for (const r of references) { | ||
const result = getReferencesWorker(r, seen); | ||
if (!result) continue; | ||
|
||
const [otherReferences, otherTransitiveReferences] = result; | ||
for (const r of otherReferences) { | ||
transitiveReferences.add(r); | ||
} | ||
for (const r of otherTransitiveReferences) { | ||
transitiveReferences.add(r); | ||
} | ||
} | ||
|
||
return [references, transitiveReferences]; | ||
} | ||
} | ||
|
||
const paths = glob.sync("src/**/*tsconfig*.json", { cwd: path.resolve(__dirname, "..") }); | ||
for (const p of paths) { | ||
const [references, transitiveReferences] = getReferences(p); | ||
|
||
for (const r of transitiveReferences) { | ||
if (!references.has(r)) { | ||
console.error(`${p} should reference ${path.relative(path.dirname(p), r)}`); | ||
process.exitCode = 1; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.