@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
|
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
37
|
// AUDIT: does any finding describe the same thing differently in the text and in
|
|
28
38
|
// the picture?
|
|
@@ -103,9 +113,9 @@ for (const f of data.findings) {
|
|
|
103
113
|
// divergence this file exists to catch.
|
|
104
114
|
for (const o of f.fixOptions ?? []) {
|
|
105
115
|
// Repairs with no geometry: the rule's own words (`rules`), "give this code
|
|
106
|
-
//
|
|
116
|
+
// an entity" (`entity`), "create what is missing" (`add`). They name no place,
|
|
107
117
|
// and the card says so — that is not a divergence.
|
|
108
|
-
if (o.code === "rules" || o.code === "
|
|
118
|
+
if (o.code === "rules" || o.code === "entity" || o.code === "add")
|
|
109
119
|
continue;
|
|
110
120
|
// A deletion has no geometry either — and it is NOT the same as "nothing":
|
|
111
121
|
// the card must say "removed", which `plan.remove` carries.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReferencesFact } from "@md-code/follow-architecture/entities/facts";
|
|
2
|
+
declare const primeUsageIndex: (repoRoot: string, repoFiles: readonly string[]) => void;
|
|
3
|
+
declare const usageFromIndex: (name: string | null, rel: string, exported: boolean, kindName: string | null | undefined) => ReferencesFact | null;
|
|
4
|
+
export { primeUsageIndex, usageFromIndex };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.usageFromIndex = exports.primeUsageIndex = void 0;
|
|
37
|
+
// THE OPTIONAL, CHEAPER SOURCE OF `references` (option `usage: index`, CLI
|
|
38
|
+
// `--usage index`): an answer computed from an index of IDENTIFIER OCCURRENCES
|
|
39
|
+
// instead of from a program that holds the whole repository. The default stays
|
|
40
|
+
// the checker (`entities/ast/usage.ts`), whose answer is what this mode
|
|
41
|
+
// approximates: it is faster and costs less memory, and it is wrong wherever two
|
|
42
|
+
// modules use one name for different things.
|
|
43
|
+
//
|
|
44
|
+
// The index is one pass over the text of every scanned file with `ts.createScanner`
|
|
45
|
+
// — tokens, no AST, no project, no checker. Per name it keeps, per file: how many
|
|
46
|
+
// standalone occurrences, how many after a dot (`?.` included — a member, not the
|
|
47
|
+
// value), how many import specifiers (a binding, but the checker counts it as a
|
|
48
|
+
// reference too), how many `export … from` specifiers (a republish, which
|
|
49
|
+
// `usedIn` excludes), and whether the file declares the name at top level (then
|
|
50
|
+
// every occurrence in it belongs to that declaration, not to the name).
|
|
51
|
+
//
|
|
52
|
+
// The answer keeps the shape and the meaning of `ReferencesFact`
|
|
53
|
+
// (`entities/facts.ts:138`): `total`, `outside`, `files`, `usedIn`.
|
|
54
|
+
const fs = __importStar(require("node:fs"));
|
|
55
|
+
const path = __importStar(require("node:path"));
|
|
56
|
+
const ts_morph_1 = require("ts-morph");
|
|
57
|
+
const empty = () => ({ declares: false, plain: 0, member: 0, imported: 0, exported: 0, declared: 0 });
|
|
58
|
+
const emptySums = () => ({ total: 0, outside: 0, where: [], used: [] });
|
|
59
|
+
let index = null;
|
|
60
|
+
const isDeclKeyword = (kind) => kind === ts_morph_1.ts.SyntaxKind.FunctionKeyword ||
|
|
61
|
+
kind === ts_morph_1.ts.SyntaxKind.ClassKeyword ||
|
|
62
|
+
kind === ts_morph_1.ts.SyntaxKind.ConstKeyword ||
|
|
63
|
+
kind === ts_morph_1.ts.SyntaxKind.LetKeyword ||
|
|
64
|
+
kind === ts_morph_1.ts.SyntaxKind.VarKeyword ||
|
|
65
|
+
kind === ts_morph_1.ts.SyntaxKind.InterfaceKeyword ||
|
|
66
|
+
kind === ts_morph_1.ts.SyntaxKind.TypeKeyword ||
|
|
67
|
+
kind === ts_morph_1.ts.SyntaxKind.EnumKeyword ||
|
|
68
|
+
kind === ts_morph_1.ts.SyntaxKind.AbstractKeyword ||
|
|
69
|
+
kind === ts_morph_1.ts.SyntaxKind.AsyncKeyword;
|
|
70
|
+
// One file's text → its occurrences. The scanner is the parser's own lexer: it
|
|
71
|
+
// knows a comment from a string from a template from a regex, which is the reason
|
|
72
|
+
// the index can be built without an AST at all.
|
|
73
|
+
// eslint-disable-next-line complexity, max-lines-per-function -- a token scanner is a state machine: the roles (value / member / import / export / declaration) are decided from one running cursor and the previous token, and the branches are its states.
|
|
74
|
+
const scanInto = (into, rel, text) => {
|
|
75
|
+
const scanner = ts_morph_1.ts.createScanner(ts_morph_1.ts.ScriptTarget.Latest, true, ts_morph_1.ts.LanguageVariant.JSX, text);
|
|
76
|
+
const touch = (name) => {
|
|
77
|
+
let files = into.get(name);
|
|
78
|
+
if (!files) {
|
|
79
|
+
files = new Map();
|
|
80
|
+
into.set(name, files);
|
|
81
|
+
}
|
|
82
|
+
let found = files.get(rel);
|
|
83
|
+
if (!found) {
|
|
84
|
+
found = empty();
|
|
85
|
+
files.set(rel, found);
|
|
86
|
+
}
|
|
87
|
+
return found;
|
|
88
|
+
};
|
|
89
|
+
let previous = ts_morph_1.ts.SyntaxKind.Unknown;
|
|
90
|
+
let depth = 0;
|
|
91
|
+
// `export { … } from "x"`: the names between the braces, kept until `from`
|
|
92
|
+
// says they are a republish. Any other token ends the guess.
|
|
93
|
+
let pendingExport = null;
|
|
94
|
+
let pendingState = "idle";
|
|
95
|
+
// `import { … } from` / `import x from`: the same shape, marked as a binding.
|
|
96
|
+
let pendingImport = null;
|
|
97
|
+
let importing = false;
|
|
98
|
+
// The next identifier is a declaration of its own name (`function foo`).
|
|
99
|
+
let declareNext = false;
|
|
100
|
+
const flush = (names, field) => {
|
|
101
|
+
for (const name of names ?? [])
|
|
102
|
+
touch(name)[field] += 1;
|
|
103
|
+
};
|
|
104
|
+
for (;;) {
|
|
105
|
+
const kind = scanner.scan();
|
|
106
|
+
if (kind === ts_morph_1.ts.SyntaxKind.EndOfFileToken)
|
|
107
|
+
break;
|
|
108
|
+
if (kind === ts_morph_1.ts.SyntaxKind.OpenBraceToken) {
|
|
109
|
+
depth += 1;
|
|
110
|
+
if (pendingState === "after-export") {
|
|
111
|
+
pendingExport = [];
|
|
112
|
+
pendingState = "in-list";
|
|
113
|
+
}
|
|
114
|
+
else if (pendingState !== "in-list") {
|
|
115
|
+
flush(pendingExport, "exported");
|
|
116
|
+
pendingExport = null;
|
|
117
|
+
pendingState = "idle";
|
|
118
|
+
flush(pendingImport, "imported");
|
|
119
|
+
pendingImport = null;
|
|
120
|
+
importing = false;
|
|
121
|
+
}
|
|
122
|
+
previous = kind;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (kind === ts_morph_1.ts.SyntaxKind.CloseBraceToken) {
|
|
126
|
+
depth -= 1;
|
|
127
|
+
if (pendingState === "in-list")
|
|
128
|
+
pendingState = "after-close";
|
|
129
|
+
previous = kind;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (kind === ts_morph_1.ts.SyntaxKind.ExportKeyword) {
|
|
133
|
+
flush(pendingExport, "exported");
|
|
134
|
+
pendingExport = null;
|
|
135
|
+
pendingState = "after-export";
|
|
136
|
+
declareNext = false;
|
|
137
|
+
previous = kind;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (kind === ts_morph_1.ts.SyntaxKind.ImportKeyword) {
|
|
141
|
+
importing = true;
|
|
142
|
+
pendingImport = null;
|
|
143
|
+
previous = kind;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (kind === ts_morph_1.ts.SyntaxKind.FromKeyword) {
|
|
147
|
+
flush(pendingExport, "exported");
|
|
148
|
+
pendingExport = null;
|
|
149
|
+
pendingState = "idle";
|
|
150
|
+
flush(pendingImport, "imported");
|
|
151
|
+
pendingImport = null;
|
|
152
|
+
importing = false;
|
|
153
|
+
previous = kind;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (kind === ts_morph_1.ts.SyntaxKind.Identifier) {
|
|
157
|
+
const name = scanner.getTokenText();
|
|
158
|
+
const found = touch(name);
|
|
159
|
+
if (declareNext && depth === 0) {
|
|
160
|
+
found.declares = true;
|
|
161
|
+
found.declared += 1;
|
|
162
|
+
declareNext = false;
|
|
163
|
+
}
|
|
164
|
+
else if (pendingState === "in-list") {
|
|
165
|
+
if (pendingExport !== null)
|
|
166
|
+
pendingExport.push(name);
|
|
167
|
+
}
|
|
168
|
+
else if (pendingState === "after-export") {
|
|
169
|
+
// `export const x` / `export default x`: no list, the name is a value.
|
|
170
|
+
pendingState = "idle";
|
|
171
|
+
if (previous === ts_morph_1.ts.SyntaxKind.DotToken || previous === ts_morph_1.ts.SyntaxKind.QuestionDotToken)
|
|
172
|
+
found.member += 1;
|
|
173
|
+
else
|
|
174
|
+
found.plain += 1;
|
|
175
|
+
}
|
|
176
|
+
else if (importing) {
|
|
177
|
+
pendingImport?.push(name);
|
|
178
|
+
found.imported += 1;
|
|
179
|
+
if (pendingImport === null)
|
|
180
|
+
pendingImport = [name];
|
|
181
|
+
}
|
|
182
|
+
else if (previous === ts_morph_1.ts.SyntaxKind.DotToken || previous === ts_morph_1.ts.SyntaxKind.QuestionDotToken) {
|
|
183
|
+
found.member += 1;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
found.plain += 1;
|
|
187
|
+
}
|
|
188
|
+
previous = kind;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
// Anything else ends a list being guessed at (an `as` alias keeps it: the
|
|
192
|
+
// LOCAL name is a binding of the imported one, and the checker names the
|
|
193
|
+
// pair by the one on the left).
|
|
194
|
+
if (kind !== ts_morph_1.ts.SyntaxKind.CommaToken && kind !== ts_morph_1.ts.SyntaxKind.AsKeyword) {
|
|
195
|
+
if (pendingState !== "idle") {
|
|
196
|
+
flush(pendingExport, "exported");
|
|
197
|
+
pendingExport = null;
|
|
198
|
+
pendingState = "idle";
|
|
199
|
+
}
|
|
200
|
+
if (pendingImport !== null || importing) {
|
|
201
|
+
flush(pendingImport, "imported");
|
|
202
|
+
pendingImport = null;
|
|
203
|
+
importing = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (depth === 0 && isDeclKeyword(kind))
|
|
207
|
+
declareNext = true;
|
|
208
|
+
else if (kind !== ts_morph_1.ts.SyntaxKind.DefaultKeyword)
|
|
209
|
+
declareNext = false;
|
|
210
|
+
previous = kind;
|
|
211
|
+
}
|
|
212
|
+
flush(pendingExport, "exported");
|
|
213
|
+
flush(pendingImport, "imported");
|
|
214
|
+
};
|
|
215
|
+
// Build the index for the files this run can see. Called once, before any file is
|
|
216
|
+
// read: an answer about a name is a statement about every file, so a partial
|
|
217
|
+
// index would answer with a part of the truth.
|
|
218
|
+
const primeUsageIndex = (repoRoot, repoFiles) => {
|
|
219
|
+
const into = new Map();
|
|
220
|
+
for (const rel of repoFiles) {
|
|
221
|
+
let text;
|
|
222
|
+
try {
|
|
223
|
+
text = fs.readFileSync(path.join(repoRoot, rel), "utf8");
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
scanInto(into, rel, text);
|
|
229
|
+
}
|
|
230
|
+
index = into;
|
|
231
|
+
};
|
|
232
|
+
exports.primeUsageIndex = primeUsageIndex;
|
|
233
|
+
// A member of an object or a shape is named after the property; a value, a
|
|
234
|
+
// function, a class or a type is named after the binding. The two are counted from
|
|
235
|
+
// different occurrences, which is what keeps `a.foo` from reading as a use of `foo`.
|
|
236
|
+
const isMemberKind = (kindName) => kindName === "PropertyDeclaration" ||
|
|
237
|
+
kindName === "MethodDeclaration" ||
|
|
238
|
+
kindName === "PropertySignature" ||
|
|
239
|
+
kindName === "MethodSignature" ||
|
|
240
|
+
kindName === "EnumMember" ||
|
|
241
|
+
kindName === "GetAccessor" ||
|
|
242
|
+
kindName === "SetAccessor";
|
|
243
|
+
// How many uses of the name one file's part counts, given the role the
|
|
244
|
+
// declaration plays (a member is counted from its occurrences after a dot).
|
|
245
|
+
const tally = (member, found) => member ? found.member : found.plain + found.imported + found.exported;
|
|
246
|
+
// The name's parts in every file but the declaring one: `outside` counts the
|
|
247
|
+
// occurrences, `where` the files that mention it, `used` the files that would
|
|
248
|
+
// break without it. A file that owns the name is skipped — its occurrences are
|
|
249
|
+
// its own declaration, not a use.
|
|
250
|
+
const sumParts = (files, rel, member) => {
|
|
251
|
+
const sums = emptySums();
|
|
252
|
+
for (const [file, found] of files) {
|
|
253
|
+
if (file !== rel && found.declares)
|
|
254
|
+
continue;
|
|
255
|
+
const n = tally(member, found);
|
|
256
|
+
sums.total += n;
|
|
257
|
+
if (file === rel)
|
|
258
|
+
continue;
|
|
259
|
+
sums.outside += n;
|
|
260
|
+
if (n > 0)
|
|
261
|
+
sums.where.push(file);
|
|
262
|
+
if (isUse(member, found))
|
|
263
|
+
sums.used.push(file);
|
|
264
|
+
}
|
|
265
|
+
return sums;
|
|
266
|
+
};
|
|
267
|
+
// Whether a file's occurrences are USES rather than a republish or a member of
|
|
268
|
+
// another object: `usedIn` counts places that would break if the name went away.
|
|
269
|
+
const isUse = (member, found) => member ? found.member > found.exported : found.plain + found.imported > 0;
|
|
270
|
+
// The answer for one name, in the shape `usageFact` returns. `null` where the
|
|
271
|
+
// question does not apply — the same rule as the checker path: only a named,
|
|
272
|
+
// exported piece has a reach beyond itself.
|
|
273
|
+
const usageFromIndex = (name, rel, exported, kindName) => {
|
|
274
|
+
if (index === null || name === null || !exported)
|
|
275
|
+
return null;
|
|
276
|
+
const files = index.get(name);
|
|
277
|
+
if (files === undefined)
|
|
278
|
+
return { total: 0, outside: 0, files: [], usedIn: [] };
|
|
279
|
+
const sums = sumParts(files, rel, isMemberKind(kindName));
|
|
280
|
+
return { total: sums.total, outside: sums.outside, files: sums.where.sort(), usedIn: sums.used.sort() };
|
|
281
|
+
};
|
|
282
|
+
exports.usageFromIndex = usageFromIndex;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type UsageMode = "checker" | "index";
|
|
2
|
+
declare const DEFAULT_USAGE: UsageMode;
|
|
3
|
+
declare const usageModeOf: (raw: string | undefined) => UsageMode;
|
|
4
|
+
declare const setUsageMode: (next: UsageMode) => void;
|
|
5
|
+
declare const usageMode: () => UsageMode;
|
|
6
|
+
export { DEFAULT_USAGE, setUsageMode, usageMode, usageModeOf };
|
|
7
|
+
export type { UsageMode };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usageModeOf = exports.usageMode = exports.setUsageMode = exports.DEFAULT_USAGE = void 0;
|
|
4
|
+
const DEFAULT_USAGE = "checker";
|
|
5
|
+
exports.DEFAULT_USAGE = DEFAULT_USAGE;
|
|
6
|
+
let mode = DEFAULT_USAGE;
|
|
7
|
+
// Anything but the exact spelling of `index` keeps the checker: a typo must not
|
|
8
|
+
// silently change what a rule is told about the code.
|
|
9
|
+
const usageModeOf = (raw) => (raw === "index" ? "index" : DEFAULT_USAGE);
|
|
10
|
+
exports.usageModeOf = usageModeOf;
|
|
11
|
+
const setUsageMode = (next) => {
|
|
12
|
+
mode = next;
|
|
13
|
+
};
|
|
14
|
+
exports.setUsageMode = setUsageMode;
|
|
15
|
+
const usageMode = () => mode;
|
|
16
|
+
exports.usageMode = usageMode;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Index, type Usage } from "./fa-index";
|
|
2
|
+
import type { RunArgs } from "./index-run";
|
|
3
|
+
import type { Candidate } from "./entities/facts";
|
|
4
|
+
import type { SourceFile } from "ts-morph";
|
|
5
|
+
type UsageArgs = {
|
|
6
|
+
run: RunArgs;
|
|
7
|
+
index: Index;
|
|
8
|
+
zone: ReadonlySet<string>;
|
|
9
|
+
absOf: ReadonlyMap<string, string>;
|
|
10
|
+
};
|
|
11
|
+
type UsageStats = {
|
|
12
|
+
files: number;
|
|
13
|
+
asked: number;
|
|
14
|
+
answered: number;
|
|
15
|
+
};
|
|
16
|
+
declare const usageFor: (sf: SourceFile, candidates: readonly Candidate[], repoRoot: string) => Usage;
|
|
17
|
+
declare const runUsagePass: (args: UsageArgs) => UsageStats;
|
|
18
|
+
export { runUsagePass, usageFor };
|
|
19
|
+
export type { UsageStats };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usageFor = exports.runUsagePass = void 0;
|
|
4
|
+
// THE PASS THAT ASKS THE CHECKER. `references` and `implementations` are the only
|
|
5
|
+
// facts a file's record cannot get from its own syntax: who calls a name is a
|
|
6
|
+
// statement about every other file. Asking them while a chunk of the zone is being
|
|
7
|
+
// read would answer "nobody" for a helper the rest of the repo calls — so they are
|
|
8
|
+
// asked once, here, on ONE project over the whole repository, and the answers are
|
|
9
|
+
// stored by position in the index (`fa-usage`). The checks then read a number
|
|
10
|
+
// instead of opening a project to ask a question the run has already answered.
|
|
11
|
+
//
|
|
12
|
+
// The project is the same one every other whole-repo question uses
|
|
13
|
+
// (`wholeRepoProject` → `openProject`): a second configuration would give the
|
|
14
|
+
// checker different answers than the reference path, and the reference path is
|
|
15
|
+
// what a run without an index answers with.
|
|
16
|
+
const notices_1 = require("./report/notices");
|
|
17
|
+
const pipeline_facts_1 = require("./pipeline-facts");
|
|
18
|
+
const usage_mode_1 = require("./usage-mode");
|
|
19
|
+
const fa_index_1 = require("./fa-index");
|
|
20
|
+
const tree_1 = require("./entities/ast/tree");
|
|
21
|
+
const file_1 = require("./entities/ast/file");
|
|
22
|
+
const release_file_1 = require("./release-file");
|
|
23
|
+
const usage_1 = require("./entities/ast/usage");
|
|
24
|
+
const usage_sweep_1 = require("./usage-sweep");
|
|
25
|
+
const scan_run_1 = require("./scan-run");
|
|
26
|
+
// One declaration's answer, or null when the checker had nothing to add: a name
|
|
27
|
+
// that is not published keeps the `null` the record already carries, and storing
|
|
28
|
+
// that would be a second copy of the same silence.
|
|
29
|
+
//
|
|
30
|
+
// The count comes from the one-pass sweep (`usage-sweep`), which answers for every
|
|
31
|
+
// name the same way the language service does; a shape the sweep cannot attribute
|
|
32
|
+
// (`null`) is asked exactly, as before. Both are asked through the same project,
|
|
33
|
+
// so an answer does not depend on which of the two produced it.
|
|
34
|
+
const answerOf = (candidate, sf, relOf, ask) => {
|
|
35
|
+
if (candidate.at === undefined || candidate.len === undefined)
|
|
36
|
+
return null;
|
|
37
|
+
const node = sf.getDescendantAtStartWithWidth(candidate.at, candidate.len);
|
|
38
|
+
if (node === null || node === undefined)
|
|
39
|
+
return null;
|
|
40
|
+
const exported = (0, tree_1.isExported)(node);
|
|
41
|
+
const swept = maySweep(node, exported, ask) ? sweptOf(node, sf, candidate, ask) : null;
|
|
42
|
+
if (swept !== null)
|
|
43
|
+
return swept;
|
|
44
|
+
const answer = (0, usage_1.usageFact)(node, sf, { exported, relOf });
|
|
45
|
+
if (answer.references === null && answer.implementations === null)
|
|
46
|
+
return null;
|
|
47
|
+
return { references: answer.references, implementations: answer.implementations };
|
|
48
|
+
};
|
|
49
|
+
// A name that is not published has no answer at all (`usageFact` says so), and a
|
|
50
|
+
// rule reads `null` as "unknown", not as "nobody": the sweep counts uses of every
|
|
51
|
+
// name, so it must not answer for one of those. An interface keeps the exact path
|
|
52
|
+
// because `implementations` is a question only it raises.
|
|
53
|
+
const maySweep = (node, exported, ask) => ask !== null && exported && node.getKindName() !== "InterfaceDeclaration";
|
|
54
|
+
// The sweep's answer for one declaration, as the record stores it. `implementations`
|
|
55
|
+
// is a separate question (`getImplementations`) that only an interface raises, and
|
|
56
|
+
// the caller sends an interface down the exact path.
|
|
57
|
+
const sweptOf = (node, sf, candidate, ask) => {
|
|
58
|
+
if (candidate.name === undefined || candidate.name === null)
|
|
59
|
+
return null;
|
|
60
|
+
// The declaration's own symbol: `getSymbolAtLocation` answers for a name token,
|
|
61
|
+
// not for the declaration that holds it.
|
|
62
|
+
const symbol = node.getSymbol()?.compilerSymbol;
|
|
63
|
+
if (symbol === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
const rel = (0, file_1.repoRelative)(sf.getFilePath(), ask.root) ?? sf.getBaseName();
|
|
66
|
+
const references = ask.walk.references(symbol, rel, candidate.name);
|
|
67
|
+
if (references === null)
|
|
68
|
+
return null;
|
|
69
|
+
return { references, implementations: null };
|
|
70
|
+
};
|
|
71
|
+
// Every name of one file the checker can be asked about: the answers are keyed by
|
|
72
|
+
// the declaration's start, which is what the record keeps and what a later check
|
|
73
|
+
// looks a candidate up by.
|
|
74
|
+
const counted = (candidates, sf, repoRoot, ask = null) => {
|
|
75
|
+
const capture = (0, notices_1.beginNotices)();
|
|
76
|
+
const { answers, asked, answered } = answersOf(candidates, sf, repoRoot, ask);
|
|
77
|
+
return { answers, notices: capture.end(), asked, answered };
|
|
78
|
+
};
|
|
79
|
+
const answersOf = (candidates, sf, repoRoot, ask) => {
|
|
80
|
+
const relOf = (p) => (0, file_1.repoRelative)(p, repoRoot) ?? p;
|
|
81
|
+
const answers = {};
|
|
82
|
+
let asked = 0;
|
|
83
|
+
let answered = 0;
|
|
84
|
+
for (const candidate of candidates) {
|
|
85
|
+
const answer = answerOf(candidate, sf, relOf, ask);
|
|
86
|
+
asked += 1;
|
|
87
|
+
if (answer === null || candidate.at === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
answers[String(candidate.at)] = answer;
|
|
90
|
+
answered += 1;
|
|
91
|
+
}
|
|
92
|
+
return { answers, asked, answered };
|
|
93
|
+
};
|
|
94
|
+
// The same answers for ONE file whose syntax the caller already holds: the plain
|
|
95
|
+
// path (`pipeline.checkFile`, and a file outside the scan scope) has the file open
|
|
96
|
+
// and asks the checker right there, exactly as before the pass existed.
|
|
97
|
+
const usageFor = (sf, candidates, repoRoot) => {
|
|
98
|
+
const capture = (0, notices_1.beginNotices)();
|
|
99
|
+
const { answers } = answersOf(candidates, sf, repoRoot, null);
|
|
100
|
+
return { answers, notices: capture.end() };
|
|
101
|
+
};
|
|
102
|
+
exports.usageFor = usageFor;
|
|
103
|
+
// The pass itself: one project, one open per file, one write per chunk. The
|
|
104
|
+
// file's syntax is given back as its answers are taken (`releaseFile`), so what
|
|
105
|
+
// the pass holds is the program, never the tree of every file it walked.
|
|
106
|
+
const runUsagePass = (args) => {
|
|
107
|
+
const { run, index, zone, absOf } = args;
|
|
108
|
+
const stats = { files: 0, asked: 0, answered: 0 };
|
|
109
|
+
if (zone.size === 0 || !(0, pipeline_facts_1.needsUsage)(run.arch))
|
|
110
|
+
return stats;
|
|
111
|
+
// `usage: index` answered at extraction (`usageFromIndex`), where no project was
|
|
112
|
+
// needed: opening one now would be the whole-repo parse this mode exists to skip.
|
|
113
|
+
if ((0, usage_mode_1.usageMode)() === "index")
|
|
114
|
+
return stats;
|
|
115
|
+
const repoRoot = run.arch.repoRoot ?? ".";
|
|
116
|
+
const project = (0, scan_run_1.wholeRepoProject)();
|
|
117
|
+
const program = project.getProgram().compilerObject;
|
|
118
|
+
const ask = { walk: (0, usage_sweep_1.sweep)(program, repoRoot), checker: program.getTypeChecker(), root: repoRoot };
|
|
119
|
+
for (const rel of zone) {
|
|
120
|
+
const abs = absOf.get(rel);
|
|
121
|
+
if (abs === undefined)
|
|
122
|
+
continue;
|
|
123
|
+
const record = (0, fa_index_1.recordAt)(index, abs);
|
|
124
|
+
const sf = project.getSourceFile(abs) ?? null;
|
|
125
|
+
if (record === null || sf === null)
|
|
126
|
+
continue;
|
|
127
|
+
const { answers, notices, asked, answered } = counted(record.candidates, sf, repoRoot, ask);
|
|
128
|
+
stats.files += 1;
|
|
129
|
+
stats.asked += asked;
|
|
130
|
+
stats.answered += answered;
|
|
131
|
+
(0, fa_index_1.keepUsage)(index, abs, { answers, notices });
|
|
132
|
+
(0, release_file_1.releaseFile)(sf);
|
|
133
|
+
}
|
|
134
|
+
return stats;
|
|
135
|
+
};
|
|
136
|
+
exports.runUsagePass = runUsagePass;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareUsage = void 0;
|
|
4
|
+
// ONE PLACE THAT PICKS THE SOURCE OF `references` AND PREPARES IT. The mode is a
|
|
5
|
+
// run's (`--usage`, the rule's `usage`); the occurrence index has to be read from
|
|
6
|
+
// the repo's text before any answer is asked, and reading it twice for the same
|
|
7
|
+
// repo is wasted work — the CLI picks the mode and the scan asks again.
|
|
8
|
+
const usage_index_1 = require("./usage-index");
|
|
9
|
+
const usage_mode_1 = require("./usage-mode");
|
|
10
|
+
let primedFor = null;
|
|
11
|
+
let primedCount = 0;
|
|
12
|
+
const prepareUsage = (raw, root, files) => {
|
|
13
|
+
(0, usage_mode_1.setUsageMode)((0, usage_mode_1.usageModeOf)(raw));
|
|
14
|
+
if ((0, usage_mode_1.usageMode)() !== "index")
|
|
15
|
+
return;
|
|
16
|
+
if (primedFor === root && primedCount === files.length)
|
|
17
|
+
return;
|
|
18
|
+
(0, usage_index_1.primeUsageIndex)(root, files);
|
|
19
|
+
primedFor = root;
|
|
20
|
+
primedCount = files.length;
|
|
21
|
+
};
|
|
22
|
+
exports.prepareUsage = prepareUsage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ts } from "ts-morph";
|
|
2
|
+
import type { ReferencesFact } from "@md-code/follow-architecture/entities/facts";
|
|
3
|
+
type Sweep = {
|
|
4
|
+
references: (symbol: ts.Symbol, ownRel: string, name: string) => ReferencesFact | null;
|
|
5
|
+
unsure: ReadonlySet<string>;
|
|
6
|
+
};
|
|
7
|
+
declare const nameSymbol: (checker: ts.TypeChecker, node: ts.Node) => ts.Symbol | undefined;
|
|
8
|
+
declare const sweep: (program: ts.Program, repoRoot: string) => Sweep;
|
|
9
|
+
export { sweep, nameSymbol };
|
|
10
|
+
export type { Sweep };
|