Skip to content

Commit aeede54

Browse files
committed
refactor(prettier-plugin-toml): import the tombi binding directly
`@tombi-toml/lib` is CommonJS, so the ESM build and the CJS build can both import it the ordinary way. The dynamic `import()` was only ever needed because `@tombi-toml/wasm-lib` is ESM-only -- its `exports` map has no `require` condition -- so the CommonJS bundle could not load it at all. This also drops the promise cache and the `typeof import()` alias.
1 parent 74b6650 commit aeede54

1 file changed

Lines changed: 1 addition & 17 deletions

File tree

‎packages/toml/src/index.ts‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Diagnostic } from '@tombi-toml/lib'
1+
import { type Diagnostic, format as formatToml } from '@tombi-toml/lib'
22
import type { Plugin } from 'prettier'
33
import { stringify } from 'smol-toml'
44

@@ -14,10 +14,6 @@ import type { PrettierOptions } from './types.js'
1414

1515
const PLUGIN_NAME = 'toml'
1616

17-
type Tombi = typeof import('@tombi-toml/lib')
18-
19-
let tombiPromise: Promise<Tombi> | undefined
20-
2117
/** Error thrown when Tombi reports one or more error level diagnostics. */
2218
class TombiFormatError extends SyntaxError {
2319
declare loc: { start: { line: number; column: number } }
@@ -35,16 +31,6 @@ class TombiFormatError extends SyntaxError {
3531
}
3632
}
3733

38-
/**
39-
* Lazily import the Tombi native module, reusing the same instance for every
40-
* subsequent format call. The import is deferred so that merely loading the
41-
* Prettier plugin does not require the platform specific binary to be present.
42-
*/
43-
async function loadTombi(): Promise<Tombi> {
44-
tombiPromise ??= import('@tombi-toml/lib')
45-
return tombiPromise
46-
}
47-
4834
/**
4935
* Build the Tombi configuration for a file, merging a discovered `tombi.toml`
5036
* (or `[tool.tombi]` in `pyproject.toml`) with the resolved Prettier options.
@@ -75,8 +61,6 @@ async function resolveConfig(options: PrettierOptions) {
7561
* {@link TombiFormatError} so Prettier can render them with a code frame.
7662
*/
7763
async function format(code: string, options: PrettierOptions) {
78-
const { format: formatToml } = await loadTombi()
79-
8064
const { formatted, diagnostics } = await formatToml(code, options.filepath, {
8165
config: await resolveConfig(options),
8266
})

0 commit comments

Comments
 (0)