@whaaaley/crush 0.0.0-stage → 0.2.6
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/LICENSE +32 -0
- package/README.md +185 -2
- package/SKILL.md +187 -0
- package/THIRD_PARTY_NOTICES.md +277 -0
- package/dist/capture/capture.operations.d.ts +23 -0
- package/dist/capture/capture.operations.js +231 -0
- package/dist/capture/capture.schema.d.ts +73 -0
- package/dist/capture/capture.schema.js +28 -0
- package/dist/collapse/collapse.operations.d.ts +2 -0
- package/dist/collapse/collapse.operations.js +82 -0
- package/dist/collapse/collapse.schema.d.ts +40 -0
- package/dist/collapse/collapse.schema.js +35 -0
- package/dist/crush.tables.d.ts +3583 -0
- package/dist/crush.tables.js +456 -0
- package/dist/crushes/callback.crush.d.ts +2 -0
- package/dist/crushes/callback.crush.js +19 -0
- package/dist/crushes/crush.d.ts +36 -0
- package/dist/crushes/crush.js +12 -0
- package/dist/crushes/crush.names.d.ts +1 -0
- package/dist/crushes/crush.names.js +2 -0
- package/dist/crushes/crushes.d.ts +2 -0
- package/dist/crushes/crushes.js +9 -0
- package/dist/crushes/default-value.crush.d.ts +2 -0
- package/dist/crushes/default-value.crush.js +29 -0
- package/dist/crushes/drop-operand.crush.d.ts +2 -0
- package/dist/crushes/drop-operand.crush.js +37 -0
- package/dist/crushes/fold.d.ts +64 -0
- package/dist/crushes/fold.js +366 -0
- package/dist/crushes/force-fork.crush.d.ts +2 -0
- package/dist/crushes/force-fork.crush.js +79 -0
- package/dist/crushes/loop-once.crush.d.ts +2 -0
- package/dist/crushes/loop-once.crush.js +71 -0
- package/dist/crushes/optional-chain.crush.d.ts +2 -0
- package/dist/crushes/optional-chain.crush.js +30 -0
- package/dist/crushes/switch-case.crush.d.ts +2 -0
- package/dist/crushes/switch-case.crush.js +19 -0
- package/dist/decisions/decide.d.ts +61 -0
- package/dist/decisions/decide.js +161 -0
- package/dist/decisions/decisions.d.ts +24 -0
- package/dist/decisions/decisions.js +62 -0
- package/dist/decisions/forks.decision.d.ts +4 -0
- package/dist/decisions/forks.decision.js +32 -0
- package/dist/decisions/kinds.d.ts +101 -0
- package/dist/decisions/kinds.js +38 -0
- package/dist/decisions/loops.decision.d.ts +4 -0
- package/dist/decisions/loops.decision.js +39 -0
- package/dist/decisions/shorts.decision.d.ts +3 -0
- package/dist/decisions/shorts.decision.js +66 -0
- package/dist/decisions/switches.decision.d.ts +3 -0
- package/dist/decisions/switches.decision.js +20 -0
- package/dist/decisions/throws.decision.d.ts +3 -0
- package/dist/decisions/throws.decision.js +35 -0
- package/dist/decisions/values.decision.d.ts +3 -0
- package/dist/decisions/values.decision.js +67 -0
- package/dist/explore/edges/explore.d.ts +60 -0
- package/dist/explore/edges/explore.db.d.ts +22 -0
- package/dist/explore/edges/explore.db.js +55 -0
- package/dist/explore/edges/explore.js +305 -0
- package/dist/explore/edges/random.d.ts +2 -0
- package/dist/explore/edges/random.js +32 -0
- package/dist/explore/explore.operations.d.ts +30 -0
- package/dist/explore/explore.operations.js +117 -0
- package/dist/explore/limits.operations.d.ts +14 -0
- package/dist/explore/limits.operations.js +20 -0
- package/dist/explore/targets.operations.d.ts +36 -0
- package/dist/explore/targets.operations.js +32 -0
- package/dist/explore/utils/draws.d.ts +6 -0
- package/dist/explore/utils/draws.js +2 -0
- package/dist/explore/utils/edits.d.ts +15 -0
- package/dist/explore/utils/edits.js +151 -0
- package/dist/explore/utils/guide.d.ts +23 -0
- package/dist/explore/utils/guide.js +35 -0
- package/dist/explore/utils/keep.d.ts +10 -0
- package/dist/explore/utils/keep.js +61 -0
- package/dist/explore/utils/pools.d.ts +17 -0
- package/dist/explore/utils/pools.js +121 -0
- package/dist/explore/utils/reads.d.ts +19 -0
- package/dist/explore/utils/reads.js +118 -0
- package/dist/explore/utils/twin.d.ts +21 -0
- package/dist/explore/utils/twin.js +55 -0
- package/dist/forks/forks.operations.d.ts +32 -0
- package/dist/forks/forks.operations.js +134 -0
- package/dist/forks/forks.schema.d.ts +20 -0
- package/dist/forks/forks.schema.js +14 -0
- package/dist/graph/cfg/cfg.d.ts +28 -0
- package/dist/graph/cfg/cfg.js +31 -0
- package/dist/graph/cfg/code-paths/analyzer.d.ts +27 -0
- package/dist/graph/cfg/code-paths/analyzer.js +358 -0
- package/dist/graph/cfg/code-paths/segments.d.ts +44 -0
- package/dist/graph/cfg/code-paths/segments.js +105 -0
- package/dist/graph/cfg/code-paths/state.d.ts +121 -0
- package/dist/graph/cfg/code-paths/state.js +611 -0
- package/dist/graph/cfg/entries.d.ts +13 -0
- package/dist/graph/cfg/entries.js +120 -0
- package/dist/graph/cfg/functions.d.ts +6 -0
- package/dist/graph/cfg/functions.js +47 -0
- package/dist/graph/cfg/paths.d.ts +27 -0
- package/dist/graph/cfg/paths.js +91 -0
- package/dist/graph/cfg/scopes/scopes.d.ts +40 -0
- package/dist/graph/cfg/scopes/scopes.js +375 -0
- package/dist/graph/symbols/file.d.ts +90 -0
- package/dist/graph/symbols/file.js +427 -0
- package/dist/graph/symbols/keys.d.ts +13 -0
- package/dist/graph/symbols/keys.js +22 -0
- package/dist/graph/symbols/resolve.operations.d.ts +4 -0
- package/dist/graph/symbols/resolve.operations.js +33 -0
- package/dist/graph/symbols/symbols.d.ts +12 -0
- package/dist/graph/symbols/symbols.js +155 -0
- package/dist/graph/symbols/symbols.schema.d.ts +32 -0
- package/dist/graph/symbols/symbols.schema.js +19 -0
- package/dist/graph/unused/tests.d.ts +7 -0
- package/dist/graph/unused/tests.js +95 -0
- package/dist/graph/unused/unused.d.ts +53 -0
- package/dist/graph/unused/unused.js +319 -0
- package/dist/graph/walk/walk.d.ts +7 -0
- package/dist/graph/walk/walk.js +39 -0
- package/dist/instrument/instrument.operations.d.ts +72 -0
- package/dist/instrument/instrument.operations.js +786 -0
- package/dist/instrument/instrument.schema.d.ts +257 -0
- package/dist/instrument/instrument.schema.js +100 -0
- package/dist/judge/counters.d.ts +86 -0
- package/dist/judge/counters.js +402 -0
- package/dist/judge/edges/api.d.ts +14 -0
- package/dist/judge/edges/api.js +80 -0
- package/dist/judge/edges/completion.reporter.d.ts +9 -0
- package/dist/judge/edges/completion.reporter.js +51 -0
- package/dist/judge/edges/hints.reporter.d.ts +13 -0
- package/dist/judge/edges/hints.reporter.js +29 -0
- package/dist/judge/edges/judge.edges.d.ts +52 -0
- package/dist/judge/edges/judge.edges.js +59 -0
- package/dist/judge/edges/judge.fs.d.ts +8 -0
- package/dist/judge/edges/judge.fs.js +45 -0
- package/dist/judge/edges/merge.d.ts +11 -0
- package/dist/judge/edges/merge.js +60 -0
- package/dist/judge/edges/plugin.d.ts +132 -0
- package/dist/judge/edges/plugin.js +441 -0
- package/dist/judge/edges/reach.d.ts +68 -0
- package/dist/judge/edges/reach.js +132 -0
- package/dist/judge/edges/speed.d.ts +32 -0
- package/dist/judge/edges/speed.js +34 -0
- package/dist/judge/edges/strays.d.ts +1 -0
- package/dist/judge/edges/strays.js +14 -0
- package/dist/judge/edges/vitest.d.ts +20 -0
- package/dist/judge/edges/vitest.js +36 -0
- package/dist/judge/edges/vitest.schema.d.ts +14 -0
- package/dist/judge/edges/vitest.schema.js +16 -0
- package/dist/judge/explore.test.d.ts +1 -0
- package/dist/judge/explore.test.js +101 -0
- package/dist/judge/hints.d.ts +11 -0
- package/dist/judge/hints.js +44 -0
- package/dist/judge/judge.operations.d.ts +218 -0
- package/dist/judge/judge.operations.js +464 -0
- package/dist/judge/judge.schema.d.ts +135 -0
- package/dist/judge/judge.schema.js +129 -0
- package/dist/judge/judge.shard-1.test.d.ts +1 -0
- package/dist/judge/judge.shard-1.test.js +3 -0
- package/dist/judge/judge.shard-2.test.d.ts +1 -0
- package/dist/judge/judge.shard-2.test.js +3 -0
- package/dist/judge/judge.test.d.ts +1 -0
- package/dist/judge/judge.test.js +3 -0
- package/dist/judge/refusals.d.ts +14 -0
- package/dist/judge/refusals.js +10 -0
- package/dist/judge/report.test.d.ts +1 -0
- package/dist/judge/report.test.js +432 -0
- package/dist/judge/runner.d.ts +3 -0
- package/dist/judge/runner.js +1602 -0
- package/dist/judge/stresses.test.d.ts +1 -0
- package/dist/judge/stresses.test.js +12 -0
- package/dist/judge/task-meta.d.ts +51 -0
- package/dist/judge/task-meta.js +3 -0
- package/dist/justify/edges/load.d.ts +7 -0
- package/dist/justify/edges/load.js +40 -0
- package/dist/justify/edges/refresh.fs.d.ts +8 -0
- package/dist/justify/edges/refresh.fs.js +15 -0
- package/dist/justify/justify.operations.d.ts +46 -0
- package/dist/justify/justify.operations.js +80 -0
- package/dist/justify/justify.schema.d.ts +21 -0
- package/dist/justify/justify.schema.js +11 -0
- package/dist/mutators/arithmetic-operator.mutator.d.ts +2 -0
- package/dist/mutators/arithmetic-operator.mutator.js +22 -0
- package/dist/mutators/array-declaration.mutator.d.ts +2 -0
- package/dist/mutators/array-declaration.mutator.js +12 -0
- package/dist/mutators/arrow-function.mutator.d.ts +2 -0
- package/dist/mutators/arrow-function.mutator.js +10 -0
- package/dist/mutators/assignment-operator.mutator.d.ts +2 -0
- package/dist/mutators/assignment-operator.mutator.js +29 -0
- package/dist/mutators/await-expression.mutator.d.ts +2 -0
- package/dist/mutators/await-expression.mutator.js +7 -0
- package/dist/mutators/bitwise-operator.mutator.d.ts +2 -0
- package/dist/mutators/bitwise-operator.mutator.js +19 -0
- package/dist/mutators/block-statement.mutator.d.ts +2 -0
- package/dist/mutators/block-statement.mutator.js +30 -0
- package/dist/mutators/boolean-literal.mutator.d.ts +2 -0
- package/dist/mutators/boolean-literal.mutator.js +5 -0
- package/dist/mutators/coercion.mutator.d.ts +2 -0
- package/dist/mutators/coercion.mutator.js +28 -0
- package/dist/mutators/conditional-expression.mutator.d.ts +2 -0
- package/dist/mutators/conditional-expression.mutator.js +36 -0
- package/dist/mutators/disposal.mutator.d.ts +2 -0
- package/dist/mutators/disposal.mutator.js +13 -0
- package/dist/mutators/empty-destructuring.mutator.d.ts +2 -0
- package/dist/mutators/empty-destructuring.mutator.js +35 -0
- package/dist/mutators/empty-return.mutator.d.ts +2 -0
- package/dist/mutators/empty-return.mutator.js +35 -0
- package/dist/mutators/equality-operator.mutator.d.ts +2 -0
- package/dist/mutators/equality-operator.mutator.js +16 -0
- package/dist/mutators/loop-exit.mutator.d.ts +2 -0
- package/dist/mutators/loop-exit.mutator.js +5 -0
- package/dist/mutators/method-expression.mutator.d.ts +2 -0
- package/dist/mutators/method-expression.mutator.js +59 -0
- package/dist/mutators/missing-lookup.mutator.d.ts +2 -0
- package/dist/mutators/missing-lookup.mutator.js +25 -0
- package/dist/mutators/mutator.d.ts +40 -0
- package/dist/mutators/mutator.js +49 -0
- package/dist/mutators/mutator.names.d.ts +3 -0
- package/dist/mutators/mutator.names.js +43 -0
- package/dist/mutators/mutators.d.ts +8 -0
- package/dist/mutators/mutators.js +84 -0
- package/dist/mutators/nested-condition.mutator.d.ts +2 -0
- package/dist/mutators/nested-condition.mutator.js +16 -0
- package/dist/mutators/number-literal.mutator.d.ts +3 -0
- package/dist/mutators/number-literal.mutator.js +13 -0
- package/dist/mutators/object-literal.mutator.d.ts +2 -0
- package/dist/mutators/object-literal.mutator.js +6 -0
- package/dist/mutators/odd-number.mutator.d.ts +2 -0
- package/dist/mutators/odd-number.mutator.js +15 -0
- package/dist/mutators/operand-deletion.mutator.d.ts +2 -0
- package/dist/mutators/operand-deletion.mutator.js +9 -0
- package/dist/mutators/outcome.mutator.d.ts +3 -0
- package/dist/mutators/outcome.mutator.js +45 -0
- package/dist/mutators/plain-assignment.mutator.d.ts +2 -0
- package/dist/mutators/plain-assignment.mutator.js +7 -0
- package/dist/mutators/power-operator.mutator.d.ts +2 -0
- package/dist/mutators/power-operator.mutator.js +13 -0
- package/dist/mutators/private-brand.mutator.d.ts +2 -0
- package/dist/mutators/private-brand.mutator.js +7 -0
- package/dist/mutators/regex.mutator.d.ts +2 -0
- package/dist/mutators/regex.mutator.js +29 -0
- package/dist/mutators/short-iteration.mutator.d.ts +2 -0
- package/dist/mutators/short-iteration.mutator.js +8 -0
- package/dist/mutators/string-literal.mutator.d.ts +3 -0
- package/dist/mutators/string-literal.mutator.js +149 -0
- package/dist/mutators/switch-default.mutator.d.ts +2 -0
- package/dist/mutators/switch-default.mutator.js +13 -0
- package/dist/mutators/sync-iteration.mutator.d.ts +3 -0
- package/dist/mutators/sync-iteration.mutator.js +9 -0
- package/dist/mutators/thrown-call.mutator.d.ts +2 -0
- package/dist/mutators/thrown-call.mutator.js +7 -0
- package/dist/mutators/unary-operator.mutator.d.ts +2 -0
- package/dist/mutators/unary-operator.mutator.js +18 -0
- package/dist/mutators/unbound-call.mutator.d.ts +2 -0
- package/dist/mutators/unbound-call.mutator.js +14 -0
- package/dist/mutators/update-operator.mutator.d.ts +2 -0
- package/dist/mutators/update-operator.mutator.js +15 -0
- package/dist/mutators/yield-value.mutator.d.ts +2 -0
- package/dist/mutators/yield-value.mutator.js +7 -0
- package/dist/parity/compare.d.ts +27 -0
- package/dist/parity/compare.js +26 -0
- package/dist/parity/corpus.parity.d.ts +1 -0
- package/dist/parity/corpus.parity.js +97 -0
- package/dist/parity/edges/corpus.fs.d.ts +3 -0
- package/dist/parity/edges/corpus.fs.js +30 -0
- package/dist/parity/edges/ports.d.ts +2 -0
- package/dist/parity/edges/ports.js +21 -0
- package/dist/parity/edges/vitest.d.ts +2 -0
- package/dist/parity/edges/vitest.js +3 -0
- package/dist/parity/parity.operations.d.ts +33 -0
- package/dist/parity/parity.operations.js +60 -0
- package/dist/parity/parity.schema.d.ts +5 -0
- package/dist/parity/parity.schema.js +6 -0
- package/dist/parity/stryker/compare.d.ts +14 -0
- package/dist/parity/stryker/compare.js +52 -0
- package/dist/parity/stryker/edges/ports.d.ts +12 -0
- package/dist/parity/stryker/edges/ports.js +28 -0
- package/dist/parity/stryker/equivalence.d.ts +1 -0
- package/dist/parity/stryker/equivalence.js +42 -0
- package/dist/parity/stryker/intended.d.ts +29 -0
- package/dist/parity/stryker/intended.js +152 -0
- package/dist/parity/stryker/normalize.d.ts +27 -0
- package/dist/parity/stryker/normalize.js +181 -0
- package/dist/parity/stryker/rules.d.ts +6 -0
- package/dist/parity/stryker/rules.js +116 -0
- package/dist/parity/stryker/sides.d.ts +46 -0
- package/dist/parity/stryker/sides.js +199 -0
- package/dist/parity/stryker/stryker.parity.d.ts +1 -0
- package/dist/parity/stryker/stryker.parity.js +147 -0
- package/dist/parity/stryker/stryker.schema.d.ts +6 -0
- package/dist/parity/stryker/stryker.schema.js +7 -0
- package/dist/parity/views.d.ts +21 -0
- package/dist/parity/views.js +119 -0
- package/dist/questions/questions.operations.d.ts +110 -0
- package/dist/questions/questions.operations.js +446 -0
- package/dist/questions/questions.schema.d.ts +57 -0
- package/dist/questions/questions.schema.js +28 -0
- package/dist/record/edges/calls.db.d.ts +10 -0
- package/dist/record/edges/calls.db.js +91 -0
- package/dist/record/edges/hits.db.d.ts +3 -0
- package/dist/record/edges/hits.db.js +5 -0
- package/dist/record/edges/holds.db.d.ts +4 -0
- package/dist/record/edges/holds.db.js +31 -0
- package/dist/record/edges/judged-state.db.d.ts +5 -0
- package/dist/record/edges/judged-state.db.js +25 -0
- package/dist/record/edges/markers.db.d.ts +11 -0
- package/dist/record/edges/markers.db.js +55 -0
- package/dist/record/edges/merge.db.d.ts +7 -0
- package/dist/record/edges/merge.db.js +46 -0
- package/dist/record/edges/parts.db.d.ts +42 -0
- package/dist/record/edges/parts.db.js +389 -0
- package/dist/record/edges/parts.edges.d.ts +2 -0
- package/dist/record/edges/parts.edges.js +7 -0
- package/dist/record/edges/parts.fs.d.ts +1 -0
- package/dist/record/edges/parts.fs.js +11 -0
- package/dist/record/edges/parts.writer.d.ts +1 -0
- package/dist/record/edges/parts.writer.js +85 -0
- package/dist/record/edges/passes.db.d.ts +19 -0
- package/dist/record/edges/passes.db.js +31 -0
- package/dist/record/edges/plan.db.d.ts +21 -0
- package/dist/record/edges/plan.db.js +174 -0
- package/dist/record/edges/reach.db.d.ts +6 -0
- package/dist/record/edges/reach.db.js +62 -0
- package/dist/record/edges/record.db.d.ts +22 -0
- package/dist/record/edges/record.db.js +176 -0
- package/dist/record/edges/record.fs.d.ts +3 -0
- package/dist/record/edges/record.fs.js +7 -0
- package/dist/record/edges/site-verdicts.db.d.ts +11 -0
- package/dist/record/edges/site-verdicts.db.js +66 -0
- package/dist/record/edges/verified.db.d.ts +7 -0
- package/dist/record/edges/verified.db.js +71 -0
- package/dist/record/parts.operations.d.ts +26 -0
- package/dist/record/parts.operations.js +31 -0
- package/dist/record/path-checks.operations.d.ts +15 -0
- package/dist/record/path-checks.operations.js +84 -0
- package/dist/record/record.operations.d.ts +36 -0
- package/dist/record/record.operations.js +11 -0
- package/dist/stresses/edges/stresses.record.d.ts +4 -0
- package/dist/stresses/edges/stresses.record.js +37 -0
- package/dist/stresses/stresses.operations.d.ts +28 -0
- package/dist/stresses/stresses.operations.js +22 -0
- package/dist/utils/ast.d.ts +55 -0
- package/dist/utils/ast.js +181 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.js +12 -0
- package/dist/utils/faults.d.ts +6 -0
- package/dist/utils/faults.js +10 -0
- package/dist/utils/lookup.d.ts +4 -0
- package/dist/utils/lookup.js +27 -0
- package/dist/utils/order.d.ts +2 -0
- package/dist/utils/order.js +17 -0
- package/dist/utils/retry.d.ts +14 -0
- package/dist/utils/retry.js +15 -0
- package/dist/utils/safe.d.ts +11 -0
- package/dist/utils/safe.js +31 -0
- package/migrations/main/20261129123324_initial/migration.sql +418 -0
- package/migrations/main/20261129123324_initial/snapshot.json +3641 -0
- package/package.json +89 -4
- package/references/consumer-setup.md +92 -0
- package/src/graph/cfg/code-paths/LICENSE +21 -0
- package/src/graph/cfg/scopes/LICENSE +24 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { matchesGlob } from 'node:path';
|
|
2
|
+
import { exportKey, fileKey, namespaceKey } from './keys.js';
|
|
3
|
+
import { normalized } from './resolve.operations.js';
|
|
4
|
+
import { itemAt } from '../../utils/lookup.js';
|
|
5
|
+
// Every node the edges lead to from the starts, the starts included.
|
|
6
|
+
export const reachedFrom = (edges, starts, canEnter) => {
|
|
7
|
+
const seen = new Set(starts);
|
|
8
|
+
const queue = [...starts];
|
|
9
|
+
for (let key = queue.pop(); key !== undefined; key = queue.pop()) {
|
|
10
|
+
for (const next of edges.get(key) ?? []) {
|
|
11
|
+
if (seen.has(next) || canEnter?.(next) === false)
|
|
12
|
+
continue;
|
|
13
|
+
seen.add(next);
|
|
14
|
+
queue.push(next);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return seen;
|
|
18
|
+
};
|
|
19
|
+
// The whole project's graph joined from every file's part.
|
|
20
|
+
// A file's namespace stands for all of its exports, and an entry's every export is reached, since the runtime calls it.
|
|
21
|
+
export const symbolGraphOf = ({ files, roots, resolve }) => {
|
|
22
|
+
const byPath = new Map(files.map((file) => [file.path, file]));
|
|
23
|
+
const nodes = new Map();
|
|
24
|
+
const edges = new Map();
|
|
25
|
+
const edge = (from, to) => {
|
|
26
|
+
const out = edges.get(from) ?? new Set();
|
|
27
|
+
edges.set(from, out.add(to));
|
|
28
|
+
};
|
|
29
|
+
// An import resolving to no file of the project leads to no node, and the edge goes with the others leading nowhere.
|
|
30
|
+
const keyOf = (from, to) => {
|
|
31
|
+
if ('key' in to)
|
|
32
|
+
return to.key;
|
|
33
|
+
const file = resolve(from, to.specifier) ?? '';
|
|
34
|
+
if ('namespace' in to)
|
|
35
|
+
return namespaceKey(file);
|
|
36
|
+
return to.name === null ? fileKey(file) : exportKey(file, to.name);
|
|
37
|
+
};
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
for (const node of file.nodes)
|
|
40
|
+
nodes.set(node.key, node);
|
|
41
|
+
const namespace = namespaceKey(file.path);
|
|
42
|
+
nodes.set(namespace, { key: namespace, file: file.path, kind: 'namespace', name: '*', line: 1 });
|
|
43
|
+
for (const { from, to } of file.edges)
|
|
44
|
+
edge(from, keyOf(file.path, to));
|
|
45
|
+
const folder = file.path.split('/').slice(0, -1).join('/');
|
|
46
|
+
for (const { from, patterns } of file.globs) {
|
|
47
|
+
// A glob starting with `/` is read from the root, any other from the file's folder, root-level files included.
|
|
48
|
+
// A negated pattern read as one to include matches no path, so only the excluded list sets it apart.
|
|
49
|
+
const fromRoot = (pattern) => normalized(pattern.startsWith('/') ? pattern : `${folder}/${pattern}`);
|
|
50
|
+
// A pattern climbing out of the project matches no file of it.
|
|
51
|
+
const globsOf = (list) => list.map(fromRoot).filter((glob) => glob !== null);
|
|
52
|
+
const included = globsOf(patterns);
|
|
53
|
+
const excluded = globsOf(patterns.filter((pattern) => pattern.startsWith('!')).map((pattern) => pattern.slice(1)));
|
|
54
|
+
for (const path of byPath.keys()) {
|
|
55
|
+
const matches = (glob) => matchesGlob(path, glob);
|
|
56
|
+
if (!included.some(matches) || excluded.some(matches))
|
|
57
|
+
continue;
|
|
58
|
+
edge(from, fileKey(path));
|
|
59
|
+
edge(from, namespaceKey(path));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (roots.get(file.path) === 'entry')
|
|
63
|
+
edge(fileKey(file.path), namespace);
|
|
64
|
+
}
|
|
65
|
+
// A file's own export names, before any star passes others on.
|
|
66
|
+
const ownNamesOf = (file) => file.nodes.flatMap((node) => (node.kind === 'export' ? [node.name] : []));
|
|
67
|
+
// A file's namespace reaches every export it has, its own and those its stars pass on, each file's names found once.
|
|
68
|
+
// A star of a module outside the project passes nothing on.
|
|
69
|
+
// Each file's names are its own and every name but the default of each file its stars reach at any depth.
|
|
70
|
+
// Files whose stars reach each other share the names passed on to them, so each loop and each file is worked out once, in Tarjan's order, which finishes a group only after every group it reaches.
|
|
71
|
+
// The walk keeps its own stack, so a chain of barrels longer than the call stack is walked whole.
|
|
72
|
+
const indexOfPath = new Map(files.map((file, at) => [file.path, at]));
|
|
73
|
+
const starsAt = files.map(({ path, stars }) => stars.flatMap((star) => indexOfPath.get(resolve(path, star) ?? '') ?? []));
|
|
74
|
+
const passedOwnOf = (at) => ownNamesOf(itemAt(files, at)).filter((name) => name !== 'default');
|
|
75
|
+
// A file's index is set when the walk enters it, its group once its group is finished, and only the index is read before it is set.
|
|
76
|
+
const indexOf = [];
|
|
77
|
+
const lowOf = [];
|
|
78
|
+
const groupOf = [];
|
|
79
|
+
const isOpen = [];
|
|
80
|
+
// A group passes on every name but the default its members own and every group its stars reach carries, each member's own names already being its names.
|
|
81
|
+
const carried = [];
|
|
82
|
+
const open = [];
|
|
83
|
+
let counter = 0;
|
|
84
|
+
const enter = (at, work) => {
|
|
85
|
+
indexOf[at] = counter;
|
|
86
|
+
lowOf[at] = counter;
|
|
87
|
+
counter += 1;
|
|
88
|
+
open.push(at);
|
|
89
|
+
isOpen[at] = true;
|
|
90
|
+
work.push({ at, next: 0 });
|
|
91
|
+
};
|
|
92
|
+
for (const [root] of files.entries()) {
|
|
93
|
+
if (indexOf[root] !== undefined)
|
|
94
|
+
continue;
|
|
95
|
+
const work = [];
|
|
96
|
+
enter(root, work);
|
|
97
|
+
for (let top = work.at(-1); top; top = work.at(-1)) {
|
|
98
|
+
const stars = itemAt(starsAt, top.at);
|
|
99
|
+
if (top.next < stars.length) {
|
|
100
|
+
const star = itemAt(stars, top.next);
|
|
101
|
+
top.next += 1;
|
|
102
|
+
const starIndex = indexOf[star];
|
|
103
|
+
if (starIndex === undefined)
|
|
104
|
+
enter(star, work);
|
|
105
|
+
else if (itemAt(isOpen, star))
|
|
106
|
+
lowOf[top.at] = Math.min(itemAt(lowOf, top.at), starIndex);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
work.pop();
|
|
110
|
+
const parent = work.at(-1);
|
|
111
|
+
if (parent)
|
|
112
|
+
lowOf[parent.at] = Math.min(itemAt(lowOf, parent.at), itemAt(lowOf, top.at));
|
|
113
|
+
if (itemAt(lowOf, top.at) !== indexOf[top.at])
|
|
114
|
+
continue;
|
|
115
|
+
const group = carried.length;
|
|
116
|
+
const members = open.splice(open.lastIndexOf(top.at));
|
|
117
|
+
const passed = new Set(members.flatMap(passedOwnOf));
|
|
118
|
+
for (const member of members) {
|
|
119
|
+
isOpen[member] = false;
|
|
120
|
+
groupOf[member] = group;
|
|
121
|
+
}
|
|
122
|
+
for (const member of members)
|
|
123
|
+
for (const star of itemAt(starsAt, member))
|
|
124
|
+
if (itemAt(groupOf, star) !== group)
|
|
125
|
+
for (const name of itemAt(carried, itemAt(groupOf, star)))
|
|
126
|
+
passed.add(name);
|
|
127
|
+
carried.push(passed);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const namesAt = files.map((file, at) => new Set([...ownNamesOf(file), ...itemAt(carried, itemAt(groupOf, at))]));
|
|
131
|
+
for (const [at, file] of files.entries()) {
|
|
132
|
+
const { path } = file;
|
|
133
|
+
const own = new Set(ownNamesOf(file));
|
|
134
|
+
for (const name of itemAt(namesAt, at)) {
|
|
135
|
+
const key = exportKey(path, name);
|
|
136
|
+
if (!nodes.has(key)) {
|
|
137
|
+
const passed = { key, file: path, kind: 'export', name, line: 1, bindings: [], isOwn: false };
|
|
138
|
+
nodes.set(key, passed);
|
|
139
|
+
}
|
|
140
|
+
edge(namespaceKey(path), key);
|
|
141
|
+
if (own.has(name))
|
|
142
|
+
continue;
|
|
143
|
+
// A name leads only into the files its stars reach that hold it, since an edge to a file lacking it would lead to no node.
|
|
144
|
+
for (const star of itemAt(starsAt, at))
|
|
145
|
+
if (itemAt(namesAt, star).has(name))
|
|
146
|
+
edge(key, exportKey(itemAt(files, star).path, name));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// An edge into a node the graph never made, as a name a module does not export or a file outside the project, leads nowhere.
|
|
150
|
+
for (const out of edges.values())
|
|
151
|
+
for (const to of out)
|
|
152
|
+
if (!nodes.has(to))
|
|
153
|
+
out.delete(to);
|
|
154
|
+
return { nodes, edges };
|
|
155
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const reachKeyOutput: z.ZodString;
|
|
3
|
+
export declare const reachNodeOutput: z.ZodObject<{
|
|
4
|
+
key: z.ZodString;
|
|
5
|
+
file: z.ZodString;
|
|
6
|
+
kind: z.ZodEnum<{
|
|
7
|
+
binding: "binding";
|
|
8
|
+
export: "export";
|
|
9
|
+
file: "file";
|
|
10
|
+
function: "function";
|
|
11
|
+
}>;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
line: z.ZodNumber;
|
|
14
|
+
parsed: z.ZodBoolean;
|
|
15
|
+
ask: z.ZodEnum<{
|
|
16
|
+
none: "none";
|
|
17
|
+
remove: "remove";
|
|
18
|
+
test: "test";
|
|
19
|
+
tests: "tests";
|
|
20
|
+
unexport: "unexport";
|
|
21
|
+
}>;
|
|
22
|
+
alongside: z.ZodString;
|
|
23
|
+
onlyTests: z.ZodString;
|
|
24
|
+
sharedTests: z.ZodString;
|
|
25
|
+
unnamedTests: z.ZodString;
|
|
26
|
+
patternTests: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type ReachNodeOutput = z.infer<typeof reachNodeOutput>;
|
|
29
|
+
export type ReachEdgeOutput = {
|
|
30
|
+
fromKey: string;
|
|
31
|
+
toKey: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { reachAsks, reachKinds } from '../../crush.tables.js';
|
|
3
|
+
import { decodeReachKey, reachFile, reachName } from './keys.js';
|
|
4
|
+
export const reachKeyOutput = z.string().refine((key) => decodeReachKey(key) !== null, 'Invalid reach key');
|
|
5
|
+
// One node of the whole-project graph as the record keeps it.
|
|
6
|
+
export const reachNodeOutput = z.object({
|
|
7
|
+
key: reachKeyOutput,
|
|
8
|
+
file: reachFile,
|
|
9
|
+
kind: z.enum(reachKinds),
|
|
10
|
+
name: reachName,
|
|
11
|
+
line: z.number().int().positive(),
|
|
12
|
+
parsed: z.boolean(),
|
|
13
|
+
ask: z.enum(reachAsks),
|
|
14
|
+
alongside: z.string().max(65_536),
|
|
15
|
+
onlyTests: z.string().max(1_048_576),
|
|
16
|
+
sharedTests: z.string().max(1_048_576),
|
|
17
|
+
unnamedTests: z.string().max(1_048_576),
|
|
18
|
+
patternTests: z.string().max(1_048_576),
|
|
19
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { testLabelOf } from '../../judge/judge.operations.js';
|
|
2
|
+
import { fixedTextOf } from '../symbols/file.js';
|
|
3
|
+
import { functionKey } from '../symbols/keys.js';
|
|
4
|
+
const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
|
|
5
|
+
// The calls Vitest declares a test and a group of tests with.
|
|
6
|
+
const testCallees = new Set(['it', 'test']);
|
|
7
|
+
const groupCallees = new Set(['describe', 'suite']);
|
|
8
|
+
const hookCallees = new Set(['beforeAll', 'beforeEach', 'afterAll', 'afterEach', 'aroundAll', 'aroundEach']);
|
|
9
|
+
// The tests, hooks and describe bodies a test file declares, by the graph's keys for the functions they run.
|
|
10
|
+
export const runnersOf = (path, tree) => {
|
|
11
|
+
const runners = { tests: [], hooks: [], inside: [] };
|
|
12
|
+
if (!tree)
|
|
13
|
+
return runners;
|
|
14
|
+
const { parents, owners, bindings, definitionOf } = tree;
|
|
15
|
+
// A test is an `it` or `test` call, through modifiers such as `skip` or `concurrent`, named by its fixed title and the titles of the `describe` calls around it.
|
|
16
|
+
// A title Vitest formats per row, as an `each` table's, or one computed at run time, cannot be named, so its test is kept by its file alone.
|
|
17
|
+
const callOf = (node, callees) => {
|
|
18
|
+
if (node.type !== 'CallExpression')
|
|
19
|
+
return null;
|
|
20
|
+
let isFormatted = false;
|
|
21
|
+
let callee = node.callee;
|
|
22
|
+
for (;;) {
|
|
23
|
+
if (callee.type === 'CallExpression') {
|
|
24
|
+
isFormatted = true;
|
|
25
|
+
callee = callee.callee;
|
|
26
|
+
}
|
|
27
|
+
else if (callee.type === 'MemberExpression' && !callee.computed)
|
|
28
|
+
callee = callee.object;
|
|
29
|
+
else
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (callee.type !== 'Identifier' || !callees.has(callee.name))
|
|
33
|
+
return null;
|
|
34
|
+
return { call: node, title: isFormatted ? null : fixedTextOf(node.arguments[0]) };
|
|
35
|
+
};
|
|
36
|
+
// A test's body is a function written in place, or one a name binds, read through its binding.
|
|
37
|
+
// The body is the first function argument after the title, a timeout or options after it aside.
|
|
38
|
+
const bodyOf = (call, hasTitle) => {
|
|
39
|
+
const body = call.arguments.slice(hasTitle ? 1 : 0).find((argument) => functionTypes.has(argument.type) || argument.type === 'Identifier');
|
|
40
|
+
if (!body)
|
|
41
|
+
return undefined;
|
|
42
|
+
return functionTypes.has(body.type) ? functionKey(path, body.start) : bindings.get(definitionOf.get(body) ?? body);
|
|
43
|
+
};
|
|
44
|
+
const seen = new Map();
|
|
45
|
+
// Each runner's call and body, so a group knows the tests and hooks inside it.
|
|
46
|
+
const runnerCalls = new Map();
|
|
47
|
+
for (const node of owners.keys()) {
|
|
48
|
+
const test = callOf(node, testCallees);
|
|
49
|
+
if (!test)
|
|
50
|
+
continue;
|
|
51
|
+
const body = bodyOf(test.call, true);
|
|
52
|
+
if (!body)
|
|
53
|
+
continue;
|
|
54
|
+
runnerCalls.set(node, body);
|
|
55
|
+
const groups = [];
|
|
56
|
+
for (let above = parents.get(node); above; above = parents.get(above)) {
|
|
57
|
+
const group = callOf(above, groupCallees);
|
|
58
|
+
if (group)
|
|
59
|
+
groups.unshift(group.title);
|
|
60
|
+
}
|
|
61
|
+
const label = test.title !== null && groups.every((title) => title !== null) ? testLabelOf({ file: path, groups, title: test.title }, seen) : '';
|
|
62
|
+
runners.tests.push([label, body]);
|
|
63
|
+
}
|
|
64
|
+
// A hook and a describe body run code for the tests around them, so each is listed beside the tests, named by its group path and its hook.
|
|
65
|
+
for (const node of owners.keys()) {
|
|
66
|
+
if (node.type !== 'CallExpression')
|
|
67
|
+
continue;
|
|
68
|
+
const hook = node.callee.type === 'Identifier' && hookCallees.has(node.callee.name) ? node.callee.name : null;
|
|
69
|
+
const group = callOf(node, groupCallees);
|
|
70
|
+
if (!hook && !group)
|
|
71
|
+
continue;
|
|
72
|
+
const body = bodyOf(node, group !== null);
|
|
73
|
+
if (!body)
|
|
74
|
+
continue;
|
|
75
|
+
runnerCalls.set(node, body);
|
|
76
|
+
const groups = group ? [group.title] : [];
|
|
77
|
+
for (let above = parents.get(node); above; above = parents.get(above)) {
|
|
78
|
+
const around = callOf(above, groupCallees);
|
|
79
|
+
if (around)
|
|
80
|
+
groups.unshift(around.title);
|
|
81
|
+
}
|
|
82
|
+
const titles = hook ? [...groups, hook] : groups;
|
|
83
|
+
const isNamed = titles.every((title) => title !== null);
|
|
84
|
+
runners.hooks.push([isNamed ? `${path}::${titles.join(' > ')}` : '', body]);
|
|
85
|
+
}
|
|
86
|
+
// A group holds the tests and hooks whose calls sit inside it, at any depth.
|
|
87
|
+
for (const [node, body] of runnerCalls) {
|
|
88
|
+
for (let above = parents.get(node); above; above = parents.get(above)) {
|
|
89
|
+
const group = runnerCalls.get(above);
|
|
90
|
+
if (group && callOf(above, groupCallees))
|
|
91
|
+
runners.inside.push([group, body]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return runners;
|
|
95
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { reachAsks, reachKinds } from '../../crush.tables.ts';
|
|
2
|
+
import { type SymbolGraph } from '../symbols/symbols.ts';
|
|
3
|
+
import type { Runners } from './tests.ts';
|
|
4
|
+
export type ReachAsk = (typeof reachAsks)[number];
|
|
5
|
+
export type Unused = {
|
|
6
|
+
key: string;
|
|
7
|
+
ask: Exclude<ReachAsk, 'none'>;
|
|
8
|
+
alongside: string[];
|
|
9
|
+
onlyTests: string[];
|
|
10
|
+
sharedTests: string[];
|
|
11
|
+
unnamedTests: string[];
|
|
12
|
+
};
|
|
13
|
+
export type UnusedOutput = {
|
|
14
|
+
unused: Unused[];
|
|
15
|
+
patternTests: Map<string, string[]>;
|
|
16
|
+
};
|
|
17
|
+
export type UnusedInput = {
|
|
18
|
+
symbols: SymbolGraph;
|
|
19
|
+
roots: ReadonlyMap<string, 'entry' | 'test'>;
|
|
20
|
+
runners: ReadonlyMap<string, Runners>;
|
|
21
|
+
};
|
|
22
|
+
export declare const fixturePattern: RegExp;
|
|
23
|
+
export declare const unusedOf: ({ symbols, roots, runners: declared }: UnusedInput) => UnusedOutput;
|
|
24
|
+
export type ReachNode = {
|
|
25
|
+
key: string;
|
|
26
|
+
file: string;
|
|
27
|
+
kind: (typeof reachKinds)[number];
|
|
28
|
+
name: string;
|
|
29
|
+
line: number;
|
|
30
|
+
parsed: boolean;
|
|
31
|
+
ask: ReachAsk;
|
|
32
|
+
alongside: string;
|
|
33
|
+
onlyTests: string;
|
|
34
|
+
sharedTests: string;
|
|
35
|
+
unnamedTests: string;
|
|
36
|
+
patternTests: string;
|
|
37
|
+
};
|
|
38
|
+
export type ReachEdge = {
|
|
39
|
+
fromKey: string;
|
|
40
|
+
toKey: string;
|
|
41
|
+
};
|
|
42
|
+
export type Reach = {
|
|
43
|
+
nodes: ReachNode[];
|
|
44
|
+
edges: ReachEdge[];
|
|
45
|
+
};
|
|
46
|
+
export declare const reachOf: (symbols: SymbolGraph, { unused, patternTests }: UnusedOutput) => Reach;
|
|
47
|
+
export type ReachChanges = {
|
|
48
|
+
removedNodes: string[];
|
|
49
|
+
savedNodes: ReachNode[];
|
|
50
|
+
removedEdges: ReachEdge[];
|
|
51
|
+
addedEdges: ReachEdge[];
|
|
52
|
+
};
|
|
53
|
+
export declare const reachChangesOf: (before: Reach, after: Reach) => ReachChanges;
|