From 2699877f6a9d9543577591fa34608991e6c89b90 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 11 Jul 2026 18:08:37 +0800 Subject: [PATCH] feat: export Rslib APIs from rstack/lib --- .../skills/rstack-cli-best-practices/SKILL.md | 1 + README.md | 16 ++++++++++++++++ packages/rstack/package.json | 4 ++++ packages/rstack/rslib.config.ts | 1 + packages/rstack/src/lib.ts | 9 +++++++++ .../test/exports/lib-subpath/index.test.ts | 8 ++++++++ packages/rstack/test/tsconfig.json | 1 + 7 files changed, 40 insertions(+) create mode 100644 packages/rstack/src/lib.ts create mode 100644 packages/rstack/test/exports/lib-subpath/index.test.ts diff --git a/.agents/skills/rstack-cli-best-practices/SKILL.md b/.agents/skills/rstack-cli-best-practices/SKILL.md index 2e8f491..53ea14d 100644 --- a/.agents/skills/rstack-cli-best-practices/SKILL.md +++ b/.agents/skills/rstack-cli-best-practices/SKILL.md @@ -75,6 +75,7 @@ Prefer Rstack-exported paths: | Instead of | Prefer | | ------------------------- | ------------------------ | +| `@rslib/core` | `rstack/lib` | | `@rstest/core` | `rstack/test` | | `@rslint/core` | `rstack/lint` | | `@rsbuild/core/types` | `rstack/types` | diff --git a/README.md b/README.md index f3bc98e..b01bed2 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,22 @@ pnpm lib pnpm doc ``` +## API imports + +Rstack re-exports the APIs of its underlying tools through dedicated entry points: + +| Tool | Import path | +| ------ | ------------- | +| Rslib | `rstack/lib` | +| Rslint | `rstack/lint` | +| Rstest | `rstack/test` | + +For example, import Rstest APIs without adding `@rstest/core` as a direct dependency: + +```ts +import { expect, test } from 'rstack/test'; +``` + ## Credits Rstack CLI is inspired by: diff --git a/packages/rstack/package.json b/packages/rstack/package.json index ce6f0bc..5a3604c 100644 --- a/packages/rstack/package.json +++ b/packages/rstack/package.json @@ -23,6 +23,10 @@ "types": "./dist/test.d.ts", "default": "./dist/test.js" }, + "./lib": { + "types": "./dist/lib.d.ts", + "default": "./dist/lib.js" + }, "./lint": { "types": "./dist/lint.d.ts", "default": "./dist/lint.js" diff --git a/packages/rstack/rslib.config.ts b/packages/rstack/rslib.config.ts index 1b3500e..88ffe6d 100644 --- a/packages/rstack/rslib.config.ts +++ b/packages/rstack/rslib.config.ts @@ -11,6 +11,7 @@ export default defineConfig({ rslintConfig: './src/rslintConfig.ts', rspressConfig: './src/rspressConfig.ts', rstestConfig: './src/rstestConfig.ts', + lib: './src/lib.ts', lint: './src/lint.ts', test: './src/test.ts', }, diff --git a/packages/rstack/src/lib.ts b/packages/rstack/src/lib.ts new file mode 100644 index 0000000..b7da801 --- /dev/null +++ b/packages/rstack/src/lib.ts @@ -0,0 +1,9 @@ +/** + * Re-export @rslib/core APIs so users can import library APIs from `rstack/lib`. + * + * @example + * ```ts + * import { defineConfig } from 'rstack/lib'; + * ``` + */ +export * from '@rslib/core'; diff --git a/packages/rstack/test/exports/lib-subpath/index.test.ts b/packages/rstack/test/exports/lib-subpath/index.test.ts new file mode 100644 index 0000000..1f1dc52 --- /dev/null +++ b/packages/rstack/test/exports/lib-subpath/index.test.ts @@ -0,0 +1,8 @@ +import * as rslib from '@rslib/core'; +import { expect, test } from 'rstack/test'; + +test('should expose all Rslib APIs from `rstack/lib`', async () => { + const lib = await import('rstack/lib'); + + expect(lib).toEqual(rslib); +}); diff --git a/packages/rstack/test/tsconfig.json b/packages/rstack/test/tsconfig.json index 5f97097..2cef022 100644 --- a/packages/rstack/test/tsconfig.json +++ b/packages/rstack/test/tsconfig.json @@ -7,6 +7,7 @@ "types": ["node"], "paths": { "rstack": ["../src/index.ts"], + "rstack/lib": ["../src/lib.ts"], "rstack/lint": ["../src/lint.ts"], "rstack/test": ["../src/test.ts"], "#test-helpers": ["./helpers/index.ts"]