@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.
Files changed (148) hide show
  1. package/lib/cli/cli.d.ts +2 -1
  2. package/lib/cli/cli.js +9 -6
  3. package/lib/cli/cli.js.map +1 -1
  4. package/lib/cli/options.js +69 -0
  5. package/lib/cli/options.js.map +1 -1
  6. package/lib/cli/plugins.js +7 -1
  7. package/lib/cli/plugins.js.map +1 -1
  8. package/lib/config/projectConfig.d.ts +10 -0
  9. package/lib/config/projectConfig.js +14 -0
  10. package/lib/config/projectConfig.js.map +1 -1
  11. package/lib/convert/check.d.ts +33 -0
  12. package/lib/convert/check.js +411 -0
  13. package/lib/convert/check.js.map +1 -0
  14. package/lib/convert/config.d.ts +20 -0
  15. package/lib/convert/config.js +147 -0
  16. package/lib/convert/config.js.map +1 -0
  17. package/lib/convert/documents.d.ts +40 -0
  18. package/lib/convert/documents.js +154 -0
  19. package/lib/convert/documents.js.map +1 -0
  20. package/lib/convert/index.d.ts +7 -0
  21. package/lib/convert/index.js +47 -0
  22. package/lib/convert/index.js.map +1 -0
  23. package/lib/convert/plan.d.ts +53 -0
  24. package/lib/convert/plan.js +669 -0
  25. package/lib/convert/plan.js.map +1 -0
  26. package/lib/convert/project.d.ts +29 -0
  27. package/lib/convert/project.js +109 -0
  28. package/lib/convert/project.js.map +1 -0
  29. package/lib/convert/run.d.ts +3 -0
  30. package/lib/convert/run.js +241 -0
  31. package/lib/convert/run.js.map +1 -0
  32. package/lib/convert/tests.d.ts +22 -0
  33. package/lib/convert/tests.js +267 -0
  34. package/lib/convert/tests.js.map +1 -0
  35. package/lib/datasource/conditionLocations.d.ts +9 -0
  36. package/lib/datasource/conditionLocations.js +70 -0
  37. package/lib/datasource/conditionLocations.js.map +1 -0
  38. package/lib/datasource/datasource.d.ts +11 -0
  39. package/lib/datasource/datasource.js +26 -6
  40. package/lib/datasource/datasource.js.map +1 -1
  41. package/lib/datasource/expressions.d.ts +36 -0
  42. package/lib/datasource/expressions.js +118 -0
  43. package/lib/datasource/expressions.js.map +1 -0
  44. package/lib/datasource/parseError.d.ts +11 -0
  45. package/lib/datasource/parseError.js +33 -19
  46. package/lib/datasource/parseError.js.map +1 -1
  47. package/lib/diff/conditions.d.ts +23 -0
  48. package/lib/diff/conditions.js +86 -0
  49. package/lib/diff/conditions.js.map +1 -0
  50. package/lib/diff/details.d.ts +7 -1
  51. package/lib/diff/details.js +54 -25
  52. package/lib/diff/details.js.map +1 -1
  53. package/lib/diff/index.d.ts +5 -0
  54. package/lib/diff/index.js +17 -2
  55. package/lib/diff/index.js.map +1 -1
  56. package/lib/evaluate/explain.d.ts +4 -1
  57. package/lib/evaluate/explain.js +35 -14
  58. package/lib/evaluate/explain.js.map +1 -1
  59. package/lib/evaluate/index.js +9 -5
  60. package/lib/evaluate/index.js.map +1 -1
  61. package/lib/formatter/expressions.d.ts +21 -0
  62. package/lib/formatter/expressions.js +79 -0
  63. package/lib/formatter/expressions.js.map +1 -0
  64. package/lib/formatter/formatDefinition.d.ts +46 -0
  65. package/lib/formatter/formatDefinition.js +201 -0
  66. package/lib/formatter/formatDefinition.js.map +1 -0
  67. package/lib/formatter/formatProject.d.ts +70 -0
  68. package/lib/formatter/formatProject.js +186 -0
  69. package/lib/formatter/formatProject.js.map +1 -0
  70. package/lib/formatter/index.d.ts +6 -0
  71. package/lib/formatter/index.js +53 -0
  72. package/lib/formatter/index.js.map +1 -0
  73. package/lib/formatter/layout.d.ts +26 -0
  74. package/lib/formatter/layout.js +175 -0
  75. package/lib/formatter/layout.js.map +1 -0
  76. package/lib/formatter/printFormatResult.d.ts +9 -0
  77. package/lib/formatter/printFormatResult.js +100 -0
  78. package/lib/formatter/printFormatResult.js.map +1 -0
  79. package/lib/formatter/run.d.ts +6 -0
  80. package/lib/formatter/run.js +97 -0
  81. package/lib/formatter/run.js.map +1 -0
  82. package/lib/formatter/simplify.d.ts +14 -0
  83. package/lib/formatter/simplify.js +21 -0
  84. package/lib/formatter/simplify.js.map +1 -0
  85. package/lib/formatter/since.d.ts +6 -0
  86. package/lib/formatter/since.js +80 -0
  87. package/lib/formatter/since.js.map +1 -0
  88. package/lib/formatter/style.d.ts +105 -0
  89. package/lib/formatter/style.js +248 -0
  90. package/lib/formatter/style.js.map +1 -0
  91. package/lib/linter/conditionKinds.js +2 -54
  92. package/lib/linter/conditionKinds.js.map +1 -1
  93. package/lib/linter/conditionSchema.js +42 -13
  94. package/lib/linter/conditionSchema.js.map +1 -1
  95. package/lib/linter/diagnostics.d.ts +14 -14
  96. package/lib/linter/expressionDiagnostics.d.ts +28 -0
  97. package/lib/linter/expressionDiagnostics.js +127 -0
  98. package/lib/linter/expressionDiagnostics.js.map +1 -0
  99. package/lib/linter/featureSchema.d.ts +2 -2
  100. package/lib/linter/featureSchema.js +14 -13
  101. package/lib/linter/featureSchema.js.map +1 -1
  102. package/lib/linter/lintProject.d.ts +7 -0
  103. package/lib/linter/lintProject.js +300 -52
  104. package/lib/linter/lintProject.js.map +1 -1
  105. package/lib/linter/listTypes.d.ts +7 -0
  106. package/lib/linter/listTypes.js +19 -0
  107. package/lib/linter/listTypes.js.map +1 -0
  108. package/lib/linter/printError.d.ts +2 -0
  109. package/lib/linter/printError.js +1 -0
  110. package/lib/linter/printError.js.map +1 -1
  111. package/lib/linter/requiredVariablesSchema.js +129 -13
  112. package/lib/linter/requiredVariablesSchema.js.map +1 -1
  113. package/lib/migrate/definitions.d.ts +46 -0
  114. package/lib/migrate/definitions.js +488 -0
  115. package/lib/migrate/definitions.js.map +1 -0
  116. package/lib/migrate/index.d.ts +6 -0
  117. package/lib/migrate/index.js +30 -0
  118. package/lib/migrate/index.js.map +1 -0
  119. package/lib/migrate/migrateProject.d.ts +33 -0
  120. package/lib/migrate/migrateProject.js +195 -0
  121. package/lib/migrate/migrateProject.js.map +1 -0
  122. package/lib/migrate/project.d.ts +31 -0
  123. package/lib/migrate/project.js +153 -0
  124. package/lib/migrate/project.js.map +1 -0
  125. package/lib/migrate/run.d.ts +3 -0
  126. package/lib/migrate/run.js +81 -0
  127. package/lib/migrate/run.js.map +1 -0
  128. package/lib/migrate/write.d.ts +10 -0
  129. package/lib/migrate/write.js +150 -0
  130. package/lib/migrate/write.js.map +1 -0
  131. package/lib/promoter/index.js +85 -4
  132. package/lib/promoter/index.js.map +1 -1
  133. package/lib/rewrite/conditions.d.ts +73 -0
  134. package/lib/rewrite/conditions.js +485 -0
  135. package/lib/rewrite/conditions.js.map +1 -0
  136. package/lib/rewrite/diff.d.ts +2 -0
  137. package/lib/rewrite/diff.js +76 -0
  138. package/lib/rewrite/diff.js.map +1 -0
  139. package/lib/rewrite/documents.d.ts +25 -0
  140. package/lib/rewrite/documents.js +54 -0
  141. package/lib/rewrite/documents.js.map +1 -0
  142. package/lib/rewrite/files.d.ts +6 -0
  143. package/lib/rewrite/files.js +66 -0
  144. package/lib/rewrite/files.js.map +1 -0
  145. package/lib/rewrite/lines.d.ts +56 -0
  146. package/lib/rewrite/lines.js +205 -0
  147. package/lib/rewrite/lines.js.map +1 -0
  148. package/package.json +5 -4
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORMAT_ENTITY_TYPES = void 0;
4
+ exports.getKeyOrder = getKeyOrder;
5
+ exports.isSpacedMap = isSpacedMap;
6
+ exports.isSpacedList = isSpacedList;
7
+ exports.orderValue = orderValue;
8
+ exports.getFormatLayout = getFormatLayout;
9
+ const style_1 = require("./style");
10
+ /**
11
+ * Where each kind of object sits in a definition, so the house style in style.ts reaches the
12
+ * right maps and lists. A parser's `format` receives the result as a FormatLayout.
13
+ *
14
+ * This file keeps the promise that formatting never changes a datafile. Only objects the
15
+ * builder rebuilds key by key are given a key order here: features, rules, force entries,
16
+ * variations, variablesSchema entries, segments, global variables and their overrides, and
17
+ * everything in test specs, which datafiles never hold. Values stay as written: variable
18
+ * values, context, condition leaves, compose references, and maps keyed by the author, such
19
+ * as variablesSchema or properties. Lists are never reordered, since rules, overrides,
20
+ * variations, conditions and mutations depend on their order.
21
+ */
22
+ /** Every kind of definition fmt formats, in the order it formats them */
23
+ exports.FORMAT_ENTITY_TYPES = [
24
+ "attribute",
25
+ "schema",
26
+ "segment",
27
+ "feature",
28
+ "variable",
29
+ "target",
30
+ "test",
31
+ "scenario",
32
+ ];
33
+ const VALUE = { kind: "value" };
34
+ /** Children are given as a function, so a shape can hold itself, as schemas and overrides do */
35
+ function map(order, space = false, children) {
36
+ let resolved;
37
+ return { kind: "map", order, space, children: () => (resolved ?? (resolved = children?.() ?? {})) };
38
+ }
39
+ function dict(value, space = false) {
40
+ return { kind: "dict", value, space };
41
+ }
42
+ function list(item, space = false) {
43
+ return { kind: "list", item, space };
44
+ }
45
+ function byEnvironment(item, space, spaceEnvironments) {
46
+ return { kind: "byEnvironment", item, space, spaceEnvironments };
47
+ }
48
+ const { keyOrder, blankLines } = style_1.HOUSE_STYLE;
49
+ /** A whole file */
50
+ function file(order, children) {
51
+ return map(order, blankLines.topLevelKeys, children);
52
+ }
53
+ const schema = map(keyOrder.schema, false, () => schemaChildren());
54
+ function schemaChildren() {
55
+ return {
56
+ properties: dict(schema, blankLines.schemaProperties),
57
+ items: schema,
58
+ oneOf: list(schema),
59
+ };
60
+ }
61
+ const featureVariableOverrides = dict(list(map(keyOrder.featureVariableOverride), blankLines.featureVariableOverrides));
62
+ const variableOverride = map(keyOrder.variableOverride, false, () => ({
63
+ overrides: list(variableOverride, blankLines.variableOverrides),
64
+ }));
65
+ const check = map(keyOrder.check, false, () => ({
66
+ and: list(check, blankLines.checks),
67
+ or: list(check, blankLines.checks),
68
+ not: list(check, blankLines.checks),
69
+ }));
70
+ function assertionChildren() {
71
+ return {
72
+ checks: list(check, blankLines.checks),
73
+ children: list(assertion, blankLines.assertionChildren),
74
+ };
75
+ }
76
+ const assertion = map(keyOrder.assertion, false, assertionChildren);
77
+ const SHAPES = {
78
+ attribute: file(keyOrder.attribute, schemaChildren),
79
+ schema: file(keyOrder.schema, schemaChildren),
80
+ segment: file(keyOrder.segment),
81
+ feature: file(keyOrder.feature, () => ({
82
+ variablesSchema: dict(map(keyOrder.variableSchema, false, schemaChildren), blankLines.variablesSchema),
83
+ variations: list(map(keyOrder.variation, false, () => ({ variableOverrides: featureVariableOverrides })), blankLines.variations),
84
+ force: byEnvironment(map(keyOrder.force), blankLines.force, blankLines.forceEnvironments),
85
+ // true, false or a list of tags, or one of those by environment
86
+ expose: dict(VALUE, blankLines.exposeEnvironments),
87
+ rules: byEnvironment(map(keyOrder.rule, false, () => ({ variableOverrides: featureVariableOverrides })), blankLines.rules, blankLines.ruleEnvironments),
88
+ })),
89
+ variable: file(keyOrder.variable, () => ({
90
+ ...schemaChildren(),
91
+ overrides: byEnvironment(variableOverride, blankLines.variableOverrides, blankLines.variableOverrideEnvironments),
92
+ })),
93
+ target: file(keyOrder.target),
94
+ test: file(keyOrder.test, () => ({ assertions: list(assertion, blankLines.assertions) })),
95
+ // a scenario spec is one assertion at the top level of its file
96
+ scenario: file(keyOrder.assertion, assertionChildren),
97
+ };
98
+ function childShape(shape, key) {
99
+ switch (shape.kind) {
100
+ case "map":
101
+ return typeof key === "string" ? shape.children()[key] || VALUE : VALUE;
102
+ case "dict":
103
+ return typeof key === "string" ? shape.value : VALUE;
104
+ case "list":
105
+ return typeof key === "number" ? shape.item : VALUE;
106
+ case "byEnvironment":
107
+ // a list's item, or an environment's list
108
+ return typeof key === "number" ? shape.item : list(shape.item, shape.space);
109
+ default:
110
+ return VALUE;
111
+ }
112
+ }
113
+ function shapeAt(entityType, path) {
114
+ let shape = SHAPES[entityType];
115
+ for (const key of path) {
116
+ shape = childShape(shape, key);
117
+ if (shape.kind === "value")
118
+ return shape;
119
+ }
120
+ return shape;
121
+ }
122
+ /** The keys of the map at `path` in house order, then any others as they were written */
123
+ function getKeyOrder(entityType, path, keys) {
124
+ const shape = shapeAt(entityType, path);
125
+ if (shape.kind !== "map")
126
+ return undefined;
127
+ const known = new Set(shape.order);
128
+ return [
129
+ ...shape.order.filter((key) => keys.includes(key)),
130
+ ...keys.filter((key) => !known.has(key)),
131
+ ];
132
+ }
133
+ /** Whether the map at `path` has a blank line between its entries */
134
+ function isSpacedMap(entityType, path) {
135
+ const shape = shapeAt(entityType, path);
136
+ if (shape.kind === "map" || shape.kind === "dict")
137
+ return shape.space;
138
+ // the node at a byEnvironment path is a map only when it groups lists by environment
139
+ if (shape.kind === "byEnvironment")
140
+ return shape.spaceEnvironments;
141
+ return false;
142
+ }
143
+ /** Whether the list at `path` has a blank line between its items */
144
+ function isSpacedList(entityType, path) {
145
+ const shape = shapeAt(entityType, path);
146
+ return (shape.kind === "list" || shape.kind === "byEnvironment") && shape.space;
147
+ }
148
+ /** The key order applied to a parsed value, for parsers that write from values */
149
+ function orderValue(entityType, value, path = []) {
150
+ if (Array.isArray(value)) {
151
+ return value.map((item, index) => orderValue(entityType, item, [...path, index]));
152
+ }
153
+ if (!value || typeof value !== "object")
154
+ return value;
155
+ const record = value;
156
+ const keys = getKeyOrder(entityType, path, Object.keys(record)) || Object.keys(record);
157
+ return Object.fromEntries(keys.map((key) => [key, orderValue(entityType, record[key], [...path, key])]));
158
+ }
159
+ /** Extensions that take another one's section of the house style's formats */
160
+ const FORMAT_ALIASES = { yaml: "yml" };
161
+ /** The layout a parser's `format` applies to one kind of definition */
162
+ function getFormatLayout(entityType, extension) {
163
+ const formats = style_1.HOUSE_STYLE.formats;
164
+ const format = extension && (FORMAT_ALIASES[extension] ?? extension);
165
+ return {
166
+ indent: style_1.HOUSE_STYLE.indent,
167
+ orderKeys: (path, keys) => getKeyOrder(entityType, path, keys),
168
+ spaceEntries: (path) => isSpacedMap(entityType, path),
169
+ spaceItems: (path) => isSpacedList(entityType, path),
170
+ keepBlankLines: style_1.HOUSE_STYLE.keepBlankLines,
171
+ orderValue: (value) => orderValue(entityType, value),
172
+ options: { ...(format ? formats[format] : undefined) },
173
+ };
174
+ }
175
+ //# sourceMappingUR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AAO,CAAC;IACxE,MAAM,MAAM,GAAG,SAAS,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC;IACrE,OAAO;QACL,MAAM,EAAE,mBAAW,CAAC,MAAM;QAC1B,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC;QAC9D,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC;QACrD,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC;QACpD,cAAc,EAAE,mBAAW,CAAC,cAAc;QAC1C,UAAU,EAAE,CAAI,KAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,CAAM;QAC/D,OAAO,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE;KACvD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { FormatProjectOptions, FormatProjectResult } from "./formatProject";
2
+ /**
3
+ * Prints the result of formatting source given on stdin. The formatted source goes to stdout
4
+ * for an editor, or what --check and --diff report, and an error goes to stderr. Source for a
5
+ * path that holds no definition comes back as it is.
6
+ */
7
+ export declare function printStdinResult(result: FormatProjectResult, options: FormatProjectOptions): void;
8
+ /** `simplifyFlag` is the flag that repeats this run's simplifying, when the project's setting does not */
9
+ export declare function printFormatResult(result: FormatProjectResult, options: FormatProjectOptions, simplifyFlag?: string): void;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printStdinResult = printStdinResult;
4
+ exports.printFormatResult = printFormatResult;
5
+ const cliFormat_1 = require("../tester/cliFormat");
6
+ function printError(file, log) {
7
+ const { line, column, message } = file.error;
8
+ const where = line ? `:${line}${column ? `:${column}` : ""}` : "";
9
+ log(cliFormat_1.CLI_FORMAT_RED, `${file.filePath}${where}`);
10
+ log(cliFormat_1.CLI_FORMAT_RED, ` => Error: ${message}`);
11
+ }
12
+ /**
13
+ * Prints the result of formatting source given on stdin. The formatted source goes to stdout
14
+ * for an editor, or what --check and --diff report, and an error goes to stderr. Source for a
15
+ * path that holds no definition comes back as it is.
16
+ */
17
+ function printStdinResult(result, options) {
18
+ const file = result.files[0];
19
+ if (file?.status === "error") {
20
+ printError(file, console.error);
21
+ }
22
+ else if (options.diff) {
23
+ if (file?.diff)
24
+ process.stdout.write(file.diff);
25
+ }
26
+ else if (options.check) {
27
+ if (file?.status === "changed")
28
+ console.log(file.filePath);
29
+ }
30
+ else {
31
+ process.stdout.write(file?.output ?? options.stdin.source);
32
+ }
33
+ }
34
+ /** `simplifyFlag` is the flag that repeats this run's simplifying, when the project's setting does not */
35
+ function printFormatResult(result, options, simplifyFlag = options.simplify ? "--simplify" : "") {
36
+ const write = !options.check && !options.diff;
37
+ if (result.unsupported) {
38
+ console.log(cliFormat_1.CLI_FORMAT_YELLOW, "This project's parser has no format function, so fmt leaves its files as they are.");
39
+ return;
40
+ }
41
+ for (const file of result.files) {
42
+ if (file.status === "changed") {
43
+ if (options.diff && file.diff) {
44
+ process.stdout.write(file.diff);
45
+ }
46
+ else {
47
+ console.log(write ? `Formatted ${file.filePath}` : file.filePath);
48
+ }
49
+ }
50
+ else if (file.status === "declined") {
51
+ console.log(cliFormat_1.CLI_FORMAT_DIM, `Left ${file.filePath} as it is: the parser could not format it`);
52
+ }
53
+ else if (file.status === "error" && file.error) {
54
+ printError(file, console.log);
55
+ }
56
+ }
57
+ for (const skipped of result.skipped) {
58
+ console.log(cliFormat_1.CLI_FORMAT_DIM, `Skipped ${skipped}, no definitions of this project there`);
59
+ }
60
+ const total = result.files.length;
61
+ const files = (count) => `${count} ${count === 1 ? "file" : "files"}`;
62
+ console.log("");
63
+ if (total === 0) {
64
+ console.log(cliFormat_1.CLI_FORMAT_YELLOW, options.since === undefined
65
+ ? "No definition files matched"
66
+ : `No definition files changed since ${options.since}`);
67
+ return;
68
+ }
69
+ if (result.errors > 0) {
70
+ console.log(cliFormat_1.CLI_FORMAT_RED, `${files(result.errors)} could not be formatted`);
71
+ }
72
+ if (result.declined > 0) {
73
+ console.log(cliFormat_1.CLI_FORMAT_YELLOW, `${files(result.declined)} left unformatted by the parser`);
74
+ }
75
+ if (result.ignored > 0) {
76
+ console.log(cliFormat_1.CLI_FORMAT_DIM, `${files(result.ignored)} left as written by featurevisor-ignore`);
77
+ }
78
+ if (result.changed > 0) {
79
+ if (write) {
80
+ console.log(cliFormat_1.CLI_FORMAT_GREEN, `✔ Formatted ${files(result.changed)} of ${total}`);
81
+ }
82
+ else {
83
+ const verb = result.changed === 1 ? "needs" : "need";
84
+ const since = options.since === undefined ? "" : ` --since=${options.since}`;
85
+ const simplify = simplifyFlag ? ` ${simplifyFlag}` : "";
86
+ console.log(cliFormat_1.CLI_FORMAT_YELLOW, `${files(result.changed)} of ${total} ${verb} formatting. Run: npx featurevisor fmt${simplify}${since}`);
87
+ }
88
+ }
89
+ else if (result.errors === 0) {
90
+ const left = result.declined + result.ignored;
91
+ const formatted = total - left;
92
+ if (formatted === 1) {
93
+ console.log(cliFormat_1.CLI_FORMAT_GREEN, `✔ ${left > 0 ? "The other file" : "The file"} is formatted`);
94
+ }
95
+ else if (formatted > 1) {
96
+ console.log(cliFormat_1.CLI_FORMAT_GREEN, `✔ ${left > 0 ? "The other" : "All"} ${files(formatted)} are formatted`);
97
+ }
98
+ }
99
+ }
100
+ //# sourceMappingURL=printFormatResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printFormatResult.js","sourceRoot":"","sources":["../../src/formatter/printFormatResult.ts"],"names":[],"mappings":";;AAoBA,4CAWC;AAGD,8CAgFC;AAlHD,mDAK6B;AAG7B,SAAS,UAAU,CAAC,IAAsB,EAAE,GAAiC;IAC3E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CAAC,CAAC,CAAC,MAAM,CAAC;YACrD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7E,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxD,OAAO,CAAC,GAAG,CACT,6BAAiB,EACjB,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,IAAI,yCAAyC,QAAQ,GAAG,KAAK,EAAE,CACxG,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9C,MAAM,SAAS,GAAG,KAAK,GAAG,IAAI,CAAC;QAC/B,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,4BAAgB,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,eAAe,CAAC,CAAC;QAC9F,CAAC;aAAM,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CACT,4BAAgB,EAChB,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,gBAAgB,CACxE,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { PluginHandlerOptions } from "../cli";
2
+ /**
3
+ * The command, as Prettier exits: 0 when formatted, 1 when --check finds files that need
4
+ * formatting, and 2 when fmt could not format, for errors to stand apart from work to do in CI
5
+ */
6
+ export declare function runFormat({ rootDirectoryPath, projectConfig, datasource, parsed, }: PluginHandlerOptions): Promise<number>;
@@ -0,0 +1,97 @@
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.runFormat = runFormat;
37
+ const fs = __importStar(require("node:fs"));
38
+ const validation_1 = require("../cli/validation");
39
+ const error_1 = require("../error");
40
+ const formatProject_1 = require("./formatProject");
41
+ const printFormatResult_1 = require("./printFormatResult");
42
+ /**
43
+ * The command, as Prettier exits: 0 when formatted, 1 when --check finds files that need
44
+ * formatting, and 2 when fmt could not format, for errors to stand apart from work to do in CI
45
+ */
46
+ async function runFormat({ rootDirectoryPath, projectConfig, datasource, parsed, }) {
47
+ const json = parsed.json === true;
48
+ // --simplify and --no-simplify win over the project's simplifyConditions
49
+ const simplifyByDefault = projectConfig.simplifyConditions === true;
50
+ const simplify = typeof parsed.simplify === "boolean" ? parsed.simplify : simplifyByDefault;
51
+ try {
52
+ const options = {
53
+ check: parsed.check === true,
54
+ diff: parsed.diff === true,
55
+ entityType: parsed.entityType,
56
+ keyPattern: parsed.keyPattern !== undefined
57
+ ? (0, validation_1.parseRegexOption)("--key-pattern", parsed.keyPattern)
58
+ : undefined,
59
+ paths: parsed.paths || [],
60
+ since: parsed.since,
61
+ set: parsed.set,
62
+ simplify,
63
+ };
64
+ if (parsed.stdinFilepath !== undefined) {
65
+ if (options.paths.length > 0 || options.since !== undefined) {
66
+ throw new error_1.FeaturevisorCLIError("--stdin-filepath formats one file. Leave out the other paths and --since.", { code: "invalid_cli_arguments" });
67
+ }
68
+ options.stdin = {
69
+ filePath: String(parsed.stdinFilepath),
70
+ source: fs.readFileSync(0, "utf8"),
71
+ };
72
+ }
73
+ // one run across every Set, so a project is formatted, checked and reported as a whole
74
+ const result = await (0, formatProject_1.formatProject)({ rootDirectoryPath, projectConfig, datasource }, options);
75
+ if (json) {
76
+ console.log(parsed.pretty ? JSON.stringify(result, null, 2) : JSON.stringify(result));
77
+ }
78
+ else if (options.stdin) {
79
+ (0, printFormatResult_1.printStdinResult)(result, options);
80
+ }
81
+ else {
82
+ const flag = simplify === simplifyByDefault ? "" : simplify ? "--simplify" : "--no-simplify";
83
+ (0, printFormatResult_1.printFormatResult)(result, options, flag);
84
+ }
85
+ // --diff alone shows the changes, and --check fails on them, with or without --diff
86
+ if (result.errors > 0)
87
+ return 2;
88
+ if (options.check && result.changed > 0)
89
+ return 1;
90
+ return 0;
91
+ }
92
+ catch (error) {
93
+ console.error((0, error_1.formatFeaturevisorCLIError)(error, { json, pretty: parsed.pretty === true }));
94
+ return 2;
95
+ }
96
+ }
97
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"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,kCAA0B,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3F,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ExpressionOptions } from "@featurevisor/expressions";
2
+ import type { CustomParser } from "@featurevisor/parsers";
3
+ import type { EntityType } from "@featurevisor/types";
4
+ /** The source with its conditions simplified, and the comment lines moved into expressions */
5
+ export interface SimplifiedSource {
6
+ source: string;
7
+ moved: string[];
8
+ }
9
+ /**
10
+ * The source with each condition in its simplest form that evaluates the same, the rest of
11
+ * the file as written, for fmt's --simplify to format next. Only `conditions` values change.
12
+ * Undefined when the parser cannot read it back, which fmt then reports.
13
+ */
14
+ export declare function simplifySource(entityType: EntityType, source: string, parser: CustomParser, expressions?: ExpressionOptions): SimplifiedSource | undefined;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simplifySource = simplifySource;
4
+ const conditions_1 = require("../rewrite/conditions");
5
+ const documents_1 = require("../rewrite/documents");
6
+ /**
7
+ * The source with each condition in its simplest form that evaluates the same, the rest of
8
+ * the file as written, for fmt's --simplify to format next. Only `conditions` values change.
9
+ * Undefined when the parser cannot read it back, which fmt then reports.
10
+ */
11
+ function simplifySource(entityType, source, parser, expressions) {
12
+ if (!conditions_1.CONDITION_KINDS.includes(entityType))
13
+ return { source, moved: [] };
14
+ const { doc } = (0, documents_1.load)(source, parser);
15
+ const result = (0, conditions_1.simplifyConditions)(doc, entityType, parser.parse(source), expressions);
16
+ if (result.changed === 0)
17
+ return { source, moved: [] };
18
+ const rendered = (0, documents_1.render)(source, doc, parser);
19
+ return rendered ? { source: rendered.text, moved: result.moved } : undefined;
20
+ }
21
+ //# sourceMappingURL=simplify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplify.js","sourceRoot":"","sources":["../../src/formatter/simplify.ts"],"names":[],"mappings":";;AAkBA,wCAiBC;AA/BD,sDAAgG;AAChG,oDAAoD;AAQpD;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,UAAsB,EACtB,MAAc,EACd,MAAoB,EACpB,WAA+B;IAE/B,IAAI,CAAC,4BAAe,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACxE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,gBAAI,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,IAAA,+BAAkB,EAC/B,GAAG,EACH,UAA2B,EAC3B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EACpB,WAAW,CACZ,CAAC;IACF,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAA,kBAAM,EAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The real paths of the files changed since HEAD left `ref`: committed since the commit they
3
+ * share, staged, unstaged and untracked. Deleted files are left out. Compare them with
4
+ * fs.realpathSync.native, which writes a path as Git does, also on Windows.
5
+ */
6
+ export declare function getChangedFiles(directory: string, ref: string): Set<string>;
@@ -0,0 +1,80 @@
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.getChangedFiles = getChangedFiles;
37
+ const node_child_process_1 = require("node:child_process");
38
+ const fs = __importStar(require("node:fs"));
39
+ const path = __importStar(require("node:path"));
40
+ const error_1 = require("../error");
41
+ /** Reads Git without a shell or optional lock writes, as the diff command does */
42
+ function git(directory, args) {
43
+ return (0, node_child_process_1.execFileSync)("git", ["--literal-pathspecs", ...args], {
44
+ cwd: directory,
45
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
46
+ maxBuffer: 64 * 1024 * 1024,
47
+ stdio: ["ignore", "pipe", "pipe"],
48
+ }).toString();
49
+ }
50
+ function sinceError(message, ref) {
51
+ return new error_1.FeaturevisorCLIError(message, { code: "since_error", details: { ref } });
52
+ }
53
+ /**
54
+ * The real paths of the files changed since HEAD left `ref`: committed since the commit they
55
+ * share, staged, unstaged and untracked. Deleted files are left out. Compare them with
56
+ * fs.realpathSync.native, which writes a path as Git does, also on Windows.
57
+ */
58
+ function getChangedFiles(directory, ref) {
59
+ let root;
60
+ try {
61
+ root = fs.realpathSync.native(git(directory, ["rev-parse", "--show-toplevel"]).trim());
62
+ }
63
+ catch {
64
+ throw sinceError("fmt --since needs the project in a Git working tree.", ref);
65
+ }
66
+ let base;
67
+ try {
68
+ const commit = git(root, ["rev-parse", "--verify", "--end-of-options", `${ref}^{commit}`]);
69
+ base = git(root, ["merge-base", commit.trim(), "HEAD"]).trim();
70
+ }
71
+ catch {
72
+ throw sinceError(`Cannot find where HEAD left ${JSON.stringify(ref)}. Check the reference, and fetch its history in CI.`, ref);
73
+ }
74
+ const files = [
75
+ ...git(root, ["diff", "--name-only", "-z", "--diff-filter=d", base]).split("\0"),
76
+ ...git(root, ["ls-files", "--others", "--exclude-standard", "-z"]).split("\0"),
77
+ ];
78
+ return new Set(files.filter(Boolean).map((file) => path.join(root, file)));
79
+ }
80
+ //# sourceMappingURL=since.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"since.js","sourceRoot":"","sources":["../../src/formatter/since.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,0CAwBC;AAjDD,2DAAkD;AAClD,4CAA8B;AAC9B,gDAAkC;AAElC,oCAAgD;AAEhD,kFAAkF;AAClF,SAAS,GAAG,CAAC,SAAiB,EAAE,IAAc;IAC5C,OAAO,IAAA,iCAAY,EAAC,KAAK,EAAE,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,EAAE;QAC3D,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE;QAChD,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;QAC3B,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;KAClC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAChB,CAA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