@md-code/follow-architecture 0.1.1 → 0.3.2
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/CHANGELOG.md +37 -0
- package/LICENSE +202 -0
- package/README.md +1420 -139
- package/dist/aliases.d.ts +3 -0
- package/dist/aliases.js +12 -0
- package/dist/args.d.ts +18 -0
- package/dist/args.js +94 -0
- package/dist/bin/follow-architecture.d.ts +2 -0
- package/dist/bin/follow-architecture.js +23 -0
- package/dist/closure-project.d.ts +4 -0
- package/dist/closure-project.js +132 -0
- package/dist/code-entities/classify.d.ts +11 -0
- package/dist/code-entities/classify.js +45 -0
- package/dist/code-entities/connector.d.ts +8 -0
- package/dist/code-entities/connector.js +119 -0
- package/dist/code-entities/entities.d.ts +9 -0
- package/dist/code-entities/entities.js +227 -0
- package/dist/code-entities/project.d.ts +21 -0
- package/dist/code-entities/project.js +259 -0
- package/dist/code-entities/walk.d.ts +31 -0
- package/dist/code-entities/walk.js +105 -0
- package/dist/config-options.d.ts +76 -0
- package/dist/config-options.js +52 -0
- package/dist/config-project.d.ts +4 -0
- package/dist/config-project.js +92 -0
- package/dist/config-report.d.ts +19 -0
- package/dist/config-report.js +161 -0
- package/dist/config-rule.d.ts +95 -0
- package/dist/config-rule.js +211 -0
- package/dist/config-state.d.ts +25 -0
- package/dist/config-state.js +269 -0
- package/dist/config.d.ts +107 -0
- package/dist/config.js +38 -0
- package/dist/css/index.d.ts +31 -0
- package/dist/css/index.js +251 -0
- package/dist/css/syntax/css/gate.d.ts +2 -0
- package/dist/css/syntax/css/gate.js +69 -0
- package/dist/css/syntax/css/index.d.ts +7 -0
- package/dist/css/syntax/css/index.js +51 -0
- package/dist/css/syntax/css/reference.d.ts +3 -0
- package/dist/css/syntax/css/reference.js +36 -0
- package/dist/css/syntax/language.d.ts +25 -0
- package/dist/css/syntax/language.js +81 -0
- package/dist/css/syntax/scss/index.d.ts +25 -0
- package/dist/css/syntax/scss/index.js +95 -0
- package/dist/css/syntax/scss/reference.d.ts +3 -0
- package/dist/css/syntax/scss/reference.js +17 -0
- package/dist/css/syntax/styled/document.d.ts +68 -0
- package/dist/css/syntax/styled/document.js +261 -0
- package/dist/css/syntax/styled/markup.d.ts +6 -0
- package/dist/css/syntax/styled/markup.js +84 -0
- package/dist/css/syntax/styled/tags.d.ts +2 -0
- package/dist/css/syntax/styled/tags.js +22 -0
- package/dist/css/syntax/styled/template.d.ts +23 -0
- package/dist/css/syntax/styled/template.js +67 -0
- package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
- package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
- package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
- package/dist/css/syntax/tailwind/tailwind.js +118 -0
- package/dist/css/value/check.d.ts +86 -0
- package/dist/css/value/check.js +122 -0
- package/dist/css/value/expression/arithmetic.d.ts +7 -0
- package/dist/css/value/expression/arithmetic.js +73 -0
- package/dist/css/value/expression/block.d.ts +9 -0
- package/dist/css/value/expression/block.js +92 -0
- package/dist/css/value/expression/conditional.d.ts +8 -0
- package/dist/css/value/expression/conditional.js +53 -0
- package/dist/css/value/expression/index.d.ts +5 -0
- package/dist/css/value/expression/index.js +73 -0
- package/dist/css/value/expression/map.d.ts +7 -0
- package/dist/css/value/expression/map.js +113 -0
- package/dist/css/value/object/index.d.ts +5 -0
- package/dist/css/value/object/index.js +113 -0
- package/dist/css/value/object/members.d.ts +7 -0
- package/dist/css/value/object/members.js +103 -0
- package/dist/css/value/object/node.d.ts +8 -0
- package/dist/css/value/object/node.js +134 -0
- package/dist/css/value/object/path.d.ts +10 -0
- package/dist/css/value/object/path.js +152 -0
- package/dist/css/value/pieces.d.ts +61 -0
- package/dist/css/value/pieces.js +65 -0
- package/dist/css/value/resolve.d.ts +33 -0
- package/dist/css/value/resolve.js +104 -0
- package/dist/css/value/scope.d.ts +28 -0
- package/dist/css/value/scope.js +205 -0
- package/dist/css/value/substitute.d.ts +10 -0
- package/dist/css/value/substitute.js +145 -0
- package/dist/css/value/values.d.ts +23 -0
- package/dist/css/value/values.js +131 -0
- package/dist/entities/architecture.d.ts +165 -0
- package/dist/entities/architecture.js +2 -0
- package/dist/entities/ast/assignments-nodes.d.ts +10 -0
- package/dist/entities/ast/assignments-nodes.js +64 -0
- package/dist/entities/ast/assignments-raw.d.ts +6 -0
- package/dist/entities/ast/assignments-raw.js +139 -0
- package/dist/entities/ast/assignments-tagged.d.ts +5 -0
- package/dist/entities/ast/assignments-tagged.js +195 -0
- package/dist/entities/ast/assignments.d.ts +9 -0
- package/dist/entities/ast/assignments.js +80 -0
- package/dist/entities/ast/branches.d.ts +4 -0
- package/dist/entities/ast/branches.js +32 -0
- package/dist/entities/ast/calls.d.ts +6 -0
- package/dist/entities/ast/calls.js +150 -0
- package/dist/entities/ast/classes.d.ts +5 -0
- package/dist/entities/ast/classes.js +61 -0
- package/dist/entities/ast/climb.d.ts +12 -0
- package/dist/entities/ast/climb.js +17 -0
- package/dist/entities/ast/comments.d.ts +5 -0
- package/dist/entities/ast/comments.js +130 -0
- package/dist/entities/ast/declaration.d.ts +4 -0
- package/dist/entities/ast/declaration.js +26 -0
- package/dist/entities/ast/depth.d.ts +17 -0
- package/dist/entities/ast/depth.js +166 -0
- package/dist/entities/ast/enums.d.ts +6 -0
- package/dist/entities/ast/enums.js +17 -0
- package/dist/entities/ast/export-chain.d.ts +15 -0
- package/dist/entities/ast/export-chain.js +171 -0
- package/dist/entities/ast/file-exports.d.ts +7 -0
- package/dist/entities/ast/file-exports.js +101 -0
- package/dist/entities/ast/file-facts.d.ts +16 -0
- package/dist/entities/ast/file-facts.js +64 -0
- package/dist/entities/ast/file-imports.d.ts +5 -0
- package/dist/entities/ast/file-imports.js +100 -0
- package/dist/entities/ast/file.d.ts +5 -0
- package/dist/entities/ast/file.js +23 -0
- package/dist/entities/ast/functions.d.ts +8 -0
- package/dist/entities/ast/functions.js +111 -0
- package/dist/entities/ast/heritage.d.ts +4 -0
- package/dist/entities/ast/heritage.js +44 -0
- package/dist/entities/ast/index.d.ts +9 -0
- package/dist/entities/ast/index.js +181 -0
- package/dist/entities/ast/kind.d.ts +5 -0
- package/dist/entities/ast/kind.js +34 -0
- package/dist/entities/ast/loose.d.ts +37 -0
- package/dist/entities/ast/loose.js +2 -0
- package/dist/entities/ast/modifiers.d.ts +5 -0
- package/dist/entities/ast/modifiers.js +32 -0
- package/dist/entities/ast/project.d.ts +9 -0
- package/dist/entities/ast/project.js +106 -0
- package/dist/entities/ast/properties.d.ts +11 -0
- package/dist/entities/ast/properties.js +176 -0
- package/dist/entities/ast/resolve.d.ts +16 -0
- package/dist/entities/ast/resolve.js +317 -0
- package/dist/entities/ast/tree.d.ts +31 -0
- package/dist/entities/ast/tree.js +518 -0
- package/dist/entities/ast/types.d.ts +6 -0
- package/dist/entities/ast/types.js +46 -0
- package/dist/entities/ast/usage.d.ts +11 -0
- package/dist/entities/ast/usage.js +81 -0
- package/dist/entities/ast/variables.d.ts +8 -0
- package/dist/entities/ast/variables.js +91 -0
- package/dist/entities/context.d.ts +29 -0
- package/dist/entities/context.js +2 -0
- package/dist/entities/facts.d.ts +284 -0
- package/dist/entities/facts.js +2 -0
- package/dist/entities/findings.d.ts +19 -0
- package/dist/entities/findings.js +2 -0
- package/dist/entities/kinds.d.ts +40 -0
- package/dist/entities/kinds.js +332 -0
- package/dist/entities/location/homes.d.ts +28 -0
- package/dist/entities/location/homes.js +195 -0
- package/dist/entities/location/place.d.ts +10 -0
- package/dist/entities/location/place.js +63 -0
- package/dist/entities/location/where.d.ts +19 -0
- package/dist/entities/location/where.js +277 -0
- package/dist/entities/location.d.ts +16 -0
- package/dist/entities/location.js +140 -0
- package/dist/entities/operators.d.ts +14 -0
- package/dist/entities/operators.js +30 -0
- package/dist/entities/overview/data.d.ts +43 -0
- package/dist/entities/overview/data.js +2 -0
- package/dist/entities/overview/decision.d.ts +60 -0
- package/dist/entities/overview/decision.js +2 -0
- package/dist/entities/overview/file-tree.d.ts +10 -0
- package/dist/entities/overview/file-tree.js +2 -0
- package/dist/entities/overview/finding.d.ts +58 -0
- package/dist/entities/overview/finding.js +2 -0
- package/dist/entities/overview/graph.d.ts +82 -0
- package/dist/entities/overview/graph.js +2 -0
- package/dist/entities/overview/input.d.ts +15 -0
- package/dist/entities/overview/input.js +2 -0
- package/dist/entities/overview/summaries.d.ts +81 -0
- package/dist/entities/overview/summaries.js +2 -0
- package/dist/entities/place.d.ts +5 -0
- package/dist/entities/place.js +2 -0
- package/dist/entities/queries.d.ts +9 -0
- package/dist/entities/queries.js +375 -0
- package/dist/entities/repair.d.ts +16 -0
- package/dist/entities/repair.js +29 -0
- package/dist/entities/schema.d.ts +22 -0
- package/dist/entities/schema.js +81 -0
- package/dist/entities/story.d.ts +47 -0
- package/dist/entities/story.js +2 -0
- package/dist/entities/structure-facts.d.ts +11 -0
- package/dist/entities/structure-facts.js +2 -0
- package/dist/entities/token.d.ts +23 -0
- package/dist/entities/token.js +2 -0
- package/dist/entities/tree/build.d.ts +6 -0
- package/dist/entities/tree/build.js +313 -0
- package/dist/entities/tree/entries.d.ts +7 -0
- package/dist/entities/tree/entries.js +145 -0
- package/dist/entities/tree/index.d.ts +6 -0
- package/dist/entities/tree/index.js +21 -0
- package/dist/entities/tree/match.d.ts +17 -0
- package/dist/entities/tree/match.js +190 -0
- package/dist/fa-index.d.ts +16 -0
- package/dist/fa-index.js +165 -0
- package/dist/fa-open.d.ts +51 -0
- package/dist/fa-open.js +242 -0
- package/dist/fa-store.d.ts +22 -0
- package/dist/fa-store.js +232 -0
- package/dist/fa-values.d.ts +37 -0
- package/dist/fa-values.js +104 -0
- package/dist/facts-record.d.ts +45 -0
- package/dist/facts-record.js +297 -0
- package/dist/frameworks/angular/index.d.ts +7 -0
- package/dist/frameworks/angular/index.js +18 -0
- package/dist/frameworks/facet.d.ts +18 -0
- package/dist/frameworks/facet.js +15 -0
- package/dist/frameworks/index.d.ts +9 -0
- package/dist/frameworks/index.js +134 -0
- package/dist/frameworks/react/index.d.ts +7 -0
- package/dist/frameworks/react/index.js +237 -0
- package/dist/frameworks/test/index.d.ts +6 -0
- package/dist/frameworks/test/index.js +157 -0
- package/dist/frameworks/vue/index.d.ts +7 -0
- package/dist/frameworks/vue/index.js +18 -0
- package/dist/ignore.d.ts +3 -0
- package/dist/ignore.js +62 -0
- package/dist/index-file.d.ts +43 -0
- package/dist/index-file.js +218 -0
- package/dist/index-run.d.ts +39 -0
- package/dist/index-run.js +217 -0
- package/dist/index-zone.d.ts +25 -0
- package/dist/index-zone.js +219 -0
- package/dist/main.d.ts +10 -0
- package/dist/main.js +411 -0
- package/dist/nodes/child-entities.d.ts +3 -0
- package/dist/nodes/child-entities.js +12 -0
- package/dist/nodes/children.d.ts +25 -0
- package/dist/nodes/children.js +165 -0
- package/dist/nodes/finally/emit.d.ts +6 -0
- package/dist/nodes/finally/emit.js +71 -0
- package/dist/nodes/finally/entities.d.ts +13 -0
- package/dist/nodes/finally/entities.js +42 -0
- package/dist/nodes/finally/index.d.ts +8 -0
- package/dist/nodes/finally/index.js +35 -0
- package/dist/nodes/finally/queries.d.ts +5 -0
- package/dist/nodes/finally/queries.js +25 -0
- package/dist/nodes/finally/relations-access.d.ts +5 -0
- package/dist/nodes/finally/relations-access.js +50 -0
- package/dist/nodes/finally/relations-edge.d.ts +29 -0
- package/dist/nodes/finally/relations-edge.js +148 -0
- package/dist/nodes/finally/relations-group.d.ts +31 -0
- package/dist/nodes/finally/relations-group.js +106 -0
- package/dist/nodes/finally/relations.d.ts +5 -0
- package/dist/nodes/finally/relations.js +85 -0
- package/dist/nodes/finally/required.d.ts +5 -0
- package/dist/nodes/finally/required.js +92 -0
- package/dist/nodes/finally/violation.d.ts +17 -0
- package/dist/nodes/finally/violation.js +2 -0
- package/dist/nodes/similar.d.ts +21 -0
- package/dist/nodes/similar.js +178 -0
- package/dist/piece-forms.d.ts +9 -0
- package/dist/piece-forms.js +68 -0
- package/dist/pipeline-entities.d.ts +6 -0
- package/dist/pipeline-entities.js +79 -0
- package/dist/pipeline-facts.d.ts +12 -0
- package/dist/pipeline-facts.js +114 -0
- package/dist/pipeline-unclassified.d.ts +14 -0
- package/dist/pipeline-unclassified.js +188 -0
- package/dist/pipeline.d.ts +7 -0
- package/dist/pipeline.js +28 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +3 -0
- package/dist/release-file.d.ts +3 -0
- package/dist/release-file.js +13 -0
- package/dist/report/asks.d.ts +55 -0
- package/dist/report/asks.js +60 -0
- package/dist/report/cli-report.d.ts +2 -0
- package/dist/report/cli-report.js +13 -0
- package/dist/report/config-error-guard.d.ts +8 -0
- package/dist/report/config-error-guard.js +5 -0
- package/dist/report/configErrors.d.ts +126 -0
- package/dist/report/configErrors.js +121 -0
- package/dist/report/errorTypes/codes/structure.d.ts +15 -0
- package/dist/report/errorTypes/codes/structure.js +76 -0
- package/dist/report/errorTypes/decision-maker.d.ts +23 -0
- package/dist/report/errorTypes/decision-maker.js +109 -0
- package/dist/report/errorTypes/destinations.d.ts +38 -0
- package/dist/report/errorTypes/destinations.js +165 -0
- package/dist/report/errorTypes/finding-type.d.ts +11 -0
- package/dist/report/errorTypes/finding-type.js +2 -0
- package/dist/report/errorTypes/index.d.ts +15 -0
- package/dist/report/errorTypes/index.js +55 -0
- package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
- package/dist/report/errorTypes/types/fileContents.js +40 -0
- package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
- package/dist/report/errorTypes/types/unknownEntity.js +27 -0
- package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
- package/dist/report/errorTypes/types/wrongAction.js +140 -0
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
- package/dist/report/errorTypes/types/wrongPlacement.js +67 -0
- package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
- package/dist/report/errorTypes/vocabulary/ids.js +16 -0
- package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
- package/dist/report/errorTypes/vocabulary/phrases.js +187 -0
- package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
- package/dist/report/errorTypes/vocabulary/places.js +36 -0
- package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
- package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
- package/dist/report/finding-from.d.ts +9 -0
- package/dist/report/finding-from.js +108 -0
- package/dist/report/notices.d.ts +9 -0
- package/dist/report/notices.js +57 -0
- package/dist/report/observed.d.ts +19 -0
- package/dist/report/observed.js +87 -0
- package/dist/report/render-report.d.ts +12 -0
- package/dist/report/render-report.js +145 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +188 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +1262 -0
- package/dist/report/user-report/data/collect.d.ts +4 -0
- package/dist/report/user-report/data/collect.js +93 -0
- package/dist/report/user-report/data/entities.d.ts +7 -0
- package/dist/report/user-report/data/entities.js +88 -0
- package/dist/report/user-report/data/entity-examples.d.ts +16 -0
- package/dist/report/user-report/data/entity-examples.js +136 -0
- package/dist/report/user-report/data/entity-filters.d.ts +15 -0
- package/dist/report/user-report/data/entity-filters.js +79 -0
- package/dist/report/user-report/data/entity-marks.d.ts +5 -0
- package/dist/report/user-report/data/entity-marks.js +79 -0
- package/dist/report/user-report/data/file-tree.d.ts +9 -0
- package/dist/report/user-report/data/file-tree.js +80 -0
- package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
- package/dist/report/user-report/data/finding-boundary.js +21 -0
- package/dist/report/user-report/data/finding-plan.d.ts +16 -0
- package/dist/report/user-report/data/finding-plan.js +45 -0
- package/dist/report/user-report/data/finding-title.d.ts +12 -0
- package/dist/report/user-report/data/finding-title.js +36 -0
- package/dist/report/user-report/data/findings.d.ts +10 -0
- package/dist/report/user-report/data/findings.js +181 -0
- package/dist/report/user-report/data/graph-edges.d.ts +19 -0
- package/dist/report/user-report/data/graph-edges.js +109 -0
- package/dist/report/user-report/data/graph-entities.d.ts +6 -0
- package/dist/report/user-report/data/graph-entities.js +158 -0
- package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
- package/dist/report/user-report/data/graph-helpers.js +67 -0
- package/dist/report/user-report/data/graph.d.ts +12 -0
- package/dist/report/user-report/data/graph.js +97 -0
- package/dist/report/user-report/data/nodes.d.ts +11 -0
- package/dist/report/user-report/data/nodes.js +116 -0
- package/dist/report/user-report/data/rules.d.ts +7 -0
- package/dist/report/user-report/data/rules.js +62 -0
- package/dist/report/user-report/data/scan.d.ts +8 -0
- package/dist/report/user-report/data/scan.js +69 -0
- package/dist/report/user-report/html/shell.d.ts +3 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +8 -0
- package/dist/report/user-report/index.js +58 -0
- package/dist/report/user-report/shared/describe.d.ts +7 -0
- package/dist/report/user-report/shared/describe.js +86 -0
- package/dist/rules/index.d.ts +7 -0
- package/dist/rules/index.js +327 -0
- package/dist/rules/list-vars.d.ts +5 -0
- package/dist/rules/list-vars.js +149 -0
- package/dist/rules/name.d.ts +16 -0
- package/dist/rules/name.js +18 -0
- package/dist/rules/normalize.d.ts +5 -0
- package/dist/rules/normalize.js +108 -0
- package/dist/rules/vars.d.ts +22 -0
- package/dist/rules/vars.js +117 -0
- package/dist/scan-run.d.ts +20 -0
- package/dist/scan-run.js +130 -0
- package/dist/scripts/audit-report.d.ts +2 -0
- package/dist/scripts/audit-report.js +157 -0
- package/dist/usage-index.d.ts +4 -0
- package/dist/usage-index.js +282 -0
- package/dist/usage-mode.d.ts +7 -0
- package/dist/usage-mode.js +16 -0
- package/dist/usage-pass.d.ts +19 -0
- package/dist/usage-pass.js +136 -0
- package/dist/usage-prepare.d.ts +2 -0
- package/dist/usage-prepare.js +22 -0
- package/dist/usage-sweep.d.ts +10 -0
- package/dist/usage-sweep.js +264 -0
- package/dist/utils/accumulate.d.ts +6 -0
- package/dist/utils/accumulate.js +18 -0
- package/dist/utils/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +173 -0
- package/dist/utils/article.d.ts +2 -0
- package/dist/utils/article.js +12 -0
- package/dist/utils/classify.d.ts +12 -0
- package/dist/utils/classify.js +25 -0
- package/dist/utils/configs.d.ts +25 -0
- package/dist/utils/configs.js +97 -0
- package/dist/utils/count.d.ts +7 -0
- package/dist/utils/count.js +13 -0
- package/dist/utils/dispatch.d.ts +2 -0
- package/dist/utils/dispatch.js +27 -0
- package/dist/utils/distinct.d.ts +2 -0
- package/dist/utils/distinct.js +14 -0
- package/dist/utils/field.d.ts +14 -0
- package/dist/utils/field.js +60 -0
- package/dist/utils/file-name.d.ts +2 -0
- package/dist/utils/file-name.js +11 -0
- package/dist/utils/files.d.ts +7 -0
- package/dist/utils/files.js +77 -0
- package/dist/utils/fixpoint.d.ts +2 -0
- package/dist/utils/fixpoint.js +19 -0
- package/dist/utils/gate.d.ts +2 -0
- package/dist/utils/gate.js +12 -0
- package/dist/utils/group.d.ts +3 -0
- package/dist/utils/group.js +33 -0
- package/dist/utils/host.d.ts +3 -0
- package/dist/utils/host.js +16 -0
- package/dist/utils/imports.d.ts +12 -0
- package/dist/utils/imports.js +185 -0
- package/dist/utils/judged.d.ts +5 -0
- package/dist/utils/judged.js +19 -0
- package/dist/utils/keyed.d.ts +2 -0
- package/dist/utils/keyed.js +23 -0
- package/dist/utils/map-record.d.ts +2 -0
- package/dist/utils/map-record.js +11 -0
- package/dist/utils/packages.d.ts +15 -0
- package/dist/utils/packages.js +207 -0
- package/dist/utils/path-label.d.ts +6 -0
- package/dist/utils/path-label.js +37 -0
- package/dist/utils/pattern.d.ts +19 -0
- package/dist/utils/pattern.js +231 -0
- package/dist/utils/permission.d.ts +16 -0
- package/dist/utils/permission.js +18 -0
- package/dist/utils/plural.d.ts +2 -0
- package/dist/utils/plural.js +9 -0
- package/dist/utils/qualified.d.ts +2 -0
- package/dist/utils/qualified.js +21 -0
- package/dist/utils/rank.d.ts +2 -0
- package/dist/utils/rank.js +24 -0
- package/dist/utils/read-field.d.ts +12 -0
- package/dist/utils/read-field.js +50 -0
- package/dist/utils/read-when.d.ts +2 -0
- package/dist/utils/read-when.js +17 -0
- package/dist/utils/reason.d.ts +4 -0
- package/dist/utils/reason.js +9 -0
- package/dist/utils/record.d.ts +3 -0
- package/dist/utils/record.js +21 -0
- package/dist/utils/resolve.d.ts +2 -0
- package/dist/utils/resolve.js +24 -0
- package/dist/utils/search.d.ts +2 -0
- package/dist/utils/search.js +21 -0
- package/dist/utils/seen.d.ts +6 -0
- package/dist/utils/seen.js +27 -0
- package/dist/utils/span.d.ts +5 -0
- package/dist/utils/span.js +2 -0
- package/dist/utils/speak.d.ts +2 -0
- package/dist/utils/speak.js +18 -0
- package/dist/utils/split.d.ts +8 -0
- package/dist/utils/split.js +21 -0
- package/dist/utils/template.d.ts +5 -0
- package/dist/utils/template.js +5 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.js +42 -0
- package/dist/utils/tokenize.d.ts +2 -0
- package/dist/utils/tokenize.js +18 -0
- package/dist/utils/try-read.d.ts +4 -0
- package/dist/utils/try-read.js +24 -0
- package/dist/utils/typed-field.d.ts +3 -0
- package/dist/utils/typed-field.js +16 -0
- package/dist/utils/verdicts.d.ts +4 -0
- package/dist/utils/verdicts.js +20 -0
- package/entities/operators.ts +31 -0
- package/package.json +101 -47
- package/report/errorTypes/vocabulary/ids.ts +17 -0
- package/report/errorTypes/vocabulary/phrases.ts +181 -0
- package/report/errorTypes/vocabulary/places.ts +51 -0
- package/report/errorTypes/vocabulary/verbs.ts +31 -0
- package/report/user-report/shared/describe.ts +107 -0
- package/ast.js +0 -107
- package/bin/follow-architecture.js +0 -6
- package/config.js +0 -101
- package/entities/aliases.js +0 -10
- package/entities/invariants.js +0 -134
- package/entities/nodes.js +0 -112
- package/main.js +0 -96
- package/plugin.js +0 -5
- package/report.js +0 -73
- package/utils.js +0 -104
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classFact = void 0;
|
|
4
|
+
const tree_1 = require("./tree");
|
|
5
|
+
const modifiers_1 = require("./modifiers");
|
|
6
|
+
// The declared type of a member, else the text of its initializer — what a
|
|
7
|
+
// filter reads as the member's `type`.
|
|
8
|
+
const memberType = (m) => {
|
|
9
|
+
const typeNode = typeof m.getTypeNode === "function" ? m.getTypeNode() : null;
|
|
10
|
+
if (typeNode)
|
|
11
|
+
return typeNode.getText();
|
|
12
|
+
const initializer = typeof m.getInitializer === "function" ? m.getInitializer() : null;
|
|
13
|
+
return initializer ? initializer.getText() : null;
|
|
14
|
+
};
|
|
15
|
+
// The visibility word a member carries, when it carries one.
|
|
16
|
+
const VISIBILITY = ["private", "protected", "public"];
|
|
17
|
+
// What a member IS, beyond its name: a `#private` field, a `static` one, a
|
|
18
|
+
// `readonly`/`accessor` one, the visibility word, its type and the fact that a
|
|
19
|
+
// `static {}` block runs at class definition.
|
|
20
|
+
const memberFact = (m) => {
|
|
21
|
+
const name = m.getName?.() ?? null;
|
|
22
|
+
const words = (typeof m.getModifiers === "function" ? m.getModifiers() : []).map((x) => x.getText());
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
is: (0, tree_1.kindName)(m),
|
|
26
|
+
// `#value` is a name the language keeps private: `name` starts with `#`.
|
|
27
|
+
private: Boolean(name?.startsWith("#")),
|
|
28
|
+
static: Boolean(m.isStatic?.()),
|
|
29
|
+
readonly: words.includes("readonly"),
|
|
30
|
+
accessor: words.includes("accessor"),
|
|
31
|
+
visibility: words.find((w) => VISIBILITY.includes(w)) ?? null,
|
|
32
|
+
type: memberType(m),
|
|
33
|
+
decorators: (0, modifiers_1.decoratorsOf)(m),
|
|
34
|
+
line: (0, tree_1.startLine)(m),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const constructorParamsOf = (ctor) => (ctor?.getParameters?.() ?? []).map((p) => ({
|
|
38
|
+
name: p.getName?.() ?? "",
|
|
39
|
+
type: p.getTypeNode?.()?.getText() ?? null,
|
|
40
|
+
decorators: (0, modifiers_1.decoratorsOf)(p),
|
|
41
|
+
}));
|
|
42
|
+
// A class is a candidate like any other, so it receives every generic candidate
|
|
43
|
+
// fact (location, lines, kind, calls, assignments …) and adds only what a
|
|
44
|
+
// class has and nothing else does.
|
|
45
|
+
const classFact = (node, base) => {
|
|
46
|
+
const ctor = node.getConstructors()[0] ?? null;
|
|
47
|
+
const members = node.getMembers();
|
|
48
|
+
const baseExpr = node.getExtends();
|
|
49
|
+
return {
|
|
50
|
+
...base,
|
|
51
|
+
members: members.map(memberFact),
|
|
52
|
+
// `static { … }` runs once, at class definition — not a member, but code.
|
|
53
|
+
// The parser spells it `ClassStaticBlockDeclaration`.
|
|
54
|
+
staticBlocks: members.filter((m) => (0, tree_1.kindName)(m).includes("StaticBlock")).length,
|
|
55
|
+
extends: baseExpr ? (0, tree_1.nodeText)(baseExpr) : null,
|
|
56
|
+
implements: node.getImplements().map(tree_1.nodeText),
|
|
57
|
+
constructorParams: constructorParamsOf(ctor),
|
|
58
|
+
hasConstructor: Boolean(ctor),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.classFact = classFact;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node } from "ts-morph";
|
|
2
|
+
interface ClimbVerdicts {
|
|
3
|
+
isHolder: (node: Node) => boolean;
|
|
4
|
+
passesThrough?: (node: Node) => boolean;
|
|
5
|
+
}
|
|
6
|
+
type ClimbStop = {
|
|
7
|
+
node: Node;
|
|
8
|
+
found: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const climbFrom: (start: Node, { isHolder, passesThrough }: ClimbVerdicts) => ClimbStop;
|
|
11
|
+
export { climbFrom };
|
|
12
|
+
export type { ClimbVerdicts, ClimbStop };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.climbFrom = void 0;
|
|
4
|
+
const climbFrom = (start, { isHolder, passesThrough }) => {
|
|
5
|
+
let current = start;
|
|
6
|
+
for (;;) {
|
|
7
|
+
if (isHolder(current))
|
|
8
|
+
return { node: current, found: true };
|
|
9
|
+
if (passesThrough && !passesThrough(current))
|
|
10
|
+
return { node: current, found: false };
|
|
11
|
+
const parent = current.getParent();
|
|
12
|
+
if (!parent)
|
|
13
|
+
return { node: current, found: false };
|
|
14
|
+
current = parent;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.climbFrom = climbFrom;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SourceFile } from "ts-morph";
|
|
2
|
+
import type { Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
3
|
+
declare const commentsOf: (sf: SourceFile, rel: string | null) => Candidate[];
|
|
4
|
+
declare const releaseComments: (sf: SourceFile) => void;
|
|
5
|
+
export { commentsOf, releaseComments };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseComments = exports.commentsOf = void 0;
|
|
4
|
+
const tree_1 = require("./tree");
|
|
5
|
+
const kind_1 = require("./kind");
|
|
6
|
+
const functions_1 = require("./functions");
|
|
7
|
+
// The three forms the language distinguishes. The doc form is not a separate
|
|
8
|
+
// trivia kind to the compiler — it is a block comment whose text opens with
|
|
9
|
+
// `*` — but it is a separate thing to every reader and to the tooling, so it is
|
|
10
|
+
// named as its own kind instead of leaving the YAML to slice strings.
|
|
11
|
+
const kindOf = (range, text) => {
|
|
12
|
+
if (range.getKind() === tree_1.SK.SingleLineCommentTrivia)
|
|
13
|
+
return "SingleLineCommentTrivia";
|
|
14
|
+
return text.startsWith("/**") ? "JSDocComment" : "MultiLineCommentTrivia";
|
|
15
|
+
};
|
|
16
|
+
// Every comment in the file, each once, in document order. A comment is trivia
|
|
17
|
+
// of the token that follows it, so the walk asks every node for the comments
|
|
18
|
+
// around it and keeps them by position — the file itself carries the ones above
|
|
19
|
+
// the first token.
|
|
20
|
+
const rangesOf = (sf, descendants) => {
|
|
21
|
+
const text = sf.getFullText();
|
|
22
|
+
const byPos = new Map();
|
|
23
|
+
for (const node of [sf, ...descendants]) {
|
|
24
|
+
const ranges = [...(node.getLeadingCommentRanges?.() ?? []), ...(node.getTrailingCommentRanges?.() ?? [])];
|
|
25
|
+
for (const range of ranges)
|
|
26
|
+
if (!byPos.has(range.getPos()))
|
|
27
|
+
byPos.set(range.getPos(), range);
|
|
28
|
+
}
|
|
29
|
+
return [...byPos.values()]
|
|
30
|
+
.sort((a, b) => a.getPos() - b.getPos())
|
|
31
|
+
.map((range) => ({
|
|
32
|
+
pos: range.getPos(),
|
|
33
|
+
end: range.getEnd(),
|
|
34
|
+
kind: kindOf(range, text.slice(range.getPos(), range.getEnd())),
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
// A comment is TRIVIA — text between tokens — but the parser still builds a node
|
|
38
|
+
// for a doc block, and that node has a subtree of its own: `JSDocParameterTag`
|
|
39
|
+
// (with the parameter's name), `JSDocReturnTag`, `JSDocTypeExpression`… So the
|
|
40
|
+
// inside of a doc block is described by the SAME machinery as any other node —
|
|
41
|
+
// no `tags` field, no list of known tag names, nothing to keep in sync with the
|
|
42
|
+
// language. Any comment that has no node of its own simply has no subtree.
|
|
43
|
+
const nodesByPos = (descendants) => {
|
|
44
|
+
const byPos = new Map();
|
|
45
|
+
for (const node of descendants)
|
|
46
|
+
if (!byPos.has(node.getStart()))
|
|
47
|
+
byPos.set(node.getStart(), node);
|
|
48
|
+
return byPos;
|
|
49
|
+
};
|
|
50
|
+
// The lines a comment covers. `end` is exclusive, so the last line is the one
|
|
51
|
+
// the last character sits on — a block that ends with `*/` belongs to its own
|
|
52
|
+
// last line, not to the one after it.
|
|
53
|
+
const linesOfRange = (sf, pos, end) => {
|
|
54
|
+
const first = sf.getLineAndColumnAtPos(pos).line;
|
|
55
|
+
const last = sf.getLineAndColumnAtPos(Math.max(pos, end - 1)).line;
|
|
56
|
+
return (0, tree_1.rangeLines)(first, last);
|
|
57
|
+
};
|
|
58
|
+
// The deepest function or class a comment sits inside. A doc block above a
|
|
59
|
+
// declaration is NOT inside it (it starts before the declaration does), which is
|
|
60
|
+
// the distinction a rule needs to say "no comments outside the action". The
|
|
61
|
+
// candidates are the file's function/class nodes, gathered once.
|
|
62
|
+
const pieceAt = (pos, pieces) => {
|
|
63
|
+
let best = null;
|
|
64
|
+
for (const node of pieces) {
|
|
65
|
+
if (node.getStart() > pos || node.getEnd() < pos)
|
|
66
|
+
continue;
|
|
67
|
+
if (!best || node.getStart() > best.getStart())
|
|
68
|
+
best = node;
|
|
69
|
+
}
|
|
70
|
+
return best;
|
|
71
|
+
};
|
|
72
|
+
// The comment's `kind`: its own syntactic form, and — when the parser has a
|
|
73
|
+
// node for it — the node's whole neighbourhood and subtree, read through `is`
|
|
74
|
+
// like any other code.
|
|
75
|
+
const commentKind = (node, kind) => node ? { ...(0, tree_1.kindFact)(node), ...(0, kind_1.spelled)(kind), own: { is: kind } } : (0, kind_1.spelled)(kind);
|
|
76
|
+
// The candidates. Each one carries the same facts every other candidate carries
|
|
77
|
+
// (where it is, the lines it spans, what kind it is) plus what only a comment
|
|
78
|
+
// has: its text, markers included — the markers are what tells a doc block from
|
|
79
|
+
// a plain block, and stripping them would throw that away.
|
|
80
|
+
const commentCandidate = (sf, rel, view, span) => {
|
|
81
|
+
const piece = pieceAt(span.pos, view.pieces);
|
|
82
|
+
return {
|
|
83
|
+
name: null,
|
|
84
|
+
location: { path: rel ?? null, piece: piece ? ((0, functions_1.nameOf)(piece) ?? null) : null, nested: Boolean(piece) },
|
|
85
|
+
lines: linesOfRange(sf, span.pos, span.end),
|
|
86
|
+
kind: commentKind(view.nodes.get(span.pos), span.kind),
|
|
87
|
+
text: sf.getFullText().slice(span.pos, span.end),
|
|
88
|
+
// A comment has no actions: it runs nothing, writes nothing, yields
|
|
89
|
+
// nothing. Stated, because every candidate answers every question.
|
|
90
|
+
returns: [],
|
|
91
|
+
calls: [],
|
|
92
|
+
branches: [],
|
|
93
|
+
assignments: [],
|
|
94
|
+
parameters: [],
|
|
95
|
+
exported: false,
|
|
96
|
+
mutable: false,
|
|
97
|
+
references: null,
|
|
98
|
+
implementations: null,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
// A file's comments are the same every time it is walked in a run, and candidate
|
|
102
|
+
// collection walks the same file in several places (the linted file's pipeline and
|
|
103
|
+
// the project-wide index). So the comments are built once per SourceFile and handed
|
|
104
|
+
// out as shallow copies — the facets attach fields to the candidate they were
|
|
105
|
+
// handed. Guarded by the file's current text: overwriting a SourceFile in place
|
|
106
|
+
// yields a new comment set.
|
|
107
|
+
const COMMENTS = new WeakMap();
|
|
108
|
+
const commentsOf = (sf, rel) => {
|
|
109
|
+
const text = sf.getFullText();
|
|
110
|
+
const cached = COMMENTS.get(sf);
|
|
111
|
+
if (cached && cached.text === text)
|
|
112
|
+
return cached.list.map((c) => ({ ...c }));
|
|
113
|
+
const descendants = (0, tree_1.fileDescendants)(sf);
|
|
114
|
+
const view = {
|
|
115
|
+
nodes: nodesByPos(descendants),
|
|
116
|
+
pieces: descendants.filter((n) => (0, tree_1.isFunctionNode)(n) || (0, tree_1.isClassNode)(n)),
|
|
117
|
+
};
|
|
118
|
+
const list = rangesOf(sf, descendants).map((span) => commentCandidate(sf, rel, view, span));
|
|
119
|
+
COMMENTS.set(sf, { text, list });
|
|
120
|
+
return list.map((c) => ({ ...c }));
|
|
121
|
+
};
|
|
122
|
+
exports.commentsOf = commentsOf;
|
|
123
|
+
// Drop this file's cached comment candidates. A run that is done with a file's
|
|
124
|
+
// syntax releases them with the rest of the file (see `entities/ast/tree.ts`):
|
|
125
|
+
// the list is plain data, but it is derived from the file and must not outlive
|
|
126
|
+
// the walk that needed it.
|
|
127
|
+
const releaseComments = (sf) => {
|
|
128
|
+
COMMENTS.delete(sf);
|
|
129
|
+
};
|
|
130
|
+
exports.releaseComments = releaseComments;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.declarationFact = void 0;
|
|
4
|
+
// The candidate fact every "declares a name with no code inside it" node shares:
|
|
5
|
+
// an `enum` and a `type`/`interface` are candidates like any other, so they
|
|
6
|
+
// carry the same generic fields (kind, name, location, lines, the empty action
|
|
7
|
+
// lists, whether they are published) and add only their own `members`. The
|
|
8
|
+
// shape lives here once; `enums.js` and `types.js` supply the members their
|
|
9
|
+
// syntax actually has.
|
|
10
|
+
const tree_1 = require("./tree");
|
|
11
|
+
const kind_1 = require("./kind");
|
|
12
|
+
const declarationFact = (node, rel, members) => ({
|
|
13
|
+
kind: (0, kind_1.kindOf)(node),
|
|
14
|
+
name: node.getName?.() ?? null,
|
|
15
|
+
location: { path: rel ?? null, piece: null },
|
|
16
|
+
lines: (0, tree_1.linesOf)(node),
|
|
17
|
+
returns: [],
|
|
18
|
+
calls: [],
|
|
19
|
+
branches: [],
|
|
20
|
+
assignments: [],
|
|
21
|
+
parameters: [],
|
|
22
|
+
members,
|
|
23
|
+
exported: (0, tree_1.isExported)(node),
|
|
24
|
+
mutable: false,
|
|
25
|
+
});
|
|
26
|
+
exports.declarationFact = declarationFact;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
2
|
+
import type { ScanContext } from "@md-code/follow-architecture/entities/context";
|
|
3
|
+
type Chain = {
|
|
4
|
+
depth: number;
|
|
5
|
+
chain: string[];
|
|
6
|
+
};
|
|
7
|
+
type DepthCache = {
|
|
8
|
+
memo: Map<string, Chain>;
|
|
9
|
+
files: Map<string, Candidate[]>;
|
|
10
|
+
};
|
|
11
|
+
type DepthWalk = ScanContext & {
|
|
12
|
+
rel: string;
|
|
13
|
+
cache?: DepthCache;
|
|
14
|
+
};
|
|
15
|
+
declare const attachCallDepth: (candidates: Candidate[], ctx: DepthWalk) => Candidate[];
|
|
16
|
+
export { attachCallDepth };
|
|
17
|
+
export type { DepthCache, Chain };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.attachCallDepth = void 0;
|
|
37
|
+
// How many calls deep a piece of code goes before somebody else does the work.
|
|
38
|
+
//
|
|
39
|
+
// A piece that calls an imported function which calls another which calls
|
|
40
|
+
// another is not readable at the call site: nobody can see where the state is
|
|
41
|
+
// finally changed, and no entity rule can point at the place that changed it.
|
|
42
|
+
// The chain is what this fact measures — `toggleLineAction → applyDecorations →
|
|
43
|
+
// applyActiveEditorDecorations → …` is a depth of 5, and a rule may refuse it.
|
|
44
|
+
//
|
|
45
|
+
// The walk follows the facts the AST already produces: a bare-identifier call
|
|
46
|
+
// carries `target: { path, name }`, so the next piece is found by parsing that
|
|
47
|
+
// module and looking for the name. Files are parsed once per run and every
|
|
48
|
+
// (file, name) pair is memoised, so a chain is walked once however often it is
|
|
49
|
+
// asked about. A cycle stops the walk (a recursive helper is not "deeper").
|
|
50
|
+
const fs = __importStar(require("node:fs"));
|
|
51
|
+
const path = __importStar(require("node:path"));
|
|
52
|
+
const index_1 = require("./index");
|
|
53
|
+
const index_2 = require("@md-code/follow-architecture/frameworks/index");
|
|
54
|
+
const notices_1 = require("@md-code/follow-architecture/report/notices");
|
|
55
|
+
const try_read_1 = require("@md-code/follow-architecture/utils/try-read");
|
|
56
|
+
const reason_1 = require("@md-code/follow-architecture/utils/reason");
|
|
57
|
+
// How many files' candidate lists the cache keeps. A chain is answered from the
|
|
58
|
+
// file's TEXT and never changes inside a run, so a file that falls out of the
|
|
59
|
+
// cache is read again — the bound trades a re-read for the memory a whole repo's
|
|
60
|
+
// candidates would take, and the answers do not depend on it.
|
|
61
|
+
const MAX_CACHED_FILES = 64;
|
|
62
|
+
// A link's target: an imported name names its module (followed only when the
|
|
63
|
+
// module is a repo file); a local name is walked in this file. A link back to
|
|
64
|
+
// the piece itself is not a step.
|
|
65
|
+
const follow = (link, at, ctx, stack) => {
|
|
66
|
+
if (link.module)
|
|
67
|
+
return (ctx.repoFiles ?? []).includes(link.module) ? depthOf(link.module, link.name, ctx, stack) : null;
|
|
68
|
+
if (at.local.has(link.name) && link.name !== at.name)
|
|
69
|
+
return depthOf(at.rel, link.name, ctx, stack);
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
// Where a CALL leads next: an imported symbol names its module; otherwise the
|
|
73
|
+
// invoked member is followed when it names a piece in this file — a bare call
|
|
74
|
+
// (`f()`) and a member call (`new B().n()`, `this.step()`) are both ways one
|
|
75
|
+
// piece hands work to another.
|
|
76
|
+
const nextOf = (call, at, ctx, stack) => follow({ name: call.target?.path ? (call.target.name ?? "") : (call.action ?? ""), module: call.target?.path ?? null }, at, ctx, stack);
|
|
77
|
+
// The longest chain among everything a piece hands work to: the calls it makes
|
|
78
|
+
// and the components it renders. A framework that reads markup supplies its
|
|
79
|
+
// links as facts (`framework.links`); the walk needs no framework of its own.
|
|
80
|
+
const deepestLink = (piece, at, ctx, stack) => {
|
|
81
|
+
let best = { depth: 0, chain: [] };
|
|
82
|
+
for (const call of piece.calls ?? []) {
|
|
83
|
+
const next = nextOf(call, at, ctx, stack);
|
|
84
|
+
if (next && next.depth > best.depth)
|
|
85
|
+
best = next;
|
|
86
|
+
}
|
|
87
|
+
for (const link of piece.framework?.links ?? []) {
|
|
88
|
+
const next = follow(link, at, ctx, stack);
|
|
89
|
+
if (next && next.depth > best.depth)
|
|
90
|
+
best = next;
|
|
91
|
+
}
|
|
92
|
+
return best;
|
|
93
|
+
};
|
|
94
|
+
const depthOf = (rel, name, ctx, stack) => {
|
|
95
|
+
const key = `${rel}#${name}`;
|
|
96
|
+
const memo = ctx.cache?.memo.get(key);
|
|
97
|
+
if (memo)
|
|
98
|
+
return memo;
|
|
99
|
+
if (stack.has(key))
|
|
100
|
+
return { depth: 0, chain: [] };
|
|
101
|
+
stack.add(key);
|
|
102
|
+
// ONE name may be several candidates — a `const f = () => …` is the variable
|
|
103
|
+
// AND the arrow — and only the arrow carries the calls, so every candidate of
|
|
104
|
+
// that name is walked and the longest chain wins.
|
|
105
|
+
const candidates = candidatesIn(rel, ctx);
|
|
106
|
+
const pieces = candidates.filter((c) => c.name === name);
|
|
107
|
+
const local = new Set(candidates.map((c) => c.name).filter((n) => Boolean(n)));
|
|
108
|
+
let best = { depth: 0, chain: [] };
|
|
109
|
+
for (const piece of pieces) {
|
|
110
|
+
const next = deepestLink(piece, { rel, name, local }, ctx, stack);
|
|
111
|
+
if (next.depth > best.depth)
|
|
112
|
+
best = next;
|
|
113
|
+
}
|
|
114
|
+
stack.delete(key);
|
|
115
|
+
const out = { depth: best.depth + 1, chain: [name, ...best.chain] };
|
|
116
|
+
ctx.cache?.memo.set(key, out);
|
|
117
|
+
return out;
|
|
118
|
+
};
|
|
119
|
+
// The candidates of one repo file, parsed once per run. An unreadable file
|
|
120
|
+
// (generated, outside the project) has no chain: the fact is about code the
|
|
121
|
+
// tool can actually read. The reason is reported, so a missing chain never
|
|
122
|
+
// passes for a shallow one.
|
|
123
|
+
const candidatesIn = (rel, ctx) => {
|
|
124
|
+
const cached = ctx.cache?.files.get(rel);
|
|
125
|
+
if (cached)
|
|
126
|
+
return cached;
|
|
127
|
+
const read = () => {
|
|
128
|
+
const abs = path.join(ctx.repoRoot, rel);
|
|
129
|
+
const text = fs.readFileSync(abs, "utf8");
|
|
130
|
+
const sf = (0, index_1.loadSourceFile)(ctx.project, abs, text);
|
|
131
|
+
const importMap = (0, index_1.importNameModules)(sf, ctx.repoRoot, ctx.aliases ?? {}, ctx.repoFiles);
|
|
132
|
+
const candidates = (0, index_1.collectCandidates)(sf, importMap, rel, ctx.repoRoot, { usage: false });
|
|
133
|
+
// The facets read the same file the walk does, so a rendered component is a
|
|
134
|
+
// link here exactly as it is in the rules. The import map is handed over
|
|
135
|
+
// so a tag imported from another module names that module.
|
|
136
|
+
(0, index_2.enrich)(candidates, { rel, sf, text, repoRoot: ctx.repoRoot, importMap });
|
|
137
|
+
return candidates;
|
|
138
|
+
};
|
|
139
|
+
const out = (0, try_read_1.readOrFallback)(rel, read, [], (e) => (0, notices_1.notice)(`the import chain of ${rel} could not be read`, (0, reason_1.reasonOf)(e)));
|
|
140
|
+
if (ctx.cache && ctx.cache.files.size >= MAX_CACHED_FILES)
|
|
141
|
+
ctx.cache.files.clear();
|
|
142
|
+
ctx.cache?.files.set(rel, out);
|
|
143
|
+
return out;
|
|
144
|
+
};
|
|
145
|
+
// Give every candidate its `kind.chain` — how many pieces the call chain passes
|
|
146
|
+
// through (this one included) and their names, outermost first. It lives under
|
|
147
|
+
// `kind` because it describes the SHAPE of the code, next to `own` and
|
|
148
|
+
// `descendants`; a top-level fact of its own would be a second vocabulary for
|
|
149
|
+
// the same question.
|
|
150
|
+
const attachCallDepth = (candidates, ctx) => {
|
|
151
|
+
for (const c of candidates) {
|
|
152
|
+
if (!c.name)
|
|
153
|
+
continue;
|
|
154
|
+
const { chain } = depthOf(ctx.rel, c.name, ctx, new Set());
|
|
155
|
+
// The chain as ONE string: a finding names it, so a rule can print it
|
|
156
|
+
// without the report layer knowing about arrays.
|
|
157
|
+
// The chain is a LIST of links, and nothing more: how deep it counts, where it
|
|
158
|
+
// stops being interesting, what it may not pass through — that is a FILTER's
|
|
159
|
+
// job, and the filter language already has the operators for it. The engine
|
|
160
|
+
// answers "what is called next", never "is that too deep".
|
|
161
|
+
const flat = chain.filter((n, i) => n !== chain[i - 1]);
|
|
162
|
+
c.kind = { ...(c.kind ?? {}), chain: flat.map((n) => ({ name: n })) };
|
|
163
|
+
}
|
|
164
|
+
return candidates;
|
|
165
|
+
};
|
|
166
|
+
exports.attachCallDepth = attachCallDepth;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Node } from "ts-morph";
|
|
2
|
+
import type { LooseNode } from "./loose";
|
|
3
|
+
import type { Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
4
|
+
declare const isEnumNode: (n: Node) => boolean;
|
|
5
|
+
declare const enumFact: (node: LooseNode, rel: string) => Candidate;
|
|
6
|
+
export { enumFact, isEnumNode };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEnumNode = exports.enumFact = void 0;
|
|
4
|
+
// An `enum` is a declaration with a shape: a closed set of names, each bound to
|
|
5
|
+
// a value. It is a candidate like a type — a node may host it, a rule may count
|
|
6
|
+
// its members — and `const`/`declare` are its modifiers.
|
|
7
|
+
const declaration_1 = require("./declaration");
|
|
8
|
+
const membersOf = (node) => (node.getMembers?.() ?? []).map((m) => {
|
|
9
|
+
const initializer = m.getInitializer?.();
|
|
10
|
+
const name = m.getName?.() ?? null;
|
|
11
|
+
return { name, value: initializer ? initializer.getText() : null, line: m.getStartLineNumber() };
|
|
12
|
+
});
|
|
13
|
+
const isEnumNode = (n) => n.getKindName() === "EnumDeclaration";
|
|
14
|
+
exports.isEnumNode = isEnumNode;
|
|
15
|
+
// `const enum` is a MODIFIER, and `kind` carries every modifier.
|
|
16
|
+
const enumFact = (node, rel) => (0, declaration_1.declarationFact)(node, rel, membersOf(node));
|
|
17
|
+
exports.enumFact = enumFact;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Project } from "ts-morph";
|
|
2
|
+
import { type AliasMap } from "./project";
|
|
3
|
+
declare const DEFAULT_BARREL_DEPTH = 8;
|
|
4
|
+
type ChainCtx = {
|
|
5
|
+
rel: string;
|
|
6
|
+
repoRoot: string;
|
|
7
|
+
repoFiles?: string[];
|
|
8
|
+
aliases?: AliasMap;
|
|
9
|
+
barrelDepth?: number;
|
|
10
|
+
project?: Project;
|
|
11
|
+
};
|
|
12
|
+
declare const declaringFiles: (ctx: ChainCtx, module: string, names: readonly string[]) => (string | null)[];
|
|
13
|
+
declare const declaringExportFiles: (ctx: ChainCtx, from: string, names: readonly string[]) => (string | null)[];
|
|
14
|
+
export { declaringFiles, declaringExportFiles, DEFAULT_BARREL_DEPTH };
|
|
15
|
+
export type { ChainCtx };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_BARREL_DEPTH = exports.declaringExportFiles = exports.declaringFiles = void 0;
|
|
7
|
+
// Follows a NAME through a barrel to the file that DECLARES it.
|
|
8
|
+
//
|
|
9
|
+
// `import { codeEditor } from "@md/styles"` resolves to `packages/styles/index.ts`
|
|
10
|
+
// — the barrel, which only passes the name on. The law is about the code that
|
|
11
|
+
// declares a theme, so the relation has to be judged where the name is BORN:
|
|
12
|
+
// `export { default as codeEditor } from "./editor"` → `themes/index` →
|
|
13
|
+
// `themes/editor.ts`. One step per re-export, `DEFAULT_BARREL_DEPTH` steps at most, and a
|
|
14
|
+
// name already visited is a cycle: both stop the walk and leave the relation at
|
|
15
|
+
// the module file, exactly as before this walk existed.
|
|
16
|
+
//
|
|
17
|
+
// The walk reads a module's export facts, not its syntax tree, so a barrel that
|
|
18
|
+
// the pipeline has already released is re-read on demand and kept only as facts.
|
|
19
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
20
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
21
|
+
const ts_morph_1 = require("ts-morph");
|
|
22
|
+
const file_exports_1 = require("./file-exports");
|
|
23
|
+
const resolve_1 = require("./resolve");
|
|
24
|
+
const project_1 = require("./project");
|
|
25
|
+
// The default depth of a barrel chain: a name that travels through more re-exports
|
|
26
|
+
// than this is not followed. Eight re-exports is deeper than any barrel in the repo;
|
|
27
|
+
// a tenth is a mistake, not a chain. The rule option `barrelDepth` and the CLI's
|
|
28
|
+
// `--barrel-depth` move it; the architecture never states it.
|
|
29
|
+
const DEFAULT_BARREL_DEPTH = 8;
|
|
30
|
+
exports.DEFAULT_BARREL_DEPTH = DEFAULT_BARREL_DEPTH;
|
|
31
|
+
const CACHE = new WeakMap();
|
|
32
|
+
const cacheOf = (project) => {
|
|
33
|
+
const cached = CACHE.get(project) ?? new Map();
|
|
34
|
+
CACHE.set(project, cached);
|
|
35
|
+
return cached;
|
|
36
|
+
};
|
|
37
|
+
// What a declaration statement publishes, when it is exported at all: `export
|
|
38
|
+
// const a` names every binding, `export function f` one, and `export default f`
|
|
39
|
+
// publishes `default` — the name a chain looks for.
|
|
40
|
+
const declaredOf = (st) => {
|
|
41
|
+
if (ts_morph_1.Node.isVariableStatement(st)) {
|
|
42
|
+
return st.isExported()
|
|
43
|
+
? { isDefault: st.isDefaultExport(), names: st.getDeclarations().map((d) => d.getName()) }
|
|
44
|
+
: null;
|
|
45
|
+
}
|
|
46
|
+
if (ts_morph_1.Node.isFunctionDeclaration(st) ||
|
|
47
|
+
ts_morph_1.Node.isClassDeclaration(st) ||
|
|
48
|
+
ts_morph_1.Node.isInterfaceDeclaration(st) ||
|
|
49
|
+
ts_morph_1.Node.isTypeAliasDeclaration(st) ||
|
|
50
|
+
ts_morph_1.Node.isEnumDeclaration(st)) {
|
|
51
|
+
if (!st.isExported())
|
|
52
|
+
return null;
|
|
53
|
+
const name = st.getName();
|
|
54
|
+
return { isDefault: st.isDefaultExport(), names: name ? [name] : [] };
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
const localExported = (sf) => {
|
|
59
|
+
const exported = new Set();
|
|
60
|
+
for (const st of sf.getStatements()) {
|
|
61
|
+
const declared = declaredOf(st);
|
|
62
|
+
if (!declared)
|
|
63
|
+
continue;
|
|
64
|
+
if (declared.isDefault)
|
|
65
|
+
exported.add("default");
|
|
66
|
+
else
|
|
67
|
+
for (const name of declared.names)
|
|
68
|
+
exported.add(name);
|
|
69
|
+
}
|
|
70
|
+
return exported;
|
|
71
|
+
};
|
|
72
|
+
// The parsed file, loaded only when the walk actually needs it.
|
|
73
|
+
const sourceAt = (ctx, rel) => {
|
|
74
|
+
const project = ctx.project;
|
|
75
|
+
if (!project)
|
|
76
|
+
return null;
|
|
77
|
+
const abs = node_path_1.default.resolve(ctx.repoRoot, rel);
|
|
78
|
+
const known = project.getSourceFile(abs);
|
|
79
|
+
if (known)
|
|
80
|
+
return known;
|
|
81
|
+
try {
|
|
82
|
+
return (0, project_1.loadSourceFile)(project, abs, node_fs_1.default.readFileSync(abs, "utf8"));
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const factsOf = (ctx, rel) => {
|
|
89
|
+
const project = ctx.project;
|
|
90
|
+
if (!project)
|
|
91
|
+
return null;
|
|
92
|
+
const sf = sourceAt(ctx, rel);
|
|
93
|
+
if (!sf)
|
|
94
|
+
return null;
|
|
95
|
+
const cache = cacheOf(project);
|
|
96
|
+
const text = sf.getFullText();
|
|
97
|
+
const cached = cache.get(rel);
|
|
98
|
+
if (cached && cached.text === text)
|
|
99
|
+
return cached;
|
|
100
|
+
const importMap = (0, resolve_1.importNameModules)(sf, ctx.repoRoot, ctx.aliases, ctx.repoFiles);
|
|
101
|
+
const facts = { text, exports: (0, file_exports_1.exportsOf)(sf, importMap, { ...ctx, rel }), local: localExported(sf) };
|
|
102
|
+
cache.set(rel, facts);
|
|
103
|
+
return facts;
|
|
104
|
+
};
|
|
105
|
+
// What this module says about `name`, in the order TypeScript reads it: an
|
|
106
|
+
// explicit export first (named, then `default`), then the module's own
|
|
107
|
+
// declarations, then the star re-exports — a name is "found in the star" only
|
|
108
|
+
// when nothing above it names it.
|
|
109
|
+
const whereOf = (facts, name) => {
|
|
110
|
+
const namespace = facts.exports.find((exp) => exp.form === "namespace" && (exp.named ?? []).includes(name));
|
|
111
|
+
if (namespace)
|
|
112
|
+
return { kind: "module", file: namespace.from ?? "" };
|
|
113
|
+
const named = facts.exports.find((exp) => exp.form === "named" && (exp.named ?? []).includes(name));
|
|
114
|
+
if (named) {
|
|
115
|
+
if (!named.from)
|
|
116
|
+
return { kind: "here" };
|
|
117
|
+
const at = (named.named ?? []).indexOf(name);
|
|
118
|
+
// The name AFTER `as` is the caller's; the one BEFORE it is what the
|
|
119
|
+
// declaring module knows (`export { default as codeEditor }`).
|
|
120
|
+
return { kind: "re-export", file: named.from, name: named.original?.[at] ?? name };
|
|
121
|
+
}
|
|
122
|
+
if (name === "default") {
|
|
123
|
+
const def = facts.exports.find((exp) => exp.form === "default" || exp.form === "equals");
|
|
124
|
+
if (def)
|
|
125
|
+
return def.from ? { kind: "re-export", file: def.from, name: "default" } : { kind: "here" };
|
|
126
|
+
}
|
|
127
|
+
if (facts.local.has(name))
|
|
128
|
+
return { kind: "here" };
|
|
129
|
+
const star = facts.exports.find((exp) => exp.form === "star" && exp.from);
|
|
130
|
+
if (star?.from)
|
|
131
|
+
return { kind: "star", file: star.from };
|
|
132
|
+
return { kind: "none" };
|
|
133
|
+
};
|
|
134
|
+
const inside = (ctx, file) => Boolean(file) && !node_path_1.default.isAbsolute(file ?? "") && (ctx.repoFiles ?? []).includes(file ?? "");
|
|
135
|
+
const walk = (ctx, step) => {
|
|
136
|
+
const { rel, name, seen, steps } = step;
|
|
137
|
+
if (steps > (ctx.barrelDepth ?? DEFAULT_BARREL_DEPTH))
|
|
138
|
+
return null;
|
|
139
|
+
const key = `${rel}#${name}`;
|
|
140
|
+
if (seen.has(key))
|
|
141
|
+
return null;
|
|
142
|
+
seen.add(key);
|
|
143
|
+
const facts = factsOf(ctx, rel);
|
|
144
|
+
if (!facts)
|
|
145
|
+
return null;
|
|
146
|
+
const where = whereOf(facts, name);
|
|
147
|
+
if (where.kind === "here")
|
|
148
|
+
return rel;
|
|
149
|
+
if (where.kind === "module")
|
|
150
|
+
return inside(ctx, where.file) ? where.file : null;
|
|
151
|
+
if (where.kind === "re-export" || where.kind === "star") {
|
|
152
|
+
if (!inside(ctx, where.file))
|
|
153
|
+
return null;
|
|
154
|
+
return walk(ctx, { rel: where.file, name: where.kind === "star" ? name : where.name, seen, steps: steps + 1 });
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
};
|
|
158
|
+
// The declaring file of each name, in the names' own order (`null` = unknown).
|
|
159
|
+
const declaringFiles = (ctx, module, names) => names.map((name) => {
|
|
160
|
+
try {
|
|
161
|
+
return walk(ctx, { rel: module, name, seen: new Set(), steps: 0 });
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
exports.declaringFiles = declaringFiles;
|
|
168
|
+
// The declaring file of an exported name a module re-exports (`export { a } from
|
|
169
|
+
// "./barrel"`): the same walk, started at the module the statement names.
|
|
170
|
+
const declaringExportFiles = (ctx, from, names) => declaringFiles(ctx, from, names);
|
|
171
|
+
exports.declaringExportFiles = declaringExportFiles;
|