@featurevisor/core 3.10.0 → 4.0.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/README.md +20 -2
- package/lib/assess-distribution/index.js +6 -2
- package/lib/assess-distribution/index.js.map +1 -1
- package/lib/benchmark/index.d.ts +1 -1
- package/lib/benchmark/index.js +15 -10
- package/lib/benchmark/index.js.map +1 -1
- package/lib/builder/applyContextToConditions.d.ts +5 -4
- package/lib/builder/applyContextToConditions.js +84 -89
- package/lib/builder/applyContextToConditions.js.map +1 -1
- package/lib/builder/applyContextToDatafile.d.ts +2 -2
- package/lib/builder/applyContextToDatafile.js +45 -149
- package/lib/builder/applyContextToDatafile.js.map +1 -1
- package/lib/builder/applyContextToSegments.d.ts +6 -4
- package/lib/builder/applyContextToSegments.js +9 -98
- package/lib/builder/applyContextToSegments.js.map +1 -1
- package/lib/builder/buildDatafile.d.ts +15 -6
- package/lib/builder/buildDatafile.js +320 -220
- package/lib/builder/buildDatafile.js.map +1 -1
- package/lib/builder/buildProject.d.ts +2 -1
- package/lib/builder/buildProject.js +36 -37
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/builder/buildRuntimeDatafiles.js +2 -0
- package/lib/builder/buildRuntimeDatafiles.js.map +1 -1
- package/lib/builder/environments.d.ts +3 -0
- package/lib/builder/environments.js +26 -0
- package/lib/builder/environments.js.map +1 -0
- package/lib/builder/hashes.d.ts +5 -5
- package/lib/builder/hashes.js +82 -100
- package/lib/builder/hashes.js.map +1 -1
- package/lib/builder/inflate.d.ts +7 -0
- package/lib/builder/inflate.js +26 -0
- package/lib/builder/inflate.js.map +1 -0
- package/lib/builder/mutateVariables.d.ts +6 -2
- package/lib/builder/mutateVariables.js +26 -18
- package/lib/builder/mutateVariables.js.map +1 -1
- package/lib/builder/mutationEntries.d.ts +5 -0
- package/lib/builder/mutationEntries.js +23 -0
- package/lib/builder/mutationEntries.js.map +1 -0
- package/lib/builder/mutator.d.ts +4 -2
- package/lib/builder/mutator.js +20 -209
- package/lib/builder/mutator.js.map +1 -1
- package/lib/builder/traffic.d.ts +2 -4
- package/lib/builder/traffic.js +48 -19
- package/lib/builder/traffic.js.map +1 -1
- package/lib/builder/variableOverrideProgram.d.ts +9 -0
- package/lib/builder/variableOverrideProgram.js +147 -0
- package/lib/builder/variableOverrideProgram.js.map +1 -0
- package/lib/catalog.d.ts +23 -0
- package/lib/catalog.js +117 -0
- package/lib/catalog.js.map +1 -0
- package/lib/cli/cli.d.ts +2 -0
- package/lib/cli/cli.js +38 -13
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/options.js +78 -17
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +13 -3
- package/lib/cli/plugins.js.map +1 -1
- package/lib/cli/suggestions.d.ts +4 -0
- package/lib/cli/suggestions.js +61 -0
- package/lib/cli/suggestions.js.map +1 -0
- package/lib/config/allowedConditions.d.ts +9 -0
- package/lib/config/allowedConditions.js +44 -0
- package/lib/config/allowedConditions.js.map +1 -0
- package/lib/config/index.d.ts +1 -0
- package/lib/config/index.js +1 -0
- package/lib/config/index.js.map +1 -1
- package/lib/config/projectConfig.d.ts +9 -3
- package/lib/config/projectConfig.js +68 -11
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/config/removedGroups.d.ts +5 -0
- package/lib/config/removedGroups.js +62 -0
- package/lib/config/removedGroups.js.map +1 -0
- package/lib/datasource/adapter.d.ts +10 -1
- package/lib/datasource/adapter.js.map +1 -1
- package/lib/datasource/attributeNamespaces.d.ts +14 -0
- package/lib/datasource/attributeNamespaces.js +70 -0
- package/lib/datasource/attributeNamespaces.js.map +1 -0
- package/lib/datasource/composition.d.ts +5 -0
- package/lib/datasource/composition.js +19 -0
- package/lib/datasource/composition.js.map +1 -0
- package/lib/datasource/conditions.d.ts +20 -0
- package/lib/datasource/conditions.js +113 -0
- package/lib/datasource/conditions.js.map +1 -0
- package/lib/datasource/datasource.d.ts +18 -12
- package/lib/datasource/datasource.js +137 -76
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/dependencies.d.ts +52 -0
- package/lib/datasource/dependencies.js +347 -0
- package/lib/datasource/dependencies.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +31 -1
- package/lib/datasource/filesystemAdapter.js +581 -99
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/datasource/index.d.ts +3 -0
- package/lib/datasource/index.js +3 -0
- package/lib/datasource/index.js.map +1 -1
- package/lib/datasource/parseError.d.ts +5 -0
- package/lib/datasource/parseError.js +68 -0
- package/lib/datasource/parseError.js.map +1 -0
- package/lib/datasource/testSpecs.d.ts +4 -0
- package/lib/datasource/testSpecs.js +40 -0
- package/lib/datasource/testSpecs.js.map +1 -0
- package/lib/diff/compare.d.ts +9 -0
- package/lib/diff/compare.js +31 -0
- package/lib/diff/compare.js.map +1 -0
- package/lib/diff/details.d.ts +11 -0
- package/lib/diff/details.js +210 -0
- package/lib/diff/details.js.map +1 -0
- package/lib/diff/git.d.ts +28 -0
- package/lib/diff/git.js +195 -0
- package/lib/diff/git.js.map +1 -0
- package/lib/diff/index.d.ts +36 -0
- package/lib/diff/index.js +229 -0
- package/lib/diff/index.js.map +1 -0
- package/lib/error.d.ts +1 -0
- package/lib/error.js +6 -0
- package/lib/error.js.map +1 -1
- package/lib/evaluate/explain.d.ts +15 -2
- package/lib/evaluate/explain.js +273 -79
- package/lib/evaluate/explain.js.map +1 -1
- package/lib/evaluate/index.js +128 -17
- package/lib/evaluate/index.js.map +1 -1
- package/lib/evaluate/probeConditions.d.ts +30 -0
- package/lib/evaluate/probeConditions.js +165 -0
- package/lib/evaluate/probeConditions.js.map +1 -0
- package/lib/evaluate/validateExplanation.js +175 -16
- package/lib/evaluate/validateExplanation.js.map +1 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js +20 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
- package/lib/find-usage/index.d.ts +14 -1
- package/lib/find-usage/index.js +359 -155
- package/lib/find-usage/index.js.map +1 -1
- package/lib/generate-code/typescript.js +156 -60
- package/lib/generate-code/typescript.js.map +1 -1
- package/lib/info/index.js +11 -5
- package/lib/info/index.js.map +1 -1
- package/lib/init/index.js +234 -28
- package/lib/init/index.js.map +1 -1
- package/lib/linter/attributeSchema.d.ts +6 -11
- package/lib/linter/attributeSchema.js +59 -53
- package/lib/linter/attributeSchema.js.map +1 -1
- package/lib/linter/comparisonOperators.d.ts +18 -0
- package/lib/linter/comparisonOperators.js +82 -0
- package/lib/linter/comparisonOperators.js.map +1 -0
- package/lib/linter/composedOverrideSchema.d.ts +5 -0
- package/lib/linter/composedOverrideSchema.js +243 -0
- package/lib/linter/composedOverrideSchema.js.map +1 -0
- package/lib/linter/compositionWarnings.d.ts +8 -0
- package/lib/linter/compositionWarnings.js +212 -0
- package/lib/linter/compositionWarnings.js.map +1 -0
- package/lib/linter/conditionKinds.d.ts +12 -0
- package/lib/linter/conditionKinds.js +129 -0
- package/lib/linter/conditionKinds.js.map +1 -0
- package/lib/linter/conditionSchema.d.ts +8 -2
- package/lib/linter/conditionSchema.js +253 -52
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/contextWarnings.d.ts +13 -0
- package/lib/linter/contextWarnings.js +241 -0
- package/lib/linter/contextWarnings.js.map +1 -0
- package/lib/linter/definitionReferences.d.ts +39 -0
- package/lib/linter/definitionReferences.js +234 -0
- package/lib/linter/definitionReferences.js.map +1 -0
- package/lib/linter/dependencyDepth.d.ts +14 -0
- package/lib/linter/dependencyDepth.js +106 -0
- package/lib/linter/dependencyDepth.js.map +1 -0
- package/lib/linter/diagnostics.d.ts +129 -0
- package/lib/linter/diagnostics.js +84 -0
- package/lib/linter/diagnostics.js.map +1 -0
- package/lib/linter/featureSchema.d.ts +189 -72
- package/lib/linter/featureSchema.js +385 -210
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/lintProject.d.ts +4 -1
- package/lib/linter/lintProject.js +449 -143
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/mutationNotation.d.ts +7 -1
- package/lib/linter/mutationNotation.js +40 -20
- package/lib/linter/mutationNotation.js.map +1 -1
- package/lib/linter/mutationOrder.d.ts +6 -0
- package/lib/linter/mutationOrder.js +105 -0
- package/lib/linter/mutationOrder.js.map +1 -0
- package/lib/linter/mutationResultPaths.d.ts +4 -0
- package/lib/linter/mutationResultPaths.js +131 -0
- package/lib/linter/mutationResultPaths.js.map +1 -0
- package/lib/linter/mutationSchema.d.ts +3 -0
- package/lib/linter/mutationSchema.js +32 -0
- package/lib/linter/mutationSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +3 -0
- package/lib/linter/printError.js +38 -25
- package/lib/linter/printError.js.map +1 -1
- package/lib/linter/regexSafety.d.ts +19 -0
- package/lib/linter/regexSafety.js +307 -0
- package/lib/linter/regexSafety.js.map +1 -0
- package/lib/linter/removedConditionFields.d.ts +10 -0
- package/lib/linter/removedConditionFields.js +47 -0
- package/lib/linter/removedConditionFields.js.map +1 -0
- package/lib/linter/requiredFeaturesSchema.d.ts +2 -2
- package/lib/linter/requiredFeaturesSchema.js +32 -28
- package/lib/linter/requiredFeaturesSchema.js.map +1 -1
- package/lib/linter/requiredVariableCost.d.ts +5 -0
- package/lib/linter/requiredVariableCost.js +60 -0
- package/lib/linter/requiredVariableCost.js.map +1 -0
- package/lib/linter/requiredVariablesSchema.d.ts +13 -0
- package/lib/linter/requiredVariablesSchema.js +498 -0
- package/lib/linter/requiredVariablesSchema.js.map +1 -0
- package/lib/linter/reservedNames.d.ts +12 -0
- package/lib/linter/reservedNames.js +52 -0
- package/lib/linter/reservedNames.js.map +1 -0
- package/lib/linter/schema.d.ts +12 -15
- package/lib/linter/schema.js +108 -26
- package/lib/linter/schema.js.map +1 -1
- package/lib/linter/schemaFormats.d.ts +35 -0
- package/lib/linter/schemaFormats.js +66 -0
- package/lib/linter/schemaFormats.js.map +1 -0
- package/lib/linter/segmentSchema.d.ts +11 -1
- package/lib/linter/segmentSchema.js +12 -2
- package/lib/linter/segmentSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +394 -2
- package/lib/linter/testSchema.js +565 -34
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/linter/variableSchema.d.ts +60 -43
- package/lib/linter/variableSchema.js +459 -60
- package/lib/linter/variableSchema.js.map +1 -1
- package/lib/linter/zodHelpers.d.ts +8 -1
- package/lib/linter/zodHelpers.js +9 -1
- package/lib/linter/zodHelpers.js.map +1 -1
- package/lib/list/index.js +384 -66
- package/lib/list/index.js.map +1 -1
- package/lib/list/matrix.d.ts +2 -2
- package/lib/list/matrix.js +60 -39
- package/lib/list/matrix.js.map +1 -1
- package/lib/list/scenarios.d.ts +8 -0
- package/lib/list/scenarios.js +84 -0
- package/lib/list/scenarios.js.map +1 -0
- package/lib/promoter/index.d.ts +1 -1
- package/lib/promoter/index.js +469 -210
- package/lib/promoter/index.js.map +1 -1
- package/lib/sets.js +14 -5
- package/lib/sets.js.map +1 -1
- package/lib/tester/checks.d.ts +12 -0
- package/lib/tester/checks.js +418 -0
- package/lib/tester/checks.js.map +1 -0
- package/lib/tester/coverage.d.ts +16 -0
- package/lib/tester/coverage.js +64 -0
- package/lib/tester/coverage.js.map +1 -0
- package/lib/tester/datafileKey.d.ts +4 -0
- package/lib/tester/datafileKey.js +18 -0
- package/lib/tester/datafileKey.js.map +1 -0
- package/lib/tester/diagnostics.d.ts +5 -0
- package/lib/tester/diagnostics.js +32 -0
- package/lib/tester/diagnostics.js.map +1 -0
- package/lib/tester/index.d.ts +2 -0
- package/lib/tester/printTestResult.d.ts +3 -2
- package/lib/tester/printTestResult.js +53 -8
- package/lib/tester/printTestResult.js.map +1 -1
- package/lib/tester/provenance.d.ts +21 -0
- package/lib/tester/provenance.js +98 -0
- package/lib/tester/provenance.js.map +1 -0
- package/lib/tester/report.d.ts +78 -0
- package/lib/tester/report.js +246 -0
- package/lib/tester/report.js.map +1 -0
- package/lib/tester/segments.d.ts +23 -0
- package/lib/tester/segments.js +103 -0
- package/lib/tester/segments.js.map +1 -0
- package/lib/tester/testFeature.d.ts +2 -0
- package/lib/tester/testFeature.js +17 -8
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/tester/testProject.d.ts +15 -3
- package/lib/tester/testProject.js +198 -83
- package/lib/tester/testProject.js.map +1 -1
- package/lib/tester/testSegment.d.ts +2 -4
- package/lib/tester/testSegment.js +89 -7
- package/lib/tester/testSegment.js.map +1 -1
- package/lib/tester/testVariable.d.ts +2 -2
- package/lib/tester/testVariable.js +195 -24
- package/lib/tester/testVariable.js.map +1 -1
- package/lib/utils/conditionReferences.d.ts +5 -0
- package/lib/utils/conditionReferences.js +30 -0
- package/lib/utils/conditionReferences.js.map +1 -0
- package/lib/utils/extractKeys.d.ts +7 -3
- package/lib/utils/extractKeys.js +32 -113
- package/lib/utils/extractKeys.js.map +1 -1
- package/lib/utils/git.d.ts +7 -2
- package/lib/utils/git.js +87 -72
- package/lib/utils/git.js.map +1 -1
- package/package.json +11 -8
- package/lib/builder/getFeatureRanges.d.ts +0 -11
- package/lib/builder/getFeatureRanges.js +0 -70
- package/lib/builder/getFeatureRanges.js.map +0 -1
- package/lib/datasource/requiredFeatures.d.ts +0 -14
- package/lib/datasource/requiredFeatures.js +0 -75
- package/lib/datasource/requiredFeatures.js.map +0 -1
- package/lib/linter/checkCircularDependency.d.ts +0 -3
- package/lib/linter/checkCircularDependency.js +0 -8
- package/lib/linter/checkCircularDependency.js.map +0 -1
- package/lib/linter/checkPercentageExceedingSlot.d.ts +0 -3
- package/lib/linter/checkPercentageExceedingSlot.js +0 -45
- package/lib/linter/checkPercentageExceedingSlot.js.map +0 -1
- package/lib/linter/groupSchema.d.ts +0 -11
- package/lib/linter/groupSchema.js +0 -31
- package/lib/linter/groupSchema.js.map +0 -1
package/lib/find-usage/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findUsagePlugin = void 0;
|
|
4
|
+
exports.readArchivedKeys = readArchivedKeys;
|
|
4
5
|
exports.findAllUsageInFeatures = findAllUsageInFeatures;
|
|
5
6
|
exports.findAllUsageInVariables = findAllUsageInVariables;
|
|
6
7
|
exports.findAllUsageInSegments = findAllUsageInSegments;
|
|
@@ -12,168 +13,167 @@ exports.findUnusedAttributes = findUnusedAttributes;
|
|
|
12
13
|
exports.assertFindUsageOptions = assertFindUsageOptions;
|
|
13
14
|
exports.findUsageInProject = findUsageInProject;
|
|
14
15
|
const error_1 = require("../error");
|
|
15
|
-
const
|
|
16
|
+
const diagnostics_1 = require("../linter/diagnostics");
|
|
17
|
+
const conditionReferences_1 = require("../utils/conditionReferences");
|
|
16
18
|
const sets_1 = require("../sets");
|
|
17
19
|
const schemaReferences_1 = require("../utils/schemaReferences");
|
|
18
20
|
const variableOverrides_1 = require("../datasource/variableOverrides");
|
|
19
|
-
const
|
|
21
|
+
const dependencies_1 = require("../datasource/dependencies");
|
|
22
|
+
const scenarios_1 = require("../list/scenarios");
|
|
23
|
+
const checks_1 = require("../tester/checks");
|
|
20
24
|
const cliFormat_1 = require("../tester/cliFormat");
|
|
25
|
+
function addConditionUsage(usage, leaves) {
|
|
26
|
+
for (const leaf of leaves) {
|
|
27
|
+
if (typeof leaf === "string")
|
|
28
|
+
usage.segments.add(leaf);
|
|
29
|
+
else if ("attribute" in leaf)
|
|
30
|
+
usage.attributes.add(leaf.attribute.split(".")[0]);
|
|
31
|
+
else if ("variable" in leaf) {
|
|
32
|
+
if (leaf.feature)
|
|
33
|
+
usage.features.add(leaf.feature);
|
|
34
|
+
else
|
|
35
|
+
usage.variables?.add(leaf.variable);
|
|
36
|
+
}
|
|
37
|
+
else if ("feature" in leaf)
|
|
38
|
+
usage.features.add(leaf.feature);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function addReferencedSegmentUsage(deps, usage) {
|
|
42
|
+
const pending = Array.from(usage.segments);
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
for (let index = 0; index < pending.length; index++) {
|
|
45
|
+
const key = pending[index];
|
|
46
|
+
if (seen.has(key))
|
|
47
|
+
continue;
|
|
48
|
+
seen.add(key);
|
|
49
|
+
if (!(await deps.datasource.segmentExists(key)))
|
|
50
|
+
continue;
|
|
51
|
+
addConditionUsage(usage, (0, conditionReferences_1.conditionLeaves)((await deps.datasource.readSegment(key)).conditions));
|
|
52
|
+
for (const dependency of usage.segments)
|
|
53
|
+
if (!seen.has(dependency))
|
|
54
|
+
pending.push(dependency);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Archived definitions are retired. Their references never keep anything in use. */
|
|
58
|
+
async function readArchivedKeys(deps) {
|
|
59
|
+
const datasource = deps.datasource;
|
|
60
|
+
const collect = async (list, read) => {
|
|
61
|
+
const archived = new Set();
|
|
62
|
+
if (!list || !read)
|
|
63
|
+
return archived;
|
|
64
|
+
for (const key of await list()) {
|
|
65
|
+
try {
|
|
66
|
+
if ((await read(key))?.archived === true)
|
|
67
|
+
archived.add(key);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Unreadable definitions are reported by lint, not here.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return archived;
|
|
74
|
+
};
|
|
75
|
+
const bind = (method) => method?.bind(datasource);
|
|
76
|
+
return {
|
|
77
|
+
features: await collect(bind(datasource.listFeatures), bind(datasource.readFeature)),
|
|
78
|
+
segments: await collect(bind(datasource.listSegments), bind(datasource.readSegment)),
|
|
79
|
+
attributes: await collect(bind(datasource.listAttributes), bind(datasource.readAttribute)),
|
|
80
|
+
variables: await collect(bind(datasource.listVariables), bind(datasource.readVariable)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
21
83
|
async function findAllUsageInFeatures(deps) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
usageInFeatures[featureKey] = {
|
|
84
|
+
const result = {};
|
|
85
|
+
const graph = await (0, dependencies_1.buildDependencyGraph)(deps.datasource);
|
|
86
|
+
for (const key of await deps.datasource.listFeatures()) {
|
|
87
|
+
const feature = await deps.datasource.readFeature(key);
|
|
88
|
+
const usage = {
|
|
28
89
|
features: new Set(),
|
|
29
90
|
segments: new Set(),
|
|
30
91
|
attributes: new Set(),
|
|
92
|
+
variables: new Set(),
|
|
31
93
|
};
|
|
32
|
-
(
|
|
33
|
-
(0,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const overrides = variation.variableOverrides?.[variableKey];
|
|
52
|
-
if (overrides) {
|
|
53
|
-
overrides.forEach((override) => {
|
|
54
|
-
if (override.segments) {
|
|
55
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(override.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
56
|
-
}
|
|
57
|
-
if (override.conditions) {
|
|
58
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(override.conditions).forEach((attributeKey) => usageInFeatures[featureKey].attributes.add(attributeKey));
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
// with environments
|
|
67
|
-
if (Array.isArray(projectConfig.environments)) {
|
|
68
|
-
projectConfig.environments.forEach((environment) => {
|
|
69
|
-
// force
|
|
70
|
-
if (feature.force && feature.force[environment]) {
|
|
71
|
-
feature.force[environment].forEach((force) => {
|
|
72
|
-
if (force.segments) {
|
|
73
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(force.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
74
|
-
}
|
|
75
|
-
if (force.conditions) {
|
|
76
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(force.conditions).forEach((attributeKey) => usageInFeatures[featureKey].attributes.add(attributeKey));
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
// rules
|
|
81
|
-
if (feature.rules && feature.rules[environment]) {
|
|
82
|
-
feature.rules[environment].forEach((rule) => {
|
|
83
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(rule.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
84
|
-
Object.values(rule.variableOverrides || {}).forEach((overrides) => {
|
|
85
|
-
overrides.forEach((override) => {
|
|
86
|
-
if (override.segments) {
|
|
87
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(override.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
88
|
-
}
|
|
89
|
-
if (override.conditions) {
|
|
90
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(override.conditions).forEach((attributeKey) => usageInFeatures[featureKey].attributes.add(attributeKey));
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
// no environments
|
|
99
|
-
if (!Array.isArray(projectConfig.environments)) {
|
|
100
|
-
// force
|
|
101
|
-
if (Array.isArray(feature.force)) {
|
|
102
|
-
feature.force.forEach((force) => {
|
|
103
|
-
if (force.segments) {
|
|
104
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(force.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
105
|
-
}
|
|
106
|
-
if (force.conditions) {
|
|
107
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(force.conditions).forEach((attributeKey) => usageInFeatures[featureKey].attributes.add(attributeKey));
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
// rules
|
|
112
|
-
if (Array.isArray(feature.rules)) {
|
|
113
|
-
feature.rules.forEach((rule) => {
|
|
114
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(rule.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
115
|
-
Object.values(rule.variableOverrides || {}).forEach((overrides) => {
|
|
116
|
-
overrides.forEach((override) => {
|
|
117
|
-
if (override.segments) {
|
|
118
|
-
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(override.segments).forEach((segmentKey) => usageInFeatures[featureKey].segments.add(segmentKey));
|
|
119
|
-
}
|
|
120
|
-
if (override.conditions) {
|
|
121
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(override.conditions).forEach((attributeKey) => usageInFeatures[featureKey].attributes.add(attributeKey));
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
94
|
+
addConditionUsage(usage, (0, conditionReferences_1.definitionConditionLeaves)(feature));
|
|
95
|
+
const structural = await (0, dependencies_1.collectDependencyClosure)(deps.datasource, [(0, dependencies_1.featureFlagNode)(key)], {
|
|
96
|
+
graph,
|
|
97
|
+
});
|
|
98
|
+
structural.features.forEach((reference) => {
|
|
99
|
+
if (reference !== key)
|
|
100
|
+
usage.features.add(reference);
|
|
101
|
+
});
|
|
102
|
+
structural.variables.forEach((reference) => usage.variables.add(reference));
|
|
103
|
+
structural.segments.forEach((reference) => usage.segments.add(reference));
|
|
104
|
+
const bucketBy = feature.bucketBy;
|
|
105
|
+
if (typeof bucketBy === "string")
|
|
106
|
+
usage.attributes.add(bucketBy);
|
|
107
|
+
else if (Array.isArray(bucketBy))
|
|
108
|
+
bucketBy.forEach((reference) => usage.attributes.add(reference));
|
|
109
|
+
else
|
|
110
|
+
bucketBy?.or.forEach((reference) => usage.attributes.add(reference));
|
|
111
|
+
await addReferencedSegmentUsage(deps, usage);
|
|
112
|
+
result[key] = usage;
|
|
128
113
|
}
|
|
129
|
-
return
|
|
114
|
+
return result;
|
|
130
115
|
}
|
|
131
116
|
async function findAllUsageInVariables(deps) {
|
|
132
117
|
const result = {};
|
|
133
|
-
|
|
134
|
-
|
|
118
|
+
const graph = await (0, dependencies_1.buildDependencyGraph)(deps.datasource);
|
|
119
|
+
for (const key of await deps.datasource.listVariables()) {
|
|
120
|
+
const variable = await deps.datasource.readVariable(key);
|
|
135
121
|
const usage = {
|
|
136
122
|
features: new Set(),
|
|
137
123
|
segments: new Set(),
|
|
138
124
|
attributes: new Set(),
|
|
139
125
|
schemas: new Set(),
|
|
126
|
+
variables: new Set(),
|
|
140
127
|
};
|
|
141
|
-
(0, schemaReferences_1.extractSchemaReferences)(variable).forEach((
|
|
128
|
+
(0, schemaReferences_1.extractSchemaReferences)(variable).forEach((reference) => usage.schemas.add(reference));
|
|
142
129
|
const pendingSchemas = Array.from(usage.schemas);
|
|
143
130
|
for (let index = 0; index < pendingSchemas.length; index++) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
usage.schemas.add(dependency);
|
|
149
|
-
pendingSchemas.push(dependency);
|
|
131
|
+
for (const reference of (0, schemaReferences_1.extractSchemaReferences)(await deps.datasource.readSchema(pendingSchemas[index]))) {
|
|
132
|
+
if (!usage.schemas.has(reference)) {
|
|
133
|
+
usage.schemas.add(reference);
|
|
134
|
+
pendingSchemas.push(reference);
|
|
150
135
|
}
|
|
151
136
|
}
|
|
152
137
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
138
|
+
addConditionUsage(usage, (0, conditionReferences_1.definitionConditionLeaves)(variable));
|
|
139
|
+
const structural = await (0, dependencies_1.collectDependencyClosure)(deps.datasource, [(0, dependencies_1.variableNode)(key)], {
|
|
140
|
+
graph,
|
|
141
|
+
});
|
|
142
|
+
structural.features.forEach((reference) => usage.features.add(reference));
|
|
143
|
+
structural.variables.forEach((reference) => {
|
|
144
|
+
if (reference !== key)
|
|
145
|
+
usage.variables.add(reference);
|
|
158
146
|
});
|
|
159
|
-
|
|
147
|
+
structural.segments.forEach((reference) => usage.segments.add(reference));
|
|
148
|
+
await addReferencedSegmentUsage(deps, usage);
|
|
149
|
+
result[key] = usage;
|
|
160
150
|
}
|
|
161
151
|
return result;
|
|
162
152
|
}
|
|
163
153
|
async function findAllUsageInSegments(deps) {
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
154
|
+
const result = {};
|
|
155
|
+
const graph = await (0, dependencies_1.buildDependencyGraph)(deps.datasource);
|
|
156
|
+
for (const key of await deps.datasource.listSegments()) {
|
|
157
|
+
const usage = {
|
|
158
|
+
features: new Set(),
|
|
159
|
+
segments: new Set(),
|
|
170
160
|
attributes: new Set(),
|
|
161
|
+
variables: new Set(),
|
|
171
162
|
};
|
|
172
|
-
(0,
|
|
173
|
-
|
|
163
|
+
addConditionUsage(usage, (0, conditionReferences_1.conditionLeaves)((await deps.datasource.readSegment(key)).conditions));
|
|
164
|
+
const structural = await (0, dependencies_1.collectDependencyClosure)(deps.datasource, [(0, dependencies_1.segmentNode)(key)], {
|
|
165
|
+
graph,
|
|
166
|
+
});
|
|
167
|
+
structural.features.forEach((reference) => usage.features.add(reference));
|
|
168
|
+
structural.variables.forEach((reference) => usage.variables.add(reference));
|
|
169
|
+
structural.segments.forEach((reference) => {
|
|
170
|
+
if (reference !== key)
|
|
171
|
+
usage.segments.add(reference);
|
|
174
172
|
});
|
|
173
|
+
await addReferencedSegmentUsage(deps, usage);
|
|
174
|
+
result[key] = usage;
|
|
175
175
|
}
|
|
176
|
-
return
|
|
176
|
+
return result;
|
|
177
177
|
}
|
|
178
178
|
async function findFeatureUsage(usageInFeatures, searchFeatureKey) {
|
|
179
179
|
const usedInFeatures = new Set();
|
|
@@ -213,16 +213,31 @@ async function findAttributeUsage(usageInFeatures, usageInSegments, attributeKey
|
|
|
213
213
|
async function findUnusedSegments(deps, usageInFeatures, usageInVariables = {}) {
|
|
214
214
|
const { datasource } = deps;
|
|
215
215
|
const unusedSegments = new Set();
|
|
216
|
+
const archived = await readArchivedKeys(deps);
|
|
216
217
|
const allSegmentKeys = await datasource.listSegments();
|
|
217
218
|
const usedSegmentKeys = new Set();
|
|
218
219
|
for (const featureKey in usageInFeatures) {
|
|
220
|
+
if (archived.features.has(featureKey))
|
|
221
|
+
continue;
|
|
219
222
|
usageInFeatures[featureKey].segments.forEach((segmentKey) => {
|
|
220
223
|
usedSegmentKeys.add(segmentKey);
|
|
221
224
|
});
|
|
222
225
|
}
|
|
223
|
-
|
|
226
|
+
for (const [variableKey, usage] of Object.entries(usageInVariables)) {
|
|
227
|
+
if (archived.variables.has(variableKey))
|
|
228
|
+
continue;
|
|
229
|
+
usage.segments.forEach((segmentKey) => usedSegmentKeys.add(segmentKey));
|
|
230
|
+
}
|
|
231
|
+
for (const key of allSegmentKeys) {
|
|
232
|
+
if (archived.segments.has(key))
|
|
233
|
+
continue;
|
|
234
|
+
for (const leaf of (0, conditionReferences_1.conditionLeaves)((await datasource.readSegment(key)).conditions)) {
|
|
235
|
+
if (typeof leaf === "string")
|
|
236
|
+
usedSegmentKeys.add(leaf);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
224
239
|
allSegmentKeys.forEach((segmentKey) => {
|
|
225
|
-
if (!usedSegmentKeys.has(segmentKey)) {
|
|
240
|
+
if (!usedSegmentKeys.has(segmentKey) && !archived.segments.has(segmentKey)) {
|
|
226
241
|
unusedSegments.add(segmentKey);
|
|
227
242
|
}
|
|
228
243
|
});
|
|
@@ -231,21 +246,30 @@ async function findUnusedSegments(deps, usageInFeatures, usageInVariables = {})
|
|
|
231
246
|
async function findUnusedAttributes(deps, usageInFeatures, usageInSegments, usageInVariables = {}) {
|
|
232
247
|
const { datasource } = deps;
|
|
233
248
|
const unusedAttributes = new Set();
|
|
249
|
+
const archived = await readArchivedKeys(deps);
|
|
234
250
|
const allAttributeKeys = await datasource.listAttributes();
|
|
235
251
|
const usedAttributeKeys = new Set();
|
|
236
252
|
for (const featureKey in usageInFeatures) {
|
|
253
|
+
if (archived.features.has(featureKey))
|
|
254
|
+
continue;
|
|
237
255
|
usageInFeatures[featureKey].attributes.forEach((attributeKey) => {
|
|
238
256
|
usedAttributeKeys.add(attributeKey);
|
|
239
257
|
});
|
|
240
258
|
}
|
|
241
259
|
for (const segmentKey in usageInSegments) {
|
|
260
|
+
if (archived.segments.has(segmentKey))
|
|
261
|
+
continue;
|
|
242
262
|
usageInSegments[segmentKey].attributes.forEach((attributeKey) => {
|
|
243
263
|
usedAttributeKeys.add(attributeKey);
|
|
244
264
|
});
|
|
245
265
|
}
|
|
246
|
-
|
|
266
|
+
for (const [variableKey, usage] of Object.entries(usageInVariables)) {
|
|
267
|
+
if (archived.variables.has(variableKey))
|
|
268
|
+
continue;
|
|
269
|
+
usage.attributes.forEach((attributeKey) => usedAttributeKeys.add(attributeKey));
|
|
270
|
+
}
|
|
247
271
|
allAttributeKeys.forEach((attributeKey) => {
|
|
248
|
-
if (!usedAttributeKeys.has(attributeKey)) {
|
|
272
|
+
if (!usedAttributeKeys.has(attributeKey) && !archived.attributes.has(attributeKey)) {
|
|
249
273
|
unusedAttributes.add(attributeKey);
|
|
250
274
|
}
|
|
251
275
|
});
|
|
@@ -269,14 +293,134 @@ function assertFindUsageOptions(options) {
|
|
|
269
293
|
});
|
|
270
294
|
}
|
|
271
295
|
}
|
|
296
|
+
function requiresVariable(value, key) {
|
|
297
|
+
return (0, conditionReferences_1.conditionLeaves)(value).some((required) => typeof required !== "string" &&
|
|
298
|
+
"variable" in required &&
|
|
299
|
+
!required.feature &&
|
|
300
|
+
required.variable === key);
|
|
301
|
+
}
|
|
302
|
+
async function findVariableReferenceSites(deps, variableKey, mark = (_type, key) => key) {
|
|
303
|
+
const overrideSites = new Set();
|
|
304
|
+
const requiredByFeatures = new Set();
|
|
305
|
+
const requiredByVariables = new Set();
|
|
306
|
+
const composedBy = new Set();
|
|
307
|
+
const aliasedBy = new Set();
|
|
308
|
+
const testChecks = new Set();
|
|
309
|
+
const requiredBySegments = new Set();
|
|
310
|
+
for (const key of await deps.datasource.listSegments()) {
|
|
311
|
+
if (requiresVariable((await deps.datasource.readSegment(key)).conditions, variableKey))
|
|
312
|
+
requiredBySegments.add(key);
|
|
313
|
+
}
|
|
314
|
+
for (const featureKey of await deps.datasource.listFeatures()) {
|
|
315
|
+
const feature = await deps.datasource.readFeature(featureKey);
|
|
316
|
+
if ((0, conditionReferences_1.definitionConditionLeaves)(feature).some((leaf) => typeof leaf !== "string" &&
|
|
317
|
+
"variable" in leaf &&
|
|
318
|
+
!leaf.feature &&
|
|
319
|
+
leaf.variable === variableKey)) {
|
|
320
|
+
requiredByFeatures.add(featureKey);
|
|
321
|
+
}
|
|
322
|
+
const collect = (overrides, site) => {
|
|
323
|
+
for (const [key, entries] of Object.entries(overrides || {})) {
|
|
324
|
+
if (entries.some((entry) => requiresVariable(entry.conditions, variableKey))) {
|
|
325
|
+
overrideSites.add(`feature ${mark("feature", featureKey)}, ${site}, variable ${key}`);
|
|
326
|
+
requiredByFeatures.add(featureKey);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
for (const variation of feature.variations || []) {
|
|
331
|
+
collect(variation.variableOverrides, `variation ${variation.value}`);
|
|
332
|
+
}
|
|
333
|
+
const ruleGroups = Array.isArray(feature.rules)
|
|
334
|
+
? [["default", feature.rules]]
|
|
335
|
+
: Object.entries(feature.rules || {});
|
|
336
|
+
for (const [environment, rules] of ruleGroups) {
|
|
337
|
+
if (!Array.isArray(rules))
|
|
338
|
+
continue;
|
|
339
|
+
for (const rule of rules)
|
|
340
|
+
collect(rule.variableOverrides, `rule ${rule.key} (${environment})`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
for (const ownerKey of await deps.datasource.listVariables()) {
|
|
344
|
+
const variable = await deps.datasource.readVariable(ownerKey);
|
|
345
|
+
if (requiresVariable(variable.conditions, variableKey)) {
|
|
346
|
+
requiredByVariables.add(ownerKey);
|
|
347
|
+
}
|
|
348
|
+
if (typeof variable.compose === "string") {
|
|
349
|
+
if (variable.compose === variableKey)
|
|
350
|
+
aliasedBy.add(ownerKey);
|
|
351
|
+
}
|
|
352
|
+
else if (Object.values(variable.compose || {}).some((source) => source.feature === undefined && source.variable === variableKey)) {
|
|
353
|
+
composedBy.add(ownerKey);
|
|
354
|
+
}
|
|
355
|
+
for (const override of (0, variableOverrides_1.flattenVariableOverrides)(variable.overrides)) {
|
|
356
|
+
if (requiresVariable(override.conditions, variableKey)) {
|
|
357
|
+
overrideSites.add(`global variable ${mark("variable", ownerKey)}, override ${override.key}`);
|
|
358
|
+
requiredByVariables.add(ownerKey);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (deps.datasource.listTests && deps.datasource.listScenarios) {
|
|
363
|
+
for (const test of await (0, scenarios_1.listTestSpecs)(deps.datasource)) {
|
|
364
|
+
const owner = "variable" in test ? test.variable : undefined;
|
|
365
|
+
for (const assertion of test.assertions || []) {
|
|
366
|
+
for (const expectation of [
|
|
367
|
+
assertion,
|
|
368
|
+
...("children" in assertion ? assertion.children || [] : []),
|
|
369
|
+
]) {
|
|
370
|
+
if (!("checks" in expectation) || !expectation.checks)
|
|
371
|
+
continue;
|
|
372
|
+
if ((0, checks_1.getCheckReferences)(expectation.checks, owner).some((reference) => !reference.feature && (reference.variable || owner) === variableKey))
|
|
373
|
+
testChecks.add(test.key || ("scenario" in test ? test.scenario : owner || ""));
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
overrideSites,
|
|
380
|
+
requiredByFeatures,
|
|
381
|
+
requiredBySegments,
|
|
382
|
+
requiredByVariables,
|
|
383
|
+
composedBy,
|
|
384
|
+
aliasedBy,
|
|
385
|
+
testChecks,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
272
388
|
async function findUsageInProject(deps, options) {
|
|
273
389
|
const { datasource } = deps;
|
|
274
390
|
console.log("");
|
|
275
391
|
console.log(cliFormat_1.CLI_FORMAT_BOLD, "Finding Featurevisor usage");
|
|
276
392
|
console.log("");
|
|
393
|
+
for (const [type, key, list] of [
|
|
394
|
+
["feature", options.feature, () => datasource.listFeatures()],
|
|
395
|
+
["segment", options.segment, () => datasource.listSegments()],
|
|
396
|
+
["attribute", options.attribute?.split(".")[0], () => datasource.listAttributes()],
|
|
397
|
+
]) {
|
|
398
|
+
if (!key)
|
|
399
|
+
continue;
|
|
400
|
+
const keys = await list();
|
|
401
|
+
if (keys.includes(key))
|
|
402
|
+
continue;
|
|
403
|
+
const namespaced = deps.projectConfig?.namespaceCharacter || ".";
|
|
404
|
+
const alternative = key.replace(/[./]/g, namespaced);
|
|
405
|
+
const hint = keys.includes(alternative)
|
|
406
|
+
? ` Did you mean "${alternative}"? This project separates namespaces with "${namespaced}".`
|
|
407
|
+
: (0, diagnostics_1.suggestKey)(key, keys);
|
|
408
|
+
throw new error_1.FeaturevisorCLIError(`Unknown ${type} "${type === "attribute" ? options.attribute : key}".${hint}`, {
|
|
409
|
+
code: type === "feature"
|
|
410
|
+
? "feature_not_found"
|
|
411
|
+
: type === "segment"
|
|
412
|
+
? "segment_not_found"
|
|
413
|
+
: "attribute_not_found",
|
|
414
|
+
details: { [type]: key },
|
|
415
|
+
});
|
|
416
|
+
}
|
|
277
417
|
const usageInFeatures = await findAllUsageInFeatures(deps);
|
|
278
418
|
const usageInSegments = await findAllUsageInSegments(deps);
|
|
279
419
|
const usageInVariables = await findAllUsageInVariables(deps);
|
|
420
|
+
const archived = await readArchivedKeys(deps);
|
|
421
|
+
const mark = (type, key) => archived[type === "feature" ? "features" : type === "segment" ? "segments" : "variables"].has(key)
|
|
422
|
+
? `${key} ${(0, cliFormat_1.colorize)("(archived)", cliFormat_1.CLI_COLOR_DIM)}`
|
|
423
|
+
: key;
|
|
280
424
|
if (options.variable) {
|
|
281
425
|
const usage = usageInVariables[options.variable];
|
|
282
426
|
if (!usage) {
|
|
@@ -289,6 +433,7 @@ async function findUsageInProject(deps, options) {
|
|
|
289
433
|
console.log("");
|
|
290
434
|
const groups = [
|
|
291
435
|
["Features", usage.features],
|
|
436
|
+
["Variables", usage.variables || new Set()],
|
|
292
437
|
["Segments", usage.segments],
|
|
293
438
|
["Attributes", usage.attributes],
|
|
294
439
|
["Schemas", usage.schemas],
|
|
@@ -303,13 +448,63 @@ async function findUsageInProject(deps, options) {
|
|
|
303
448
|
if (!found)
|
|
304
449
|
console.log(cliFormat_1.CLI_FORMAT_GREEN, " No dependencies.");
|
|
305
450
|
console.log("");
|
|
451
|
+
const { overrideSites, requiredByFeatures, requiredBySegments, requiredByVariables, composedBy, aliasedBy, testChecks, } = await findVariableReferenceSites(deps, options.variable, mark);
|
|
452
|
+
console.log(cliFormat_1.CLI_FORMAT_BOLD, `References to global variable "${options.variable}"`);
|
|
453
|
+
console.log("");
|
|
454
|
+
console.log(" Direct references only.");
|
|
455
|
+
const references = [
|
|
456
|
+
["Aliased by", Array.from(aliasedBy, (key) => mark("variable", key)), false],
|
|
457
|
+
["Composed by", Array.from(composedBy, (key) => mark("variable", key)), false],
|
|
458
|
+
[
|
|
459
|
+
"Conditions in features",
|
|
460
|
+
Array.from(requiredByFeatures, (key) => mark("feature", key)),
|
|
461
|
+
false,
|
|
462
|
+
],
|
|
463
|
+
[
|
|
464
|
+
"Conditions in global variables",
|
|
465
|
+
Array.from(requiredByVariables, (key) => mark("variable", key)),
|
|
466
|
+
false,
|
|
467
|
+
],
|
|
468
|
+
[
|
|
469
|
+
"Conditions in segments",
|
|
470
|
+
Array.from(requiredBySegments, (key) => mark("segment", key)),
|
|
471
|
+
false,
|
|
472
|
+
],
|
|
473
|
+
["Override conditions", Array.from(overrideSites), true],
|
|
474
|
+
["Test checks", Array.from(testChecks), true],
|
|
475
|
+
];
|
|
476
|
+
let hasReferences = false;
|
|
477
|
+
for (const [label, keys, multiline] of references) {
|
|
478
|
+
if (!keys.length)
|
|
479
|
+
continue;
|
|
480
|
+
hasReferences = true;
|
|
481
|
+
if (multiline) {
|
|
482
|
+
console.log(` ${(0, cliFormat_1.colorize)(label, cliFormat_1.CLI_COLOR_CYAN)}:`);
|
|
483
|
+
for (const key of keys.sort())
|
|
484
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key}`);
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
console.log(` ${(0, cliFormat_1.colorize)(label, cliFormat_1.CLI_COLOR_CYAN)}: ${keys.sort().join(", ")}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (!hasReferences)
|
|
491
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, " No project references found.");
|
|
492
|
+
console.log("");
|
|
306
493
|
return;
|
|
307
494
|
}
|
|
308
495
|
// feature
|
|
309
496
|
if (options.feature) {
|
|
310
497
|
const usedInFeatures = await findFeatureUsage(usageInFeatures, options.feature);
|
|
311
498
|
const usedInVariables = Object.keys(usageInVariables).filter((key) => usageInVariables[key].features.has(options.feature));
|
|
312
|
-
|
|
499
|
+
const usedInSegments = Object.keys(usageInSegments).filter((key) => usageInSegments[key].features?.has(options.feature));
|
|
500
|
+
if (usedInSegments.length) {
|
|
501
|
+
console.log(cliFormat_1.CLI_FORMAT_BOLD, `Feature "${options.feature}" is used in these segments`);
|
|
502
|
+
console.log("");
|
|
503
|
+
for (const key of usedInSegments)
|
|
504
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("segment", key)}`);
|
|
505
|
+
console.log("");
|
|
506
|
+
}
|
|
507
|
+
if (usedInFeatures.size === 0 && usedInVariables.length === 0 && usedInSegments.length === 0) {
|
|
313
508
|
console.log(cliFormat_1.CLI_FORMAT_GREEN, `Feature "${options.feature}" is not used by other entities.`);
|
|
314
509
|
}
|
|
315
510
|
else if (usedInFeatures.size > 0) {
|
|
@@ -319,10 +514,10 @@ async function findUsageInProject(deps, options) {
|
|
|
319
514
|
if (options.authors) {
|
|
320
515
|
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
321
516
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
322
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
517
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
323
518
|
}
|
|
324
519
|
else {
|
|
325
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey}`);
|
|
520
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)}`);
|
|
326
521
|
}
|
|
327
522
|
}
|
|
328
523
|
}
|
|
@@ -333,10 +528,10 @@ async function findUsageInProject(deps, options) {
|
|
|
333
528
|
if (options.authors) {
|
|
334
529
|
const entries = await datasource.listHistoryEntries("variable", key);
|
|
335
530
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
336
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
531
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("variable", key)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
337
532
|
}
|
|
338
533
|
else {
|
|
339
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key}`);
|
|
534
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("variable", key)}`);
|
|
340
535
|
}
|
|
341
536
|
}
|
|
342
537
|
console.log("");
|
|
@@ -347,8 +542,16 @@ async function findUsageInProject(deps, options) {
|
|
|
347
542
|
if (options.segment) {
|
|
348
543
|
const usedInFeatures = await findSegmentUsage(usageInFeatures, options.segment);
|
|
349
544
|
const usedInVariables = Object.keys(usageInVariables).filter((key) => usageInVariables[key].segments.has(options.segment));
|
|
350
|
-
|
|
351
|
-
|
|
545
|
+
const usedInSegments = Object.keys(usageInSegments).filter((key) => usageInSegments[key].segments?.has(options.segment));
|
|
546
|
+
if (usedInSegments.length) {
|
|
547
|
+
console.log(cliFormat_1.CLI_FORMAT_BOLD, `Segment "${options.segment}" is used in these segments`);
|
|
548
|
+
console.log("");
|
|
549
|
+
for (const key of usedInSegments)
|
|
550
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("segment", key)}`);
|
|
551
|
+
console.log("");
|
|
552
|
+
}
|
|
553
|
+
if (usedInFeatures.size === 0 && usedInVariables.length === 0 && usedInSegments.length === 0) {
|
|
554
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, `Segment "${options.segment}" is not used in any features, variables or segments.`);
|
|
352
555
|
}
|
|
353
556
|
else if (usedInFeatures.size > 0) {
|
|
354
557
|
console.log(cliFormat_1.CLI_FORMAT_BOLD, `Segment "${options.segment}" is used in these features`);
|
|
@@ -357,10 +560,10 @@ async function findUsageInProject(deps, options) {
|
|
|
357
560
|
if (options.authors) {
|
|
358
561
|
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
359
562
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
360
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
563
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
361
564
|
}
|
|
362
565
|
else {
|
|
363
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey}`);
|
|
566
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)}`);
|
|
364
567
|
}
|
|
365
568
|
}
|
|
366
569
|
}
|
|
@@ -371,10 +574,10 @@ async function findUsageInProject(deps, options) {
|
|
|
371
574
|
if (options.authors) {
|
|
372
575
|
const entries = await datasource.listHistoryEntries("variable", key);
|
|
373
576
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
374
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
577
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("variable", key)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
375
578
|
}
|
|
376
579
|
else {
|
|
377
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key}`);
|
|
580
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("variable", key)}`);
|
|
378
581
|
}
|
|
379
582
|
}
|
|
380
583
|
console.log("");
|
|
@@ -396,10 +599,10 @@ async function findUsageInProject(deps, options) {
|
|
|
396
599
|
if (options.authors) {
|
|
397
600
|
const entries = await datasource.listHistoryEntries("segment", segmentKey);
|
|
398
601
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
399
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${segmentKey} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
602
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("segment", segmentKey)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
400
603
|
}
|
|
401
604
|
else {
|
|
402
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${segmentKey}`);
|
|
605
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("segment", segmentKey)}`);
|
|
403
606
|
}
|
|
404
607
|
}
|
|
405
608
|
// features affected by above segments
|
|
@@ -416,10 +619,10 @@ async function findUsageInProject(deps, options) {
|
|
|
416
619
|
if (options.authors) {
|
|
417
620
|
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
418
621
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
419
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
622
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
420
623
|
}
|
|
421
624
|
else {
|
|
422
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey}`);
|
|
625
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)}`);
|
|
423
626
|
}
|
|
424
627
|
}
|
|
425
628
|
console.log("");
|
|
@@ -432,10 +635,10 @@ async function findUsageInProject(deps, options) {
|
|
|
432
635
|
if (options.authors) {
|
|
433
636
|
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
434
637
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
435
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
638
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
436
639
|
}
|
|
437
640
|
else {
|
|
438
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${featureKey}`);
|
|
641
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("feature", featureKey)}`);
|
|
439
642
|
}
|
|
440
643
|
}
|
|
441
644
|
console.log("");
|
|
@@ -447,10 +650,10 @@ async function findUsageInProject(deps, options) {
|
|
|
447
650
|
if (options.authors) {
|
|
448
651
|
const entries = await datasource.listHistoryEntries("variable", key);
|
|
449
652
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
450
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
653
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("variable", key)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
451
654
|
}
|
|
452
655
|
else {
|
|
453
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${key}`);
|
|
656
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("variable", key)}`);
|
|
454
657
|
}
|
|
455
658
|
}
|
|
456
659
|
console.log("");
|
|
@@ -470,10 +673,10 @@ async function findUsageInProject(deps, options) {
|
|
|
470
673
|
if (options.authors) {
|
|
471
674
|
const entries = await datasource.listHistoryEntries("segment", segmentKey);
|
|
472
675
|
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
473
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${segmentKey} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
676
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("segment", segmentKey)} ${(0, cliFormat_1.colorize)(`(Authors: ${authors.join(", ")})`, cliFormat_1.CLI_COLOR_DIM)}`);
|
|
474
677
|
}
|
|
475
678
|
else {
|
|
476
|
-
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${segmentKey}`);
|
|
679
|
+
console.log(` ${(0, cliFormat_1.colorize)("•", cliFormat_1.CLI_COLOR_CYAN)} ${mark("segment", segmentKey)}`);
|
|
477
680
|
}
|
|
478
681
|
}
|
|
479
682
|
}
|
|
@@ -505,6 +708,7 @@ async function findUsageInProject(deps, options) {
|
|
|
505
708
|
}
|
|
506
709
|
exports.findUsagePlugin = {
|
|
507
710
|
command: "find-usage",
|
|
711
|
+
description: "Find entity dependencies, project references and unused segments or attributes",
|
|
508
712
|
handler: async ({ rootDirectoryPath, projectConfig, datasource, parsed }) => {
|
|
509
713
|
assertFindUsageOptions(parsed);
|
|
510
714
|
const executions = await (0, sets_1.getProjectSetExecutions)(projectConfig, datasource, parsed.set);
|
|
@@ -529,7 +733,7 @@ exports.findUsagePlugin = {
|
|
|
529
733
|
examples: [
|
|
530
734
|
{
|
|
531
735
|
command: "find-usage --variable=<variableKey>",
|
|
532
|
-
description: "Show dependencies of a global variable",
|
|
736
|
+
description: "Show dependencies and project references of a global variable",
|
|
533
737
|
},
|
|
534
738
|
{
|
|
535
739
|
command: "find-usage --segment=<segmentKey>",
|