@md-code/follow-architecture 0.3.0 → 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 +21 -0
- package/README.md +1310 -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 +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-roles/roles.js → code-entities/entities.js} +98 -61
- 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 +23 -0
- package/dist/config-options.js +18 -1
- package/dist/config-project.js +27 -9
- package/dist/config-report.d.ts +1 -1
- package/dist/config-report.js +37 -10
- package/dist/config-rule.d.ts +25 -0
- package/dist/config-rule.js +106 -13
- package/dist/config-state.d.ts +14 -3
- package/dist/config-state.js +197 -24
- package/dist/config.d.ts +25 -0
- package/dist/css/index.d.ts +11 -7
- package/dist/css/index.js +141 -30
- 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 +18 -8
- 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 +21 -9
- package/dist/css/syntax/scss/index.d.ts +2 -2
- package/dist/css/syntax/scss/index.js +18 -8
- 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 +34 -14
- 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 +32 -15
- 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 +21 -11
- 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 +148 -37
- 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 +10 -8
- package/dist/entities/location/where.js +89 -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 +89 -19
- 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 +112 -51
- package/dist/entities/tree/entries.d.ts +4 -4
- 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 +26 -12
- 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 +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 +25 -11
- 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 +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 +5 -2
- package/dist/main.js +223 -41
- 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 +64 -11
- package/dist/nodes/finally/emit.d.ts +4 -4
- 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 +78 -56
- 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 +64 -62
- 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.d.ts +1 -1
- 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 +21 -11
- 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/index.js +17 -7
- 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 +26 -7
- 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 +32 -19
- 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 +136 -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 +33 -23
- 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 +19 -9
- 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/index.js +17 -7
- 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/rules/normalize.js +108 -0
- 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 +19 -9
- 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/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +173 -0
- package/dist/utils/classify.d.ts +2 -2
- package/dist/utils/classify.js +4 -4
- package/dist/utils/configs.js +17 -7
- package/dist/utils/distinct.js +4 -2
- package/dist/utils/files.js +41 -37
- 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 +83 -19
- 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 +207 -0
- package/dist/utils/path-label.js +3 -1
- package/dist/utils/pattern.d.ts +5 -4
- package/dist/utils/pattern.js +55 -15
- 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/invariants/normalize.js +0 -95
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.commentsOf = void 0;
|
|
3
|
+
exports.releaseComments = exports.commentsOf = void 0;
|
|
4
4
|
const tree_1 = require("./tree");
|
|
5
5
|
const kind_1 = require("./kind");
|
|
6
6
|
const functions_1 = require("./functions");
|
|
@@ -17,16 +17,22 @@ const kindOf = (range, text) => {
|
|
|
17
17
|
// of the token that follows it, so the walk asks every node for the comments
|
|
18
18
|
// around it and keeps them by position — the file itself carries the ones above
|
|
19
19
|
// the first token.
|
|
20
|
-
const rangesOf = (sf) => {
|
|
20
|
+
const rangesOf = (sf, descendants) => {
|
|
21
21
|
const text = sf.getFullText();
|
|
22
22
|
const byPos = new Map();
|
|
23
|
-
for (const node of [sf, ...
|
|
23
|
+
for (const node of [sf, ...descendants]) {
|
|
24
24
|
const ranges = [...(node.getLeadingCommentRanges?.() ?? []), ...(node.getTrailingCommentRanges?.() ?? [])];
|
|
25
25
|
for (const range of ranges)
|
|
26
26
|
if (!byPos.has(range.getPos()))
|
|
27
27
|
byPos.set(range.getPos(), range);
|
|
28
28
|
}
|
|
29
|
-
return [...byPos.values()]
|
|
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
|
+
}));
|
|
30
36
|
};
|
|
31
37
|
// A comment is TRIVIA — text between tokens — but the parser still builds a node
|
|
32
38
|
// for a doc block, and that node has a subtree of its own: `JSDocParameterTag`
|
|
@@ -34,9 +40,9 @@ const rangesOf = (sf) => {
|
|
|
34
40
|
// inside of a doc block is described by the SAME machinery as any other node —
|
|
35
41
|
// no `tags` field, no list of known tag names, nothing to keep in sync with the
|
|
36
42
|
// language. Any comment that has no node of its own simply has no subtree.
|
|
37
|
-
const nodesByPos = (
|
|
43
|
+
const nodesByPos = (descendants) => {
|
|
38
44
|
const byPos = new Map();
|
|
39
|
-
for (const node of
|
|
45
|
+
for (const node of descendants)
|
|
40
46
|
if (!byPos.has(node.getStart()))
|
|
41
47
|
byPos.set(node.getStart(), node);
|
|
42
48
|
return byPos;
|
|
@@ -51,12 +57,11 @@ const linesOfRange = (sf, pos, end) => {
|
|
|
51
57
|
};
|
|
52
58
|
// The deepest function or class a comment sits inside. A doc block above a
|
|
53
59
|
// declaration is NOT inside it (it starts before the declaration does), which is
|
|
54
|
-
// the distinction a rule needs to say "no comments outside the action".
|
|
55
|
-
|
|
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) => {
|
|
56
63
|
let best = null;
|
|
57
|
-
for (const node of
|
|
58
|
-
if (!(0, tree_1.isFunctionNode)(node) && !(0, tree_1.isClassNode)(node))
|
|
59
|
-
continue;
|
|
64
|
+
for (const node of pieces) {
|
|
60
65
|
if (node.getStart() > pos || node.getEnd() < pos)
|
|
61
66
|
continue;
|
|
62
67
|
if (!best || node.getStart() > best.getStart())
|
|
@@ -67,18 +72,18 @@ const pieceAt = (sf, pos) => {
|
|
|
67
72
|
// The comment's `kind`: its own syntactic form, and — when the parser has a
|
|
68
73
|
// node for it — the node's whole neighbourhood and subtree, read through `is`
|
|
69
74
|
// like any other code.
|
|
70
|
-
const commentKind = (node, kind) =>
|
|
75
|
+
const commentKind = (node, kind) => node ? { ...(0, tree_1.kindFact)(node), ...(0, kind_1.spelled)(kind), own: { is: kind } } : (0, kind_1.spelled)(kind);
|
|
71
76
|
// The candidates. Each one carries the same facts every other candidate carries
|
|
72
77
|
// (where it is, the lines it spans, what kind it is) plus what only a comment
|
|
73
78
|
// has: its text, markers included — the markers are what tells a doc block from
|
|
74
79
|
// a plain block, and stripping them would throw that away.
|
|
75
|
-
const commentCandidate = (sf, rel,
|
|
76
|
-
const piece = pieceAt(
|
|
80
|
+
const commentCandidate = (sf, rel, view, span) => {
|
|
81
|
+
const piece = pieceAt(span.pos, view.pieces);
|
|
77
82
|
return {
|
|
78
83
|
name: null,
|
|
79
84
|
location: { path: rel ?? null, piece: piece ? ((0, functions_1.nameOf)(piece) ?? null) : null, nested: Boolean(piece) },
|
|
80
85
|
lines: linesOfRange(sf, span.pos, span.end),
|
|
81
|
-
kind: commentKind(nodes.get(span.pos), span.kind),
|
|
86
|
+
kind: commentKind(view.nodes.get(span.pos), span.kind),
|
|
82
87
|
text: sf.getFullText().slice(span.pos, span.end),
|
|
83
88
|
// A comment has no actions: it runs nothing, writes nothing, yields
|
|
84
89
|
// nothing. Stated, because every candidate answers every question.
|
|
@@ -93,8 +98,33 @@ const commentCandidate = (sf, rel, nodes, span) => {
|
|
|
93
98
|
implementations: null,
|
|
94
99
|
};
|
|
95
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();
|
|
96
108
|
const commentsOf = (sf, rel) => {
|
|
97
|
-
const
|
|
98
|
-
|
|
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 }));
|
|
99
121
|
};
|
|
100
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LooseNode } from "./loose";
|
|
2
|
-
import type { Candidate, AnyMember } from "
|
|
2
|
+
import type { Candidate, AnyMember } from "@md-code/follow-architecture/entities/facts";
|
|
3
3
|
declare const declarationFact: (node: LooseNode, rel: string, members: AnyMember[]) => Candidate;
|
|
4
4
|
export { declarationFact };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Candidate } from "
|
|
2
|
-
import type { ScanContext } from "
|
|
1
|
+
import type { Candidate } from "@md-code/follow-architecture/entities/facts";
|
|
2
|
+
import type { ScanContext } from "@md-code/follow-architecture/entities/context";
|
|
3
3
|
type Chain = {
|
|
4
4
|
depth: number;
|
|
5
5
|
chain: string[];
|
|
@@ -15,20 +15,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.attachCallDepth = void 0;
|
|
27
37
|
// How many calls deep a piece of code goes before somebody else does the work.
|
|
28
38
|
//
|
|
29
39
|
// A piece that calls an imported function which calls another which calls
|
|
30
40
|
// another is not readable at the call site: nobody can see where the state is
|
|
31
|
-
// finally changed, and no
|
|
41
|
+
// finally changed, and no entity rule can point at the place that changed it.
|
|
32
42
|
// The chain is what this fact measures — `toggleLineAction → applyDecorations →
|
|
33
43
|
// applyActiveEditorDecorations → …` is a depth of 5, and a rule may refuse it.
|
|
34
44
|
//
|
|
@@ -40,10 +50,15 @@ exports.attachCallDepth = void 0;
|
|
|
40
50
|
const fs = __importStar(require("node:fs"));
|
|
41
51
|
const path = __importStar(require("node:path"));
|
|
42
52
|
const index_1 = require("./index");
|
|
43
|
-
const
|
|
44
|
-
const notices_1 = require("
|
|
45
|
-
const try_read_1 = require("
|
|
46
|
-
const reason_1 = require("
|
|
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;
|
|
47
62
|
// A link's target: an imported name names its module (followed only when the
|
|
48
63
|
// module is a repo file); a local name is walked in this file. A link back to
|
|
49
64
|
// the piece itself is not a step.
|
|
@@ -114,14 +129,16 @@ const candidatesIn = (rel, ctx) => {
|
|
|
114
129
|
const text = fs.readFileSync(abs, "utf8");
|
|
115
130
|
const sf = (0, index_1.loadSourceFile)(ctx.project, abs, text);
|
|
116
131
|
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);
|
|
132
|
+
const candidates = (0, index_1.collectCandidates)(sf, importMap, rel, ctx.repoRoot, { usage: false });
|
|
118
133
|
// The facets read the same file the walk does, so a rendered component is a
|
|
119
|
-
// link here exactly as it is in the
|
|
134
|
+
// link here exactly as it is in the rules. The import map is handed over
|
|
120
135
|
// so a tag imported from another module names that module.
|
|
121
|
-
(0,
|
|
136
|
+
(0, index_2.enrich)(candidates, { rel, sf, text, repoRoot: ctx.repoRoot, importMap });
|
|
122
137
|
return candidates;
|
|
123
138
|
};
|
|
124
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();
|
|
125
142
|
ctx.cache?.files.set(rel, out);
|
|
126
143
|
return out;
|
|
127
144
|
};
|
|
@@ -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; } });
|