Skip to content

Commit

Permalink
Make prettier.clearConfigCache async (prettier#13265)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and medikoo committed Jan 17, 2024
1 parent 8cd3844 commit 47f31c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion 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<string>`
- `prettier.formatWithCursor()` returns `Promise<{formatted: string, cursorOffset: number}>`
- `prettier.formatAST()` returns `Promise<string>`
- `prettier.check()` returns `Promise<boolean>`
- `prettier.getSupportInfo()` returns `Promise`
- `prettier.clearConfigCache()` returns `Promise<void>`
- `prettier.resolveConfig.sync` is removed
- `prettier.resolveConfigFile.sync` is removed
- `prettier.getFileInfo.sync` is removed
12 changes: 5 additions & 7 deletions docs/api.md
Expand Up @@ -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:
Expand All @@ -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()`
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -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();
}
Expand Down

0 comments on commit 47f31c4

Please sign in to comment.