Skip to content

Commit 6550a6b

Browse files
committed
meta: export types for rehype-shiki
1 parent fa01ac6 commit 6550a6b

File tree

9 files changed

+82
-21
lines changed

9 files changed

+82
-21
lines changed
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
export { default } from '../../eslint.config.js';
1+
import baseConfig from '../../eslint.config.js';
2+
3+
export default baseConfig.concat([
4+
{
5+
files: ['src'],
6+
ignores: ['**/*.test.*', '**/*.stories.tsx'],
7+
languageOptions: {
8+
parserOptions: {
9+
project: './tsconfig.json',
10+
tsconfigRootDir: import.meta.dirname,
11+
},
12+
},
13+
rules: {
14+
'@typescript-eslint/consistent-type-imports': 'error',
15+
},
16+
},
17+
]);

packages/rehype-shiki/package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"name": "@node-core/rehype-shiki",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"type": "module",
5+
"types": "./dist/index.d.mts",
56
"exports": {
6-
".": "./src/index.mjs",
7+
".": {
8+
"types": "./dist/index.d.mts",
9+
"default": "./src/index.mjs"
10+
},
711
"./index.css": "./src/index.css",
812
"./*": "./src/*.mjs"
913
},
@@ -12,11 +16,18 @@
1216
"url": "https://github.com/nodejs/nodejs.org",
1317
"directory": "packages/rehype-shiki"
1418
},
19+
"imports": {
20+
"#rs/*": "./src/*"
21+
},
1522
"scripts": {
23+
"compile:ts": "tsc",
24+
"compile": "node --run compile:ts",
25+
"release": "node --run compile",
1626
"lint": "node --run lint:js",
1727
"lint:fix": "node --run lint:js:fix",
1828
"lint:js": "eslint \"**/*.mjs\"",
1929
"lint:js:fix": "node --run lint:js -- --fix",
30+
"lint:types": "tsc --noEmit",
2031
"test": "node --run test:unit",
2132
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --experimental-test-coverage --experimental-test-module-mocks --test \"**/*.test.mjs\""
2233
},
@@ -31,6 +42,7 @@
3142
"unist-util-visit": "^5.1.0"
3243
},
3344
"devDependencies": {
34-
"cross-env": "catalog:"
45+
"cross-env": "catalog:",
46+
"typescript": "catalog:"
3547
}
3648
}

packages/rehype-shiki/src/highlighter.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const DEFAULT_THEME = {
99
...shikiNordTheme,
1010
};
1111

12+
/**
13+
* @template {{ name: string; aliases?: string[] }} T
14+
* @param {string} language
15+
* @param {ReadonlyArray<T>} langs
16+
* @returns {T | undefined}
17+
*/
1218
export const getLanguageByName = (language, langs) => {
1319
const normalized = language.toLowerCase();
1420

@@ -20,7 +26,7 @@ export const getLanguageByName = (language, langs) => {
2026

2127
/**
2228
* @typedef {Object} SyntaxHighlighter
23-
* @property {import('@shikijs/core').HighlighterCoreSync} shiki - The underlying shiki core instance.
29+
* @property {import('@shikijs/core').HighlighterCore} shiki - The underlying shiki core instance.
2430
* @property {(code: string, lang: string, meta?: Record<string, any>) => string} highlightToHtml - Highlights code and returns inner HTML of the <code> tag.
2531
* @property {(code: string, lang: string, meta?: Record<string, any>) => any} highlightToHast - Highlights code and returns a HAST tree.
2632
*/

packages/rehype-shiki/src/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import shellSessionLanguage from 'shiki/langs/shellsession.mjs';
1414
import typeScriptLanguage from 'shiki/langs/typescript.mjs';
1515
import yamlLanguage from 'shiki/langs/yaml.mjs';
1616

17-
import createHighlighter, { getLanguageByName } from './highlighter.mjs';
17+
import createHighlighter, { getLanguageByName } from '#rs/highlighter.mjs';
1818

1919
/**
2020
* @typedef {Object} HighlighterOptions
@@ -48,7 +48,7 @@ async function getTransformers({ twoslash = false, twoslashOptions }) {
4848
const transformers = [];
4949

5050
if (twoslash) {
51-
const { twoslash } = await import('./transformers/twoslash/index.mjs');
51+
const { twoslash } = await import('#rs/transformers/twoslash/index.mjs');
5252
transformers.push(twoslash(twoslashOptions));
5353
}
5454

packages/rehype-shiki/src/minimal.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript';
22
import powershellLanguage from 'shiki/langs/powershell.mjs';
33
import shellScriptLanguage from 'shiki/langs/shellscript.mjs';
44

5-
import createHighlighter, { getLanguageByName } from './highlighter.mjs';
5+
import createHighlighter, { getLanguageByName } from '#rs/highlighter.mjs';
66

77
export const LANGS = [...powershellLanguage, ...shellScriptLanguage];
88

packages/rehype-shiki/src/plugin.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import classNames from 'classnames';
44
import { toString } from 'hast-util-to-string';
55
import { SKIP, visit } from 'unist-util-visit';
66

7-
import createHighlighter from './index.mjs';
7+
import createHighlighter from '#rs/index.mjs';
88

99
// This is what Remark will use as prefix within a <pre> className
1010
// to attribute the current language of the <pre> element
@@ -54,7 +54,7 @@ function isCodeBlock(node) {
5454
}
5555

5656
/**
57-
* @param {import('./index.mjs').HighlighterOptions & { highlighter: import('./highlighter.mjs').SyntaxHighlighter }} options
57+
* @param {import('#rs/index.mjs').HighlighterOptions & { highlighter: import('#rs/highlighter.mjs').SyntaxHighlighter }} options
5858
*/
5959
export default async function rehypeShikiji(options) {
6060
const highlighter =
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"esModuleInterop": true,
10+
"module": "esnext",
11+
"moduleResolution": "bundler",
12+
"resolveJsonModule": true,
13+
"jsx": "react-jsx",
14+
"declaration": true,
15+
"emitDeclarationOnly": true,
16+
"baseUrl": "./src",
17+
"rootDir": "./src",
18+
"outDir": "./dist"
19+
},
20+
"include": ["src"],
21+
"exclude": ["**/*.test.*", "**/*.stories.tsx"]
22+
}

packages/ui-components/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"isolatedModules": true,
1515
"jsx": "react-jsx",
1616
"declaration": true,
17-
"incremental": true,
1817
"baseUrl": "./src",
1918
"rootDir": "./src",
2019
"outDir": "./dist"

pnpm-lock.yaml

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)