Skip to content

refactor: lean down src/index.ts after extraction PRs (#418) - #1129

Open
coder-Yash886 wants to merge 2 commits into
OWASP:mainfrom
coder-Yash886:refactor/issue-418-lean-down-src-index
Open

refactor: lean down src/index.ts after extraction PRs (#418)#1129
coder-Yash886 wants to merge 2 commits into
OWASP:mainfrom
coder-Yash886:refactor/issue-418-lean-down-src-index

Conversation

@coder-Yash886

Copy link
Copy Markdown
Contributor

Closes #418

Summary

This PR performs the final cleanup pass on src/index.ts following earlier extraction PRs, reducing src/index.ts from 974 lines down to a clean, readable 192-line orchestration layer.

Key Changes

  1. Single-Project Scan Coordination:

    • Extracted handleSingleFolderScan and scanProject into src/scan/single-scan.ts (paralleling src/scan/multi-folder-scan.ts).
    • Encapsulates advisory source setup, package loading, vulnerability scanning, override hygiene checking, fix runner, PR creation, ratchet/baseline gating, maintenance/license checks, and output reporting.
  2. Command Handlers & CLI Extraction:

    • src/cli/advisories-sync.ts: Extracted runAdvisoriesSync() for advisory syncing logic.
    • src/cli/advisories-init.ts: Added runAdvisoriesInit() helper for empty DB creation and console output.
    • src/cli/config-command.ts: Added handleConfigCommand() for subcommand validation and dispatch.
    • src/cli/config.ts: Added setupCaCert() to handle CA cert loading, validation, and cert-aware fetch setup.
  3. Entry Point (src/index.ts):

    • main() is now purely focused on top-level dispatch, argument validation, and error handling with no inline user-facing strings or misplaced scan pipeline logic.
  4. Cross-Platform Compatibility:

    • src/utils/file.ts: Updated directory depth calculations in chooseBestLockfile and findFiles to split on /[\\/]/ for consistent behavior across POSIX and Windows.

Verification

  • npm run build passes with zero errors and clean bundle verification (dist/index.js).
  • node --experimental-vm-modules ./node_modules/jest/bin/jest.js tests/cli-integration.test.ts (42/42 tests pass).
  • node --experimental-vm-modules ./node_modules/jest/bin/jest.js tests/cli (88/88 tests pass).
  • node --experimental-vm-modules ./node_modules/jest/bin/jest.js tests/e2e/commands-and-exit-codes.test.ts (21/21 tests pass).
  • Pure refactoring with zero breaking changes or behavioral changes.

Extract command handlers and single-project scan coordination into dedicated modules, leaving src/index.ts as a thin orchestration layer of ~190 lines.
Ensures getConfigDir respects jest.spyOn(os, 'homedir') during unit tests in CI.
@coder-Yash886

Copy link
Copy Markdown
Contributor Author

@sonukapoor Please review the PR when you have free time

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.

refactor: lean down src/index.ts after extraction PRs land

1 participant