(cwd: string, files: Set<string>)
| 21 | * @param files The files to format. |
| 22 | */ |
| 23 | export async function formatFiles(cwd: string, files: Set<string>): Promise<void> { |
| 24 | if (!files.size) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if (prettierCliPath === undefined) { |
| 29 | try { |
| 30 | const prettierPath = createRequire(cwd + '/').resolve('prettier/package.json'); |
| 31 | const prettierPackageJson = JSON.parse(await readFile(prettierPath, 'utf-8')) as { |
| 32 | bin: string; |
| 33 | }; |
| 34 | prettierCliPath = join(dirname(prettierPath), prettierPackageJson.bin); |
| 35 | } catch { |
| 36 | // Prettier is not installed. |
| 37 | prettierCliPath = null; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if (!prettierCliPath) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | await execFileAsync( |
| 46 | process.execPath, |
| 47 | [prettierCliPath, '--write', '--no-error-on-unmatched-pattern', '--ignore-unknown', ...files], |
| 48 | { |
| 49 | cwd, |
| 50 | shell: false, |
| 51 | }, |
| 52 | ); |
| 53 | } |
no test coverage detected