@featurevisor/core 3.0.1 → 3.2.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/lib/datasource/datasource.d.ts +1 -1
- package/lib/datasource/datasource.js +4 -14
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/requiredFeatures.d.ts +7 -0
- package/lib/datasource/requiredFeatures.js +38 -0
- package/lib/datasource/requiredFeatures.js.map +1 -0
- package/lib/linter/checkCircularDependency.d.ts +1 -1
- package/lib/linter/checkCircularDependency.js +3 -22
- package/lib/linter/checkCircularDependency.js.map +1 -1
- package/lib/linter/conditionSchema.js +27 -3
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/tester/testFeature.js +17 -16
- package/lib/tester/testFeature.js.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -2238
- package/coverage/clover.xml +0 -5456
- package/coverage/coverage-final.json +0 -64
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -371
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
- package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
- package/coverage/lcov-report/src/benchmark/index.html +0 -116
- package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
- package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
- package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
- package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
- package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
- package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
- package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
- package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
- package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
- package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
- package/coverage/lcov-report/src/builder/index.html +0 -311
- package/coverage/lcov-report/src/builder/index.ts.html +0 -91
- package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
- package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
- package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
- package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
- package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
- package/coverage/lcov-report/src/cli/index.html +0 -131
- package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
- package/coverage/lcov-report/src/config/index.html +0 -131
- package/coverage/lcov-report/src/config/index.ts.html +0 -88
- package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
- package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
- package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
- package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
- package/coverage/lcov-report/src/datasource/index.html +0 -161
- package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
- package/coverage/lcov-report/src/evaluate/index.html +0 -116
- package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
- package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
- package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
- package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
- package/coverage/lcov-report/src/find-usage/index.html +0 -116
- package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
- package/coverage/lcov-report/src/generate-code/index.html +0 -131
- package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
- package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/info/index.html +0 -116
- package/coverage/lcov-report/src/info/index.ts.html +0 -472
- package/coverage/lcov-report/src/init/index.html +0 -116
- package/coverage/lcov-report/src/init/index.ts.html +0 -280
- package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
- package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
- package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
- package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
- package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
- package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
- package/coverage/lcov-report/src/linter/index.html +0 -326
- package/coverage/lcov-report/src/linter/index.ts.html +0 -88
- package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
- package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
- package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
- package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
- package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
- package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
- package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
- package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
- package/coverage/lcov-report/src/list/index.html +0 -131
- package/coverage/lcov-report/src/list/index.ts.html +0 -2065
- package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
- package/coverage/lcov-report/src/promoter/index.html +0 -116
- package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
- package/coverage/lcov-report/src/sets.ts.html +0 -313
- package/coverage/lcov-report/src/targeting.ts.html +0 -403
- package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
- package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
- package/coverage/lcov-report/src/tester/index.html +0 -206
- package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
- package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
- package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
- package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
- package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
- package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
- package/coverage/lcov-report/src/utils/git.ts.html +0 -559
- package/coverage/lcov-report/src/utils/index.html +0 -161
- package/coverage/lcov-report/src/utils/index.ts.html +0 -94
- package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
- package/coverage/lcov.info +0 -11615
- package/jest.config.js +0 -22
- package/json-schema/README.md +0 -5
- package/json-schema/attribute.json +0 -40
- package/json-schema/feature.json +0 -394
- package/json-schema/segment.json +0 -137
- package/src/assess-distribution/index.ts +0 -223
- package/src/benchmark/index.ts +0 -236
- package/src/builder/allocator.spec.ts +0 -105
- package/src/builder/allocator.ts +0 -45
- package/src/builder/applyContextToConditions.spec.ts +0 -2677
- package/src/builder/applyContextToConditions.ts +0 -139
- package/src/builder/applyContextToDatafile.spec.ts +0 -2626
- package/src/builder/applyContextToDatafile.ts +0 -229
- package/src/builder/applyContextToSegments.spec.ts +0 -1593
- package/src/builder/applyContextToSegments.ts +0 -165
- package/src/builder/buildDatafile.spec.ts +0 -445
- package/src/builder/buildDatafile.ts +0 -656
- package/src/builder/buildProject.ts +0 -344
- package/src/builder/buildRuntimeDatafiles.ts +0 -57
- package/src/builder/getFeatureRanges.ts +0 -61
- package/src/builder/hashes.ts +0 -109
- package/src/builder/index.ts +0 -2
- package/src/builder/mutateVariables.spec.ts +0 -1179
- package/src/builder/mutateVariables.ts +0 -112
- package/src/builder/mutator.spec.ts +0 -413
- package/src/builder/mutator.ts +0 -237
- package/src/builder/revision.spec.ts +0 -22
- package/src/builder/revision.ts +0 -22
- package/src/builder/traffic.spec.ts +0 -946
- package/src/builder/traffic.ts +0 -192
- package/src/cli/cli.ts +0 -105
- package/src/cli/index.ts +0 -2
- package/src/cli/plugins.ts +0 -43
- package/src/config/index.ts +0 -1
- package/src/config/projectConfig.spec.ts +0 -194
- package/src/config/projectConfig.ts +0 -280
- package/src/datasource/adapter.ts +0 -56
- package/src/datasource/datasource.ts +0 -305
- package/src/datasource/filesystemAdapter.spec.ts +0 -212
- package/src/datasource/filesystemAdapter.ts +0 -497
- package/src/datasource/index.ts +0 -3
- package/src/dependencies.ts +0 -13
- package/src/evaluate/index.ts +0 -243
- package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
- package/src/find-duplicate-segments/index.ts +0 -74
- package/src/find-usage/index.ts +0 -565
- package/src/generate-code/index.ts +0 -106
- package/src/generate-code/typescript.spec.ts +0 -214
- package/src/generate-code/typescript.ts +0 -608
- package/src/index.ts +0 -20
- package/src/info/index.ts +0 -129
- package/src/init/index.ts +0 -65
- package/src/linter/attributeSchema.spec.ts +0 -342
- package/src/linter/attributeSchema.ts +0 -626
- package/src/linter/checkCircularDependency.ts +0 -45
- package/src/linter/checkPercentageExceedingSlot.ts +0 -61
- package/src/linter/conditionSchema.spec.ts +0 -510
- package/src/linter/conditionSchema.ts +0 -713
- package/src/linter/featureSchema.spec.ts +0 -1985
- package/src/linter/featureSchema.ts +0 -1922
- package/src/linter/groupSchema.ts +0 -47
- package/src/linter/index.ts +0 -1
- package/src/linter/lintProject.spec.ts +0 -336
- package/src/linter/lintProject.ts +0 -873
- package/src/linter/mutationNotation.spec.ts +0 -704
- package/src/linter/mutationNotation.ts +0 -442
- package/src/linter/printError.ts +0 -68
- package/src/linter/schema.spec.ts +0 -690
- package/src/linter/schema.ts +0 -491
- package/src/linter/segmentSchema.spec.ts +0 -358
- package/src/linter/segmentSchema.ts +0 -18
- package/src/linter/targetSchema.spec.ts +0 -159
- package/src/linter/targetSchema.ts +0 -46
- package/src/linter/testSchema.spec.ts +0 -258
- package/src/linter/testSchema.ts +0 -148
- package/src/linter/zodHelpers.ts +0 -16
- package/src/list/index.spec.ts +0 -135
- package/src/list/index.ts +0 -660
- package/src/list/matrix.spec.ts +0 -49
- package/src/list/matrix.ts +0 -212
- package/src/promoter/index.spec.ts +0 -617
- package/src/promoter/index.ts +0 -1266
- package/src/sets.ts +0 -76
- package/src/targeting.spec.ts +0 -74
- package/src/targeting.ts +0 -106
- package/src/tester/cliFormat.ts +0 -16
- package/src/tester/helpers.spec.ts +0 -149
- package/src/tester/helpers.ts +0 -76
- package/src/tester/index.ts +0 -2
- package/src/tester/prettyDuration.ts +0 -34
- package/src/tester/printTestResult.ts +0 -84
- package/src/tester/testFeature.ts +0 -367
- package/src/tester/testProject.spec.ts +0 -50
- package/src/tester/testProject.ts +0 -311
- package/src/tester/testSegment.ts +0 -77
- package/src/utils/extractKeys.ts +0 -136
- package/src/utils/git.ts +0 -158
- package/src/utils/index.ts +0 -3
- package/src/utils/pretty.ts +0 -12
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.typecheck.json +0 -9
package/src/builder/mutator.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import type { VariableSchema, VariableValue } from "@featurevisor/types";
|
|
2
|
-
|
|
3
|
-
export type PathPart =
|
|
4
|
-
| { key: string }
|
|
5
|
-
| { key: string; index: number }
|
|
6
|
-
| { key: string; selector: { prop: string; value: string } };
|
|
7
|
-
|
|
8
|
-
export type MutationOperation = "set" | "append" | "prepend" | "after" | "before" | "remove";
|
|
9
|
-
|
|
10
|
-
export interface ParsedNotation {
|
|
11
|
-
segments: PathPart[];
|
|
12
|
-
operation: MutationOperation;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function parseNotation(notation: string): ParsedNotation {
|
|
16
|
-
let rest = notation.trim();
|
|
17
|
-
const operationMatch = rest.match(/:((?:append|prepend|after|before|remove))$/);
|
|
18
|
-
const operation: MutationOperation = operationMatch
|
|
19
|
-
? (operationMatch[1] as MutationOperation)
|
|
20
|
-
: "set";
|
|
21
|
-
if (operationMatch) {
|
|
22
|
-
rest = rest.slice(0, -operationMatch[0].length);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const segments: PathPart[] = [];
|
|
26
|
-
let i = 0;
|
|
27
|
-
while (i < rest.length) {
|
|
28
|
-
let key = "";
|
|
29
|
-
while (i < rest.length && rest[i] !== "." && rest[i] !== "[") {
|
|
30
|
-
key += rest[i];
|
|
31
|
-
i++;
|
|
32
|
-
}
|
|
33
|
-
key = key.trim();
|
|
34
|
-
if (key) {
|
|
35
|
-
if (rest[i] === "[") {
|
|
36
|
-
i++;
|
|
37
|
-
const bracketStart = i;
|
|
38
|
-
while (i < rest.length && rest[i] !== "]") i++;
|
|
39
|
-
const bracketContent = rest.slice(bracketStart, i);
|
|
40
|
-
i++;
|
|
41
|
-
const eq = bracketContent.indexOf("=");
|
|
42
|
-
if (eq >= 0) {
|
|
43
|
-
const prop = bracketContent.slice(0, eq).trim();
|
|
44
|
-
let val = bracketContent.slice(eq + 1).trim();
|
|
45
|
-
if (val.startsWith('"') && val.endsWith('"')) val = val.slice(1, -1);
|
|
46
|
-
else if (val.startsWith("'") && val.endsWith("'")) val = val.slice(1, -1);
|
|
47
|
-
segments.push({ key, selector: { prop, value: val } });
|
|
48
|
-
} else {
|
|
49
|
-
const index = parseInt(bracketContent.trim(), 10);
|
|
50
|
-
segments.push({ key, index });
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
segments.push({ key });
|
|
54
|
-
}
|
|
55
|
-
} else if (rest[i] === "[") {
|
|
56
|
-
i++;
|
|
57
|
-
const bracketStart = i;
|
|
58
|
-
while (i < rest.length && rest[i] !== "]") i++;
|
|
59
|
-
const bracketContent = rest.slice(bracketStart, i);
|
|
60
|
-
i++;
|
|
61
|
-
const eq = bracketContent.indexOf("=");
|
|
62
|
-
if (eq >= 0) {
|
|
63
|
-
const prop = bracketContent.slice(0, eq).trim();
|
|
64
|
-
let val = bracketContent.slice(eq + 1).trim();
|
|
65
|
-
if (val.startsWith('"') && val.endsWith('"')) val = val.slice(1, -1);
|
|
66
|
-
else if (val.startsWith("'") && val.endsWith("'")) val = val.slice(1, -1);
|
|
67
|
-
segments.push({ key: "", selector: { prop, value: val } });
|
|
68
|
-
} else {
|
|
69
|
-
const index = parseInt(bracketContent.trim(), 10);
|
|
70
|
-
segments.push({ key: "", index });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (rest[i] === ".") i++;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return { segments, operation };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function getAtSegment(obj: VariableValue, seg: PathPart): VariableValue {
|
|
80
|
-
if (obj === null || obj === undefined) return undefined;
|
|
81
|
-
const o = obj as Record<string, unknown>;
|
|
82
|
-
if ("index" in seg) {
|
|
83
|
-
const arr =
|
|
84
|
-
seg.key === ""
|
|
85
|
-
? Array.isArray(obj)
|
|
86
|
-
? obj
|
|
87
|
-
: undefined
|
|
88
|
-
: Array.isArray(obj)
|
|
89
|
-
? obj
|
|
90
|
-
: (o[seg.key] as unknown[]);
|
|
91
|
-
if (!Array.isArray(arr)) return undefined;
|
|
92
|
-
return arr[seg.index] as VariableValue;
|
|
93
|
-
}
|
|
94
|
-
if ("selector" in seg) {
|
|
95
|
-
const arr =
|
|
96
|
-
seg.key === ""
|
|
97
|
-
? Array.isArray(obj)
|
|
98
|
-
? obj
|
|
99
|
-
: undefined
|
|
100
|
-
: Array.isArray(obj)
|
|
101
|
-
? obj
|
|
102
|
-
: (o[seg.key] as unknown[]);
|
|
103
|
-
if (!Array.isArray(arr)) return undefined;
|
|
104
|
-
const { prop, value } = seg.selector;
|
|
105
|
-
const found = arr.find((item) => {
|
|
106
|
-
if (item === null || typeof item !== "object") return false;
|
|
107
|
-
const v = (item as Record<string, unknown>)[prop];
|
|
108
|
-
return String(v) === value;
|
|
109
|
-
});
|
|
110
|
-
return found as VariableValue;
|
|
111
|
-
}
|
|
112
|
-
return o[seg.key] as VariableValue;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function setAtSegment(
|
|
116
|
-
obj: Record<string, unknown> | unknown[],
|
|
117
|
-
seg: PathPart,
|
|
118
|
-
_value: VariableValue,
|
|
119
|
-
op: MutationOperation,
|
|
120
|
-
setValue: VariableValue | undefined,
|
|
121
|
-
): void {
|
|
122
|
-
if ("index" in seg) {
|
|
123
|
-
const i = seg.index;
|
|
124
|
-
const arr =
|
|
125
|
-
seg.key === ""
|
|
126
|
-
? Array.isArray(obj)
|
|
127
|
-
? obj
|
|
128
|
-
: undefined
|
|
129
|
-
: Array.isArray(obj)
|
|
130
|
-
? obj
|
|
131
|
-
: ((obj as Record<string, unknown>)[seg.key] as unknown[]);
|
|
132
|
-
if (!Array.isArray(arr)) return;
|
|
133
|
-
if (op === "remove") {
|
|
134
|
-
arr.splice(i, 1);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (op === "set") {
|
|
138
|
-
arr[i] = setValue;
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if ("selector" in seg) {
|
|
144
|
-
const arr =
|
|
145
|
-
seg.key === ""
|
|
146
|
-
? Array.isArray(obj)
|
|
147
|
-
? obj
|
|
148
|
-
: undefined
|
|
149
|
-
: Array.isArray(obj)
|
|
150
|
-
? obj
|
|
151
|
-
: ((obj as Record<string, unknown>)[seg.key] as unknown[]);
|
|
152
|
-
if (!Array.isArray(arr)) return;
|
|
153
|
-
const { prop, value: selVal } = seg.selector;
|
|
154
|
-
const numVal = /^\d+$/.test(selVal) ? parseInt(selVal, 10) : null;
|
|
155
|
-
const idx = arr.findIndex((item) => {
|
|
156
|
-
if (item === null || typeof item !== "object") return false;
|
|
157
|
-
const v = (item as Record<string, unknown>)[prop];
|
|
158
|
-
return String(v) === selVal || (numVal !== null && v === numVal);
|
|
159
|
-
});
|
|
160
|
-
if (idx < 0) return;
|
|
161
|
-
if (op === "remove") {
|
|
162
|
-
arr.splice(idx, 1);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (op === "after" && setValue !== undefined) {
|
|
166
|
-
arr.splice(idx + 1, 0, setValue);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (op === "before" && setValue !== undefined) {
|
|
170
|
-
arr.splice(idx, 0, setValue);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
const key = seg.key;
|
|
176
|
-
const o = obj as Record<string, unknown>;
|
|
177
|
-
if (op === "remove") {
|
|
178
|
-
delete o[key];
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (op === "append" && setValue !== undefined) {
|
|
182
|
-
const arr = (o[key] ?? []) as unknown[];
|
|
183
|
-
arr.push(setValue);
|
|
184
|
-
o[key] = arr;
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (op === "prepend" && setValue !== undefined) {
|
|
188
|
-
const arr = (o[key] ?? []) as unknown[];
|
|
189
|
-
arr.unshift(setValue);
|
|
190
|
-
o[key] = arr;
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (op === "set") {
|
|
194
|
-
o[key] = setValue as unknown;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function mutate(
|
|
199
|
-
_schema: VariableSchema,
|
|
200
|
-
value: VariableValue,
|
|
201
|
-
notation: string,
|
|
202
|
-
setValue: VariableValue | undefined,
|
|
203
|
-
): VariableValue {
|
|
204
|
-
if (value === null || value === undefined) return value;
|
|
205
|
-
const result = JSON.parse(JSON.stringify(value)) as VariableValue;
|
|
206
|
-
|
|
207
|
-
const { segments, operation } = parseNotation(notation);
|
|
208
|
-
if (segments.length === 0) {
|
|
209
|
-
if (Array.isArray(result) && setValue !== undefined) {
|
|
210
|
-
const arr = result as VariableValue[];
|
|
211
|
-
if (operation === "append") {
|
|
212
|
-
arr.push(setValue);
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
if (operation === "prepend") {
|
|
216
|
-
arr.unshift(setValue);
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const last = segments[segments.length - 1];
|
|
224
|
-
const parentSegments = segments.slice(0, -1);
|
|
225
|
-
|
|
226
|
-
let container: Record<string, unknown> | unknown[] = result as
|
|
227
|
-
| Record<string, unknown>
|
|
228
|
-
| unknown[];
|
|
229
|
-
for (const seg of parentSegments) {
|
|
230
|
-
const next = getAtSegment(container as VariableValue, seg);
|
|
231
|
-
if (next === undefined) return result;
|
|
232
|
-
container = next as Record<string, unknown> | unknown[];
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
setAtSegment(container, last, undefined, operation, setValue);
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getNextRevision } from "./revision";
|
|
2
|
-
|
|
3
|
-
describe("core: Revision", function () {
|
|
4
|
-
it("should be a function", function () {
|
|
5
|
-
expect(typeof getNextRevision).toEqual("function");
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it("should return next version number", function () {
|
|
9
|
-
// string-string
|
|
10
|
-
expect(getNextRevision("")).toEqual("1");
|
|
11
|
-
expect(getNextRevision("random text")).toEqual("1");
|
|
12
|
-
|
|
13
|
-
// string-numeric
|
|
14
|
-
expect(getNextRevision("1")).toEqual("2");
|
|
15
|
-
expect(getNextRevision("2024")).toEqual("2025");
|
|
16
|
-
|
|
17
|
-
// string-semver
|
|
18
|
-
expect(getNextRevision("1.0.0")).toEqual("1");
|
|
19
|
-
expect(getNextRevision("0.0.0")).toEqual("1");
|
|
20
|
-
expect(getNextRevision("0.0.1523")).toEqual("1524");
|
|
21
|
-
});
|
|
22
|
-
});
|
package/src/builder/revision.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export function getNextRevision(currentRevision: string) {
|
|
2
|
-
// If the string is empty or can't be parsed with parseInt(), return "1".
|
|
3
|
-
if (!currentRevision || isNaN(parseInt(currentRevision, 10))) {
|
|
4
|
-
return "1";
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// If the string is like an integer, increment it by 1 and return the value.
|
|
8
|
-
if (currentRevision.indexOf(".") === -1) {
|
|
9
|
-
return (parseInt(currentRevision, 10) + 1).toString();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// If the string is a semver, parse the patch version out of it, increment it by one and return it.
|
|
13
|
-
const parts = currentRevision.split(".");
|
|
14
|
-
const lastPart = parseInt(parts[parts.length - 1], 10);
|
|
15
|
-
|
|
16
|
-
if (!isNaN(lastPart)) {
|
|
17
|
-
return (lastPart + 1).toString();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// If the string can't be parsed as a semver, return "1".
|
|
21
|
-
return "1";
|
|
22
|
-
}
|