Skip to content

Commit

Permalink
feat: rename createWasmOnigEngine to createOnigurumaEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 26, 2024
1 parent 73a9585 commit 2335dda
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 26 deletions.
4 changes: 2 additions & 2 deletions bench/engines.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import type { BundledLanguage } from 'shiki'
import type { ReportItem } from '../scripts/report-engine-js-compat'
import fs from 'node:fs/promises'
import { createHighlighter, createJavaScriptRegexEngine, createWasmOnigEngine } from 'shiki'
import { createHighlighter, createJavaScriptRegexEngine, createOnigurumaEngine } from 'shiki'
import { bench, describe } from 'vitest'

const js = createJavaScriptRegexEngine()
const wasm = await createWasmOnigEngine(() => import('shiki/wasm'))
const wasm = await createOnigurumaEngine(() => import('shiki/wasm'))

const RANGE = [0, 20]

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const highlighter = await createHighlighterCore({
async () => JSON.parse(await fs.readFile('my-grammar.json', 'utf-8'))
],
// `shiki/wasm` contains the wasm binary inlined as base64 string.
engine: createWasmOnigEngine(import('shiki/wasm'))
engine: createOnigurumaEngine(import('shiki/wasm'))
})

// optionally, load themes and languages after creation
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/future.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ import { loadWasm } from 'shiki/engine/oniguruma' // [!code ++]
```ts
import { createHighlighter } from 'shiki'
import { createWasmOnigEngine } from 'shiki/engine/oniguruma' // [!code ++]
import { createOnigurumaEngine } from 'shiki/engine/oniguruma' // [!code ++]
const shiki = await createHighlighter({
// ...
loadWasm: () => import('shiki/wasm'), // [!code --]
engine: createWasmOnigEngine(() => import('shiki/wasm')), // [!code ++]
engine: createOnigurumaEngine(() => import('shiki/wasm')), // [!code ++]
})
```
4 changes: 2 additions & 2 deletions docs/guide/regex-engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ This is the default engine that uses the compiled Oniguruma WebAssembly. The mos

```ts
import { createHighlighter } from 'shiki'
import { createWasmOnigEngine } from 'shiki/engine/oniguruma'
import { createOnigurumaEngine } from 'shiki/engine/oniguruma'

const shiki = await createShiki({
themes: ['nord'],
langs: ['javascript'],
engine: createWasmOnigEngine(import('shiki/wasm'))
engine: createOnigurumaEngine(import('shiki/wasm'))
})
```

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/sync-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ The [Oniguruma Engine](/guide/regex-engines#oniguruma-engine) can only be create

```ts
import { createHighlighterCoreSync } from 'shiki/core'
import { createWasmOnigEngine } from 'shiki/engine/oniguruma'
import { createOnigurumaEngine } from 'shiki/engine/oniguruma'
import js from 'shiki/langs/javascript.mjs'
import nord from 'shiki/themes/nord.mjs'

// Load this somewhere beforehand
const engine = await createWasmOnigEngine(import('shiki/wasm'))
const engine = await createOnigurumaEngine(import('shiki/wasm'))

const shiki = createHighlighterCoreSync({
themes: [nord],
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/constructors/bundle-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
import type { Root } from 'hast'
import { ShikiError } from '@shikijs/types'

import { createWasmOnigEngine } from '../engines/oniguruma'
import { createOnigurumaEngine } from '../engines/oniguruma'
import { isSpecialLang, isSpecialTheme } from '../utils'
import { warnDeprecated } from '../warn'
import { createHighlighterCore } from './highlighter'
Expand All @@ -43,7 +43,7 @@ import { createHighlighterCore } from './highlighter'
* nord: () => import('shiki/themes/nord.mjs'),
* // ...
* },
* engine: () => createWasmOnigEngine(), // or createJavaScriptRegexEngine()
* engine: () => createOnigurumaEngine(), // or createJavaScriptRegexEngine()
* })
* ```
*
Expand Down Expand Up @@ -78,7 +78,7 @@ export function createdBundledHighlighter<BundledLangs extends string, BundledTh
warnDeprecated('`createdBundledHighlighter` signature with `bundledLanguages` and `bundledThemes` is deprecated. Use the options object signature instead.')
bundledLanguages = arg1 as Record<BundledLangs, LanguageInput>
bundledThemes = arg2
engine = () => createWasmOnigEngine(arg3)
engine = () => createOnigurumaEngine(arg3)
}
else {
const options = arg1 as CreatedBundledHighlighterOptions<BundledLangs, BundledThemes>
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/constructors/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
HighlighterCoreOptions,
ShikiInternal,
} from '@shikijs/types'
import { createWasmOnigEngine, getDefaultWasmLoader } from '@shikijs/engine-oniguruma'
import { createOnigurumaEngine, getDefaultWasmLoader } from '@shikijs/engine-oniguruma'

import { resolveLangs, resolveThemes } from '../textmate/getters-resolve'
import { warnDeprecated } from '../warn'
Expand All @@ -13,7 +13,7 @@ import { createShikiInternalSync } from './internal-sync'
*/
export async function createShikiInternal(options: HighlighterCoreOptions = {}): Promise<ShikiInternal> {
if (options.loadWasm) {
warnDeprecated('`loadWasm` option is deprecated. Use `engine: createWasmOnigEngine(loadWasm)` instead.')
warnDeprecated('`loadWasm` option is deprecated. Use `engine: createOnigurumaEngine(loadWasm)` instead.')
}

const [
Expand All @@ -23,7 +23,7 @@ export async function createShikiInternal(options: HighlighterCoreOptions = {}):
] = await Promise.all([
resolveThemes(options.themes || []),
resolveLangs(options.langs || []),
(options.engine || createWasmOnigEngine(options.loadWasm || getDefaultWasmLoader())),
(options.engine || createOnigurumaEngine(options.loadWasm || getDefaultWasmLoader())),
] as const)

return createShikiInternalSync({
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/engines/oniguruma.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import type { LoadWasmOptions, RegexEngine } from '@shikijs/types'
import {
createWasmOnigEngine as _createWasmOnigEngine,
createOnigurumaEngine as _createOnigurumaEngine,
loadWasm as _loadWasm,
} from '@shikijs/engine-oniguruma'
import { warnDeprecated } from '../warn'

export function createOnigurumaEngine(options?: LoadWasmOptions | null): Promise<RegexEngine> {
warnDeprecated('import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead')
return _createOnigurumaEngine(options)
}

export function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine> {
warnDeprecated('import `createWasmOnigEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead')
return _createWasmOnigEngine(options)
warnDeprecated('import `createOnigurumaEngine` from `@shikijs/engine-oniguruma` or `shiki/engine/oniguruma` instead')
return createOnigurumaEngine(options)
}

export function loadWasm(options: LoadWasmOptions): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { createShikiInternalSync } from './constructors/internal-sync'

// Engines
export { createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor } from './engines/javascript'
export { createWasmOnigEngine, loadWasm } from './engines/oniguruma'
export { createOnigurumaEngine, createWasmOnigEngine, loadWasm } from './engines/oniguruma'

// Low-level Highlighting
export { codeToHast, tokensToHast } from './highlight/code-to-hast'
Expand Down
9 changes: 8 additions & 1 deletion packages/engine-oniguruma/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function getDefaultWasmLoader(): LoadWasmOptions | undefined {
return _defaultWasmLoader
}

export async function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine> {
export async function createOnigurumaEngine(options?: LoadWasmOptions | null): Promise<RegexEngine> {
if (options)
await loadWasm(options)

Expand All @@ -34,3 +34,10 @@ export async function createWasmOnigEngine(options?: LoadWasmOptions | null): Pr
},
}
}

/**
* Deprecated. Use `createOnigurumaEngine` instead.
*/
export async function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine> {
return createOnigurumaEngine(options)
}
5 changes: 3 additions & 2 deletions packages/shiki/src/bundle-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type {} from 'hast'
import type { BundledLanguage } from './assets/langs-bundle-full'
import type { BundledTheme } from './themes'
import { bundledLanguages } from './assets/langs-bundle-full'
import { createdBundledHighlighter, createSingletonShorthands, createWasmOnigEngine, warnDeprecated } from './core'
import { createdBundledHighlighter, createSingletonShorthands, warnDeprecated } from './core'
import { createOnigurumaEngine } from './engine-oniguruma'
import { bundledThemes } from './themes'
import { getWasmInlined } from './wasm-dynamic'

Expand Down Expand Up @@ -31,7 +32,7 @@ export const createHighlighter = /* @__PURE__ */ createdBundledHighlighter<
>({
langs: bundledLanguages,
themes: bundledThemes,
engine: () => createWasmOnigEngine(getWasmInlined),
engine: () => createOnigurumaEngine(getWasmInlined),
})

export const {
Expand Down
6 changes: 3 additions & 3 deletions packages/shiki/src/bundle-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {} from 'hast'
import type { BundledLanguage } from './assets/langs-bundle-web'
import type { BundledTheme } from './themes'
import { bundledLanguages } from './assets/langs-bundle-web'

import { createdBundledHighlighter, createSingletonShorthands, createWasmOnigEngine, warnDeprecated } from './core'
import { createdBundledHighlighter, createSingletonShorthands, warnDeprecated } from './core'
import { createOnigurumaEngine } from './engine-oniguruma'
import { bundledThemes } from './themes'
import { getWasmInlined } from './wasm-dynamic'

Expand Down Expand Up @@ -33,7 +33,7 @@ export const createHighlighter = /* @__PURE__ */ createdBundledHighlighter<
>({
langs: bundledLanguages,
themes: bundledThemes,
engine: () => createWasmOnigEngine(getWasmInlined),
engine: () => createOnigurumaEngine(getWasmInlined),
})

export const {
Expand Down
3 changes: 3 additions & 0 deletions packages/shiki/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ export type { CssVariablesThemeOptions } from './theme-css-variables'

export { createCssVariablesTheme } from './theme-css-variables'
export * from '@shikijs/core'

export { createJavaScriptRegexEngine } from '@shikijs/engine-javascript'
export { createOnigurumaEngine, loadWasm } from '@shikijs/engine-oniguruma'
2 changes: 1 addition & 1 deletion packages/types/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface HighlighterCoreOptions<Sync extends boolean = false> {
/**
* Load wasm file from a custom path or using a custom function.
*
* @deprecated Use `engine: createWasmOnigEngine(loadWasm)` instead.
* @deprecated Use `engine: createOnigurumaEngine(loadWasm)` instead.
*/
loadWasm?: Sync extends true ? never : LoadWasmOptions
}
Expand Down

0 comments on commit 2335dda

Please sign in to comment.