refactor: lean down src/index.ts after extraction PRs (#418) - #1129
Open
coder-Yash886 wants to merge 2 commits into
Open
refactor: lean down src/index.ts after extraction PRs (#418)#1129coder-Yash886 wants to merge 2 commits into
coder-Yash886 wants to merge 2 commits into
Conversation
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.
Contributor
Author
|
@sonukapoor Please review the PR when you have free time |
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.
Closes #418
Summary
This PR performs the final cleanup pass on
src/index.tsfollowing earlier extraction PRs, reducingsrc/index.tsfrom 974 lines down to a clean, readable 192-line orchestration layer.Key Changes
Single-Project Scan Coordination:
handleSingleFolderScanandscanProjectintosrc/scan/single-scan.ts(parallelingsrc/scan/multi-folder-scan.ts).Command Handlers & CLI Extraction:
src/cli/advisories-sync.ts: ExtractedrunAdvisoriesSync()for advisory syncing logic.src/cli/advisories-init.ts: AddedrunAdvisoriesInit()helper for empty DB creation and console output.src/cli/config-command.ts: AddedhandleConfigCommand()for subcommand validation and dispatch.src/cli/config.ts: AddedsetupCaCert()to handle CA cert loading, validation, and cert-aware fetch setup.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.Cross-Platform Compatibility:
src/utils/file.ts: Updated directory depth calculations inchooseBestLockfileandfindFilesto split on/[\\/]/for consistent behavior across POSIX and Windows.Verification
npm run buildpasses 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).