Skip to content

Commit 91bdd9f

Browse files
authored
fix: @taplo/lib is commonjs actually, export options and types for reusing (#318)
1 parent 0dda4a4 commit 91bdd9f

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

.changeset/khaki-mails-sell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"prettier-plugin-toml": patch
3+
---
4+
5+
fix: `@taplo/lib` is commonjs actually, export `options` and `types` for reusing

packages/toml/src/index.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Taplo } from '@taplo/lib'
1+
import taplo from '@taplo/lib'
22
import type { Plugin } from 'prettier'
33

44
import { languages } from './languages.js'
@@ -7,29 +7,25 @@ import type { PrettierOptions, TaploOptions } from './types.js'
77

88
const PLUGIN_NAME = 'toml'
99

10-
let taplo: Taplo | undefined
10+
let taploIns: taplo.Taplo | undefined
1111

1212
async function format(code: string, options: TaploOptions) {
13-
if (!taplo) {
14-
taplo = await Taplo.initialize()
13+
if (!taploIns) {
14+
taploIns = await taplo.Taplo.initialize()
1515
}
1616

17-
return taplo.format(code, { options })
17+
return taploIns.format(code, { options })
1818
}
1919

2020
const TomlPlugin: Plugin<string> = {
2121
languages,
2222
parsers: {
2323
[PLUGIN_NAME]: {
24-
async parse(code: string, options: PrettierOptions) {
25-
const indentString = options.useTabs
26-
? '\t'
27-
: ' '.repeat(options.tabWidth)
28-
29-
return await format(code.trim(), {
24+
parse(code: string, options: PrettierOptions) {
25+
return format(code.trim(), {
3026
...options,
3127
columnWidth: options.printWidth,
32-
indentString,
28+
indentString: options.useTabs ? '\t' : ' '.repeat(options.tabWidth),
3329
trailingNewline: true,
3430
arrayTrailingComma: options.trailingComma !== 'none',
3531
crlf: options.endOfLine === 'crlf',
@@ -48,4 +44,7 @@ const TomlPlugin: Plugin<string> = {
4844
options: prettierOptionsDefinitions,
4945
}
5046

47+
export type * from './options.js'
48+
export type * from './types.js'
49+
5150
export default TomlPlugin

0 commit comments

Comments
 (0)