Skip to content

Commit 27d3b52

Browse files
committed
feat(oxfmt): publish preset types and .js export
Add oxfmt-preset.d.ts and a types condition on the ./oxfmt export so TypeScript resolves without consumer shims. Rename the preset from .mjs to .js under this package's type module. Made-with: Cursor
1 parent 61279a2 commit 27d3b52

7 files changed

Lines changed: 20 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ configure anything more than the defaults).
6262
Install [Oxfmt](https://oxc.rs/docs/guide/usage/formatter.html) alongside this
6363
package (it is listed in `peerDependencies`).
6464

65-
The `@epic-web/config/oxfmt` entry resolves to a plain `.mjs` preset so Node
66-
does not need to strip TypeScript from files under `node_modules` when you
67-
extend it.
65+
The `@epic-web/config/oxfmt` entry resolves to a plain `.js` preset (this
66+
package uses `"type": "module"`) so Node does not need to strip TypeScript from
67+
files under `node_modules` when you extend it.
6868

6969
Create an `oxfmt.config.ts` file in your project root:
7070

@@ -108,7 +108,7 @@ Epic projects. Adjust in your `defineConfig` if your layout differs.
108108
<summary>Customizing Oxfmt</summary>
109109

110110
If you want to customize things heavily, you can copy the options from
111-
[`oxfmt-preset.mjs`](./oxfmt-preset.mjs) into your own config. For small tweaks,
111+
[`oxfmt-preset.js`](./oxfmt-preset.js) into your own config. For small tweaks,
112112
keep spreading `epicOxfmt` and override or extend fields as in the example
113113
above.
114114

docs/decisions/011-oxfmt-over-prettier.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ignore files; lockfiles and generated paths were duplicated across
2626

2727
Adopt **Oxfmt** as the shared formatter for `@epic-web/config`:
2828

29-
- Replace the Prettier entry point with a published `oxfmt-preset.mjs` (via
29+
- Replace the Prettier entry point with a published `oxfmt-preset.js` (via
3030
`defineConfig`) and document `oxfmt` as a peer dependency.
3131
- Map the old Prettier options into Oxfmt where supported; document gaps (for
3232
example `insertPragma` / `requirePragma`, and regex-based Tailwind attribute
@@ -53,7 +53,7 @@ Adopt **Oxfmt** as the shared formatter for `@epic-web/config`:
5353
- Output is “Prettier-like” but not identical everywhere; teams should expect a
5454
one-time format churn when switching.
5555
- Some Prettier options and comment forms have no equivalent; those are called
56-
out in `oxfmt-preset.mjs` and the readme.
56+
out in `oxfmt-preset.js` and the readme.
5757

5858
Historical decision docs that mention Prettier remain valid as context for
5959
_formatting style_; this decision supersedes the _tool choice_ for applying that

oxfmt-preset.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { type OxfmtConfig } from 'oxfmt'
2+
3+
declare const preset: OxfmtConfig
4+
export default preset

oxfmt-preset.mjs renamed to oxfmt-preset.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { defineConfig } from 'oxfmt'
22

33
/**
4-
* Shared Oxfmt preset for `@epic-web/config` consumers (plain `.mjs` so Node does
5-
* not load TypeScript from `node_modules`).
4+
* Shared Oxfmt preset for `@epic-web/config` consumers (plain `.js` under this
5+
* package’s `"type": "module"` so Node does not execute TypeScript from
6+
* `node_modules`).
67
*
78
* @see https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html
89
*/

oxfmt.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './oxfmt-preset.mjs'
1+
export { default } from './oxfmt-preset.js'

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
},
1414
"exports": {
1515
".": "./index.js",
16-
"./oxfmt": "./oxfmt-preset.mjs",
16+
"./oxfmt": {
17+
"types": "./oxfmt-preset.d.ts",
18+
"import": "./oxfmt-preset.js",
19+
"default": "./oxfmt-preset.js"
20+
},
1721
"./typescript": "./typescript.json",
1822
"./reset.d.ts": "./reset.d.ts",
1923
"./oxlint": "./oxlint-config.json"

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./typescript.json",
3-
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
3+
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "oxfmt-preset.d.ts"]
44
}

0 commit comments

Comments
 (0)