Skip to content

Commit 7eb55ec

Browse files
authored
meta: export types for rehype-shiki (#8632)
* meta: export types for rehype-shiki * chore: some type changes * meta: for now remove compile from topo to fix current build * meta: fix prod dependencies * fix: tsx is required for tests * meta: fixed dependencies based on dependency-pinning.md
1 parent 7237dd3 commit 7eb55ec

File tree

13 files changed

+223
-598
lines changed

13 files changed

+223
-598
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"name": "Node.js Website Team and Contributors"
1414
},
1515
"scripts": {
16+
"compile": "turbo compile",
1617
"build": "turbo build",
1718
"cloudflare:deploy": "turbo cloudflare:deploy",
1819
"cloudflare:preview": "turbo cloudflare:preview",
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: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
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-
"./index.css": "./src/index.css",
8-
"./*": "./src/*.mjs"
7+
".": {
8+
"types": "./dist/index.d.mts",
9+
"default": "./src/index.mjs"
10+
},
11+
"./*": {
12+
"types": "./dist/*.d.mts",
13+
"default": "./src/*.mjs"
14+
},
15+
"./index.css": "./src/index.css"
916
},
1017
"repository": {
1118
"type": "git",
1219
"url": "https://github.com/nodejs/nodejs.org",
1320
"directory": "packages/rehype-shiki"
1421
},
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
},
@@ -28,9 +39,19 @@
2839
"classnames": "catalog:",
2940
"hast-util-to-string": "^3.0.1",
3041
"shiki": "~3.22.0",
42+
"typescript": "catalog:",
3143
"unist-util-visit": "^5.1.0"
3244
},
3345
"devDependencies": {
3446
"cross-env": "catalog:"
47+
},
48+
"imports": {
49+
"#rs/*": [
50+
"./src/*",
51+
"./src/*.mjs"
52+
]
53+
},
54+
"engines": {
55+
"node": ">=20"
3556
}
3657
}

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/rehype-shiki/turbo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"lint:fix": {
99
"cache": false
1010
},
11+
"lint:types": {
12+
"cache": false
13+
},
1114
"test:unit": {
1215
"inputs": ["src/**/*.mjs"]
1316
}

packages/ui-components/package.json

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,49 +44,48 @@
4444
},
4545
"dependencies": {
4646
"@heroicons/react": "^2.2.0",
47+
"@orama/core": "^1.2.16",
4748
"@orama/ui": "^1.5.4",
4849
"@radix-ui/react-avatar": "^1.1.11",
4950
"@radix-ui/react-dialog": "^1.1.15",
50-
"@radix-ui/react-dropdown-menu": "~2.1.16",
51-
"@radix-ui/react-label": "~2.1.8",
52-
"@radix-ui/react-select": "~2.2.6",
53-
"@radix-ui/react-separator": "~1.1.8",
54-
"@radix-ui/react-tabs": "~1.1.13",
55-
"@radix-ui/react-tooltip": "~1.2.8",
51+
"@radix-ui/react-dropdown-menu": "^2.1.16",
52+
"@radix-ui/react-label": "^2.1.8",
53+
"@radix-ui/react-select": "^2.2.6",
54+
"@radix-ui/react-separator": "^1.1.8",
55+
"@radix-ui/react-tabs": "^1.1.13",
56+
"@radix-ui/react-tooltip": "^1.2.8",
5657
"@tailwindcss/postcss": "~4.1.18",
58+
"@types/react": "catalog:",
5759
"@vcarl/remark-headings": "~0.1.0",
5860
"classnames": "catalog:",
59-
"postcss-calc": "^10.1.1",
60-
"tailwindcss": "catalog:"
61+
"postcss-cli": "11.0.1",
62+
"postcss-calc": "10.1.1",
63+
"react": "catalog:",
64+
"tailwindcss": "catalog:",
65+
"typescript": "catalog:"
6166
},
6267
"devDependencies": {
63-
"@orama/core": "^1.2.16",
64-
"@storybook/addon-styling-webpack": "^3.0.0",
65-
"@storybook/addon-themes": "^10.2.6",
66-
"@storybook/addon-webpack5-compiler-swc": "^4.0.2",
67-
"@storybook/react-webpack5": "^10.2.6",
68+
"@storybook/addon-styling-webpack": "~3.0.0",
69+
"@storybook/addon-themes": "~10.2.6",
70+
"@storybook/addon-webpack5-compiler-swc": "~4.0.2",
71+
"@storybook/react-webpack5": "~10.2.6",
6872
"@testing-library/user-event": "~14.6.1",
6973
"@types/node": "catalog:",
70-
"@types/react": "catalog:",
7174
"cross-env": "catalog:",
72-
"concurrently": "^8.2.2",
73-
"css-loader": "~7.1.2",
74-
"eslint-plugin-react": "~7.37.5",
75-
"eslint-plugin-react-hooks": "^7.0.1",
76-
"eslint-plugin-storybook": "~10.0.2",
77-
"global-jsdom": "^27.0.0",
78-
"postcss-cli": "^11.0.1",
79-
"postcss-loader": "~8.2.0",
80-
"react": "catalog:",
81-
"storybook": "^10.2.6",
82-
"style-loader": "~4.0.0",
83-
"stylelint": "^17.1.1",
84-
"stylelint-config-standard": "^40.0.0",
75+
"concurrently": "8.2.2",
76+
"css-loader": "7.1.2",
77+
"eslint-plugin-react": "7.37.5",
78+
"eslint-plugin-react-hooks": "7.0.1",
79+
"eslint-plugin-storybook": "10.0.7",
80+
"global-jsdom": "27.0.0",
81+
"postcss-loader": "8.2.0",
82+
"storybook": "~10.2.6",
83+
"style-loader": "4.0.0",
84+
"stylelint": "17.1.1",
85+
"stylelint-config-standard": "40.0.0",
8586
"stylelint-order": "7.0.1",
8687
"stylelint-selector-bem-pattern": "4.0.1",
87-
"tailwindcss": "catalog:",
88-
"tsx": "^4.21.0",
89-
"typescript": "catalog:"
88+
"tsx": "4.21.0"
9089
},
9190
"imports": {
9291
"#ui/*": {

0 commit comments

Comments
 (0)