Skip to content

refactor(cli): reuse resolveDataDir() instead of duplicating its logic - #5190

Merged
pedrofrxncx merged 1 commit into
mainfrom
refactor/cli-dedupe-data-dir-resolution-w4
Jul 24, 2026
Merged

refactor(cli): reuse resolveDataDir() instead of duplicating its logic#5190
pedrofrxncx merged 1 commit into
mainfrom
refactor/cli-dedupe-data-dir-resolution-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Source: reduction found while auditing apps/api/src/cli.ts for the backfill-assets argument-validation area (following up on #5180, which fixed --batch/--limit NaN handling). No further validation gaps found there, but this file had a real duplication.

Why: cli.ts already defines a resolveDataDir() helper (values.home || process.env.DATA_DIR || process.env.DECOCMS_HOME || join(homedir(), "deco")) used by the auth command. The exact same 4-line expression was copy-pasted verbatim in two other places: the services command and the default server-mode block. Three copies of the same precedence chain is a correctness risk if one is ever updated and the others aren't.

Change: Replaced both duplicated blocks with calls to the existing resolveDataDir() helper. Purely mechanical — resolveDataDir() is byte-identical to the inlined logic it replaces (verified by diff), so behavior for deco services, deco (default server mode), and deco auth is unchanged. Net: -10 / +2 lines.

How to verify: cd apps/api && bunx tsc --noEmit (clean), and manually compare resolveDataDir()'s body against the removed blocks — they're identical.

Checks run locally: bun run fmt, bunx tsc --noEmit in apps/api (both clean). No existing test covers this file's argument-routing directly (it's the CLI entrypoint script), so this relies on the identical-logic diff as verification; full CI validates the rest.


Summary by cubic

Refactor CLI to reuse resolveDataDir() for data directory resolution in the services command and default server mode. Removes duplicated precedence logic and preserves existing behavior.

Written for commit 03f60be. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 24, 2026 15:30
@pedrofrxncx
pedrofrxncx merged commit 34318fe into main Jul 24, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the refactor/cli-dedupe-data-dir-resolution-w4 branch July 24, 2026 15:33
decocms Bot pushed a commit that referenced this pull request Jul 24, 2026
PR: #5190 refactor(cli): reuse resolveDataDir() instead of duplicating its logic
Bump type: patch

- decocms (apps/api/package.json): 4.122.15 -> 4.122.16

Deploy-Scope: server
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.

1 participant