Skip to content

Commit ea6772a

Browse files
authored
fix(codemods): Support both .cjs and .mjs prettier config (#1292)
1 parent 32d30ea commit ea6772a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/codemods/src/lib/prettify.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import path from 'path'
1+
import fs from 'node:fs'
2+
import path from 'node:path'
23

34
import { format } from 'prettier'
45

56
import { getPaths } from '@cedarjs/project-config'
67

78
const getPrettierConfig = async () => {
9+
const basePath = getPaths().base
10+
const prettierConfigCjsPath = path.join(basePath, 'prettier.config.cjs')
11+
const prettierConfigMjsPath = path.join(basePath, 'prettier.config.mjs')
12+
const prettierConfigPath = fs.existsSync(prettierConfigCjsPath)
13+
? prettierConfigCjsPath
14+
: prettierConfigMjsPath
15+
816
try {
917
const { default: prettierConfig } = await import(
10-
`file://${path.join(getPaths().base, 'prettier.config.cjs')}`
18+
`file://${prettierConfigPath}`
1119
)
1220
return prettierConfig
1321
} catch {

0 commit comments

Comments
 (0)