Skip to content

Commit fbbc937

Browse files
Copilothuangyiirene
andcommitted
Fix import inconsistencies based on code review feedback
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent d760c29 commit fbbc937

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

packages/tools/cli/src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ObjectLoader } from '@objectql/platform-node';
33
import { generateTypes } from './generate';
44
import * as path from 'path';
55
import * as fs from 'fs';
6+
import glob from 'fast-glob';
67
import chalk from 'chalk';
78

89
interface BuildOptions {
@@ -71,7 +72,6 @@ export async function build(options: BuildOptions) {
7172
];
7273

7374
let fileCount = 0;
74-
const glob = require('fast-glob');
7575
const files = await glob(metadataPatterns, { cwd: rootDir });
7676

7777
for (const file of files) {

packages/tools/cli/src/commands/format.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'path';
22
import * as fs from 'fs';
33
import chalk from 'chalk';
44
import * as yaml from 'js-yaml';
5+
import glob from 'fast-glob';
56

67
interface FormatOptions {
78
dir?: string;
@@ -20,7 +21,6 @@ export async function format(options: FormatOptions) {
2021
let errorCount = 0;
2122

2223
try {
23-
const glob = require('fast-glob');
2424
const files = await glob(['**/*.yml', '**/*.yaml'], {
2525
cwd: rootDir,
2626
ignore: ['node_modules/**', 'dist/**', 'build/**']
@@ -37,29 +37,34 @@ export async function format(options: FormatOptions) {
3737
// Parse to validate YAML
3838
yaml.load(content);
3939

40-
// Format with Prettier (using require instead of import for better compatibility)
41-
const prettierFormat = require('prettier').format;
42-
const formatted = await prettierFormat(content, {
43-
parser: 'yaml',
44-
printWidth: 80,
45-
tabWidth: 2,
46-
singleQuote: true
47-
});
48-
49-
if (content !== formatted) {
50-
if (options.check) {
51-
console.log(chalk.yellow(` ⚠️ ${file} needs formatting`));
52-
formattedCount++;
40+
// Format with Prettier - use dynamic import for better compatibility
41+
try {
42+
const prettier = await import('prettier');
43+
const formatted = await prettier.format(content, {
44+
parser: 'yaml',
45+
printWidth: 80,
46+
tabWidth: 2,
47+
singleQuote: true
48+
});
49+
50+
if (content !== formatted) {
51+
if (options.check) {
52+
console.log(chalk.yellow(` ⚠️ ${file} needs formatting`));
53+
formattedCount++;
54+
} else {
55+
fs.writeFileSync(filePath, formatted, 'utf-8');
56+
console.log(chalk.green(` ✅ ${file}`));
57+
formattedCount++;
58+
}
5359
} else {
54-
fs.writeFileSync(filePath, formatted, 'utf-8');
55-
console.log(chalk.green(` ✅ ${file}`));
56-
formattedCount++;
57-
}
58-
} else {
59-
unchangedCount++;
60-
if (!options.check) {
61-
console.log(chalk.gray(` ✓ ${file}`));
60+
unchangedCount++;
61+
if (!options.check) {
62+
console.log(chalk.gray(` ✓ ${file}`));
63+
}
6264
}
65+
} catch (prettierError: any) {
66+
console.error(chalk.red(` ❌ ${file}: Prettier error - ${prettierError.message}`));
67+
errorCount++;
6368
}
6469
} catch (e: any) {
6570
console.error(chalk.red(` ❌ ${file}: ${e.message}`));

packages/tools/cli/src/commands/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'path';
2+
import * as fs from 'fs';
23
import chalk from 'chalk';
34
import { spawn } from 'child_process';
45

@@ -21,7 +22,6 @@ export async function test(options: TestOptions) {
2122
let testCommand = 'npm test';
2223

2324
try {
24-
const fs = require('fs');
2525
if (fs.existsSync(packageJsonPath)) {
2626
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
2727

0 commit comments

Comments
 (0)