-
Notifications
You must be signed in to change notification settings - Fork 456
refactor: simplify internals across the workspace #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f249e3a
refactor(cli): extract inspect result finalization
aidenybai dce5541
refactor: harden scan orchestration and caches
aidenybai e20ce0a
chore: add refactor changeset
aidenybai 8e0dfb8
refactor: consolidate scan and graph internals
aidenybai 4bd5408
refactor: remove analyzer-confirmed dead internals
aidenybai b42acf6
refactor: simplify package internals
aidenybai a38b5e6
refactor: harden internal ownership boundaries
aidenybai 257ed73
Merge remote-tracking branch 'origin/main' into codex/extract-inspect…
aidenybai 540523a
Merge remote-tracking branch 'origin/main' into codex/extract-inspect…
aidenybai 998c3b4
refactor: clarify analysis and scan phases
aidenybai 4afa480
refactor(core): deepen Effect runtime boundaries
aidenybai 78ac0ec
refactor(core): align score transport with conventions
aidenybai 1840313
refactor(core): modernize effect v4 usage
aidenybai 659d917
refactor: remove dead internals
aidenybai 6cd4b26
ci: drive interactive e2e with termctrl
aidenybai 5ab6307
fix(core): preserve refactor API compatibility
aidenybai 86c0553
test(api): allow full-scan CI headroom
aidenybai 8fa98d7
test(api): avoid redundant lint subprocess
aidenybai 7ab01e4
ci: serialize Node 20 test packages
aidenybai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "react-doctor": patch | ||
| "deslop-js": patch | ||
| --- | ||
|
|
||
| Harden scan orchestration and cache persistence by validating stored payloads, preserving independently written entries, and keeping workflow paths inside the repository. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { randomUUID } from "node:crypto"; | ||
| import * as fs from "node:fs"; | ||
| import * as path from "node:path"; | ||
|
|
||
| export const atomicWriteFile = (filePath: string, contents: string): void => { | ||
| let temporaryPath: string | null = null; | ||
| try { | ||
| fs.mkdirSync(path.dirname(filePath), { recursive: true }); | ||
| temporaryPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`; | ||
| fs.writeFileSync(temporaryPath, contents); | ||
| fs.renameSync(temporaryPath, filePath); | ||
| temporaryPath = null; | ||
| } catch { | ||
| return; | ||
| } finally { | ||
| if (temporaryPath !== null) { | ||
| try { | ||
| fs.rmSync(temporaryPath, { force: true }); | ||
| } catch {} | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { randomUUID } from "node:crypto"; | ||
| import * as fs from "node:fs"; | ||
| import * as path from "node:path"; | ||
|
|
||
| export const atomicWriteFile = (filePath: string, contents: string): void => { | ||
| let temporaryPath: string | null = null; | ||
| try { | ||
| fs.mkdirSync(path.dirname(filePath), { recursive: true }); | ||
| temporaryPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`; | ||
| fs.writeFileSync(temporaryPath, contents); | ||
| fs.renameSync(temporaryPath, filePath); | ||
| temporaryPath = null; | ||
| } catch { | ||
| return; | ||
| } finally { | ||
| if (temporaryPath !== null) { | ||
| try { | ||
| fs.rmSync(temporaryPath, { force: true }); | ||
| } catch {} | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
packages/react-doctor/src/cli/utils/finalize-inspect-result.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| import * as Console from "effect/Console"; | ||
| import * as Effect from "effect/Effect"; | ||
| import { | ||
| buildSkippedChecks, | ||
| filterDiagnosticsForSurface, | ||
| highlighter, | ||
| type InspectResult, | ||
| } from "@react-doctor/core"; | ||
| import type { ResolvedInspectOptions } from "../../inspect-options.js"; | ||
| import { buildEmptyReportMessage } from "./build-empty-report-message.js"; | ||
| import { buildNoScoreMessage } from "./build-no-score-message.js"; | ||
| import { filterDiagnosticsByCategories } from "./filter-diagnostics-by-categories.js"; | ||
| import { hasIncompleteScoreAnalysis } from "./has-incomplete-score-analysis.js"; | ||
| import { printDiagnosticsDump } from "./print-diagnostics-dump.js"; | ||
| import { printFooter } from "./print-footer.js"; | ||
| import { printHeadlessReport } from "./print-headless-report.js"; | ||
| import { printAgentGuidance } from "./render-agent-guidance.js"; | ||
| import type { CachedScanPayload } from "./scan-result-cache-payload.js"; | ||
|
|
||
| export interface InspectExecutionCacheStats { | ||
| readonly lintCacheHitFileCount: number | null; | ||
| readonly lintCacheTotalFileCount: number | null; | ||
| readonly lintSidecarReplayedFileCount: number | null; | ||
| readonly lintSidecarTotalFileCount: number | null; | ||
| readonly deadCodeCacheHit: boolean | null; | ||
| readonly deadCodeSummaryCacheHits: number | null; | ||
| readonly deadCodeSummaryCacheMisses: number | null; | ||
| } | ||
|
|
||
| interface FinalizeInspectResultInput { | ||
| readonly options: ResolvedInspectOptions; | ||
| readonly elapsedMilliseconds: number; | ||
| readonly payload: CachedScanPayload; | ||
| readonly cacheStats: InspectExecutionCacheStats; | ||
| } | ||
|
|
||
| export const finalizeInspectResult = ( | ||
| input: FinalizeInspectResultInput, | ||
| ): Effect.Effect<InspectResult> => | ||
| Effect.gen(function* () { | ||
| const { payload, cacheStats } = input; | ||
| const { skippedChecks, skippedCheckReasons } = buildSkippedChecks({ | ||
| didLintFail: payload.didLintFail, | ||
| lintFailureReason: payload.lintFailureReason, | ||
| lintPartialFailures: payload.lintPartialFailures, | ||
| didDeadCodeFail: payload.didDeadCodeFail, | ||
| deadCodeFailureReason: payload.deadCodeFailureReason, | ||
| supplyChainOverlapTimedOut: payload.supplyChainOverlapTimedOut, | ||
| securityScanFailed: payload.securityScanFailed ?? false, | ||
| securityScanFailureReason: payload.securityScanFailureReason ?? null, | ||
| }); | ||
| const hasSkippedChecks = skippedChecks.length > 0; | ||
| const noScoreMessage = buildNoScoreMessage({ | ||
| isScoreDisabled: input.options.noScore, | ||
| isAnalysisIncomplete: hasIncompleteScoreAnalysis(skippedChecks), | ||
| disabledMessage: input.options.scoreDisabledMessage, | ||
| }); | ||
| const result: InspectResult = { | ||
| diagnostics: [...payload.diagnostics], | ||
| score: payload.score, | ||
| skippedChecks, | ||
| ...(Object.keys(skippedCheckReasons).length > 0 ? { skippedCheckReasons } : {}), | ||
| project: payload.project, | ||
| elapsedMilliseconds: input.elapsedMilliseconds, | ||
| scannedFileCount: payload.scannedFileCount, | ||
| scannedFilePaths: payload.scannedFilePaths, | ||
| analyzedFiles: payload.analyzedFiles ?? [], | ||
| scanElapsedMilliseconds: payload.scanElapsedMilliseconds, | ||
| ...(cacheStats.lintCacheTotalFileCount !== null | ||
| ? { | ||
| lintCacheHitFileCount: cacheStats.lintCacheHitFileCount, | ||
| lintCacheTotalFileCount: cacheStats.lintCacheTotalFileCount, | ||
| } | ||
| : {}), | ||
| ...(cacheStats.lintSidecarTotalFileCount !== null | ||
| ? { | ||
| lintSidecarReplayedFileCount: cacheStats.lintSidecarReplayedFileCount, | ||
| lintSidecarTotalFileCount: cacheStats.lintSidecarTotalFileCount, | ||
| } | ||
| : {}), | ||
| ...(cacheStats.deadCodeCacheHit !== null | ||
| ? { deadCodeCacheHit: cacheStats.deadCodeCacheHit } | ||
| : {}), | ||
| ...(cacheStats.deadCodeSummaryCacheHits !== null && | ||
| cacheStats.deadCodeSummaryCacheMisses !== null | ||
| ? { | ||
| deadCodeSummaryCacheHits: cacheStats.deadCodeSummaryCacheHits, | ||
| deadCodeSummaryCacheMisses: cacheStats.deadCodeSummaryCacheMisses, | ||
| } | ||
| : {}), | ||
| ...(payload.baselineDelta ? { baselineDelta: payload.baselineDelta } : {}), | ||
| }; | ||
|
|
||
| if (input.options.suppressRendering) return result; | ||
|
|
||
| const surfaceDiagnostics = filterDiagnosticsForSurface( | ||
| [...payload.diagnostics], | ||
| input.options.outputSurface, | ||
| payload.userConfig, | ||
| ); | ||
| const printedDiagnostics = filterDiagnosticsByCategories( | ||
| surfaceDiagnostics, | ||
| input.options.categoryFilters, | ||
| ); | ||
|
|
||
| if (input.options.scoreOnly) { | ||
| if (input.options.outputDirectory !== null) { | ||
| yield* printDiagnosticsDump( | ||
| printedDiagnostics, | ||
| input.options.outputDirectory, | ||
| false, | ||
| "stderr", | ||
| ); | ||
| } | ||
| if (payload.score) { | ||
| yield* Console.log(`${payload.score.score}`); | ||
| } else { | ||
| yield* Console.error(highlighter.gray(noScoreMessage)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| const demotedDiagnosticCount = payload.diagnostics.length - surfaceDiagnostics.length; | ||
| if (input.options.isNonInteractiveEnvironment && input.options.outputSurface !== "prComment") { | ||
| yield* printAgentGuidance(); | ||
| } | ||
|
|
||
| yield* printHeadlessReport({ | ||
| diagnostics: printedDiagnostics, | ||
| elapsedMilliseconds: input.elapsedMilliseconds, | ||
| emptyStateMessage: buildEmptyReportMessage({ | ||
| categoryFilters: input.options.categoryFilters, | ||
| demotedDiagnosticCount, | ||
| outputSurface: input.options.outputSurface, | ||
| }), | ||
| noScoreMessage, | ||
| projectName: payload.project.projectName, | ||
| scannedFileCount: payload.scannedFileCount, | ||
| scoreResult: hasSkippedChecks ? null : payload.score, | ||
| skippedChecks, | ||
| }); | ||
|
|
||
| if (input.options.outputDirectory !== null || input.options.verbose) { | ||
| yield* printDiagnosticsDump( | ||
| printedDiagnostics, | ||
| input.options.outputDirectory, | ||
| input.options.verbose, | ||
| ); | ||
| } | ||
| if (input.options.categoryFilters.size === 0 && demotedDiagnosticCount > 0) { | ||
| yield* Console.log( | ||
| highlighter.gray( | ||
| ` ${demotedDiagnosticCount} demoted from the ${input.options.outputSurface} surface (e.g. design cleanup) — run \`npx react-doctor@latest .\` locally for the full list.`, | ||
| ), | ||
| ); | ||
| yield* Console.log(""); | ||
| } | ||
|
|
||
| yield* printFooter({ | ||
| diagnostics: printedDiagnostics, | ||
| scoreResult: payload.score, | ||
| projectName: payload.project.projectName, | ||
| isOffline: input.options.isCi || !input.options.share || payload.score === null, | ||
| }); | ||
|
|
||
| return result; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.