@bleedingdev/modern-js-create 3.2.0-ultramodern.98 → 3.2.0-ultramodern.99

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.
Files changed (34) hide show
  1. package/package.json +3 -3
  2. package/template/.agents/skills-lock.json +34 -0
  3. package/template/.browserslistrc +4 -0
  4. package/template/.codex/hooks.json +16 -0
  5. package/template/.github/renovate.json +53 -0
  6. package/template/.github/workflows/ultramodern-gates.yml.handlebars +54 -0
  7. package/template/.gitignore.handlebars +30 -0
  8. package/template/.mise.toml.handlebars +2 -0
  9. package/template/.nvmrc +2 -0
  10. package/template-workspace/.agents/agent-reference-repos.json +24 -0
  11. package/template-workspace/.agents/rstackjs-agent-skills-LICENSE +21 -0
  12. package/template-workspace/.agents/skills/rsbuild-best-practices/SKILL.md +57 -0
  13. package/template-workspace/.agents/skills/rsdoctor-analysis/SKILL.md +96 -0
  14. package/template-workspace/.agents/skills/rsdoctor-analysis/references/command-map.md +113 -0
  15. package/template-workspace/.agents/skills/rsdoctor-analysis/references/common-analysis-patterns.md +190 -0
  16. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-common.md +88 -0
  17. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-rspack.md +138 -0
  18. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-webpack.md +71 -0
  19. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor.md +39 -0
  20. package/template-workspace/.agents/skills/rsdoctor-analysis/references/rsdoctor-data-types.md +103 -0
  21. package/template-workspace/.agents/skills/rslib-best-practices/SKILL.md +58 -0
  22. package/template-workspace/.agents/skills/rslib-modern-package/SKILL.md +173 -0
  23. package/template-workspace/.agents/skills/rspack-best-practices/SKILL.md +70 -0
  24. package/template-workspace/.agents/skills/rspack-tracing/SKILL.md +75 -0
  25. package/template-workspace/.agents/skills/rspack-tracing/references/bottlenecks.md +47 -0
  26. package/template-workspace/.agents/skills/rspack-tracing/references/tracing-guide.md +38 -0
  27. package/template-workspace/.agents/skills/rspack-tracing/scripts/analyze_trace.js +184 -0
  28. package/template-workspace/.agents/skills/rstest-best-practices/SKILL.md +133 -0
  29. package/template-workspace/.agents/skills-lock.json +114 -0
  30. package/template-workspace/.codex/hooks.json +16 -0
  31. package/template-workspace/.github/renovate.json +29 -0
  32. package/template-workspace/.github/workflows/ultramodern-workspace-gates.yml.handlebars +54 -0
  33. package/template-workspace/.gitignore.handlebars +5 -0
  34. package/template-workspace/.mise.toml.handlebars +2 -0
@@ -0,0 +1,190 @@
1
+ # Common Analysis Patterns
2
+
3
+ Use this reference for common Rspack/Webpack bundle analysis questions after locating `rsdoctor-data.json`.
4
+
5
+ ## Similar Packages
6
+
7
+ Use direct dependency package data to inspect similar packages. Start with `packages direct-dependencies` or `query packages_direct_dependencies`, then check known package families and other potentially similar packages.
8
+
9
+ Suggested flow:
10
+
11
+ 1. Fetch direct dependency package data with `packages direct-dependencies` or `query packages_direct_dependencies`. Use `--filter` fields for package name, version, issuer/dependency relation, and size when available.
12
+ 2. Treat this direct dependency list as the replacement-candidate set. Do not make replacement recommendations from indirect package-only evidence.
13
+ 3. Check the known families below. The presence of one package from a family is fine; only consider replacement when multiple packages from the same family are present.
14
+ 4. After known-family checks, inspect the direct dependency list for other potentially similar packages not listed below. Treat these as candidates only when package purpose overlaps clearly; avoid speculative replacement advice.
15
+ 5. Use `packages similar` or `query packages_similar` as an additional signal, not the only source of evidence.
16
+
17
+ Similar package families:
18
+
19
+ 1. `lodash`, `lodash-es`
20
+ - Consider migrating from `lodash` to `lodash-es` for better tree-shaking support when both are present.
21
+ 2. `dayjs`, `moment`, `date-fns`, `js-joda`
22
+ - Consider replacing `moment` with `dayjs` for smaller bundle size when both are present and project requirements allow it.
23
+ 3. `antd`, `material-ui`, `semantic-ui-react`, `arco-design`
24
+ 4. `axios`, `node-fetch`
25
+ 5. `redux`, `mobx`, `zustand`, `recoil`, `jotai`
26
+ 6. `chalk`, `colors`, `picocolors`, `kleur`
27
+ 7. `fs-extra`, `graceful-fs`
28
+
29
+ If there are no similar packages, simply say there are no similar packages. Do not list packages that merely exist in the project.
30
+
31
+ Keep the response simple: name only coexisting known-family packages or other direct-dependency candidates with clear overlap, explain why coexistence is worth reviewing, and give one replacement direction if the evidence supports it.
32
+
33
+ ## Media Asset Analysis
34
+
35
+ Use `assets media` or `bundle optimize` when checking oversized image, font, or video assets. Return recommendations only for assets that are actually oversized or relevant to the user's question.
36
+
37
+ Image thresholds:
38
+
39
+ - Mobile: one image file should ideally be under `60 KB`; Base64 SVG should ideally be under `7 KB`.
40
+ - PC: one image file should ideally be under `200 KB`; Base64 SVG should ideally be under `20 KB`.
41
+
42
+ Image recommendations:
43
+
44
+ - Compress large images with image compression tools such as `@rsbuild/plugin-image-compress` (`svgo` for SVG and `@napi-rs/image` for other images).
45
+ - Optimize SVG paths with tools such as SVGO.
46
+ - Consider whether SVG is necessary for the asset.
47
+ - Choose formats by compression characteristics:
48
+ - PNG works best for images with few colors and sharp boundaries, such as text or simple patterns.
49
+ - JPG works best for natural images with gradients and irregular transitions, such as landscapes and portraits.
50
+ - Base64 is suitable for important small images that should avoid extra requests and render immediately. Base64 increases binary size by about one third, but after gzip the increase is usually no more than about 10%.
51
+
52
+ Font thresholds:
53
+
54
+ - Prefer `.woff2`.
55
+ - Keep a single font file under `100 KB` when possible.
56
+ - Keep total font size under `300 KB` for the page, and under `200 KB` for mobile when possible.
57
+ - Avoid font formats other than `ttf`, `woff`, and `woff2` unless there is a compatibility requirement.
58
+
59
+ Font recommendations:
60
+
61
+ - Prefer system fonts when custom fonts are not required.
62
+ - Use `font-display: swap` or `@font-face unicode-range` for more efficient loading.
63
+ - Ensure server-side Gzip or Brotli compression is enabled.
64
+ - Consider variable fonts when they replace multiple weight or width files.
65
+
66
+ Video thresholds:
67
+
68
+ - Keep a single video file under `500 KB` when possible.
69
+ - Keep total video resources loaded on a page under `1 MB` when possible.
70
+
71
+ Video recommendations:
72
+
73
+ - Compress video files with tools such as HandBrake or FFmpeg.
74
+ - Use MP4 (H.264) as the compatibility default.
75
+ - Use WebM (VP9) when modern-browser compression benefits justify it.
76
+ - Lazy-load non-critical videos.
77
+ - Use HLS or DASH for long videos.
78
+ - Remove unused videos.
79
+ - Tune `preload`:
80
+ - `none`: do not download until playback starts; useful for videos unlikely to be played.
81
+ - `metadata`: downloads metadata only, often around 3% of file size.
82
+ - `auto`: downloads the full video; use only when playback is very likely.
83
+
84
+ ## Bundle Optimize
85
+
86
+ Use `bundle optimize` / `build optimize` as an aggregate optimization pass. It can combine evidence from:
87
+
88
+ - Duplicate package rules (`getRuleInfo` / `errors list` / rule details).
89
+ - Similar package checks (`packages similar` / `query packages_similar`).
90
+ - Media asset checks (`assets media`).
91
+ - Chunk checks (`chunks list`, `chunks large`, or chunk details) for oversized resources and `splitChunks` recommendations.
92
+
93
+ Do not run `bundle optimize` / `build optimize` in the default analysis path. Use it only for a user-requested optimization deep dive or when the compact default evidence set is missing required fields.
94
+
95
+ When using it, keep output compact with `--compact`, narrow `--filter` fields, and pagination options such as `--side-effects-page-size 10`. If the command still returns thousands of lines, stop and switch to narrower supporting commands.
96
+
97
+ Do not treat aggregate output as enough by itself when the recommendation needs concrete evidence. Fetch the narrow supporting data before recommending a config or dependency change.
98
+
99
+ ## Build Performance
100
+
101
+ Use these as short recommendation candidates when Rsdoctor evidence points to build-time cost, loader cost, too many modules, or slow dev rebuilds. Source: [Rsbuild build performance guide](https://rsbuild.rs/zh/guide/optimization/build-performance).
102
+
103
+ - Start with build performance analysis. Use measured bottlenecks before recommending config changes. Use Rsdoctor loader costs data.
104
+ - General improvements: upgrade Rsbuild, enable `performance.buildCache` for faster rebuilds, reduce module count, and keep Tailwind CSS v3 `content` narrow and correct.
105
+ - Tooling choices: prefer SWC over Babel transforms, avoid Less-heavy pipelines when possible, and prefer faster minification such as Rsbuild/Rspack SWC minification over Terser when compatible.
106
+ - Sass handling: do not send already-built `node_modules/**/*.css` through `sass-loader`; prefer third-party `dist/*.css` outputs when available. Compile third-party `.scss` / `.sass` only when Sass source features are required, such as variables, mixins, functions, or theme customization, and use an allowlist for those packages instead of all `node_modules`.
107
+ - Less projects: if many Less files are present, consider `@rsbuild/plugin-less` parallel compilation.
108
+ - Development mode: consider `dev.lazyCompilation`, Rspack `experiments.nativeWatcher`, cheaper or disabled dev source maps, and a narrower development Browserslist.
109
+ - Rsdoctor loader evidence: if `sass-loader` time is concentrated in third-party package directories and those packages ship CSS artifacts, recommend importing the CSS artifact or narrowing Sass rule `include` to app source plus specific allowlisted theme packages.
110
+ - Call out tradeoffs: development Browserslist and source map changes can make dev output differ from production or reduce debugging detail.
111
+
112
+ ## Retained Module Tree-shaking Analysis
113
+
114
+ Use `tree-shaking retained-modules` for first-pass tree-shaking evidence when the goal is to find retained emitted modules by reason category. Prefer it over broad `tree-shaking summary` when the user asks for top retained modules, CommonJS retention, barrel imports, side effects, or gzip-size priority.
115
+
116
+ Recommended first-pass command shape:
117
+
118
+ ```bash
119
+ rsdoctor-agent tree-shaking retained-modules \
120
+ --data-file dist/rsdoctor-data.json \
121
+ --emitted-only \
122
+ --category cjs,barrel,side-effects \
123
+ --sort gzipSize \
124
+ --limit 10 \
125
+ --filter id,path,packageName,version,category,size,chunks,bailoutReason,recommendation
126
+ ```
127
+
128
+ Guidance:
129
+
130
+ 1. Keep `--emitted-only` by default so findings map to shipped bundle impact.
131
+ 2. Use `--category cjs,barrel,side-effects` for optimization scans; narrow `--category` when the user asks about one class.
132
+ 3. Sort by `gzipSize` for bundle impact, unless the user asks for source or parsed size.
133
+ 4. Keep `--limit` bounded. Use `--limit 10` for default analysis. Increase to `50` only for user-requested deep dives.
134
+ 5. Do not add `--compact`; `tree-shaking retained-modules` output size is controlled with `--limit` and `--filter`.
135
+ 6. Report rows as `Path | Package | Category | Gzip/Parsed Size | Chunks | Bailout | Recommendation`.
136
+ 7. Treat results as first-pass evidence. Use `modules issuer` only after the user asks to trace who imported a retained module.
137
+
138
+ ## Common Questions
139
+
140
+ ### Why is a module not tree-shaken?
141
+
142
+ Example: "Why is `node_modules/rc-tree/lib/util.js` not tree-shaken?"
143
+
144
+ - Start with `tree-shaking retained-modules` filtered to id, path, package, category, size, chunks, bailout reason, and recommendation when the module appears in emitted output.
145
+ - Use `tree-shaking summary` only when retained modules do not include the needed field or the question needs broader aggregate context.
146
+ - Return the module's `bailoutReason`.
147
+ - Explain the bailout in plain language.
148
+ - Show `issuerPath` only when the user asks for chain tracing or when it is necessary to explain the issue.
149
+
150
+ ### Who imported a module?
151
+
152
+ Example: "Who imported `lodash-es/constant.js`?"
153
+
154
+ - Use module lookup by path, then issuer/import-chain data.
155
+ - Show the dependency chain using arrow notation or a tree.
156
+
157
+ ### Show modules with side effects
158
+
159
+ Example: "Show all modules with side effects."
160
+
161
+ - Prefer `tree-shaking retained-modules --emitted-only --category side-effects` for emitted side-effect modules.
162
+ - Fall back to `tree-shaking summary` or the relevant module-side-effects command only when retained-module output is insufficient.
163
+ - Filter to module id, path, package, size, chunks, bailout reason, and recommendation.
164
+ - List modules with non-empty `bailoutReason` containing `side_effects`.
165
+ - Use `--limit 10` for default output. Increase only after user confirmation.
166
+ - If falling back to `tree-shaking summary` or `modules side-effects`, use `--page-size 10` or `--side-effects-page-size 10`, keep the same narrow fields, and stop expanding when one command exceeds `5k` tokens or `500 KB` raw output.
167
+ - Sort by size, give priority to the largest emitted modules.
168
+
169
+ ### Why is a package duplicated?
170
+
171
+ Example: "Why is package X duplicated?"
172
+
173
+ - Use duplicate package rule data (`E1001` / `E1002`) and package graph fields.
174
+ - Show which chunks and modules contain the duplicate versions.
175
+ - Explain the dependency path if the user asks to continue chain tracing.
176
+
177
+ ### Which modules are not tree-shaken because of side effects?
178
+
179
+ - Use the E1007 rule results directly to identify modules that are not tree-shaken due to side effects. By `tree-shaking summary`.
180
+ - If further details are needed, you may also use `tree-shaking retained-modules --emitted-only --category side-effects` and filter to module id, path, package, size, chunks, bailout reason, and recommendation.
181
+ - List modules with `bailoutReason` containing `side_effects`.
182
+ - Use `--limit 10` by default and the same `5k` token / `500 KB` raw-output stop rule for fallback commands.
183
+ - Show `issuerPath` when needed to identify the import source.
184
+
185
+ ## Output Style
186
+
187
+ - For dependency chains, use a tree or arrow notation.
188
+ - For module details, use a table or key-value list.
189
+ - For explanations, use concise, plain language.
190
+ - Avoid listing all packages or assets when the finding is empty.
@@ -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.
@@ -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).
@@ -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.