@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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registryFromIndex = exports.checkIndexed = exports.runIndexed = void 0;
|
|
4
|
+
// A SCAN THAT READS ITS OWN PAST: what a run can answer from the file index, what
|
|
5
|
+
// it has to ask the syntax again, and how the two are stitched back into one
|
|
6
|
+
// answer.
|
|
7
|
+
//
|
|
8
|
+
// THE ORDER OF A RUN (any mode):
|
|
9
|
+
// 1. read the LIGHT section (`fa-out`) of every scanned file: the summary — the
|
|
10
|
+
// classified pieces, the literals' places, the entities, the deps — and the
|
|
11
|
+
// verdicts an earlier run derived. Small (a few MB over a whole repo) and
|
|
12
|
+
// the only thing a warm run reads;
|
|
13
|
+
// 2. the zone is what must be read again — see `index-zone.ts` for what makes a
|
|
14
|
+
// summary stale and how far a change reaches;
|
|
15
|
+
// 3. the project-wide entity index is rebuilt from the SUMMARIES: every summary
|
|
16
|
+
// carries the classified pieces and the object-literal places of its file, so
|
|
17
|
+
// the pass over every file's syntax does not happen at all;
|
|
18
|
+
// 4. the zone is read again and written back in chunks: its record goes to `fa`,
|
|
19
|
+
// its summary to `fa-out`, and the objects are dropped as each chunk lands —
|
|
20
|
+
// a cold run never holds the records of the files it has already read;
|
|
21
|
+
// 5. one pass in scan order answers every file: a file whose verdicts are stored
|
|
22
|
+
// and whose facts did not change is REPLAYED from `fa-out` (nothing is read
|
|
23
|
+
// twice), a file in the zone is read back from `fa`, checked, and its verdicts
|
|
24
|
+
// written into `fa-out` alone — the record it was checked from is dropped as
|
|
25
|
+
// its chunk goes by.
|
|
26
|
+
//
|
|
27
|
+
// WHY THE VERDICTS ARE STORED: everything except the lookalike question is a pure
|
|
28
|
+
// function of one record plus the run's shared state, so replaying it from the
|
|
29
|
+
// index would replay findings that were deduped per PLACE (`dedupeBy`) against a
|
|
30
|
+
// population that no longer exists — the first file of a place wins, and editing a
|
|
31
|
+
// file can change the winner. That is why a file whose facts changed is checked
|
|
32
|
+
// together with everything the change can reach (the zone): a stored verdict is
|
|
33
|
+
// the answer its own facts gave, and the zone is the boundary of what a change
|
|
34
|
+
// invalidates.
|
|
35
|
+
const fa_index_1 = require("./fa-index");
|
|
36
|
+
const rules_1 = require("./rules");
|
|
37
|
+
const facts_record_1 = require("./facts-record");
|
|
38
|
+
const scan_run_1 = require("./scan-run");
|
|
39
|
+
const notices_1 = require("./report/notices");
|
|
40
|
+
const index_zone_1 = require("./index-zone");
|
|
41
|
+
const usage_pass_1 = require("./usage-pass");
|
|
42
|
+
const usage_prepare_1 = require("./usage-prepare");
|
|
43
|
+
const index_file_1 = require("./index-file");
|
|
44
|
+
const fa_values_1 = require("./fa-values");
|
|
45
|
+
// A record is read on the SAME project the checks use — the whole repo. Every
|
|
46
|
+
// fact that depends on type resolution (`parameters[].type`, an assignment's
|
|
47
|
+
// presence, a call's resolved module) has one answer per program, and a project
|
|
48
|
+
// holding only part of the repo gives a different one: `--index off` would then
|
|
49
|
+
// report findings the index cannot reproduce. The chunked project this run used
|
|
50
|
+
// before is gone for that reason.
|
|
51
|
+
const extractZone = (args, zone) => {
|
|
52
|
+
const { run, index, light, kept, registry, pieces } = args;
|
|
53
|
+
let extracted = 0;
|
|
54
|
+
for (const rel of zone) {
|
|
55
|
+
const abs = args.absOf.get(rel);
|
|
56
|
+
if (abs === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
const record = (0, facts_record_1.slimmable)((0, index_file_1.readOne)(abs, run, (0, scan_run_1.wholeRepoProject)()));
|
|
59
|
+
extracted += 1;
|
|
60
|
+
const summary = (0, fa_values_1.summaryOf)(record);
|
|
61
|
+
(0, index_file_1.addSummary)(registry, abs, record.rel, summary);
|
|
62
|
+
if (pieces)
|
|
63
|
+
(0, index_file_1.addPieces)(registry, record.candidates);
|
|
64
|
+
const fresh = { findings: null, notices: [...record.notices], summary };
|
|
65
|
+
// The lookalike answer of a fresh file is asked live in the scan pass; the
|
|
66
|
+
// verdicts are written there, once they exist.
|
|
67
|
+
if (!(0, fa_index_1.keepFacts)(index, abs, record, fresh))
|
|
68
|
+
kept.set(abs, record);
|
|
69
|
+
light.set(abs, fresh);
|
|
70
|
+
}
|
|
71
|
+
return extracted;
|
|
72
|
+
};
|
|
73
|
+
// Nothing to recompute: the verdicts of this file were derived from these very
|
|
74
|
+
// facts in an earlier run, and the zone says no change reached it.
|
|
75
|
+
const replayStored = (entry, findings) => {
|
|
76
|
+
if (entry === undefined || entry.findings === null)
|
|
77
|
+
return false;
|
|
78
|
+
(0, notices_1.replayNotices)(entry.notices);
|
|
79
|
+
findings.push(...entry.findings.before, ...entry.findings.nodes, ...entry.findings.after);
|
|
80
|
+
return true;
|
|
81
|
+
};
|
|
82
|
+
// One file, checked and — when this run read it again or its verdicts are missing
|
|
83
|
+
// — written back at once.
|
|
84
|
+
const scanOne = (args, at, findings) => {
|
|
85
|
+
const { run, light, absFiles, live } = args;
|
|
86
|
+
const abs = absFiles[at];
|
|
87
|
+
const entry = light.get(abs);
|
|
88
|
+
// A file outside `--files` is not checked, but what its READING could not read
|
|
89
|
+
// is still part of the report — the light value carries those lines.
|
|
90
|
+
if (run.shouldCheck && !run.shouldCheck(abs)) {
|
|
91
|
+
(0, notices_1.replayNotices)(entry?.notices ?? []);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const fresh = live.has(run.repoFiles[at]);
|
|
95
|
+
if (!fresh && replayStored(entry, findings))
|
|
96
|
+
return false;
|
|
97
|
+
return (0, index_file_1.checkOne)(args, { abs, entry, fresh }, findings);
|
|
98
|
+
};
|
|
99
|
+
// The scan itself: one pass in scan order, so the dedupe store, the folder
|
|
100
|
+
// counters and the entity scope see every file in the order a cold run saw them —
|
|
101
|
+
// and the index is opened once per chunk of files, not once per file.
|
|
102
|
+
const scanAll = (args) => {
|
|
103
|
+
const findings = [];
|
|
104
|
+
let written = 0;
|
|
105
|
+
(0, fa_index_1.scanChunks)(args.index, args.absFiles, (from, to) => {
|
|
106
|
+
for (let at = from; at < to; at += 1)
|
|
107
|
+
if (scanOne(args, at, findings))
|
|
108
|
+
written += 1;
|
|
109
|
+
});
|
|
110
|
+
return { findings, written };
|
|
111
|
+
};
|
|
112
|
+
const modeOf = (stale, zone, total) => {
|
|
113
|
+
if (stale === 0)
|
|
114
|
+
return "warm";
|
|
115
|
+
return zone >= total ? "cold" : "hybrid";
|
|
116
|
+
};
|
|
117
|
+
// The project-wide index, from the summaries: the answers a check gives about
|
|
118
|
+
// OTHER files. The `entity` scope is the one question about other files' PIECES:
|
|
119
|
+
// asked for by the same predicate that makes the checks read them, so a config
|
|
120
|
+
// that never names a code entity never decodes a file it does not check — and a
|
|
121
|
+
// config that names one decodes only the files that have it.
|
|
122
|
+
const lightIndex = (args) => {
|
|
123
|
+
const { index, light, absFiles, repoFiles, arch } = args;
|
|
124
|
+
const registry = (0, index_file_1.emptyRegistry)();
|
|
125
|
+
for (let at = 0; at < absFiles.length; at += 1) {
|
|
126
|
+
const entry = light.get(absFiles[at]);
|
|
127
|
+
if (entry !== undefined)
|
|
128
|
+
(0, index_file_1.addSummary)(registry, absFiles[at], repoFiles[at], entry.summary);
|
|
129
|
+
}
|
|
130
|
+
const pieces = (0, facts_record_1.namesCodeEntity)(arch.rules);
|
|
131
|
+
if (pieces) {
|
|
132
|
+
for (const list of (0, fa_index_1.readPeers)(index, (0, fa_index_1.pieceFiles)(light, (0, rules_1.namedEntitySlugs)(arch.rules))).values())
|
|
133
|
+
(0, index_file_1.addPieces)(registry, list);
|
|
134
|
+
}
|
|
135
|
+
return { registry, pieces, kept: new Map(), known: new Set(light.keys()), depsOf: (abs) => light.get(abs)?.summary.deps ?? [] };
|
|
136
|
+
};
|
|
137
|
+
// null means "this run may not use an index" — the caller then takes the plain
|
|
138
|
+
// path, which remembers nothing and reads every file.
|
|
139
|
+
const runIndexed = (run) => {
|
|
140
|
+
const root = run.arch.repoRoot ?? ".";
|
|
141
|
+
(0, usage_prepare_1.prepareUsage)(run.usage, root, run.repoFiles);
|
|
142
|
+
const index = (0, fa_index_1.openFactsIndex)({ root, option: run.option, arch: run.arch, scope: run.scope });
|
|
143
|
+
if (index === null)
|
|
144
|
+
return null;
|
|
145
|
+
// THE LIGHT PASS: every file's summary and stored verdicts, one decode each. No
|
|
146
|
+
// record is touched, so what a run holds from here on is a few MB, not the repo.
|
|
147
|
+
const light = (0, fa_index_1.readLight)(index, run.absFiles);
|
|
148
|
+
const absOf = new Map(run.repoFiles.map((rel, at) => [rel, run.absFiles[at]]));
|
|
149
|
+
const { zone, stale } = (0, index_zone_1.zoneOf)({ index, light, absFiles: run.absFiles, repoFiles: run.repoFiles, root });
|
|
150
|
+
const { registry, pieces, kept, known, depsOf } = lightIndex({ index, light, absFiles: run.absFiles, repoFiles: run.repoFiles, arch: run.arch });
|
|
151
|
+
const zoneArgs = { run, index, light, pieces, kept, registry, absOf };
|
|
152
|
+
let extracted = extractZone(zoneArgs, zone);
|
|
153
|
+
extracted += (0, index_zone_1.extendZone)({ zone, known, depsOf, absOf, repoFiles: run.repoFiles }, (paths) => extractZone(zoneArgs, paths));
|
|
154
|
+
// The depth cache answers a question about a file's TEXT, and every answer is
|
|
155
|
+
// already in a record: dropped here, so the scan pass does not keep the
|
|
156
|
+
// candidates of every file the extraction happened to look at.
|
|
157
|
+
delete run.arch.depthCache;
|
|
158
|
+
// Everything extracted is on disk before the checks read it back.
|
|
159
|
+
(0, fa_index_1.settle)(index);
|
|
160
|
+
// THE CHECKER'S ANSWERS, asked once: one project over the whole repo, the zone's
|
|
161
|
+
// published names only. The records in the zone carry no answer yet; every later
|
|
162
|
+
// check of them reads one from the index instead of opening a project.
|
|
163
|
+
const usage = (0, usage_pass_1.runUsagePass)({ run, index, zone, absOf });
|
|
164
|
+
// The answers are on disk before the first check reads one: a chunk that reads
|
|
165
|
+
// the section would otherwise see a value still queued in this process.
|
|
166
|
+
(0, fa_index_1.settle)(index);
|
|
167
|
+
// A file whose facts are stored but whose verdicts never landed (a run that
|
|
168
|
+
// stopped between the two) is checked without being read again.
|
|
169
|
+
const partial = [...light.values()].some((entry) => entry.findings === null);
|
|
170
|
+
(0, scan_run_1.adoptEntityIndex)(registry);
|
|
171
|
+
// Counted from here: a project built AFTER this point would be a second parse of
|
|
172
|
+
// the repo for a question the pass has already answered.
|
|
173
|
+
const beforeChecks = (0, scan_run_1.projectsOpened)();
|
|
174
|
+
const scanned = scanAll({
|
|
175
|
+
run,
|
|
176
|
+
index,
|
|
177
|
+
light,
|
|
178
|
+
kept,
|
|
179
|
+
absFiles: run.absFiles,
|
|
180
|
+
live: zone,
|
|
181
|
+
// The lookalike question and the css templates a re-read file carries are the
|
|
182
|
+
// two things that still need syntax in the checks; the checker's answers are
|
|
183
|
+
// already stored and read as data.
|
|
184
|
+
projectOpen: zone.size > 0 || partial,
|
|
185
|
+
});
|
|
186
|
+
const done = (0, fa_index_1.finish)(index);
|
|
187
|
+
// A run that has the whole file list is the one that can tombstone the rest.
|
|
188
|
+
const pruned = (0, fa_index_1.prune)(index, run.absFiles);
|
|
189
|
+
(0, scan_run_1.adoptEntityIndex)(null);
|
|
190
|
+
return {
|
|
191
|
+
findings: scanned.findings,
|
|
192
|
+
stats: {
|
|
193
|
+
mode: modeOf(stale, zone.size, run.repoFiles.length),
|
|
194
|
+
stale,
|
|
195
|
+
zone: zone.size,
|
|
196
|
+
extracted,
|
|
197
|
+
written: scanned.written,
|
|
198
|
+
bytes: done.bytes,
|
|
199
|
+
chunks: done.chunks,
|
|
200
|
+
compactions: done.compactions,
|
|
201
|
+
pruned: pruned.dropped,
|
|
202
|
+
warning: done.warning,
|
|
203
|
+
// The names the usage pass stored an answer for, and those that are not null.
|
|
204
|
+
usageFiles: usage.files,
|
|
205
|
+
usageNames: usage.answered,
|
|
206
|
+
// Whole-repo projects this run built, and how many of them the checks built.
|
|
207
|
+
projectsOpened: (0, scan_run_1.projectsOpened)(),
|
|
208
|
+
checksProjects: (0, scan_run_1.projectsOpened)() - beforeChecks,
|
|
209
|
+
// Read after the prune: a flush there can be the one that deferred.
|
|
210
|
+
compactionWarning: index.compactionWarning,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
exports.runIndexed = runIndexed;
|
|
215
|
+
var index_file_2 = require("./index-file");
|
|
216
|
+
Object.defineProperty(exports, "checkIndexed", { enumerable: true, get: function () { return index_file_2.checkIndexed; } });
|
|
217
|
+
Object.defineProperty(exports, "registryFromIndex", { enumerable: true, get: function () { return index_file_2.registryFromIndex; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Index, type Light } from "./fa-index";
|
|
2
|
+
declare const MAX_ZONE = 200;
|
|
3
|
+
declare const MAX_FOLDER = 400;
|
|
4
|
+
declare const importersOf: (light: Map<string, Light>, relOf: ReadonlyMap<string, string>) => Map<string, string[]>;
|
|
5
|
+
declare const closureOf: (seeds: readonly string[], edges: readonly ((rel: string) => readonly string[])[], limit: number) => Set<string>;
|
|
6
|
+
declare const extendZone: (args: {
|
|
7
|
+
zone: Set<string>;
|
|
8
|
+
known: ReadonlySet<string>;
|
|
9
|
+
depsOf: (abs: string) => readonly string[];
|
|
10
|
+
absOf: ReadonlyMap<string, string>;
|
|
11
|
+
repoFiles: readonly string[];
|
|
12
|
+
}, extract: (paths: ReadonlySet<string>) => number) => number;
|
|
13
|
+
type ZoneArgs = {
|
|
14
|
+
index: Index;
|
|
15
|
+
light: Map<string, Light>;
|
|
16
|
+
absFiles: readonly string[];
|
|
17
|
+
repoFiles: readonly string[];
|
|
18
|
+
root: string;
|
|
19
|
+
};
|
|
20
|
+
declare const zoneOf: (args: ZoneArgs) => {
|
|
21
|
+
zone: Set<string>;
|
|
22
|
+
stale: number;
|
|
23
|
+
};
|
|
24
|
+
export { zoneOf, importersOf, closureOf, extendZone, MAX_ZONE, MAX_FOLDER };
|
|
25
|
+
export type { ZoneArgs };
|
|
@@ -0,0 +1,219 @@
|
|
|
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.MAX_FOLDER = exports.MAX_ZONE = exports.extendZone = exports.closureOf = exports.importersOf = exports.zoneOf = void 0;
|
|
37
|
+
// WHICH FILES A WARM RUN HAS TO READ AGAIN. The summary in the light section
|
|
38
|
+
// answers for the bytes of its own file, but not all of a file's facts are decided
|
|
39
|
+
// there: a type, a usage
|
|
40
|
+
// count or an import is answered by ANOTHER file, and a file that moved changes
|
|
41
|
+
// the answers of its neighbours. So freshness cannot be "the file's own hash
|
|
42
|
+
// matches" — the zone adds everything the change can reach: the imports (what
|
|
43
|
+
// this file reads), the importers (what reads this file) and, transitively, their
|
|
44
|
+
// neighbours, plus the folders those files sit in (a folder-level finding is a
|
|
45
|
+
// statement about the folder's members).
|
|
46
|
+
//
|
|
47
|
+
// A zone that has grown past `MAX_ZONE` files is no longer a neighbourhood: the
|
|
48
|
+
// change touched something everything depends on, and reading the whole scan
|
|
49
|
+
// again is both simpler and no slower.
|
|
50
|
+
//
|
|
51
|
+
// A file that DISAPPEARED is the one change the index cannot report: the index
|
|
52
|
+
// answers only for paths a run names, and the walk no longer names it. It is
|
|
53
|
+
// still visible through the survivors that imported it — those are stale anyway —
|
|
54
|
+
// and its own record is still in the index, which is what names the files IT
|
|
55
|
+
// pointed at: their answers ("who uses me") were decided by a file that no longer
|
|
56
|
+
// exists.
|
|
57
|
+
const fs = __importStar(require("node:fs"));
|
|
58
|
+
const path = __importStar(require("node:path"));
|
|
59
|
+
const fa_index_1 = require("./fa-index");
|
|
60
|
+
// Files read again in one run.
|
|
61
|
+
const MAX_ZONE = 200;
|
|
62
|
+
exports.MAX_ZONE = MAX_ZONE;
|
|
63
|
+
// A directory's own members are part of the zone, but a folder with more files
|
|
64
|
+
// than this is treated as "everything".
|
|
65
|
+
const MAX_FOLDER = 400;
|
|
66
|
+
exports.MAX_FOLDER = MAX_FOLDER;
|
|
67
|
+
// Importers of every file, from the summaries' dependency lists.
|
|
68
|
+
const importersOf = (light, relOf) => {
|
|
69
|
+
const out = new Map();
|
|
70
|
+
for (const [abs, entry] of light) {
|
|
71
|
+
const rel = relOf.get(abs);
|
|
72
|
+
if (rel === undefined)
|
|
73
|
+
continue;
|
|
74
|
+
for (const dep of entry.summary.deps) {
|
|
75
|
+
const list = out.get(dep) ?? [];
|
|
76
|
+
list.push(rel);
|
|
77
|
+
out.set(dep, list);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
};
|
|
82
|
+
exports.importersOf = importersOf;
|
|
83
|
+
const expand = (out, queue, rels) => {
|
|
84
|
+
for (const rel of rels) {
|
|
85
|
+
if (out.has(rel))
|
|
86
|
+
continue;
|
|
87
|
+
out.add(rel);
|
|
88
|
+
queue.push(rel);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
// The transitive closure of `seeds` over the given edge sets, stopping once the
|
|
92
|
+
// answer is already too large to be worth narrowing.
|
|
93
|
+
const closureOf = (seeds, edges, limit) => {
|
|
94
|
+
const out = new Set(seeds);
|
|
95
|
+
const queue = [...seeds];
|
|
96
|
+
for (let at = 0; at < queue.length && out.size <= limit; at += 1) {
|
|
97
|
+
for (const next of edges)
|
|
98
|
+
expand(out, queue, next(queue[at]));
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
};
|
|
102
|
+
exports.closureOf = closureOf;
|
|
103
|
+
// A folder's own members, or null when the folder is too large to treat as a zone.
|
|
104
|
+
const folderMates = (repoFiles, rels) => {
|
|
105
|
+
const dirs = new Set(rels.map((rel) => path.posix.dirname(rel)));
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const rel of repoFiles)
|
|
108
|
+
if (dirs.has(path.posix.dirname(rel)))
|
|
109
|
+
out.push(rel);
|
|
110
|
+
return out.length > MAX_FOLDER ? null : out;
|
|
111
|
+
};
|
|
112
|
+
// A dependency that is not part of the scan is not a lost dependency: an import of
|
|
113
|
+
// `react` resolves into `node_modules`, and a file the scope excluded (another
|
|
114
|
+
// extension, an ignored folder) is still on disk. Only a path that the scan would
|
|
115
|
+
// have covered AND that is no longer there means the file went away.
|
|
116
|
+
const EXISTS = new Map();
|
|
117
|
+
const isGone = (root, rel, known) => {
|
|
118
|
+
if (known.has(rel))
|
|
119
|
+
return false;
|
|
120
|
+
const cached = EXISTS.get(rel);
|
|
121
|
+
if (cached !== undefined)
|
|
122
|
+
return cached;
|
|
123
|
+
const exists = fs.existsSync(path.resolve(root, rel));
|
|
124
|
+
EXISTS.set(rel, exists);
|
|
125
|
+
return !exists;
|
|
126
|
+
};
|
|
127
|
+
// The files that changed since the last run: no summary, a summary this tool
|
|
128
|
+
// cannot use, or one that names a dependency that is gone.
|
|
129
|
+
const staleOf = (args) => {
|
|
130
|
+
const { light, absFiles, repoFiles, root } = args;
|
|
131
|
+
const known = new Set(repoFiles);
|
|
132
|
+
const out = [];
|
|
133
|
+
for (let at = 0; at < absFiles.length; at += 1) {
|
|
134
|
+
const entry = light.get(absFiles[at]);
|
|
135
|
+
const fresh = entry !== undefined && !entry.summary.deps.some((dep) => isGone(root, dep, known));
|
|
136
|
+
if (!fresh)
|
|
137
|
+
out.push(repoFiles[at]);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
};
|
|
141
|
+
// The files a gone file pointed at. `null` means the targets cannot be known (the
|
|
142
|
+
// index never held the gone file), and the caller then reads everything.
|
|
143
|
+
const lostTargets = (args) => {
|
|
144
|
+
const { index, light, repoFiles, root } = args;
|
|
145
|
+
const known = new Set(repoFiles);
|
|
146
|
+
const gone = new Set();
|
|
147
|
+
for (const entry of light.values()) {
|
|
148
|
+
for (const dep of entry.summary.deps)
|
|
149
|
+
if (isGone(root, dep, known))
|
|
150
|
+
gone.add(dep);
|
|
151
|
+
}
|
|
152
|
+
if (gone.size === 0)
|
|
153
|
+
return [];
|
|
154
|
+
const targets = [];
|
|
155
|
+
for (const rel of gone) {
|
|
156
|
+
const entry = (0, fa_index_1.lightAt)(index, path.resolve(root, rel));
|
|
157
|
+
if (entry === null)
|
|
158
|
+
return null;
|
|
159
|
+
targets.push(...entry.summary.deps);
|
|
160
|
+
}
|
|
161
|
+
return targets;
|
|
162
|
+
};
|
|
163
|
+
// A file the index has never seen brings facts nobody has read yet — and its
|
|
164
|
+
// imports are facts about OTHER files: an export it starts to use gains a
|
|
165
|
+
// reference, and a reference travels through barrels. So the added file's own
|
|
166
|
+
// dependencies join the zone, and so do theirs while new ones keep appearing.
|
|
167
|
+
// The reverse direction (a file that goes away) needs none of this: `zoneOf`
|
|
168
|
+
// already read the tombstone's deps.
|
|
169
|
+
const depsOfAdded = (added, depsOf, absOf, zone) => {
|
|
170
|
+
const extra = new Set();
|
|
171
|
+
for (const rel of added) {
|
|
172
|
+
for (const dep of depsOf(absOf.get(rel) ?? ""))
|
|
173
|
+
if (!zone.has(dep) && absOf.has(dep))
|
|
174
|
+
extra.add(dep);
|
|
175
|
+
}
|
|
176
|
+
return extra;
|
|
177
|
+
};
|
|
178
|
+
const extendZone = (args, extract) => {
|
|
179
|
+
const { zone, known, depsOf, absOf, repoFiles } = args;
|
|
180
|
+
let added = [...zone].filter((rel) => !known.has(absOf.get(rel) ?? ""));
|
|
181
|
+
let extracted = 0;
|
|
182
|
+
for (;;) {
|
|
183
|
+
const extra = depsOfAdded(added, depsOf, absOf, zone);
|
|
184
|
+
if (extra.size === 0)
|
|
185
|
+
return extracted;
|
|
186
|
+
if (zone.size + extra.size > MAX_ZONE) {
|
|
187
|
+
// The addition pulls in more than a neighbourhood: read everything.
|
|
188
|
+
for (const rel of repoFiles)
|
|
189
|
+
zone.add(rel);
|
|
190
|
+
return extracted + extract(zone);
|
|
191
|
+
}
|
|
192
|
+
for (const rel of extra)
|
|
193
|
+
zone.add(rel);
|
|
194
|
+
extracted += extract(extra);
|
|
195
|
+
added = [...extra];
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
exports.extendZone = extendZone;
|
|
199
|
+
// What must be read again, and how many files changed.
|
|
200
|
+
const zoneOf = (args) => {
|
|
201
|
+
const { index, light, absFiles, repoFiles, root } = args;
|
|
202
|
+
const stale = staleOf({ light, absFiles, repoFiles, root });
|
|
203
|
+
const absOf = new Map();
|
|
204
|
+
const relOf = new Map();
|
|
205
|
+
for (let at = 0; at < repoFiles.length; at += 1) {
|
|
206
|
+
absOf.set(repoFiles[at], absFiles[at]);
|
|
207
|
+
relOf.set(absFiles[at], repoFiles[at]);
|
|
208
|
+
}
|
|
209
|
+
const importers = importersOf(light, relOf);
|
|
210
|
+
const depsOfRel = (rel) => light.get(absOf.get(rel) ?? "")?.summary.deps ?? [];
|
|
211
|
+
const importersOfRel = (rel) => importers.get(rel) ?? [];
|
|
212
|
+
const lost = lostTargets({ index, light, repoFiles, root });
|
|
213
|
+
const seeds = lost === null ? [...repoFiles] : [...stale, ...lost];
|
|
214
|
+
const widened = closureOf(seeds, [depsOfRel, importersOfRel], MAX_ZONE);
|
|
215
|
+
const mates = folderMates(repoFiles, [...widened]);
|
|
216
|
+
const zone = mates === null ? new Set(repoFiles) : new Set([...widened, ...mates]);
|
|
217
|
+
return { zone, stale: stale.length };
|
|
218
|
+
};
|
|
219
|
+
exports.zoneOf = zoneOf;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { type Args } from "./args";
|
|
1
2
|
import type { Arch, RawArch } from "./entities/architecture";
|
|
2
3
|
import type { RuleOptions } from "./config-options";
|
|
3
|
-
type ArchSections = Pick<RawArch, "nodes" | "
|
|
4
|
+
type ArchSections = Pick<RawArch, "nodes" | "entities" | "rules" | "aliases" | "report">;
|
|
4
5
|
declare const buildArchitecture: (raw: ArchSections | null | undefined) => Arch;
|
|
5
6
|
declare const loadArchitecture: (config: string | RawArch | RuleOptions | null | undefined) => Arch;
|
|
7
|
+
declare const canonicalRoot: (dir: string) => string;
|
|
8
|
+
declare const repoOf: (args: Args, cwd: string) => string;
|
|
6
9
|
declare const main: (argv: string[]) => number;
|
|
7
|
-
export { main, loadArchitecture, buildArchitecture };
|
|
10
|
+
export { main, loadArchitecture, buildArchitecture, canonicalRoot, repoOf };
|