cleanup(misc): remove unused error message & simplify quotes in format (#3568)
The yargs conflicts, already handles the message.
This commit is contained in:
parent
a409a2cf68
commit
26c13d66a7
@ -3,7 +3,6 @@ import * as path from 'path';
|
|||||||
import * as resolve from 'resolve';
|
import * as resolve from 'resolve';
|
||||||
import { getProjectRoots, parseFiles } from './shared';
|
import { getProjectRoots, parseFiles } from './shared';
|
||||||
import { fileExists } from '../utils/fileutils';
|
import { fileExists } from '../utils/fileutils';
|
||||||
import { output } from '../utils/output';
|
|
||||||
import {
|
import {
|
||||||
createProjectGraph,
|
createProjectGraph,
|
||||||
onlyWorkspaceProjects,
|
onlyWorkspaceProjects,
|
||||||
@ -27,31 +26,14 @@ const PRETTIER_EXTENSIONS = [
|
|||||||
'mdx',
|
'mdx',
|
||||||
];
|
];
|
||||||
|
|
||||||
export function format(command: 'check' | 'write', args: yargs.Arguments) {
|
const MATCH_ALL_PATTERN = `**/*.{${PRETTIER_EXTENSIONS.join(',')}}`;
|
||||||
let patterns: string[];
|
|
||||||
|
|
||||||
|
export function format(command: 'check' | 'write', args: yargs.Arguments) {
|
||||||
const { nxArgs } = splitArgsIntoNxArgsAndOverrides(args, 'affected');
|
const { nxArgs } = splitArgsIntoNxArgsAndOverrides(args, 'affected');
|
||||||
|
|
||||||
try {
|
const patterns = getPatterns({ ...args, ...nxArgs } as any).map(
|
||||||
patterns = getPatterns({
|
(p) => `"${p}"`
|
||||||
...args,
|
);
|
||||||
...nxArgs,
|
|
||||||
} as any);
|
|
||||||
} catch (e) {
|
|
||||||
output.error({
|
|
||||||
title: e.message,
|
|
||||||
bodyLines: [
|
|
||||||
`Pass the SHA range: ${output.bold(
|
|
||||||
`npm run format:${command} -- --base=SHA1 --head=SHA2`
|
|
||||||
)}`,
|
|
||||||
'',
|
|
||||||
`Or pass the list of files: ${output.bold(
|
|
||||||
`npm run format:${command} -- --files="libs/mylib/index.ts,libs/mylib2/index.ts"`
|
|
||||||
)}`,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chunkify the patterns array to prevent crashing the windows terminal
|
// Chunkify the patterns array to prevent crashing the windows terminal
|
||||||
const chunkList: string[][] = chunkify(patterns, 50);
|
const chunkList: string[][] = chunkify(patterns, 50);
|
||||||
@ -67,7 +49,7 @@ export function format(command: 'check' | 'write', args: yargs.Arguments) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPatterns(args: NxArgs & { libsAndApps: boolean; _: string[] }) {
|
function getPatterns(args: NxArgs & { libsAndApps: boolean; _: string[] }) {
|
||||||
const allFilesPattern = [`"**/*.{${PRETTIER_EXTENSIONS.join(',')}}"`];
|
const allFilesPattern = [MATCH_ALL_PATTERN];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.all) {
|
if (args.all) {
|
||||||
@ -75,16 +57,13 @@ function getPatterns(args: NxArgs & { libsAndApps: boolean; _: string[] }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const p = parseFiles(args);
|
const p = parseFiles(args);
|
||||||
let patterns = p.files
|
const patterns = p.files
|
||||||
.filter((f) => fileExists(f))
|
.filter((f) => fileExists(f))
|
||||||
.filter((f) =>
|
.filter((f) =>
|
||||||
PRETTIER_EXTENSIONS.map((ext) => '.' + ext).includes(path.extname(f))
|
PRETTIER_EXTENSIONS.map((ext) => '.' + ext).includes(path.extname(f))
|
||||||
);
|
);
|
||||||
|
|
||||||
const libsAndApp = args.libsAndApps;
|
return args.libsAndApps ? getPatternsFromApps(patterns) : patterns;
|
||||||
return libsAndApp
|
|
||||||
? getPatternsFromApps(patterns)
|
|
||||||
: patterns.map((f) => `"${f}"`);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return allFilesPattern;
|
return allFilesPattern;
|
||||||
}
|
}
|
||||||
@ -97,9 +76,7 @@ function getPatternsFromApps(affectedFiles: string[]): string[] {
|
|||||||
calculateFileChanges(affectedFiles)
|
calculateFileChanges(affectedFiles)
|
||||||
);
|
);
|
||||||
const roots = getProjectRoots(Object.keys(affectedGraph.nodes));
|
const roots = getProjectRoots(Object.keys(affectedGraph.nodes));
|
||||||
return roots.map(
|
return roots.map((root) => `${root}/${MATCH_ALL_PATTERN}`);
|
||||||
(root) => `"${root}/**/*.{${PRETTIER_EXTENSIONS.join(',')}}"`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function chunkify(target: string[], size: number): string[][] {
|
function chunkify(target: string[], size: number): string[][] {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user