From 97c9636e1a57441c45dda23d7115cce646c43255 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 14 Jan 2024 12:41:08 +0100 Subject: [PATCH] refactor!: remove deprecated APIs (#75) --- packages/shikiji-compat/src/index.ts | 3 +- packages/shikiji-core/src/index.ts | 4 +-- packages/shikiji-core/src/internal.ts | 5 ---- packages/shikiji-core/src/normalize.ts | 5 ---- packages/shikiji-core/src/renderer-hast.ts | 6 ---- packages/shikiji-core/src/types.ts | 5 ---- .../shikiji-twoslash/src/renderer-rich.ts | 1 - packages/shikiji/test/hast.test.ts | 29 ------------------- .../src/renderer-floating-vue.ts | 2 -- tsconfig.json | 2 ++ 10 files changed, 6 insertions(+), 56 deletions(-) diff --git a/packages/shikiji-compat/src/index.ts b/packages/shikiji-compat/src/index.ts index 81d4bb2cf..f308589e6 100644 --- a/packages/shikiji-compat/src/index.ts +++ b/packages/shikiji-compat/src/index.ts @@ -11,7 +11,8 @@ export const BUNDLED_THEMES = bundledThemes export * from './stub' export * from './types' -export { toShikiTheme } from 'shikiji' +export { normalizeTheme } from 'shikiji' +export { normalizeTheme as toShikiTheme } from 'shikiji' export async function getHighlighter(options: HighlighterOptions = {}) { const themes = options.themes || [] diff --git a/packages/shikiji-core/src/index.ts b/packages/shikiji-core/src/index.ts index 6d1eb7c06..3b228c892 100644 --- a/packages/shikiji-core/src/index.ts +++ b/packages/shikiji-core/src/index.ts @@ -4,10 +4,10 @@ export * from './utils' export * from './types' export { loadWasm } from './oniguruma' -export { getShikiInternal, getShikiContext } from './internal' +export { getShikiInternal } from './internal' export { codeToThemedTokens } from './tokenizer' export { tokenizeAnsiWithTheme } from './tokenizer-ansi' export { codeToHast } from './renderer-hast' export { codeToHtml } from './renderer-html' export { codeToTokensWithThemes } from './renderer-html-themes' -export { normalizeTheme, toShikiTheme } from './normalize' +export { normalizeTheme } from './normalize' diff --git a/packages/shikiji-core/src/internal.ts b/packages/shikiji-core/src/internal.ts index d4ca99227..456eb7c72 100644 --- a/packages/shikiji-core/src/internal.ts +++ b/packages/shikiji-core/src/internal.ts @@ -110,8 +110,3 @@ export async function getShikiInternal(options: HighlighterCoreOptions = {}): Pr loadTheme, } } - -/** - * @deprecated Use `getShikiInternal` instead. - */ -export const getShikiContext = getShikiInternal diff --git a/packages/shikiji-core/src/normalize.ts b/packages/shikiji-core/src/normalize.ts index c63917f11..eaced2e25 100644 --- a/packages/shikiji-core/src/normalize.ts +++ b/packages/shikiji-core/src/normalize.ts @@ -136,8 +136,3 @@ export function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistratio return theme } - -/** - * @deprecated Use `normalizeTheme` instead. - */ -export const toShikiTheme = normalizeTheme diff --git a/packages/shikiji-core/src/renderer-hast.ts b/packages/shikiji-core/src/renderer-hast.ts index 11785ecfa..091701ae1 100644 --- a/packages/shikiji-core/src/renderer-hast.ts +++ b/packages/shikiji-core/src/renderer-hast.ts @@ -151,12 +151,6 @@ export function tokensToHast( transformers = [], } = options - // TODO: remove this in next major version - if (options.transforms) { - transformers.push(options.transforms) - console.warn('[shikiji] `transforms` option is deprecated, use `transformers` instead') - } - if (mergeWhitespaces === true) tokens = mergeWhitespaceTokens(tokens) else if (mergeWhitespaces === 'never') diff --git a/packages/shikiji-core/src/types.ts b/packages/shikiji-core/src/types.ts index 7fd9c11ca..7578823dc 100644 --- a/packages/shikiji-core/src/types.ts +++ b/packages/shikiji-core/src/types.ts @@ -349,11 +349,6 @@ export interface TransformerOptions { * Transformers for the Shikiji pipeline. */ transformers?: ShikijiTransformer[] - - /** - * @deprecated use `transformers` instead - */ - transforms?: ShikijiTransformer } export type CodeToHastOptions = diff --git a/packages/shikiji-twoslash/src/renderer-rich.ts b/packages/shikiji-twoslash/src/renderer-rich.ts index 7536e402e..6c38df25e 100644 --- a/packages/shikiji-twoslash/src/renderer-rich.ts +++ b/packages/shikiji-twoslash/src/renderer-rich.ts @@ -92,7 +92,6 @@ export function rendererRich(options: RendererRichOptions = {}): TwoSlashRendere ...shikijiOptions, lang: options.lang || shikijiOptions.lang, transformers: [], - transforms: undefined, }).children[0] as Element).children[0] as Element).children if (jsdoc && info.docs) { diff --git a/packages/shikiji/test/hast.test.ts b/packages/shikiji/test/hast.test.ts index 14de3a794..8f0264815 100644 --- a/packages/shikiji/test/hast.test.ts +++ b/packages/shikiji/test/hast.test.ts @@ -22,35 +22,6 @@ describe('should', () => { foo.bar" `) }) - - it('hast transformer', async () => { - const warn = vi.spyOn(console, 'warn') - warn.mockImplementation((() => {}) as any) - - const code = await codeToHtml('foo\bar', { - lang: 'js', - theme: 'vitesse-light', - // Use deprecated `transforms` option on purpose to test - transforms: { - line(node, line) { - node.properties['data-line'] = line - }, - code(node) { - node.properties.class = 'language-js' - }, - token(node, line, col) { - node.properties.class = `token:${line}:${col}` - }, - }, - }) - - expect(code) - .toMatchInlineSnapshot(`"
fooar
"`) - - expect(warn).toBeCalledTimes(1) - expect(warn.mock.calls[0][0]) - .toMatchInlineSnapshot('"[shikiji] `transforms` option is deprecated, use `transformers` instead"') - }) }) it('hasfocus support', async () => { diff --git a/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts b/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts index d3223fd27..45b460336 100644 --- a/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts +++ b/packages/vitepress-plugin-twoslash/src/renderer-floating-vue.ts @@ -32,7 +32,6 @@ export function rendererFloatingVue(options: VitePressPluginTwoSlashOptions & Re { ...this.options, transformers: [], - transforms: undefined, }, ).children[0] as Element).children as Element[] @@ -56,7 +55,6 @@ export function rendererFloatingVue(options: VitePressPluginTwoSlashOptions & Re { ...this.options, transformers: [], - transforms: undefined, lang, }, ).children[0] as Element diff --git a/tsconfig.json b/tsconfig.json index 95590016b..b0dbef027 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,8 @@ "shikiji/wasm": ["./packages/shikiji/src/wasm.ts"], "shikiji/langs": ["./packages/shikiji/src/langs.ts"], "shikiji/themes": ["./packages/shikiji/src/themes.ts"], + "shikiji/bundle/web": ["./packages/shikiji/src/bundle-web.ts"], + "shikiji/bundle/full": ["./packages/shikiji/src/bundle-full.ts"], "shikiji": ["./packages/shikiji/src/index.ts"], "markdown-it-shikiji": ["./packages/markdown-it-shikiji/src/index.ts"] },