@bleedingdev/modern-js-create 3.2.0-ultramodern.5 → 3.2.0-ultramodern.7
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/dist/index.js +34 -5
- package/package.json +4 -1
- package/template-workspace/.agents/rstackjs-agent-skills-LICENSE +21 -0
- package/template-workspace/.agents/skills/rsbuild-best-practices/SKILL.md +57 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/SKILL.md +96 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/command-map.md +113 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/common-analysis-patterns.md +190 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-common.md +88 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-rspack.md +138 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-webpack.md +71 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor.md +39 -0
- package/template-workspace/.agents/skills/rsdoctor-analysis/references/rsdoctor-data-types.md +103 -0
- package/template-workspace/.agents/skills/rslib-best-practices/SKILL.md +58 -0
- package/template-workspace/.agents/skills/rslib-modern-package/SKILL.md +173 -0
- package/template-workspace/.agents/skills/rspack-best-practices/SKILL.md +70 -0
- package/template-workspace/.agents/skills/rspack-tracing/SKILL.md +75 -0
- package/template-workspace/.agents/skills/rspack-tracing/references/bottlenecks.md +47 -0
- package/template-workspace/.agents/skills/rspack-tracing/references/tracing-guide.md +38 -0
- package/template-workspace/.agents/skills/rspack-tracing/scripts/analyze_trace.js +184 -0
- package/template-workspace/.agents/skills/rstest-best-practices/SKILL.md +133 -0
- package/template-workspace/.agents/skills-lock.json +56 -0
- package/template-workspace/AGENTS.md +28 -0
- package/template-workspace/scripts/validate-ultramodern-workspace.mjs.handlebars +67 -0
package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-common.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Common Steps for Rsdoctor Installation
|
|
2
|
+
|
|
3
|
+
This document contains common steps that apply to both Rspack and Webpack projects.
|
|
4
|
+
|
|
5
|
+
## Step 3: Locate the rsdoctor-data.json
|
|
6
|
+
|
|
7
|
+
First, use the fast path to check whether `rsdoctor-data.json` already exists. If the user provided a path, check that path first. Otherwise check common build artifact/output locations before any package-manager, install, config, or build command:
|
|
8
|
+
|
|
9
|
+
- `dist/rsdoctor-data.json` (most common)
|
|
10
|
+
- `output/rsdoctor-data.json`
|
|
11
|
+
- `static/rsdoctor-data.json`
|
|
12
|
+
- `.rsdoctor/rsdoctor-data.json` (if using custom reportDir)
|
|
13
|
+
|
|
14
|
+
If common paths do not contain the file, run one bounded local file search that excludes expensive directories, for example `rg --files -g 'rsdoctor-data.json' -g '!node_modules' -g '!**/.git/**'`. If `rsdoctor-data.json` is found, skip the generation/version gate and go directly to JSON analysis. If it is not found, do not run any `rsdoctor-agent` analysis command; ask for the data path or generate the file first.
|
|
15
|
+
|
|
16
|
+
For repeated analysis in the same repository, use a lightweight project-local cache such as `.rsdoctor-analysis-cache.json`. Reuse it only when the cached data-file path still exists and cached modification times match the current `rsdoctor-data.json`, dependency files (`package.json`, lock files), relevant build config files, and plugin `package.json` if recorded. Refresh the cache after locating a new data file or confirming a plugin version.
|
|
17
|
+
|
|
18
|
+
When the runtime supports parallel execution, run independent local initialization checks concurrently: common path checks, bounded `rg --files` lookup, and local plugin-version file reads. Do not run `rsdoctor-agent` CLI checks until a real `rsdoctor-data.json` path exists. Treat plugin-version results as speculative until the data file is confirmed missing; never let parallel plugin checks trigger generation by themselves.
|
|
19
|
+
|
|
20
|
+
If you cannot find the file, ask the user to provide the path to `rsdoctor-data.json`. If the file truly does not exist and generation/setup is required, check the installed `@rsdoctor/rspack-plugin` or `@rsdoctor/webpack-plugin` version before changing config or running a build. The `@rsdoctor/agent-cli` version does not prove plugin support for `RSDOCTOR_OUTPUT=json`.
|
|
21
|
+
|
|
22
|
+
Required version gate (use exactly this if/else order):
|
|
23
|
+
|
|
24
|
+
1. Identify `pluginName`: `@rsdoctor/rspack-plugin` or `@rsdoctor/webpack-plugin`.
|
|
25
|
+
2. Determine `pluginVersion` from local files first: dependency declarations in `package.json`, lockfile entries, then installed `node_modules/<plugin>/package.json`. Use package-manager output such as `pnpm why @rsdoctor/rspack-plugin` / `npm ls @rsdoctor/rspack-plugin` only as a fallback.
|
|
26
|
+
3. Choose one branch; do not merge branches:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
if pluginName is missing:
|
|
30
|
+
install/register the matching Rsdoctor plugin, then MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
31
|
+
else if pluginVersion is unknown:
|
|
32
|
+
resolve pluginVersion first; if still unknown, MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
33
|
+
else if pluginVersion >= 1.5.11:
|
|
34
|
+
do not modify plugin config just for JSON; build with RSDOCTOR_OUTPUT=json and RSDOCTOR=true if needed
|
|
35
|
+
else: # pluginVersion < 1.5.11
|
|
36
|
+
MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Preflight every build command: `RSDOCTOR_OUTPUT=json` is allowed only in the `pluginVersion >= 1.5.11` branch. For missing, unknown, or `< 1.5.11` versions, a command such as `RSDOCTOR_OUTPUT=json RSDOCTOR=true pnpm run build:rspack` is incorrect.
|
|
40
|
+
|
|
41
|
+
The file is typically generated in the same directory as your build output (e.g., `dist`, `output`, `static`). For plugin versions < `1.5.11`, configure a custom output directory using the `output.reportDir` option:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// Example for Rspack: use RsdoctorRspackPlugin
|
|
45
|
+
// Example for Webpack: use RsdoctorWebpackPlugin
|
|
46
|
+
new RsdoctorRspackPlugin({
|
|
47
|
+
// or RsdoctorWebpackPlugin
|
|
48
|
+
disableClientServer: true,
|
|
49
|
+
output: {
|
|
50
|
+
mode: 'brief',
|
|
51
|
+
options: {
|
|
52
|
+
type: ['json'],
|
|
53
|
+
},
|
|
54
|
+
reportDir: './dist', // Custom output directory (defaults to build output directory)
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Step 4: Use JSON file for analysis
|
|
62
|
+
|
|
63
|
+
Once you have the `rsdoctor-data.json` file, you can use it for analysis. This JSON file contains all the build analysis data and can be used without starting the Rsdoctor server.
|
|
64
|
+
|
|
65
|
+
Analyze the JSON file with the `rsdoctor-agent` CLI from the repository root or another directory that can access the JSON file:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
rsdoctor-agent build summary --data-file ./dist/rsdoctor-data.json --filter "<fields>"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Keep analysis output small:
|
|
72
|
+
|
|
73
|
+
- Reuse already returned results from context/history first, then run only missing queries.
|
|
74
|
+
- Use `--filter` on data-fetch commands to return only fields required for the current question.
|
|
75
|
+
- Use first-pass summaries for duplicate packages and tree-shaking issues; ask before continuing reference-chain tracing.
|
|
76
|
+
- Stop broad commands when one response exceeds `5k` tokens (o200k_base) or `500 KB` raw output, then switch to filtered or targeted queries.
|
|
77
|
+
|
|
78
|
+
For command names, option scopes, tree-shaking command selection, and `--filter` guidance, use [command-map.md](command-map.md). For raw data field names, use [rsdoctor-data-types.md](rsdoctor-data-types.md).
|
|
79
|
+
|
|
80
|
+
**Benefits of JSON Mode:**
|
|
81
|
+
|
|
82
|
+
- ✅ No need to keep the build process running
|
|
83
|
+
- ✅ Works in CI/CD environments
|
|
84
|
+
- ✅ Can be shared and version controlled
|
|
85
|
+
- ✅ Faster analysis for large projects
|
|
86
|
+
- ✅ No server connection required
|
|
87
|
+
|
|
88
|
+
Note: `rsdoctor-data.json` can be large in complex projects. Add it to `.gitignore` if you do not want to commit it.
|
package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-rspack.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Install Rsdoctor Plugin for Rspack Projects
|
|
2
|
+
|
|
3
|
+
This guide covers installation for Rspack-based projects, including:
|
|
4
|
+
|
|
5
|
+
- Rspack CLI
|
|
6
|
+
- Rsbuild
|
|
7
|
+
- Modern.js
|
|
8
|
+
- Rslib
|
|
9
|
+
- Rspress
|
|
10
|
+
|
|
11
|
+
## Step 1: Install Dependencies
|
|
12
|
+
|
|
13
|
+
For projects based on Rspack, such as Rsbuild or Rslib:
|
|
14
|
+
|
|
15
|
+
**Note:** Prefer using the latest versions of the above dependencies when available.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm add @rsdoctor/rspack-plugin -D
|
|
19
|
+
pnpm add @rsdoctor/rspack-plugin -D
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Step 2: Register Plugin
|
|
23
|
+
|
|
24
|
+
After the dependency installation, check the installed `@rsdoctor/rspack-plugin` version before changing config or running a build. Do not infer plugin capabilities from `@rsdoctor/agent-cli --version`.
|
|
25
|
+
|
|
26
|
+
Required version gate (use exactly this if/else order):
|
|
27
|
+
|
|
28
|
+
1. Set `pluginName = '@rsdoctor/rspack-plugin'`.
|
|
29
|
+
2. Determine `pluginVersion` from local files first: dependency declarations in `package.json`, lockfile entries, then `node_modules/@rsdoctor/rspack-plugin/package.json` if installed. Use `pnpm why @rsdoctor/rspack-plugin` / `npm ls @rsdoctor/rspack-plugin` only as a fallback. When repeating analysis, reuse a valid `.rsdoctor-analysis-cache.json` plugin entry before re-reading files; invalidate it if `package.json`, lock files, or the plugin package file modification time changed.
|
|
30
|
+
3. Choose one branch; do not merge branches:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
if @rsdoctor/rspack-plugin is missing:
|
|
34
|
+
install/register @rsdoctor/rspack-plugin, then configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
35
|
+
else if pluginVersion is unknown:
|
|
36
|
+
resolve pluginVersion first; if still unknown, configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
37
|
+
else if pluginVersion >= 1.5.11:
|
|
38
|
+
do not modify plugin config just for JSON; build with RSDOCTOR_OUTPUT=json and RSDOCTOR=true if needed
|
|
39
|
+
else: # pluginVersion < 1.5.11
|
|
40
|
+
MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Preflight every build command: `RSDOCTOR_OUTPUT=json` is allowed only in the `pluginVersion >= 1.5.11` branch. For missing, unknown, or `< 1.5.11`, `RSDOCTOR_OUTPUT=json` is forbidden. For example, when `@rsdoctor/rspack-plugin` is `1.5.7`, this command is incorrect:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
RSDOCTOR_OUTPUT=json RSDOCTOR=true pnpm run build:rspack
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Below are configuration examples for old Rspack plugin versions, unknown versions, missing plugins, or projects that still need to register the plugin:
|
|
50
|
+
|
|
51
|
+
### Rspack CLI
|
|
52
|
+
|
|
53
|
+
Initialize the plugin in the [plugins](https://www.rspack.rs/config/plugins.html#plugins) of `rspack.config.ts`:
|
|
54
|
+
|
|
55
|
+
```ts title="rspack.config.ts"
|
|
56
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
plugins: [
|
|
60
|
+
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
61
|
+
process.env.RSDOCTOR &&
|
|
62
|
+
new RsdoctorRspackPlugin({
|
|
63
|
+
disableClientServer: true,
|
|
64
|
+
// Required for @rsdoctor/rspack-plugin < 1.5.11.
|
|
65
|
+
output: {
|
|
66
|
+
mode: 'brief',
|
|
67
|
+
options: {
|
|
68
|
+
type: ['json'],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Rsbuild/Rslib/Modern.js
|
|
77
|
+
|
|
78
|
+
See [Rsbuild - Use Rsdoctor](https://rsbuild.rs/guide/debug/rsdoctor) for more details.
|
|
79
|
+
If this is Modern.js project can see [tools.rspack](https://modernjs.dev/configure/app/tools/rspack) of `modern.config.ts`:
|
|
80
|
+
|
|
81
|
+
For `@rsdoctor/rspack-plugin` < `1.5.11`, configure JSON output in `rsbuild.config.ts`:
|
|
82
|
+
|
|
83
|
+
```ts title="rsbuild.config.ts"
|
|
84
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
85
|
+
|
|
86
|
+
export default {
|
|
87
|
+
tools: {
|
|
88
|
+
rspack: {
|
|
89
|
+
plugins: [
|
|
90
|
+
process.env.RSDOCTOR === 'true' &&
|
|
91
|
+
new RsdoctorRspackPlugin({
|
|
92
|
+
disableClientServer: true, // Prevent starting local server
|
|
93
|
+
output: {
|
|
94
|
+
mode: 'brief', // Required for plugin versions < 1.5.11
|
|
95
|
+
options: {
|
|
96
|
+
type: ['json'], // Only generate JSON data
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Rspress
|
|
107
|
+
|
|
108
|
+
For Rspress projects, configure the plugin in `builderConfig.tools.rspack`:
|
|
109
|
+
|
|
110
|
+
```ts title="rspress.config.ts"
|
|
111
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
112
|
+
import { defineConfig } from 'rspress/config';
|
|
113
|
+
|
|
114
|
+
export default defineConfig({
|
|
115
|
+
builderConfig: {
|
|
116
|
+
tools: {
|
|
117
|
+
rspack: {
|
|
118
|
+
plugins: [
|
|
119
|
+
process.env.RSDOCTOR === 'true' &&
|
|
120
|
+
new RsdoctorRspackPlugin({
|
|
121
|
+
disableClientServer: true, // Prevent starting local server
|
|
122
|
+
output: {
|
|
123
|
+
mode: 'brief', // Required for plugin versions < 1.5.11
|
|
124
|
+
options: {
|
|
125
|
+
type: ['json'], // Only generate JSON data
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Step 3 & 4: Locate and Use rsdoctor-data.json
|
|
137
|
+
|
|
138
|
+
For steps on locating the `rsdoctor-data.json` file and using it for analysis, see the [common installation guide](./install-rsdoctor-common.md).
|
package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-webpack.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Install Rsdoctor Plugin for Webpack Projects
|
|
2
|
+
|
|
3
|
+
This guide covers installation for Webpack projects (webpack >= 5).
|
|
4
|
+
|
|
5
|
+
## Step 1: Install Dependencies
|
|
6
|
+
|
|
7
|
+
Rsdoctor only supports webpack >= 5.
|
|
8
|
+
|
|
9
|
+
For projects based on webpack:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm add @rsdoctor/webpack-plugin -D
|
|
13
|
+
pnpm add @rsdoctor/webpack-plugin -D
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Step 2: Register Plugin
|
|
17
|
+
|
|
18
|
+
After the dependency installation, check the installed `@rsdoctor/webpack-plugin` version before changing config or running a build. Do not infer plugin capabilities from `@rsdoctor/agent-cli --version`.
|
|
19
|
+
|
|
20
|
+
Required version gate (use exactly this if/else order):
|
|
21
|
+
|
|
22
|
+
1. Set `pluginName = '@rsdoctor/webpack-plugin'`.
|
|
23
|
+
2. Determine `pluginVersion` from local files first: dependency declarations in `package.json`, lockfile entries, then `node_modules/@rsdoctor/webpack-plugin/package.json` if installed. Use `pnpm why @rsdoctor/webpack-plugin` / `npm ls @rsdoctor/webpack-plugin` only as a fallback. When repeating analysis, reuse a valid `.rsdoctor-analysis-cache.json` plugin entry before re-reading files; invalidate it if `package.json`, lock files, or the plugin package file modification time changed.
|
|
24
|
+
3. Choose one branch; do not merge branches:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
if @rsdoctor/webpack-plugin is missing:
|
|
28
|
+
install/register @rsdoctor/webpack-plugin, then configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
29
|
+
else if pluginVersion is unknown:
|
|
30
|
+
resolve pluginVersion first; if still unknown, configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
31
|
+
else if pluginVersion >= 1.5.11:
|
|
32
|
+
do not modify plugin config just for JSON; build with RSDOCTOR_OUTPUT=json and RSDOCTOR=true if needed
|
|
33
|
+
else: # pluginVersion < 1.5.11
|
|
34
|
+
MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Preflight every build command: `RSDOCTOR_OUTPUT=json` is allowed only in the `pluginVersion >= 1.5.11` branch. For missing, unknown, or `< 1.5.11`, `RSDOCTOR_OUTPUT=json` is forbidden. For example, when `@rsdoctor/webpack-plugin` is `1.5.7`, this command is incorrect:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
RSDOCTOR_OUTPUT=json RSDOCTOR=true pnpm run build
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Webpack
|
|
44
|
+
|
|
45
|
+
For old Webpack plugin versions, unknown versions, missing plugins, or projects that still need to register the plugin, initialize it in the [plugins](https://webpack.js.org/configuration/plugins/#plugins) of `webpack.config.js`:
|
|
46
|
+
|
|
47
|
+
```js title="webpack.config.js"
|
|
48
|
+
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
// ...
|
|
52
|
+
plugins: [
|
|
53
|
+
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
54
|
+
process.env.RSDOCTOR &&
|
|
55
|
+
new RsdoctorWebpackPlugin({
|
|
56
|
+
disableClientServer: true,
|
|
57
|
+
// Required for @rsdoctor/webpack-plugin < 1.5.11.
|
|
58
|
+
output: {
|
|
59
|
+
mode: 'brief',
|
|
60
|
+
options: {
|
|
61
|
+
type: ['json'],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
].filter(Boolean),
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Step 3 & 4: Locate and Use rsdoctor-data.json
|
|
70
|
+
|
|
71
|
+
For steps on locating the `rsdoctor-data.json` file and using it for analysis, see the [common installation guide](./install-rsdoctor-common.md).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Install Rsdoctor Plugin
|
|
2
|
+
|
|
3
|
+
This documentation has been split into project-specific guides:
|
|
4
|
+
|
|
5
|
+
## Choose Your Project Type
|
|
6
|
+
|
|
7
|
+
- **For Rspack/Rsbuild/Modern.js projects:** See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
8
|
+
- **For Webpack projects:** See [install-rsdoctor-webpack.md](./install-rsdoctor-webpack.md)
|
|
9
|
+
|
|
10
|
+
## Quick Decision Guide
|
|
11
|
+
|
|
12
|
+
**Determine your project type:**
|
|
13
|
+
|
|
14
|
+
1. **Check project type** (`projectType`):
|
|
15
|
+
- If project uses **Rspack** (including Rsbuild, Rslib, or any Rspack-based project) → Use `projectType: 'rspack'` → See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
16
|
+
- If project uses **Webpack** (webpack >= 5) → Use `projectType: 'webpack'` → See [install-rsdoctor-webpack.md](./install-rsdoctor-webpack.md)
|
|
17
|
+
|
|
18
|
+
2. **Check framework** (`framework`):
|
|
19
|
+
- If using **Rspack CLI** → `framework: 'rspack'` → See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
20
|
+
- If using **Rsbuild** → `framework: 'rsbuild'` → See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
21
|
+
- If using **Modern.js** → `framework: 'modern.js'` → See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
22
|
+
- If using **Rslib** → `framework: 'rslib'` → See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
23
|
+
- If using **Rspress** → `framework: 'rspress'` → See [install-rsdoctor-rspack.md](./install-rsdoctor-rspack.md)
|
|
24
|
+
- If using **Webpack** → `framework: 'webpack'` → See [install-rsdoctor-webpack.md](./install-rsdoctor-webpack.md)
|
|
25
|
+
|
|
26
|
+
**Decision flow:**
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
User's project
|
|
30
|
+
├─ Is it Rspack-based? (Rsbuild, Rslib, Rspress, etc.)
|
|
31
|
+
│ ├─ Yes → projectType: 'rspack'
|
|
32
|
+
│ │ ├─ Rspack CLI? → framework: 'rspack' → install-rsdoctor-rspack.md
|
|
33
|
+
│ │ ├─ Rsbuild? → framework: 'rsbuild' → install-rsdoctor-rspack.md
|
|
34
|
+
│ │ ├─ Rslib? → framework: 'rslib' → install-rsdoctor-rspack.md
|
|
35
|
+
│ │ ├─ Rspress? → framework: 'rspress' → install-rsdoctor-rspack.md
|
|
36
|
+
│ │ └─ Modern.js? → framework: 'modern.js' → install-rsdoctor-rspack.md
|
|
37
|
+
│ └─ No → Is it Webpack >= 5?
|
|
38
|
+
│ └─ Yes → projectType: 'webpack', framework: 'webpack' → install-rsdoctor-webpack.md
|
|
39
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Rsdoctor Data Type Context
|
|
2
|
+
|
|
3
|
+
Use this reference when a task requires understanding raw `rsdoctor-data.json` fields, schema, or nested data attributes.
|
|
4
|
+
|
|
5
|
+
## Source of Truth
|
|
6
|
+
|
|
7
|
+
Read type definitions from the published npm package `@rsdoctor/types`. Do not use local repository `dist/` artifacts unless the user explicitly asks for local development branch behavior.
|
|
8
|
+
|
|
9
|
+
Brief JSON output has this wrapper shape:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import type { Manifest, SDK } from '@rsdoctor/types';
|
|
13
|
+
|
|
14
|
+
export interface RsdoctorDataJson {
|
|
15
|
+
data: SDK.BuilderStoreData;
|
|
16
|
+
clientRoutes: Manifest.RsdoctorManifestClientRoutes[];
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The core payload type is `SDK.BuilderStoreData`.
|
|
21
|
+
|
|
22
|
+
## npm Lookup Flow
|
|
23
|
+
|
|
24
|
+
Prefer the npm registry/package interface.
|
|
25
|
+
|
|
26
|
+
Use the latest published package unless the user gives a specific Rsdoctor package version or asks to match an installed project version.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm view @rsdoctor/types version dist.tarball --json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If command execution is unavailable, use the registry endpoint directly:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
https://registry.npmjs.org/@rsdoctor%2Ftypes/latest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Read the `dist.tarball` URL from the response, download the tarball, and inspect `.d.ts` files under `package/dist/`.
|
|
39
|
+
|
|
40
|
+
If matching an installed project version is important:
|
|
41
|
+
|
|
42
|
+
1. Inspect the project package versions for `@rsdoctor/rspack-plugin`, `@rsdoctor/webpack-plugin`, `@rsdoctor/core`, `@rsdoctor/sdk`, or `@rsdoctor/types`.
|
|
43
|
+
2. Query the matching type package:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm view @rsdoctor/types@<version> version dist.tarball --json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
3. If that exact version does not exist, use the closest compatible published `@rsdoctor/types` version and state the version mismatch.
|
|
50
|
+
|
|
51
|
+
## Files to Inspect
|
|
52
|
+
|
|
53
|
+
Start here:
|
|
54
|
+
|
|
55
|
+
- `package/dist/index.d.ts`: namespace exports. `SDK` comes from `./sdk/index.js`; `Manifest` comes from `./manifest.js`.
|
|
56
|
+
- `package/dist/sdk/index.d.ts`: exports all SDK data subtypes.
|
|
57
|
+
- `package/dist/sdk/result.d.ts`: defines `BuilderStoreData`, the `rsdoctor-data.json.data` payload.
|
|
58
|
+
- `package/dist/manifest.d.ts`: defines client routes and manifest types.
|
|
59
|
+
|
|
60
|
+
Then load nested files as needed:
|
|
61
|
+
|
|
62
|
+
- `package/dist/sdk/module.d.ts`: `moduleGraph`, modules, dependencies, source ranges, module code, tree-shaking-linked module data.
|
|
63
|
+
- `package/dist/sdk/chunk.d.ts`: `chunkGraph`, assets, chunks, entrypoints.
|
|
64
|
+
- `package/dist/sdk/package.d.ts`: `packageGraph`, package dependency data, duplicate package reports, other reports.
|
|
65
|
+
- `package/dist/sdk/loader.d.ts`: loader timing/input/output data.
|
|
66
|
+
- `package/dist/sdk/resolver.d.ts`: resolver data.
|
|
67
|
+
- `package/dist/sdk/plugin.d.ts`: plugin hook/tap timing data.
|
|
68
|
+
- `package/dist/sdk/summary.d.ts`: build summary/cost data.
|
|
69
|
+
- `package/dist/sdk/config.d.ts`: collected bundler config data.
|
|
70
|
+
- `package/dist/sdk/envinfo.d.ts`: environment info data.
|
|
71
|
+
- `package/dist/rule/data.d.ts`: `errors`/rule store data.
|
|
72
|
+
|
|
73
|
+
## Field Map
|
|
74
|
+
|
|
75
|
+
`SDK.BuilderStoreData` contains:
|
|
76
|
+
|
|
77
|
+
- `hash`: build hash.
|
|
78
|
+
- `root`: project root.
|
|
79
|
+
- `pid`: process id.
|
|
80
|
+
- `envinfo`: environment information.
|
|
81
|
+
- `errors`: rule/error store data.
|
|
82
|
+
- `configs`: collected bundler config data.
|
|
83
|
+
- `summary`: build summary data.
|
|
84
|
+
- `resolver`: resolver events.
|
|
85
|
+
- `loader`: loader transform events.
|
|
86
|
+
- `plugin`: plugin hook/tap events.
|
|
87
|
+
- `moduleGraph`: module graph data.
|
|
88
|
+
- `chunkGraph`: asset/chunk/entrypoint graph data.
|
|
89
|
+
- `packageGraph`: package/dependency graph data.
|
|
90
|
+
- `moduleCodeMap`: module source/code map data.
|
|
91
|
+
- `treeShaking`: optional tree-shaking data.
|
|
92
|
+
- `otherReports`: optional extra report payloads.
|
|
93
|
+
|
|
94
|
+
In brief JSON mode, `moduleCodeMap` is normally `{}` and `treeShaking` is normally absent unless generated by a mode that includes it.
|
|
95
|
+
|
|
96
|
+
## Usage Guidance
|
|
97
|
+
|
|
98
|
+
- Cite the npm package version used when explaining fields.
|
|
99
|
+
- Distinguish wrapper fields (`data`, `clientRoutes`) from `SDK.BuilderStoreData` fields.
|
|
100
|
+
- When a nested field is unclear, inspect the specific `.d.ts` file instead of guessing.
|
|
101
|
+
- Use these types to construct `@rsdoctor/agent-cli --filter` field selections before each data fetch. Prefer the smallest field set that can answer the current question.
|
|
102
|
+
- Match filters to the relevant data domain: chunks from `chunkGraph`, modules and tree-shaking module details from `moduleGraph`/`treeShaking`, packages from `packageGraph`, loader cost from `loader`, build cost from `summary`, and rule findings from `errors`.
|
|
103
|
+
- For analysis recommendations, prefer `@rsdoctor/agent-cli` commands. Use these types for schema explanation, prompt grounding, or validating raw JSON field names.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rslib-best-practices
|
|
3
|
+
description: Rslib best practices for config, CLI workflow, output, declaration files, dependency handling, build optimization and toolchain integration. Use when writing, reviewing, or troubleshooting Rslib projects.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Rslib Best Practices
|
|
7
|
+
|
|
8
|
+
Apply these rules when writing or reviewing Rslib library projects.
|
|
9
|
+
|
|
10
|
+
## Configuration
|
|
11
|
+
|
|
12
|
+
- Use `rslib.config.ts` and `defineConfig`
|
|
13
|
+
- Check Rslib-specific configurations first (e.g., `lib.*`), and also leverage Rsbuild configurations (e.g., `source.*`, `output.*`, `tools.*`) as needed
|
|
14
|
+
- For deep-level or advanced configuration needs, use `tools.rspack` or `tools.bundlerChain` to access Rspack's native configurations
|
|
15
|
+
- In TypeScript projects, prefer `tsconfig.json` path aliases
|
|
16
|
+
|
|
17
|
+
## CLI
|
|
18
|
+
|
|
19
|
+
- Use `rslib` to build
|
|
20
|
+
- Use `rslib --watch` to build in watch mode for local development
|
|
21
|
+
- Use `rslib inspect` to inspect final Rslib/Rsbuild/Rspack configs
|
|
22
|
+
|
|
23
|
+
## Output
|
|
24
|
+
|
|
25
|
+
- Prefer to build pure-ESM package with `"type": "module"` in `package.json`
|
|
26
|
+
- Prefer to use bundleless mode with `output.target` set to `'web'` when building component libraries
|
|
27
|
+
- Prefer to use bundle mode when building Node.js utility libraries
|
|
28
|
+
- Ensure `exports` field in `package.json` is correctly configured and matches the actual JavaScript output and declaration files output of different formats (ESM, CJS, etc.)
|
|
29
|
+
|
|
30
|
+
## Declaration files
|
|
31
|
+
|
|
32
|
+
- Prefer to enable declaration file generation with `lib.dts: true` or detailed configurations
|
|
33
|
+
- For faster type generation, enable `lib.dts.tsgo` experimental feature with `@typescript/native-preview` installed
|
|
34
|
+
|
|
35
|
+
## Dependencies
|
|
36
|
+
|
|
37
|
+
- Prefer to place dependencies to be bundled in `devDependencies` in bundle mode and dependencies in `dependencies` and `peerDependencies` will be automatically externalized (not bundled) by default
|
|
38
|
+
- Verify the build output and dependency specifiers in `package.json` carefully to ensure no missing dependency errors occur when consumers install and use this package
|
|
39
|
+
|
|
40
|
+
## Build optimization
|
|
41
|
+
|
|
42
|
+
- Keep syntax target in `lib.syntax` aligned with real compatibility requirements to enable better optimizations
|
|
43
|
+
- Avoid format-specific APIs in source code for better compatibility with different output formats
|
|
44
|
+
- Prefer lightweight dependencies to reduce bundle size
|
|
45
|
+
|
|
46
|
+
## Toolchain integration
|
|
47
|
+
|
|
48
|
+
- Prefer to use Rstest with `@rstest/adapter-rslib` for writing tests
|
|
49
|
+
- Prefer to use Rspress for writing library documentation, with `@rspress/plugin-preview` and `@rspress/plugin-api-docgen` for component previews and API docs
|
|
50
|
+
|
|
51
|
+
## Debugging
|
|
52
|
+
|
|
53
|
+
- Run with `DEBUG=rsbuild` when diagnosing config resolution or plugin behavior
|
|
54
|
+
- Read generated files in `dist/.rsbuild` to confirm final Rsbuild/Rspack config, not assumed config
|
|
55
|
+
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
- For the latest Rslib docs, read https://rslib.rs/llms.txt
|