diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4b4744cfa..f0f654899 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1553,7 +1553,7 @@ importers: specifier: ^5.9.3 version: 5.9.3 - rslib/solid: + rslib/solid-basic: devDependencies: '@rsbuild/plugin-babel': specifier: ^1.2.1 @@ -1564,9 +1564,36 @@ importers: '@rslib/core': specifier: ^0.22.0 version: 0.22.0(@module-federation/runtime-tools@2.5.0)(core-js@3.49.0)(typescript@5.9.3) - preact: - specifier: ^10.29.2 - version: 10.29.2 + solid-js: + specifier: ^1.9.13 + version: 1.9.13 + typescript: + specifier: ^5.9.3 + version: 5.9.3 + + rslib/solid-rstest: + devDependencies: + '@rsbuild/plugin-babel': + specifier: ^1.2.1 + version: 1.2.1(@rsbuild/core@2.0.11) + '@rsbuild/plugin-solid': + specifier: ^1.2.1 + version: 1.2.1(@babel/core@7.29.7)(@rsbuild/core@2.0.11)(solid-js@1.9.13) + '@rslib/core': + specifier: ^0.22.0 + version: 0.22.0(@module-federation/runtime-tools@2.5.0)(core-js@3.49.0)(typescript@5.9.3) + '@rstest/adapter-rslib': + specifier: ^0.10.3 + version: 0.10.3(@rslib/core@0.22.0)(@rstest/core@0.10.3)(typescript@5.9.3) + '@rstest/core': + specifier: ^0.10.3 + version: 0.10.3(@module-federation/runtime-tools@2.5.0)(core-js@3.49.0)(happy-dom@20.9.0)(jsdom@27.4.0) + '@solidjs/testing-library': + specifier: ^0.8.10 + version: 0.8.10(solid-js@1.9.13) + happy-dom: + specifier: ^20.9.0 + version: 20.9.0 solid-js: specifier: ^1.9.13 version: 1.9.13 @@ -8348,6 +8375,16 @@ packages: peerDependencies: solid-js: '>=1.8.4' + '@solidjs/testing-library@0.8.10': + resolution: {integrity: sha512-qdeuIerwyq7oQTIrrKvV0aL9aFeuwTd86VYD3afdq5HYEwoox1OBTJy4y8A3TFZr8oAR0nujYgCzY/8wgHGfeQ==} + engines: {node: '>= 14'} + peerDependencies: + '@solidjs/router': '>=0.9.0' + solid-js: '>=1.0.0' + peerDependenciesMeta: + '@solidjs/router': + optional: true + '@storybook/addon-docs@10.4.1': resolution: {integrity: sha512-IYqUdjoZe4VO2LFZlKL/gwy7DsQSWCq6hX+zc1MBmZo04yycDASk1tte57n9pdlW3ajw9yYMF/+lVBi+xQjyvw==} peerDependencies: @@ -21481,6 +21518,11 @@ snapshots: dependencies: solid-js: 1.9.13 + '@solidjs/testing-library@0.8.10(solid-js@1.9.13)': + dependencies: + '@testing-library/dom': 10.4.1 + solid-js: 1.9.13 + '@storybook/addon-docs@10.4.1(@types/react-dom@19.2.3)(@types/react@19.2.15)(esbuild@0.28.0)(rollup@4.60.3)(storybook@10.4.1)(vite@7.1.1)(webpack@5.102.1)': dependencies: '@mdx-js/react': 3.1.1(@types/react@19.2.15)(react@19.2.7) diff --git a/rslib/solid/.gitignore b/rslib/solid-basic/.gitignore similarity index 100% rename from rslib/solid/.gitignore rename to rslib/solid-basic/.gitignore diff --git a/rslib/solid/README.md b/rslib/solid-basic/README.md similarity index 89% rename from rslib/solid/README.md rename to rslib/solid-basic/README.md index ae4f5bbed..ace8557f5 100644 --- a/rslib/solid/README.md +++ b/rslib/solid-basic/README.md @@ -1,4 +1,4 @@ -# Rslib project +# Rslib Solid basic ## Setup diff --git a/rslib/solid/package.json b/rslib/solid-basic/package.json similarity index 82% rename from rslib/solid/package.json rename to rslib/solid-basic/package.json index e6409fefc..12038fc4d 100644 --- a/rslib/solid/package.json +++ b/rslib/solid-basic/package.json @@ -1,9 +1,10 @@ { - "name": "@rslib-example/solid", + "name": "@rslib-example/solid-basic", "version": "0.0.0", "type": "module", "exports": { ".": { + "solid": "./dist/source/index.jsx", "types": "./dist/index.d.ts", "import": "./dist/index.js" } @@ -20,11 +21,10 @@ "@rsbuild/plugin-babel": "^1.2.1", "@rsbuild/plugin-solid": "^1.2.1", "@rslib/core": "^0.22.0", - "preact": "^10.29.2", "solid-js": "^1.9.13", "typescript": "^5.9.3" }, "peerDependencies": { - "solid-js": "^1.0.0" + "solid-js": "^1.8.0" } } diff --git a/rslib/solid-basic/rslib.config.ts b/rslib/solid-basic/rslib.config.ts new file mode 100644 index 000000000..a321b384a --- /dev/null +++ b/rslib/solid-basic/rslib.config.ts @@ -0,0 +1,57 @@ +import { pluginBabel } from '@rsbuild/plugin-babel'; +import { pluginSolid } from '@rsbuild/plugin-solid'; +import { defineConfig } from '@rslib/core'; + +export default defineConfig({ + lib: [ + { + id: 'compiled', + bundle: false, + format: 'esm', + dts: true, + plugins: [ + pluginBabel({ + include: /\.(?:jsx|tsx)$/, + }), + pluginSolid(), + ], + }, + { + id: 'source', + bundle: false, + format: 'esm', + output: { + distPath: { + root: './dist/source', + }, + filename: { + js: '[name].jsx', + }, + }, + tools: { + swc: { + detectSyntax: 'auto', + jsc: { + transform: { + react: { + runtime: 'preserve', + }, + }, + }, + }, + rspack: { + module: { + parser: { + javascript: { + jsx: true, + }, + }, + }, + }, + }, + }, + ], + output: { + target: 'web', + }, +}); diff --git a/rslib/solid/src/Button.tsx b/rslib/solid-basic/src/Button.tsx similarity index 81% rename from rslib/solid/src/Button.tsx rename to rslib/solid-basic/src/Button.tsx index d692348d8..d3ed5737a 100644 --- a/rslib/solid/src/Button.tsx +++ b/rslib/solid-basic/src/Button.tsx @@ -1,7 +1,7 @@ import type { Component } from 'solid-js'; import './button.css'; -interface ButtonProps { +export interface ButtonProps { primary?: boolean; backgroundColor?: string; size?: 'small' | 'medium' | 'large'; @@ -14,15 +14,16 @@ export const Button: Component = ({ size = 'medium', backgroundColor, label, - ...props + onClick, }) => { const mode = primary ? 'demo-button--primary' : 'demo-button--secondary'; + return ( diff --git a/rslib/solid/src/button.css b/rslib/solid-basic/src/button.css similarity index 100% rename from rslib/solid/src/button.css rename to rslib/solid-basic/src/button.css diff --git a/rslib/solid-basic/src/index.tsx b/rslib/solid-basic/src/index.tsx new file mode 100644 index 000000000..fa3c8a518 --- /dev/null +++ b/rslib/solid-basic/src/index.tsx @@ -0,0 +1,2 @@ +export { Button } from './Button'; +export type { ButtonProps } from './Button'; diff --git a/rslib/solid/tsconfig.json b/rslib/solid-basic/tsconfig.json similarity index 100% rename from rslib/solid/tsconfig.json rename to rslib/solid-basic/tsconfig.json diff --git a/rslib/solid-rstest/.gitignore b/rslib/solid-rstest/.gitignore new file mode 100644 index 000000000..b538abcd1 --- /dev/null +++ b/rslib/solid-rstest/.gitignore @@ -0,0 +1,14 @@ +# Local +.DS_Store +*.local +*.log* + +# Dist +node_modules +dist/ +storybook-static + +# IDE +.vscode/* +!.vscode/extensions.json +.idea diff --git a/rslib/solid-rstest/README.md b/rslib/solid-rstest/README.md new file mode 100644 index 000000000..beacabf1d --- /dev/null +++ b/rslib/solid-rstest/README.md @@ -0,0 +1,29 @@ +# Rslib Solid Rstest + +## Setup + +Install the dependencies: + +```bash +pnpm install +``` + +## Get started + +Build the library: + +```bash +pnpm build +``` + +Build the library in watch mode: + +```bash +pnpm dev +``` + +Run tests: + +```bash +pnpm test +``` diff --git a/rslib/solid-rstest/package.json b/rslib/solid-rstest/package.json new file mode 100644 index 000000000..ecd76366c --- /dev/null +++ b/rslib/solid-rstest/package.json @@ -0,0 +1,35 @@ +{ + "name": "@rslib-example/solid-rstest", + "version": "0.0.0", + "type": "module", + "exports": { + ".": { + "solid": "./dist/source/index.jsx", + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "rslib", + "dev": "rslib -w", + "test": "rstest" + }, + "devDependencies": { + "@rsbuild/plugin-babel": "^1.2.1", + "@rsbuild/plugin-solid": "^1.2.1", + "@rslib/core": "^0.22.0", + "@rstest/adapter-rslib": "^0.10.3", + "@rstest/core": "^0.10.3", + "@solidjs/testing-library": "^0.8.10", + "happy-dom": "^20.9.0", + "solid-js": "^1.9.13", + "typescript": "^5.9.3" + }, + "peerDependencies": { + "solid-js": "^1.8.0" + } +} diff --git a/rslib/solid-rstest/rslib.config.ts b/rslib/solid-rstest/rslib.config.ts new file mode 100644 index 000000000..a321b384a --- /dev/null +++ b/rslib/solid-rstest/rslib.config.ts @@ -0,0 +1,57 @@ +import { pluginBabel } from '@rsbuild/plugin-babel'; +import { pluginSolid } from '@rsbuild/plugin-solid'; +import { defineConfig } from '@rslib/core'; + +export default defineConfig({ + lib: [ + { + id: 'compiled', + bundle: false, + format: 'esm', + dts: true, + plugins: [ + pluginBabel({ + include: /\.(?:jsx|tsx)$/, + }), + pluginSolid(), + ], + }, + { + id: 'source', + bundle: false, + format: 'esm', + output: { + distPath: { + root: './dist/source', + }, + filename: { + js: '[name].jsx', + }, + }, + tools: { + swc: { + detectSyntax: 'auto', + jsc: { + transform: { + react: { + runtime: 'preserve', + }, + }, + }, + }, + rspack: { + module: { + parser: { + javascript: { + jsx: true, + }, + }, + }, + }, + }, + }, + ], + output: { + target: 'web', + }, +}); diff --git a/rslib/solid-rstest/rstest.config.ts b/rslib/solid-rstest/rstest.config.ts new file mode 100644 index 000000000..a737f6123 --- /dev/null +++ b/rslib/solid-rstest/rstest.config.ts @@ -0,0 +1,9 @@ +import { withRslibConfig } from '@rstest/adapter-rslib'; +import { defineConfig } from '@rstest/core'; + +export default defineConfig({ + extends: withRslibConfig({ + libId: 'compiled', + }), + testEnvironment: 'happy-dom', +}); diff --git a/rslib/solid-rstest/src/Button.tsx b/rslib/solid-rstest/src/Button.tsx new file mode 100644 index 000000000..d3ed5737a --- /dev/null +++ b/rslib/solid-rstest/src/Button.tsx @@ -0,0 +1,31 @@ +import type { Component } from 'solid-js'; +import './button.css'; + +export interface ButtonProps { + primary?: boolean; + backgroundColor?: string; + size?: 'small' | 'medium' | 'large'; + label: string; + onClick?: () => void; +} + +export const Button: Component = ({ + primary = false, + size = 'medium', + backgroundColor, + label, + onClick, +}) => { + const mode = primary ? 'demo-button--primary' : 'demo-button--secondary'; + + return ( + + ); +}; diff --git a/rslib/solid-rstest/src/button.css b/rslib/solid-rstest/src/button.css new file mode 100644 index 000000000..b7a36cbde --- /dev/null +++ b/rslib/solid-rstest/src/button.css @@ -0,0 +1,34 @@ +.demo-button { + font-weight: 700; + border: 0; + border-radius: 3em; + cursor: pointer; + display: inline-block; + line-height: 1; +} + +.demo-button--primary { + color: white; + background-color: #1ea7fd; +} + +.demo-button--secondary { + color: #333; + background-color: transparent; + box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset; +} + +.demo-button--small { + font-size: 12px; + padding: 10px 16px; +} + +.demo-button--medium { + font-size: 14px; + padding: 11px 20px; +} + +.demo-button--large { + font-size: 16px; + padding: 12px 24px; +} diff --git a/rslib/solid-rstest/src/index.tsx b/rslib/solid-rstest/src/index.tsx new file mode 100644 index 000000000..fa3c8a518 --- /dev/null +++ b/rslib/solid-rstest/src/index.tsx @@ -0,0 +1,2 @@ +export { Button } from './Button'; +export type { ButtonProps } from './Button'; diff --git a/rslib/solid-rstest/tests/index.test.tsx b/rslib/solid-rstest/tests/index.test.tsx new file mode 100644 index 000000000..bb142a9b0 --- /dev/null +++ b/rslib/solid-rstest/tests/index.test.tsx @@ -0,0 +1,22 @@ +import { render, screen } from '@solidjs/testing-library'; +import { expect, test } from '@rstest/core'; +import { Button } from '../src'; + +test('The button should handle click events', () => { + let count = 0; + render(() => ( +