Skip to content

[NO-TICKET] Collapse duplicated helpers and drop dead code - #281

Merged
mariojgt merged 1 commit into
mainfrom
cleanup/collapse-duplicated-helpers
Sep 23, 2026
Merged

mariojgt merged 1 commit into
mainfrom
cleanup/collapse-duplicated-helpers

Conversation

@mariojgt

Copy link
Copy Markdown
Contributor

What changed

Ten cleanups across the CLI, config, parsers and the protect scaffolder. Net 60 insertions / 114 deletions over ten files. Nothing here changes behaviour — no printed string, doc, or guide checklist output is touched.

Why these were safe to collapse

Each one is either an exact reimplementation of something that already exists in the same directory, or code with no reachable caller. The four adapter detect bodies were the clearest case: util.ts already exports hasDependency(cwd, name), documented as "True when name is in the project's dependencies or devDependencies", and four call sites had inlined it — same JSON.parse, same spread, same catch → false.

For the two removals I checked reachability rather than assuming it: neither symbol is referenced anywhere in src, tests, scripts or field-test, neither is re-exported from index.ts, and the package's exports map only exposes . and ./protect — so no consumer could reach them either.

Changes

Reuse

  • protect/install/adapters/{next,sveltekit,astro}.ts and protect/install/generic.ts — four hand-rolled copies of hasDependency replaced with the helper. The two detect functions stay as functions because they're part of the Adapter shape; only the bodies collapsed. Astro and SvelteKit's join/read imports were used only by the duplicated code, so they went too.
  • cli.ts — init re-spelled the canonical-UUID regex inline; it now calls isCanonicalUuid, which was already in the module graph via client.ts.
  • cli.ts — four identical resolveConfig({ cwd, cliSiteUuid, cliEndpoint }) blocks (and two near-identical ones) behind resolveCliConfig(args, extra?). mark-build's call is deliberately different — no --endpoint — so it stays inline.
  • cli.ts — the same three-clause process.env.CI test in claim and login → runningInCi(), with the CI=false case explained once.
  • cli.ts — the same .gitignore-outcome ternary in both → gitignoreOutcomeLine(). A third site nearby has different wording and indentation, so it was left alone.

Dead code

  • normalize.ts — removed findPackageInManifest. No caller, no test, not re-exported.
  • map/coordinates.ts — removed namespaceOf. Same.
  • login.ts — removed makeTempDir, documented as "exported for tests" but referenced by none; its three imports went with it.

Naming

  • config.ts — in persistApiKey, _movedKey / _movedPulse carried the "intentionally unused" underscore prefix but are read two lines later. Renamed to match what they do.
  • site-url.ts — the bare 191 now has a name, mirroring NAME_MAX_LENGTH in site-name.ts.

Verified

npm test — 197 files, 3252 passed / 7 skipped, identical to the baseline taken before any edit. npm run typecheck, npm run build, npm run capabilities:check and npm run rule-contract:check all clean.

I also checked explicitly that no import was orphaned by a removal: noUnusedLocals is off, so tsc would not have caught one.

No field-test run applies. The gates in CLAUDE.md cover the install prompt, AGENT-INSTALL.md and the guide checklist output — this PR changes none of them.

Out of scope, worth a follow-up

  • Ten further exports are unused outside their own file (baseFrom, BUILD_DIR_CANDIDATES, writeSecretFile, classifyDescriptor, MASKED_CHAR, routesBefore among them). All have real in-file callers, so only the export keyword is surplus. Eleven files of churn for no runtime effect, and some read as deliberate seams — left alone.
  • packageType in register.ts and packageIsEsm in generic.ts both read package.json's type but return different shapes (string | undefined vs boolean). Merging them means a new shared export and a judgement about which shape wins, which is more than a cleanup.

Docs: not needed. Internal refactor, no flow, label or command output affected.

🤖 Generated with Claude Code

Ten cleanups across the CLI, config, parsers and the protect scaffolder.
None of them change behaviour: no printed string, doc or guide-checklist
output is touched.

The largest group is reuse. Four adapters in the protect scaffolder had
each inlined a character-for-character copy of hasDependency() from the
util module sitting next to them, and the CLI had four copies of the same
resolveConfig() call, two of the same CI test, and two of the same
gitignore-outcome line.

The rest is dead code and naming: two exported functions with no callers
anywhere, a pair of destructured locals whose underscore prefix said
"unused" while both were read two lines later, and a bare 191 that now
has the same name its twin already carries in site-name.ts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mariojgt

Copy link
Copy Markdown
Contributor Author

/review

@coderbuds

coderbuds Bot commented Sep 23, 2026

Copy link
Copy Markdown

Extracted shared helpers and removed redundant code without altering functionality.

🎯 Quality: 82% Excellent · 📦 Size: Medium

📈 This month: Your 155th PR — above team average · Averaging Excellent

See how your team is trending →

@mariojgt
mariojgt merged commit f1c8d73 into main Sep 23, 2026
18 checks passed
@mariojgt
mariojgt deleted the cleanup/collapse-duplicated-helpers branch September 23, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants