Skip to content

Commit

Permalink
Merge pull request #154 from nxpm/fix/workspace-lint
Browse files Browse the repository at this point in the history
Remove unecessary sorts, add undefined check to packageJson sort

Merges #153
  • Loading branch information
beeman authored Jan 20, 2022
2 parents b9bda8c + cece005 commit 5dd5b13
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions packages/cli/src/lib/commands/workspace-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,14 @@ function sortItems(items: Record<string, unknown> = {}) {
.reduce((acc, curr) => ({ ...acc, [curr]: items[curr] }), {})
}

export function sortTsConfigPaths(file) {
return {
...file,
compilerOptions: {
...file?.compilerOptions,
paths: sortItems(file?.compilerOptions?.paths),
},
}
}

export function sortWorkspaceProjects(file) {
return {
...file,
projects: sortItems(file?.projects),
}
}

export function sortPackageJson(file) {
return {
...file,
scripts: sortItems(file?.scripts),
...(file?.scripts ? { scripts: sortItems(file?.scripts) } : {}),
}
}

export async function workspaceLint({ dryRun, skipPackageJson }: { dryRun: boolean; skipPackageJson: boolean }) {
for (const file of projectFiles) {
const contents = await getFileContents(file)
if (contents && !dryRun) {
await writeJson(file, sortWorkspaceProjects(contents), { spaces: 2 })
execSync('prettier --write ' + file)
}
}

for (const file of tsconfigFiles) {
const contents = await getFileContents(file)
if (contents && !dryRun) {
await writeJson(file, sortTsConfigPaths(contents), { spaces: 2 })
execSync('prettier --write ' + file)
}
}
if (!skipPackageJson) {
const file = 'package.json'
const contents = await getFileContents(file)
Expand Down

0 comments on commit 5dd5b13

Please sign in to comment.