@md-code/follow-architecture 0.1.0 → 0.3.0
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 +16 -0
- package/LICENSE +202 -0
- package/README.md +597 -126
- package/dist/aliases.d.ts +3 -0
- package/dist/aliases.js +12 -0
- package/dist/args.d.ts +14 -0
- package/dist/args.js +77 -0
- package/dist/bin/follow-architecture.d.ts +2 -0
- package/dist/bin/follow-architecture.js +23 -0
- package/dist/code-roles/classify.d.ts +11 -0
- package/dist/code-roles/classify.js +43 -0
- package/dist/code-roles/connector.d.ts +5 -0
- package/dist/code-roles/connector.js +114 -0
- package/dist/code-roles/project.d.ts +12 -0
- package/dist/code-roles/project.js +122 -0
- package/dist/code-roles/roles.d.ts +8 -0
- package/dist/code-roles/roles.js +190 -0
- package/dist/config-options.d.ts +53 -0
- package/dist/config-options.js +35 -0
- package/dist/config-project.d.ts +4 -0
- package/dist/config-project.js +74 -0
- package/dist/config-report.d.ts +19 -0
- package/dist/config-report.js +134 -0
- package/dist/config-rule.d.ts +70 -0
- package/dist/config-rule.js +118 -0
- package/dist/config-state.d.ts +14 -0
- package/dist/config-state.js +96 -0
- package/dist/config.d.ts +82 -0
- package/dist/config.js +38 -0
- package/dist/css/index.d.ts +27 -0
- package/dist/css/index.js +140 -0
- package/dist/css/syntax/css/gate.d.ts +2 -0
- package/dist/css/syntax/css/gate.js +69 -0
- package/dist/css/syntax/css/index.d.ts +7 -0
- package/dist/css/syntax/css/index.js +41 -0
- package/dist/css/syntax/css/reference.d.ts +3 -0
- package/dist/css/syntax/css/reference.js +24 -0
- package/dist/css/syntax/language.d.ts +25 -0
- package/dist/css/syntax/language.js +69 -0
- package/dist/css/syntax/scss/index.d.ts +25 -0
- package/dist/css/syntax/scss/index.js +85 -0
- package/dist/css/syntax/scss/reference.d.ts +3 -0
- package/dist/css/syntax/scss/reference.js +11 -0
- package/dist/css/syntax/styled/document.d.ts +68 -0
- package/dist/css/syntax/styled/document.js +241 -0
- package/dist/css/syntax/styled/markup.d.ts +6 -0
- package/dist/css/syntax/styled/markup.js +76 -0
- package/dist/css/syntax/styled/template.d.ts +23 -0
- package/dist/css/syntax/styled/template.js +61 -0
- package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
- package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
- package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
- package/dist/css/syntax/tailwind/tailwind.js +118 -0
- package/dist/css/value/check.d.ts +86 -0
- package/dist/css/value/check.js +122 -0
- package/dist/css/value/expression/arithmetic.d.ts +7 -0
- package/dist/css/value/expression/arithmetic.js +69 -0
- package/dist/css/value/expression/block.d.ts +9 -0
- package/dist/css/value/expression/block.js +91 -0
- package/dist/css/value/expression/conditional.d.ts +8 -0
- package/dist/css/value/expression/conditional.js +53 -0
- package/dist/css/value/expression/index.d.ts +5 -0
- package/dist/css/value/expression/index.js +69 -0
- package/dist/css/value/expression/map.d.ts +7 -0
- package/dist/css/value/expression/map.js +113 -0
- package/dist/css/value/object/index.d.ts +5 -0
- package/dist/css/value/object/index.js +103 -0
- package/dist/css/value/object/members.d.ts +7 -0
- package/dist/css/value/object/members.js +103 -0
- package/dist/css/value/object/node.d.ts +8 -0
- package/dist/css/value/object/node.js +129 -0
- package/dist/css/value/object/path.d.ts +10 -0
- package/dist/css/value/object/path.js +146 -0
- package/dist/css/value/pieces.d.ts +61 -0
- package/dist/css/value/pieces.js +55 -0
- package/dist/css/value/resolve.d.ts +33 -0
- package/dist/css/value/resolve.js +94 -0
- package/dist/css/value/scope.d.ts +27 -0
- package/dist/css/value/scope.js +187 -0
- package/dist/css/value/substitute.d.ts +10 -0
- package/dist/css/value/substitute.js +113 -0
- package/dist/css/value/values.d.ts +23 -0
- package/dist/css/value/values.js +131 -0
- package/dist/entities/architecture.d.ts +162 -0
- package/dist/entities/architecture.js +2 -0
- package/dist/entities/ast/assignments-nodes.d.ts +10 -0
- package/dist/entities/ast/assignments-nodes.js +64 -0
- package/dist/entities/ast/assignments-raw.d.ts +6 -0
- package/dist/entities/ast/assignments-raw.js +86 -0
- package/dist/entities/ast/assignments-tagged.d.ts +5 -0
- package/dist/entities/ast/assignments-tagged.js +180 -0
- package/dist/entities/ast/assignments.d.ts +9 -0
- package/dist/entities/ast/assignments.js +78 -0
- package/dist/entities/ast/branches.d.ts +4 -0
- package/dist/entities/ast/branches.js +32 -0
- package/dist/entities/ast/calls.d.ts +6 -0
- package/dist/entities/ast/calls.js +134 -0
- package/dist/entities/ast/classes.d.ts +5 -0
- package/dist/entities/ast/classes.js +57 -0
- package/dist/entities/ast/climb.d.ts +12 -0
- package/dist/entities/ast/climb.js +17 -0
- package/dist/entities/ast/comments.d.ts +4 -0
- package/dist/entities/ast/comments.js +100 -0
- package/dist/entities/ast/declaration.d.ts +4 -0
- package/dist/entities/ast/declaration.js +26 -0
- package/dist/entities/ast/depth.d.ts +17 -0
- package/dist/entities/ast/depth.js +149 -0
- package/dist/entities/ast/enums.d.ts +6 -0
- package/dist/entities/ast/enums.js +17 -0
- package/dist/entities/ast/file-exports.d.ts +7 -0
- package/dist/entities/ast/file-exports.js +78 -0
- package/dist/entities/ast/file-facts.d.ts +13 -0
- package/dist/entities/ast/file-facts.js +35 -0
- package/dist/entities/ast/file-imports.d.ts +5 -0
- package/dist/entities/ast/file-imports.js +77 -0
- package/dist/entities/ast/file.d.ts +5 -0
- package/dist/entities/ast/file.js +22 -0
- package/dist/entities/ast/functions.d.ts +8 -0
- package/dist/entities/ast/functions.js +102 -0
- package/dist/entities/ast/heritage.d.ts +4 -0
- package/dist/entities/ast/heritage.js +36 -0
- package/dist/entities/ast/index.d.ts +6 -0
- package/dist/entities/ast/index.js +125 -0
- package/dist/entities/ast/kind.d.ts +5 -0
- package/dist/entities/ast/kind.js +28 -0
- package/dist/entities/ast/loose.d.ts +37 -0
- package/dist/entities/ast/loose.js +2 -0
- package/dist/entities/ast/modifiers.d.ts +5 -0
- package/dist/entities/ast/modifiers.js +32 -0
- package/dist/entities/ast/project.d.ts +9 -0
- package/dist/entities/ast/project.js +75 -0
- package/dist/entities/ast/properties.d.ts +11 -0
- package/dist/entities/ast/properties.js +171 -0
- package/dist/entities/ast/resolve.d.ts +16 -0
- package/dist/entities/ast/resolve.js +307 -0
- package/dist/entities/ast/tree.d.ts +29 -0
- package/dist/entities/ast/tree.js +351 -0
- package/dist/entities/ast/types.d.ts +6 -0
- package/dist/entities/ast/types.js +45 -0
- package/dist/entities/ast/usage.d.ts +11 -0
- package/dist/entities/ast/usage.js +81 -0
- package/dist/entities/ast/variables.d.ts +8 -0
- package/dist/entities/ast/variables.js +91 -0
- package/dist/entities/context.d.ts +29 -0
- package/dist/entities/context.js +2 -0
- package/dist/entities/facts.d.ts +261 -0
- package/dist/entities/facts.js +2 -0
- package/dist/entities/findings.d.ts +19 -0
- package/dist/entities/findings.js +2 -0
- package/dist/entities/kinds.d.ts +40 -0
- package/dist/entities/kinds.js +221 -0
- package/dist/entities/location/homes.d.ts +28 -0
- package/dist/entities/location/homes.js +169 -0
- package/dist/entities/location/place.d.ts +10 -0
- package/dist/entities/location/place.js +56 -0
- package/dist/entities/location/where.d.ts +17 -0
- package/dist/entities/location/where.js +218 -0
- package/dist/entities/location.d.ts +16 -0
- package/dist/entities/location.js +140 -0
- package/dist/entities/operators.d.ts +14 -0
- package/dist/entities/operators.js +30 -0
- package/dist/entities/overview/data.d.ts +43 -0
- package/dist/entities/overview/data.js +2 -0
- package/dist/entities/overview/decision.d.ts +60 -0
- package/dist/entities/overview/decision.js +2 -0
- package/dist/entities/overview/file-tree.d.ts +10 -0
- package/dist/entities/overview/file-tree.js +2 -0
- package/dist/entities/overview/finding.d.ts +58 -0
- package/dist/entities/overview/finding.js +2 -0
- package/dist/entities/overview/graph.d.ts +65 -0
- package/dist/entities/overview/graph.js +2 -0
- package/dist/entities/overview/input.d.ts +15 -0
- package/dist/entities/overview/input.js +2 -0
- package/dist/entities/overview/summaries.d.ts +79 -0
- package/dist/entities/overview/summaries.js +2 -0
- package/dist/entities/place.d.ts +5 -0
- package/dist/entities/place.js +2 -0
- package/dist/entities/queries.d.ts +9 -0
- package/dist/entities/queries.js +305 -0
- package/dist/entities/repair.d.ts +16 -0
- package/dist/entities/repair.js +23 -0
- package/dist/entities/schema.d.ts +8 -0
- package/dist/entities/schema.js +23 -0
- package/dist/entities/story.d.ts +47 -0
- package/dist/entities/story.js +2 -0
- package/dist/entities/structure-facts.d.ts +11 -0
- package/dist/entities/structure-facts.js +2 -0
- package/dist/entities/token.d.ts +23 -0
- package/dist/entities/token.js +2 -0
- package/dist/entities/tree/build.d.ts +5 -0
- package/dist/entities/tree/build.js +252 -0
- package/dist/entities/tree/entries.d.ts +7 -0
- package/dist/entities/tree/entries.js +120 -0
- package/dist/entities/tree/index.d.ts +6 -0
- package/dist/entities/tree/index.js +21 -0
- package/dist/entities/tree/match.d.ts +17 -0
- package/dist/entities/tree/match.js +176 -0
- package/dist/frameworks/angular/index.d.ts +7 -0
- package/dist/frameworks/angular/index.js +17 -0
- package/dist/frameworks/facet.d.ts +16 -0
- package/dist/frameworks/facet.js +2 -0
- package/dist/frameworks/index.d.ts +9 -0
- package/dist/frameworks/index.js +120 -0
- package/dist/frameworks/react/index.d.ts +7 -0
- package/dist/frameworks/react/index.js +214 -0
- package/dist/frameworks/vue/index.d.ts +7 -0
- package/dist/frameworks/vue/index.js +17 -0
- package/dist/invariants/index.d.ts +6 -0
- package/dist/invariants/index.js +299 -0
- package/dist/invariants/list-vars.d.ts +5 -0
- package/dist/invariants/list-vars.js +143 -0
- package/dist/invariants/name.d.ts +16 -0
- package/dist/invariants/name.js +18 -0
- package/dist/invariants/normalize.d.ts +4 -0
- package/dist/invariants/normalize.js +95 -0
- package/dist/invariants/vars.d.ts +20 -0
- package/dist/invariants/vars.js +117 -0
- package/dist/main.d.ts +7 -0
- package/dist/main.js +229 -0
- package/dist/nodes/child-roles.d.ts +3 -0
- package/dist/nodes/child-roles.js +12 -0
- package/dist/nodes/children.d.ts +25 -0
- package/dist/nodes/children.js +112 -0
- package/dist/nodes/finally/emit.d.ts +6 -0
- package/dist/nodes/finally/emit.js +55 -0
- package/dist/nodes/finally/index.d.ts +8 -0
- package/dist/nodes/finally/index.js +35 -0
- package/dist/nodes/finally/queries.d.ts +5 -0
- package/dist/nodes/finally/queries.js +22 -0
- package/dist/nodes/finally/relations-access.d.ts +5 -0
- package/dist/nodes/finally/relations-access.js +46 -0
- package/dist/nodes/finally/relations-edge.d.ts +29 -0
- package/dist/nodes/finally/relations-edge.js +125 -0
- package/dist/nodes/finally/relations-group.d.ts +31 -0
- package/dist/nodes/finally/relations-group.js +103 -0
- package/dist/nodes/finally/relations.d.ts +5 -0
- package/dist/nodes/finally/relations.js +81 -0
- package/dist/nodes/finally/required.d.ts +5 -0
- package/dist/nodes/finally/required.js +90 -0
- package/dist/nodes/finally/roles.d.ts +13 -0
- package/dist/nodes/finally/roles.js +41 -0
- package/dist/nodes/finally/violation.d.ts +17 -0
- package/dist/nodes/finally/violation.js +2 -0
- package/dist/nodes/similar.d.ts +21 -0
- package/dist/nodes/similar.js +156 -0
- package/dist/pipeline-facts.d.ts +11 -0
- package/dist/pipeline-facts.js +112 -0
- package/dist/pipeline-roles.d.ts +6 -0
- package/dist/pipeline-roles.js +75 -0
- package/dist/pipeline-unroled.d.ts +14 -0
- package/dist/pipeline-unroled.js +193 -0
- package/dist/pipeline.d.ts +7 -0
- package/dist/pipeline.js +73 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +3 -0
- package/dist/report/asks.d.ts +55 -0
- package/dist/report/asks.js +50 -0
- package/dist/report/cli-report.d.ts +2 -0
- package/dist/report/cli-report.js +13 -0
- package/dist/report/config-error-guard.d.ts +8 -0
- package/dist/report/config-error-guard.js +5 -0
- package/dist/report/configErrors.d.ts +98 -0
- package/dist/report/configErrors.js +75 -0
- package/dist/report/errorTypes/codes/structure.d.ts +15 -0
- package/dist/report/errorTypes/codes/structure.js +76 -0
- package/dist/report/errorTypes/decision-maker.d.ts +23 -0
- package/dist/report/errorTypes/decision-maker.js +99 -0
- package/dist/report/errorTypes/destinations.d.ts +38 -0
- package/dist/report/errorTypes/destinations.js +147 -0
- package/dist/report/errorTypes/finding-type.d.ts +11 -0
- package/dist/report/errorTypes/finding-type.js +2 -0
- package/dist/report/errorTypes/index.d.ts +15 -0
- package/dist/report/errorTypes/index.js +45 -0
- package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
- package/dist/report/errorTypes/types/fileContents.js +34 -0
- package/dist/report/errorTypes/types/unknownRole.d.ts +9 -0
- package/dist/report/errorTypes/types/unknownRole.js +22 -0
- package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
- package/dist/report/errorTypes/types/wrongAction.js +135 -0
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
- package/dist/report/errorTypes/types/wrongPlacement.js +57 -0
- package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
- package/dist/report/errorTypes/vocabulary/ids.js +16 -0
- package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
- package/dist/report/errorTypes/vocabulary/phrases.js +174 -0
- package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
- package/dist/report/errorTypes/vocabulary/places.js +36 -0
- package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
- package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
- package/dist/report/finding-from.d.ts +9 -0
- package/dist/report/finding-from.js +103 -0
- package/dist/report/notices.d.ts +4 -0
- package/dist/report/notices.js +31 -0
- package/dist/report/render-report.d.ts +12 -0
- package/dist/report/render-report.js +142 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +169 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +760 -0
- package/dist/report/user-report/data/collect.d.ts +4 -0
- package/dist/report/user-report/data/collect.js +80 -0
- package/dist/report/user-report/data/file-tree.d.ts +9 -0
- package/dist/report/user-report/data/file-tree.js +72 -0
- package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
- package/dist/report/user-report/data/finding-boundary.js +21 -0
- package/dist/report/user-report/data/finding-plan.d.ts +16 -0
- package/dist/report/user-report/data/finding-plan.js +45 -0
- package/dist/report/user-report/data/finding-title.d.ts +12 -0
- package/dist/report/user-report/data/finding-title.js +36 -0
- package/dist/report/user-report/data/findings.d.ts +10 -0
- package/dist/report/user-report/data/findings.js +171 -0
- package/dist/report/user-report/data/graph-edges.d.ts +19 -0
- package/dist/report/user-report/data/graph-edges.js +109 -0
- package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
- package/dist/report/user-report/data/graph-helpers.js +67 -0
- package/dist/report/user-report/data/graph-roles.d.ts +5 -0
- package/dist/report/user-report/data/graph-roles.js +71 -0
- package/dist/report/user-report/data/graph.d.ts +11 -0
- package/dist/report/user-report/data/graph.js +90 -0
- package/dist/report/user-report/data/invariants.d.ts +7 -0
- package/dist/report/user-report/data/invariants.js +62 -0
- package/dist/report/user-report/data/nodes.d.ts +11 -0
- package/dist/report/user-report/data/nodes.js +106 -0
- package/dist/report/user-report/data/role-examples.d.ts +16 -0
- package/dist/report/user-report/data/role-examples.js +94 -0
- package/dist/report/user-report/data/role-filters.d.ts +15 -0
- package/dist/report/user-report/data/role-filters.js +79 -0
- package/dist/report/user-report/data/role-marks.d.ts +5 -0
- package/dist/report/user-report/data/role-marks.js +79 -0
- package/dist/report/user-report/data/roles.d.ts +7 -0
- package/dist/report/user-report/data/roles.js +83 -0
- package/dist/report/user-report/data/scan.d.ts +8 -0
- package/dist/report/user-report/data/scan.js +59 -0
- package/dist/report/user-report/html/shell.d.ts +3 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +8 -0
- package/dist/report/user-report/index.js +48 -0
- package/dist/report/user-report/shared/describe.d.ts +7 -0
- package/dist/report/user-report/shared/describe.js +86 -0
- package/dist/scripts/audit-report.d.ts +2 -0
- package/dist/scripts/audit-report.js +147 -0
- package/dist/utils/accumulate.d.ts +6 -0
- package/dist/utils/accumulate.js +18 -0
- package/dist/utils/article.d.ts +2 -0
- package/dist/utils/article.js +12 -0
- package/dist/utils/classify.d.ts +12 -0
- package/dist/utils/classify.js +25 -0
- package/dist/utils/configs.d.ts +25 -0
- package/dist/utils/configs.js +87 -0
- package/dist/utils/count.d.ts +7 -0
- package/dist/utils/count.js +13 -0
- package/dist/utils/dispatch.d.ts +2 -0
- package/dist/utils/dispatch.js +27 -0
- package/dist/utils/distinct.d.ts +2 -0
- package/dist/utils/distinct.js +12 -0
- package/dist/utils/field.d.ts +14 -0
- package/dist/utils/field.js +60 -0
- package/dist/utils/file-name.d.ts +2 -0
- package/dist/utils/file-name.js +11 -0
- package/dist/utils/files.d.ts +7 -0
- package/dist/utils/files.js +73 -0
- package/dist/utils/fixpoint.d.ts +2 -0
- package/dist/utils/fixpoint.js +19 -0
- package/dist/utils/gate.d.ts +2 -0
- package/dist/utils/gate.js +12 -0
- package/dist/utils/group.d.ts +3 -0
- package/dist/utils/group.js +33 -0
- package/dist/utils/host.d.ts +3 -0
- package/dist/utils/host.js +13 -0
- package/dist/utils/imports.d.ts +12 -0
- package/dist/utils/imports.js +121 -0
- package/dist/utils/judged.d.ts +5 -0
- package/dist/utils/judged.js +19 -0
- package/dist/utils/keyed.d.ts +2 -0
- package/dist/utils/keyed.js +23 -0
- package/dist/utils/map-record.d.ts +2 -0
- package/dist/utils/map-record.js +11 -0
- package/dist/utils/path-label.d.ts +6 -0
- package/dist/utils/path-label.js +35 -0
- package/dist/utils/pattern.d.ts +18 -0
- package/dist/utils/pattern.js +191 -0
- package/dist/utils/permission.d.ts +16 -0
- package/dist/utils/permission.js +16 -0
- package/dist/utils/plural.d.ts +2 -0
- package/dist/utils/plural.js +9 -0
- package/dist/utils/qualified.d.ts +2 -0
- package/dist/utils/qualified.js +21 -0
- package/dist/utils/rank.d.ts +2 -0
- package/dist/utils/rank.js +24 -0
- package/dist/utils/read-field.d.ts +12 -0
- package/dist/utils/read-field.js +50 -0
- package/dist/utils/read-when.d.ts +2 -0
- package/dist/utils/read-when.js +17 -0
- package/dist/utils/reason.d.ts +4 -0
- package/dist/utils/reason.js +9 -0
- package/dist/utils/record.d.ts +3 -0
- package/dist/utils/record.js +21 -0
- package/dist/utils/resolve.d.ts +2 -0
- package/dist/utils/resolve.js +24 -0
- package/dist/utils/search.d.ts +2 -0
- package/dist/utils/search.js +16 -0
- package/dist/utils/seen.d.ts +6 -0
- package/dist/utils/seen.js +27 -0
- package/dist/utils/span.d.ts +5 -0
- package/dist/utils/span.js +2 -0
- package/dist/utils/speak.d.ts +2 -0
- package/dist/utils/speak.js +18 -0
- package/dist/utils/split.d.ts +8 -0
- package/dist/utils/split.js +8 -0
- package/dist/utils/template.d.ts +5 -0
- package/dist/utils/template.js +5 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.js +42 -0
- package/dist/utils/tokenize.d.ts +2 -0
- package/dist/utils/tokenize.js +13 -0
- package/dist/utils/try-read.d.ts +4 -0
- package/dist/utils/try-read.js +24 -0
- package/dist/utils/typed-field.d.ts +3 -0
- package/dist/utils/typed-field.js +16 -0
- package/dist/utils/verdicts.d.ts +4 -0
- package/dist/utils/verdicts.js +20 -0
- package/entities/operators.ts +31 -0
- package/package.json +62 -19
- package/report/errorTypes/vocabulary/ids.ts +12 -0
- package/report/errorTypes/vocabulary/phrases.ts +161 -0
- package/report/errorTypes/vocabulary/places.ts +46 -0
- package/report/errorTypes/vocabulary/verbs.ts +31 -0
- package/report/user-report/shared/describe.ts +107 -0
- package/ast.js +0 -107
- package/bin/follow-architecture.js +0 -6
- package/config.js +0 -82
- package/entities/aliases.js +0 -10
- package/entities/invariants.js +0 -134
- package/entities/nodes.js +0 -112
- package/main.js +0 -95
- package/report.js +0 -73
- package/utils.js +0 -104
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Turn a nested architecture query (`infer` blocks, invariant conditions, `when`
|
|
4
|
+
// blocks) into short, readable lines: `subscriptions.length > 0`,
|
|
5
|
+
// `descendants[*].kind = ClassDeclaration`. ONE walk, shared by the Node-side
|
|
6
|
+
// summarizer (`data/invariants`) and the browser describer
|
|
7
|
+
// (`src/utils/describe`), which used to carry the same algorithm twice and
|
|
8
|
+
// could drift.
|
|
9
|
+
//
|
|
10
|
+
// The two callers differ in PRESENTATION only, so that is what the options
|
|
11
|
+
// carry — never a second copy of the walk:
|
|
12
|
+
// ignore keys that are prose, not part of the condition (report/message/…)
|
|
13
|
+
// setValue the text an `is set` operator prints; `undefined` keeps the value
|
|
14
|
+
// the query carries (the browser reader), `""` blanks it (Node side)
|
|
15
|
+
|
|
16
|
+
import { CONTAINERS, QUANTIFIERS, SCALAR_OPS } from "../../../entities/operators";
|
|
17
|
+
import { isObj, isList, type FieldValue } from "../../../utils/field";
|
|
18
|
+
import { dispatchOn } from "../../../utils/dispatch";
|
|
19
|
+
|
|
20
|
+
// One condition line: a path, an operator, and the value it demands.
|
|
21
|
+
type Condition = { path: string; op: string; value: string };
|
|
22
|
+
|
|
23
|
+
const fmt = (v: FieldValue): string => (typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? String(v) : JSON.stringify(v));
|
|
24
|
+
|
|
25
|
+
// The presentation options: which keys are prose, and what `is set` prints.
|
|
26
|
+
type DescribeOptions = { ignore?: readonly string[]; setValue?: string };
|
|
27
|
+
|
|
28
|
+
// The walk state, threaded through the recursion (one options bag, not five
|
|
29
|
+
// positional parameters).
|
|
30
|
+
type Walk = { trail: string[]; out: Condition[]; ignore: Set<string>; setValue: string | undefined };
|
|
31
|
+
|
|
32
|
+
const scalarValue = (op: string, child: FieldValue, setValue: string | undefined): string =>
|
|
33
|
+
op === "is set" && setValue !== undefined ? setValue : fmt(child);
|
|
34
|
+
|
|
35
|
+
// `at` picks ONE element: it reads as `segments[-2]`, not as a field called
|
|
36
|
+
// `at` with children — the index belongs to the path.
|
|
37
|
+
const walkAt = (child: FieldValue, trail: string[], state: Walk): void => {
|
|
38
|
+
const src = isObj(child) ? child : { index: child };
|
|
39
|
+
const index = src.index;
|
|
40
|
+
const by = { ...src };
|
|
41
|
+
delete by.index;
|
|
42
|
+
const path = `${trail.join(".")}[${fmt(index)}]`;
|
|
43
|
+
if (!Object.keys(by).length) state.out.push({ path, op: "is set", value: "" });
|
|
44
|
+
else walk(by, [path], state);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The scalar operator a key names, if it is one (the table is the engine's own).
|
|
48
|
+
const scalarOpOf = (key: string): string | undefined => Object.entries(SCALAR_OPS).find(([k]) => k === key)?.[1];
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const walkEntry = (key: string, child: FieldValue, state: Walk): void => {
|
|
52
|
+
if (state.ignore.has(key)) return;
|
|
53
|
+
if (key === "at") {
|
|
54
|
+
walkAt(child, state.trail, state);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (QUANTIFIERS.has(key)) {
|
|
58
|
+
walk(child, [...state.trail, "[*]"], state);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (CONTAINERS.has(key)) {
|
|
62
|
+
walk(child, [...state.trail, key], state);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const op = scalarOpOf(key);
|
|
66
|
+
if (op) {
|
|
67
|
+
state.out.push({ path: state.trail.join(".") || key, op, value: scalarValue(op, child, state.setValue) });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
walk(child, [...state.trail, key], state);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const walkRecord = (value: FieldValue, trail: string[], state: Walk): void => {
|
|
74
|
+
if (!isObj(value)) return;
|
|
75
|
+
for (const [key, child] of Object.entries(value)) walkEntry(key, child, { ...state, trail });
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const walkLeaf = (value: FieldValue, trail: string[], state: Walk): void => {
|
|
79
|
+
state.out.push({ path: trail.join("."), op: "=", value: fmt(value) });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// A record walks its entries; anything else is one leaf condition. The dispatch
|
|
83
|
+
// is the shared `dispatchOn` core; the readers are this module's own.
|
|
84
|
+
const walk = (value: FieldValue, trail: string[], state: Walk): void => {
|
|
85
|
+
if (value == null) return;
|
|
86
|
+
dispatchOn(
|
|
87
|
+
value,
|
|
88
|
+
(v) => (isObj(v) && !isList(v) ? "record" : "leaf"),
|
|
89
|
+
new Map<string, (v: FieldValue) => void>([
|
|
90
|
+
["record", (v) => walkRecord(v, trail, state)],
|
|
91
|
+
["leaf", (v) => walkLeaf(v, trail, state)],
|
|
92
|
+
]),
|
|
93
|
+
() => undefined,
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// The condition lines for one query. `ignore` is a list of keys to skip;
|
|
98
|
+
// `setValue` overrides the text an `is set` operator prints (see the header).
|
|
99
|
+
const describeQuery = (query: FieldValue, opts: DescribeOptions = {}): string[] => {
|
|
100
|
+
const out: Condition[] = [];
|
|
101
|
+
walk(query, [], { trail: [], out, ignore: new Set(opts.ignore ?? []), setValue: opts.setValue });
|
|
102
|
+
// `descendants[*].kind = X` reads better than `.some` colliding mid-path;
|
|
103
|
+
// `[*]` and `[n]` belong to the segment, so the dot before them goes.
|
|
104
|
+
return out.map((c) => `${c.path.replace(/\.\[/g, "[")} ${c.op} ${c.value}`.trim());
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { describeQuery };
|
package/ast.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const { Project, ts } = require("ts-morph");
|
|
6
|
-
const { pipe, filter, map } = require("remeda");
|
|
7
|
-
|
|
8
|
-
const norm = (p) => String(p).replace(/\\/g, "/");
|
|
9
|
-
|
|
10
|
-
const toRel = (repoRoot, filePath) => norm(path.relative(repoRoot, filePath));
|
|
11
|
-
|
|
12
|
-
const createTsProject = () =>
|
|
13
|
-
new Project({
|
|
14
|
-
useInMemoryFileSystem: true,
|
|
15
|
-
skipAddingFilesFromTsConfig: true,
|
|
16
|
-
compilerOptions: {
|
|
17
|
-
allowJs: true,
|
|
18
|
-
jsx: ts.JsxEmit.Preserve,
|
|
19
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
20
|
-
module: ts.ModuleKind.ESNext,
|
|
21
|
-
target: ts.ScriptTarget.ESNext,
|
|
22
|
-
esModuleInterop: true,
|
|
23
|
-
skipLibCheck: true,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const importEntry = (imp) => {
|
|
28
|
-
const source = imp.getModuleSpecifierValue();
|
|
29
|
-
const entry = { source, named: [], defaultName: null, namespaceName: null, typeOnly: imp.isTypeOnly() };
|
|
30
|
-
for (const el of imp.getNamedImports()) entry.named.push(el.getName());
|
|
31
|
-
const def = imp.getDefaultImport();
|
|
32
|
-
if (def) entry.defaultName = def.getText();
|
|
33
|
-
const ns = imp.getNamespaceImport();
|
|
34
|
-
if (ns) entry.namespaceName = ns.getText();
|
|
35
|
-
return entry;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const resolveImport = (sf, source, repoRoot, aliases) => {
|
|
39
|
-
const tryFile = (rel) => {
|
|
40
|
-
if (!rel) return null;
|
|
41
|
-
const abs = path.resolve(repoRoot, rel);
|
|
42
|
-
if (fs.existsSync(abs) && fs.statSync(abs).isFile()) return rel;
|
|
43
|
-
return null;
|
|
44
|
-
};
|
|
45
|
-
const candidates = (rel) => [rel, `${rel}.ts`, `${rel}.tsx`, `${rel}.js`, `${rel}.jsx`, `${rel}/index.ts`, `${rel}/index.tsx`, `${rel}/index.js`];
|
|
46
|
-
const resolveBase = (base) => pipe(candidates(base), map(tryFile), filter(Boolean), (r) => (r.length ? r[0] : null));
|
|
47
|
-
const alias = Object.keys(aliases).find((a) => source === a || source.startsWith(`${a}/`));
|
|
48
|
-
if (alias) return resolveBase(`${aliases[alias]}/${source.slice(alias.length).replace(/^\//, "")}`);
|
|
49
|
-
return resolveBase(toRel(repoRoot, path.resolve(path.dirname(sf.getFilePath()), source)));
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const sliceOf = (relPath) => {
|
|
53
|
-
const m = relPath.replace(/\\/g, "/").match(/\/([^/]+)\.v(\/|$)/);
|
|
54
|
-
return m ? m[1] : null;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const enclosingFunctionName = (sf, line) => {
|
|
58
|
-
let node = sf;
|
|
59
|
-
try {
|
|
60
|
-
const pos = sf.getPositionAtLineAndCharacter(line, 0);
|
|
61
|
-
node = sf.getDescendantAtPosition(pos, (n) => n.getStart() <= pos && n.getEnd() >= pos);
|
|
62
|
-
} catch {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
let cur = node;
|
|
66
|
-
while (cur) {
|
|
67
|
-
if (cur.isFunctionDeclaration() && cur.getName()) return cur.getName();
|
|
68
|
-
if (cur.isMethodDeclaration()) {
|
|
69
|
-
const n = cur.getName();
|
|
70
|
-
if (n) return n;
|
|
71
|
-
}
|
|
72
|
-
if (cur.isFunctionExpression() || cur.isArrowFunction()) {
|
|
73
|
-
const p = cur.getParent();
|
|
74
|
-
if (p && (p.isVariableDeclaration() || p.isPropertyAssignment() || p.isPropertyDeclaration() || p.isMethodDeclaration())) {
|
|
75
|
-
const n = p.getName();
|
|
76
|
-
if (n) return n;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
cur = cur.getParent();
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const buildContext = (project, filePath, text, repoRoot, aliases, siblings = []) => {
|
|
85
|
-
const sf = project.createSourceFile(filePath, text, { overwrite: true });
|
|
86
|
-
const relPath = toRel(repoRoot, filePath);
|
|
87
|
-
const imports = pipe(
|
|
88
|
-
sf.getImportDeclarations(),
|
|
89
|
-
map((imp) => {
|
|
90
|
-
const entry = importEntry(imp);
|
|
91
|
-
return { ...entry, resolved: resolveImport(sf, entry.source, repoRoot, aliases) };
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
return {
|
|
95
|
-
file: sf,
|
|
96
|
-
path: relPath,
|
|
97
|
-
basename: path.posix.basename(relPath),
|
|
98
|
-
dir: path.posix.dirname(relPath),
|
|
99
|
-
captures: {},
|
|
100
|
-
imports,
|
|
101
|
-
slice: sliceOf(relPath),
|
|
102
|
-
siblings,
|
|
103
|
-
enclosingFunctionName: (line) => enclosingFunctionName(sf, line),
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
module.exports = { createTsProject, buildContext, toRel };
|
package/config.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const { buildArchitecture } = require("./main");
|
|
6
|
-
const { checkFile } = require("./utils");
|
|
7
|
-
const { createTsProject } = require("./ast");
|
|
8
|
-
const pkg = require("./package.json");
|
|
9
|
-
|
|
10
|
-
const findRepoRoot = (from) => {
|
|
11
|
-
let dir = from;
|
|
12
|
-
while (true) {
|
|
13
|
-
for (const name of ["architecture.json", "architecture.config.js"]) {
|
|
14
|
-
if (fs.existsSync(path.join(dir, name))) return dir;
|
|
15
|
-
}
|
|
16
|
-
const parent = path.dirname(dir);
|
|
17
|
-
if (parent === dir) return from;
|
|
18
|
-
dir = parent;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const rule = {
|
|
23
|
-
meta: {
|
|
24
|
-
type: "problem",
|
|
25
|
-
docs: { description: "Enforces the vertical-slice architecture defined in architecture.json" },
|
|
26
|
-
schema: [{ type: "object" }],
|
|
27
|
-
},
|
|
28
|
-
create(context) {
|
|
29
|
-
const arch = buildArchitecture(context.options[0] ?? {});
|
|
30
|
-
const filePath = context.filename ?? context.getFilename();
|
|
31
|
-
const repoRoot = findRepoRoot(path.dirname(filePath));
|
|
32
|
-
const project = createTsProject();
|
|
33
|
-
const findings = checkFile(filePath, fs.readFileSync(filePath, "utf8"), repoRoot, arch, project);
|
|
34
|
-
for (const f of findings) {
|
|
35
|
-
context.report({
|
|
36
|
-
message: f.message,
|
|
37
|
-
loc: { start: { line: f.pos.line, column: f.pos.column - 1 }, end: { line: f.pos.line, column: f.pos.column } },
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return {};
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const plugin = {
|
|
45
|
-
meta: { name: pkg.name, version: pkg.version },
|
|
46
|
-
rules: { "follow-architecture": rule },
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const flatConfig = (architecture, opts = {}) => {
|
|
50
|
-
const { parser, files, ignores, plugins } = opts;
|
|
51
|
-
const list = [];
|
|
52
|
-
if (ignores?.length) list.push({ ignores });
|
|
53
|
-
list.push({
|
|
54
|
-
files: files ?? architecture.files,
|
|
55
|
-
languageOptions: {
|
|
56
|
-
parser: parser ?? require("@typescript-eslint/parser"),
|
|
57
|
-
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
|
|
58
|
-
},
|
|
59
|
-
linterOptions: { reportUnusedDisableDirectives: "off" },
|
|
60
|
-
plugins: plugins ?? { "md-code": plugin },
|
|
61
|
-
rules: { "md-code/follow-architecture": ["error", architecture.raw ?? architecture] },
|
|
62
|
-
});
|
|
63
|
-
return list;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const parseArgs = (argv) => {
|
|
67
|
-
const args = { config: null, ignore: [], out: null, check: false, help: false, cwd: null };
|
|
68
|
-
const rest = [];
|
|
69
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
70
|
-
const a = argv[i];
|
|
71
|
-
if (a === "--config" || a === "-c") args.config = argv[++i];
|
|
72
|
-
else if (a === "--ignore") args.ignore.push(argv[++i]);
|
|
73
|
-
else if (a === "--out" || a === "-o") args.out = argv[++i];
|
|
74
|
-
else if (a === "--check") args.check = true;
|
|
75
|
-
else if (a === "--help" || a === "-h") args.help = true;
|
|
76
|
-
else rest.push(a);
|
|
77
|
-
}
|
|
78
|
-
if (rest.length) args.cwd = rest[0];
|
|
79
|
-
return args;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
module.exports = { flatConfig, parseArgs, plugin };
|
package/entities/aliases.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { pipe, map, entries } = require("remeda");
|
|
4
|
-
|
|
5
|
-
const normalizeAliases = (raw) => {
|
|
6
|
-
const entriesRaw = raw && typeof raw === "object" ? raw : {};
|
|
7
|
-
return pipe(entries(entriesRaw), map(([k, v]) => [String(k), String(v).replace(/\\/g, "/").replace(/\/+$/, "")]));
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
module.exports = { normalizeAliases };
|
package/entities/invariants.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { pipe, map, filter, unique } = require("remeda");
|
|
4
|
-
const { minimatch } = require("minimatch");
|
|
5
|
-
const { asReport, compilePattern, compileWhen, checkRegex } = require("../utils");
|
|
6
|
-
|
|
7
|
-
const FORBID_TYPES = ["fileContent", "imports", "syntax"];
|
|
8
|
-
|
|
9
|
-
const normalizeInvariant = (i, slugs) => {
|
|
10
|
-
if (!i || typeof i !== "object") throw new Error("architecture.invariants: entry is not an object");
|
|
11
|
-
if (!i.id) throw new Error("architecture.invariants: entry without id");
|
|
12
|
-
if (i.node && i.node !== "*" && !slugs.includes(i.node)) throw new Error(`invariant ${i.id}: unknown node \`${i.node}\``);
|
|
13
|
-
const contentSpec = (p) => {
|
|
14
|
-
checkRegex(p.pattern, `invariant ${i.id}: forbid`);
|
|
15
|
-
return { type: "fileContent", key: p.key ?? null, pattern: p.pattern, except: p.except ?? [], report: asReport(p.report) };
|
|
16
|
-
};
|
|
17
|
-
const syntaxSpec = (p) => {
|
|
18
|
-
if (!p.kind) throw new Error(`invariant ${i.id}: forbid syntax entry requires \`kind\``);
|
|
19
|
-
if (p.pattern != null) checkRegex(p.pattern, `invariant ${i.id}: forbid syntax`);
|
|
20
|
-
return { type: "syntax", key: p.key ?? null, kind: p.kind, pattern: p.pattern ?? null, except: p.except ?? [], report: asReport(p.report) };
|
|
21
|
-
};
|
|
22
|
-
const importsSpec = (p) => {
|
|
23
|
-
const { re, names } = compilePattern(p.pattern);
|
|
24
|
-
return { type: "imports", key: p.key ?? null, pattern: p.pattern, re, names, except: p.except ?? [], report: asReport(p.report) };
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
id: i.id,
|
|
28
|
-
key: i.key ?? null,
|
|
29
|
-
node: i.node ?? "*",
|
|
30
|
-
where: i.where == null ? null : (() => {
|
|
31
|
-
const { re, names } = compilePattern(i.where);
|
|
32
|
-
return { re, names, pattern: i.where };
|
|
33
|
-
})(),
|
|
34
|
-
when: compileWhen(i.when),
|
|
35
|
-
except: i.except ?? [],
|
|
36
|
-
report: asReport(i.report),
|
|
37
|
-
forbid: [
|
|
38
|
-
...pipe(i.forbid ?? [], map((f) => {
|
|
39
|
-
const type = f.type ?? "fileContent";
|
|
40
|
-
if (!FORBID_TYPES.includes(type)) throw new Error(`invariant ${i.id}: forbid entry has unknown type \`${type}\` (expected ${FORBID_TYPES.join(" | ")})`);
|
|
41
|
-
return type === "imports" ? importsSpec(f) : type === "syntax" ? syntaxSpec(f) : contentSpec(f);
|
|
42
|
-
})),
|
|
43
|
-
...pipe(i.must ?? [], map(importsSpec)),
|
|
44
|
-
],
|
|
45
|
-
children: pipe(i.children ?? [], map((c) => normalizeInvariant(c, slugs))),
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const matchNode = (inv, ctx) => inv.node === "*" || !!ctx.captures[inv.node];
|
|
50
|
-
|
|
51
|
-
const matchWhere = (inv, ctx) => !inv.where || inv.where.re.test(ctx.path);
|
|
52
|
-
|
|
53
|
-
const fileVars = (ctx) => ({ slice: ctx.slice, path: ctx.path, dir: ctx.dir, basename: ctx.basename, ...ctx.captures });
|
|
54
|
-
|
|
55
|
-
const runWhen = (inv, ctx, baseCaps, out, findingFrom) => {
|
|
56
|
-
if (!inv.when) return true;
|
|
57
|
-
const res = inv.when(ctx);
|
|
58
|
-
if (res == null || res === false) return false;
|
|
59
|
-
if (res === true) return true;
|
|
60
|
-
if (Array.isArray(res)) {
|
|
61
|
-
for (const f of res) out.push(findingFrom(f, inv.key ?? inv.id, inv.node, `when:${inv.id}`, { ...baseCaps }));
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
out.push(findingFrom(res, inv.key ?? inv.id, inv.node, `when:${inv.id}`, { ...baseCaps }));
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const checkForbidImports = (f, ctx, baseCaps, inv, out, findingFrom) => {
|
|
69
|
-
const hits = pipe(ctx.imports, filter((imp) => {
|
|
70
|
-
const target = imp.resolved ?? imp.source;
|
|
71
|
-
return target != null && f.re.test(target);
|
|
72
|
-
}), map((imp) => ({ imp, caps: f.re.exec(imp.resolved ?? imp.source) })));
|
|
73
|
-
for (const { imp, caps } of hits) {
|
|
74
|
-
out.push(findingFrom({ key: f.key ?? "forbid", message: `import \`${imp.source}\` is not allowed here`, fix: null, pattern: imp.source, report: f.report }, inv.key ?? inv.id, inv.node, `forbid:${inv.id}`, { ...baseCaps, ...Object.fromEntries((caps ?? []).map((v, idx) => [idx, v])) }));
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const checkForbidContent = (f, ctx, baseCaps, inv, out, findingFrom) => {
|
|
79
|
-
const lines = ctx.file.getFullText().split("\n");
|
|
80
|
-
const hits = [];
|
|
81
|
-
lines.forEach((line, i) => {
|
|
82
|
-
const m = new RegExp(f.pattern).exec(line);
|
|
83
|
-
if (m) hits.push({ line: i + 1, snippet: line.trim(), match: m[0] });
|
|
84
|
-
});
|
|
85
|
-
for (const h of hits) {
|
|
86
|
-
const where = ctx.enclosingFunctionName(h.line) ? ` in \`${ctx.enclosingFunctionName(h.line)}\`` : "";
|
|
87
|
-
const vars = { ...baseCaps, line: h.line, lines: pipe(hits, map((x) => String(x.line)), unique(), (ls) => ls.join(", ")), count: hits.length, plural: hits.length > 1 ? "s" : "", snippet: h.snippet, match: h.match, where };
|
|
88
|
-
out.push(findingFrom({ key: f.key ?? "forbid", ...vars, report: f.report }, inv.key ?? inv.id, inv.node, `forbid:${inv.id}`, vars));
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const checkForbidSyntax = (f, ctx, baseCaps, inv, out, findingFrom) => {
|
|
93
|
-
const re = f.pattern == null ? null : new RegExp(f.pattern);
|
|
94
|
-
const hits = [];
|
|
95
|
-
const visit = (node) => {
|
|
96
|
-
if (node.getKindName() === f.kind) {
|
|
97
|
-
const text = node.getText();
|
|
98
|
-
const m = re == null ? text : re.exec(text);
|
|
99
|
-
if (m) {
|
|
100
|
-
const line = node.getStartLineNumber();
|
|
101
|
-
hits.push({ line, snippet: text.split("\n")[0].trim().slice(0, 120), match: m[0] });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
node.forEachChild(visit);
|
|
105
|
-
};
|
|
106
|
-
visit(ctx.file);
|
|
107
|
-
for (const h of hits) {
|
|
108
|
-
const where = ctx.enclosingFunctionName(h.line) ? ` in \`${ctx.enclosingFunctionName(h.line)}\`` : "";
|
|
109
|
-
const vars = { ...baseCaps, line: h.line, lines: pipe(hits, map((x) => String(x.line)), unique(), (ls) => ls.join(", ")), count: hits.length, plural: hits.length > 1 ? "s" : "", snippet: h.snippet, match: h.match, where };
|
|
110
|
-
out.push(findingFrom({ key: f.key ?? "forbid", ...vars, report: f.report }, inv.key ?? inv.id, inv.node, `forbid:${inv.id}`, vars));
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const checkForbid = (inv, ctx, baseCaps, out, findingFrom) => {
|
|
115
|
-
for (const f of inv.forbid) {
|
|
116
|
-
if (f.except.some((g) => minimatch(ctx.path, g))) continue;
|
|
117
|
-
if (f.type === "imports") checkForbidImports(f, ctx, baseCaps, inv, out, findingFrom);
|
|
118
|
-
else if (f.type === "syntax") checkForbidSyntax(f, ctx, baseCaps, inv, out, findingFrom);
|
|
119
|
-
else checkForbidContent(f, ctx, baseCaps, inv, out, findingFrom);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const checkInvariant = (inv, ctx, caps, out, findingFrom) => {
|
|
124
|
-
if (inv.except.some((g) => minimatch(ctx.path, g))) return;
|
|
125
|
-
if (!matchNode(inv, ctx)) return;
|
|
126
|
-
if (!matchWhere(inv, ctx)) return;
|
|
127
|
-
const baseCaps = { ...caps, ...fileVars(ctx) };
|
|
128
|
-
if (inv.report) out.push(findingFrom({ key: null, report: inv.report }, inv.key ?? inv.id, inv.node, `root:${inv.id}`, baseCaps));
|
|
129
|
-
const gated = runWhen(inv, ctx, baseCaps, out, findingFrom);
|
|
130
|
-
if (gated) checkForbid(inv, ctx, baseCaps, out, findingFrom);
|
|
131
|
-
for (const child of inv.children) checkInvariant(child, ctx, { ...caps, ...baseCaps }, out, findingFrom);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
module.exports = { normalizeInvariant, checkInvariant };
|
package/entities/nodes.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { pipe, map, filter, sort, flatMap, unique } = require("remeda");
|
|
4
|
-
const { asReport, nodePrefixRe, compileChild } = require("../utils");
|
|
5
|
-
|
|
6
|
-
const isFolderName = (name) => !/[^/]+\.[A-Za-z0-9]+$/.test(String(name).split("/").pop());
|
|
7
|
-
|
|
8
|
-
const normalizeChild = (c) => {
|
|
9
|
-
if (typeof c === "string") {
|
|
10
|
-
const { re, captures } = compileChild(c);
|
|
11
|
-
return { name: c, re, captures, folder: isFolderName(c), forbidden: false, report: null, description: null };
|
|
12
|
-
}
|
|
13
|
-
const { re, captures } = compileChild(c.name);
|
|
14
|
-
return { name: c.name, re, captures, folder: isFolderName(c.name), forbidden: !!c.forbidden, report: asReport(c.report), description: c.description == null ? null : String(c.description) };
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const buildTree = (rawNodes) => {
|
|
18
|
-
const list = Array.isArray(rawNodes) ? rawNodes : Object.values(rawNodes);
|
|
19
|
-
const bySlugRaw = Object.fromEntries(list.map((n) => [n.slug, n]));
|
|
20
|
-
const slugs = Object.keys(bySlugRaw);
|
|
21
|
-
if (new Set(slugs).size !== slugs.length) throw new Error("duplicate node slug in architecture.nodes");
|
|
22
|
-
const computePath = (slug, depth = 0) => {
|
|
23
|
-
const n = bySlugRaw[slug];
|
|
24
|
-
if (!n) throw new Error(`node ${slug}: unknown parent`);
|
|
25
|
-
if (depth > 10) throw new Error(`node ${slug}: parent chain too deep (cycle?)`);
|
|
26
|
-
if (!n.parent) return n.name;
|
|
27
|
-
const parent = computePath(n.parent, depth + 1);
|
|
28
|
-
return `${parent}/${n.name}`;
|
|
29
|
-
};
|
|
30
|
-
const make = (slug) => {
|
|
31
|
-
const n = bySlugRaw[slug];
|
|
32
|
-
const path = computePath(slug);
|
|
33
|
-
const { re, names } = nodePrefixRe(path);
|
|
34
|
-
return {
|
|
35
|
-
slug,
|
|
36
|
-
name: n.name,
|
|
37
|
-
parent: n.parent ?? null,
|
|
38
|
-
path,
|
|
39
|
-
prefixRe: re,
|
|
40
|
-
prefixNames: names,
|
|
41
|
-
closed: !!n.closed,
|
|
42
|
-
description: n.description == null ? null : String(n.description),
|
|
43
|
-
report: asReport(n.report),
|
|
44
|
-
children: pipe(n.children ?? [], map((c) => normalizeChild(c))),
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
const all = pipe(slugs, map(make));
|
|
48
|
-
const bySlug = Object.fromEntries(all.map((n) => [n.slug, n]));
|
|
49
|
-
for (const n of all) {
|
|
50
|
-
if (n.parent && !bySlug[n.parent]) throw new Error(`node ${n.slug}: unknown parent \`${n.parent}\``);
|
|
51
|
-
}
|
|
52
|
-
const roots = all.filter((n) => !n.parent);
|
|
53
|
-
return { roots, all, bySlug, slugs };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const matchNode = (relPath, node) => {
|
|
57
|
-
const m = node.prefixRe.exec(relPath);
|
|
58
|
-
if (!m) return null;
|
|
59
|
-
const segIdx = node.prefixNames.length;
|
|
60
|
-
const caps = Object.fromEntries(node.prefixNames.map((n, i) => [n, m[i + 1]]));
|
|
61
|
-
return { node, seg: m[segIdx + 1], isFile: m[segIdx + 2] == null, caps };
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const deepestMatch = (relPath, arch) => {
|
|
65
|
-
const matches = pipe(
|
|
66
|
-
arch.nodes.all,
|
|
67
|
-
map((node) => matchNode(relPath, node)),
|
|
68
|
-
filter(Boolean),
|
|
69
|
-
sort((x) => x.node.path.length),
|
|
70
|
-
);
|
|
71
|
-
return matches.length ? matches[matches.length - 1] : null;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const findChild = (children, seg, isFile) => pipe(children, filter((c) => c.folder === !isFile && c.re.test(seg)), (r) => (r.length ? r[0] : null));
|
|
75
|
-
|
|
76
|
-
const checkEntry = (match, child, out, findingFrom) => {
|
|
77
|
-
const vars = { basename: match.seg, ...match.caps };
|
|
78
|
-
if (child && child.forbidden) {
|
|
79
|
-
out.push(findingFrom({ key: "forbidden", report: child.report }, "nodes", match.node.slug, `nodes:${match.node.slug}:forbidden`, vars));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (!child && match.node.closed) {
|
|
83
|
-
out.push(findingFrom({ key: "closed", report: match.node.report }, "nodes", match.node.slug, `nodes:${match.node.slug}:closed`, vars));
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const checkTree = (relPath, arch, out, finding) => {
|
|
88
|
-
const match = deepestMatch(relPath, arch);
|
|
89
|
-
if (!match) return;
|
|
90
|
-
if (match.isFile) {
|
|
91
|
-
checkEntry(match, findChild(match.node.children, match.seg, true), out, finding);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const m = match.node.prefixRe.exec(relPath);
|
|
95
|
-
const parts = m[match.node.prefixNames.length + 2].split("/");
|
|
96
|
-
let node = match.node;
|
|
97
|
-
for (const part of parts) {
|
|
98
|
-
const child = findChild(node.children, part, false);
|
|
99
|
-
checkEntry({ node, seg: part, isFile: false }, child, out, finding);
|
|
100
|
-
node = child ? arch.nodes.bySlug[child.name] ?? null : null;
|
|
101
|
-
if (!node) break;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const matchers = (arch) => {
|
|
106
|
-
const nodeRes = arch.nodes.all.map((n) => n.prefixRe);
|
|
107
|
-
const invRes = arch.invariants.map((i) => i.where?.re).filter(Boolean);
|
|
108
|
-
const all = [...nodeRes, ...invRes];
|
|
109
|
-
return (rel) => all.some((re) => re.test(rel));
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
module.exports = { buildTree, checkTree, matchers };
|
package/main.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const { pipe, map, filter, flatMap } = require("remeda");
|
|
6
|
-
const { minimatch } = require("minimatch");
|
|
7
|
-
const { buildTree, matchers } = require("./entities/nodes");
|
|
8
|
-
const { normalizeInvariant } = require("./entities/invariants");
|
|
9
|
-
const { normalizeAliases } = require("./entities/aliases");
|
|
10
|
-
const { checkFile } = require("./utils");
|
|
11
|
-
const { renderReport } = require("./report");
|
|
12
|
-
const { createTsProject, toRel } = require("./ast");
|
|
13
|
-
|
|
14
|
-
const buildArchitecture = (raw) => {
|
|
15
|
-
if (!raw || typeof raw !== "object") throw new Error("architecture: expected an object");
|
|
16
|
-
if (!raw.nodes || !Object.keys(raw.nodes).length) throw new Error("architecture.nodes: must be a non-empty object");
|
|
17
|
-
const tree = buildTree(raw.nodes);
|
|
18
|
-
const invariants = pipe(raw.invariants ?? [], map((i) => normalizeInvariant(i, tree.slugs)));
|
|
19
|
-
const ids = invariants.map((i) => i.id);
|
|
20
|
-
if (new Set(ids).size !== ids.length) throw new Error("architecture.invariants: ids must be unique");
|
|
21
|
-
return {
|
|
22
|
-
nodes: tree,
|
|
23
|
-
invariants,
|
|
24
|
-
aliases: normalizeAliases(raw.aliases ?? {}),
|
|
25
|
-
files: raw.files ?? ["**/*.ts", "**/*.tsx"],
|
|
26
|
-
ignores: raw.ignores ?? [],
|
|
27
|
-
exts: raw.exts ?? [".ts", ".tsx", ".js", ".jsx"],
|
|
28
|
-
raw,
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const loadArchitecture = (config) => {
|
|
33
|
-
if (typeof config === "string") {
|
|
34
|
-
const p = path.resolve(process.cwd(), config);
|
|
35
|
-
const text = fs.readFileSync(p, "utf8");
|
|
36
|
-
if (p.endsWith(".js") || p.endsWith(".cjs")) return buildArchitecture(require(p));
|
|
37
|
-
return buildArchitecture(JSON.parse(text));
|
|
38
|
-
}
|
|
39
|
-
if (config && typeof config === "object" && typeof config.file === "string") return loadArchitecture(config.file);
|
|
40
|
-
return buildArchitecture(config);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const collectFiles = (repoRoot, { exts, ignoreDirs, ignoreGlobs }) => {
|
|
44
|
-
const extSet = new Set(exts);
|
|
45
|
-
const ignoreSet = new Set(ignoreDirs);
|
|
46
|
-
const out = [];
|
|
47
|
-
const walk = (dir) => {
|
|
48
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
49
|
-
const abs = path.join(dir, entry.name);
|
|
50
|
-
if (entry.isDirectory()) {
|
|
51
|
-
if (!ignoreSet.has(entry.name)) walk(abs);
|
|
52
|
-
} else if (extSet.has(path.extname(entry.name))) {
|
|
53
|
-
if (!ignoreGlobs.some((g) => minimatch(toRel(repoRoot, abs), g))) out.push(abs);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
walk(repoRoot);
|
|
58
|
-
return out;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const main = (argv) => {
|
|
62
|
-
const { parseArgs } = require("./config");
|
|
63
|
-
const args = parseArgs(argv);
|
|
64
|
-
if (args.help) {
|
|
65
|
-
console.log("usage: follow-architecture [--config <path>] [--ignore <glob>]... [--out <path>] [--check]");
|
|
66
|
-
return 0;
|
|
67
|
-
}
|
|
68
|
-
const repoRoot = path.resolve(args.cwd ?? process.cwd());
|
|
69
|
-
const arch = loadArchitecture(args.config);
|
|
70
|
-
const project = createTsProject();
|
|
71
|
-
const shouldCheck = matchers(arch);
|
|
72
|
-
const files = pipe(
|
|
73
|
-
collectFiles(repoRoot, { exts: arch.exts, ignoreDirs: ["node_modules", ".git", "dist", "build", "_medplum"], ignoreGlobs: [...(arch.ignores ?? []), ...(args.ignore ?? [])] }),
|
|
74
|
-
map((abs) => ({ abs, rel: toRel(repoRoot, abs) })),
|
|
75
|
-
filter((f) => shouldCheck(f.rel)),
|
|
76
|
-
);
|
|
77
|
-
const byDir = new Map();
|
|
78
|
-
for (const f of files) {
|
|
79
|
-
const dir = path.posix.dirname(f.rel);
|
|
80
|
-
if (!byDir.has(dir)) byDir.set(dir, []);
|
|
81
|
-
byDir.get(dir).push(f.rel);
|
|
82
|
-
}
|
|
83
|
-
const findings = pipe(files, flatMap((f) => checkFile(f.abs, fs.readFileSync(f.abs, "utf8"), repoRoot, arch, project, byDir.get(path.posix.dirname(f.rel)) ?? [])));
|
|
84
|
-
const text = renderReport(findings, repoRoot);
|
|
85
|
-
if (args.out) {
|
|
86
|
-
fs.writeFileSync(args.out, text);
|
|
87
|
-
console.log(`wrote ${args.out} (${findings.length} findings)`);
|
|
88
|
-
} else {
|
|
89
|
-
console.log(text);
|
|
90
|
-
}
|
|
91
|
-
if (args.check && findings.length > 0) return 1;
|
|
92
|
-
return 0;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
module.exports = { main, loadArchitecture, buildArchitecture };
|