Ver código fonte

refactor: rename formatter utilities

xingyu4j 3 meses atrás
pai
commit
542ed6c08f

+ 0 - 1
internal/node-utils/package.json

@@ -37,7 +37,6 @@
     "find-up": "catalog:",
     "ora": "catalog:",
     "pkg-types": "catalog:",
-    "prettier": "catalog:",
     "rimraf": "catalog:"
   }
 }

+ 13 - 0
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 };

+ 1 - 1
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';

+ 0 - 21
internal/node-utils/src/prettier.ts

@@ -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 };

+ 2 - 2
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);
   }