Skip to content

Commit

Permalink
fix(core): Update unit test and improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Dec 13, 2024
1 parent d86d2df commit 5443fe0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ describe('updateTsconfig', () => {
});

const tsconfigContent = {
...readJson(tree, 'tsconfig.base.json'),
extends: './tsconfig.base.json',
compilerOptions: {},
files: [],
include: [],
references: [
{
path: './my-lib',
Expand Down
28 changes: 13 additions & 15 deletions packages/workspace/src/generators/remove/lib/update-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ export async function updateTsconfig(tree: Tree, schema: Schema) {
const graph: ProjectGraph = await createProjectGraphAsync();
const projectMapping = createProjectRootMappings(graph.nodes);
updateJson(tree, tsConfigPath, (json) => {
if (!isUsingTsSolution) {
if (isUsingTsSolution) {
const projectConfigs = readProjectsConfigurationFromProjectGraph(graph);
const project = projectConfigs.projects[schema.projectName];
if (!project) {
throw new Error(
`Could not find project '${schema.project}'. Please choose a project that exists in the Nx Workspace.`
);
}
json.references = json.references.filter(
(ref) => relative(ref.path, project.root) !== ''
);
} else {
for (const importPath in json.compilerOptions.paths) {
for (const path of json.compilerOptions.paths[importPath]) {
const project = findProjectForPath(
Expand All @@ -43,21 +54,8 @@ export async function updateTsconfig(tree: Tree, schema: Schema) {
}
}
}
return json;
} else {
const projectConfigs = readProjectsConfigurationFromProjectGraph(graph);
const project = projectConfigs.projects[schema.projectName];
if (!project) {
throw new Error(
`Could not find project '${schema.project}'. Please choose a project that exists in the Nx Workspace.`
);
}

json.references = json.references.filter(
(ref) => relative(ref.path, project.root) !== ''
);
return json;
}
return json;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ function isUsingPackageManagerWorkspaces(tree: Tree): boolean {
return isWorkspacesEnabled(tree);
}

function isWorkspacesEnabled(
tree: Tree
// packageManager: PackageManager = detectPackageManager(),
// root: string = workspaceRoot
): boolean {
function isWorkspacesEnabled(tree: Tree): boolean {
const packageManager = detectPackageManager(tree.root);
if (packageManager === 'pnpm') {
return tree.exists('pnpm-workspace.yaml');
Expand Down

0 comments on commit 5443fe0

Please sign in to comment.