fix(js): improve typescript-sync generator messaging (#28162)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
49c5a73cd0
commit
153451f32b
@ -92,7 +92,7 @@ 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]`
|
||||
);
|
||||
});
|
||||
|
||||
@ -100,7 +100,7 @@ describe('syncGenerator()', () => {
|
||||
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"]`
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@ -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,
|
||||
@ -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>();
|
||||
@ -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.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user