Skip to content
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

Ensure our project references include transitive references #55339

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -242,3 +242,17 @@ jobs:
echo "Unused baselines:"
git diff --exit-code --name-only
fi

check-project-references:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "*"
check-latest: true
- run: npm ci

- name: Check project references
run: node ./scripts/checkProjectReferences.mjs src/**/*tsconfig*.json
jakebailey marked this conversation as resolved.
Show resolved Hide resolved
65 changes: 65 additions & 0 deletions scripts/checkProjectReferences.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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) {
sandersn marked this conversation as resolved.
Show resolved Hide resolved
if (fs.statSync(p).isDirectory()) {
p += "/tsconfig.json";
}
else if (!p.endsWith(".json")) {
p += ".json";
}
return p;
}

/**
* @param {string} p
*/
function getReferences(p) {
const tsconfigPath = getTsconfigPath(p);
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 [references, parentTransitiveReferences] = getReferences(r);
jakebailey marked this conversation as resolved.
Show resolved Hide resolved
for (const r of references) {
transitiveReferences.add(r);
}
for (const r of parentTransitiveReferences) {
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;
}
}
}
2 changes: 2 additions & 0 deletions src/tsserver/tsconfig.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
{ "path": "../services" },
{ "path": "../jsTyping" },
{ "path": "../server" },
{ "path": "../typingsInstallerCore" },
{ "path": "../deprecatedCompat" },
],
"include": ["**/*"]
}
4 changes: 3 additions & 1 deletion src/tsserverlibrary/tsconfig.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@
{ "path": "../compiler" },
{ "path": "../jsTyping" },
{ "path": "../services" },
{ "path": "../server" }
{ "path": "../server" },
{ "path": "../typingsInstallerCore"},
{ "path": "../deprecatedCompat" },
],
"include": ["**/*"]
}