octocode-cli 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -63
- package/README.md +85 -142
- package/out/octocode-cli.js +7026 -6945
- package/package.json +8 -6
- package/skills/README.md +97 -120
- package/skills/octocode-code-engineer/.claude/settings.local.json +18 -0
- package/skills/octocode-code-engineer/.octocode/rfc/RFC-code-engineer-weakness-fixes.md +255 -0
- package/skills/octocode-code-engineer/.plan/VALIDATED_PLAN.md +223 -0
- package/skills/octocode-code-engineer/README.md +178 -0
- package/skills/octocode-code-engineer/SKILL.md +418 -0
- package/skills/octocode-code-engineer/coverage/architecture.ts.html +7828 -0
- package/skills/octocode-code-engineer/coverage/ast-helpers.ts.html +211 -0
- package/skills/octocode-code-engineer/coverage/ast-search.ts.html +1795 -0
- package/skills/octocode-code-engineer/coverage/base.css +224 -0
- package/skills/octocode-code-engineer/coverage/block-navigation.js +87 -0
- package/skills/octocode-code-engineer/coverage/cache.ts.html +376 -0
- package/skills/octocode-code-engineer/coverage/cli.ts.html +982 -0
- package/skills/octocode-code-engineer/coverage/clover.xml +3217 -0
- package/skills/octocode-code-engineer/coverage/collect-effects.ts.html +664 -0
- package/skills/octocode-code-engineer/coverage/collect-input-sources.ts.html +577 -0
- package/skills/octocode-code-engineer/coverage/collect-performance.ts.html +331 -0
- package/skills/octocode-code-engineer/coverage/collect-prototype-pollution.ts.html +421 -0
- package/skills/octocode-code-engineer/coverage/collect-security.ts.html +604 -0
- package/skills/octocode-code-engineer/coverage/collect-test-profile.ts.html +589 -0
- package/skills/octocode-code-engineer/coverage/coverage-final.json +30 -0
- package/skills/octocode-code-engineer/coverage/dependencies.ts.html +997 -0
- package/skills/octocode-code-engineer/coverage/dependency-summary.ts.html +688 -0
- package/skills/octocode-code-engineer/coverage/discovery.ts.html +322 -0
- package/skills/octocode-code-engineer/coverage/favicon.png +0 -0
- package/skills/octocode-code-engineer/coverage/graph-analytics.ts.html +1510 -0
- package/skills/octocode-code-engineer/coverage/index.html +536 -0
- package/skills/octocode-code-engineer/coverage/index.ts.html +826 -0
- package/skills/octocode-code-engineer/coverage/metrics.ts.html +553 -0
- package/skills/octocode-code-engineer/coverage/pipeline.ts.html +2044 -0
- package/skills/octocode-code-engineer/coverage/prettify.css +1 -0
- package/skills/octocode-code-engineer/coverage/prettify.js +2 -0
- package/skills/octocode-code-engineer/coverage/report-analysis.ts.html +1570 -0
- package/skills/octocode-code-engineer/coverage/report-writer.ts.html +1102 -0
- package/skills/octocode-code-engineer/coverage/security-detectors.ts.html +1747 -0
- package/skills/octocode-code-engineer/coverage/semantic-detectors.ts.html +2152 -0
- package/skills/octocode-code-engineer/coverage/semantic.ts.html +1897 -0
- package/skills/octocode-code-engineer/coverage/sort-arrow-sprite.png +0 -0
- package/skills/octocode-code-engineer/coverage/sorter.js +210 -0
- package/skills/octocode-code-engineer/coverage/summary-md.ts.html +1222 -0
- package/skills/octocode-code-engineer/coverage/test-quality-detectors.ts.html +1039 -0
- package/skills/octocode-code-engineer/coverage/tree-sitter-analyzer.ts.html +955 -0
- package/skills/octocode-code-engineer/coverage/ts-analyzer.ts.html +1213 -0
- package/skills/octocode-code-engineer/coverage/types.ts.html +2473 -0
- package/skills/octocode-code-engineer/coverage/utils.ts.html +820 -0
- package/skills/octocode-code-engineer/eslint.config.mjs +54 -0
- package/skills/octocode-code-engineer/minify-scripts.mjs +32 -0
- package/skills/octocode-code-engineer/package.json +54 -0
- package/skills/octocode-code-engineer/references/agent-ast-reading-rfc.md +95 -0
- package/skills/octocode-code-engineer/references/architecture-techniques.md +121 -0
- package/skills/octocode-code-engineer/references/ast-search.md +210 -0
- package/skills/octocode-code-engineer/references/ast-tree-search.md +151 -0
- package/skills/octocode-code-engineer/references/cli-reference.md +167 -0
- package/skills/octocode-code-engineer/references/concepts.md +107 -0
- package/skills/octocode-code-engineer/references/finding-categories.md +128 -0
- package/skills/octocode-code-engineer/references/improvement-roadmap.md +304 -0
- package/skills/octocode-code-engineer/references/output-files.md +144 -0
- package/skills/octocode-code-engineer/references/playbooks.md +204 -0
- package/skills/octocode-code-engineer/references/present-results.md +136 -0
- package/skills/octocode-code-engineer/references/tool-workflows.md +566 -0
- package/skills/octocode-code-engineer/references/validate-investigate.md +225 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependencies.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependency-summary.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/discovery.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/graph-analytics.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/helpers.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/metrics.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-sitter.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/ts-analyzer.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/chains.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/effects.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/input-sources.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/performance.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/prototype-pollution.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/test-profile.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/is-direct-run.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/utils.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/code-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cohesion.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/coupling.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cycle.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/dead-code.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/import-style.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/shared.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/test-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cache.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cli.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/main.js +2 -0
- package/skills/octocode-code-engineer/scripts/reporting/analysis.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/summary-md.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/writer.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/constants.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/interfaces.js +1 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.test.ts +545 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.ts +406 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.test.ts +566 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.ts +257 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.test.ts +420 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.ts +87 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.test.ts +449 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.ts +534 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.test.ts +1533 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.ts +830 -0
- package/skills/octocode-code-engineer/src/ast/helpers.test.ts +185 -0
- package/skills/octocode-code-engineer/src/ast/helpers.ts +62 -0
- package/skills/octocode-code-engineer/src/ast/metrics.test.ts +304 -0
- package/skills/octocode-code-engineer/src/ast/metrics.ts +204 -0
- package/skills/octocode-code-engineer/src/ast/search.test.ts +647 -0
- package/skills/octocode-code-engineer/src/ast/search.ts +648 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.test.ts +199 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.ts +392 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.test.ts +407 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.ts +402 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.test.ts +1864 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.ts +509 -0
- package/skills/octocode-code-engineer/src/collectors/chains.ts +74 -0
- package/skills/octocode-code-engineer/src/collectors/effects.test.ts +490 -0
- package/skills/octocode-code-engineer/src/collectors/effects.ts +332 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.test.ts +144 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.ts +196 -0
- package/skills/octocode-code-engineer/src/collectors/performance.test.ts +82 -0
- package/skills/octocode-code-engineer/src/collectors/performance.ts +141 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.test.ts +55 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.ts +162 -0
- package/skills/octocode-code-engineer/src/collectors/security.test.ts +124 -0
- package/skills/octocode-code-engineer/src/collectors/security.ts +309 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.test.ts +97 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.ts +269 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.test.ts +32 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.ts +13 -0
- package/skills/octocode-code-engineer/src/common/utils.test.ts +463 -0
- package/skills/octocode-code-engineer/src/common/utils.ts +304 -0
- package/skills/octocode-code-engineer/src/detectors/code-quality.ts +966 -0
- package/skills/octocode-code-engineer/src/detectors/cohesion.ts +539 -0
- package/skills/octocode-code-engineer/src/detectors/coupling.ts +323 -0
- package/skills/octocode-code-engineer/src/detectors/cycle.ts +349 -0
- package/skills/octocode-code-engineer/src/detectors/dead-code.ts +320 -0
- package/skills/octocode-code-engineer/src/detectors/import-style.ts +376 -0
- package/skills/octocode-code-engineer/src/detectors/index.test.ts +3061 -0
- package/skills/octocode-code-engineer/src/detectors/index.ts +88 -0
- package/skills/octocode-code-engineer/src/detectors/security.test.ts +882 -0
- package/skills/octocode-code-engineer/src/detectors/security.ts +821 -0
- package/skills/octocode-code-engineer/src/detectors/semantic.ts +758 -0
- package/skills/octocode-code-engineer/src/detectors/shared.ts +49 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.test.ts +388 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.ts +367 -0
- package/skills/octocode-code-engineer/src/index.test.ts +4425 -0
- package/skills/octocode-code-engineer/src/index.ts +403 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.test.ts +199 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.ts +130 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.test.ts +493 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.ts +344 -0
- package/skills/octocode-code-engineer/src/pipeline/main.test.ts +174 -0
- package/skills/octocode-code-engineer/src/pipeline/main.ts +1074 -0
- package/skills/octocode-code-engineer/src/pipeline.test.ts +84 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.test.ts +782 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.ts +688 -0
- package/skills/octocode-code-engineer/src/reporting/output-contract.test.ts +463 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.test.ts +421 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.ts +714 -0
- package/skills/octocode-code-engineer/src/reporting/writer.ts +430 -0
- package/skills/octocode-code-engineer/src/sanity.test.ts +47 -0
- package/skills/octocode-code-engineer/src/types/constants.ts +248 -0
- package/skills/octocode-code-engineer/src/types/index.ts +80 -0
- package/skills/octocode-code-engineer/src/types/interfaces.ts +682 -0
- package/skills/octocode-code-engineer/tsconfig.json +17 -0
- package/skills/octocode-code-engineer/vitest.config.ts +8 -0
- package/skills/octocode-documentation-writer/README.md +113 -0
- package/skills/octocode-documentation-writer/SKILL.md +886 -0
- package/skills/octocode-documentation-writer/references/agent-discovery-analysis.md +453 -0
- package/skills/octocode-documentation-writer/references/agent-documentation-writer.md +255 -0
- package/skills/octocode-documentation-writer/references/agent-engineer-questions.md +247 -0
- package/skills/octocode-documentation-writer/references/agent-orchestrator.md +370 -0
- package/skills/octocode-documentation-writer/references/agent-qa-validator.md +227 -0
- package/skills/octocode-documentation-writer/references/agent-researcher.md +250 -0
- package/skills/octocode-documentation-writer/schemas/analysis-schema.json +886 -0
- package/skills/octocode-documentation-writer/schemas/discovery-tasks.json +96 -0
- package/skills/octocode-documentation-writer/schemas/documentation-structure.json +373 -0
- package/skills/octocode-documentation-writer/schemas/partial-discovery-schema.json +102 -0
- package/skills/octocode-documentation-writer/schemas/partial-research-schema.json +98 -0
- package/skills/octocode-documentation-writer/schemas/qa-results-schema.json +113 -0
- package/skills/octocode-documentation-writer/schemas/questions-schema.json +228 -0
- package/skills/octocode-documentation-writer/schemas/research-schema.json +104 -0
- package/skills/octocode-documentation-writer/schemas/state-schema.json +222 -0
- package/skills/octocode-documentation-writer/schemas/work-assignments-schema.json +74 -0
- package/skills/octocode-plan/SKILL.md +122 -116
- package/skills/octocode-prompt-optimizer/SKILL.md +617 -0
- package/skills/octocode-pull-request-reviewer/README.md +249 -0
- package/skills/octocode-pull-request-reviewer/SKILL.md +479 -0
- package/skills/octocode-pull-request-reviewer/references/dependency-check.md +74 -0
- package/skills/octocode-pull-request-reviewer/references/domain-reviewers.md +24 -0
- package/skills/octocode-pull-request-reviewer/references/execution-lifecycle.md +441 -0
- package/skills/octocode-pull-request-reviewer/references/flow-analysis-protocol.md +64 -0
- package/skills/octocode-pull-request-reviewer/references/output-template.md +174 -0
- package/skills/octocode-pull-request-reviewer/references/parallel-agent-protocol.md +182 -0
- package/skills/octocode-pull-request-reviewer/references/review-guidelines.md +26 -0
- package/skills/octocode-pull-request-reviewer/references/verification-checklist.md +40 -0
- package/skills/octocode-research/.claude/settings.local.json +46 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/plan.md +312 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/research.md +212 -0
- package/skills/octocode-research/.octocode/plans/NODE_SERVER_START_PLAN.md +755 -0
- package/skills/octocode-research/.octocode/research/code-review/research.md +371 -0
- package/skills/octocode-research/.octocode/review/IMPROVEMENTS.md +391 -0
- package/skills/octocode-research/.octocode/review/REVIEW_PLAN.md +289 -0
- package/skills/octocode-research/.octocode/review/REVIEW_REPORT.md +356 -0
- package/skills/octocode-research/AGENTS.md +349 -0
- package/skills/octocode-research/README.md +494 -0
- package/skills/octocode-research/SKILL.md +652 -274
- package/skills/octocode-research/docs/API_REFERENCE.md +562 -0
- package/skills/octocode-research/docs/ARCHITECTURE.md +554 -0
- package/skills/octocode-research/docs/FLOWS.md +577 -0
- package/skills/octocode-research/docs/OVERVIEW.md +564 -0
- package/skills/octocode-research/docs/SERVER_FLOWS.md +631 -0
- package/skills/octocode-research/ecosystem.config.cjs +88 -0
- package/skills/octocode-research/eslint.config.mjs +27 -0
- package/skills/octocode-research/package.json +84 -0
- package/skills/octocode-research/references/GUARDRAILS.md +40 -0
- package/skills/octocode-research/references/PARALLEL_AGENT_PROTOCOL.md +178 -0
- package/skills/octocode-research/references/roast-prompt.md +149 -0
- package/skills/octocode-research/scripts/server-init.d.ts +2 -0
- package/skills/octocode-research/scripts/server-init.js +2 -0
- package/skills/octocode-research/scripts/server.d.ts +8 -0
- package/skills/octocode-research/scripts/server.js +445 -0
- package/skills/octocode-research/src/__tests__/integration/circuitBreaker.test.ts +205 -0
- package/skills/octocode-research/src/__tests__/integration/routes.test.ts +374 -0
- package/skills/octocode-research/src/__tests__/unit/circuitBreaker.test.ts +245 -0
- package/skills/octocode-research/src/__tests__/unit/errorHandler.test.ts +183 -0
- package/skills/octocode-research/src/__tests__/unit/httpPreprocess.test.ts +157 -0
- package/skills/octocode-research/src/__tests__/unit/logger.test.ts +143 -0
- package/skills/octocode-research/src/__tests__/unit/queryParser.test.ts +130 -0
- package/skills/octocode-research/src/__tests__/unit/responseBuilder.test.ts +469 -0
- package/skills/octocode-research/src/__tests__/unit/retry.test.ts +205 -0
- package/skills/octocode-research/src/index.ts +186 -0
- package/skills/octocode-research/src/mcpCache.ts +49 -0
- package/skills/octocode-research/src/middleware/errorHandler.ts +65 -0
- package/skills/octocode-research/src/middleware/logger.ts +61 -0
- package/skills/octocode-research/src/middleware/queryParser.ts +115 -0
- package/skills/octocode-research/src/middleware/readiness.ts +17 -0
- package/skills/octocode-research/src/routes/github.ts +197 -0
- package/skills/octocode-research/src/routes/local.ts +175 -0
- package/skills/octocode-research/src/routes/lsp.ts +177 -0
- package/skills/octocode-research/src/routes/package.ts +127 -0
- package/skills/octocode-research/src/routes/prompts.ts +138 -0
- package/skills/octocode-research/src/routes/tools.ts +677 -0
- package/skills/octocode-research/src/server-init.ts +363 -0
- package/skills/octocode-research/src/server.ts +285 -0
- package/skills/octocode-research/src/types/errorGuards.ts +151 -0
- package/skills/octocode-research/src/types/express.d.ts +76 -0
- package/skills/octocode-research/src/types/guards.ts +98 -0
- package/skills/octocode-research/src/types/mcp.ts +119 -0
- package/skills/octocode-research/src/types/responses.ts +199 -0
- package/skills/octocode-research/src/types/toolTypes.ts +33 -0
- package/skills/octocode-research/src/utils/asyncTimeout.ts +116 -0
- package/skills/octocode-research/src/utils/circuitBreaker.ts +492 -0
- package/skills/octocode-research/src/utils/colors.ts +53 -0
- package/skills/octocode-research/src/utils/errorQueue.ts +71 -0
- package/skills/octocode-research/src/utils/logEmoji.ts +103 -0
- package/skills/octocode-research/src/utils/logger.ts +413 -0
- package/skills/octocode-research/src/utils/resilience.ts +169 -0
- package/skills/octocode-research/src/utils/responseBuilder.ts +495 -0
- package/skills/octocode-research/src/utils/responseFactory.ts +100 -0
- package/skills/octocode-research/src/utils/responseParser.ts +272 -0
- package/skills/octocode-research/src/utils/retry.ts +280 -0
- package/skills/octocode-research/src/utils/routeFactory.ts +117 -0
- package/skills/octocode-research/src/utils/url.ts +20 -0
- package/skills/octocode-research/src/validation/httpPreprocess.ts +155 -0
- package/skills/octocode-research/src/validation/index.ts +2 -0
- package/skills/octocode-research/src/validation/schemas.ts +578 -0
- package/skills/octocode-research/src/validation/toolCallSchema.ts +132 -0
- package/skills/octocode-research/tsconfig.json +21 -0
- package/skills/octocode-research/tsdown.config.ts +42 -0
- package/skills/octocode-research/vitest.config.ts +20 -0
- package/skills/octocode-researcher/SKILL.md +461 -0
- package/skills/octocode-researcher/references/fallbacks.md +120 -0
- package/skills/{octocode-local-search → octocode-researcher}/references/tool-reference.md +132 -49
- package/skills/{octocode-local-search → octocode-researcher}/references/workflow-patterns.md +204 -4
- package/skills/octocode-rfc-generator/SKILL.md +223 -0
- package/skills/octocode-rfc-generator/references/rfc-template.md +193 -0
- package/skills/octocode-roast/SKILL.md +63 -21
- package/skills/octocode-implement/SKILL.md +0 -293
- package/skills/octocode-implement/references/execution-phases.md +0 -317
- package/skills/octocode-implement/references/tool-reference.md +0 -403
- package/skills/octocode-implement/references/workflow-patterns.md +0 -385
- package/skills/octocode-local-search/SKILL.md +0 -449
- package/skills/octocode-pr-review/SKILL.md +0 -391
- package/skills/octocode-pr-review/references/domain-reviewers.md +0 -105
- package/skills/octocode-pr-review/references/execution-lifecycle.md +0 -116
- package/skills/octocode-pr-review/references/research-flows.md +0 -75
- package/skills/octocode-research/references/tool-reference.md +0 -304
- package/skills/octocode-research/references/workflow-patterns.md +0 -325
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
addToMapSet,
|
|
7
|
+
isRelativeImport,
|
|
8
|
+
isTestFile,
|
|
9
|
+
normalizeDependencyValue,
|
|
10
|
+
resolveImportTarget,
|
|
11
|
+
toRepoPath,
|
|
12
|
+
} from '../common/utils.js';
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
AnalysisOptions,
|
|
16
|
+
DependencyProfile,
|
|
17
|
+
DependencyRecord,
|
|
18
|
+
DependencyState,
|
|
19
|
+
ExportSymbol,
|
|
20
|
+
ImportedSymbolRef,
|
|
21
|
+
ReExportRef,
|
|
22
|
+
} from '../types/index.js';
|
|
23
|
+
|
|
24
|
+
export function collectModuleDependencies(
|
|
25
|
+
sourceFile: ts.SourceFile,
|
|
26
|
+
filePath: string,
|
|
27
|
+
repoRoot: string
|
|
28
|
+
): DependencyProfile {
|
|
29
|
+
const currentDirectory = path.dirname(filePath);
|
|
30
|
+
const internal = new Set<string>();
|
|
31
|
+
const external = new Set<string>();
|
|
32
|
+
const unresolved = new Set<string>();
|
|
33
|
+
const declaredExports: ExportSymbol[] = [];
|
|
34
|
+
const importedSymbols: ImportedSymbolRef[] = [];
|
|
35
|
+
const reExports: ReExportRef[] = [];
|
|
36
|
+
|
|
37
|
+
const hasExportModifier = (node: ts.Node): boolean => {
|
|
38
|
+
if (!ts.canHaveModifiers(node)) return false;
|
|
39
|
+
return Boolean(
|
|
40
|
+
ts
|
|
41
|
+
.getModifiers(node)
|
|
42
|
+
?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const pushDeclaredExport = (item: ExportSymbol): void => {
|
|
47
|
+
if (
|
|
48
|
+
declaredExports.some(
|
|
49
|
+
entry => entry.name === item.name && entry.kind === item.kind
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
return;
|
|
53
|
+
declaredExports.push(item);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const resolveSpecifier = (specifier: string | undefined): string | null => {
|
|
57
|
+
if (!specifier || typeof specifier !== 'string') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!isRelativeImport(specifier)) {
|
|
62
|
+
external.add(specifier);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const resolved = resolveImportTarget(currentDirectory, specifier);
|
|
67
|
+
if (!resolved) {
|
|
68
|
+
unresolved.add(specifier);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!resolved.startsWith(repoRoot)) {
|
|
73
|
+
external.add(specifier);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const relativeResolved = normalizeDependencyValue(
|
|
78
|
+
path.relative(repoRoot, resolved)
|
|
79
|
+
);
|
|
80
|
+
internal.add(relativeResolved);
|
|
81
|
+
return relativeResolved;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const importLine = (
|
|
85
|
+
node: ts.Node
|
|
86
|
+
): { lineStart: number; lineEnd: number } => {
|
|
87
|
+
const start = sourceFile.getLineAndCharacterOfPosition(
|
|
88
|
+
node.getStart(sourceFile)
|
|
89
|
+
);
|
|
90
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
91
|
+
return { lineStart: start.line + 1, lineEnd: end.line + 1 };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const visit = (node: ts.Node): void => {
|
|
95
|
+
if (
|
|
96
|
+
ts.isImportDeclaration(node) &&
|
|
97
|
+
node.moduleSpecifier &&
|
|
98
|
+
ts.isStringLiteral(node.moduleSpecifier)
|
|
99
|
+
) {
|
|
100
|
+
const sourceModule = node.moduleSpecifier.text;
|
|
101
|
+
const resolvedModule = resolveSpecifier(sourceModule) ?? undefined;
|
|
102
|
+
const loc = importLine(node);
|
|
103
|
+
const clause = node.importClause;
|
|
104
|
+
if (clause) {
|
|
105
|
+
if (clause.name) {
|
|
106
|
+
importedSymbols.push({
|
|
107
|
+
sourceModule,
|
|
108
|
+
resolvedModule,
|
|
109
|
+
importedName: 'default',
|
|
110
|
+
localName: clause.name.text,
|
|
111
|
+
isTypeOnly: clause.isTypeOnly,
|
|
112
|
+
...loc,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (clause.namedBindings) {
|
|
116
|
+
if (ts.isNamespaceImport(clause.namedBindings)) {
|
|
117
|
+
importedSymbols.push({
|
|
118
|
+
sourceModule,
|
|
119
|
+
resolvedModule,
|
|
120
|
+
importedName: '*',
|
|
121
|
+
localName: clause.namedBindings.name.text,
|
|
122
|
+
isTypeOnly: clause.isTypeOnly,
|
|
123
|
+
...loc,
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
for (const element of clause.namedBindings.elements) {
|
|
127
|
+
importedSymbols.push({
|
|
128
|
+
sourceModule,
|
|
129
|
+
resolvedModule,
|
|
130
|
+
importedName: element.propertyName?.text ?? element.name.text,
|
|
131
|
+
localName: element.name.text,
|
|
132
|
+
isTypeOnly: clause.isTypeOnly || element.isTypeOnly,
|
|
133
|
+
...loc,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (
|
|
142
|
+
ts.isExportDeclaration(node) &&
|
|
143
|
+
node.moduleSpecifier &&
|
|
144
|
+
ts.isStringLiteral(node.moduleSpecifier)
|
|
145
|
+
) {
|
|
146
|
+
const sourceModule = node.moduleSpecifier.text;
|
|
147
|
+
const resolvedModule = resolveSpecifier(sourceModule) ?? undefined;
|
|
148
|
+
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
|
|
149
|
+
for (const element of node.exportClause.elements) {
|
|
150
|
+
reExports.push({
|
|
151
|
+
sourceModule,
|
|
152
|
+
resolvedModule,
|
|
153
|
+
exportedAs: element.name.text,
|
|
154
|
+
importedName: element.propertyName?.text ?? element.name.text,
|
|
155
|
+
isStar: false,
|
|
156
|
+
isTypeOnly: node.isTypeOnly || element.isTypeOnly,
|
|
157
|
+
lineStart:
|
|
158
|
+
sourceFile.getLineAndCharacterOfPosition(
|
|
159
|
+
element.getStart(sourceFile)
|
|
160
|
+
).line + 1,
|
|
161
|
+
lineEnd:
|
|
162
|
+
sourceFile.getLineAndCharacterOfPosition(element.getEnd()).line +
|
|
163
|
+
1,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
reExports.push({
|
|
168
|
+
sourceModule,
|
|
169
|
+
resolvedModule,
|
|
170
|
+
exportedAs: '*',
|
|
171
|
+
importedName: '*',
|
|
172
|
+
isStar: true,
|
|
173
|
+
isTypeOnly: node.isTypeOnly,
|
|
174
|
+
lineStart:
|
|
175
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
|
|
176
|
+
.line + 1,
|
|
177
|
+
lineEnd:
|
|
178
|
+
sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (ts.isExportAssignment(node)) {
|
|
184
|
+
pushDeclaredExport({
|
|
185
|
+
name: 'default',
|
|
186
|
+
kind: 'value',
|
|
187
|
+
isDefault: true,
|
|
188
|
+
lineStart:
|
|
189
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
|
|
190
|
+
.line + 1,
|
|
191
|
+
lineEnd:
|
|
192
|
+
sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (ts.isFunctionDeclaration(node) && hasExportModifier(node)) {
|
|
197
|
+
pushDeclaredExport({
|
|
198
|
+
name: node.name?.text || 'default',
|
|
199
|
+
kind: 'value',
|
|
200
|
+
isDefault: node.name ? false : true,
|
|
201
|
+
lineStart:
|
|
202
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
|
|
203
|
+
.line + 1,
|
|
204
|
+
lineEnd:
|
|
205
|
+
sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (ts.isClassDeclaration(node) && hasExportModifier(node)) {
|
|
210
|
+
pushDeclaredExport({
|
|
211
|
+
name: node.name?.text || 'default',
|
|
212
|
+
kind: 'value',
|
|
213
|
+
isDefault: node.name ? false : true,
|
|
214
|
+
lineStart:
|
|
215
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
|
|
216
|
+
.line + 1,
|
|
217
|
+
lineEnd:
|
|
218
|
+
sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (ts.isEnumDeclaration(node) && hasExportModifier(node)) {
|
|
223
|
+
pushDeclaredExport({
|
|
224
|
+
name: node.name.text,
|
|
225
|
+
kind: 'value',
|
|
226
|
+
lineStart:
|
|
227
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
|
|
228
|
+
.line + 1,
|
|
229
|
+
lineEnd:
|
|
230
|
+
sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (
|
|
235
|
+
(ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) &&
|
|
236
|
+
hasExportModifier(node)
|
|
237
|
+
) {
|
|
238
|
+
pushDeclaredExport({
|
|
239
|
+
name: node.name.text,
|
|
240
|
+
kind: 'type',
|
|
241
|
+
lineStart:
|
|
242
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
|
|
243
|
+
.line + 1,
|
|
244
|
+
lineEnd:
|
|
245
|
+
sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (ts.isVariableStatement(node) && hasExportModifier(node)) {
|
|
250
|
+
for (const decl of node.declarationList.declarations) {
|
|
251
|
+
if (ts.isIdentifier(decl.name)) {
|
|
252
|
+
pushDeclaredExport({
|
|
253
|
+
name: decl.name.text,
|
|
254
|
+
kind: 'value',
|
|
255
|
+
lineStart:
|
|
256
|
+
sourceFile.getLineAndCharacterOfPosition(
|
|
257
|
+
decl.getStart(sourceFile)
|
|
258
|
+
).line + 1,
|
|
259
|
+
lineEnd:
|
|
260
|
+
sourceFile.getLineAndCharacterOfPosition(decl.getEnd()).line + 1,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (
|
|
267
|
+
ts.isExportDeclaration(node) &&
|
|
268
|
+
!node.moduleSpecifier &&
|
|
269
|
+
node.exportClause &&
|
|
270
|
+
ts.isNamedExports(node.exportClause)
|
|
271
|
+
) {
|
|
272
|
+
for (const element of node.exportClause.elements) {
|
|
273
|
+
pushDeclaredExport({
|
|
274
|
+
name: element.name.text,
|
|
275
|
+
kind: element.isTypeOnly ? 'type' : 'unknown',
|
|
276
|
+
lineStart:
|
|
277
|
+
sourceFile.getLineAndCharacterOfPosition(
|
|
278
|
+
element.getStart(sourceFile)
|
|
279
|
+
).line + 1,
|
|
280
|
+
lineEnd:
|
|
281
|
+
sourceFile.getLineAndCharacterOfPosition(element.getEnd()).line + 1,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (
|
|
287
|
+
ts.isCallExpression(node) &&
|
|
288
|
+
ts.isIdentifier(node.expression) &&
|
|
289
|
+
node.expression.text === 'require' &&
|
|
290
|
+
node.arguments.length === 1 &&
|
|
291
|
+
ts.isStringLiteral(node.arguments[0])
|
|
292
|
+
) {
|
|
293
|
+
const sourceModule = node.arguments[0].text;
|
|
294
|
+
const resolvedModule = resolveSpecifier(sourceModule) ?? undefined;
|
|
295
|
+
importedSymbols.push({
|
|
296
|
+
sourceModule,
|
|
297
|
+
resolvedModule,
|
|
298
|
+
importedName: '*',
|
|
299
|
+
localName: 'require',
|
|
300
|
+
isTypeOnly: false,
|
|
301
|
+
...importLine(node),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
ts.forEachChild(node, visit);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
visit(sourceFile);
|
|
309
|
+
return {
|
|
310
|
+
internalDependencies: [...internal].sort(),
|
|
311
|
+
externalDependencies: [...external].sort(),
|
|
312
|
+
unresolvedDependencies: [...unresolved].sort(),
|
|
313
|
+
declaredExports,
|
|
314
|
+
importedSymbols,
|
|
315
|
+
reExports,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function trackDependencyEdge(
|
|
320
|
+
dependencyState: DependencyState,
|
|
321
|
+
fromFile: string,
|
|
322
|
+
toFile: string,
|
|
323
|
+
importerIsTest: boolean
|
|
324
|
+
): void {
|
|
325
|
+
addToMapSet(dependencyState.outgoing, fromFile, toFile);
|
|
326
|
+
addToMapSet(dependencyState.incoming, toFile, fromFile);
|
|
327
|
+
if (importerIsTest) {
|
|
328
|
+
addToMapSet(dependencyState.incomingFromTests, toFile, fromFile);
|
|
329
|
+
} else {
|
|
330
|
+
addToMapSet(dependencyState.incomingFromProduction, toFile, fromFile);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function collectDependencyProfile(
|
|
335
|
+
sourceFile: ts.SourceFile,
|
|
336
|
+
filePath: string,
|
|
337
|
+
packageName: string,
|
|
338
|
+
options: AnalysisOptions,
|
|
339
|
+
dependencyState: DependencyState
|
|
340
|
+
): DependencyProfile {
|
|
341
|
+
const fileRelative = toRepoPath(filePath, options.root);
|
|
342
|
+
dependencyState.files.add(fileRelative);
|
|
343
|
+
|
|
344
|
+
const deps = collectModuleDependencies(sourceFile, filePath, options.root);
|
|
345
|
+
const importerIsTest = isTestFile(filePath);
|
|
346
|
+
|
|
347
|
+
for (const internalDependency of deps.internalDependencies) {
|
|
348
|
+
const normalizedDep = normalizeDependencyValue(internalDependency);
|
|
349
|
+
trackDependencyEdge(
|
|
350
|
+
dependencyState,
|
|
351
|
+
fileRelative,
|
|
352
|
+
normalizedDep,
|
|
353
|
+
importerIsTest
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (deps.externalDependencies.length > 0) {
|
|
358
|
+
dependencyState.externalCounts.set(
|
|
359
|
+
fileRelative,
|
|
360
|
+
new Set(deps.externalDependencies)
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (deps.unresolvedDependencies.length > 0) {
|
|
365
|
+
dependencyState.unresolvedCounts.set(
|
|
366
|
+
fileRelative,
|
|
367
|
+
new Set(deps.unresolvedDependencies)
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
dependencyState.declaredExportsByFile.set(fileRelative, deps.declaredExports);
|
|
372
|
+
dependencyState.importedSymbolsByFile.set(fileRelative, deps.importedSymbols);
|
|
373
|
+
dependencyState.reExportsByFile.set(fileRelative, deps.reExports);
|
|
374
|
+
|
|
375
|
+
return {
|
|
376
|
+
...deps,
|
|
377
|
+
package: packageName,
|
|
378
|
+
file: fileRelative,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function dependencyProfileToRecord(
|
|
383
|
+
fileRelative: string,
|
|
384
|
+
dependencyState: DependencyState
|
|
385
|
+
): DependencyRecord {
|
|
386
|
+
const outbound = dependencyState.outgoing.get(fileRelative) || new Set();
|
|
387
|
+
const inbound = dependencyState.incoming.get(fileRelative) || new Set();
|
|
388
|
+
const prodIn =
|
|
389
|
+
dependencyState.incomingFromProduction.get(fileRelative) || new Set();
|
|
390
|
+
const testIn =
|
|
391
|
+
dependencyState.incomingFromTests.get(fileRelative) || new Set();
|
|
392
|
+
const external =
|
|
393
|
+
dependencyState.externalCounts.get(fileRelative) || new Set();
|
|
394
|
+
const unresolvedSet =
|
|
395
|
+
dependencyState.unresolvedCounts.get(fileRelative) || new Set();
|
|
396
|
+
|
|
397
|
+
return {
|
|
398
|
+
file: fileRelative,
|
|
399
|
+
outboundCount: outbound.size,
|
|
400
|
+
inboundCount: inbound.size,
|
|
401
|
+
inboundFromProduction: prodIn.size,
|
|
402
|
+
inboundFromTests: testIn.size,
|
|
403
|
+
externalDependencyCount: external.size,
|
|
404
|
+
unresolvedDependencyCount: unresolvedSet.size,
|
|
405
|
+
};
|
|
406
|
+
}
|