npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cmshiki/shiki

v0.2.0

Published

use shiki to highlight code in CodeMirror

Readme

@cmshiki/shiki

把 Shiki 高亮能力接到 CodeMirror 6 的底层扩展包。

安装

pnpm add @cmshiki/shiki

Peer 依赖:

pnpm add @codemirror/state @codemirror/view shiki

快速开始

import { EditorView } from "@codemirror/view";
import { shikiToCodeMirror } from "@cmshiki/shiki";

const { shiki } = await shikiToCodeMirror({
  lang: "typescript",
  themes: {
    light: "github-light",
    dark: "github-dark",
  },
  defaultColor: "light",
  themeStyle: "cm",
  engine: "oniguruma", // or "javascript"
});

new EditorView({
  parent: document.getElementById("editor")!,
  doc: "const n: number = 1;",
  extensions: [shiki],
});

主题切换

import { themeCompartment } from "@cmshiki/shiki";

const { shiki, getTheme } = await shikiToCodeMirror({
  lang: "javascript",
  themes: { light: "github-light", dark: "github-dark" },
});

// ...创建 EditorView 后
view.dispatch({
  effects: themeCompartment.reconfigure(getTheme("dark", view)),
});

主要配置

shikiToCodeMirror(options) 支持以下常用字段:

  • lang:语言名或自定义 language 输入
  • theme:单主题简写;当未传 themes 时,会映射到 themes.light
  • themes:多主题映射对象,支持 light / dark 及任意别名(推荐)
  • defaultColor:初始主题键,必须是 themes 的 key,默认 light
  • themeStyle"cm""shiki",默认 "cm"
  • engine
    • "oniguruma"(默认):兼容性更高
    • "javascript":启动更快
    • 自定义 RegexEngine
  • highlighter:预初始化的 Shiki highlighter(传入后跳过内部初始化)

theme / themes / defaultColor 关系说明

1) 三者职责

  • theme:单主题输入,适合只需要一个主题的场景。
  • themes:主题注册表,键是业务侧可切换的“主题键”(例如 light / dark / nord),值是 Shiki 主题名或主题对象。
  • defaultColor:初始主题键,只在 themes 的键空间内生效。

2) 推荐规则

  • 只用单主题:传 theme,不传 themes / defaultColor
  • 需要主题切换:只用 themes + defaultColor,不再传 theme
  • defaultColor 必须指向 themes 中存在的 key(例如 dark)。
  • 如果 defaultColor 非法,库会告警并自动回退到可用 key(优先 dark、其次 light,否则第一个 key)。

3) 推荐示例(可切换)

const { shiki, getTheme } = await shikiToCodeMirror({
  lang: "javascript",
  themes: {
    light: "github-light",
    dark: "github-dark",
    nord: "nord",
  },
  defaultColor: "dark",
  themeStyle: "cm",
  engine: "javascript",
});

4) 单主题示例(不切换)

const { shiki } = await shikiToCodeMirror({
  lang: "javascript",
  theme: "github-dark",
  themeStyle: "cm",
  engine: "javascript",
});

预初始化 highlighter(推荐多编辑器场景)

import { createHighlighterCore } from "shiki/core";
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
import { shikiToCodeMirror } from "@cmshiki/shiki";

const highlighter = await createHighlighterCore({
  themes: [import("@shikijs/themes/github-dark")],
  langs: [import("@shikijs/langs/javascript")],
  engine: createJavaScriptRegexEngine(),
});

const { shiki } = await shikiToCodeMirror({
  highlighter,
  lang: "javascript",
  themes: { dark: "github-dark", light: "github-light" },
});

导出 API

export async function shikiToCodeMirror(options: Options): Promise<{
  shiki: Extension;
  getTheme: (name?: string, view?: EditorView) => Extension;
}>;

export class ShikiHighlighter {}
export const updateEffect: StateEffect<Partial<Options>>;
export const themeCompartment: Compartment;
export const configsFacet: Facet<ShikiToCMOptions, ShikiToCMOptions>;