diff --git a/internal/node-utils/package.json b/internal/node-utils/package.json index f8add8b4e..b2c68590b 100644 --- a/internal/node-utils/package.json +++ b/internal/node-utils/package.json @@ -37,7 +37,6 @@ "find-up": "catalog:", "ora": "catalog:", "pkg-types": "catalog:", - "prettier": "catalog:", "rimraf": "catalog:" } } diff --git a/internal/node-utils/src/formatter.ts b/internal/node-utils/src/formatter.ts new file mode 100644 index 000000000..78c6be0b9 --- /dev/null +++ b/internal/node-utils/src/formatter.ts @@ -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 }; diff --git a/internal/node-utils/src/index.ts b/internal/node-utils/src/index.ts index 963cb8756..a3e419b39 100644 --- a/internal/node-utils/src/index.ts +++ b/internal/node-utils/src/index.ts @@ -1,12 +1,12 @@ export * from './constants'; export * from './date'; +export { formatFile } from './formatter'; export * from './fs'; export * from './git'; export { getStagedFiles, add as gitAdd } from './git'; export { generatorContentHash } from './hash'; export * from './monorepo'; export { toPosixPath } from './path'; -export { prettierFormat } from './prettier'; export * from './spinner'; export type { Package } from '@manypkg/get-packages'; export { default as colors } from 'chalk'; diff --git a/internal/node-utils/src/prettier.ts b/internal/node-utils/src/prettier.ts deleted file mode 100644 index 1e1525db1..000000000 --- a/internal/node-utils/src/prettier.ts +++ /dev/null @@ -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 }; diff --git a/scripts/vsh/src/code-workspace/index.ts b/scripts/vsh/src/code-workspace/index.ts index d5ec4ee90..02706db4b 100644 --- a/scripts/vsh/src/code-workspace/index.ts +++ b/scripts/vsh/src/code-workspace/index.ts @@ -6,10 +6,10 @@ import { colors, consola, findMonorepoRoot, + formatFile, getPackages, gitAdd, outputJSON, - prettierFormat, toPosixPath, } from '@vben/node-utils'; @@ -40,7 +40,7 @@ async function createCodeWorkspace({ const outputPath = join(monorepoRoot, CODE_WORKSPACE_FILE); await outputJSON(outputPath, { folders }, spaces); - await prettierFormat(outputPath); + await formatFile(outputPath); if (autoCommit) { await gitAdd(CODE_WORKSPACE_FILE, monorepoRoot); }