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

fix(js): only add typescript project references for explicit dependencies in sync generator #28998

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ describe('syncGenerator()', () => {
});
}

function addProjectWithImplicitDependencies(
name: string,
implicitDependencies: string[]
) {
addProject(name);
projectGraph.nodes[name].data.implicitDependencies = implicitDependencies;
}

beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();
projectGraph = {
Expand Down Expand Up @@ -612,6 +620,23 @@ describe('syncGenerator()', () => {
`);
});

it('should not add a reference if dependent project is an implicit dependency', async () => {
addProject('implicit-dep');
addProjectWithImplicitDependencies('foo', ['implicit-dep']);

await syncGenerator(tree);

expect(tree.read('packages/foo/tsconfig.json').toString('utf-8'))
.toMatchInlineSnapshot(`
"{
"compilerOptions": {
"composite": true
}
}
"
`);
});

describe('without custom sync generator options', () => {
it.each`
runtimeTsConfigFileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,22 @@ function collectProjectDependencies(

collectedDependencies.set(projectName, []);

const implicitDependencies = new Set(
projectGraph.nodes[projectName].data.implicitDependencies ?? []
);

for (const dep of projectGraph.dependencies[projectName]) {
const targetProjectNode = projectGraph.nodes[dep.target];
if (!targetProjectNode) {
// It's an npm dependency
continue;
}

if (implicitDependencies.has(targetProjectNode.name)) {
// It's an implicit dependency and therefore not explicitly referenced in code
continue;
}

// Add the target project node to the list of dependencies for the current project
if (
!collectedDependencies
Expand Down