@goodbones/core 0.1.0-beta.1 → 0.1.0-beta.10
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/build/dts/core/campaigns.d.ts +141 -0
- package/build/dts/core/campaigns.d.ts.map +1 -0
- package/build/dts/core/coverage.d.ts +20 -0
- package/build/dts/core/coverage.d.ts.map +1 -1
- package/build/dts/core/graph.d.ts +2 -0
- package/build/dts/core/graph.d.ts.map +1 -1
- package/build/dts/core/imports.d.ts +3 -1
- package/build/dts/core/imports.d.ts.map +1 -1
- package/build/dts/core/ledger.d.ts +61 -0
- package/build/dts/core/ledger.d.ts.map +1 -0
- package/build/dts/core/slack.d.ts +22 -0
- package/build/dts/core/slack.d.ts.map +1 -0
- package/build/dts/core/structure.d.ts +1 -0
- package/build/dts/core/structure.d.ts.map +1 -1
- package/build/dts/domain/architecture-config.d.ts +324 -1
- package/build/dts/domain/architecture-config.d.ts.map +1 -1
- package/build/dts/domain/architecture-error.d.ts +8 -0
- package/build/dts/domain/architecture-error.d.ts.map +1 -1
- package/build/dts/domain/facts.d.ts +1 -0
- package/build/dts/domain/facts.d.ts.map +1 -1
- package/build/dts/domain/manifest-location.d.ts +9 -0
- package/build/dts/domain/manifest-location.d.ts.map +1 -0
- package/build/dts/domain/report.d.ts +16 -0
- package/build/dts/domain/report.d.ts.map +1 -0
- package/build/dts/domain/snapshot.d.ts +224 -0
- package/build/dts/domain/snapshot.d.ts.map +1 -0
- package/build/dts/domain/violation.d.ts +1 -1
- package/build/dts/domain/violation.d.ts.map +1 -1
- package/build/dts/index.d.ts +24 -9
- package/build/dts/index.d.ts.map +1 -1
- package/build/dts/infrastructure/campaign-functions.d.ts +7 -0
- package/build/dts/infrastructure/campaign-functions.d.ts.map +1 -0
- package/build/dts/infrastructure/manifest-file.d.ts +11 -2
- package/build/dts/infrastructure/manifest-file.d.ts.map +1 -1
- package/build/dts/infrastructure/manifest-include.d.ts +16 -0
- package/build/dts/infrastructure/manifest-include.d.ts.map +1 -0
- package/build/dts/infrastructure/report-source-fake.d.ts +4 -0
- package/build/dts/infrastructure/report-source-fake.d.ts.map +1 -0
- package/build/dts/infrastructure/report-source-live.d.ts +3 -0
- package/build/dts/infrastructure/report-source-live.d.ts.map +1 -0
- package/build/dts/infrastructure/syntax-matcher-fake.d.ts +10 -0
- package/build/dts/infrastructure/syntax-matcher-fake.d.ts.map +1 -0
- package/build/dts/infrastructure/walk.d.ts +6 -0
- package/build/dts/infrastructure/walk.d.ts.map +1 -1
- package/build/dts/load/policy.d.ts +16 -0
- package/build/dts/load/policy.d.ts.map +1 -1
- package/build/dts/manifest/compile.d.ts +7 -2
- package/build/dts/manifest/compile.d.ts.map +1 -1
- package/build/dts/manifest/expand.d.ts +27 -0
- package/build/dts/manifest/expand.d.ts.map +1 -0
- package/build/dts/manifest/infer.d.ts +55 -0
- package/build/dts/manifest/infer.d.ts.map +1 -0
- package/build/dts/manifest/json-schema.d.ts +10 -0
- package/build/dts/manifest/json-schema.d.ts.map +1 -0
- package/build/dts/manifest/manifest.d.ts +381 -1
- package/build/dts/manifest/manifest.d.ts.map +1 -1
- package/build/dts/ports/campaign-predicate.d.ts +24 -0
- package/build/dts/ports/campaign-predicate.d.ts.map +1 -0
- package/build/dts/ports/language.d.ts +4 -0
- package/build/dts/ports/language.d.ts.map +1 -1
- package/build/dts/ports/report-source.d.ts +14 -0
- package/build/dts/ports/report-source.d.ts.map +1 -0
- package/build/dts/ports/syntax-matcher.d.ts +21 -0
- package/build/dts/ports/syntax-matcher.d.ts.map +1 -0
- package/build/dts/testing.d.ts +2 -0
- package/build/dts/testing.d.ts.map +1 -1
- package/build/esm/core/campaigns.js +778 -0
- package/build/esm/core/campaigns.js.map +1 -0
- package/build/esm/core/coverage.js +107 -32
- package/build/esm/core/coverage.js.map +1 -1
- package/build/esm/core/graph.js +45 -0
- package/build/esm/core/graph.js.map +1 -1
- package/build/esm/core/imports.js +14 -9
- package/build/esm/core/imports.js.map +1 -1
- package/build/esm/core/ledger.js +171 -0
- package/build/esm/core/ledger.js.map +1 -0
- package/build/esm/core/slack.js +76 -0
- package/build/esm/core/slack.js.map +1 -0
- package/build/esm/core/structure.js +5 -2
- package/build/esm/core/structure.js.map +1 -1
- package/build/esm/domain/architecture-config.js +158 -1
- package/build/esm/domain/architecture-config.js.map +1 -1
- package/build/esm/domain/architecture-error.js +27 -0
- package/build/esm/domain/architecture-error.js.map +1 -1
- package/build/esm/domain/manifest-location.js +21 -0
- package/build/esm/domain/manifest-location.js.map +1 -0
- package/build/esm/domain/report.js +168 -0
- package/build/esm/domain/report.js.map +1 -0
- package/build/esm/domain/snapshot.js +141 -0
- package/build/esm/domain/snapshot.js.map +1 -0
- package/build/esm/domain/violation.js.map +1 -1
- package/build/esm/index.js +21 -8
- package/build/esm/index.js.map +1 -1
- package/build/esm/infrastructure/campaign-functions.js +67 -0
- package/build/esm/infrastructure/campaign-functions.js.map +1 -0
- package/build/esm/infrastructure/manifest-file.js +158 -7
- package/build/esm/infrastructure/manifest-file.js.map +1 -1
- package/build/esm/infrastructure/manifest-include.js +187 -0
- package/build/esm/infrastructure/manifest-include.js.map +1 -0
- package/build/esm/infrastructure/report-source-fake.js +6 -0
- package/build/esm/infrastructure/report-source-fake.js.map +1 -0
- package/build/esm/infrastructure/report-source-live.js +165 -0
- package/build/esm/infrastructure/report-source-live.js.map +1 -0
- package/build/esm/infrastructure/syntax-matcher-fake.js +33 -0
- package/build/esm/infrastructure/syntax-matcher-fake.js.map +1 -0
- package/build/esm/infrastructure/walk.js +57 -1
- package/build/esm/infrastructure/walk.js.map +1 -1
- package/build/esm/load/policy.js +123 -3
- package/build/esm/load/policy.js.map +1 -1
- package/build/esm/manifest/compile.js +228 -26
- package/build/esm/manifest/compile.js.map +1 -1
- package/build/esm/manifest/expand.js +116 -0
- package/build/esm/manifest/expand.js.map +1 -0
- package/build/esm/manifest/infer.js +455 -0
- package/build/esm/manifest/infer.js.map +1 -0
- package/build/esm/manifest/json-schema.js +135 -0
- package/build/esm/manifest/json-schema.js.map +1 -0
- package/build/esm/manifest/manifest.js +243 -5
- package/build/esm/manifest/manifest.js.map +1 -1
- package/build/esm/ports/campaign-predicate.js +2 -0
- package/build/esm/ports/campaign-predicate.js.map +1 -0
- package/build/esm/ports/report-source.js +7 -0
- package/build/esm/ports/report-source.js.map +1 -0
- package/build/esm/ports/syntax-matcher.js +12 -0
- package/build/esm/ports/syntax-matcher.js.map +1 -0
- package/build/esm/testing.js +2 -0
- package/build/esm/testing.js.map +1 -1
- package/package.json +9 -3
- package/schema/architecture-node.schema.json +2405 -0
- package/schema/architecture.schema.json +2825 -0
- package/schema/conformance.schema.json +775 -0
- package/src/core/campaigns.ts +1056 -0
- package/src/core/coverage.ts +164 -34
- package/src/core/graph.ts +48 -0
- package/src/core/imports.ts +29 -13
- package/src/core/ledger.ts +242 -0
- package/src/core/slack.ts +135 -0
- package/src/core/structure.ts +10 -5
- package/src/domain/architecture-config.ts +205 -1
- package/src/domain/architecture-error.ts +30 -0
- package/src/domain/facts.ts +9 -4
- package/src/domain/manifest-location.ts +41 -0
- package/src/domain/report.ts +203 -0
- package/src/domain/snapshot.ts +302 -0
- package/src/domain/violation.ts +4 -1
- package/src/index.ts +172 -3
- package/src/infrastructure/campaign-functions.ts +98 -0
- package/src/infrastructure/manifest-file.ts +204 -8
- package/src/infrastructure/manifest-include.ts +318 -0
- package/src/infrastructure/report-source-fake.ts +10 -0
- package/src/infrastructure/report-source-live.ts +192 -0
- package/src/infrastructure/syntax-matcher-fake.ts +51 -0
- package/src/infrastructure/walk.ts +70 -1
- package/src/load/policy.ts +193 -3
- package/src/manifest/compile.ts +290 -28
- package/src/manifest/expand.ts +183 -0
- package/src/manifest/infer.ts +643 -0
- package/src/manifest/json-schema.ts +168 -0
- package/src/manifest/manifest.ts +339 -11
- package/src/ports/campaign-predicate.ts +30 -0
- package/src/ports/language.ts +17 -0
- package/src/ports/report-source.ts +35 -0
- package/src/ports/syntax-matcher.ts +42 -0
- package/src/testing.ts +2 -0
|
@@ -1,15 +1,166 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
1
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { isAlias, isMap, isScalar, isSeq, LineCounter, parseDocument, stringify, } from "yaml";
|
|
2
5
|
import { ConfigInvalid } from "../domain/architecture-error.js";
|
|
3
|
-
|
|
4
|
-
// The manifest, as the
|
|
5
|
-
//
|
|
6
|
-
//
|
|
6
|
+
import { expandIncludes } from "./manifest-include.js";
|
|
7
|
+
// The manifest, as the files on disk state it, before any decoding. A data
|
|
8
|
+
// file — YAML, or JSON, which YAML 1.2 contains — is what any host in any
|
|
9
|
+
// language can read, and is the form the docs are written in. A JavaScript
|
|
10
|
+
// module is the escape hatch a Node host alone honours: for a manifest
|
|
11
|
+
// generated from other data, and for what the ecosystem expects of a config
|
|
12
|
+
// file. Either may `include` further data files, so a monorepo's policy can
|
|
13
|
+
// live beside the packages it governs. Whichever it is, what comes out is one
|
|
14
|
+
// `unknown` value for the decoder, and, from the data formats, a way to turn
|
|
15
|
+
// a path in it back into a file and a line.
|
|
16
|
+
// In discovery order. A repository with none of these is told all four; one
|
|
17
|
+
// with more than one is refused, so nobody edits the wrong file for a week.
|
|
18
|
+
export const MANIFEST_FILENAMES = [
|
|
19
|
+
"architecture.yaml",
|
|
20
|
+
"architecture.yml",
|
|
21
|
+
"architecture.json",
|
|
22
|
+
"architecture.config.mjs",
|
|
23
|
+
];
|
|
24
|
+
export const findManifestFile = (repoRoot) => {
|
|
25
|
+
const present = MANIFEST_FILENAMES.filter((name) => existsSync(path.resolve(repoRoot, name)));
|
|
26
|
+
const [found] = present;
|
|
27
|
+
if (found === undefined) {
|
|
28
|
+
throw new ConfigInvalid({
|
|
29
|
+
configPath: repoRoot,
|
|
30
|
+
detail: `no architecture manifest found. Looked for ${MANIFEST_FILENAMES.join(", ")} ` +
|
|
31
|
+
`in this directory; \`architecture init\` writes a starter architecture.yaml.`,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (present.length > 1) {
|
|
35
|
+
throw new ConfigInvalid({
|
|
36
|
+
configPath: repoRoot,
|
|
37
|
+
detail: `more than one architecture manifest is present (${present.join(", ")}), and only one ` +
|
|
38
|
+
`can be the policy. Delete the others, or name one with ARCHITECTURE_CONFIG.`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return path.resolve(repoRoot, found);
|
|
42
|
+
};
|
|
43
|
+
const extensionOf = (configPath) => path.extname(configPath).toLowerCase();
|
|
44
|
+
const isDataManifest = (configPath) => [".yaml", ".yml", ".json"].includes(extensionOf(configPath));
|
|
45
|
+
const isModuleManifest = (configPath) => [".mjs", ".js", ".cjs"].includes(extensionOf(configPath));
|
|
46
|
+
// Whichever form the root takes, an `include` in it names a data file, read
|
|
47
|
+
// by the same parser; the locator that comes back answers across every file.
|
|
7
48
|
export const readManifestFile = async (configPath) => {
|
|
49
|
+
const root = isDataManifest(configPath)
|
|
50
|
+
? parseDataFile(configPath)
|
|
51
|
+
: isModuleManifest(configPath)
|
|
52
|
+
? await readModule(configPath)
|
|
53
|
+
: undefined;
|
|
54
|
+
if (root === undefined) {
|
|
55
|
+
throw new ConfigInvalid({
|
|
56
|
+
configPath,
|
|
57
|
+
detail: "a manifest is a .yaml, .yml or .json file, or a .mjs/.js module — " +
|
|
58
|
+
`not ${JSON.stringify(path.basename(configPath))}.`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const assembled = expandIncludes(configPath, root, { exists: existsSync, read: parseDataFile });
|
|
62
|
+
return {
|
|
63
|
+
configPath,
|
|
64
|
+
manifest: assembled.value,
|
|
65
|
+
locate: assembled.locate,
|
|
66
|
+
files: assembled.files,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const readModule = async (configPath) => {
|
|
8
70
|
const module = await import(pathToFileURL(configPath).href).catch((cause) => {
|
|
9
71
|
throw new ConfigInvalid({ configPath, detail: String(cause) });
|
|
10
72
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
73
|
+
const value = typeof module === "object" && module !== null && "default" in module ? module.default : module;
|
|
74
|
+
return { value, locate: undefined };
|
|
75
|
+
};
|
|
76
|
+
// YAML 1.2 core schema, which is what a reader without a YAML background
|
|
77
|
+
// expects: `on` and `no` are strings, not booleans. Merge keys (`<<`) resolve,
|
|
78
|
+
// because the parser handles them before the manifest sees the document, and
|
|
79
|
+
// duplicate keys are refused rather than last-one-wins. A tag the parser does
|
|
80
|
+
// not know is refused too — a manifest is data, and a `!!js/function` in it
|
|
81
|
+
// would be a manifest only one runtime could read.
|
|
82
|
+
const parseDataFile = (configPath) => {
|
|
83
|
+
let text;
|
|
84
|
+
try {
|
|
85
|
+
text = readFileSync(configPath, "utf8");
|
|
86
|
+
}
|
|
87
|
+
catch (cause) {
|
|
88
|
+
throw new ConfigInvalid({ configPath, detail: String(cause) });
|
|
89
|
+
}
|
|
90
|
+
const lines = new LineCounter();
|
|
91
|
+
const document = parseDocument(text, {
|
|
92
|
+
merge: true,
|
|
93
|
+
uniqueKeys: true,
|
|
94
|
+
customTags: [],
|
|
95
|
+
lineCounter: lines,
|
|
96
|
+
// A JSON file is read by the same parser; strict JSON is valid YAML.
|
|
97
|
+
schema: "core",
|
|
98
|
+
});
|
|
99
|
+
const problems = [...document.errors, ...document.warnings];
|
|
100
|
+
if (problems.length > 0) {
|
|
101
|
+
const file = path.basename(configPath);
|
|
102
|
+
throw new ConfigInvalid({
|
|
103
|
+
configPath,
|
|
104
|
+
detail: "the manifest does not parse:\n" +
|
|
105
|
+
problems
|
|
106
|
+
.map((problem) => {
|
|
107
|
+
const [position] = problem.linePos ?? [];
|
|
108
|
+
const at = position === undefined
|
|
109
|
+
? ""
|
|
110
|
+
: `${file}:${String(position.line)}:${String(position.col)} `;
|
|
111
|
+
return ` ${at}${problem.code}: ${problem.message.split("\n")[0] ?? problem.message}`;
|
|
112
|
+
})
|
|
113
|
+
.join("\n"),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
value: document.toJS({ mapAsMap: false }),
|
|
118
|
+
locate: makeLocator(document, lines),
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const keyMatches = (pair, segment) => isScalar(pair.key) && String(pair.key.value) === String(segment);
|
|
122
|
+
// Walks the document's own tree by the decoder's path and answers with the
|
|
123
|
+
// position of the deepest thing that exists along it. A map key is reported
|
|
124
|
+
// at the key, where the reader's eye lands; a sequence item at the item. A
|
|
125
|
+
// key merged in through `<<` lives in the fragment it came from, which the
|
|
126
|
+
// walk cannot see — the reader then gets the position of the map instead.
|
|
127
|
+
const makeLocator = (document, lines) => {
|
|
128
|
+
const positionOf = (node) => {
|
|
129
|
+
const offset = node?.range?.[0];
|
|
130
|
+
if (offset === undefined)
|
|
131
|
+
return null;
|
|
132
|
+
const { col, line } = lines.linePos(offset);
|
|
133
|
+
return { line, column: col };
|
|
134
|
+
};
|
|
135
|
+
const resolved = (node) => (isAlias(node) ? node.resolve(document) : node);
|
|
136
|
+
return (manifestPath) => {
|
|
137
|
+
let current = resolved(document.contents);
|
|
138
|
+
let position = positionOf(document.contents);
|
|
139
|
+
for (const segment of manifestPath) {
|
|
140
|
+
if (isMap(current)) {
|
|
141
|
+
const pair = current.items.find((one) => keyMatches(one, segment));
|
|
142
|
+
if (pair === undefined)
|
|
143
|
+
break;
|
|
144
|
+
position = positionOf(isScalar(pair.key) ? pair.key : null) ?? position;
|
|
145
|
+
current = resolved(pair.value);
|
|
146
|
+
}
|
|
147
|
+
else if (isSeq(current) && typeof segment === "number") {
|
|
148
|
+
const item = current.items[segment];
|
|
149
|
+
if (item === undefined)
|
|
150
|
+
break;
|
|
151
|
+
position = positionOf(item) ?? position;
|
|
152
|
+
current = resolved(item);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return position;
|
|
159
|
+
};
|
|
14
160
|
};
|
|
161
|
+
// The value as a YAML document, for `architecture migrate` and anything else
|
|
162
|
+
// that writes a manifest rather than reads one. Strings are quoted whenever
|
|
163
|
+
// the core schema would read them as something else, and a multi-line one —
|
|
164
|
+
// a probe source — becomes a block scalar.
|
|
165
|
+
export const formatManifestYaml = (manifest) => stringify(manifest, { lineWidth: 100, blockQuote: "literal", schema: "core" });
|
|
15
166
|
//# sourceMappingURL=manifest-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest-file.js","sourceRoot":"","sources":["../../../src/infrastructure/manifest-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"manifest-file.js","sourceRoot":"","sources":["../../../src/infrastructure/manifest-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAEL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,KAAK,EACL,WAAW,EAGX,aAAa,EACb,SAAS,GACV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAMhE,OAAO,EAAE,cAAc,EAAuB,MAAM,uBAAuB,CAAC;AAE5E,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAC3E,uEAAuE;AACvE,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,4CAA4C;AAE5C,4EAA4E;AAC5E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,mBAAmB;IACnB,kBAAkB;IAClB,mBAAmB;IACnB,yBAAyB;CACjB,CAAC;AA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M,CAAC;gBACN,MAAM;YACR,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,2CAA2C;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAiB,EAAU,EAAE,CAC9D,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { ConfigInvalid } from "../domain/architecture-error.js";
|
|
3
|
+
import { renderManifestPath, } from "../domain/manifest-location.js";
|
|
4
|
+
const INCLUDABLE = [".yaml", ".yml", ".json"];
|
|
5
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
const isInclude = (value) => isRecord(value) && "include" in value;
|
|
7
|
+
const isPrefix = (prefix, whole) => prefix.length <= whole.length && prefix.every((segment, index) => whole[index] === segment);
|
|
8
|
+
const makeLocator = (mounts) => {
|
|
9
|
+
if (!mounts.some((mount) => mount.locate !== undefined))
|
|
10
|
+
return undefined;
|
|
11
|
+
return (manifestPath) => {
|
|
12
|
+
const innermost = mounts
|
|
13
|
+
.filter((mount) => isPrefix(mount.at, manifestPath))
|
|
14
|
+
.sort((a, b) => a.at.length - b.at.length)
|
|
15
|
+
.at(-1);
|
|
16
|
+
if (innermost === undefined)
|
|
17
|
+
return null;
|
|
18
|
+
const found = innermost.locate?.([...innermost.origin, ...manifestPath.slice(innermost.at.length)]) ?? null;
|
|
19
|
+
if (found === null)
|
|
20
|
+
return null;
|
|
21
|
+
return innermost.label === undefined ? found : { ...found, file: innermost.label };
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const expandIncludes = (rootPath, root, reader) => {
|
|
25
|
+
const rootDirectory = path.dirname(rootPath);
|
|
26
|
+
const labelOf = (file) => path.relative(rootDirectory, file).split(path.sep).join("/");
|
|
27
|
+
const nameOf = (source) => source.label ?? path.basename(rootPath);
|
|
28
|
+
const files = [rootPath];
|
|
29
|
+
const mounts = [{ at: [], origin: [], label: undefined, locate: root.locate }];
|
|
30
|
+
// Fragments hoisted out of included files, and the file each name came from.
|
|
31
|
+
const hoisted = {};
|
|
32
|
+
const definedIn = new Map();
|
|
33
|
+
const refuse = (source, origin, detail) => {
|
|
34
|
+
const position = source.locate?.(origin) ?? null;
|
|
35
|
+
const at = position === null
|
|
36
|
+
? ""
|
|
37
|
+
: `${nameOf(source)}:${String(position.line)}:${String(position.column)} `;
|
|
38
|
+
throw new ConfigInvalid({
|
|
39
|
+
configPath: rootPath,
|
|
40
|
+
detail: `the manifest does not include:\n ${at}${renderManifestPath(origin)}: ${detail}`,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
// Checks a reference and reads the file it names. Nothing is placed yet:
|
|
44
|
+
// where the value lands depends on whether it is a list spliced into a list.
|
|
45
|
+
const open = (reference, origin, source) => {
|
|
46
|
+
const { include: specifier, ...rest } = reference;
|
|
47
|
+
if (typeof specifier !== "string") {
|
|
48
|
+
return refuse(source, origin, "`include` names a file, as a string.");
|
|
49
|
+
}
|
|
50
|
+
const shown = `\`include: ${JSON.stringify(specifier)}\``;
|
|
51
|
+
const beside = Object.keys(rest);
|
|
52
|
+
if (beside.length > 0) {
|
|
53
|
+
return refuse(source, origin, `${shown} stands alone: an included file is replaced whole, so there is nothing for ` +
|
|
54
|
+
`${beside.map((key) => `\`${key}\``).join(", ")} to override. ` +
|
|
55
|
+
`To override a fragment, put it under \`defs\` and \`use\` it.`);
|
|
56
|
+
}
|
|
57
|
+
const target = path.resolve(path.dirname(source.file), specifier);
|
|
58
|
+
if (!INCLUDABLE.includes(path.extname(target).toLowerCase())) {
|
|
59
|
+
return refuse(source, origin, `${shown} names a file that is not YAML or JSON. Only a data file can be included: ` +
|
|
60
|
+
`a module would make the manifest readable by one runtime only.`);
|
|
61
|
+
}
|
|
62
|
+
if (source.stack.includes(target)) {
|
|
63
|
+
return refuse(source, origin, `${shown} includes a file that is already being included: ` +
|
|
64
|
+
`${[...source.stack, target].map(labelOf).join(" → ")}.`);
|
|
65
|
+
}
|
|
66
|
+
if (!reader.exists(target)) {
|
|
67
|
+
return refuse(source, origin, `${shown} names a file that does not exist (looked for ${labelOf(target)}, ` +
|
|
68
|
+
`relative to ${nameOf(source)}).`);
|
|
69
|
+
}
|
|
70
|
+
const document = reader.read(target);
|
|
71
|
+
files.push(target);
|
|
72
|
+
return {
|
|
73
|
+
document,
|
|
74
|
+
source: {
|
|
75
|
+
file: target,
|
|
76
|
+
label: labelOf(target),
|
|
77
|
+
locate: document.locate,
|
|
78
|
+
stack: [...source.stack, target],
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
// Places an opened file at `at`, whole, and walks it so no reference is
|
|
83
|
+
// left inside. A top-level `defs` in the file joins the root's, and its
|
|
84
|
+
// `$schema` is for the editor — unless the file was included somewhere
|
|
85
|
+
// under `defs`, where it is a fragment or the map itself, and a key by
|
|
86
|
+
// either name is the author's.
|
|
87
|
+
const place = (opened, at) => {
|
|
88
|
+
const { document, source } = opened;
|
|
89
|
+
mounts.push({ at, origin: [], label: source.label, locate: source.locate });
|
|
90
|
+
if (!isRecord(document.value) || at[0] === "defs") {
|
|
91
|
+
return walk(document.value, at, [], source);
|
|
92
|
+
}
|
|
93
|
+
const { $schema: _schema, defs, ...body } = document.value;
|
|
94
|
+
if (defs !== undefined) {
|
|
95
|
+
if (!isRecord(defs)) {
|
|
96
|
+
return refuse(source, ["defs"], "`defs` must be a map of named fragments.");
|
|
97
|
+
}
|
|
98
|
+
for (const [name, fragment] of Object.entries(defs)) {
|
|
99
|
+
const already = definedIn.get(name);
|
|
100
|
+
if (already !== undefined) {
|
|
101
|
+
return refuse(source, ["defs", name], `\`defs.${name}\` is already defined in ${already}. Every file's \`defs\` share ` +
|
|
102
|
+
`one namespace; rename one of them.`);
|
|
103
|
+
}
|
|
104
|
+
definedIn.set(name, nameOf(source));
|
|
105
|
+
mounts.push({
|
|
106
|
+
at: ["defs", name],
|
|
107
|
+
origin: ["defs", name],
|
|
108
|
+
label: source.label,
|
|
109
|
+
locate: source.locate,
|
|
110
|
+
});
|
|
111
|
+
hoisted[name] = walk(fragment, ["defs", name], ["defs", name], source);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return walk(body, at, [], source);
|
|
115
|
+
};
|
|
116
|
+
// Appends each item of `list` to `items`. An include standing as an item
|
|
117
|
+
// whose file holds a list is spliced in, so a list can be split across
|
|
118
|
+
// files; an item that does not sit at the index it was written at is
|
|
119
|
+
// mounted on its own.
|
|
120
|
+
const append = (items, list, at, origin, source, spliced) => {
|
|
121
|
+
for (const [index, item] of list.entries()) {
|
|
122
|
+
const itemOrigin = [...origin, index];
|
|
123
|
+
const slot = [...at, items.length];
|
|
124
|
+
if (isInclude(item)) {
|
|
125
|
+
const opened = open(item, itemOrigin, source);
|
|
126
|
+
if (Array.isArray(opened.document.value)) {
|
|
127
|
+
append(items, opened.document.value, at, [], opened.source, true);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
items.push(place(opened, slot));
|
|
131
|
+
}
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (spliced || items.length !== index) {
|
|
135
|
+
mounts.push({ at: slot, origin: itemOrigin, label: source.label, locate: source.locate });
|
|
136
|
+
}
|
|
137
|
+
items.push(walk(item, slot, itemOrigin, source));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const walk = (value, at, origin, source) => {
|
|
141
|
+
if (isInclude(value))
|
|
142
|
+
return place(open(value, origin, source), at);
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
const items = [];
|
|
145
|
+
append(items, value, at, origin, source, false);
|
|
146
|
+
return items;
|
|
147
|
+
}
|
|
148
|
+
if (isRecord(value)) {
|
|
149
|
+
const entries = {};
|
|
150
|
+
for (const [key, item] of Object.entries(value)) {
|
|
151
|
+
entries[key] = walk(item, [...at, key], [...origin, key], source);
|
|
152
|
+
}
|
|
153
|
+
return entries;
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
};
|
|
157
|
+
const rootSource = {
|
|
158
|
+
file: rootPath,
|
|
159
|
+
label: undefined,
|
|
160
|
+
locate: root.locate,
|
|
161
|
+
stack: [rootPath],
|
|
162
|
+
};
|
|
163
|
+
const value = walk(root.value, [], [], rootSource);
|
|
164
|
+
// Nothing was included: the value and the locator are the reader's own.
|
|
165
|
+
if (files.length === 1)
|
|
166
|
+
return { value, locate: root.locate, files };
|
|
167
|
+
const names = Object.keys(hoisted);
|
|
168
|
+
if (names.length === 0 || !isRecord(value)) {
|
|
169
|
+
return { value, locate: makeLocator(mounts), files };
|
|
170
|
+
}
|
|
171
|
+
const own = value.defs;
|
|
172
|
+
if (own !== undefined && !isRecord(own)) {
|
|
173
|
+
return refuse(rootSource, ["defs"], "`defs` must be a map of named fragments.");
|
|
174
|
+
}
|
|
175
|
+
for (const name of names) {
|
|
176
|
+
if (own !== undefined && name in own) {
|
|
177
|
+
return refuse(rootSource, ["defs", name], `\`defs.${name}\` is also defined in ${definedIn.get(name) ?? "an included file"}. ` +
|
|
178
|
+
`Every file's \`defs\` share one namespace; rename one of them.`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
value: { ...value, defs: { ...(own ?? {}), ...hoisted } },
|
|
183
|
+
locate: makeLocator(mounts),
|
|
184
|
+
files,
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=manifest-include.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-include.js","sourceRoot":"","sources":["../../../src/infrastructure/manifest-include.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,O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CAAC;QACzB,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;YACrC,OAAO,MAAM,CACX,UAAU,EACV,CAAC,MAAM,EAAE,IAAI,CAAC,EACd,UAAU,IAAI,yBAAyB,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,kBAAkB,IAAI;gBAClF,gEAAgE,CACnE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO;QACL,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE;QACzD,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;QAC3B,KAAK;KACN,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Keyed by file: a test states which diagnostics another tool reported on
|
|
2
|
+
// which file, and never runs the tool. Every spec is answered alike.
|
|
3
|
+
export const makeReportSourceFake = (staged) => ({
|
|
4
|
+
diagnosticsOf: (_spec, file) => (staged[file] ?? []).map((one) => ({ ...one, file })),
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=report-source-fake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-source-fake.js","sourceRoot":"","sources":["../../../src/infrastructure/report-source-fake.ts"],"names":[],"mappings":"AAGA,0EAA0E;AAC1E,qEAAqE;AACrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAyE,EAC3D,EAAE,CAAC,CAAC;IAClB,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;CACtF,CAAC,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { availableParallelism } from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { ReportUnavailable } from "../domain/architecture-error.js";
|
|
6
|
+
import { indexByFile, parseReport, uniqueDiagnostics } from "../domain/report.js";
|
|
7
|
+
import { reportSourcesOf } from "../ports/report-source.js";
|
|
8
|
+
// The report source on this host: runs a `report` term's commands from the
|
|
9
|
+
// repository root, or reads the files it names, and parses the output once
|
|
10
|
+
// — a report is about the whole repository, a campaign asks per file, and
|
|
11
|
+
// the plugin asks for one file at a time across a whole lint run. Cached
|
|
12
|
+
// per spec for the life of the process: the CLI is one process per `check`,
|
|
13
|
+
// and oxlint's language server is one process per editor session, which
|
|
14
|
+
// sees the report as of when it loaded the plugin. A report the build
|
|
15
|
+
// writes to a file is the predictable form for the editor, and for CI.
|
|
16
|
+
//
|
|
17
|
+
// A term may name several commands — a tool that checks one project at a
|
|
18
|
+
// time, run once per project — and their outputs are one report: parsed
|
|
19
|
+
// each, joined, and a diagnostic two of them print kept once. `read` runs
|
|
20
|
+
// them concurrently, as many at a time as the machine has cores, which is
|
|
21
|
+
// why both hosts call it before any file asks; `diagnosticsOf` with no
|
|
22
|
+
// answer kept runs them one after another, synchronously, and keeps that.
|
|
23
|
+
//
|
|
24
|
+
// A non-zero exit is not a failure — `tsc` exits 2 when there are errors,
|
|
25
|
+
// which is the case the term exists for. A command that cannot be spawned,
|
|
26
|
+
// or a file that is not there, is — and that failure is cached as the report
|
|
27
|
+
// would have been, so the second file to ask gets the same answer without a
|
|
28
|
+
// second spawn. The command is forked from the asking process; under the
|
|
29
|
+
// oxlint plugin that is the linter, which Linux refuses to fork once its AST
|
|
30
|
+
// buffers have merged into one mapping larger than RAM and swap — so the
|
|
31
|
+
// plugin asks at load, and retrying per file would only repeat the refusal.
|
|
32
|
+
const MAX_BUFFER = 256 * 1024 * 1024;
|
|
33
|
+
const fileTextOf = (repoRoot, file) => {
|
|
34
|
+
const at = path.resolve(repoRoot, file);
|
|
35
|
+
try {
|
|
36
|
+
return readFileSync(at, "utf8");
|
|
37
|
+
}
|
|
38
|
+
catch (cause) {
|
|
39
|
+
throw new ReportUnavailable({ kind: "file", source: file, detail: String(cause) });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const commandTextSync = (repoRoot, command) => {
|
|
43
|
+
const run = spawnSync(command, {
|
|
44
|
+
cwd: repoRoot,
|
|
45
|
+
shell: true,
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
maxBuffer: MAX_BUFFER,
|
|
48
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
49
|
+
});
|
|
50
|
+
if (run.error !== undefined) {
|
|
51
|
+
throw new ReportUnavailable({ kind: "command", source: command, detail: run.error.message });
|
|
52
|
+
}
|
|
53
|
+
return run.stdout;
|
|
54
|
+
};
|
|
55
|
+
const commandText = (repoRoot, command) => new Promise((resolve, reject) => {
|
|
56
|
+
const child = spawn(command, {
|
|
57
|
+
cwd: repoRoot,
|
|
58
|
+
shell: true,
|
|
59
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
60
|
+
});
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let size = 0;
|
|
63
|
+
child.stdout.on("data", (chunk) => {
|
|
64
|
+
size += chunk.length;
|
|
65
|
+
if (size > MAX_BUFFER) {
|
|
66
|
+
child.kill();
|
|
67
|
+
reject(new ReportUnavailable({
|
|
68
|
+
kind: "command",
|
|
69
|
+
source: command,
|
|
70
|
+
detail: `stdout exceeded ${String(MAX_BUFFER)} bytes`,
|
|
71
|
+
}));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
chunks.push(chunk);
|
|
75
|
+
});
|
|
76
|
+
child.stderr.resume();
|
|
77
|
+
child.on("error", (cause) => {
|
|
78
|
+
reject(new ReportUnavailable({ kind: "command", source: command, detail: cause.message }));
|
|
79
|
+
});
|
|
80
|
+
child.on("close", () => {
|
|
81
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
// `work` over `items`, at most `lanes` at a time, answers in order.
|
|
85
|
+
const inLanes = async (items, lanes, work) => {
|
|
86
|
+
const answers = new Array(items.length);
|
|
87
|
+
let next = 0;
|
|
88
|
+
const lane = async () => {
|
|
89
|
+
while (next < items.length) {
|
|
90
|
+
const index = next;
|
|
91
|
+
next += 1;
|
|
92
|
+
answers[index] = await work(items[index]);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
await Promise.all(Array.from({ length: Math.min(lanes, items.length) }, lane));
|
|
96
|
+
return answers;
|
|
97
|
+
};
|
|
98
|
+
// One command named as a string and the same one as a list of one are the
|
|
99
|
+
// same report.
|
|
100
|
+
const keyOf = (spec) => JSON.stringify([
|
|
101
|
+
spec.file === undefined ? "command" : "file",
|
|
102
|
+
reportSourcesOf(spec),
|
|
103
|
+
spec.format,
|
|
104
|
+
spec.pattern ?? null,
|
|
105
|
+
]);
|
|
106
|
+
export const makeReportSourceLive = (repoRoot) => {
|
|
107
|
+
const cache = new Map();
|
|
108
|
+
const reading = new Map();
|
|
109
|
+
// The outputs, in the order named, as one report.
|
|
110
|
+
const indexOf = (spec, texts) => indexByFile(uniqueDiagnostics(texts.flatMap((text) => parseReport(spec.format, text, { repoRoot, pattern: spec.pattern }))));
|
|
111
|
+
const answerSync = (spec) => {
|
|
112
|
+
try {
|
|
113
|
+
const texts = reportSourcesOf(spec).map((source) => spec.file === undefined ? commandTextSync(repoRoot, source) : fileTextOf(repoRoot, source));
|
|
114
|
+
return indexOf(spec, texts);
|
|
115
|
+
}
|
|
116
|
+
catch (cause) {
|
|
117
|
+
if (cause instanceof ReportUnavailable)
|
|
118
|
+
return cause;
|
|
119
|
+
throw cause;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const answer = async (spec) => {
|
|
123
|
+
try {
|
|
124
|
+
const sources = reportSourcesOf(spec);
|
|
125
|
+
const texts = spec.file === undefined
|
|
126
|
+
? await inLanes(sources, availableParallelism(), (command) => commandText(repoRoot, command))
|
|
127
|
+
: sources.map((file) => fileTextOf(repoRoot, file));
|
|
128
|
+
return indexOf(spec, texts);
|
|
129
|
+
}
|
|
130
|
+
catch (cause) {
|
|
131
|
+
if (cause instanceof ReportUnavailable)
|
|
132
|
+
return cause;
|
|
133
|
+
throw cause;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const read = (spec) => {
|
|
137
|
+
const key = keyOf(spec);
|
|
138
|
+
if (cache.has(key))
|
|
139
|
+
return Promise.resolve();
|
|
140
|
+
const pending = reading.get(key);
|
|
141
|
+
if (pending !== undefined)
|
|
142
|
+
return pending;
|
|
143
|
+
const started = answer(spec).then((found) => {
|
|
144
|
+
cache.set(key, found);
|
|
145
|
+
reading.delete(key);
|
|
146
|
+
});
|
|
147
|
+
reading.set(key, started);
|
|
148
|
+
return started;
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
read,
|
|
152
|
+
diagnosticsOf: (spec, file) => {
|
|
153
|
+
const key = keyOf(spec);
|
|
154
|
+
let found = cache.get(key);
|
|
155
|
+
if (found === undefined) {
|
|
156
|
+
found = answerSync(spec);
|
|
157
|
+
cache.set(key, found);
|
|
158
|
+
}
|
|
159
|
+
if (found instanceof ReportUnavailable)
|
|
160
|
+
throw found;
|
|
161
|
+
return found.get(file) ?? [];
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=report-source-live.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-source-live.js","sourceRoot":"","sources":["../../../src/infrastructure/report-source-live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,C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O,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YACxB,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;gBACzB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,CAAC;YACD,IAAI,KAAK,YAAY,iBAAiB;gBAAE,MAAM,KAAK,CAAC;YACpD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const ZERO = { line: 0, column: 0 };
|
|
2
|
+
// Keyed by the source text, as the extractor fake is: a core test states
|
|
3
|
+
// what a snippet's syntax yields and never the parse, which has its own
|
|
4
|
+
// tests in the matcher package. A text not staged parses to no matches; a
|
|
5
|
+
// file whose extension is not among `extensions` does not parse at all,
|
|
6
|
+
// which is the shape of a language with no matcher.
|
|
7
|
+
export const makeSyntaxMatcherFake = (staged, extensions = null) => ({
|
|
8
|
+
parse: (file, text) => {
|
|
9
|
+
if (extensions !== null && !extensions.some((extension) => file.endsWith(extension))) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const matches = staged[text] ?? [];
|
|
13
|
+
return {
|
|
14
|
+
// A staged match's line is what a position is anchored by.
|
|
15
|
+
anchorAt: (position) => matches.find((one) => one.line === position.line)?.anchor ?? null,
|
|
16
|
+
findAll: (rule) => {
|
|
17
|
+
const asked = JSON.stringify(rule);
|
|
18
|
+
return matches
|
|
19
|
+
.filter((one) => one.rule === undefined || JSON.stringify(one.rule) === asked)
|
|
20
|
+
.map((one) => ({
|
|
21
|
+
text: one.text,
|
|
22
|
+
captures: new Map(Object.entries(one.captures ?? {})),
|
|
23
|
+
range: {
|
|
24
|
+
start: one.line === undefined ? ZERO : { line: one.line, column: 0 },
|
|
25
|
+
end: one.line === undefined ? ZERO : { line: one.line, column: one.text.length },
|
|
26
|
+
},
|
|
27
|
+
anchor: one.anchor ?? null,
|
|
28
|
+
}));
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=syntax-matcher-fake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-matcher-fake.js","sourceRoot":"","sources":["../../../src/infrastructure/syntax-matcher-fake.ts"],"names":[],"mappings":"AAeA,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AAEpC,yEAAyE;AACzE,wEAAwE;AACxE,0EAA0E;AAC1E,wEAAwE;AACxE,oDAAoD;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAA4D,EAC5D,UAAU,GAAiC,IAAI,EAChC,EAAE,CAAC,CAAC;IACnB,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QACpB,IAAI,UAAU,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACrF,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO;YACL,2DAA2D;YAC3D,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KA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