diff --git a/changelog_unreleased/api/12574.md b/changelog_unreleased/api/12574.md index 9353db15d..fb0ea072c 100644 --- a/changelog_unreleased/api/12574.md +++ b/changelog_unreleased/api/12574.md @@ -1,10 +1,11 @@ -#### [BREAKING] Change public APIs to asynchronous (#12574, #12788, #12790 by @fisker) +#### [BREAKING] Change public APIs to asynchronous (#12574, #12788, #12790, #13265 by @fisker) - `prettier.format()` returns `Promise` - `prettier.formatWithCursor()` returns `Promise<{formatted: string, cursorOffset: number}>` - `prettier.formatAST()` returns `Promise` - `prettier.check()` returns `Promise` - `prettier.getSupportInfo()` returns `Promise` +- `prettier.clearConfigCache()` returns `Promise` - `prettier.resolveConfig.sync` is removed - `prettier.resolveConfigFile.sync` is removed - `prettier.getFileInfo.sync` is removed diff --git a/docs/api.md b/docs/api.md index 08278a267..31560c64f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -45,10 +45,9 @@ The promise will be rejected if there was an error parsing the configuration fil If `options.useCache` is `false`, all caching will be bypassed. ```js -const text = fs.readFileSync(filePath, "utf8"); -prettier.resolveConfig(filePath).then((options) => { - const formatted = prettier.format(text, options); -}); +const text = await fs.readFile(filePath, "utf8"); +const options = await prettier.resolveConfig(filePath); +const formatted = await prettier.format(text, options); ``` If `options.editorconfig` is `true` and an [`.editorconfig` file](https://editorconfig.org/) is in your project, Prettier will parse it and convert its properties to the corresponding Prettier configuration. This configuration will be overridden by `.prettierrc`, etc. Currently, the following EditorConfig properties are supported: @@ -70,9 +69,8 @@ The promise will be rejected if there was an error parsing the configuration fil The search starts at `process.cwd()`, or at `filePath` if provided. Please see the [cosmiconfig docs](https://github.com/davidtheclark/cosmiconfig#explorersearch) for details on how the resolving works. ```js -prettier.resolveConfigFile(filePath).then((configFile) => { - // you got the path of the configuration file -}); +const configFile = await prettier.resolveConfigFile(filePath); +// you got the path of the configuration file ``` ## `prettier.clearConfigCache()` diff --git a/src/index.js b/src/index.js index 3499e29ee..8e67bb3e1 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,8 @@ async function check(text, options) { return (await format(text, options)) === text; } -function clearCache() { +// eslint-disable-next-line require-await +async function clearCache() { clearConfigCache(); clearPluginCache(); }