|
9 | 9 | import { execFile } from 'node:child_process'; |
10 | 10 | import { readFile } from 'node:fs/promises'; |
11 | 11 | import { createRequire } from 'node:module'; |
12 | | -import { platform } from 'node:os'; |
13 | 12 | import { dirname, extname, join } from 'node:path'; |
14 | 13 | import { promisify } from 'node:util'; |
15 | 14 |
|
@@ -48,42 +47,31 @@ export async function formatFiles(cwd: string, files: Set<string>): Promise<void |
48 | 47 | const prettierPackageJson = JSON.parse(await readFile(prettierPath, 'utf-8')) as { |
49 | 48 | bin: string; |
50 | 49 | }; |
| 50 | + |
51 | 51 | prettierCliPath = join(dirname(prettierPath), prettierPackageJson.bin); |
52 | 52 | } catch { |
53 | 53 | // Prettier is not installed. |
54 | 54 | prettierCliPath = null; |
55 | 55 | } |
56 | 56 | } |
57 | 57 |
|
58 | | - console.log({ prettierCliPath }); |
59 | 58 | if (!prettierCliPath) { |
60 | 59 | return; |
61 | 60 | } |
62 | 61 |
|
63 | 62 | const filesToFormat: string[] = []; |
64 | 63 | for (const file of files) { |
65 | 64 | if (fileTypes.has(extname(file))) { |
66 | | - filesToFormat.push(`"${file}"`); |
| 65 | + filesToFormat.push(file); |
67 | 66 | } |
68 | 67 | } |
69 | 68 |
|
70 | 69 | if (!filesToFormat.length) { |
71 | 70 | return; |
72 | 71 | } |
73 | 72 |
|
74 | | - console.log({ filesToFormat, cwd }); |
75 | | - |
76 | | - console.log( |
77 | | - await execFileAsync(prettierCliPath, ['--check', ...filesToFormat], { |
78 | | - cwd, |
79 | | - shell: platform() === 'win32', |
80 | | - }), |
81 | | - ); |
82 | | - |
83 | | - const x = await execFileAsync(prettierCliPath, ['--write', ...filesToFormat], { |
| 73 | + await execFileAsync(process.execPath, [prettierCliPath, '--write', ...filesToFormat], { |
84 | 74 | cwd, |
85 | | - shell: platform() === 'win32', |
| 75 | + shell: false, |
86 | 76 | }); |
87 | | - |
88 | | - console.log({ x }); |
89 | 77 | } |
0 commit comments