Skip to content

Commit 85af9a9

Browse files
authored
feat(prettier-plugin-toml): migrate from @tombi-toml/wasm-lib to @tombi-toml/lib (#530)
1 parent f812a57 commit 85af9a9

6 files changed

Lines changed: 109 additions & 89 deletions

File tree

‎.changeset/tombi-native-lib.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"prettier-plugin-toml": major
3+
---
4+
5+
feat(prettier-plugin-toml)!: migrate from `@tombi-toml/wasm-lib` to [`@tombi-toml/lib`](https://www.npmjs.com/package/@tombi-toml/lib)
6+
7+
Tombi is now loaded through its prebuilt native Node.js binding instead of the
8+
WebAssembly build. The WASM loading shim is gone, so the plugin no longer has to
9+
resolve and read the ~6.6 MB `tombi_wasm_bg.wasm` file on first format, and the
10+
`@dual-bundle/import-meta-resolve` dependency is dropped.
11+
12+
- `@tombi-toml/lib` ships platform specific binaries (Linux, macOS and Windows
13+
on `x64`/`arm64`, including musl) as optional dependencies.
14+
- Node.js `v20.0.0` or later is required, matching the engine range declared by
15+
`@tombi-toml/lib`.
16+
17+
The exposed options, the configuration discovery and the formatting behaviour
18+
itself are unchanged.

‎packages/toml/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Of course it should just work, but may not match [prettier][]'s format sometimes
1313

1414
## Requirements
1515

16-
`prettier-plugin-toml` is an evergreen module. 🌲 This module requires an [LTS](https://github.com/nodejs/Release) Node version (v18.0.0+).
16+
`prettier-plugin-toml` is an evergreen module. 🌲 This module requires an [LTS](https://github.com/nodejs/Release) Node version (v20.0.0+).
1717

1818
## Install
1919

‎packages/toml/package.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"funding": "https://opencollective.com/unts",
1313
"license": "MIT",
1414
"engines": {
15-
"node": ">=18.0.0"
15+
"node": ">=20.0.0"
1616
},
1717
"main": "./lib/index.cjs",
1818
"types": "./index.d.cts",
@@ -41,8 +41,7 @@
4141
"prettier": "^3.0.3"
4242
},
4343
"dependencies": {
44-
"@dual-bundle/import-meta-resolve": "^4.2.1",
45-
"@tombi-toml/wasm-lib": "^1.5.5",
44+
"@tombi-toml/lib": "^1.8.4",
4645
"smol-toml": "^1.8.0"
4746
},
4847
"publishConfig": {

‎packages/toml/src/index.ts‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Diagnostic } from '@tombi-toml/wasm-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

@@ -11,23 +11,9 @@ import { discoverTombiConfig } from './discover.js'
1111
import { languages } from './languages.js'
1212
import { prettierOptionsDefinitions } from './options.js'
1313
import type { PrettierOptions } from './types.js'
14-
import { loadWasm } from './wasm.js'
1514

1615
const PLUGIN_NAME = 'toml'
1716

18-
type Tombi = typeof import('@tombi-toml/wasm-lib')
19-
20-
/**
21-
* The published `@tombi-toml/wasm-lib` type declaration re-exports
22-
* `./tombi_wasm` without a file extension, which `moduleResolution: node16`
23-
* cannot follow, so `initSync` is missing from the inferred module type.
24-
*/
25-
interface TombiWasmInit {
26-
initSync(module: { module: BufferSource | WebAssembly.Module }): unknown
27-
}
28-
29-
let tombiPromise: Promise<Tombi & TombiWasmInit> | undefined
30-
3117
/** Error thrown when Tombi reports one or more error level diagnostics. */
3218
class TombiFormatError extends SyntaxError {
3319
declare loc: { start: { line: number; column: number } }
@@ -45,20 +31,6 @@ class TombiFormatError extends SyntaxError {
4531
}
4632
}
4733

48-
/**
49-
* Lazily import and initialize the Tombi WASM module, reusing the same instance
50-
* for every subsequent format call.
51-
*/
52-
async function loadTombi(): Promise<Tombi & TombiWasmInit> {
53-
tombiPromise ??= (async () => {
54-
const tombi = (await import('@tombi-toml/wasm-lib')) as Tombi &
55-
TombiWasmInit
56-
tombi.initSync({ module: await loadWasm() })
57-
return tombi
58-
})()
59-
return tombiPromise
60-
}
61-
6234
/**
6335
* Build the Tombi configuration for a file, merging a discovered `tombi.toml`
6436
* (or `[tool.tombi]` in `pyproject.toml`) with the resolved Prettier options.
@@ -89,8 +61,6 @@ async function resolveConfig(options: PrettierOptions) {
8961
* {@link TombiFormatError} so Prettier can render them with a code frame.
9062
*/
9163
async function format(code: string, options: PrettierOptions) {
92-
const { format: formatToml } = await loadTombi()
93-
9464
const { formatted, diagnostics } = await formatToml(code, options.filepath, {
9565
config: await resolveConfig(options),
9666
})

‎packages/toml/src/wasm.ts‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎yarn.lock‎

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,13 +3034,6 @@ __metadata:
30343034
languageName: node
30353035
linkType: hard
30363036

3037-
"@dual-bundle/import-meta-resolve@npm:^4.2.1":
3038-
version: 4.2.1
3039-
resolution: "@dual-bundle/import-meta-resolve@npm:4.2.1"
3040-
checksum: 10c0/8f1e572c14c4d20ea35734635085213abd13bd440c251309cf8ae5ed1082f6759cefa1c2c52a631f76859c57e26062f78a8cee4acc239c0edc87cd316a5d3b5b
3041-
languageName: node
3042-
linkType: hard
3043-
30443037
"@emnapi/core@npm:1.10.0":
30453038
version: 1.10.0
30463039
resolution: "@emnapi/core@npm:1.10.0"
@@ -4893,10 +4886,92 @@ __metadata:
48934886
languageName: node
48944887
linkType: hard
48954888

4896-
"@tombi-toml/wasm-lib@npm:^1.5.5":
4897-
version: 1.5.5
4898-
resolution: "@tombi-toml/wasm-lib@npm:1.5.5"
4899-
checksum: 10c0/bec2dc1329c781cc486bb749826a2f16ae8bc7bb5cdd683efee3dd083b5fc2b970b7fa5ead12eedb2a7202e02c59a8e0aca6b787874e56c0a4202414783daaea
4889+
"@tombi-toml/lib-darwin-arm64@npm:1.8.4":
4890+
version: 1.8.4
4891+
resolution: "@tombi-toml/lib-darwin-arm64@npm:1.8.4"
4892+
conditions: os=darwin & cpu=arm64
4893+
languageName: node
4894+
linkType: hard
4895+
4896+
"@tombi-toml/lib-darwin-x64@npm:1.8.4":
4897+
version: 1.8.4
4898+
resolution: "@tombi-toml/lib-darwin-x64@npm:1.8.4"
4899+
conditions: os=darwin & cpu=x64
4900+
languageName: node
4901+
linkType: hard
4902+
4903+
"@tombi-toml/lib-linux-arm64-musl@npm:1.8.4":
4904+
version: 1.8.4
4905+
resolution: "@tombi-toml/lib-linux-arm64-musl@npm:1.8.4"
4906+
conditions: os=linux & cpu=arm64 & libc=musl
4907+
languageName: node
4908+
linkType: hard
4909+
4910+
"@tombi-toml/lib-linux-arm64@npm:1.8.4":
4911+
version: 1.8.4
4912+
resolution: "@tombi-toml/lib-linux-arm64@npm:1.8.4"
4913+
conditions: os=linux & cpu=arm64 & libc=glibc
4914+
languageName: node
4915+
linkType: hard
4916+
4917+
"@tombi-toml/lib-linux-x64-musl@npm:1.8.4":
4918+
version: 1.8.4
4919+
resolution: "@tombi-toml/lib-linux-x64-musl@npm:1.8.4"
4920+
conditions: os=linux & cpu=x64 & libc=musl
4921+
languageName: node
4922+
linkType: hard
4923+
4924+
"@tombi-toml/lib-linux-x64@npm:1.8.4":
4925+
version: 1.8.4
4926+
resolution: "@tombi-toml/lib-linux-x64@npm:1.8.4"
4927+
conditions: os=linux & cpu=x64 & libc=glibc
4928+
languageName: node
4929+
linkType: hard
4930+
4931+
"@tombi-toml/lib-win32-arm64@npm:1.8.4":
4932+
version: 1.8.4
4933+
resolution: "@tombi-toml/lib-win32-arm64@npm:1.8.4"
4934+
conditions: os=win32 & cpu=arm64
4935+
languageName: node
4936+
linkType: hard
4937+
4938+
"@tombi-toml/lib-win32-x64@npm:1.8.4":
4939+
version: 1.8.4
4940+
resolution: "@tombi-toml/lib-win32-x64@npm:1.8.4"
4941+
conditions: os=win32 & cpu=x64
4942+
languageName: node
4943+
linkType: hard
4944+
4945+
"@tombi-toml/lib@npm:^1.8.4":
4946+
version: 1.8.4
4947+
resolution: "@tombi-toml/lib@npm:1.8.4"
4948+
dependencies:
4949+
"@tombi-toml/lib-darwin-arm64": "npm:1.8.4"
4950+
"@tombi-toml/lib-darwin-x64": "npm:1.8.4"
4951+
"@tombi-toml/lib-linux-arm64": "npm:1.8.4"
4952+
"@tombi-toml/lib-linux-arm64-musl": "npm:1.8.4"
4953+
"@tombi-toml/lib-linux-x64": "npm:1.8.4"
4954+
"@tombi-toml/lib-linux-x64-musl": "npm:1.8.4"
4955+
"@tombi-toml/lib-win32-arm64": "npm:1.8.4"
4956+
"@tombi-toml/lib-win32-x64": "npm:1.8.4"
4957+
dependenciesMeta:
4958+
"@tombi-toml/lib-darwin-arm64":
4959+
optional: true
4960+
"@tombi-toml/lib-darwin-x64":
4961+
optional: true
4962+
"@tombi-toml/lib-linux-arm64":
4963+
optional: true
4964+
"@tombi-toml/lib-linux-arm64-musl":
4965+
optional: true
4966+
"@tombi-toml/lib-linux-x64":
4967+
optional: true
4968+
"@tombi-toml/lib-linux-x64-musl":
4969+
optional: true
4970+
"@tombi-toml/lib-win32-arm64":
4971+
optional: true
4972+
"@tombi-toml/lib-win32-x64":
4973+
optional: true
4974+
checksum: 10c0/a3f0fd3f2fef7ff593605fb9ecd0cf2f48e1387d51de5f1482c7e309d137c4fa857ae466f115485500a12f487c4507fad4933ec4e2c9a7fc09a2190ee06c8487
49004975
languageName: node
49014976
linkType: hard
49024977

@@ -13023,8 +13098,7 @@ __metadata:
1302313098
version: 0.0.0-use.local
1302413099
resolution: "prettier-plugin-toml@workspace:packages/toml"
1302513100
dependencies:
13026-
"@dual-bundle/import-meta-resolve": "npm:^4.2.1"
13027-
"@tombi-toml/wasm-lib": "npm:^1.5.5"
13101+
"@tombi-toml/lib": "npm:^1.8.4"
1302813102
smol-toml: "npm:^1.8.0"
1302913103
peerDependencies:
1303013104
prettier: ^3.0.3

0 commit comments

Comments
 (0)