Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): replace runtime require of prettier with import (#5290)
- Loading branch information
1 parent
ae6fd7a
commit 94e4e4d
Showing
2 changed files
with
5 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
import type { format, resolveConfig } from "prettier" | ||
import { format, resolveConfig } from "prettier" | ||
|
||
const createFormatFileWithPrettier = (prettier: { | ||
format: typeof format | ||
resolveConfig: typeof resolveConfig | ||
}) => async (content: string) => { | ||
const prettierConfig = await prettier.resolveConfig(process.cwd()) | ||
return prettier.format(String(content), { | ||
async function createFormatFileWithPrettier(content: string) { | ||
const prettierConfig = await resolveConfig(process.cwd()) | ||
return format(String(content), { | ||
...prettierConfig, | ||
parser: "typescript", | ||
}) | ||
} | ||
|
||
export async function formatWithPrettierIfAvailable(content: string) { | ||
let prettier | ||
try { | ||
// eslint-disable-next-line global-require | ||
prettier = require("prettier") | ||
} catch { | ||
// silent exit if prettier is not installed | ||
return content | ||
} | ||
|
||
return createFormatFileWithPrettier(prettier)(content) | ||
return createFormatFileWithPrettier(content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94e4e4d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: