# @prettier/sync

> Synchronous version of Prettier

Latest version **0.6.1** (published 2025-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @prettier/sync
pnpm add @prettier/sync
yarn add @prettier/sync
bun add @prettier/sync
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2025-06-08 |
| First published | 2022-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Author | fisker Cheung |
| Maintainers | suchipi, mgrip, czosel, patrick91, zimme, azz, vjeux, evilebottnawi, kddeisz, shinigami92, j-f, lydell, fisker, sosukesuzuki |

## Links

- npm: https://www.npmjs.com/package/@prettier/sync
- Repository: https://github.com/prettier/prettier-synchronized
- Homepage: https://github.com/prettier/prettier-synchronized#readme
- Issues: https://github.com/prettier/prettier-synchronized/issues
- Funding: https://github.com/prettier/prettier-synchronized?sponsor=1
- npm.io page: https://npm.io/package/@prettier/sync

## Dependencies (1)

- [make-synchronized](https://npm.io/package/make-synchronized.md) ^0.8.0

## Recent versions

- 0.6.1 (latest) — 2025-06-08
- 0.6.0 — 2025-06-08
- 0.5.5 — 2025-03-24
- 0.5.4 — 2025-03-22
- 0.5.3 — 2025-03-19
- 0.5.2 — 2024-04-17
- 0.5.1 — 2024-02-06
- 0.5.0 — 2024-01-23
- 0.4.0 — 2024-01-22
- 0.3.0 — 2023-07-17
- 0.2.1 — 2023-07-10
- 0.2.0 — 2023-07-10
- 0.1.0 — 2023-07-10
- 0.0.4 — 2022-08-23

## README

# @prettier/sync

[![Build Status][github_actions_badge]][github_actions_link]
[![Coverage][codecov_badge]][codecov_link]
[![Npm Version][package_version_badge]][package_link]
[![MIT License][license_badge]][license_link]

[github_actions_badge]: https://img.shields.io/github/actions/workflow/status/prettier/prettier-synchronized/continuous-integration.yml?style=flat-square
[github_actions_link]: https://github.com/prettier/prettier-synchronized/actions?query=branch%3Amain
[codecov_badge]: https://img.shields.io/codecov/c/github/prettier/prettier-synchronized?style=flat-square
[codecov_link]: https://codecov.io/gh/prettier/prettier-synchronized
[license_badge]: https://img.shields.io/npm/l/@prettier/sync.svg?style=flat-square
[license_link]: https://github.com/prettier/prettier-synchronized/blob/main/license
[package_version_badge]: https://img.shields.io/npm/v/@prettier/sync.svg?style=flat-square
[package_link]: https://www.npmjs.com/package/@prettier/sync

> Synchronous version of Prettier

## Installation

```sh
yarn add prettier @prettier/sync
```

## Usage

```js
import synchronizedPrettier from "@prettier/sync";

synchronizedPrettier.format("foo( )", { parser: "babel" });
// => 'foo();\n'
```

This package is a simple wrapper of [`make-synchronized`](https://github.com/fisker/make-synchronized).

For more complex use cases, it's better to use [`make-synchronized`](https://github.com/fisker/make-synchronized) directly:

Example 1:

```js
// utilities.js
import * as fs from "node:fs/promises";
import * as prettier from "prettier";

export async function formatFile(file) {
  const config = await prettier.resolveConfig(file);
  const content = await fs.readFile(file, "utf8");
  const formatted = await prettier.format(content, {
    ...config,
    filepath: file,
  });
  await fs.writeFile(file, formatted);
}

// index.js
import makeSynchronized from "make-synchronized";

const utilities = makeSynchronized(new URL("./utilities.js", import.meta.url));

utilities.formatFile("/path/to/file.js");
```

Example 2:

```js
import * as fs from "node:fs/promises";
import * as prettier from "prettier";
import makeSynchronized from "make-synchronized";

export default makeSynchronized(import.meta, async function formatFile(file) {
  const config = await prettier.resolveConfig(file);
  const content = await fs.readFile(file, "utf8");
  const formatted = await prettier.format(content, {
    ...config,
    filepath: file,
  });
  await fs.writeFile(file, formatted);
});
```

Alternatively you can also use [`synckit`](https://github.com/un-ts/synckit) or [`make-synchronous`](https://github.com/sindresorhus/make-synchronous).

### `createSynchronizedPrettier(options)`

#### `options`

Type: `object`

##### `prettierEntry`

Type: `string | URL`

Path or URL to prettier entry.

```js
import { createSynchronizedPrettier } from "@prettier/sync";

const synchronizedPrettier = createSynchronizedPrettier({
  prettierEntry: "/path/to/prettier/index.js",
});

synchronizedPrettier.format("foo( )", { parser: "babel" });
// => 'foo();\n'
```

---
_Source: https://npm.io/package/@prettier/sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
