Skip to content

Commit f96461d

Browse files
justin808claude
andcommitted
Improve diff output with contextual information and fix path normalization
Address code review feedback: 1. Fix basePath detection to use separate paths for left/right configs - Each side now detects its own base path independently - More accurate normalization when comparing configs from different locations 2. Remove no-op map in createHumanPath - Simplified path formatting by removing pointless transformation - Cleaner, more maintainable code 3. Fix looksLikePath to avoid normalizing URLs and module specifiers - Explicitly exclude URL schemes (http://, webpack://, etc.) - Exclude npm module specifiers starting with @ - Only match actual filesystem paths (absolute, relative, home, Windows drives) - Prevents incorrect normalization of webpack:// URLs and @scope/package names 4. Replace summary/detailed formats with contextual format - Shows "What it does" explanations for webpack config keys - Includes impact analysis (e.g., "Enabling production optimizations") - Links to official webpack documentation - Displays default values where applicable - Much more useful for understanding WHY something changed 5. Add comprehensive configuration documentation database - 20+ documented webpack/rspack configuration keys - Covers mode, devtool, optimization, output, devServer, etc. - Extensible for future additions New output format example: 1. [~] mode What it does: Defines the environment mode (development, production, or none). Controls built-in optimizations and defaults. Affects: Minification, tree-shaking, source maps, and performance optimizations Old value: "development" New value: "production" Impact: Enabling production optimizations (minification, tree-shaking) Documentation: https://webpack.js.org/configuration/mode/ Summary format is now concise: "8 changes: +3 -1 ~4" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent dc8cc00 commit f96461d

File tree

6 files changed

+362
-109
lines changed

6 files changed

+362
-109
lines changed

package/configDiffer/cli.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ export async function run(args: string[]): Promise<number> {
3636
let normalizedRight = rightConfig
3737

3838
if (options.normalizePaths) {
39-
const basePath =
39+
const leftBasePath =
4040
PathNormalizer.detectBasePath(leftConfig) || process.cwd()
41-
const normalizer = new PathNormalizer(basePath)
42-
normalizedLeft = normalizer.normalize(leftConfig).normalized
43-
normalizedRight = normalizer.normalize(rightConfig).normalized
41+
const rightBasePath =
42+
PathNormalizer.detectBasePath(rightConfig) || process.cwd()
43+
44+
const leftNormalizer = new PathNormalizer(leftBasePath)
45+
const rightNormalizer = new PathNormalizer(rightBasePath)
46+
47+
normalizedLeft = leftNormalizer.normalize(leftConfig).normalized
48+
normalizedRight = rightNormalizer.normalize(rightConfig).normalized
4449
}
4550

4651
const diffEngine = new DiffEngine(options)

package/configDiffer/configDocs.ts

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Configuration documentation for webpack/rspack keys
2+
// This provides contextual information about what each configuration key means
3+
4+
interface ConfigDoc {
5+
description: string
6+
defaultValue?: string
7+
affects?: string
8+
documentationUrl?: string
9+
}
10+
11+
const WEBPACK_CONFIG_DOCS: Record<string, ConfigDoc> = {
12+
mode: {
13+
description:
14+
"Defines the environment mode (development, production, or none). " +
15+
"Controls built-in optimizations and defaults.",
16+
affects:
17+
"Minification, tree-shaking, source maps, and performance optimizations",
18+
documentationUrl: "https://webpack.js.org/configuration/mode/"
19+
},
20+
devtool: {
21+
description:
22+
"Controls how source maps are generated for debugging. " +
23+
"Different values trade off between build speed and debugging quality.",
24+
affects: "Build speed, debugging experience, and bundle size",
25+
documentationUrl: "https://webpack.js.org/configuration/devtool/"
26+
},
27+
"output.path": {
28+
description: "The output directory for compiled bundles (absolute path).",
29+
affects: "Where webpack writes compiled files",
30+
documentationUrl: "https://webpack.js.org/configuration/output/#outputpath"
31+
},
32+
"output.publicPath": {
33+
description: "The public URL path where bundles are served from.",
34+
affects: "Asset URLs in generated HTML and runtime chunk loading",
35+
documentationUrl:
36+
"https://webpack.js.org/configuration/output/#outputpublicpath"
37+
},
38+
"output.filename": {
39+
description:
40+
"Filename template for entry chunks. Can include [name], [hash], [contenthash].",
41+
affects: "Output filenames and cache busting strategy",
42+
documentationUrl:
43+
"https://webpack.js.org/configuration/output/#outputfilename"
44+
},
45+
"optimization.minimize": {
46+
description: "Enable/disable minification of JavaScript bundles.",
47+
defaultValue: "true in production, false in development",
48+
affects: "Bundle size and build time",
49+
documentationUrl:
50+
"https://webpack.js.org/configuration/optimization/#optimizationminimize"
51+
},
52+
"optimization.minimizer": {
53+
description: "Array of plugins to use for minification.",
54+
defaultValue: "TerserPlugin for JS",
55+
affects: "Minification strategy and bundle size",
56+
documentationUrl:
57+
"https://webpack.js.org/configuration/optimization/#optimizationminimizer"
58+
},
59+
"optimization.splitChunks": {
60+
description:
61+
"Code splitting configuration. Controls how chunks are split into separate files.",
62+
affects: "Bundle splitting, caching, and load performance",
63+
documentationUrl:
64+
"https://webpack.js.org/configuration/optimization/#optimizationsplitchunks"
65+
},
66+
"optimization.splitChunks.chunks": {
67+
description:
68+
"Which chunks to optimize: 'all', 'async', or 'initial'. " +
69+
"'all' enables splitting for all chunk types.",
70+
defaultValue: "'async'",
71+
affects: "Which chunks are eligible for code splitting",
72+
documentationUrl:
73+
"https://webpack.js.org/plugins/split-chunks-plugin/#splitchunkschunks"
74+
},
75+
"optimization.splitChunks.maxSize": {
76+
description:
77+
"Maximum size (in bytes) for a chunk. Webpack will try to split chunks larger than this.",
78+
affects: "Number and size of output chunks",
79+
documentationUrl:
80+
"https://webpack.js.org/plugins/split-chunks-plugin/#splitchunksmaxsize"
81+
},
82+
"cache.type": {
83+
description:
84+
"Type of caching: 'memory' (in-memory) or 'filesystem' (persistent disk cache).",
85+
affects: "Build speed on subsequent builds",
86+
documentationUrl: "https://webpack.js.org/configuration/cache/#cachetype"
87+
},
88+
"devServer.hot": {
89+
description:
90+
"Enable Hot Module Replacement (HMR) for live updates without full reload.",
91+
defaultValue: "true",
92+
affects: "Development experience and reload behavior",
93+
documentationUrl:
94+
"https://webpack.js.org/configuration/dev-server/#devserverhot"
95+
},
96+
"devServer.port": {
97+
description: "Port number for the webpack dev server.",
98+
defaultValue: "8080",
99+
affects: "URL where dev server is accessible",
100+
documentationUrl:
101+
"https://webpack.js.org/configuration/dev-server/#devserverport"
102+
},
103+
target: {
104+
description:
105+
"Deployment target environment: 'web', 'node', 'electron-main', etc.",
106+
defaultValue: "'web'",
107+
affects: "Which environment-specific features are enabled",
108+
documentationUrl: "https://webpack.js.org/configuration/target/"
109+
},
110+
entry: {
111+
description:
112+
"Entry point(s) for the application. Where webpack starts building the dependency graph.",
113+
affects: "What code is included in the bundle",
114+
documentationUrl:
115+
"https://webpack.js.org/configuration/entry-context/#entry"
116+
},
117+
resolve: {
118+
description: "Options for module resolution (how webpack finds modules).",
119+
affects: "How imports are resolved",
120+
documentationUrl: "https://webpack.js.org/configuration/resolve/"
121+
},
122+
"resolve.extensions": {
123+
description:
124+
"File extensions to try when resolving modules (e.g., ['.js', '.jsx']).",
125+
defaultValue: "['.js', '.json', '.wasm']",
126+
affects: "Which files can be imported without extensions",
127+
documentationUrl:
128+
"https://webpack.js.org/configuration/resolve/#resolveextensions"
129+
},
130+
module: {
131+
description: "Options for module processing (loaders and rules).",
132+
affects: "How different file types are processed",
133+
documentationUrl: "https://webpack.js.org/configuration/module/"
134+
},
135+
"module.rules": {
136+
description:
137+
"Array of rules for processing different file types with loaders.",
138+
affects: "How files (JS, CSS, images, etc.) are transformed",
139+
documentationUrl: "https://webpack.js.org/configuration/module/#modulerules"
140+
},
141+
plugins: {
142+
description:
143+
"Array of plugins to extend webpack functionality (HTML generation, env vars, compression, etc.).",
144+
affects: "Build process, output, and optimizations",
145+
documentationUrl: "https://webpack.js.org/configuration/plugins/"
146+
},
147+
externals: {
148+
description:
149+
"Dependencies to exclude from bundles (assumed to be available at runtime).",
150+
affects: "Bundle size and runtime dependencies",
151+
documentationUrl: "https://webpack.js.org/configuration/externals/"
152+
},
153+
performance: {
154+
description: "Performance hints and warnings for bundle sizes.",
155+
defaultValue: "Warnings at 250kb",
156+
affects: "Build warnings about bundle size",
157+
documentationUrl: "https://webpack.js.org/configuration/performance/"
158+
}
159+
}
160+
161+
export function getDocForKey(keyPath: string): ConfigDoc | undefined {
162+
return WEBPACK_CONFIG_DOCS[keyPath]
163+
}
164+
165+
export function hasDocumentation(keyPath: string): boolean {
166+
return keyPath in WEBPACK_CONFIG_DOCS
167+
}

package/configDiffer/diffEngine.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,7 @@ export class DiffEngine {
157157
return "(root)"
158158
}
159159

160-
return path
161-
.map((segment) => {
162-
if (segment.startsWith("[") && segment.endsWith("]")) {
163-
return segment
164-
}
165-
return segment
166-
})
167-
.join(this.options.pathSeparator)
160+
return path.join(this.options.pathSeparator)
168161
}
169162

170163
private shouldIgnorePath(path: string[]): boolean {

0 commit comments

Comments
 (0)