Skip to content
Draft
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 @@ -225,6 +225,27 @@ describe('syncGenerator()', () => {
`);
});

it('should not report a non-composite project as a missing reference', async () => {
addProject('not-composite', [], [], 'packages/not-composite');
writeJson(tree, 'packages/not-composite/tsconfig.json', {
compilerOptions: {},
});

const result = await syncGenerator(tree);

// It is dropped before writing, so it must never be named as a reason
// the workspace is out of sync.
expect((result as any).outOfSyncDetails).toStrictEqual([
'tsconfig.json:',
' - Missing references: packages/a/tsconfig.json, packages/b/tsconfig.json',
'packages/b/tsconfig.json:',
' - Missing references: packages/a/tsconfig.json',
]);
expect(readJson(tree, 'tsconfig.json').references).not.toContainEqual({
path: './packages/not-composite',
});
});

it('should respect existing project references and discard non-existing ones in the tsconfig.json', async () => {
writeJson(tree, 'tsconfig.json', {
compilerOptions: {
Expand Down
13 changes: 12 additions & 1 deletion packages/js/src/generators/typescript-sync/typescript-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ export async function syncGenerator(tree: Tree): Promise<SyncGeneratorResult> {
const normalizedPath = normalizeReferencePath(node.data.root);
// Skip the root tsconfig itself
if (node.data.root !== '.' && !referencesSet.has(normalizedPath)) {
// Non-composite projects are dropped when writing below, so reporting
// them here would name a reference that can never be satisfied.
if (
!hasCompositeEnabled(
tsSysFromTree,
tsconfigInfoCaches,
joinPathFragments(normalizedPath, 'tsconfig.json')
)
) {
continue;
}
referencesSet.add(normalizedPath);
addChangedFile(
changedFiles,
Expand All @@ -182,7 +193,7 @@ export async function syncGenerator(tree: Tree): Promise<SyncGeneratorResult> {

if (changedFiles.size > 0) {
const updatedReferences = Array.from(referencesSet)
// Check composite is true in the internal reference before proceeding
// Pre-existing references skip the check above, so still filter here.
.filter((ref) =>
hasCompositeEnabled(
tsSysFromTree,
Expand Down
Loading