|
1 | 1 | import { join } from 'node:path'; |
2 | 2 | import { readFileSync } from 'node:fs'; |
3 | 3 | import { parse } from 'dotenv'; |
| 4 | +import type { ReactCompilerLoaderOption } from 'react-compiler-webpack'; |
| 5 | +import type { EnvironmentConfig } from 'babel-plugin-react-compiler'; |
4 | 6 | import { setEnvironmentVariables } from '../../build/set-environment-variables'; |
5 | 7 | import type { Variables } from '../../lib/variables'; |
6 | 8 | import type { BuildTypesConfig, BuildType } from '../../lib/build-type'; |
@@ -189,3 +191,117 @@ function loadConfigVars( |
189 | 191 |
|
190 | 192 | return definitions; |
191 | 193 | } |
| 194 | + |
| 195 | +/** |
| 196 | + * React Compiler logger that tracks compilation statistics |
| 197 | + */ |
| 198 | +class ReactCompilerLogger { |
| 199 | + private compiledCount = 0; |
| 200 | + |
| 201 | + private skippedCount = 0; |
| 202 | + |
| 203 | + private errorCount = 0; |
| 204 | + |
| 205 | + private compiledFiles: string[] = []; |
| 206 | + |
| 207 | + private skippedFiles: string[] = []; |
| 208 | + |
| 209 | + private errorFiles: string[] = []; |
| 210 | + |
| 211 | + logEvent(filename: string | null, event: { kind: string; reason?: string }) { |
| 212 | + if (filename === null) { |
| 213 | + return; |
| 214 | + } |
| 215 | + switch (event.kind) { |
| 216 | + case 'CompileSuccess': |
| 217 | + this.compiledCount++; |
| 218 | + this.compiledFiles.push(filename); |
| 219 | + // console.log(`✅ Compiled: ${filename}`); |
| 220 | + break; |
| 221 | + case 'CompileSkip': |
| 222 | + this.skippedCount++; |
| 223 | + this.skippedFiles.push(filename); |
| 224 | + break; |
| 225 | + case 'CompileError': |
| 226 | + this.errorCount++; |
| 227 | + this.errorFiles.push(filename); |
| 228 | + // console.error( |
| 229 | + // `❌ React Compiler error in ${filename}: ${event.reason || 'Unknown error'}`, |
| 230 | + // ); |
| 231 | + break; |
| 232 | + default: |
| 233 | + // Ignore other event types |
| 234 | + break; |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + getStats() { |
| 239 | + return { |
| 240 | + compiled: this.compiledCount, |
| 241 | + skipped: this.skippedCount, |
| 242 | + errors: this.errorCount, |
| 243 | + total: this.compiledCount + this.skippedCount + this.errorCount, |
| 244 | + compiledFiles: this.compiledFiles, |
| 245 | + skippedFiles: this.skippedFiles, |
| 246 | + errorFiles: this.errorFiles, |
| 247 | + }; |
| 248 | + } |
| 249 | + |
| 250 | + logSummary() { |
| 251 | + const stats = this.getStats(); |
| 252 | + console.log('\n📊 React Compiler Statistics:'); |
| 253 | + console.log(` ✅ Compiled: ${stats.compiled} files`); |
| 254 | + console.log(` ⏭️ Skipped: ${stats.skipped} files`); |
| 255 | + console.log(` ❌ Errors: ${stats.errors} files`); |
| 256 | + console.log(` 📦 Total processed: ${stats.total} files`); |
| 257 | + } |
| 258 | +} |
| 259 | + |
| 260 | +// Create a singleton logger instance |
| 261 | +const reactCompilerLogger = new ReactCompilerLogger(); |
| 262 | + |
| 263 | +export const reactCompilerOptions = { |
| 264 | + target: '17', |
| 265 | + logger: reactCompilerLogger, |
| 266 | + gating: null, |
| 267 | + noEmit: false, |
| 268 | + compilationMode: 'all', |
| 269 | + eslintSuppressionRules: null, |
| 270 | + flowSuppressions: false, |
| 271 | + ignoreUseNoForget: false, |
| 272 | + sources: (filename) => { |
| 273 | + if (!filename.includes('/ui/')) { |
| 274 | + return false; |
| 275 | + } |
| 276 | + const excludePatterns = [ |
| 277 | + '.test.', |
| 278 | + '.stories.', |
| 279 | + '.container.', |
| 280 | + '/ui/index.js', |
| 281 | + '/__mocks__/', |
| 282 | + '/__snapshots__/', |
| 283 | + '/constants/', |
| 284 | + '/helpers/', |
| 285 | + '/ducks/', |
| 286 | + '/selectors/', |
| 287 | + '/store/', |
| 288 | + '/component-library/', |
| 289 | + ]; |
| 290 | + if (excludePatterns.some((pattern) => filename.includes(pattern))) { |
| 291 | + return false; |
| 292 | + } |
| 293 | + return true; |
| 294 | + }, |
| 295 | + enableReanimatedCheck: false, |
| 296 | + environment: {} as EnvironmentConfig, |
| 297 | + dynamicGating: null, |
| 298 | + panicThreshold: 'none', |
| 299 | + customOptOutDirectives: null, |
| 300 | +} as const satisfies ReactCompilerLoaderOption; |
| 301 | + |
| 302 | +/** |
| 303 | + * Get the React Compiler logger instance for accessing statistics |
| 304 | + */ |
| 305 | +export function getReactCompilerLogger(): ReactCompilerLogger { |
| 306 | + return reactCompilerLogger; |
| 307 | +} |
0 commit comments