@md-code/follow-architecture 0.3.0 → 0.3.3
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 +38 -0
- package/README.md +1341 -472
- package/dist/args.d.ts +4 -0
- package/dist/args.js +18 -1
- package/dist/bin/follow-architecture.js +3 -3
- package/dist/closure-project.d.ts +4 -0
- package/dist/closure-project.js +122 -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-roles/roles.js → code-entities/entities.js} +81 -54
- package/dist/code-entities/project.d.ts +21 -0
- package/dist/code-entities/project.js +249 -0
- package/dist/code-entities/walk.d.ts +31 -0
- package/dist/code-entities/walk.js +95 -0
- package/dist/config-options.d.ts +23 -0
- package/dist/config-options.js +18 -1
- package/dist/config-project.js +10 -2
- package/dist/config-report.d.ts +1 -1
- package/dist/config-report.js +20 -3
- package/dist/config-rule.d.ts +25 -0
- package/dist/config-rule.js +89 -6
- package/dist/config-state.d.ts +14 -3
- package/dist/config-state.js +180 -17
- package/dist/config.d.ts +25 -0
- package/dist/css/index.d.ts +11 -7
- package/dist/css/index.js +124 -23
- package/dist/css/syntax/css/gate.js +5 -5
- package/dist/css/syntax/css/index.d.ts +1 -1
- package/dist/css/syntax/css/index.js +1 -1
- package/dist/css/syntax/css/reference.d.ts +1 -1
- package/dist/css/syntax/css/reference.js +15 -3
- package/dist/css/syntax/language.d.ts +1 -1
- package/dist/css/syntax/language.js +4 -2
- package/dist/css/syntax/scss/index.d.ts +2 -2
- package/dist/css/syntax/scss/index.js +1 -1
- package/dist/css/syntax/scss/reference.d.ts +1 -1
- package/dist/css/syntax/scss/reference.js +7 -1
- package/dist/css/syntax/styled/document.d.ts +3 -3
- package/dist/css/syntax/styled/document.js +17 -7
- package/dist/css/syntax/styled/markup.d.ts +1 -1
- package/dist/css/syntax/styled/markup.js +22 -14
- 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.js +10 -4
- package/dist/css/syntax/tailwind/tailwind.js +4 -4
- package/dist/css/value/check.d.ts +1 -1
- package/dist/css/value/check.js +1 -1
- package/dist/css/value/expression/arithmetic.d.ts +2 -2
- package/dist/css/value/expression/arithmetic.js +7 -3
- package/dist/css/value/expression/block.d.ts +2 -2
- package/dist/css/value/expression/block.js +4 -3
- package/dist/css/value/expression/conditional.d.ts +2 -2
- package/dist/css/value/expression/conditional.js +1 -1
- package/dist/css/value/expression/index.d.ts +2 -2
- package/dist/css/value/expression/index.js +10 -6
- package/dist/css/value/expression/map.d.ts +2 -2
- package/dist/css/value/expression/map.js +2 -2
- package/dist/css/value/object/index.d.ts +2 -2
- package/dist/css/value/object/index.js +14 -4
- package/dist/css/value/object/members.d.ts +2 -2
- package/dist/css/value/object/node.js +9 -4
- package/dist/css/value/object/path.d.ts +3 -3
- package/dist/css/value/object/path.js +10 -4
- package/dist/css/value/pieces.d.ts +3 -3
- package/dist/css/value/pieces.js +14 -4
- package/dist/css/value/resolve.js +15 -5
- package/dist/css/value/scope.d.ts +3 -2
- package/dist/css/value/scope.js +25 -7
- package/dist/css/value/substitute.js +43 -11
- package/dist/entities/architecture.d.ts +28 -25
- package/dist/entities/ast/assignments-raw.d.ts +1 -1
- package/dist/entities/ast/assignments-raw.js +61 -8
- package/dist/entities/ast/assignments-tagged.d.ts +1 -1
- package/dist/entities/ast/assignments-tagged.js +22 -7
- package/dist/entities/ast/assignments.d.ts +1 -1
- package/dist/entities/ast/assignments.js +6 -4
- package/dist/entities/ast/branches.d.ts +1 -1
- package/dist/entities/ast/calls.d.ts +1 -1
- package/dist/entities/ast/calls.js +19 -3
- package/dist/entities/ast/classes.d.ts +1 -1
- package/dist/entities/ast/classes.js +5 -1
- package/dist/entities/ast/comments.d.ts +3 -2
- package/dist/entities/ast/comments.js +47 -17
- package/dist/entities/ast/declaration.d.ts +1 -1
- package/dist/entities/ast/depth.d.ts +2 -2
- package/dist/entities/ast/depth.js +15 -8
- package/dist/entities/ast/enums.d.ts +1 -1
- 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 +1 -1
- package/dist/entities/ast/file-exports.js +26 -3
- package/dist/entities/ast/file-facts.d.ts +6 -3
- package/dist/entities/ast/file-facts.js +33 -4
- package/dist/entities/ast/file-imports.d.ts +1 -1
- package/dist/entities/ast/file-imports.js +26 -3
- package/dist/entities/ast/file.d.ts +2 -2
- package/dist/entities/ast/file.js +2 -1
- package/dist/entities/ast/functions.d.ts +1 -1
- package/dist/entities/ast/functions.js +13 -4
- package/dist/entities/ast/heritage.d.ts +1 -1
- package/dist/entities/ast/heritage.js +9 -1
- package/dist/entities/ast/index.d.ts +6 -3
- package/dist/entities/ast/index.js +82 -26
- package/dist/entities/ast/kind.d.ts +1 -1
- package/dist/entities/ast/kind.js +7 -1
- package/dist/entities/ast/modifiers.d.ts +1 -1
- package/dist/entities/ast/modifiers.js +4 -4
- package/dist/entities/ast/project.js +33 -2
- package/dist/entities/ast/properties.d.ts +1 -1
- package/dist/entities/ast/properties.js +10 -5
- package/dist/entities/ast/resolve.d.ts +1 -1
- package/dist/entities/ast/resolve.js +4 -4
- package/dist/entities/ast/tree.d.ts +4 -2
- package/dist/entities/ast/tree.js +184 -17
- package/dist/entities/ast/types.d.ts +1 -1
- package/dist/entities/ast/types.js +2 -1
- package/dist/entities/ast/usage.d.ts +1 -1
- package/dist/entities/ast/usage.js +1 -1
- package/dist/entities/ast/variables.d.ts +1 -1
- package/dist/entities/context.d.ts +4 -4
- package/dist/entities/facts.d.ts +36 -13
- package/dist/entities/findings.d.ts +3 -3
- package/dist/entities/kinds.d.ts +1 -1
- package/dist/entities/kinds.js +131 -30
- package/dist/entities/location/homes.d.ts +10 -10
- package/dist/entities/location/homes.js +74 -48
- package/dist/entities/location/place.d.ts +1 -1
- package/dist/entities/location/place.js +10 -3
- package/dist/entities/location/where.d.ts +8 -6
- package/dist/entities/location/where.js +79 -30
- package/dist/entities/location.d.ts +3 -3
- package/dist/entities/location.js +17 -17
- package/dist/entities/operators.js +1 -1
- package/dist/entities/overview/data.d.ts +6 -6
- package/dist/entities/overview/decision.d.ts +11 -11
- package/dist/entities/overview/finding.d.ts +10 -10
- package/dist/entities/overview/graph.d.ts +28 -11
- package/dist/entities/overview/input.d.ts +2 -2
- package/dist/entities/overview/summaries.d.ts +17 -15
- package/dist/entities/queries.d.ts +1 -1
- package/dist/entities/queries.js +72 -12
- package/dist/entities/repair.d.ts +1 -1
- package/dist/entities/repair.js +8 -2
- package/dist/entities/schema.d.ts +17 -3
- package/dist/entities/schema.js +74 -16
- package/dist/entities/story.d.ts +5 -5
- package/dist/entities/structure-facts.d.ts +1 -1
- package/dist/entities/token.d.ts +4 -4
- package/dist/entities/tree/build.d.ts +4 -3
- package/dist/entities/tree/build.js +95 -44
- package/dist/entities/tree/entries.d.ts +3 -3
- package/dist/entities/tree/entries.js +41 -16
- package/dist/entities/tree/index.d.ts +2 -2
- package/dist/entities/tree/index.js +1 -1
- package/dist/entities/tree/match.d.ts +2 -2
- package/dist/entities/tree/match.js +9 -5
- 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 +232 -0
- package/dist/fa-store.d.ts +22 -0
- package/dist/fa-store.js +222 -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 +287 -0
- package/dist/frameworks/angular/index.d.ts +2 -2
- package/dist/frameworks/angular/index.js +2 -1
- package/dist/frameworks/facet.d.ts +3 -1
- package/dist/frameworks/facet.js +13 -0
- package/dist/frameworks/index.d.ts +1 -1
- package/dist/frameworks/index.js +8 -4
- package/dist/frameworks/react/index.d.ts +2 -2
- package/dist/frameworks/react/index.js +33 -10
- package/dist/frameworks/test/index.d.ts +6 -0
- package/dist/frameworks/test/index.js +157 -0
- package/dist/frameworks/vue/index.d.ts +2 -2
- package/dist/frameworks/vue/index.js +2 -1
- package/dist/ignore.d.ts +3 -0
- package/dist/ignore.js +48 -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 +209 -0
- package/dist/main.d.ts +5 -2
- package/dist/main.js +207 -34
- package/dist/nodes/child-entities.d.ts +3 -0
- package/dist/nodes/child-entities.js +12 -0
- package/dist/nodes/children.d.ts +4 -4
- package/dist/nodes/children.js +54 -11
- package/dist/nodes/finally/emit.d.ts +3 -3
- package/dist/nodes/finally/emit.js +26 -10
- package/dist/nodes/finally/entities.d.ts +13 -0
- package/dist/nodes/finally/entities.js +42 -0
- package/dist/nodes/finally/index.d.ts +6 -6
- package/dist/nodes/finally/index.js +8 -8
- package/dist/nodes/finally/queries.d.ts +2 -2
- package/dist/nodes/finally/queries.js +7 -4
- package/dist/nodes/finally/relations-access.d.ts +2 -2
- package/dist/nodes/finally/relations-access.js +22 -18
- package/dist/nodes/finally/relations-edge.d.ts +5 -5
- package/dist/nodes/finally/relations-edge.js +67 -44
- package/dist/nodes/finally/relations-group.d.ts +7 -7
- package/dist/nodes/finally/relations-group.js +28 -25
- package/dist/nodes/finally/relations.d.ts +2 -2
- package/dist/nodes/finally/relations.js +16 -12
- package/dist/nodes/finally/required.d.ts +3 -3
- package/dist/nodes/finally/required.js +9 -7
- package/dist/nodes/finally/violation.d.ts +2 -2
- package/dist/nodes/similar.d.ts +3 -3
- package/dist/nodes/similar.js +61 -49
- package/dist/piece-forms.d.ts +9 -0
- package/dist/piece-forms.js +68 -0
- package/dist/{pipeline-roles.d.ts → pipeline-entities.d.ts} +2 -2
- package/dist/{pipeline-roles.js → pipeline-entities.js} +32 -28
- package/dist/pipeline-facts.d.ts +4 -3
- package/dist/pipeline-facts.js +47 -55
- package/dist/{pipeline-unroled.d.ts → pipeline-unclassified.d.ts} +2 -2
- package/dist/{pipeline-unroled.js → pipeline-unclassified.js} +58 -63
- package/dist/pipeline.js +19 -64
- package/dist/release-file.d.ts +3 -0
- package/dist/release-file.js +13 -0
- package/dist/report/asks.d.ts +3 -3
- package/dist/report/asks.js +16 -6
- package/dist/report/configErrors.d.ts +55 -27
- package/dist/report/configErrors.js +81 -35
- package/dist/report/errorTypes/codes/structure.d.ts +1 -1
- package/dist/report/errorTypes/codes/structure.js +9 -9
- package/dist/report/errorTypes/decision-maker.d.ts +5 -5
- package/dist/report/errorTypes/decision-maker.js +4 -4
- package/dist/report/errorTypes/destinations.d.ts +5 -5
- package/dist/report/errorTypes/destinations.js +52 -34
- package/dist/report/errorTypes/finding-type.d.ts +3 -3
- package/dist/report/errorTypes/index.d.ts +1 -1
- package/dist/report/errorTypes/types/fileContents.d.ts +4 -4
- package/dist/report/errorTypes/types/fileContents.js +11 -5
- package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
- package/dist/report/errorTypes/types/{unknownRole.js → unknownEntity.js} +12 -7
- package/dist/report/errorTypes/types/wrongAction.d.ts +5 -5
- package/dist/report/errorTypes/types/wrongAction.js +18 -13
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +4 -4
- package/dist/report/errorTypes/types/wrongPlacement.js +19 -9
- package/dist/report/errorTypes/vocabulary/ids.d.ts +2 -2
- package/dist/report/errorTypes/vocabulary/ids.js +3 -3
- package/dist/report/errorTypes/vocabulary/phrases.d.ts +2 -2
- package/dist/report/errorTypes/vocabulary/phrases.js +39 -26
- package/dist/report/errorTypes/vocabulary/places.d.ts +3 -3
- package/dist/report/errorTypes/vocabulary/places.js +13 -13
- package/dist/report/finding-from.d.ts +3 -3
- package/dist/report/finding-from.js +14 -9
- package/dist/report/notices.d.ts +6 -1
- package/dist/report/notices.js +46 -20
- package/dist/report/observed.d.ts +19 -0
- package/dist/report/observed.js +87 -0
- package/dist/report/render-report.d.ts +1 -1
- package/dist/report/render-report.js +33 -30
- package/dist/report/user-report/build/bundle.js +9 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +799 -297
- package/dist/report/user-report/data/collect.d.ts +2 -2
- package/dist/report/user-report/data/collect.js +15 -12
- package/dist/report/user-report/data/entities.d.ts +7 -0
- package/dist/report/user-report/data/{roles.js → entities.js} +27 -22
- package/dist/report/user-report/data/{role-examples.d.ts → entity-examples.d.ts} +3 -3
- package/dist/report/user-report/data/entity-examples.js +126 -0
- package/dist/report/user-report/data/{role-filters.d.ts → entity-filters.d.ts} +2 -2
- package/dist/report/user-report/data/{role-filters.js → entity-filters.js} +7 -7
- package/dist/report/user-report/data/entity-marks.d.ts +5 -0
- package/dist/report/user-report/data/{role-marks.js → entity-marks.js} +11 -11
- package/dist/report/user-report/data/file-tree.d.ts +3 -3
- package/dist/report/user-report/data/file-tree.js +13 -5
- package/dist/report/user-report/data/finding-boundary.d.ts +4 -4
- package/dist/report/user-report/data/finding-boundary.js +2 -2
- package/dist/report/user-report/data/finding-plan.d.ts +5 -5
- package/dist/report/user-report/data/finding-plan.js +10 -10
- package/dist/report/user-report/data/finding-title.d.ts +2 -2
- package/dist/report/user-report/data/finding-title.js +8 -8
- package/dist/report/user-report/data/findings.d.ts +4 -4
- package/dist/report/user-report/data/findings.js +30 -20
- package/dist/report/user-report/data/graph-edges.d.ts +4 -4
- package/dist/report/user-report/data/graph-edges.js +19 -19
- 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 +5 -5
- package/dist/report/user-report/data/graph-helpers.js +15 -15
- package/dist/report/user-report/data/graph.d.ts +5 -4
- package/dist/report/user-report/data/graph.js +28 -21
- package/dist/report/user-report/data/nodes.d.ts +2 -2
- package/dist/report/user-report/data/nodes.js +16 -16
- package/dist/report/user-report/data/rules.d.ts +7 -0
- package/dist/report/user-report/data/{invariants.js → rules.js} +13 -13
- package/dist/report/user-report/data/scan.d.ts +1 -1
- package/dist/report/user-report/data/scan.js +2 -2
- package/dist/report/user-report/html/shell.d.ts +1 -1
- package/dist/report/user-report/html/shell.js +1 -1
- package/dist/report/user-report/index.d.ts +1 -1
- package/dist/report/user-report/shared/describe.d.ts +1 -1
- package/dist/report/user-report/shared/describe.js +6 -6
- package/dist/rules/index.d.ts +7 -0
- package/dist/{invariants → rules}/index.js +85 -57
- package/dist/{invariants → rules}/list-vars.d.ts +2 -2
- package/dist/{invariants → rules}/list-vars.js +9 -3
- package/dist/{invariants → rules}/name.js +2 -2
- package/dist/rules/normalize.d.ts +5 -0
- package/dist/{invariants → rules}/normalize.js +35 -32
- package/dist/{invariants → rules}/vars.d.ts +9 -7
- package/dist/{invariants → rules}/vars.js +5 -5
- package/dist/scan-run.d.ts +20 -0
- package/dist/scan-run.js +130 -0
- package/dist/scripts/audit-report.js +2 -2
- package/dist/usage-index.d.ts +4 -0
- package/dist/usage-index.js +272 -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 +254 -0
- package/dist/utils/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +163 -0
- package/dist/utils/classify.d.ts +2 -2
- package/dist/utils/classify.js +4 -4
- package/dist/utils/distinct.js +4 -2
- package/dist/utils/files.js +24 -30
- package/dist/utils/fixpoint.js +2 -2
- package/dist/utils/host.d.ts +1 -1
- package/dist/utils/host.js +4 -1
- package/dist/utils/imports.js +66 -12
- package/dist/utils/keyed.js +2 -2
- package/dist/utils/map-record.js +2 -2
- package/dist/utils/packages.d.ts +15 -0
- package/dist/utils/packages.js +197 -0
- package/dist/utils/path-label.js +3 -1
- package/dist/utils/pattern.d.ts +5 -4
- package/dist/utils/pattern.js +38 -8
- package/dist/utils/permission.d.ts +3 -3
- package/dist/utils/permission.js +4 -2
- package/dist/utils/plural.js +2 -2
- package/dist/utils/qualified.js +4 -4
- package/dist/utils/rank.js +2 -2
- package/dist/utils/record.js +1 -1
- package/dist/utils/search.js +7 -2
- package/dist/utils/speak.js +1 -1
- package/dist/utils/split.js +14 -1
- package/dist/utils/template.d.ts +1 -1
- package/dist/utils/template.js +1 -1
- package/dist/utils/tokenize.js +6 -1
- package/dist/utils/typed-field.js +2 -2
- package/dist/utils/verdicts.js +1 -1
- package/entities/operators.ts +1 -1
- package/package.json +101 -90
- package/report/errorTypes/vocabulary/ids.ts +7 -2
- package/report/errorTypes/vocabulary/phrases.ts +47 -27
- package/report/errorTypes/vocabulary/places.ts +21 -16
- package/report/user-report/shared/describe.ts +7 -7
- package/dist/code-roles/classify.d.ts +0 -11
- package/dist/code-roles/classify.js +0 -43
- package/dist/code-roles/connector.d.ts +0 -5
- package/dist/code-roles/connector.js +0 -114
- package/dist/code-roles/project.d.ts +0 -12
- package/dist/code-roles/project.js +0 -122
- package/dist/code-roles/roles.d.ts +0 -8
- package/dist/invariants/index.d.ts +0 -6
- package/dist/invariants/normalize.d.ts +0 -4
- package/dist/nodes/child-roles.d.ts +0 -3
- package/dist/nodes/child-roles.js +0 -12
- package/dist/nodes/finally/roles.d.ts +0 -13
- package/dist/nodes/finally/roles.js +0 -41
- package/dist/report/errorTypes/types/unknownRole.d.ts +0 -9
- package/dist/report/user-report/data/graph-roles.d.ts +0 -5
- package/dist/report/user-report/data/graph-roles.js +0 -71
- package/dist/report/user-report/data/invariants.d.ts +0 -7
- package/dist/report/user-report/data/role-examples.js +0 -94
- package/dist/report/user-report/data/role-marks.d.ts +0 -5
- package/dist/report/user-report/data/roles.d.ts +0 -7
- /package/dist/{invariants → rules}/name.d.ts +0 -0
|
@@ -28,7 +28,7 @@ exports.attachCallDepth = void 0;
|
|
|
28
28
|
//
|
|
29
29
|
// A piece that calls an imported function which calls another which calls
|
|
30
30
|
// another is not readable at the call site: nobody can see where the state is
|
|
31
|
-
// finally changed, and no
|
|
31
|
+
// finally changed, and no entity rule can point at the place that changed it.
|
|
32
32
|
// The chain is what this fact measures — `toggleLineAction → applyDecorations →
|
|
33
33
|
// applyActiveEditorDecorations → …` is a depth of 5, and a rule may refuse it.
|
|
34
34
|
//
|
|
@@ -40,10 +40,15 @@ exports.attachCallDepth = void 0;
|
|
|
40
40
|
const fs = __importStar(require("node:fs"));
|
|
41
41
|
const path = __importStar(require("node:path"));
|
|
42
42
|
const index_1 = require("./index");
|
|
43
|
-
const
|
|
44
|
-
const notices_1 = require("
|
|
45
|
-
const try_read_1 = require("
|
|
46
|
-
const reason_1 = require("
|
|
43
|
+
const index_2 = require("@md-code/follow-architecture/frameworks/index");
|
|
44
|
+
const notices_1 = require("@md-code/follow-architecture/report/notices");
|
|
45
|
+
const try_read_1 = require("@md-code/follow-architecture/utils/try-read");
|
|
46
|
+
const reason_1 = require("@md-code/follow-architecture/utils/reason");
|
|
47
|
+
// How many files' candidate lists the cache keeps. A chain is answered from the
|
|
48
|
+
// file's TEXT and never changes inside a run, so a file that falls out of the
|
|
49
|
+
// cache is read again — the bound trades a re-read for the memory a whole repo's
|
|
50
|
+
// candidates would take, and the answers do not depend on it.
|
|
51
|
+
const MAX_CACHED_FILES = 64;
|
|
47
52
|
// A link's target: an imported name names its module (followed only when the
|
|
48
53
|
// module is a repo file); a local name is walked in this file. A link back to
|
|
49
54
|
// the piece itself is not a step.
|
|
@@ -114,14 +119,16 @@ const candidatesIn = (rel, ctx) => {
|
|
|
114
119
|
const text = fs.readFileSync(abs, "utf8");
|
|
115
120
|
const sf = (0, index_1.loadSourceFile)(ctx.project, abs, text);
|
|
116
121
|
const importMap = (0, index_1.importNameModules)(sf, ctx.repoRoot, ctx.aliases ?? {}, ctx.repoFiles);
|
|
117
|
-
const candidates = (0, index_1.collectCandidates)(sf, importMap, rel, ctx.repoRoot);
|
|
122
|
+
const candidates = (0, index_1.collectCandidates)(sf, importMap, rel, ctx.repoRoot, { usage: false });
|
|
118
123
|
// The facets read the same file the walk does, so a rendered component is a
|
|
119
|
-
// link here exactly as it is in the
|
|
124
|
+
// link here exactly as it is in the rules. The import map is handed over
|
|
120
125
|
// so a tag imported from another module names that module.
|
|
121
|
-
(0,
|
|
126
|
+
(0, index_2.enrich)(candidates, { rel, sf, text, repoRoot: ctx.repoRoot, importMap });
|
|
122
127
|
return candidates;
|
|
123
128
|
};
|
|
124
129
|
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)));
|
|
130
|
+
if (ctx.cache && ctx.cache.files.size >= MAX_CACHED_FILES)
|
|
131
|
+
ctx.cache.files.clear();
|
|
125
132
|
ctx.cache?.files.set(rel, out);
|
|
126
133
|
return out;
|
|
127
134
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Node } from "ts-morph";
|
|
2
2
|
import type { LooseNode } from "./loose";
|
|
3
|
-
import type { Candidate } from "
|
|
3
|
+
import type { Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
4
4
|
declare const isEnumNode: (n: Node) => boolean;
|
|
5
5
|
declare const enumFact: (node: LooseNode, rel: string) => Candidate;
|
|
6
6
|
export { enumFact, isEnumNode };
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SourceFile } from "ts-morph";
|
|
2
2
|
import type { CollectOptions } from "./file-facts";
|
|
3
|
-
import type { ExportFact } from "
|
|
3
|
+
import type { ExportFact } from "@md-code/follow-architecture/entities/facts";
|
|
4
4
|
type ResolveCtx = Omit<CollectOptions, "candidates">;
|
|
5
5
|
declare const exportsOf: (sf: SourceFile, importMap: ReadonlyMap<string, string>, ctx: ResolveCtx) => ExportFact[];
|
|
6
6
|
export { exportsOf };
|
|
@@ -11,7 +11,8 @@ exports.exportsOf = void 0;
|
|
|
11
11
|
const ts_morph_1 = require("ts-morph");
|
|
12
12
|
const tree_1 = require("./tree");
|
|
13
13
|
const properties_1 = require("./properties");
|
|
14
|
-
const imports_1 = require("
|
|
14
|
+
const imports_1 = require("@md-code/follow-architecture/utils/imports");
|
|
15
|
+
const export_chain_1 = require("./export-chain");
|
|
15
16
|
// The form of one `export …` statement: a namespace re-export, a star
|
|
16
17
|
// re-export, or named exports.
|
|
17
18
|
const formOf = (exp) => {
|
|
@@ -23,9 +24,11 @@ const formOf = (exp) => {
|
|
|
23
24
|
};
|
|
24
25
|
const statementExport = (exp, importMap, ctx) => {
|
|
25
26
|
const named = exp.getNamedExports().map((el) => el.getAliasNode()?.getText() ?? el.getName());
|
|
27
|
+
const original = exp.getNamedExports().map((el) => el.getName());
|
|
26
28
|
const entry = {
|
|
27
29
|
form: formOf(exp),
|
|
28
30
|
named,
|
|
31
|
+
original,
|
|
29
32
|
from: null,
|
|
30
33
|
source: null,
|
|
31
34
|
name: null,
|
|
@@ -49,6 +52,10 @@ const statementExport = (exp, importMap, ctx) => {
|
|
|
49
52
|
// re-export like any other — the code being published is not this file's.
|
|
50
53
|
if (!entry.from && entry.named?.length === 1 && importMap.has(entry.named[0]))
|
|
51
54
|
entry.from = importMap.get(entry.named[0]) ?? null;
|
|
55
|
+
// A re-exported name is judged where it is declared: `export { a } from
|
|
56
|
+
// "./barrel"` hides the same declaring file as the import it stands for.
|
|
57
|
+
if (entry.from && entry.named?.length)
|
|
58
|
+
entry.declaring = (0, export_chain_1.declaringExportFiles)(ctx, entry.from, entry.named);
|
|
52
59
|
return entry;
|
|
53
60
|
};
|
|
54
61
|
// `export default <expr>` / `export = <expr>`: no declaration modifier to find,
|
|
@@ -56,14 +63,30 @@ const statementExport = (exp, importMap, ctx) => {
|
|
|
56
63
|
// binding, the export is a pass-through of that module.
|
|
57
64
|
const assignmentExport = (ea, importMap) => {
|
|
58
65
|
const text = ea.getExpression()?.getText() ?? "";
|
|
59
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
form: ea.isExportEquals() ? "equals" : "default",
|
|
68
|
+
named: [],
|
|
69
|
+
source: null,
|
|
70
|
+
from: text ? (importMap.get(text) ?? null) : null,
|
|
71
|
+
name: null,
|
|
72
|
+
line: (0, tree_1.startLine)(ea),
|
|
73
|
+
piece: (0, properties_1.enclosingPiece)(ea),
|
|
74
|
+
};
|
|
60
75
|
};
|
|
61
76
|
// CommonJS, in every form it is still written in.
|
|
62
77
|
const commonJsExport = (d) => {
|
|
63
78
|
const m = /^(?:module\.)?exports(?:\.([A-Za-z0-9_$]+))?$/.exec(d.getLeft().getText());
|
|
64
79
|
if (!m)
|
|
65
80
|
return null;
|
|
66
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
form: "commonjs",
|
|
83
|
+
named: [],
|
|
84
|
+
source: null,
|
|
85
|
+
from: null,
|
|
86
|
+
name: m[1] ?? null,
|
|
87
|
+
line: d.getStartLineNumber(),
|
|
88
|
+
piece: (0, properties_1.enclosingPiece)(d),
|
|
89
|
+
};
|
|
67
90
|
};
|
|
68
91
|
const exportsOf = (sf, importMap, ctx) => {
|
|
69
92
|
const statementExports = sf.getExportDeclarations().map((exp) => statementExport(exp, importMap, ctx));
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { type SourceFile } from "ts-morph";
|
|
1
|
+
import { type Project, type SourceFile } from "ts-morph";
|
|
2
2
|
import type { AliasMap } from "./project";
|
|
3
|
-
import type { FileFacts, Candidate } from "
|
|
3
|
+
import type { FileFacts, Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
4
4
|
interface CollectOptions {
|
|
5
5
|
rel: string;
|
|
6
6
|
repoFiles?: string[];
|
|
7
7
|
aliases?: AliasMap;
|
|
8
8
|
repoRoot: string;
|
|
9
9
|
candidates?: Candidate[];
|
|
10
|
+
barrelDepth?: number;
|
|
11
|
+
project?: Project;
|
|
10
12
|
}
|
|
11
13
|
declare const collectFileFacts: (sf: SourceFile, options: CollectOptions) => FileFacts;
|
|
12
|
-
|
|
14
|
+
declare const releaseFileFacts: (sf: SourceFile) => void;
|
|
15
|
+
export { collectFileFacts, releaseFileFacts };
|
|
13
16
|
export type { CollectOptions };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectFileFacts = void 0;
|
|
3
|
+
exports.releaseFileFacts = exports.collectFileFacts = void 0;
|
|
4
4
|
const tree_1 = require("./tree");
|
|
5
5
|
const properties_1 = require("./properties");
|
|
6
6
|
const resolve_1 = require("./resolve");
|
|
7
7
|
const file_imports_1 = require("./file-imports");
|
|
8
8
|
const file_exports_1 = require("./file-exports");
|
|
9
|
-
const location_1 = require("
|
|
10
|
-
const
|
|
9
|
+
const location_1 = require("@md-code/follow-architecture/entities/location");
|
|
10
|
+
const buildFileFacts = (sf, options) => {
|
|
11
11
|
const { rel, repoFiles, aliases, repoRoot, candidates } = options;
|
|
12
12
|
// The import map is rebuilt here because reads are a FILE fact, not a
|
|
13
13
|
// per-candidate one: a read is a property of the file's surface.
|
|
@@ -29,7 +29,36 @@ const collectFileFacts = (sf, options) => {
|
|
|
29
29
|
// What is in the file: its own node, and every node below it.
|
|
30
30
|
kind: { own: (0, tree_1.descriptor)(sf), descendants: (0, tree_1.descendantsOf)(sf) },
|
|
31
31
|
candidates: candidates ?? [],
|
|
32
|
-
|
|
32
|
+
entities: [...new Set((candidates ?? []).map((c) => c.entity).filter((r) => Boolean(r)))],
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
+
// The facts of a file are the same every time it is read in a run: the source is
|
|
36
|
+
// parsed once, `repoFiles`/`aliases`/`repoRoot` describe the SAME repo. A run
|
|
37
|
+
// reads a file's facts in several places (the linted file's pipeline and the
|
|
38
|
+
// project-wide index, for instance), so they are computed once per SourceFile
|
|
39
|
+
// and handed out as a shallow copy — a consumer may attach `entities` to the
|
|
40
|
+
// file's fact object without touching the cached one. Guarded by the file's
|
|
41
|
+
// current text: an overwritten SourceFile has different facts. The barrel budget is
|
|
42
|
+
// part of the key too — the same file walked with a different `barrelDepth`
|
|
43
|
+
// answers a different declaring file.
|
|
44
|
+
const FILE_FACTS = new WeakMap();
|
|
45
|
+
const collectFileFacts = (sf, options) => {
|
|
46
|
+
// A caller that hands real `candidates` derives `entities` from them, so that
|
|
47
|
+
// result is its own and is not cached.
|
|
48
|
+
if (options.candidates?.length)
|
|
49
|
+
return buildFileFacts(sf, options);
|
|
50
|
+
const text = sf.getFullText();
|
|
51
|
+
const cached = FILE_FACTS.get(sf);
|
|
52
|
+
if (cached && cached.text === text && cached.depth === options.barrelDepth)
|
|
53
|
+
return { ...cached.facts };
|
|
54
|
+
const facts = buildFileFacts(sf, options);
|
|
55
|
+
FILE_FACTS.set(sf, { text, depth: options.barrelDepth, facts });
|
|
56
|
+
return { ...facts };
|
|
57
|
+
};
|
|
35
58
|
exports.collectFileFacts = collectFileFacts;
|
|
59
|
+
// Drop this file's cached facts, for the same reason as the comment cache: they
|
|
60
|
+
// are derived from a syntax tree the run has finished with.
|
|
61
|
+
const releaseFileFacts = (sf) => {
|
|
62
|
+
FILE_FACTS.delete(sf);
|
|
63
|
+
};
|
|
64
|
+
exports.releaseFileFacts = releaseFileFacts;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SourceFile } from "ts-morph";
|
|
2
2
|
import type { ResolveCtx } from "./file-exports";
|
|
3
|
-
import type { ImportFact } from "
|
|
3
|
+
import type { ImportFact } from "@md-code/follow-architecture/entities/facts";
|
|
4
4
|
declare const importsOf: (sf: SourceFile, ctx: ResolveCtx) => ImportFact[];
|
|
5
5
|
export { importsOf };
|
|
@@ -13,18 +13,34 @@ const ts_morph_1 = require("ts-morph");
|
|
|
13
13
|
const tree_1 = require("./tree");
|
|
14
14
|
const properties_1 = require("./properties");
|
|
15
15
|
const heritage_1 = require("./heritage");
|
|
16
|
-
const imports_1 = require("
|
|
16
|
+
const imports_1 = require("@md-code/follow-architecture/utils/imports");
|
|
17
|
+
const export_chain_1 = require("./export-chain");
|
|
17
18
|
const statementImport = (imp, ctx) => {
|
|
18
19
|
const source = imp.getModuleSpecifierValue();
|
|
19
20
|
// Named imports carry the LOCAL binding name (`b as c` → "c").
|
|
20
|
-
const entry = {
|
|
21
|
+
const entry = {
|
|
22
|
+
form: "statement",
|
|
23
|
+
source,
|
|
24
|
+
typeOnly: imp.isTypeOnly(),
|
|
25
|
+
named: imp.getNamedImports().map((el) => el.getAliasNode()?.getText() ?? el.getName()),
|
|
26
|
+
line: (0, tree_1.startLine)(imp),
|
|
27
|
+
piece: null,
|
|
28
|
+
};
|
|
21
29
|
const def = imp.getDefaultImport();
|
|
22
30
|
if (def)
|
|
23
31
|
entry.defaultName = def.getText();
|
|
24
32
|
const ns = imp.getNamespaceImport();
|
|
25
33
|
if (ns)
|
|
26
34
|
entry.namespaceName = ns.getText();
|
|
35
|
+
entry.imported = imp.getNamedImports().map((el) => el.getName());
|
|
27
36
|
entry.resolved = (0, imports_1.resolveImport)(imp.getSourceFile(), source, ctx);
|
|
37
|
+
// A named import is judged where the NAME is declared, not where the module
|
|
38
|
+
// that passes it on lives. No names (or no resolution) leaves the edge on the
|
|
39
|
+
// module file, as every relation did before.
|
|
40
|
+
// The DECLARED name is the one inside the braces; an alias (`X as Y`) renames the
|
|
41
|
+
// binding, never the symbol the target file declares.
|
|
42
|
+
if (entry.imported?.length && entry.resolved)
|
|
43
|
+
entry.declaring = (0, export_chain_1.declaringFiles)(ctx, entry.resolved, entry.imported);
|
|
28
44
|
return entry;
|
|
29
45
|
};
|
|
30
46
|
// `require("x")` / `import("x")` — the call forms, only when the first argument
|
|
@@ -38,7 +54,14 @@ const callImport = (call, ctx) => {
|
|
|
38
54
|
const arg = call.getArguments()[0];
|
|
39
55
|
if (!arg || arg.getKind() !== tree_1.SK.StringLiteral)
|
|
40
56
|
return null;
|
|
41
|
-
const entry = {
|
|
57
|
+
const entry = {
|
|
58
|
+
form: isDynamic ? "dynamic" : "require",
|
|
59
|
+
source: (0, tree_1.nodeText)(arg) || null,
|
|
60
|
+
typeOnly: false,
|
|
61
|
+
named: [],
|
|
62
|
+
line: call.getStartLineNumber(),
|
|
63
|
+
piece: (0, properties_1.enclosingPiece)(call),
|
|
64
|
+
};
|
|
42
65
|
entry.resolved = (0, imports_1.resolveImport)(call.getSourceFile(), entry.source ?? "", ctx);
|
|
43
66
|
return entry;
|
|
44
67
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createTsProject, loadSourceFile } from "./project";
|
|
2
|
-
export { importNameModules, declaredFileOfNode, declaredFileOf, declaredFileOfType, declaredFileOfExpr, repoRelative, inRepo } from "./resolve";
|
|
3
|
-
export { collectFileFacts } from "./file-facts";
|
|
2
|
+
export { importNameModules, declaredFileOfNode, declaredFileOf, declaredFileOfType, declaredFileOfExpr, repoRelative, inRepo, } from "./resolve";
|
|
3
|
+
export { collectFileFacts, releaseFileFacts } from "./file-facts";
|
|
4
4
|
export type { DeclInfo } from "./resolve";
|
|
5
5
|
export type { AliasMap } from "./project";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectFileFacts = exports.inRepo = exports.repoRelative = exports.declaredFileOfExpr = exports.declaredFileOfType = exports.declaredFileOf = exports.declaredFileOfNode = exports.importNameModules = exports.loadSourceFile = exports.createTsProject = void 0;
|
|
3
|
+
exports.releaseFileFacts = exports.collectFileFacts = exports.inRepo = exports.repoRelative = exports.declaredFileOfExpr = exports.declaredFileOfType = exports.declaredFileOf = exports.declaredFileOfNode = exports.importNameModules = exports.loadSourceFile = exports.createTsProject = void 0;
|
|
4
4
|
// A source file: how it is loaded, and everything that is true about it. The
|
|
5
5
|
// entity is split by question, each half in its own module, re-exported here so
|
|
6
6
|
// every consumer keeps importing `entities/ast/file`:
|
|
@@ -20,3 +20,4 @@ Object.defineProperty(exports, "repoRelative", { enumerable: true, get: function
|
|
|
20
20
|
Object.defineProperty(exports, "inRepo", { enumerable: true, get: function () { return resolve_1.inRepo; } });
|
|
21
21
|
var file_facts_1 = require("./file-facts");
|
|
22
22
|
Object.defineProperty(exports, "collectFileFacts", { enumerable: true, get: function () { return file_facts_1.collectFileFacts; } });
|
|
23
|
+
Object.defineProperty(exports, "releaseFileFacts", { enumerable: true, get: function () { return file_facts_1.releaseFileFacts; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node, type SourceFile } from "ts-morph";
|
|
2
2
|
import type { LooseNode } from "./loose";
|
|
3
|
-
import type { ReturnFact, ParameterFact } from "
|
|
3
|
+
import type { ReturnFact, ParameterFact } from "@md-code/follow-architecture/entities/facts";
|
|
4
4
|
declare const nearestFunction: (node: Node) => Node | null;
|
|
5
5
|
declare const nameOf: (fn: LooseNode) => string | null;
|
|
6
6
|
declare const returnsFact: (node: LooseNode) => ReturnFact[];
|
|
@@ -9,7 +9,7 @@ const ts_morph_1 = require("ts-morph");
|
|
|
9
9
|
const tree_1 = require("./tree");
|
|
10
10
|
const properties_1 = require("./properties");
|
|
11
11
|
const file_1 = require("./file");
|
|
12
|
-
const dispatch_1 = require("
|
|
12
|
+
const dispatch_1 = require("@md-code/follow-architecture/utils/dispatch");
|
|
13
13
|
// The nearest function-like ancestor of a node, or null.
|
|
14
14
|
const nearestFunction = (node) => {
|
|
15
15
|
let n = node?.getParent();
|
|
@@ -27,7 +27,12 @@ exports.nearestFunction = nearestFunction;
|
|
|
27
27
|
// `dispatchOn`): a named kind answers its OWN name — final, even when it has
|
|
28
28
|
// none — anything else asks its parent, and only a naming parent's name counts.
|
|
29
29
|
const NAMED_KINDS = new Set([tree_1.SK.FunctionDeclaration, tree_1.SK.MethodDeclaration]);
|
|
30
|
-
const NAME_PARENT_KINDS = new Set([
|
|
30
|
+
const NAME_PARENT_KINDS = new Set([
|
|
31
|
+
tree_1.SK.VariableDeclaration,
|
|
32
|
+
tree_1.SK.PropertyAssignment,
|
|
33
|
+
tree_1.SK.PropertyDeclaration,
|
|
34
|
+
tree_1.SK.PropertySignature,
|
|
35
|
+
]);
|
|
31
36
|
const ownName = (fn) => fn.getName?.() ?? null;
|
|
32
37
|
const parentName = (fn) => {
|
|
33
38
|
const p = fn?.getParent();
|
|
@@ -69,7 +74,7 @@ exports.returnsFact = returnsFact;
|
|
|
69
74
|
// ── Parameters ──────────────────────────────────────────────────────────────
|
|
70
75
|
// `typeFile` is the file that declares the parameter's TYPE, resolved by the
|
|
71
76
|
// checker through imports and aliases — the same answer `writes` uses. That is
|
|
72
|
-
// how
|
|
77
|
+
// how an entity can say "this function receives data from the host layer" without
|
|
73
78
|
// naming a folder and without naming a type.
|
|
74
79
|
//
|
|
75
80
|
// A destructured parameter (`{ a, b }`) is ONE parameter whose name is the whole
|
|
@@ -82,7 +87,11 @@ const bindingsOf = (p, checker, repoRoot) => {
|
|
|
82
87
|
return [];
|
|
83
88
|
return (nameNode?.getElements?.() ?? []).map((el) => {
|
|
84
89
|
const typeNode = el.getTypeNode?.() ?? null;
|
|
85
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
name: el.getName?.() ?? null,
|
|
92
|
+
type: typeNode ? typeNode.getText() : null,
|
|
93
|
+
typeFile: typeNode ? ((0, file_1.declaredFileOfNode)(typeNode, checker, repoRoot)?.file ?? null) : null,
|
|
94
|
+
};
|
|
86
95
|
});
|
|
87
96
|
};
|
|
88
97
|
const typeTextOfParam = (p) => p.getTypeNode?.()?.getText() ?? (0, tree_1.typeText)(p);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { SourceFile, TypeChecker } from "ts-morph";
|
|
2
|
-
import type { ImportFact } from "
|
|
2
|
+
import type { ImportFact } from "@md-code/follow-architecture/entities/facts";
|
|
3
3
|
declare const heritageOf: (sf: SourceFile, checker: TypeChecker, repoRoot: string, rel: string) => ImportFact[];
|
|
4
4
|
export { heritageOf };
|
|
@@ -28,7 +28,15 @@ const heritageOf = (sf, checker, repoRoot, rel) => {
|
|
|
28
28
|
if (!(0, file_1.inRepo)(file, repoRoot))
|
|
29
29
|
continue;
|
|
30
30
|
const name = (clause.getExpression?.() ?? clause).getText();
|
|
31
|
-
out.push({
|
|
31
|
+
out.push({
|
|
32
|
+
form: "heritage",
|
|
33
|
+
source: name,
|
|
34
|
+
typeOnly: true,
|
|
35
|
+
named: [name],
|
|
36
|
+
line: (0, tree_1.startLine)(clause),
|
|
37
|
+
piece: null,
|
|
38
|
+
resolved: file,
|
|
39
|
+
});
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
return out;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type SourceFile } from "ts-morph";
|
|
2
2
|
import { createTsProject, loadSourceFile, importNameModules, collectFileFacts } from "./file";
|
|
3
|
-
import type { Candidate } from "
|
|
3
|
+
import type { Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
4
4
|
type ImportMap = ReadonlyMap<string, string>;
|
|
5
|
-
declare const collectCandidates: (sf: SourceFile, importMap: ImportMap, rel: string
|
|
6
|
-
|
|
5
|
+
declare const collectCandidates: (sf: SourceFile, importMap: ImportMap, rel: string, repoRoot: string, opts?: {
|
|
6
|
+
usage?: boolean;
|
|
7
|
+
}) => Candidate[];
|
|
8
|
+
declare const releaseFile: (sf: SourceFile) => void;
|
|
9
|
+
export { createTsProject, loadSourceFile, importNameModules, collectFileFacts, collectCandidates, releaseFile };
|