Skip to content

Commit

Permalink
fix(js): improve typescript plugin messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Sep 27, 2024
1 parent 5d6b357 commit c465101
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ describe('syncGenerator()', () => {
writeJson(tree, 'nx.json', nxJson);

await expect(syncGenerator(tree)).rejects.toMatchInlineSnapshot(
`[Error: The @nx/js/typescript plugin must be added to the "plugins" array in nx.json before syncing tsconfigs]`
`[SyncError: The "@nx/js/typescript" plugin is not registered]`
);
});

it('should error if there is no root tsconfig.json', async () => {
tree.delete('tsconfig.json');

await expect(syncGenerator(tree)).rejects.toMatchInlineSnapshot(
`[Error: A "tsconfig.json" file must exist in the workspace root in order to use this sync generator.]`
`[SyncError: Missing root "tsconfig.json"]`
);
});

Expand Down
19 changes: 11 additions & 8 deletions packages/js/src/generators/typescript-sync/typescript-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
import ignore from 'ignore';
import { applyEdits, modify } from 'jsonc-parser';
import { dirname, normalize, relative } from 'node:path/posix';
import type { SyncGeneratorResult } from 'nx/src/utils/sync-generators';
import {
SyncError,
type SyncGeneratorResult,
} from 'nx/src/utils/sync-generators';
import * as ts from 'typescript';
import {
PLUGIN_NAME,
Expand Down Expand Up @@ -63,17 +66,17 @@ export async function syncGenerator(tree: Tree): Promise<SyncGeneratorResult> {
}
);
if (!tscPluginConfig) {
throw new Error(
`The ${PLUGIN_NAME} plugin must be added to the "plugins" array in nx.json before syncing tsconfigs`
);
throw new SyncError(`The "${PLUGIN_NAME}" plugin is not registered`, [
`The "${PLUGIN_NAME}" plugin must be added to the "plugins" array in "nx.json" in order to sync the project graph information to the TypeScript configuration files.`,
]);
}

// Root tsconfig containing project references for the whole workspace
const rootTsconfigPath = 'tsconfig.json';
if (!tree.exists(rootTsconfigPath)) {
throw new Error(
`A "tsconfig.json" file must exist in the workspace root in order to use this sync generator.`
);
throw new SyncError('Missing root "tsconfig.json"', [
`A "tsconfig.json" file must exist in the workspace root in order to sync the project graph information to the TypeScript configuration files.`,
]);
}

const rawTsconfigContentsCache = new Map<string, string>();
Expand Down Expand Up @@ -254,7 +257,7 @@ export async function syncGenerator(tree: Tree): Promise<SyncGeneratorResult> {

return {
outOfSyncMessage:
'Based on the workspace project graph, some TypeScript configuration files are missing project references to the projects they depend on.',
'Based on the workspace project graph, some TypeScript configuration files are missing project references to the projects they depend on or contain outdated project references.',
};
}
}
Expand Down

0 comments on commit c465101

Please sign in to comment.