Skip to content

Commit

Permalink
chore: migrate packages building with Rslib
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jan 24, 2025
1 parent b4ae1be commit 36930f5
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 8 deletions.
3 changes: 3 additions & 0 deletions e2e/fixtures/plugin-playground/doc/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function HelloWorld() {
return <div>Hello World External</div>;
}
15 changes: 15 additions & 0 deletions e2e/fixtures/plugin-playground/doc/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Guide

```jsx
export default function HelloWorld() {
return <div>Hello World Internal (default)</div>;
}
```

<code src="./component.jsx" />

```jsx direction=vertical
export default function HelloWorld() {
return <div>Hello World Internal (vertical)</div>;
}
```
21 changes: 21 additions & 0 deletions e2e/fixtures/plugin-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@rspress-fixture/plugin-playground",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "rspress build",
"dev": "rspress dev",
"preview": "rspress preview"
},
"dependencies": {
"@rspress/plugin-playground": "workspace:*",
"@rspress/shared": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rspress": "workspace:*",
"solid-js": "^1.9.4"
},
"devDependencies": {
"@types/node": "^18.11.17"
}
}
8 changes: 8 additions & 0 deletions e2e/fixtures/plugin-playground/rspress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'node:path';
import { pluginPlayground } from '@rspress/plugin-playground';
import { defineConfig } from 'rspress/config';

export default defineConfig({
root: path.join(__dirname, 'doc'),
plugins: [pluginPlayground()],
});
6 changes: 6 additions & 0 deletions e2e/fixtures/plugin-playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react-jsx"
}
}
46 changes: 46 additions & 0 deletions e2e/tests/plugin-playground.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import path from 'node:path';
import { expect, test } from '@playwright/test';
import { getPort, killProcess, runDevCommand } from '../utils/runCommands';

const fixtureDir = path.resolve(__dirname, '../fixtures');

test.describe('plugin test', async () => {
let appPort;
let app;
test.beforeAll(async () => {
const appDir = path.join(fixtureDir, 'plugin-playground');
appPort = await getPort();
app = await runDevCommand(appDir, appPort);
});

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

test('Should render the element', async ({ page }) => {
await page.goto(`http://localhost:${appPort}/`, {
waitUntil: 'networkidle',
});

const playgroundElements = await page.$$('.rspress-playground');

const internalDemoCodePreviewDefault = await page
.locator('.rspress-playground > .rspress-playground-runner > div')
.getByText('Hello World Internal (default)');

const internalDemoCodePreviewVertical = await page
.locator('.rspress-playground > .rspress-playground-runner > div')
.getByText('Hello World Internal (vertical)');

const externalDemoCodePreview = await page
.locator('.rspress-playground > .rspress-playground-runner > div')
.getByText('Hello World External');

expect(playgroundElements.length).toBe(3);
expect(await internalDemoCodePreviewDefault.count()).toBe(1);
expect(await internalDemoCodePreviewVertical.count()).toBe(1);
expect(await externalDemoCodePreview.count()).toBe(1);
});
});
11 changes: 7 additions & 4 deletions packages/plugin-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"exports": {
".": {
"types": "./dist/cli/esm/index.d.ts",
"import": "./dist/cli/esm/index.js",
"import": "./dist/cli/esm/index.mjs",
"default": "./dist/cli/cjs/index.js"
},
"./web": {
"types": "./dist/web/esm/index.d.ts",
"import": "./dist/web/esm/index.js",
"import": "./dist/web/esm/index.mjs",
"default": "./dist/web/cjs/index.js"
}
},
Expand All @@ -29,8 +29,10 @@
"static"
],
"scripts": {
"build": "modern build",
"dev": "modern build -w",
"build": "rslib build",
"build:m": "modern build",
"dev": "rslib build -w",
"dev:m": "modern build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
},
Expand All @@ -44,6 +46,7 @@
},
"devDependencies": {
"@babel/types": "^7.26.5",
"@rslib/core": "0.3.2",
"@types/babel__core": "^7.20.5",
"@types/babel__standalone": "^7.1.9",
"@types/babel__traverse": "^7.20.6",
Expand Down
58 changes: 58 additions & 0 deletions packages/plugin-playground/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [
{
format: 'cjs',
source: {
entry: { index: 'src/cli/index.ts' },
},
output: {
distPath: {
root: 'dist/cli/cjs',
},
},
syntax: 'es2020',
},
{
format: 'esm',
source: {
entry: { index: 'src/cli/index.ts' },
},
output: {
distPath: {
root: 'dist/cli/esm',
},
externals: ['@types/react'],
},
syntax: 'es2020',
dts: { bundle: true },
},
{
format: 'cjs',
source: {
entry: { index: 'src/web/index.ts' },
},
output: {
distPath: {
root: 'dist/web/cjs',
},
},
syntax: 'es2020',
},
{
format: 'esm',
source: {
entry: { index: 'src/web/index.ts' },
},
output: {
externals: ['@types/react'],
distPath: {
root: 'dist/web/esm',
},
},
syntax: 'es2020',
dts: { bundle: true },
},
],
});
2 changes: 1 addition & 1 deletion packages/plugin-playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@/*": ["./*"]
}
},
"include": ["src", "vitest.config.ts", "index.d.ts", "modern.config.ts"],
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"exclude": ["node_modules", "dist"]
}
5 changes: 3 additions & 2 deletions packages/plugin-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"mdx-meta-loader.cjs"
],
"scripts": {
"build": "modern build",
"dev": "modern build -w",
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
},
Expand All @@ -35,6 +35,7 @@
"qrcode.react": "^3.2.0"
},
"devDependencies": {
"@rslib/core": "0.3.2",
"@types/lodash": "^4.17.14",
"@types/mdast": "^3.0.15",
"@types/node": "^18.11.17",
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin-preview/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [
{
format: 'cjs',
source: {
entry: { index: 'src/index.ts' },
},
syntax: 'es2020',
dts: {
bundle: true,
},
},
{
format: 'cjs',
source: {
entry: { utils: 'src/utils.ts' },
},
syntax: 'es2020',
dts: {
bundle: true,
},
},
],
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NoSSR, usePageData, withBase } from '@rspress/core/runtime';
import { useCallback, useEffect, useMemo, useState } from 'react';
// @ts-expect-error
import { normalizeId } from '../../dist/utils';
import MobileOperation from './common/mobile-operation';
import './Device.scss';
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-preview/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"index.d.ts",
"mdx-meta-loader.cjs",
"static/",
"modern.config.ts"
"rslib.config.ts"
],
"exclude": ["runtime.d.ts", "theme.d.ts", "node_modules", "dist"]
}
31 changes: 31 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 36930f5

Please sign in to comment.