Skip to content

Commit 7dc60ef

Browse files
authored
chore: migrate packages building with Rslib (#1770)
1 parent e60ae89 commit 7dc60ef

File tree

16 files changed

+225
-82
lines changed

16 files changed

+225
-82
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function HelloWorld() {
2+
return <div>Hello World External</div>;
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Guide
2+
3+
```jsx
4+
export default function HelloWorld() {
5+
return <div>Hello World Internal (default)</div>;
6+
}
7+
```
8+
9+
<code src="./component.jsx" />
10+
11+
```jsx direction=vertical
12+
export default function HelloWorld() {
13+
return <div>Hello World Internal (vertical)</div>;
14+
}
15+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@rspress-fixture/plugin-playground",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "rspress build",
7+
"dev": "rspress dev",
8+
"preview": "rspress preview"
9+
},
10+
"dependencies": {
11+
"@rspress/plugin-playground": "workspace:*",
12+
"@rspress/shared": "workspace:*",
13+
"react": "^18.3.1",
14+
"react-dom": "^18.3.1",
15+
"rspress": "workspace:*",
16+
"solid-js": "^1.9.4"
17+
},
18+
"devDependencies": {
19+
"@types/node": "^18.11.17"
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import path from 'node:path';
2+
import { pluginPlayground } from '@rspress/plugin-playground';
3+
import { defineConfig } from 'rspress/config';
4+
5+
export default defineConfig({
6+
root: path.join(__dirname, 'doc'),
7+
plugins: [pluginPlayground()],
8+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"jsx": "react-jsx"
5+
}
6+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import path from 'node:path';
2+
import { expect, test } from '@playwright/test';
3+
import { getPort, killProcess, runDevCommand } from '../utils/runCommands';
4+
5+
const fixtureDir = path.resolve(__dirname, '../fixtures');
6+
7+
test.describe('plugin test', async () => {
8+
let appPort;
9+
let app;
10+
test.beforeAll(async () => {
11+
const appDir = path.join(fixtureDir, 'plugin-playground');
12+
appPort = await getPort();
13+
app = await runDevCommand(appDir, appPort);
14+
});
15+
16+
test.afterAll(async () => {
17+
if (app) {
18+
await killProcess(app);
19+
}
20+
});
21+
22+
test('Should render the element', async ({ page }) => {
23+
await page.goto(`http://localhost:${appPort}/`, {
24+
waitUntil: 'networkidle',
25+
});
26+
27+
const playgroundElements = await page.$$('.rspress-playground');
28+
29+
const internalDemoCodePreviewDefault = await page
30+
.locator('.rspress-playground > .rspress-playground-runner > div')
31+
.getByText('Hello World Internal (default)');
32+
33+
const internalDemoCodePreviewVertical = await page
34+
.locator('.rspress-playground > .rspress-playground-runner > div')
35+
.getByText('Hello World Internal (vertical)');
36+
37+
const externalDemoCodePreview = await page
38+
.locator('.rspress-playground > .rspress-playground-runner > div')
39+
.getByText('Hello World External');
40+
41+
expect(playgroundElements.length).toBe(3);
42+
expect(await internalDemoCodePreviewDefault.count()).toBe(1);
43+
expect(await internalDemoCodePreviewVertical.count()).toBe(1);
44+
expect(await externalDemoCodePreview.count()).toBe(1);
45+
});
46+
});

packages/plugin-playground/modern.config.ts

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

packages/plugin-playground/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"exports": {
1313
".": {
1414
"types": "./dist/cli/esm/index.d.ts",
15-
"import": "./dist/cli/esm/index.js",
15+
"import": "./dist/cli/esm/index.mjs",
1616
"default": "./dist/cli/cjs/index.js"
1717
},
1818
"./web": {
1919
"types": "./dist/web/esm/index.d.ts",
20-
"import": "./dist/web/esm/index.js",
20+
"import": "./dist/web/esm/index.mjs",
2121
"default": "./dist/web/cjs/index.js"
2222
}
2323
},
@@ -29,8 +29,8 @@
2929
"static"
3030
],
3131
"scripts": {
32-
"build": "modern build",
33-
"dev": "modern build -w",
32+
"build": "rslib build",
33+
"dev": "rslib build -w",
3434
"reset": "rimraf ./**/node_modules",
3535
"test": "vitest run --passWithNoTests"
3636
},
@@ -44,6 +44,7 @@
4444
},
4545
"devDependencies": {
4646
"@babel/types": "^7.26.5",
47+
"@rslib/core": "0.3.2",
4748
"@types/babel__core": "^7.20.5",
4849
"@types/babel__standalone": "^7.1.9",
4950
"@types/babel__traverse": "^7.20.6",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { defineConfig } from '@rslib/core';
2+
3+
export default defineConfig({
4+
lib: [
5+
{
6+
format: 'cjs',
7+
source: {
8+
entry: { index: 'src/cli/index.ts' },
9+
},
10+
output: {
11+
distPath: {
12+
root: 'dist/cli/cjs',
13+
},
14+
},
15+
syntax: 'es2020',
16+
},
17+
{
18+
format: 'esm',
19+
source: {
20+
entry: { index: 'src/cli/index.ts' },
21+
},
22+
output: {
23+
distPath: {
24+
root: 'dist/cli/esm',
25+
},
26+
externals: ['@types/react'],
27+
},
28+
syntax: 'es2020',
29+
dts: { bundle: true },
30+
},
31+
{
32+
format: 'cjs',
33+
source: {
34+
entry: { index: 'src/web/index.ts' },
35+
},
36+
output: {
37+
distPath: {
38+
root: 'dist/web/cjs',
39+
},
40+
},
41+
syntax: 'es2020',
42+
},
43+
{
44+
format: 'esm',
45+
source: {
46+
entry: { index: 'src/web/index.ts' },
47+
},
48+
output: {
49+
externals: ['@types/react'],
50+
distPath: {
51+
root: 'dist/web/esm',
52+
},
53+
},
54+
syntax: 'es2020',
55+
dts: { bundle: true },
56+
},
57+
],
58+
});

packages/plugin-playground/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"@/*": ["./*"]
1515
}
1616
},
17-
"include": ["src", "vitest.config.ts", "index.d.ts", "modern.config.ts"],
17+
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
1818
"exclude": ["node_modules", "dist"]
1919
}

0 commit comments

Comments
 (0)