5 changed files with 16 additions and 25 deletions
@ -0,0 +1,13 @@ |
|||
import fs from 'node:fs/promises'; |
|||
|
|||
import { execa } from 'execa'; |
|||
|
|||
async function formatFile(filepath: string) { |
|||
await execa('oxfmt', [filepath], { |
|||
stdio: 'inherit', |
|||
}); |
|||
|
|||
return await fs.readFile(filepath, 'utf8'); |
|||
} |
|||
|
|||
export { formatFile }; |
|||
@ -1,21 +0,0 @@ |
|||
import fs from 'node:fs/promises'; |
|||
|
|||
import { format, getFileInfo, resolveConfig } from 'prettier'; |
|||
|
|||
async function prettierFormat(filepath: string) { |
|||
const prettierOptions = await resolveConfig(filepath, {}); |
|||
|
|||
const fileInfo = await getFileInfo(filepath); |
|||
|
|||
const input = await fs.readFile(filepath, 'utf8'); |
|||
const output = await format(input, { |
|||
...prettierOptions, |
|||
parser: fileInfo.inferredParser as any, |
|||
}); |
|||
if (output !== input) { |
|||
await fs.writeFile(filepath, output, 'utf8'); |
|||
} |
|||
return output; |
|||
} |
|||
|
|||
export { prettierFormat }; |
|||
Loading…
Reference in new issue