@featurevisor/core 4.3.0 → 4.5.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/cli/cli.d.ts +2 -1
- package/lib/cli/cli.js +9 -6
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/options.js +69 -0
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +7 -1
- package/lib/cli/plugins.js.map +1 -1
- package/lib/config/projectConfig.d.ts +10 -0
- package/lib/config/projectConfig.js +14 -0
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/convert/check.d.ts +33 -0
- package/lib/convert/check.js +411 -0
- package/lib/convert/check.js.map +1 -0
- package/lib/convert/config.d.ts +20 -0
- package/lib/convert/config.js +147 -0
- package/lib/convert/config.js.map +1 -0
- package/lib/convert/documents.d.ts +40 -0
- package/lib/convert/documents.js +154 -0
- package/lib/convert/documents.js.map +1 -0
- package/lib/convert/index.d.ts +7 -0
- package/lib/convert/index.js +47 -0
- package/lib/convert/index.js.map +1 -0
- package/lib/convert/plan.d.ts +53 -0
- package/lib/convert/plan.js +669 -0
- package/lib/convert/plan.js.map +1 -0
- package/lib/convert/project.d.ts +29 -0
- package/lib/convert/project.js +109 -0
- package/lib/convert/project.js.map +1 -0
- package/lib/convert/run.d.ts +3 -0
- package/lib/convert/run.js +241 -0
- package/lib/convert/run.js.map +1 -0
- package/lib/convert/tests.d.ts +22 -0
- package/lib/convert/tests.js +267 -0
- package/lib/convert/tests.js.map +1 -0
- package/lib/datasource/conditionLocations.d.ts +9 -0
- package/lib/datasource/conditionLocations.js +70 -0
- package/lib/datasource/conditionLocations.js.map +1 -0
- package/lib/datasource/datasource.d.ts +11 -0
- package/lib/datasource/datasource.js +26 -6
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/expressions.d.ts +36 -0
- package/lib/datasource/expressions.js +118 -0
- package/lib/datasource/expressions.js.map +1 -0
- package/lib/datasource/parseError.d.ts +11 -0
- package/lib/datasource/parseError.js +33 -19
- package/lib/datasource/parseError.js.map +1 -1
- package/lib/diff/conditions.d.ts +23 -0
- package/lib/diff/conditions.js +86 -0
- package/lib/diff/conditions.js.map +1 -0
- package/lib/diff/details.d.ts +7 -1
- package/lib/diff/details.js +54 -25
- package/lib/diff/details.js.map +1 -1
- package/lib/diff/index.d.ts +5 -0
- package/lib/diff/index.js +17 -2
- package/lib/diff/index.js.map +1 -1
- package/lib/evaluate/explain.d.ts +4 -1
- package/lib/evaluate/explain.js +35 -14
- package/lib/evaluate/explain.js.map +1 -1
- package/lib/evaluate/index.js +9 -5
- package/lib/evaluate/index.js.map +1 -1
- package/lib/formatter/expressions.d.ts +21 -0
- package/lib/formatter/expressions.js +79 -0
- package/lib/formatter/expressions.js.map +1 -0
- package/lib/formatter/formatDefinition.d.ts +46 -0
- package/lib/formatter/formatDefinition.js +201 -0
- package/lib/formatter/formatDefinition.js.map +1 -0
- package/lib/formatter/formatProject.d.ts +70 -0
- package/lib/formatter/formatProject.js +186 -0
- package/lib/formatter/formatProject.js.map +1 -0
- package/lib/formatter/index.d.ts +6 -0
- package/lib/formatter/index.js +53 -0
- package/lib/formatter/index.js.map +1 -0
- package/lib/formatter/layout.d.ts +26 -0
- package/lib/formatter/layout.js +175 -0
- package/lib/formatter/layout.js.map +1 -0
- package/lib/formatter/printFormatResult.d.ts +9 -0
- package/lib/formatter/printFormatResult.js +100 -0
- package/lib/formatter/printFormatResult.js.map +1 -0
- package/lib/formatter/run.d.ts +6 -0
- package/lib/formatter/run.js +97 -0
- package/lib/formatter/run.js.map +1 -0
- package/lib/formatter/simplify.d.ts +14 -0
- package/lib/formatter/simplify.js +21 -0
- package/lib/formatter/simplify.js.map +1 -0
- package/lib/formatter/since.d.ts +6 -0
- package/lib/formatter/since.js +80 -0
- package/lib/formatter/since.js.map +1 -0
- package/lib/formatter/style.d.ts +105 -0
- package/lib/formatter/style.js +248 -0
- package/lib/formatter/style.js.map +1 -0
- package/lib/linter/conditionKinds.js +2 -54
- package/lib/linter/conditionKinds.js.map +1 -1
- package/lib/linter/conditionSchema.js +42 -13
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/diagnostics.d.ts +14 -14
- package/lib/linter/expressionDiagnostics.d.ts +28 -0
- package/lib/linter/expressionDiagnostics.js +127 -0
- package/lib/linter/expressionDiagnostics.js.map +1 -0
- package/lib/linter/featureSchema.d.ts +2 -2
- package/lib/linter/featureSchema.js +14 -13
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/lintProject.d.ts +7 -0
- package/lib/linter/lintProject.js +300 -52
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/listTypes.d.ts +7 -0
- package/lib/linter/listTypes.js +19 -0
- package/lib/linter/listTypes.js.map +1 -0
- package/lib/linter/printError.d.ts +2 -0
- package/lib/linter/printError.js +1 -0
- package/lib/linter/printError.js.map +1 -1
- package/lib/linter/requiredVariablesSchema.js +129 -13
- package/lib/linter/requiredVariablesSchema.js.map +1 -1
- package/lib/migrate/definitions.d.ts +46 -0
- package/lib/migrate/definitions.js +488 -0
- package/lib/migrate/definitions.js.map +1 -0
- package/lib/migrate/index.d.ts +6 -0
- package/lib/migrate/index.js +30 -0
- package/lib/migrate/index.js.map +1 -0
- package/lib/migrate/migrateProject.d.ts +33 -0
- package/lib/migrate/migrateProject.js +195 -0
- package/lib/migrate/migrateProject.js.map +1 -0
- package/lib/migrate/project.d.ts +31 -0
- package/lib/migrate/project.js +153 -0
- package/lib/migrate/project.js.map +1 -0
- package/lib/migrate/run.d.ts +3 -0
- package/lib/migrate/run.js +81 -0
- package/lib/migrate/run.js.map +1 -0
- package/lib/migrate/write.d.ts +10 -0
- package/lib/migrate/write.js +150 -0
- package/lib/migrate/write.js.map +1 -0
- package/lib/promoter/index.js +85 -4
- package/lib/promoter/index.js.map +1 -1
- package/lib/rewrite/conditions.d.ts +73 -0
- package/lib/rewrite/conditions.js +485 -0
- package/lib/rewrite/conditions.js.map +1 -0
- package/lib/rewrite/diff.d.ts +2 -0
- package/lib/rewrite/diff.js +76 -0
- package/lib/rewrite/diff.js.map +1 -0
- package/lib/rewrite/documents.d.ts +25 -0
- package/lib/rewrite/documents.js +54 -0
- package/lib/rewrite/documents.js.map +1 -0
- package/lib/rewrite/files.d.ts +6 -0
- package/lib/rewrite/files.js +66 -0
- package/lib/rewrite/files.js.map +1 -0
- package/lib/rewrite/lines.d.ts +56 -0
- package/lib/rewrite/lines.js +205 -0
- package/lib/rewrite/lines.js.map +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ExpressionOptions } from "@featurevisor/expressions";
|
|
2
|
+
import { type CustomParser } from "@featurevisor/parsers";
|
|
3
|
+
import type { EntityType } from "@featurevisor/types";
|
|
4
|
+
export interface FormatDefinitionOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The project's expression options when it allows condition expressions, so they in `conditions` are written in
|
|
7
|
+
* the house style too. Without them, expressions stay as written.
|
|
8
|
+
*/
|
|
9
|
+
expressions?: ExpressionOptions;
|
|
10
|
+
/**
|
|
11
|
+
* Writes each condition in its simplest form that evaluates the same before formatting, as
|
|
12
|
+
* `fmt --simplify` does. Only conditions change, and a datafile may change its shape but
|
|
13
|
+
* never what it evaluates to.
|
|
14
|
+
*/
|
|
15
|
+
simplify?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface FormatResult {
|
|
18
|
+
output: string;
|
|
19
|
+
changed: boolean;
|
|
20
|
+
/** The parser's `format` left the file as it is, such as a file whose comments it cannot keep */
|
|
21
|
+
declined?: boolean;
|
|
22
|
+
/** The file asks to be left as it is, with the ignore comment at its top */
|
|
23
|
+
ignored?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** The source could not be read as a definition, so it was left as it is. */
|
|
26
|
+
export declare class FormatParseError extends Error {
|
|
27
|
+
line?: number;
|
|
28
|
+
column?: number;
|
|
29
|
+
constructor(cause: unknown);
|
|
30
|
+
}
|
|
31
|
+
/** Formatting would have changed a value, lost something, or was not stable. Never written. */
|
|
32
|
+
export declare class FormatGuardError extends Error {
|
|
33
|
+
constructor(message: string);
|
|
34
|
+
}
|
|
35
|
+
/** Whether the parser lays out its own files. Built-in YAML and JSON do. */
|
|
36
|
+
export declare function canFormat(parser: CustomParser): boolean;
|
|
37
|
+
/** Whether one of the comments at the top of the file, in # or // syntax, is the ignore comment */
|
|
38
|
+
export declare function isIgnoredFile(source: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Formats one definition file's source with its parser's `format`, which applies what its
|
|
41
|
+
* format can express of Featurevisor's layout for this kind of definition. The result is
|
|
42
|
+
* checked before it is returned: it must parse to the same value, apart from expressions
|
|
43
|
+
* written in the house style, keep every comment when the parser can list them, and stay the
|
|
44
|
+
* same when formatted again. A file with the ignore comment at its top is left as it is.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatDefinition(entityType: EntityType, original: string, parser: CustomParser, filePath?: string, options?: FormatDefinitionOptions): FormatResult;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatGuardError = exports.FormatParseError = void 0;
|
|
4
|
+
exports.canFormat = canFormat;
|
|
5
|
+
exports.isIgnoredFile = isIgnoredFile;
|
|
6
|
+
exports.formatDefinition = formatDefinition;
|
|
7
|
+
const parsers_1 = require("@featurevisor/parsers");
|
|
8
|
+
const parseError_1 = require("../datasource/parseError");
|
|
9
|
+
const lines_1 = require("../rewrite/lines");
|
|
10
|
+
const expressions_1 = require("./expressions");
|
|
11
|
+
const layout_1 = require("./layout");
|
|
12
|
+
const simplify_1 = require("./simplify");
|
|
13
|
+
const style_1 = require("./style");
|
|
14
|
+
/** The source could not be read as a definition, so it was left as it is. */
|
|
15
|
+
class FormatParseError extends Error {
|
|
16
|
+
constructor(cause) {
|
|
17
|
+
// as lint reports it: one line, with the position kept apart from the message
|
|
18
|
+
const { message, line, column } = (0, parseError_1.describeParseError)(cause);
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "FormatParseError";
|
|
21
|
+
this.line = line;
|
|
22
|
+
this.column = column;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.FormatParseError = FormatParseError;
|
|
26
|
+
/** Formatting would have changed a value, lost something, or was not stable. Never written. */
|
|
27
|
+
class FormatGuardError extends Error {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "FormatGuardError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.FormatGuardError = FormatGuardError;
|
|
34
|
+
/** Whether the parser lays out its own files. Built-in YAML and JSON do. */
|
|
35
|
+
function canFormat(parser) {
|
|
36
|
+
return typeof parser.format === "function";
|
|
37
|
+
}
|
|
38
|
+
/** Whether one of the comments at the top of the file, in # or // syntax, is the ignore comment */
|
|
39
|
+
function isIgnoredFile(source) {
|
|
40
|
+
for (const line of source.replace(/^\uFEFF/, "").split("\n")) {
|
|
41
|
+
const text = line.trim();
|
|
42
|
+
if (!text)
|
|
43
|
+
continue;
|
|
44
|
+
const comment = /^(?:#|\/\/)(.*)$/.exec(text);
|
|
45
|
+
if (!comment)
|
|
46
|
+
return false;
|
|
47
|
+
if (comment[1].trim() === parsers_1.IGNORE_FILE_COMMENT)
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
function dateText(date) {
|
|
53
|
+
try {
|
|
54
|
+
// TOML's dates write their own kind here: a date, a time, or both
|
|
55
|
+
return date.toISOString();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return String(date.getTime());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Equal as values: maps compare without key order, lists in order, dates by their time. */
|
|
62
|
+
function sameValue(a, b) {
|
|
63
|
+
if (a === b)
|
|
64
|
+
return true;
|
|
65
|
+
if (typeof a !== typeof b || a === null || b === null)
|
|
66
|
+
return false;
|
|
67
|
+
if (typeof a === "number")
|
|
68
|
+
return Number.isNaN(a) && Number.isNaN(b);
|
|
69
|
+
if (typeof a !== "object")
|
|
70
|
+
return false;
|
|
71
|
+
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
|
|
72
|
+
return false;
|
|
73
|
+
if (a instanceof Date) {
|
|
74
|
+
return Object.is(a.getTime(), b.getTime()) && dateText(a) === dateText(b);
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(a)) {
|
|
77
|
+
const other = b;
|
|
78
|
+
return a.length === other.length && a.every((item, index) => sameValue(item, other[index]));
|
|
79
|
+
}
|
|
80
|
+
const prototype = Object.getPrototypeOf(a);
|
|
81
|
+
// any other kind of object cannot be compared, so it never passes for the same
|
|
82
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
83
|
+
return false;
|
|
84
|
+
const left = a;
|
|
85
|
+
const right = b;
|
|
86
|
+
const keys = Object.keys(left);
|
|
87
|
+
if (keys.length !== Object.keys(right).length)
|
|
88
|
+
return false;
|
|
89
|
+
return keys.every((key) => key in right && sameValue(left[key], right[key]));
|
|
90
|
+
}
|
|
91
|
+
function parseSource(parser, source, filePath) {
|
|
92
|
+
try {
|
|
93
|
+
return parser.parse(source, filePath);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw new FormatParseError(error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** The house style texts of the expressions in a source, when expressions are formatted and it parses */
|
|
100
|
+
function expressionTextsOf(entityType, source, parser, filePath, options) {
|
|
101
|
+
if (!options.expressions)
|
|
102
|
+
return new Map();
|
|
103
|
+
let value;
|
|
104
|
+
try {
|
|
105
|
+
value = parser.parse(source, filePath);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// the format reports the parse error itself
|
|
109
|
+
return new Map();
|
|
110
|
+
}
|
|
111
|
+
return (0, expressions_1.getExpressionTexts)(entityType, value, options.expressions);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The source with its conditions simplified, which must keep every comment, apart from those
|
|
115
|
+
* moved into expressions joined as one, and read back as the simplified document
|
|
116
|
+
*/
|
|
117
|
+
function simplified(entityType, source, parser, filePath, options) {
|
|
118
|
+
parseSource(parser, source, filePath);
|
|
119
|
+
const result = (0, simplify_1.simplifySource)(entityType, source, parser, options.expressions);
|
|
120
|
+
if (!result)
|
|
121
|
+
throw new FormatGuardError("Simplifying would change the parsed value.");
|
|
122
|
+
if (!(0, lines_1.sameComments)(parser, source, result.source, result.moved)) {
|
|
123
|
+
throw new FormatGuardError("Simplifying would lose or change a comment.");
|
|
124
|
+
}
|
|
125
|
+
return result.source;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* One pass of the parser's `format`, or undefined when it leaves the file as it is. Line
|
|
129
|
+
* endings, a byte order mark and the final newline are the same in every format, so they are
|
|
130
|
+
* handled here: the parser sees `\n` line endings, and the output gets the house style's.
|
|
131
|
+
*/
|
|
132
|
+
function formatOnce(entityType, source, parser, filePath, texts) {
|
|
133
|
+
const { text, restore } = (0, lines_1.lineEndings)(source, style_1.HOUSE_STYLE.endOfLine);
|
|
134
|
+
const layout = (0, layout_1.getFormatLayout)(entityType, parser.extension);
|
|
135
|
+
if (texts.size > 0)
|
|
136
|
+
layout.formatText = (0, expressions_1.formatTextOf)(texts);
|
|
137
|
+
let output;
|
|
138
|
+
try {
|
|
139
|
+
output = parser.format(text, layout, filePath);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
// the author's when the parser cannot read the file either, and a fault in the format if not
|
|
143
|
+
parseSource(parser, source, filePath);
|
|
144
|
+
throw new FormatGuardError(error.message);
|
|
145
|
+
}
|
|
146
|
+
if (output === undefined || output === null)
|
|
147
|
+
return undefined;
|
|
148
|
+
if (output.length > 0 && !output.endsWith("\n"))
|
|
149
|
+
output += "\n";
|
|
150
|
+
return restore(output);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Formats one definition file's source with its parser's `format`, which applies what its
|
|
154
|
+
* format can express of Featurevisor's layout for this kind of definition. The result is
|
|
155
|
+
* checked before it is returned: it must parse to the same value, apart from expressions
|
|
156
|
+
* written in the house style, keep every comment when the parser can list them, and stay the
|
|
157
|
+
* same when formatted again. A file with the ignore comment at its top is left as it is.
|
|
158
|
+
*/
|
|
159
|
+
function formatDefinition(entityType, original, parser, filePath, options = {}) {
|
|
160
|
+
if (!canFormat(parser))
|
|
161
|
+
return { output: original, changed: false };
|
|
162
|
+
if (isIgnoredFile(original))
|
|
163
|
+
return { output: original, changed: false, ignored: true };
|
|
164
|
+
// the guards below check formatting from the simplified source, and simplifying checks itself
|
|
165
|
+
const source = options.simplify
|
|
166
|
+
? simplified(entityType, original, parser, filePath, options)
|
|
167
|
+
: original;
|
|
168
|
+
const texts = expressionTextsOf(entityType, source, parser, filePath, options);
|
|
169
|
+
const output = formatOnce(entityType, source, parser, filePath, texts);
|
|
170
|
+
if (output === undefined || output === source) {
|
|
171
|
+
// a built-in format reads the source as its parse does, and a custom one may not read it
|
|
172
|
+
if (!lines_1.BUILT_IN_PARSERS.has(parser))
|
|
173
|
+
parseSource(parser, source, filePath);
|
|
174
|
+
return output === undefined
|
|
175
|
+
? { output: source, changed: source !== original, declined: true }
|
|
176
|
+
: { output, changed: output !== original };
|
|
177
|
+
}
|
|
178
|
+
// the source parsed, so output that does not is the format's fault, not the author's
|
|
179
|
+
const before = parseSource(parser, source, filePath);
|
|
180
|
+
let readable = true;
|
|
181
|
+
let after;
|
|
182
|
+
try {
|
|
183
|
+
after = parser.parse(output, filePath);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
readable = false;
|
|
187
|
+
}
|
|
188
|
+
// each expression is as written or in the house style, which reads back the same, as checked
|
|
189
|
+
if (!readable || !sameValue((0, expressions_1.withExpressionTexts)(before, texts, after), after)) {
|
|
190
|
+
throw new FormatGuardError("Formatting would change the parsed value.");
|
|
191
|
+
}
|
|
192
|
+
if (!(0, lines_1.sameComments)(parser, source, output)) {
|
|
193
|
+
throw new FormatGuardError("Formatting would lose or change a comment.");
|
|
194
|
+
}
|
|
195
|
+
const again = expressionTextsOf(entityType, output, parser, filePath, options);
|
|
196
|
+
if (formatOnce(entityType, output, parser, filePath, again) !== output) {
|
|
197
|
+
throw new FormatGuardError("Formatting is not stable: a second pass changes the output.");
|
|
198
|
+
}
|
|
199
|
+
return { output, changed: true };
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=formatDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatDefinition.js","sourceRoot":"","sources":["../../src/formatter/formatDefinition.ts"],"names":[],"mappings":";;;AA+DA,8BAEC;AAGD,sCASC;AA0HD,4CA8CC;AApPD,mDAA+E;AAG/E,yDAA8D;AAC9D,4CAA+E;AAC/E,+CAKuB;AACvB,qCAA2C;AAC3C,yCAA4C;AAC5C,mCAAsC;AAyBtC,6EAA6E;AAC7E,MAAa,gBAAiB,SAAQ,KAAK;IAIzC,YAAY,KAAc;QACxB,8EAA8E;QAC9E,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAA,+BAAkB,EAAC,KAAK,CAAC,CAAC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAZD,4CAYC;AAED,+FAA+F;AAC/F,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC;AAED,4EAA4E;AAC5E,SAAgB,SAAS,CAAC,MAAoB;IAC5C,OAAO,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC;AAC7C,CAAC;AAED,mGA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QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,6FAA6F;IAC7F,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,IAAA,iCAAmB,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,gBAAgB,CAAC,2CAA2C,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,CAAC,IAAA,oBAAY,EAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,gBAAgB,CAAC,4CAA4C,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,KAAK,GAAG,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/E,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC;QACvE,MAAM,IAAI,gBAAgB,CAAC,6DAA6D,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { EntityType } from "@featurevisor/types";
|
|
2
|
+
import type { ProjectConfig } from "../config";
|
|
3
|
+
import type { Datasource } from "../datasource";
|
|
4
|
+
export interface FormatProjectOptions {
|
|
5
|
+
/** Report files that need formatting without writing them */
|
|
6
|
+
check?: boolean;
|
|
7
|
+
/** Print what would change as a unified diff, without writing */
|
|
8
|
+
diff?: boolean;
|
|
9
|
+
entityType?: EntityType;
|
|
10
|
+
keyPattern?: RegExp;
|
|
11
|
+
/** Only these files, or the files in these directories, absolute or relative to the working directory */
|
|
12
|
+
paths?: string[];
|
|
13
|
+
/** Only files changed since HEAD left this Git reference, uncommitted and untracked ones too */
|
|
14
|
+
since?: string;
|
|
15
|
+
/** Only this Set, in a project with Sets. Without it, every Set is formatted in one run. */
|
|
16
|
+
set?: string;
|
|
17
|
+
/** Format this source as the file at `filePath`, reading and writing no files, for editors */
|
|
18
|
+
stdin?: {
|
|
19
|
+
filePath: string;
|
|
20
|
+
source: string;
|
|
21
|
+
};
|
|
22
|
+
/** Write each condition in its simplest form that evaluates the same, before formatting */
|
|
23
|
+
simplify?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface FormatFileResult {
|
|
26
|
+
/** The Set the file belongs to, in a project with Sets */
|
|
27
|
+
set?: string;
|
|
28
|
+
entityType: EntityType;
|
|
29
|
+
key: string;
|
|
30
|
+
/** Relative to the working directory */
|
|
31
|
+
filePath: string;
|
|
32
|
+
/**
|
|
33
|
+
* `declined` when the parser's format left the file as it is, and `ignored` when the file
|
|
34
|
+
* asks to be left as it is
|
|
35
|
+
*/
|
|
36
|
+
status: "unchanged" | "changed" | "declined" | "ignored" | "error";
|
|
37
|
+
error?: {
|
|
38
|
+
code: "parse_error" | "format_guard" | "missing_file";
|
|
39
|
+
message: string;
|
|
40
|
+
line?: number;
|
|
41
|
+
column?: number;
|
|
42
|
+
};
|
|
43
|
+
diff?: string;
|
|
44
|
+
/** The formatted source, when formatting the source given on stdin */
|
|
45
|
+
output?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface FormatProjectResult {
|
|
48
|
+
files: FormatFileResult[];
|
|
49
|
+
/** Paths given that hold no definition of this project */
|
|
50
|
+
skipped: string[];
|
|
51
|
+
changed: number;
|
|
52
|
+
declined: number;
|
|
53
|
+
ignored: number;
|
|
54
|
+
errors: number;
|
|
55
|
+
/** The project's parser has no `format`, so its files were left as they are */
|
|
56
|
+
unsupported?: boolean;
|
|
57
|
+
}
|
|
58
|
+
interface Dependencies {
|
|
59
|
+
rootDirectoryPath: string;
|
|
60
|
+
projectConfig: ProjectConfig;
|
|
61
|
+
datasource: Datasource;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Formats every definition file of a project in one run: attributes, schemas, segments,
|
|
65
|
+
* features, variables, targets, tests and scenarios, across every Set unless one is picked.
|
|
66
|
+
* Writes only files that change, unless checking or diffing. Given source on stdin, formats it
|
|
67
|
+
* as the file at its path instead, and writes nothing.
|
|
68
|
+
*/
|
|
69
|
+
export declare function formatProject(deps: Dependencies, options?: FormatProjectOptions): Promise<FormatProjectResult>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.formatProject = formatProject;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const error_1 = require("../error");
|
|
40
|
+
const sets_1 = require("../sets");
|
|
41
|
+
const formatDefinition_1 = require("./formatDefinition");
|
|
42
|
+
const expressions_1 = require("./expressions");
|
|
43
|
+
const layout_1 = require("./layout");
|
|
44
|
+
const since_1 = require("./since");
|
|
45
|
+
const diff_1 = require("../rewrite/diff");
|
|
46
|
+
const LIST_KEYS = {
|
|
47
|
+
attribute: (datasource) => datasource.listAttributes(),
|
|
48
|
+
schema: (datasource) => datasource.listSchemas(),
|
|
49
|
+
segment: (datasource) => datasource.listSegments(),
|
|
50
|
+
feature: (datasource) => datasource.listFeatures(),
|
|
51
|
+
variable: (datasource) => datasource.listVariables(),
|
|
52
|
+
target: (datasource) => datasource.listTargets(),
|
|
53
|
+
test: (datasource) => datasource.listTests(),
|
|
54
|
+
scenario: (datasource) => datasource.listScenarios(),
|
|
55
|
+
};
|
|
56
|
+
function relative(filePath) {
|
|
57
|
+
return path.relative(process.cwd(), filePath) || filePath;
|
|
58
|
+
}
|
|
59
|
+
function toWantedPath(given) {
|
|
60
|
+
const absolute = path.resolve(given);
|
|
61
|
+
const directory = fs.existsSync(absolute) && fs.statSync(absolute).isDirectory();
|
|
62
|
+
return { absolute, directory, matched: false };
|
|
63
|
+
}
|
|
64
|
+
function isWanted(wanted, filePath) {
|
|
65
|
+
return wanted.directory
|
|
66
|
+
? filePath.startsWith(wanted.absolute.endsWith(path.sep) ? wanted.absolute : wanted.absolute + path.sep)
|
|
67
|
+
: filePath === wanted.absolute;
|
|
68
|
+
}
|
|
69
|
+
function toFileError(error) {
|
|
70
|
+
if (error instanceof formatDefinition_1.FormatParseError) {
|
|
71
|
+
return { code: "parse_error", message: error.message, line: error.line, column: error.column };
|
|
72
|
+
}
|
|
73
|
+
// a guard caught a fault in the parser's format, which is never the author's
|
|
74
|
+
const message = error instanceof formatDefinition_1.FormatGuardError
|
|
75
|
+
? `${error.message} The file was left as it is. Please report this.`
|
|
76
|
+
: error.message;
|
|
77
|
+
return { code: "format_guard", message };
|
|
78
|
+
}
|
|
79
|
+
/** Formats one file, writing it only when it changes and fmt is neither checking nor diffing */
|
|
80
|
+
function formatFile(file, parser, options, expressions) {
|
|
81
|
+
const filePath = path.resolve(file.filePath);
|
|
82
|
+
if (!options.stdin && !fs.existsSync(filePath)) {
|
|
83
|
+
file.error = { code: "missing_file", message: "File not found" };
|
|
84
|
+
return "error";
|
|
85
|
+
}
|
|
86
|
+
const source = options.stdin ? options.stdin.source : fs.readFileSync(filePath, "utf8");
|
|
87
|
+
try {
|
|
88
|
+
const { output, changed, declined, ignored } = (0, formatDefinition_1.formatDefinition)(file.entityType, source, parser, filePath, { expressions, simplify: options.simplify });
|
|
89
|
+
if (options.stdin)
|
|
90
|
+
file.output = output;
|
|
91
|
+
if (ignored)
|
|
92
|
+
return "ignored";
|
|
93
|
+
if (declined)
|
|
94
|
+
return "declined";
|
|
95
|
+
if (!changed)
|
|
96
|
+
return "unchanged";
|
|
97
|
+
if (options.diff)
|
|
98
|
+
file.diff = (0, diff_1.unifiedDiff)(file.filePath, file.filePath, source, output);
|
|
99
|
+
if (!options.stdin && !options.check && !options.diff)
|
|
100
|
+
fs.writeFileSync(filePath, output);
|
|
101
|
+
return "changed";
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
file.error = toFileError(error);
|
|
105
|
+
return "error";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Every definition file of the project, once each, across every Set unless one is picked */
|
|
109
|
+
async function* listDefinitionFiles(deps, options) {
|
|
110
|
+
const { projectConfig, datasource } = deps;
|
|
111
|
+
const entityTypes = options.entityType ? [options.entityType] : layout_1.FORMAT_ENTITY_TYPES;
|
|
112
|
+
const executions = await (0, sets_1.getProjectSetExecutions)(projectConfig, datasource, options.set);
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
for (const execution of executions) {
|
|
115
|
+
for (const entityType of entityTypes) {
|
|
116
|
+
const keys = await LIST_KEYS[entityType](execution.datasource);
|
|
117
|
+
for (const key of keys) {
|
|
118
|
+
if (options.keyPattern && !options.keyPattern.test(key))
|
|
119
|
+
continue;
|
|
120
|
+
const filePath = execution.datasource.getEntitySourcePath(entityType, key);
|
|
121
|
+
if (!filePath) {
|
|
122
|
+
throw new error_1.FeaturevisorCLIError("fmt needs definitions stored as files. This project's datasource adapter does not expose file paths.", { code: "unsupported_adapter" });
|
|
123
|
+
}
|
|
124
|
+
const absolute = path.resolve(filePath);
|
|
125
|
+
if (seen.has(absolute))
|
|
126
|
+
continue;
|
|
127
|
+
seen.add(absolute);
|
|
128
|
+
yield {
|
|
129
|
+
...(projectConfig.sets ? { set: execution.set } : {}),
|
|
130
|
+
entityType,
|
|
131
|
+
key,
|
|
132
|
+
filePath: relative(filePath),
|
|
133
|
+
status: "unchanged",
|
|
134
|
+
absolute,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Formats every definition file of a project in one run: attributes, schemas, segments,
|
|
142
|
+
* features, variables, targets, tests and scenarios, across every Set unless one is picked.
|
|
143
|
+
* Writes only files that change, unless checking or diffing. Given source on stdin, formats it
|
|
144
|
+
* as the file at its path instead, and writes nothing.
|
|
145
|
+
*/
|
|
146
|
+
async function formatProject(deps, options = {}) {
|
|
147
|
+
const result = {
|
|
148
|
+
files: [],
|
|
149
|
+
skipped: [],
|
|
150
|
+
changed: 0,
|
|
151
|
+
declined: 0,
|
|
152
|
+
ignored: 0,
|
|
153
|
+
errors: 0,
|
|
154
|
+
};
|
|
155
|
+
const parser = deps.projectConfig.parser;
|
|
156
|
+
if (!(0, formatDefinition_1.canFormat)(parser))
|
|
157
|
+
return { ...result, unsupported: true };
|
|
158
|
+
const expressions = (0, expressions_1.getFormatExpressionOptions)(deps.projectConfig);
|
|
159
|
+
const paths = options.stdin ? [options.stdin.filePath] : options.paths || [];
|
|
160
|
+
const wanted = paths.map(toWantedPath);
|
|
161
|
+
const changedFiles = options.since === undefined
|
|
162
|
+
? undefined
|
|
163
|
+
: (0, since_1.getChangedFiles)(deps.rootDirectoryPath, options.since);
|
|
164
|
+
for await (const { absolute, ...file } of listDefinitionFiles(deps, options)) {
|
|
165
|
+
if (wanted.length > 0) {
|
|
166
|
+
const matches = wanted.filter((item) => isWanted(item, absolute));
|
|
167
|
+
if (matches.length === 0)
|
|
168
|
+
continue;
|
|
169
|
+
matches.forEach((item) => (item.matched = true));
|
|
170
|
+
}
|
|
171
|
+
// Git gives real paths, which a project reached through a symbolic link, or a Windows
|
|
172
|
+
// short name such as RUNNER~1, differs from
|
|
173
|
+
if (changedFiles && !changedFiles.has(fs.realpathSync.native(absolute)))
|
|
174
|
+
continue;
|
|
175
|
+
file.status = formatFile(file, parser, options, expressions);
|
|
176
|
+
result.files.push(file);
|
|
177
|
+
}
|
|
178
|
+
const count = (status) => result.files.filter((file) => file.status === status).length;
|
|
179
|
+
result.changed = count("changed");
|
|
180
|
+
result.declined = count("declined");
|
|
181
|
+
result.ignored = count("ignored");
|
|
182
|
+
result.errors = count("error");
|
|
183
|
+
result.skipped = wanted.filter((item) => !item.matched).map((item) => relative(item.absolute));
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=formatProject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatProject.js","sourceRoot":"","sources":["../../src/formatter/formatProject.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoNA,sCA8CC;AAlQD,4CAA8B;AAC9B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0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fmtPlugin = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `featurevisor fmt` lays out definitions in one house style. The command loads its code only
|
|
6
|
+
* when it runs, so other commands start without it.
|
|
7
|
+
*/
|
|
8
|
+
exports.fmtPlugin = {
|
|
9
|
+
command: "fmt [paths...]",
|
|
10
|
+
handler: async function (options) {
|
|
11
|
+
const { runFormat } = require("./run");
|
|
12
|
+
return runFormat(options);
|
|
13
|
+
},
|
|
14
|
+
examples: [
|
|
15
|
+
{
|
|
16
|
+
command: "fmt",
|
|
17
|
+
description: "Format every definition file in place",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
command: "fmt --check",
|
|
21
|
+
description: "List files that need formatting and exit with 1 if any do, for CI",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
command: "fmt --check --since=origin/main",
|
|
25
|
+
description: "Check only the files changed since the branch left main",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
command: "fmt --diff",
|
|
29
|
+
description: "Show what formatting would change, without writing",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
command: "fmt --check --diff",
|
|
33
|
+
description: "Show what formatting would change and exit with 1 if anything would, for CI",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
command: "fmt features/checkout.yml segments",
|
|
37
|
+
description: "Format only the given files, and the files in the given directories",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
command: "fmt --simplify",
|
|
41
|
+
description: "Also write each condition in its simplest form, which can change datafiles but not evaluation",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
command: "fmt --entity-type=feature --key-pattern=checkout",
|
|
45
|
+
description: "Format only matching features",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
command: "fmt --stdin-filepath=features/checkout.yml < checkout.yml",
|
|
49
|
+
description: "Format text from stdin as the given file and print it, for editors",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formatter/index.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACU,QAAA,SAAS,GAAW;IAC/B,OAAO,EAAE,gBAAgB;IACzB,OAAO,EAAE,KAAK,WAAW,OAAO;QAC9B,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,OAAO,CAA2B,CAAC;QACjE,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,QAAQ,EAAE;QACR;YACE,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,uCAAuC;SACrD;QACD;YACE,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,mEAAmE;SACjF;QACD;YACE,OAAO,EAAE,iCAAiC;YAC1C,WAAW,EAAE,yDAAyD;SACvE;QACD;YACE,OAAO,EAAE,YAAY;YACrB,WAAW,EAAE,oDAAoD;SAClE;QACD;YACE,OAAO,EAAE,oBAAoB;YAC7B,WAAW,EAAE,6EAA6E;SAC3F;QACD;YACE,OAAO,EAAE,oCAAoC;YAC7C,WAAW,EAAE,qEAAqE;SACnF;QACD;YACE,OAAO,EAAE,gBAAgB;YACzB,WAAW,EACT,+FAA+F;SAClG;QACD;YACE,OAAO,EAAE,kDAAkD;YAC3D,WAAW,EAAE,+BAA+B;SAC7C;QACD;YACE,OAAO,EAAE,2DAA2D;YACpE,WAAW,EAAE,oEAAoE;SAClF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FormatLayout, FormatPath } from "@featurevisor/parsers";
|
|
2
|
+
import type { EntityType } from "@featurevisor/types";
|
|
3
|
+
/**
|
|
4
|
+
* Where each kind of object sits in a definition, so the house style in style.ts reaches the
|
|
5
|
+
* right maps and lists. A parser's `format` receives the result as a FormatLayout.
|
|
6
|
+
*
|
|
7
|
+
* This file keeps the promise that formatting never changes a datafile. Only objects the
|
|
8
|
+
* builder rebuilds key by key are given a key order here: features, rules, force entries,
|
|
9
|
+
* variations, variablesSchema entries, segments, global variables and their overrides, and
|
|
10
|
+
* everything in test specs, which datafiles never hold. Values stay as written: variable
|
|
11
|
+
* values, context, condition leaves, compose references, and maps keyed by the author, such
|
|
12
|
+
* as variablesSchema or properties. Lists are never reordered, since rules, overrides,
|
|
13
|
+
* variations, conditions and mutations depend on their order.
|
|
14
|
+
*/
|
|
15
|
+
/** Every kind of definition fmt formats, in the order it formats them */
|
|
16
|
+
export declare const FORMAT_ENTITY_TYPES: EntityType[];
|
|
17
|
+
/** The keys of the map at `path` in house order, then any others as they were written */
|
|
18
|
+
export declare function getKeyOrder(entityType: EntityType, path: FormatPath, keys: string[]): string[] | undefined;
|
|
19
|
+
/** Whether the map at `path` has a blank line between its entries */
|
|
20
|
+
export declare function isSpacedMap(entityType: EntityType, path: FormatPath): boolean;
|
|
21
|
+
/** Whether the list at `path` has a blank line between its items */
|
|
22
|
+
export declare function isSpacedList(entityType: EntityType, path: FormatPath): boolean;
|
|
23
|
+
/** The key order applied to a parsed value, for parsers that write from values */
|
|
24
|
+
export declare function orderValue(entityType: EntityType, value: unknown, path?: FormatPath): unknown;
|
|
25
|
+
/** The layout a parser's `format` applies to one kind of definition */
|
|
26
|
+
export declare function getFormatLayout(entityType: EntityType, extension?: string): FormatLayout;
|