Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 12, 2023
1 parent 653080d commit 151ac57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/astro/components/Code.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/errors/dev/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getHighlighter } from 'shikiji';
import { type Highlighter, getHighlighter } from 'shikiji';

/** @type {Record<string, string>} */
const ASTRO_COLOR_REPLACEMENTS = {
type HighlighterOptions = NonNullable<Parameters<typeof getHighlighter>[0]>;

const ASTRO_COLOR_REPLACEMENTS: Record<string, string> = {
'#000001': 'var(--astro-code-color-text)',
'#000002': 'var(--astro-code-color-background)',
'#000004': 'var(--astro-code-token-constant)',
Expand All @@ -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<Parameters<typeof getHighlighter>[0]>} opts
* @returns {Promise<import('shikiji').Highlighter>}
*/
export function getCachedHighlighter(opts) {
export function getCachedHighlighter(opts: HighlighterOptions): Promise<Highlighter> {
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
const key = JSON.stringify(opts, Object.keys(opts).sort());

Expand Down

0 comments on commit 151ac57

Please sign in to comment.