Skip to content

Commit 259db02

Browse files
authored
chore(monorepo): rehype-shiki (#7760)
* chore(monorepo): `rehype-shiki` * fixup! * add build to turbo
1 parent 3d50b07 commit 259db02

File tree

16 files changed

+157
-76
lines changed

16 files changed

+157
-76
lines changed

.github/workflows/lint-and-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ jobs:
149149
if: ${{ !cancelled() && github.event_name != 'merge_group' }}
150150
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
151151
with:
152-
files: ./apps/site/lcov.info,./packages/ui-components/lcov.info
152+
files: ./apps/site/lcov.info,./packages/*/lcov.info
153153

154154
- name: Upload test results to Codecov
155155
if: ${{ !cancelled() && github.event_name != 'merge_group' }}
156156
uses: codecov/test-results-action@f2dba722c67b86c6caa034178c6e4d35335f6706 # v1.1.0
157157
with:
158-
files: ./apps/site/junit.xml,./packages/ui-components/junit.xml
158+
files: ./apps/site/junit.xml,./packages/*/junit.xml

apps/site/components/Downloads/Release/ReleaseCodeBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { highlightToHtml } from '@node-core/rehype-shiki';
34
import AlertBox from '@node-core/ui-components/Common/AlertBox';
45
import Skeleton from '@node-core/ui-components/Common/Skeleton';
56
import { useTranslations } from 'next-intl';
@@ -16,7 +17,6 @@ import {
1617
} from '#site/providers/releaseProvider';
1718
import type { ReleaseContextType } from '#site/types/release';
1819
import { INSTALL_METHODS } from '#site/util/downloadUtils';
19-
import { highlightToHtml } from '#site/util/getHighlighter';
2020

2121
// Creates a minimal JavaScript interpreter for parsing the JavaScript code from the snippets
2222
// Note: that the code runs inside a sandboxed environment and cannot interact with any code outside of the sandbox

apps/site/components/MDX/CodeBox/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { getLanguageDisplayName } from '@node-core/rehype-shiki';
12
import type { FC, PropsWithChildren } from 'react';
23

34
import CodeBox from '#site/components/Common/CodeBox';
4-
import { getLanguageDisplayName } from '#site/util/getLanguageDisplayName';
55

66
type CodeBoxProps = { className?: string; showCopyButton?: string };
77

apps/site/next.mdx.plugins.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

3+
import rehypeShikiji from '@node-core/rehype-shiki';
34
import remarkHeadings from '@vcarl/remark-headings';
45
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
56
import rehypeSlug from 'rehype-slug';
67
import remarkGfm from 'remark-gfm';
78
import readingTime from 'remark-reading-time';
89

9-
import rehypeShikiji from './next.mdx.shiki.mjs';
10-
1110
/**
1211
* Provides all our Rehype Plugins that are used within MDX
1312
*/

apps/site/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dependencies": {
2929
"@heroicons/react": "~2.2.0",
3030
"@mdx-js/mdx": "^3.1.0",
31+
"@node-core/rehype-shiki": "workspace:*",
3132
"@node-core/ui-components": "workspace:*",
3233
"@node-core/website-i18n": "workspace:*",
3334
"@nodevu/core": "0.3.0",
@@ -41,8 +42,6 @@
4142
"@radix-ui/react-tabs": "^1.1.3",
4243
"@radix-ui/react-toast": "^1.2.6",
4344
"@radix-ui/react-tooltip": "^1.2.4",
44-
"@shikijs/core": "^3.2.2",
45-
"@shikijs/engine-javascript": "^3.2.2",
4645
"@tailwindcss/postcss": "~4.1.5",
4746
"@types/node": "22.15.3",
4847
"@types/react": "^19.1.0",
@@ -56,7 +55,6 @@
5655
"github-slugger": "~2.0.0",
5756
"glob": "~11.0.1",
5857
"gray-matter": "~4.0.3",
59-
"hast-util-to-string": "~3.0.1",
6058
"next": "15.3.1",
6159
"next-intl": "~4.1.0",
6260
"next-themes": "~0.4.6",
@@ -69,10 +67,8 @@
6967
"remark-gfm": "~4.0.1",
7068
"remark-reading-time": "~2.0.1",
7169
"semver": "~7.7.1",
72-
"shiki": "~3.3.0",
7370
"sval": "^0.6.3",
7471
"tailwindcss": "~4.0.17",
75-
"unist-util-visit": "~5.0.0",
7672
"vfile": "~6.0.3",
7773
"vfile-matter": "~5.0.1"
7874
},

apps/site/util/getHighlighter.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

apps/site/util/getLanguageDisplayName.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import baseConfig from '../../eslint.config.js';
2+
3+
export default [
4+
...baseConfig,
5+
{
6+
languageOptions: {
7+
parserOptions: {
8+
// Allow nullish syntax (i.e. "?." or "??")
9+
ecmaVersion: 2020,
10+
},
11+
},
12+
rules: {
13+
// Shiki's export isn't named, it's a re-export
14+
'import-x/named': 'off',
15+
},
16+
},
17+
];

packages/rehype-shiki/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@node-core/rehype-shiki",
3+
"type": "module",
4+
"main": "./src/index.mjs",
5+
"module": "./src/index.mjs",
6+
"scripts": {
7+
"lint:js": "eslint \"**/*.mjs\"",
8+
"test": "node --test"
9+
},
10+
"dependencies": {
11+
"@shikijs/core": "^3.3.0",
12+
"@shikijs/engine-javascript": "^3.3.0",
13+
"classnames": "~2.5.1",
14+
"hast-util-to-string": "^3.0.1",
15+
"shiki": "~3.3.0",
16+
"unist-util-visit": "^5.0.0"
17+
}
18+
}

apps/site/util/__tests__/getLanguageDisplayName.test.mjs renamed to packages/rehype-shiki/src/__tests__/languages.test.mjs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import assert from 'node:assert/strict';
2-
import { it, describe, mock } from 'node:test';
2+
import { it, describe } from 'node:test';
33

4-
describe('getLanguageDisplayName', async () => {
5-
mock.module('#site/shiki.config.mjs', {
6-
namedExports: {
7-
LANGUAGES: [
8-
{ name: 'javascript', aliases: ['js'], displayName: 'JavaScript' },
9-
{ name: 'typescript', aliases: ['ts'], displayName: 'TypeScript' },
10-
],
11-
},
12-
});
4+
import { getLanguageDisplayName, LANGUAGES } from '../languages.mjs';
135

14-
const { getLanguageDisplayName } = await import(
15-
'#site/util/getLanguageDisplayName'
16-
);
6+
LANGUAGES.splice(
7+
0,
8+
LANGUAGES.length,
9+
{ name: 'javascript', aliases: ['js'], displayName: 'JavaScript' },
10+
{ name: 'typescript', aliases: ['ts'], displayName: 'TypeScript' }
11+
);
1712

13+
describe('getLanguageDisplayName', async () => {
1814
it('should return the display name for a known language', () => {
1915
assert.equal(getLanguageDisplayName('javascript'), 'JavaScript');
2016
assert.equal(getLanguageDisplayName('js'), 'JavaScript');

0 commit comments

Comments
 (0)