|
| 1 | +# Future |
| 2 | + |
| 3 | +We planned to remove some deprecated APIs and optimize the tree-shaking in the future major versions. |
| 4 | + |
| 5 | +The plan is: |
| 6 | + |
| 7 | +- 👉 `v1.x`: Deprecated APIs are still supported, marked on type level only. With optional runtime warnings to opt-in. |
| 8 | +- `v2.0`: No breaking changes, but enable runtime deprecated warnings by default. |
| 9 | +- `v3.0`: Remove deprecated APIs, breaking changes. |
| 10 | + |
| 11 | +At the current version, since v1.19.0, you can opt-in to the runtime warnings by calling `enableDeprecationWarnings()` at the beginning of your application. |
| 12 | + |
| 13 | +```ts |
| 14 | +import { enableDeprecationWarnings, getHighlighter } from 'shiki' |
| 15 | + |
| 16 | +enableDeprecationWarnings() // [!code hl] |
| 17 | + |
| 18 | +// Then calling deprecated usages like below would warn: |
| 19 | +// [SHIKI DEPRECATED]: Use `createHighlighter` instead |
| 20 | +const shiki = await getHighlighter(/* ... */) |
| 21 | +``` |
| 22 | + |
| 23 | +This would help you better prepare for the future changes and upgrade smoothly. |
| 24 | + |
| 25 | +## Notable Deprecations |
| 26 | + |
| 27 | +### `getHighlighter` -> `createHighlighter` |
| 28 | + |
| 29 | +There is no functional changes, but more like correcting the naming to avoid confusion. It should be a straightforward find-and-replace. |
| 30 | + |
| 31 | +### WASM Related APIs |
| 32 | + |
| 33 | +Since the introduce of the [engine system](/guide/regex-engines) in v0.16, the WebAssembly related dependencies are no longer a hard requirement. To make tree-shaking easier and decoupled the engines with the core, two packages are extracted `@shikijs/engine-oniguruma` and `@shikijs/engine-javascript`. They are also re-exported from the main package's `shiki/engine/oniguruma` and `shiki/engine/javascript` respectively. |
| 34 | + |
| 35 | +You might need to change your import path: |
| 36 | + |
| 37 | +```ts |
| 38 | +import { loadWasm } from 'shiki' // [!code --] |
| 39 | +import { loadWasm } from 'shiki/engine/oniguruma' // [!code ++] |
| 40 | +``` |
| 41 | +
|
| 42 | +`loadWasm` field in `getHighlighter` is replaced with `engine` field: |
| 43 | +
|
| 44 | +```ts |
| 45 | +import { createHighlighter } from 'shiki' |
| 46 | +import { createWasmOnigEngine } from 'shiki/engine/oniguruma' // [!code ++] |
| 47 | +
|
| 48 | +const shiki = await createHighlighter({ |
| 49 | + // ... |
| 50 | + loadWasm: () => import('shiki/wasm'), // [!code --] |
| 51 | + engine: createWasmOnigEngine(() => import('shiki/wasm')), // [!code ++] |
| 52 | +}) |
| 53 | +``` |
0 commit comments