@savvy-web/rspress-builder 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/index.d.ts +43 -0
- package/index.js +53 -0
- package/package.json +42 -0
- package/public/ecma.json +55 -0
- package/public/rspress-env.d.ts +19 -0
- package/public/tsconfig/plugin.json +11 -0
- package/tsdoc-metadata.json +11 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @savvy-web/rspress-builder
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@savvy-web/rspress-builder)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
Builds an [RSPress](https://rspress.rs/) plugin package on top of [`@savvy-web/bundler`](https://www.npmjs.com/package/@savvy-web/bundler). One `definePlugin` call produces the dual-bundle shape an RSPress plugin needs: a Node plugin entry plus a browser, bundleless, CSS-module React runtime entry, each with the right externals and platform already set.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install --save-dev @savvy-web/rspress-builder
|
|
12
|
+
# or
|
|
13
|
+
pnpm add -D @savvy-web/rspress-builder
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`@rspress/core`, `react`, `react-dom` and `@tsdown/css` are peer dependencies the host plugin provides.
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
Add a `savvy.build.ts` to the plugin package root. `definePlugin` returns a standard bundler config, which the re-exported `runBuild` consumes unchanged:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// savvy.build.ts
|
|
24
|
+
import { definePlugin, runBuild } from "@savvy-web/rspress-builder";
|
|
25
|
+
|
|
26
|
+
const config = definePlugin({ runtime: true, dtsBundledPackages: ["@rspress/core"] });
|
|
27
|
+
|
|
28
|
+
export default config;
|
|
29
|
+
|
|
30
|
+
if (import.meta.main) {
|
|
31
|
+
await runBuild(config, { cwd: import.meta.dirname, argv: process.argv.slice(2) });
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Wire the build targets into `package.json` scripts and run them with Node's native TypeScript support:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build:dev": "node savvy.build.ts --target dev",
|
|
41
|
+
"build:prod": "node savvy.build.ts --target prod"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The plugin entry (`.`) builds for Node with `@rspress/core` externalized. The runtime entry (`./runtime`) builds for the browser, bundleless, with CSS modules enabled and React, `@rspress/core` and `@theme` externalized so RSPress provides them at site build time.
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
`definePlugin` keeps a small surface because RSPress plugins have a fixed shape:
|
|
51
|
+
|
|
52
|
+
- `runtime` — build the `./runtime` bundle. `true` (default) builds it, `false` disables it for a plugin with no runtime, an object tunes its externals. It does not probe the filesystem; pass `false` when there is no runtime entry.
|
|
53
|
+
- `plugin` — externals tuning for the plugin (`.`) bundle.
|
|
54
|
+
- `dtsBundledPackages` — packages whose declarations are inlined into the bundled `.d.ts`, for example `["@rspress/core"]`.
|
|
55
|
+
- `apiModel` — API Extractor api-model generation, on by default. Pass `false` to opt out.
|
|
56
|
+
- `transform`, `jsx`, `define` — forwarded to the underlying bundler config.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
[MIT](LICENSE)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BuildConfig, BuildConfigInput, RunOptions, runBuild } from "@savvy-web/bundler";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** Per-bundle externals tuning for a single partition (plugin or runtime). */
|
|
5
|
+
interface RspressBundleOptions {
|
|
6
|
+
/** Additional externals merged with the built-ins for that bundle. */
|
|
7
|
+
readonly externals?: ReadonlyArray<string>;
|
|
8
|
+
}
|
|
9
|
+
/** Options for {@link definePlugin}. Deliberately small — RSPress plugins have a fixed shape. */
|
|
10
|
+
interface RspressPluginOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Enable the `./runtime` bundle (browser, bundleless, CSS modules, React/@theme external).
|
|
13
|
+
* `true` (default) builds it; `false` disables it; an object tunes its externals.
|
|
14
|
+
* This does not auto-detect the filesystem — pass `false` for a plugin with no runtime.
|
|
15
|
+
*/
|
|
16
|
+
readonly runtime?: boolean | RspressBundleOptions;
|
|
17
|
+
/** Tuning for the plugin (`.`) bundle (node, bundled). */
|
|
18
|
+
readonly plugin?: RspressBundleOptions;
|
|
19
|
+
/** Packages whose declarations are inlined into the bundled dts (e.g. ["@rspress/core"]). */
|
|
20
|
+
readonly dtsBundledPackages?: ReadonlyArray<string>;
|
|
21
|
+
/** API-model generation. Defaults to on (documents plugin options AND runtime components). `false` opts out. */
|
|
22
|
+
readonly apiModel?: BuildConfigInput["meta"];
|
|
23
|
+
/** Final package.json mutation; defaults to the bundler's defaultManifestTransform. */
|
|
24
|
+
readonly transform?: BuildConfigInput["transform"];
|
|
25
|
+
/** JSX override; defaults to tsconfig-inferred. */
|
|
26
|
+
readonly jsx?: BuildConfigInput["jsx"];
|
|
27
|
+
/**
|
|
28
|
+
* Build-wide compile-time global replacements forwarded to every partition (the bundler's
|
|
29
|
+
* `define` is build-wide; there is no per-bundle define). Merged AFTER the `import.meta.env`
|
|
30
|
+
* identity map, so a user key may override it intentionally. Values are inserted verbatim
|
|
31
|
+
* (string literals must be quoted).
|
|
32
|
+
*/
|
|
33
|
+
readonly define?: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build an RSPress plugin package: a Node plugin entry (`.`) plus a browser, bundleless,
|
|
37
|
+
* CSS-module React runtime entry (`./runtime`). Returns a standard {@link BuildConfig};
|
|
38
|
+
* hand it to {@link runBuild} from a self-executing `savvy.build.ts`.
|
|
39
|
+
*/
|
|
40
|
+
declare function definePlugin(options?: RspressPluginOptions): BuildConfig;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { RspressBundleOptions, RspressPluginOptions, type RunOptions, definePlugin, runBuild };
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineBuild, runBuild } from "@savvy-web/bundler";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/** Built-in externals for the plugin (node) bundle. */
|
|
5
|
+
const PLUGIN_EXTERNALS = ["@rspress/core"];
|
|
6
|
+
/** Built-in externals for the runtime (browser) bundle — provided by RSPress at site build time. */
|
|
7
|
+
const RUNTIME_EXTERNALS = [
|
|
8
|
+
"react",
|
|
9
|
+
"react/jsx-runtime",
|
|
10
|
+
"react/jsx-dev-runtime",
|
|
11
|
+
"@rspress/core",
|
|
12
|
+
"@theme"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Build an RSPress plugin package: a Node plugin entry (`.`) plus a browser, bundleless,
|
|
16
|
+
* CSS-module React runtime entry (`./runtime`). Returns a standard {@link BuildConfig};
|
|
17
|
+
* hand it to {@link runBuild} from a self-executing `savvy.build.ts`.
|
|
18
|
+
*/
|
|
19
|
+
function definePlugin(options = {}) {
|
|
20
|
+
const runtimeOpt = options.runtime ?? true;
|
|
21
|
+
const runtimeEnabled = runtimeOpt !== false;
|
|
22
|
+
const runtimeTuning = typeof runtimeOpt === "object" ? runtimeOpt : {};
|
|
23
|
+
const pluginTuning = options.plugin ?? {};
|
|
24
|
+
const pluginExternals = [...PLUGIN_EXTERNALS, ...pluginTuning.externals ?? []];
|
|
25
|
+
const overrides = runtimeEnabled ? [{
|
|
26
|
+
entries: ["./runtime"],
|
|
27
|
+
outSubdir: "runtime",
|
|
28
|
+
platform: "browser",
|
|
29
|
+
css: {
|
|
30
|
+
modules: {
|
|
31
|
+
localsConvention: "camelCaseOnly",
|
|
32
|
+
namedExport: false
|
|
33
|
+
},
|
|
34
|
+
inject: true
|
|
35
|
+
},
|
|
36
|
+
externals: [...RUNTIME_EXTERNALS, ...runtimeTuning.externals ?? []]
|
|
37
|
+
}] : [];
|
|
38
|
+
return defineBuild({
|
|
39
|
+
externals: pluginExternals,
|
|
40
|
+
define: {
|
|
41
|
+
"import.meta.env": "import.meta.env",
|
|
42
|
+
...options.define
|
|
43
|
+
},
|
|
44
|
+
...options.dtsBundledPackages !== void 0 ? { bundledPackages: options.dtsBundledPackages } : {},
|
|
45
|
+
...options.apiModel !== void 0 ? { meta: options.apiModel } : {},
|
|
46
|
+
...options.transform !== void 0 ? { transform: options.transform } : {},
|
|
47
|
+
...options.jsx !== void 0 ? { jsx: options.jsx } : {},
|
|
48
|
+
...overrides.length > 0 ? { overrides } : {}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { definePlugin, runBuild };
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@savvy-web/rspress-builder",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "RSPress plugin builder for the Silk Suite, built on @savvy-web/bundler",
|
|
6
|
+
"homepage": "https://github.com/savvy-web/systems/tree/main/packages/rspress-builder",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/savvy-web/systems/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/savvy-web/systems.git",
|
|
13
|
+
"directory": "packages/rspress-builder"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "C. Spencer Beggs",
|
|
18
|
+
"email": "spencer@savvyweb.systems",
|
|
19
|
+
"url": "https://savvyweb.systems"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./index.d.ts",
|
|
25
|
+
"import": "./index.js"
|
|
26
|
+
},
|
|
27
|
+
"./rspress-env.d.ts": "./public/rspress-env.d.ts",
|
|
28
|
+
"./tsconfig/ecma.json": "./public/ecma.json",
|
|
29
|
+
"./tsconfig/plugin.json": "./public/tsconfig/plugin.json",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@savvy-web/bundler": "0.5.0",
|
|
34
|
+
"@savvy-web/tsdown-plugins": "0.5.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@rspress/core": "^2.0.0",
|
|
38
|
+
"@tsdown/css": "^0.22.2",
|
|
39
|
+
"react": "^19.2.0",
|
|
40
|
+
"react-dom": "^19.2.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/public/ecma.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"composite": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationDir": "${configDir}/dist",
|
|
8
|
+
"declarationMap": false,
|
|
9
|
+
"emitDeclarationOnly": false,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"explainFiles": false,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"isolatedDeclarations": false,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"exactOptionalPropertyTypes": true,
|
|
17
|
+
"jsx": "preserve",
|
|
18
|
+
"lib": ["esnext"],
|
|
19
|
+
"module": "nodenext",
|
|
20
|
+
"moduleResolution": "nodenext",
|
|
21
|
+
"outDir": "${configDir}/dist",
|
|
22
|
+
"resolveJsonModule": true,
|
|
23
|
+
"rootDir": "${configDir}",
|
|
24
|
+
"skipLibCheck": true,
|
|
25
|
+
"sourceMap": false,
|
|
26
|
+
"strict": true,
|
|
27
|
+
"strictNullChecks": true,
|
|
28
|
+
"target": "es2025",
|
|
29
|
+
"tsBuildInfoFile": "${configDir}/dist/.tsbuildinfo.lib",
|
|
30
|
+
"typeRoots": ["${configDir}/node_modules/@types", "${configDir}/types"],
|
|
31
|
+
"verbatimModuleSyntax": true,
|
|
32
|
+
"types": ["node"]
|
|
33
|
+
},
|
|
34
|
+
"exclude": ["${configDir}/node_modules", "${configDir}/dist/**/*"],
|
|
35
|
+
"include": [
|
|
36
|
+
"${configDir}/types/*.ts",
|
|
37
|
+
"${configDir}/package.json",
|
|
38
|
+
"${configDir}/*.ts",
|
|
39
|
+
"${configDir}/*.cts",
|
|
40
|
+
"${configDir}/*.mts",
|
|
41
|
+
"${configDir}/src/**/*.ts",
|
|
42
|
+
"${configDir}/src/**/*.tsx",
|
|
43
|
+
"${configDir}/src/**/*.cts",
|
|
44
|
+
"${configDir}/src/**/*.mts",
|
|
45
|
+
"${configDir}/lib/**/*.ts",
|
|
46
|
+
"${configDir}/lib/**/*.tsx",
|
|
47
|
+
"${configDir}/lib/**/*.cts",
|
|
48
|
+
"${configDir}/lib/**/*.mts",
|
|
49
|
+
"${configDir}/__test__/**/*.ts",
|
|
50
|
+
"${configDir}/__test__/**/*.tsx",
|
|
51
|
+
"${configDir}/__test__/**/*.cts",
|
|
52
|
+
"${configDir}/__test__/**/*.mts",
|
|
53
|
+
"${configDir}/public/**/*.json"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Ambient module + import.meta.env declarations for RSPress plugin runtimes built with
|
|
2
|
+
// @savvy-web/rspress-builder. Replaces the rslib-era @rslib/core/types reference.
|
|
3
|
+
|
|
4
|
+
type CSSModuleClasses = Readonly<Record<string, string>>;
|
|
5
|
+
|
|
6
|
+
declare module "*.module.css" {
|
|
7
|
+
const classes: CSSModuleClasses;
|
|
8
|
+
export default classes;
|
|
9
|
+
}
|
|
10
|
+
declare module "*.css" {}
|
|
11
|
+
|
|
12
|
+
interface ImportMetaEnv {
|
|
13
|
+
readonly [key: string]: string | boolean | undefined;
|
|
14
|
+
/** RSPress static-site-generation markdown flag, resolved per site build. */
|
|
15
|
+
readonly SSG_MD?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface ImportMeta {
|
|
18
|
+
readonly env: ImportMetaEnv;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"lib": ["es2025", "dom"],
|
|
6
|
+
"types": ["node", "react", "react-dom"]
|
|
7
|
+
},
|
|
8
|
+
"exclude": ["${configDir}/node_modules", "${configDir}/dist"],
|
|
9
|
+
"extends": "../ecma.json",
|
|
10
|
+
"include": ["${configDir}/types/*.d.ts", "${configDir}/src/**/*.ts", "${configDir}/src/**/*.tsx"]
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.58.9"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|