Skip to content

Commit

Permalink
fix(plugin-shiki): __dirname is not found (#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter authored Sep 26, 2024
1 parent b887a30 commit 49d914a
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 3 deletions.
34 changes: 34 additions & 0 deletions e2e/fixtures/plugin-shiki/doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @rspress/plugin-shiki

<!-- createTransformerDiff -->

```ts
export function foo() {
console.log('Diff remove'); // [!code --]
console.log('Diff add'); // [!code ++]
}
```

<!-- createTransformerLineNumber -->

```ts
export function foo() {
console.log('Line number'); // [!code hl]
}
```

<!-- createTransformerErrorLevel -->

```ts
export function foo() {
console.log('Error level'); // [!code error]
}
```

<!-- createTransformerFocus -->

```ts
export function foo() {
console.log('Focus'); // [!code focus]
}
```
17 changes: 17 additions & 0 deletions e2e/fixtures/plugin-shiki/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@rspress-fixture/plugin-shiki",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "rspress dev",
"build": "rspress build",
"preview": "rspress preview"
},
"dependencies": {
"rspress": "workspace:*",
"@rspress/plugin-shiki": "workspace:*"
},
"devDependencies": {
"@types/node": "^18.11.17"
}
}
25 changes: 25 additions & 0 deletions e2e/fixtures/plugin-shiki/rspress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import path from 'node:path';
import { defineConfig } from 'rspress/config';
import {
createTransformerDiff,
createTransformerErrorLevel,
createTransformerFocus,
createTransformerHighlight,
createTransformerLineNumber,
pluginShiki,
} from '@rspress/plugin-shiki';

export default defineConfig({
root: path.join(__dirname, 'doc'),
plugins: [
pluginShiki({
transformers: [
createTransformerDiff(),
createTransformerLineNumber(),
createTransformerErrorLevel(),
createTransformerHighlight(),
createTransformerFocus(),
],
}),
],
});
6 changes: 6 additions & 0 deletions e2e/fixtures/plugin-shiki/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react-jsx"
}
}
File renamed without changes.
35 changes: 35 additions & 0 deletions e2e/tests/plugin-shiki.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from 'node:path';
import { expect, test } from '@playwright/test';
import fixture from '../fixtures/plugin-rss/fixture.json';
import {
getPort,
killProcess,
runBuildCommand,
runPreviewCommand,
} from '../utils/runCommands';

const fixtureDir = path.resolve(__dirname, '../fixtures');
test.describe('plugin shiki test', async () => {
let appPort: number;
let app: unknown;
test.beforeAll(async () => {
const appDir = path.join(fixtureDir, 'plugin-shiki');
appPort = await getPort();
await runBuildCommand(appDir);
app = await runPreviewCommand(appDir, appPort);
});

test.afterAll(async () => {
if (app) {
await killProcess(app);
}
});

test('should render shiki code block successfully', async ({ page }) => {
await page.goto(`http://localhost:${appPort}`, {
waitUntil: 'networkidle',
});
const shikiDoms = await page.$$('.shiki');
expect(shikiDoms.length).toBe(4);
});
});
2 changes: 1 addition & 1 deletion packages/core/src/node/runtimeModule/siteData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function siteDataVMPlugin(context: FactoryContext) {
// If the dev server restart when config file, we will reuse the siteData instead of extracting the siteData from source files again.
const domain =
userConfig?.search && userConfig?.search?.mode === 'remote'
? userConfig?.search.domain ?? ''
? (userConfig?.search.domain ?? '')
: '';
const pages = (
await extractPageData(
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-preview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function pluginPreview(options?: Options): RspressPlugin {
previewLanguages = DEFAULT_PREVIEW_LANGUAGES,
previewCodeTransform = ({ code }: { code: string }) => code,
} = options ?? {};
const previewMode = options?.previewMode ?? isMobile ? 'iframe' : 'internal';
const previewMode =
(options?.previewMode ?? isMobile) ? 'iframe' : 'internal';
const {
devPort = 7890,
framework = 'react',
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-shiki/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default defineConfig({
buildConfig: {
buildType: 'bundle',
format: 'esm',
target: 'es2021',
sourceMap: true,
shims: true,
dts: {
respectExternal: false,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-shiki/src/shiki/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function getHighlighter(
typeof htmlOptions === 'object' ? htmlOptions.lang! : htmlOptions!;

const baseLineOptions =
typeof htmlOptions === 'object' ? htmlOptions.lineOptions ?? [] : [];
typeof htmlOptions === 'object' ? (htmlOptions.lineOptions ?? []) : [];

const theme =
typeof htmlOptions === 'object' ? htmlOptions.theme : undefined;
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49d914a

Please sign in to comment.