Skip to content

Commit

Permalink
fix(devkit): remove ensuring property locations from formatFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Dec 14, 2022
1 parent a1d7d2f commit c4a20f9
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions packages/devkit/src/generators/format-files.ts
Expand Up @@ -2,12 +2,7 @@ import type { Tree } from 'nx/src/generators/tree';
import * as path from 'path';
import type * as Prettier from 'prettier';
import { readJson, updateJson, writeJson } from 'nx/src/generators/utils/json';
import {
getWorkspacePath,
readWorkspaceConfiguration,
updateWorkspaceConfiguration,
WorkspaceConfiguration,
} from 'nx/src/generators/utils/project-configuration';
import { getWorkspacePath } from 'nx/src/generators/utils/project-configuration';
import { sortObjectByKeys } from 'nx/src/utils/object-sort';

/**
Expand All @@ -20,7 +15,6 @@ export async function formatFiles(tree: Tree): Promise<void> {
prettier = await import('prettier');
} catch {}

ensurePropertiesAreInNewLocations(tree);
sortWorkspaceJson(tree);
sortTsConfig(tree);

Expand Down Expand Up @@ -88,41 +82,6 @@ function sortWorkspaceJson(tree: Tree) {
}
}

/**
* `updateWorkspaceConfiguration` already handles
* placing properties in their new locations, so
* reading + updating it ensures that props are placed
* correctly.
*/
function ensurePropertiesAreInNewLocations(tree: Tree) {
// If nx.json doesn't exist then there is no where to move these properties to
if (!tree.exists('nx.json')) {
return;
}

const workspacePath = getWorkspacePath(tree);
if (!workspacePath) {
return;
}
const wc = readWorkspaceConfiguration(tree);
updateJson<WorkspaceConfiguration>(tree, workspacePath, (json) => {
wc.generators ??= json.generators ?? (json as any).schematics;
if (wc.cli) {
wc.cli.defaultCollection ??= json.cli?.defaultCollection;
wc.cli.packageManager ??= json.cli?.packageManager;
} else if (json.cli) {
wc.cli ??= json.cli;
}
wc.defaultProject ??= json.defaultProject;
delete json.cli;
delete json.defaultProject;
delete (json as any).schematics;
delete json.generators;
return json;
});
updateWorkspaceConfiguration(tree, wc);
}

function sortTsConfig(tree: Tree) {
try {
const tsConfigPath = getRootTsConfigPath(tree);
Expand Down

0 comments on commit c4a20f9

Please sign in to comment.