From 151ac57a7360a5fd3b44236c5770fa85dfb77c5f Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 13 Oct 2023 01:30:34 +0800 Subject: [PATCH] Fix build --- packages/astro/components/Code.astro | 2 +- packages/astro/src/core/errors/dev/vite.ts | 2 +- .../{components/shiki.js => src/core/shiki.ts} | 17 ++++++----------- 3 files changed, 8 insertions(+), 13 deletions(-) rename packages/astro/{components/shiki.js => src/core/shiki.ts} (79%) diff --git a/packages/astro/components/Code.astro b/packages/astro/components/Code.astro index a502c6eaa4c2..281b16fb4018 100644 --- a/packages/astro/components/Code.astro +++ b/packages/astro/components/Code.astro @@ -8,7 +8,7 @@ import type { ThemeRegistrationRaw, } from 'shikiji'; import { visit } from 'unist-util-visit'; -import { getCachedHighlighter, replaceCssVariables } from './shiki.js'; +import { getCachedHighlighter, replaceCssVariables } from '../dist/core/shiki.js'; interface Props { /** The code to highlight. Required. */ diff --git a/packages/astro/src/core/errors/dev/vite.ts b/packages/astro/src/core/errors/dev/vite.ts index fd976e327a24..8705534a96ec 100644 --- a/packages/astro/src/core/errors/dev/vite.ts +++ b/packages/astro/src/core/errors/dev/vite.ts @@ -8,7 +8,7 @@ import { AstroError, type ErrorWithMetadata } from '../errors.js'; import { createSafeError } from '../utils.js'; import type { SSRLoadedRenderer } from './../../../@types/astro.js'; import { getDocsForError, renderErrorMarkdown } from './utils.js'; -import { replaceCssVariables } from '../../../../components/shiki.js'; +import { replaceCssVariables } from '../../shiki.js'; export function enhanceViteSSRError({ error, diff --git a/packages/astro/components/shiki.js b/packages/astro/src/core/shiki.ts similarity index 79% rename from packages/astro/components/shiki.js rename to packages/astro/src/core/shiki.ts index ecb53b86f6e8..4ce27c51d426 100644 --- a/packages/astro/components/shiki.js +++ b/packages/astro/src/core/shiki.ts @@ -1,7 +1,8 @@ -import { getHighlighter } from 'shikiji'; +import { type Highlighter, getHighlighter } from 'shikiji'; -/** @type {Record} */ -const ASTRO_COLOR_REPLACEMENTS = { +type HighlighterOptions = NonNullable[0]>; + +const ASTRO_COLOR_REPLACEMENTS: Record = { '#000001': 'var(--astro-code-color-text)', '#000002': 'var(--astro-code-color-background)', '#000004': 'var(--astro-code-token-constant)', @@ -24,18 +25,12 @@ const cachedHighlighters = new Map(); /** * shiki -> shikiji compat as we need to manually replace it - * @param {string} str */ -export function replaceCssVariables(str) { +export function replaceCssVariables(str: string) { return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match); } -/** - * - * @param {NonNullable[0]>} opts - * @returns {Promise} - */ -export function getCachedHighlighter(opts) { +export function getCachedHighlighter(opts: HighlighterOptions): Promise { // Always sort keys before stringifying to make sure objects match regardless of parameter ordering const key = JSON.stringify(opts, Object.keys(opts).sort());