@featurevisor/core 3.1.0 → 3.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.
Files changed (213) hide show
  1. package/lib/datasource/datasource.d.ts +1 -1
  2. package/lib/datasource/datasource.js +4 -14
  3. package/lib/datasource/datasource.js.map +1 -1
  4. package/lib/datasource/requiredFeatures.d.ts +7 -0
  5. package/lib/datasource/requiredFeatures.js +38 -0
  6. package/lib/datasource/requiredFeatures.js.map +1 -0
  7. package/lib/linter/checkCircularDependency.d.ts +1 -1
  8. package/lib/linter/checkCircularDependency.js +3 -22
  9. package/lib/linter/checkCircularDependency.js.map +1 -1
  10. package/lib/linter/conditionSchema.js +27 -3
  11. package/lib/linter/conditionSchema.js.map +1 -1
  12. package/lib/linter/testSchema.d.ts +4 -0
  13. package/lib/linter/testSchema.js +46 -4
  14. package/lib/linter/testSchema.js.map +1 -1
  15. package/lib/promoter/index.js +62 -1
  16. package/lib/promoter/index.js.map +1 -1
  17. package/lib/tester/testFeature.js +17 -16
  18. package/lib/tester/testFeature.js.map +1 -1
  19. package/package.json +10 -7
  20. package/CHANGELOG.md +0 -2246
  21. package/coverage/clover.xml +0 -5456
  22. package/coverage/coverage-final.json +0 -64
  23. package/coverage/lcov-report/base.css +0 -224
  24. package/coverage/lcov-report/block-navigation.js +0 -87
  25. package/coverage/lcov-report/favicon.png +0 -0
  26. package/coverage/lcov-report/index.html +0 -371
  27. package/coverage/lcov-report/prettify.css +0 -1
  28. package/coverage/lcov-report/prettify.js +0 -2
  29. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  30. package/coverage/lcov-report/sorter.js +0 -210
  31. package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
  32. package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
  33. package/coverage/lcov-report/src/benchmark/index.html +0 -116
  34. package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
  35. package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
  36. package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
  37. package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
  38. package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
  39. package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
  40. package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
  41. package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
  42. package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
  43. package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
  44. package/coverage/lcov-report/src/builder/index.html +0 -311
  45. package/coverage/lcov-report/src/builder/index.ts.html +0 -91
  46. package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
  47. package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
  48. package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
  49. package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
  50. package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
  51. package/coverage/lcov-report/src/cli/index.html +0 -131
  52. package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
  53. package/coverage/lcov-report/src/config/index.html +0 -131
  54. package/coverage/lcov-report/src/config/index.ts.html +0 -88
  55. package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
  56. package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
  57. package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
  58. package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
  59. package/coverage/lcov-report/src/datasource/index.html +0 -161
  60. package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
  61. package/coverage/lcov-report/src/evaluate/index.html +0 -116
  62. package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
  63. package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
  64. package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
  65. package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
  66. package/coverage/lcov-report/src/find-usage/index.html +0 -116
  67. package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
  68. package/coverage/lcov-report/src/generate-code/index.html +0 -131
  69. package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
  70. package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
  71. package/coverage/lcov-report/src/index.html +0 -131
  72. package/coverage/lcov-report/src/info/index.html +0 -116
  73. package/coverage/lcov-report/src/info/index.ts.html +0 -472
  74. package/coverage/lcov-report/src/init/index.html +0 -116
  75. package/coverage/lcov-report/src/init/index.ts.html +0 -280
  76. package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
  77. package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
  78. package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
  79. package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
  80. package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
  81. package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
  82. package/coverage/lcov-report/src/linter/index.html +0 -326
  83. package/coverage/lcov-report/src/linter/index.ts.html +0 -88
  84. package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
  85. package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
  86. package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
  87. package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
  88. package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
  89. package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
  90. package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
  91. package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
  92. package/coverage/lcov-report/src/list/index.html +0 -131
  93. package/coverage/lcov-report/src/list/index.ts.html +0 -2065
  94. package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
  95. package/coverage/lcov-report/src/promoter/index.html +0 -116
  96. package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
  97. package/coverage/lcov-report/src/sets.ts.html +0 -313
  98. package/coverage/lcov-report/src/targeting.ts.html +0 -403
  99. package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
  100. package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
  101. package/coverage/lcov-report/src/tester/index.html +0 -206
  102. package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
  103. package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
  104. package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
  105. package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
  106. package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
  107. package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
  108. package/coverage/lcov-report/src/utils/git.ts.html +0 -559
  109. package/coverage/lcov-report/src/utils/index.html +0 -161
  110. package/coverage/lcov-report/src/utils/index.ts.html +0 -94
  111. package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
  112. package/coverage/lcov.info +0 -11615
  113. package/jest.config.js +0 -22
  114. package/json-schema/README.md +0 -5
  115. package/json-schema/attribute.json +0 -40
  116. package/json-schema/feature.json +0 -394
  117. package/json-schema/segment.json +0 -137
  118. package/src/assess-distribution/index.ts +0 -223
  119. package/src/benchmark/index.ts +0 -236
  120. package/src/builder/allocator.spec.ts +0 -105
  121. package/src/builder/allocator.ts +0 -45
  122. package/src/builder/applyContextToConditions.spec.ts +0 -2677
  123. package/src/builder/applyContextToConditions.ts +0 -139
  124. package/src/builder/applyContextToDatafile.spec.ts +0 -2626
  125. package/src/builder/applyContextToDatafile.ts +0 -229
  126. package/src/builder/applyContextToSegments.spec.ts +0 -1593
  127. package/src/builder/applyContextToSegments.ts +0 -165
  128. package/src/builder/buildDatafile.spec.ts +0 -445
  129. package/src/builder/buildDatafile.ts +0 -656
  130. package/src/builder/buildProject.ts +0 -344
  131. package/src/builder/buildRuntimeDatafiles.ts +0 -57
  132. package/src/builder/getFeatureRanges.ts +0 -61
  133. package/src/builder/hashes.ts +0 -109
  134. package/src/builder/index.ts +0 -2
  135. package/src/builder/mutateVariables.spec.ts +0 -1179
  136. package/src/builder/mutateVariables.ts +0 -112
  137. package/src/builder/mutator.spec.ts +0 -413
  138. package/src/builder/mutator.ts +0 -237
  139. package/src/builder/revision.spec.ts +0 -22
  140. package/src/builder/revision.ts +0 -22
  141. package/src/builder/traffic.spec.ts +0 -946
  142. package/src/builder/traffic.ts +0 -192
  143. package/src/cli/cli.ts +0 -105
  144. package/src/cli/index.ts +0 -2
  145. package/src/cli/plugins.ts +0 -43
  146. package/src/config/index.ts +0 -1
  147. package/src/config/projectConfig.spec.ts +0 -194
  148. package/src/config/projectConfig.ts +0 -280
  149. package/src/datasource/adapter.ts +0 -56
  150. package/src/datasource/datasource.ts +0 -305
  151. package/src/datasource/filesystemAdapter.spec.ts +0 -212
  152. package/src/datasource/filesystemAdapter.ts +0 -497
  153. package/src/datasource/index.ts +0 -3
  154. package/src/dependencies.ts +0 -13
  155. package/src/evaluate/index.ts +0 -243
  156. package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
  157. package/src/find-duplicate-segments/index.ts +0 -74
  158. package/src/find-usage/index.ts +0 -565
  159. package/src/generate-code/index.ts +0 -106
  160. package/src/generate-code/typescript.spec.ts +0 -214
  161. package/src/generate-code/typescript.ts +0 -608
  162. package/src/index.ts +0 -20
  163. package/src/info/index.ts +0 -129
  164. package/src/init/index.ts +0 -65
  165. package/src/linter/attributeSchema.spec.ts +0 -342
  166. package/src/linter/attributeSchema.ts +0 -626
  167. package/src/linter/checkCircularDependency.ts +0 -45
  168. package/src/linter/checkPercentageExceedingSlot.ts +0 -61
  169. package/src/linter/conditionSchema.spec.ts +0 -510
  170. package/src/linter/conditionSchema.ts +0 -713
  171. package/src/linter/featureSchema.spec.ts +0 -1985
  172. package/src/linter/featureSchema.ts +0 -1922
  173. package/src/linter/groupSchema.ts +0 -47
  174. package/src/linter/index.ts +0 -1
  175. package/src/linter/lintProject.spec.ts +0 -336
  176. package/src/linter/lintProject.ts +0 -873
  177. package/src/linter/mutationNotation.spec.ts +0 -704
  178. package/src/linter/mutationNotation.ts +0 -442
  179. package/src/linter/printError.ts +0 -68
  180. package/src/linter/schema.spec.ts +0 -690
  181. package/src/linter/schema.ts +0 -491
  182. package/src/linter/segmentSchema.spec.ts +0 -358
  183. package/src/linter/segmentSchema.ts +0 -18
  184. package/src/linter/targetSchema.spec.ts +0 -159
  185. package/src/linter/targetSchema.ts +0 -46
  186. package/src/linter/testSchema.spec.ts +0 -258
  187. package/src/linter/testSchema.ts +0 -148
  188. package/src/linter/zodHelpers.ts +0 -16
  189. package/src/list/index.spec.ts +0 -135
  190. package/src/list/index.ts +0 -660
  191. package/src/list/matrix.spec.ts +0 -49
  192. package/src/list/matrix.ts +0 -212
  193. package/src/promoter/index.spec.ts +0 -617
  194. package/src/promoter/index.ts +0 -1266
  195. package/src/sets.ts +0 -76
  196. package/src/targeting.spec.ts +0 -74
  197. package/src/targeting.ts +0 -106
  198. package/src/tester/cliFormat.ts +0 -16
  199. package/src/tester/helpers.spec.ts +0 -149
  200. package/src/tester/helpers.ts +0 -76
  201. package/src/tester/index.ts +0 -2
  202. package/src/tester/prettyDuration.ts +0 -34
  203. package/src/tester/printTestResult.ts +0 -84
  204. package/src/tester/testFeature.ts +0 -367
  205. package/src/tester/testProject.spec.ts +0 -50
  206. package/src/tester/testProject.ts +0 -311
  207. package/src/tester/testSegment.ts +0 -77
  208. package/src/utils/extractKeys.ts +0 -136
  209. package/src/utils/git.ts +0 -158
  210. package/src/utils/index.ts +0 -3
  211. package/src/utils/pretty.ts +0 -12
  212. package/tsconfig.cjs.json +0 -13
  213. package/tsconfig.typecheck.json +0 -9
@@ -1,192 +0,0 @@
1
- import type {
2
- Rule,
3
- ExistingFeature,
4
- Traffic,
5
- Variation,
6
- Range,
7
- Percentage,
8
- } from "@featurevisor/types";
9
- import { MAX_BUCKETED_NUMBER } from "@featurevisor/sdk";
10
-
11
- import { getAllocation, getUpdatedAvailableRangesAfterFilling } from "./allocator";
12
-
13
- export function detectIfVariationsChanged(
14
- yamlVariations: Variation[] | undefined, // as exists in latest YAML
15
- existingFeature?: ExistingFeature, // from state file
16
- ): boolean {
17
- if (!existingFeature || typeof existingFeature.variations === "undefined") {
18
- if (Array.isArray(yamlVariations) && yamlVariations.length > 0) {
19
- // feature did not previously have any variations,
20
- // but now variations have been added
21
- return true;
22
- }
23
-
24
- // variations didn't exist before, and not even now
25
- return false;
26
- }
27
-
28
- const checkVariations = Array.isArray(yamlVariations)
29
- ? JSON.stringify(yamlVariations.map(({ value, weight }) => ({ value, weight })))
30
- : undefined;
31
-
32
- return (
33
- JSON.stringify(
34
- existingFeature.variations.map(({ value, weight }) => ({
35
- value,
36
- weight,
37
- })),
38
- ) !== checkVariations
39
- );
40
- }
41
-
42
- export function getRulePercentageDiff(
43
- trafficPercentage: Percentage, // 0 to 100k
44
- existingTrafficRule,
45
- ): number {
46
- if (!existingTrafficRule) {
47
- return 0;
48
- }
49
-
50
- const existingPercentage = existingTrafficRule.percentage;
51
-
52
- return trafficPercentage - existingPercentage;
53
- }
54
-
55
- export function detectIfRangesChanged(
56
- availableRanges: Range[], // as exists in latest YAML
57
- existingFeature?: ExistingFeature, // from state file
58
- ): boolean {
59
- if (!existingFeature) {
60
- return false;
61
- }
62
-
63
- if (!existingFeature.ranges) {
64
- return false;
65
- }
66
-
67
- return JSON.stringify(existingFeature.ranges) !== JSON.stringify(availableRanges);
68
- }
69
-
70
- export function getTraffic(
71
- // from current YAML
72
- variations: Variation[] | undefined,
73
- parsedRules: Rule[],
74
- // from previous release
75
- existingFeature: ExistingFeature | undefined,
76
- // ranges from group slots
77
- ranges?: Range[],
78
- ): Traffic[] {
79
- const result: Traffic[] = [];
80
-
81
- // @NOTE: may be pass from builder directly?
82
- const availableRanges =
83
- ranges && ranges.length > 0 ? ranges : ([[0, MAX_BUCKETED_NUMBER]] as Range[]);
84
-
85
- parsedRules.forEach(function (parsedRule) {
86
- const rulePercentage = parsedRule.percentage; // 0 - 100
87
-
88
- const traffic: Traffic = {
89
- key: parsedRule.key,
90
- segments: parsedRule.segments,
91
- percentage: rulePercentage * (MAX_BUCKETED_NUMBER / 100),
92
- allocation: [],
93
- variationWeights: parsedRule.variationWeights,
94
- variableOverrides: parsedRule.variableOverrides,
95
- };
96
-
97
- // overrides
98
- if (parsedRule.variables) {
99
- traffic.variables = parsedRule.variables;
100
- }
101
-
102
- if (parsedRule.variation) {
103
- traffic.variation = parsedRule.variation;
104
- }
105
-
106
- // detect changes
107
- const variationsChanged = detectIfVariationsChanged(variations, existingFeature);
108
- const existingTrafficRule = existingFeature?.traffic.find((t) => t.key === parsedRule.key);
109
- const rulePercentageDiff = getRulePercentageDiff(traffic.percentage, existingTrafficRule);
110
- const rangesChanged = detectIfRangesChanged(availableRanges, existingFeature);
111
-
112
- const needsRebucketing =
113
- !existingTrafficRule || // new rule
114
- variationsChanged || // variations changed
115
- rulePercentageDiff < 0 || // percentage decreased
116
- rangesChanged || // belongs to a group, and group ranges changed
117
- // @NOTE: this means, if variationWeights is present, it will always rebucket.
118
- // worth checking if we can maintain consistent bucketing for this use case as well.
119
- // but this use case is unlikely to hit in practice because it doesn't matter if the feature itself is 100% rolled out.
120
- traffic.variationWeights; // variation weights overridden
121
-
122
- let updatedAvailableRanges = JSON.parse(JSON.stringify(availableRanges));
123
-
124
- if (existingTrafficRule && existingTrafficRule.allocation && !needsRebucketing) {
125
- // increase: build on top of existing allocations
126
- let existingSum = 0;
127
-
128
- traffic.allocation = existingTrafficRule.allocation.map(function ({ variation, range }) {
129
- const result = {
130
- variation,
131
- range: range,
132
- };
133
-
134
- existingSum += range[1] - range[0];
135
-
136
- return result;
137
- });
138
-
139
- updatedAvailableRanges = getUpdatedAvailableRangesAfterFilling(availableRanges, existingSum);
140
- }
141
-
142
- if (Array.isArray(variations)) {
143
- variations.forEach(function (variation) {
144
- let weight = variation.weight as number;
145
-
146
- if (traffic.variationWeights && traffic.variationWeights[variation.value]) {
147
- // override weight from rule
148
- weight = traffic.variationWeights[variation.value];
149
- }
150
-
151
- const percentage = weight * (MAX_BUCKETED_NUMBER / 100);
152
-
153
- const toFillValue = needsRebucketing
154
- ? percentage * (rulePercentage / 100) // whole value
155
- : (weight / 100) * rulePercentageDiff; // incrementing
156
- const rangesToFill = getAllocation(updatedAvailableRanges, toFillValue);
157
-
158
- rangesToFill.forEach(function (range) {
159
- if (traffic.allocation) {
160
- traffic.allocation.push({
161
- variation: variation.value,
162
- range,
163
- });
164
- }
165
- });
166
-
167
- updatedAvailableRanges = getUpdatedAvailableRangesAfterFilling(
168
- updatedAvailableRanges,
169
- toFillValue,
170
- );
171
- });
172
- }
173
-
174
- if (traffic.allocation) {
175
- traffic.allocation = traffic.allocation.filter((a) => {
176
- if (a.range && a.range[0] === a.range[1]) {
177
- return false;
178
- }
179
-
180
- return true;
181
- });
182
-
183
- if (traffic.allocation.length === 0) {
184
- delete traffic.allocation;
185
- }
186
- }
187
-
188
- result.push(traffic);
189
- });
190
-
191
- return result;
192
- }
package/src/cli/cli.ts DELETED
@@ -1,105 +0,0 @@
1
- import { ProjectConfig } from "../config";
2
- import { Datasource } from "../datasource";
3
-
4
- import { commonPlugins, nonProjectPlugins, projectBasedPlugins } from "./plugins";
5
-
6
- export interface ParsedOptions {
7
- _: string[];
8
- [key: string]: any;
9
- }
10
-
11
- export interface PluginHandlerOptions {
12
- rootDirectoryPath: string;
13
- projectConfig: ProjectConfig;
14
- datasource: Datasource;
15
- parsed: ParsedOptions;
16
- }
17
-
18
- export interface Plugin {
19
- command: string; // single word
20
- handler: (options: PluginHandlerOptions) => Promise<void | boolean>;
21
- examples: {
22
- command: string; // full command usage
23
- description: string;
24
- }[];
25
- }
26
-
27
- export interface RunnerOptions {
28
- rootDirectoryPath: string;
29
-
30
- // optional because Featurevisor CLI can be used without a project
31
- projectConfig?: ProjectConfig;
32
- datasource?: Datasource;
33
- }
34
-
35
- export async function runCLI(runnerOptions: RunnerOptions) {
36
- const yargs = require("yargs");
37
-
38
- let y = yargs(process.argv.slice(2)).usage("Usage: <command> [options]");
39
- const registeredSubcommands: string[] = [];
40
-
41
- const { rootDirectoryPath, projectConfig, datasource } = runnerOptions;
42
-
43
- function registerPlugin(plugin: Plugin) {
44
- const subcommand = plugin.command.split(" ")[0];
45
-
46
- if (registeredSubcommands.includes(subcommand)) {
47
- console.warn(`Plugin "${subcommand}" already registered. Skipping.`);
48
- return;
49
- }
50
-
51
- y = y.command({
52
- command: plugin.command,
53
- handler: async function (parsed: ParsedOptions) {
54
- try {
55
- const result = await plugin.handler({
56
- rootDirectoryPath,
57
- projectConfig,
58
- datasource,
59
- parsed,
60
- } as PluginHandlerOptions);
61
-
62
- if (result === false) {
63
- process.exit(1);
64
- }
65
- } catch (error) {
66
- console.error(error);
67
- process.exit(1);
68
- }
69
- },
70
- });
71
-
72
- for (const example of plugin.examples) {
73
- y = y.example(`$0 ${example.command}`, example.description);
74
- }
75
-
76
- registeredSubcommands.push(subcommand);
77
- }
78
-
79
- // non project-based plugins
80
- if (!projectConfig) {
81
- for (const plugin of nonProjectPlugins) {
82
- registerPlugin(plugin);
83
- }
84
- }
85
-
86
- // project-based plugins
87
- if (projectConfig) {
88
- for (const plugin of [...projectBasedPlugins, ...(projectConfig.plugins || [])]) {
89
- registerPlugin(plugin);
90
- }
91
- }
92
-
93
- // common plugins
94
- for (const plugin of commonPlugins) {
95
- registerPlugin(plugin);
96
- }
97
-
98
- // show help if no command is provided
99
- y.command({
100
- command: "*",
101
- handler() {
102
- y.showHelp();
103
- },
104
- }).argv;
105
- }
package/src/cli/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./cli";
2
- export * from "./plugins";
@@ -1,43 +0,0 @@
1
- import type { Plugin } from "./cli";
2
- import { createCatalogPlugin } from "@featurevisor/catalog";
3
-
4
- import { initPlugin } from "../init";
5
- import { lintPlugin } from "../linter";
6
- import { buildPlugin } from "../builder";
7
- import { testPlugin } from "../tester";
8
- import { generateCodePlugin } from "../generate-code";
9
- import { findDuplicateSegmentsPlugin } from "../find-duplicate-segments";
10
- import { findUsagePlugin } from "../find-usage";
11
- import { benchmarkPlugin } from "../benchmark";
12
- import { configPlugin } from "../config";
13
- import { evaluatePlugin } from "../evaluate";
14
- import { assessDistributionPlugin } from "../assess-distribution";
15
- import { infoPlugin } from "../info";
16
- import { listPlugin } from "../list";
17
- import { promotePlugin } from "../promoter";
18
- import { getProjectSetExecutions } from "../sets";
19
-
20
- // that do not require an existing project
21
- export const nonProjectPlugins: Plugin[] = [initPlugin];
22
-
23
- // that require an existing Featurevisor project
24
- export const projectBasedPlugins: Plugin[] = [
25
- lintPlugin,
26
- buildPlugin,
27
- testPlugin,
28
- generateCodePlugin,
29
- findDuplicateSegmentsPlugin,
30
- findUsagePlugin,
31
- benchmarkPlugin,
32
- configPlugin,
33
- evaluatePlugin,
34
- assessDistributionPlugin,
35
- infoPlugin,
36
- listPlugin,
37
- promotePlugin,
38
- createCatalogPlugin({
39
- getProjectSetExecutions,
40
- }),
41
- ];
42
-
43
- export const commonPlugins: Plugin[] = [];
@@ -1 +0,0 @@
1
- export * from "./projectConfig";
@@ -1,194 +0,0 @@
1
- import * as fs from "fs";
2
- import * as os from "os";
3
- import * as path from "path";
4
-
5
- import {
6
- getProjectConfig,
7
- getProjectConfigForSet,
8
- SETS_DIRECTORY_NAME,
9
- TARGETS_DIRECTORY_NAME,
10
- } from "./projectConfig";
11
-
12
- function createTempProject(configBody: string) {
13
- const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "featurevisor-project-config-"));
14
- fs.writeFileSync(path.join(tempRoot, "featurevisor.config.js"), configBody, "utf8");
15
- return tempRoot;
16
- }
17
-
18
- describe("core: projectConfig", () => {
19
- it("sets project defaults", () => {
20
- const root = createTempProject("module.exports = {};");
21
- const config = getProjectConfig(root);
22
-
23
- expect(config.environments).toBeUndefined();
24
- expect(config.namespaceCharacter).toBe(".");
25
- expect(config.sets).toBe(false);
26
- expect(config.promotionFlows).toBeUndefined();
27
- expect(config.setsDirectoryPath).toBe(path.join(root, SETS_DIRECTORY_NAME));
28
- expect(config.targetsDirectoryPath).toBe(path.join(root, TARGETS_DIRECTORY_NAME));
29
- expect("scopes" in config).toBe(false);
30
- expect("siteExportDirectoryPath" in config).toBe(false);
31
- });
32
-
33
- it("silently ignores obsolete scopes configuration", () => {
34
- const root = createTempProject(
35
- 'module.exports = { scopes: [{ name: "web", context: { platform: "web" } }] };',
36
- );
37
- const config = getProjectConfig(root);
38
-
39
- expect("scopes" in config).toBe(false);
40
- });
41
-
42
- it("throws when sets is not boolean", () => {
43
- const root = createTempProject("module.exports = { sets: 'yes' };");
44
-
45
- expect(() => getProjectConfig(root)).toThrow("Invalid sets: yes. It must be a boolean.");
46
- });
47
-
48
- it("accepts environments when it is an array of strings", () => {
49
- const root = createTempProject('module.exports = { environments: ["staging", "production"] };');
50
- const config = getProjectConfig(root);
51
-
52
- expect(config.environments).toEqual(["staging", "production"]);
53
- });
54
-
55
- it("throws when environments is present but not an array of strings", () => {
56
- const cases = [
57
- {
58
- config: "module.exports = { environments: false };",
59
- message: "Invalid environments: false. It must be an array of strings when defined.",
60
- },
61
- {
62
- config: 'module.exports = { environments: "production" };',
63
- message: "Invalid environments: production. It must be an array of strings when defined.",
64
- },
65
- {
66
- config: "module.exports = { environments: { production: true } };",
67
- message:
68
- "Invalid environments: [object Object]. It must be an array of strings when defined.",
69
- },
70
- {
71
- config: 'module.exports = { environments: ["production", 1] };',
72
- message: "Invalid environments[1]: 1. It must be a string.",
73
- },
74
- ];
75
-
76
- for (const testCase of cases) {
77
- const root = createTempProject(testCase.config);
78
-
79
- expect(() => getProjectConfig(root)).toThrow(testCase.message);
80
- }
81
- });
82
-
83
- it("accepts custom namespaceCharacter values including slash", () => {
84
- const root = createTempProject('module.exports = { namespaceCharacter: "/" };');
85
- const config = getProjectConfig(root);
86
-
87
- expect(config.namespaceCharacter).toBe("/");
88
- });
89
-
90
- it("throws when namespaceCharacter is not a non-empty string", () => {
91
- const cases = [
92
- {
93
- config: "module.exports = { namespaceCharacter: '' };",
94
- message: "Invalid namespaceCharacter: . It must be a non-empty string.",
95
- },
96
- {
97
- config: "module.exports = { namespaceCharacter: 1 };",
98
- message: "Invalid namespaceCharacter: 1. It must be a non-empty string.",
99
- },
100
- ];
101
-
102
- for (const testCase of cases) {
103
- const root = createTempProject(testCase.config);
104
-
105
- expect(() => getProjectConfig(root)).toThrow(testCase.message);
106
- }
107
- });
108
-
109
- it("accepts valid promotionFlows object rules", () => {
110
- const root = createTempProject(
111
- [
112
- "module.exports = {",
113
- " promotionFlows: [",
114
- ' { from: "dev", to: "staging" },',
115
- ' { from: "staging", to: "production" },',
116
- " ],",
117
- "};",
118
- "",
119
- ].join("\n"),
120
- );
121
-
122
- const config = getProjectConfig(root);
123
-
124
- expect(config.promotionFlows).toEqual([
125
- { from: "dev", to: "staging" },
126
- { from: "staging", to: "production" },
127
- ]);
128
- });
129
-
130
- it("rejects invalid promotionFlows shapes", () => {
131
- const cases = [
132
- {
133
- config: "module.exports = { promotionFlows: true };",
134
- message: "Invalid promotionFlows: true. It must be an array.",
135
- },
136
- {
137
- config: 'module.exports = { promotionFlows: ["dev"] };',
138
- message:
139
- 'Invalid promotionFlows[0]: dev. Each entry must be an object with exactly "from" and "to" string fields.',
140
- },
141
- {
142
- config: 'module.exports = { promotionFlows: [{ from: "dev" }] };',
143
- message:
144
- 'Invalid promotionFlows[0]: {"from":"dev"}. Each entry must contain exactly "from" and "to".',
145
- },
146
- {
147
- config:
148
- 'module.exports = { promotionFlows: [{ from: "dev", to: "staging", note: true }] };',
149
- message:
150
- 'Invalid promotionFlows[0]: {"from":"dev","to":"staging","note":true}. Each entry must contain exactly "from" and "to".',
151
- },
152
- {
153
- config: 'module.exports = { promotionFlows: [{ from: "dev", to: 1 }] };',
154
- message:
155
- 'Invalid promotionFlows[0]: {"from":"dev","to":1}. "from" and "to" must be strings.',
156
- },
157
- ];
158
-
159
- for (const testCase of cases) {
160
- const root = createTempProject(testCase.config);
161
-
162
- expect(() => getProjectConfig(root)).toThrow(testCase.message);
163
- }
164
- });
165
-
166
- it("remaps project config paths for a set", () => {
167
- const root = createTempProject("module.exports = { sets: true };");
168
- const config = getProjectConfig(root);
169
- const setConfig = getProjectConfigForSet(config, "staging");
170
- const setRoot = path.join(root, "sets", "staging");
171
-
172
- expect(setConfig.featuresDirectoryPath).toBe(path.join(setRoot, "features"));
173
- expect(setConfig.environments).toBeUndefined();
174
- expect(setConfig.namespaceCharacter).toBe(".");
175
- expect(setConfig.segmentsDirectoryPath).toBe(path.join(setRoot, "segments"));
176
- expect(setConfig.attributesDirectoryPath).toBe(path.join(setRoot, "attributes"));
177
- expect(setConfig.groupsDirectoryPath).toBe(path.join(setRoot, "groups"));
178
- expect(setConfig.schemasDirectoryPath).toBe(path.join(setRoot, "schemas"));
179
- expect(setConfig.targetsDirectoryPath).toBe(path.join(setRoot, "targets"));
180
- expect(setConfig.testsDirectoryPath).toBe(path.join(setRoot, "tests"));
181
- expect(setConfig.stateDirectoryPath).toBe(path.join(root, ".featurevisor", "sets", "staging"));
182
- expect(setConfig.datafilesDirectoryPath).toBe(path.join(root, "datafiles", "staging"));
183
- });
184
-
185
- it("preserves configured environments when remapping project config for a set", () => {
186
- const root = createTempProject(
187
- 'module.exports = { sets: true, environments: ["staging", "production"] };',
188
- );
189
- const config = getProjectConfig(root);
190
- const setConfig = getProjectConfigForSet(config, "staging");
191
-
192
- expect(setConfig.environments).toEqual(["staging", "production"]);
193
- });
194
- });