@cplieger/deadset-ts 0.1.0 → 1.1.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/src/print.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { renderOrigin, type Config, type Provenance } from "./config.ts";
2
+
3
+ /**
4
+ * The resolved configuration and its provenance as one JSON object, indented,
5
+ * ending in a newline.
6
+ *
7
+ * The output is an instance of the closed key list, so reading it back as a
8
+ * repository configuration resolves to the same configuration: the provenance
9
+ * object is a declared key resolution ignores. Keys are written in the schema's
10
+ * order and the severity and provenance objects in ascending key order, so one
11
+ * configuration renders to one string whatever order a source named its settings
12
+ * in.
13
+ */
14
+ export function printConfig(config: Config, provenance: Provenance): string {
15
+ const document = {
16
+ contract_version: config.contractVersion,
17
+ target: { kind: config.targetKind },
18
+ analysis: {
19
+ languages: config.analysis.languages,
20
+ min_confidence: config.analysis.minConfidence,
21
+ generated_files: config.analysis.generatedFiles,
22
+ consumer_tests: config.analysis.consumerTests,
23
+ configurations: config.analysis.configurations.map((entry) => ({
24
+ id: entry.id,
25
+ os: entry.os,
26
+ arch: entry.arch,
27
+ tags: entry.tags,
28
+ })),
29
+ matrix: { complete: config.analysis.matrixComplete },
30
+ template_dirs: config.analysis.templateDirs,
31
+ template_delimiters: {
32
+ left: config.analysis.templateDelimiters.left,
33
+ right: config.analysis.templateDelimiters.right,
34
+ },
35
+ },
36
+ consumers: { complete: config.consumersComplete },
37
+ roots: { patterns: config.rootPatterns },
38
+ severity: Object.fromEntries([...config.severity].sort(([a], [b]) => (a < b ? -1 : 1))),
39
+ exemptions: { disabled: config.exemptionsDisabled },
40
+ reporters: {
41
+ formats: config.reporters.formats,
42
+ sort: config.reporters.sort,
43
+ cascade: config.reporters.cascade,
44
+ max_findings: config.reporters.maxFindings,
45
+ fail_on: config.reporters.failOn,
46
+ },
47
+ go: {},
48
+ ts: {
49
+ test_files: config.ts.testFiles,
50
+ entry_files: config.ts.entryFiles,
51
+ },
52
+ provenance: Object.fromEntries(
53
+ [...provenance]
54
+ .sort(([a], [b]) => (a < b ? -1 : 1))
55
+ .map(([path, origin]) => [path, renderOrigin(origin)]),
56
+ ),
57
+ };
58
+ return `${JSON.stringify(document, undefined, 2)}\n`;
59
+ }