Repository navigation
cli(refactor): split project.ts into cohesive modules - #596
Merged
Merged
Conversation
project.ts had grown to 2,106 lines mixing target detection, the masking scanner, fragment wiring and Payload localization. Move the code into modules along those seams, verbatim, and keep project.ts as the facade so every existing import of './project' keeps working: - source-scanner.ts: the masking scanner and structural primitives (pure functions of source text; no imports) - payload-fragments.ts: RenderBlocks/Pages fragment apply, remove, verify - payload-localization.ts: the localizeFields wrap and the buildConfig localization block (set/read) - project-paths.ts: CANONICAL_HOST_FILES and the two path helpers the other modules share, so none of them imports another sideways - project.ts: detection, host-file resolution, manifest support and prerequisite checks, installed-file checks, base-collection registration, and re-exports of the moved public API Every function body moves byte-for-byte; the only new lines are module headers, import blocks, export lists and the facade re-exports. Previously private helpers are exported through one export list per module instead of editing their declarations. Behavior is unchanged: the runtime export surface of project.ts is identical, and the bundled CLI differs from main's only in esbuild's pathN alias numbering and module comments. The blog catalog's two renderer excerpts now point at payload-fragments.ts (the regenerated figure changes only its provenance line), the design essay's "patch by anchor" receipt follows the code, and AGENTS.md names the new modules. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merged
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
tools/payload-components/project.tshad grown to 2,106 lines. The September audit put it this way: it "mixes detection, scanning, wiring and localization". This PR moves the code into separate modules along those four lines. It moves code without rewriting it, so behavior does not change.project.tsstays as the facade, so every existingimport … from './project'still works. No importer, test or mock changed.Module map
tools/payload-components/project.tsdetectProject(support-matrix target matching,resolveHostFile),flattenRequiredFiles/findExistingRequiredFile,resolveRecoveryPatchedFiles,assertManifestSupport, the manifest prerequisite checks (checkManifestProjectRequirements/assertManifestProjectRequirements),verifyInstalledManifestFilesandsetBaseCollections. Also re-exports the fragment and localization APIs.tools/payload-components/payload-fragments.tsapplyPayloadFragments,preparePayloadFragmentRemoval,removePayloadFragmentsandverifyInstalledPayloadFragments. Also holds the anchors, the dedup checks (hasDirectObjectEntry,hasDirectArrayIdentifier), the removal helpers and thedescribeFragmentFailurehand-edit message.tools/payload-components/payload-localization.tslocalizeBlockConfigSource,applyLocalizedFields,isBlockConfigFile,LOCALIZE_HELPER_FILE. Config level:setPayloadLocalization/readPayloadLocalizationand their private readers.tools/payload-components/source-scanner.tsmaskIgnoredSource) plus the structural primitives built on it: delimiter matching, top-level object and anchor lookup, named-import lookup,insertLineBeforeAnchor, and the object-literal readers (findBuildConfigObject,findDirectProperty,findDirectShorthand,findLastDirectSpread,findDirectArrayEntries, …). These are pure functions of source text and the module imports nothing.tools/payload-components/project-paths.tsCANONICAL_HOST_FILESand the two one-line helpers (getAbsolutePath,normalizeFileList) that detection, fragments and localization all use. It exists so none of those modules has to import another sideways.Dependency graph (no cycles among the 52 CLI modules):
project-pathsis a leaf.source-scanneris a leaf.payload-fragmentsandpayload-localizationdepend onproject-pathsandsource-scanner. They do not depend on each other.projectdepends on both leaves and re-exportspayload-fragmentsandpayload-localization.Why these boundaries
buildConfigobject readers moved to the scanner. They were written for config-level localization, butmissingCollectionRequirementsandsetBaseCollectionsnow use them too. Leaving them in the localization module would make the project checks import from localization.findRenderBlocksObject,findPagesLayoutBlocksandexpandToOwnLinestay in fragments, anddetectObjectIndentandreadDirectStringstay in localization.Deliberately left in
project.tsverifyInstalledManifestFiles. These are the "project" concerns the file name describes, and leaving them in place keeps that part of the diff at zero.setBaseCollections. It is theinit --scaffoldpatch that registers Pages/Media inbuildConfig.collections. It stays next tomissingCollectionRequirements, which reads the samecollectionsarray for the prerequisite check, so the read/write pair stays together. It is not localization, and it is not aPayloadFragment.Behavior is unchanged
Every function body is byte-for-byte identical. The only new lines are the five module header comments, the import blocks, one export list per new module, and the facade re-exports. Previously private helpers are exported through that one export list (as
project.tsalready did forLOCALIZE_HELPER_FILE), so no moved declaration line was edited. The only lines removed outright are the two import namesproject.tsno longer uses (PayloadFragment,commitFileChanges) and three stray blank lines.How I verified it:
Object.keys(await import('./project'))returns the same 20 runtime names before and after. The three type exports also remain:LocalizationConfigPatchandReadLocalizationare re-exported, andProjectRequirementFailureis unchanged in place.dist/cli.jswith tsup from main and from this branch and compared them line by line. The only differences are esbuild'spathNimport-alias numbering (one morenode:pathimport shifts the counter) and its// tools/payload-components/<file>.tsmodule markers. The code is the same; only its order in the bundle changed. That reordering is safe because every top-level statement in these modules only initializes a constant or declares a function.tests/int/payload-components-add-command.int.spec.tsandpayload-components-doctor-orchestration.int.spec.tsvi.doMocktheprojectmodule. All consumers still import through the facade, so those mocks still intercept the same calls.Checks (run locally):
pnpm lint: pass, 0 warnings.eslint --max-warnings 0also passes on the five modules.pnpm format:check: pass.pnpm exec tsc --noEmit: pass.pnpm run test:int: 64 files passed, 1 skipped (the gated pack test); 803 tests passed, 1 skipped.pnpm test:pack: pass. It packs the tarball, installs it, and runs the bundled bin.Reviewing
With
histogram(orpatience), git colours 1,674 of the 1,679 lines removed fromproject.tsas moved. The 39 lines added toproject.tsare just the new imports and the facade. The new files' uncoloured lines are their headers, imports and export lists. The default Myers algorithm also works, but it shows about 90 kept lines ofproject.tsas moved within the file.Docs and blog figures
tools/blog/visual-system/catalog.ts: the two renderer excerpts (how-renderblocks-works, anchored atconst propertyLine, andtext-anchors-vs-ast, anchored atapplyRenderBlocksFragment) now point atpayload-fragments.ts.pnpm blog:visuals:figuresregenerated all 27 figures. Onlypublic/blog/how-renderblocks-works/figure-01-renderer-dispatch.svgchanged, and only its provenance line; the excerpt text is identical.content/docs/design.mdx, decision 03 ("Patch by anchor, refuse when unsure") now points its GitHub receipt atpayload-fragments.ts, where the anchor refusal and dedup logic now live.payload-fragments.ts,source-scanner.tsandpayload-localization.tswhere it describedproject.ts.docs/reviews/anddocs/superpowers/plans/are history and were not changed.tests/int/ci-change-selection.int.spec.tsusesproject.tsonly as a sample path, and that file still exists.Notes for reviewers
cover.webpimages forhow-renderblocks-worksandtext-anchors-vs-aststill caption their primary provenance astools/payload-components/project.ts. Covers are Chromium renders and are not byte-gated. Re-rendering those two from unmodified main on my machine (render-covers.ts --slug …) already differs from the committed files in 18–22% of pixels across the whole canvas. Regenerating them here would therefore ship unrelated visual changes along with the one-line caption fix. They should be refreshed with the rest of the covers, or the stale caption accepted..prettierignore's barepayload-componentsentry matches at any depth, so it also excludestools/payload-components/. That is whymissingCollectionRequirementsandsetBaseCollectionsare not Prettier-shaped. I kept them verbatim rather than reformat during a move. Anchoring the entry as/payload-componentswould bring the CLI under the gate, but as a separate change with its own formatting diff.tools/changed. I did not runpnpm test:freshlocally.🤖 Generated with Claude Code