1
- import { Taplo } from '@taplo/lib'
1
+ import taplo from '@taplo/lib'
2
2
import type { Plugin } from 'prettier'
3
3
4
4
import { languages } from './languages.js'
@@ -7,29 +7,25 @@ import type { PrettierOptions, TaploOptions } from './types.js'
7
7
8
8
const PLUGIN_NAME = 'toml'
9
9
10
- let taplo : Taplo | undefined
10
+ let taploIns : taplo . Taplo | undefined
11
11
12
12
async function format ( code : string , options : TaploOptions ) {
13
- if ( ! taplo ) {
14
- taplo = await Taplo . initialize ( )
13
+ if ( ! taploIns ) {
14
+ taploIns = await taplo . Taplo . initialize ( )
15
15
}
16
16
17
- return taplo . format ( code , { options } )
17
+ return taploIns . format ( code , { options } )
18
18
}
19
19
20
20
const TomlPlugin : Plugin < string > = {
21
21
languages,
22
22
parsers : {
23
23
[ 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 ( ) , {
30
26
...options ,
31
27
columnWidth : options . printWidth ,
32
- indentString,
28
+ indentString : options . useTabs ? '\t' : ' ' . repeat ( options . tabWidth ) ,
33
29
trailingNewline : true ,
34
30
arrayTrailingComma : options . trailingComma !== 'none' ,
35
31
crlf : options . endOfLine === 'crlf' ,
@@ -48,4 +44,7 @@ const TomlPlugin: Plugin<string> = {
48
44
options : prettierOptionsDefinitions ,
49
45
}
50
46
47
+ export type * from './options.js'
48
+ export type * from './types.js'
49
+
51
50
export default TomlPlugin
0 commit comments