Skip to content

Commit ac67db5

Browse files
committed
stash
1 parent cfbcdc2 commit ac67db5

File tree

6 files changed

+469
-8
lines changed

6 files changed

+469
-8
lines changed

development/webpack/utils/cli.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ function getOptions(
356356
group: toOrange('Security:'),
357357
type: 'boolean',
358358
},
359+
reactCompilerDebug: {
360+
alias: 'u',
361+
array: false,
362+
default: false,
363+
description: 'Enables/disables React Compiler debug mode',
364+
group: toOrange('Developer Assistance:'),
365+
type: 'boolean',
366+
},
359367

360368
dryRun: {
361369
array: false,

development/webpack/utils/config.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,83 @@ function loadConfigVars(
190190

191191
return definitions;
192192
}
193+
194+
/**
195+
* React Compiler logger that tracks compilation statistics
196+
*/
197+
class ReactCompilerLogger {
198+
private compiledCount = 0;
199+
200+
private skippedCount = 0;
201+
202+
private errorCount = 0;
203+
204+
private compiledFiles: string[] = [];
205+
206+
private skippedFiles: string[] = [];
207+
208+
private errorFiles: string[] = [];
209+
210+
logEvent(
211+
filename: string | null,
212+
event: { kind: string; detail: { options: { category: string } } },
213+
) {
214+
if (filename === null) {
215+
return;
216+
}
217+
switch (event.kind) {
218+
case 'CompileSuccess':
219+
this.compiledCount++;
220+
this.compiledFiles.push(filename);
221+
console.log(`✅ Compiled: ${filename}`);
222+
break;
223+
case 'CompileSkip':
224+
this.skippedCount++;
225+
this.skippedFiles.push(filename);
226+
break;
227+
case 'CompileError':
228+
this.errorCount++;
229+
this.errorFiles.push(filename);
230+
if (event.detail?.options?.category !== 'Todo') {
231+
console.error(
232+
`❌ React Compiler error in ${filename}: ${JSON.stringify(event.detail?.options) || 'Unknown error'}`,
233+
);
234+
}
235+
break;
236+
default:
237+
// Ignore other event types
238+
break;
239+
}
240+
}
241+
242+
getStats() {
243+
return {
244+
compiled: this.compiledCount,
245+
skipped: this.skippedCount,
246+
errors: this.errorCount,
247+
total: this.compiledCount + this.skippedCount + this.errorCount,
248+
compiledFiles: this.compiledFiles,
249+
skippedFiles: this.skippedFiles,
250+
errorFiles: this.errorFiles,
251+
};
252+
}
253+
254+
logSummary() {
255+
const stats = this.getStats();
256+
console.log('\n📊 React Compiler Statistics:');
257+
console.log(` ✅ Compiled: ${stats.compiled} files`);
258+
console.log(` ⏭️ Skipped: ${stats.skipped} files`);
259+
console.log(` ❌ Errors: ${stats.errors} files`);
260+
console.log(` 📦 Total processed: ${stats.total} files`);
261+
}
262+
}
263+
264+
// Create a singleton logger instance
265+
const reactCompilerLogger = new ReactCompilerLogger();
266+
193267
export const reactCompilerOptions = {
194268
target: '17',
269+
logger: reactCompilerLogger,
195270
sources: (filename) => {
196271
const excludePatterns = [
197272
'.test.',
@@ -212,3 +287,10 @@ export const reactCompilerOptions = {
212287
return true;
213288
},
214289
} as const satisfies ReactCompilerLoaderOption;
290+
291+
/**
292+
* Get the React Compiler logger instance for accessing statistics
293+
*/
294+
export function getReactCompilerLogger(): ReactCompilerLogger {
295+
return reactCompilerLogger;
296+
}

development/webpack/webpack.config.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ import { transformManifest } from './utils/plugins/ManifestPlugin/helpers';
3838
import { parseArgv, getDryRunMessage } from './utils/cli';
3939
import { getCodeFenceLoader } from './utils/loaders/codeFenceLoader';
4040
import { getSwcLoader } from './utils/loaders/swcLoader';
41-
import { getVariables, reactCompilerOptions } from './utils/config';
41+
import {
42+
getVariables,
43+
reactCompilerOptions,
44+
getReactCompilerLogger,
45+
} from './utils/config';
4246
import { ManifestPlugin } from './utils/plugins/ManifestPlugin';
4347
import { getLatestCommit } from './utils/git';
4448

@@ -215,6 +219,19 @@ if (args.progress) {
215219
const { ProgressPlugin } = require('webpack');
216220
plugins.push(new ProgressPlugin());
217221
}
222+
223+
if (args.stats) {
224+
// React Compiler statistics logger plugin
225+
plugins.push({
226+
apply(compiler) {
227+
compiler.hooks.done.tap('ReactCompilerStatsPlugin', () => {
228+
const logger = getReactCompilerLogger();
229+
logger.logSummary();
230+
});
231+
},
232+
} as WebpackPluginInstance);
233+
}
234+
218235
// #endregion plugins
219236

220237
const swcConfig = { args, browsersListQuery, isDevelopment };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@
682682
"process": "^0.11.10",
683683
"pumpify": "^2.0.1",
684684
"randomcolor": "^0.5.4",
685-
"react-compiler-webpack": "0.2.1",
685+
"react-compiler-webpack": "^1.0.0",
686686
"react-devtools": "^6.1.5",
687687
"react-devtools-core": "^6.1.5",
688688
"react-syntax-highlighter": "^15.5.0",

0 commit comments

Comments
 (0)