@r_masseater/msch 0.10.0 → 0.12.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/dist/cli.mjs +1028 -824
- package/dist/cli.mjs.map +1 -1
- package/dist/{comment-directives-DApQXgQf.mjs → comment-directives-TN0dNEbg.mjs} +2 -2
- package/dist/comment-directives-TN0dNEbg.mjs.map +1 -0
- package/dist/decision-rules.mjs +1 -1
- package/dist/decision-rules.mjs.map +1 -1
- package/dist/inline-exports.d.mts +8 -0
- package/dist/inline-exports.mjs +370 -0
- package/dist/inline-exports.mjs.map +1 -0
- package/dist/lint.d.mts +22 -14
- package/dist/lint.mjs +30 -9
- package/dist/lint.mjs.map +1 -1
- package/dist/oxlint.mjs +3 -3
- package/dist/oxlint.mjs.map +1 -1
- package/dist/{cli-contract-ChzTJ0Na.mjs → problem-BeBSq75T.mjs} +11 -7
- package/dist/problem-BeBSq75T.mjs.map +1 -0
- package/dist/repository-files-CfhXZQrO.mjs +55 -0
- package/dist/repository-files-CfhXZQrO.mjs.map +1 -0
- package/dist/{workspace-tasks-CRL-gm__.mjs → workspace-jN1GGTGn.mjs} +196 -39
- package/dist/workspace-jN1GGTGn.mjs.map +1 -0
- package/dist/workspace-settings.d.mts +2 -2
- package/dist/workspace-settings.mjs +5 -17
- package/dist/workspace-settings.mjs.map +1 -1
- package/package.json +10 -3
- package/src/{vite.d.ts → app/vite.d.ts} +7 -17
- package/dist/cli-contract-ChzTJ0Na.mjs.map +0 -1
- package/dist/comment-directives-DApQXgQf.mjs.map +0 -1
- package/dist/dependencies-x3j9tLcR.mjs +0 -186
- package/dist/dependencies-x3j9tLcR.mjs.map +0 -1
- package/dist/workspace-tasks-CRL-gm__.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as COMMENT_DIRECTIVES } from "./comment-directives-
|
|
2
|
+
import { $ as isTypeLiteralNode, A as isArrayLiteralExpression, B as isModuleBlock, C as IndexKind, D as getLeadingCommentRanges, E as getJSDocTags, F as isEnumDeclaration, G as isPropertyAccessExpression, H as isNewExpression, I as isExportDeclaration, J as isSignatureDeclaration, K as isPropertyAssignment, L as isIdentifier, M as isCallExpression, N as isClassDeclaration, O as getNameOfDeclaration, P as isElementAccessExpression, Q as isTypeAliasDeclaration, R as isImportDeclaration, S as API, T as SyntaxKind, U as isNumericLiteral, V as isModuleDeclaration, W as isObjectLiteralExpression, X as isSpreadElement, Y as isSourceFile, Z as isStringLiteral, _ as propertyNamesOf, a as sortProblems, b as symbolAt, c as columnOf, d as descendantsOf, et as isTypeReferenceNode, f as importedModulesOf, g as lineOf, h as isTypeDeclaration, i as problemAt, it as isVariableStatement, j as isBinaryExpression, k as getTextOfJSDocComment, l as contains, m as isGenericDeclaration, nt as isVariableDeclaration, o as NODE_MODULES_SEGMENT, p as isExternalDeclaration, q as isSatisfiesExpression, r as formatProblem, rt as isVariableDeclarationList, s as childrenOf$2, t as ProblemList, tt as isUnionTypeNode, u as declarationsOf, v as referencedSymbols, w as InternalSymbolName, x as uniqueByReference, y as resolvedSymbol, z as isInterfaceDeclaration } from "./problem-BeBSq75T.mjs";
|
|
3
|
+
import { i as nodeServicesLayer, n as RepositoryFiles, r as nodeRepositoryFiles, t as NODE_MODULES } from "./repository-files-CfhXZQrO.mjs";
|
|
4
|
+
import { C as publicEntriesOf, D as workspaceDependencies, E as readManifest, S as publishedWorkspaces, T as dependencyEntries, _ as keyName, c as workspaceDirectories, g as childrenOf$3, h as KeySchema, i as hasVerifyTask, m as workspaceConfigOf, n as VERIFY_TASK, r as definesTask, v as literalOf, w as MANIFEST_FILE, y as nestedValues } from "./workspace-jN1GGTGn.mjs";
|
|
5
|
+
import { t as COMMENT_DIRECTIVES } from "./comment-directives-TN0dNEbg.mjs";
|
|
6
6
|
import { Array, Cause, Effect, FileSystem, Function, HashMap, HashSet, Layer, Number as Number$1, Option, Order, Path, Predicate, Record, Result, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
|
|
7
7
|
import { ChildProcess } from "effect/process";
|
|
8
8
|
import { parse, resolveConfigFromFile } from "vite-plus";
|
|
9
|
-
import { LineCounter, Parser, isMap, isScalar, parseAllDocuments, parseDocument } from "yaml";
|
|
9
|
+
import { LineCounter, Parser, isMap, isScalar, parse as parse$1, parseAllDocuments, parseDocument } from "yaml";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import treeSitter from "@vscode/tree-sitter-wasm";
|
|
@@ -18,39 +18,7 @@ import { parseTOML } from "toml-eslint-parser";
|
|
|
18
18
|
import { runMain } from "@effect/platform-node-shared/NodeRuntime";
|
|
19
19
|
import { FetchHttpClient } from "effect/http";
|
|
20
20
|
import { Otlp, OtlpSerialization } from "effect/observability";
|
|
21
|
-
// src/
|
|
22
|
-
const ANNOTATED_KINDS = /* @__PURE__ */ new Set([
|
|
23
|
-
SyntaxKind.Parameter,
|
|
24
|
-
SyntaxKind.VariableDeclaration,
|
|
25
|
-
SyntaxKind.PropertySignature,
|
|
26
|
-
SyntaxKind.PropertyDeclaration
|
|
27
|
-
]);
|
|
28
|
-
const isAnnotated = (declaration) => ANNOTATED_KINDS.has(declaration.kind);
|
|
29
|
-
const annotationOf = (declaration) => Option.liftPredicate(declaration, isAnnotated).pipe(Option.flatMap((annotated) => Option.fromUndefinedOr(annotated.type)));
|
|
30
|
-
const argumentSlot = (checker) => (expression) => {
|
|
31
|
-
const call = expression.parent;
|
|
32
|
-
if (!isCallExpression(call) && !isNewExpression(call)) return Option.none();
|
|
33
|
-
const { arguments: listed } = call;
|
|
34
|
-
const index = (listed ?? []).indexOf(expression);
|
|
35
|
-
return Option.fromUndefinedOr(checker.getResolvedSignature(call).declaration).pipe(Option.flatMap((handle) => Option.fromUndefinedOr(handle.resolve())), Option.filter(isSignatureDeclaration), Option.flatMap((declaration) => Array.get(declaration.parameters, index)));
|
|
36
|
-
};
|
|
37
|
-
const propertySlot = (checker) => (expression) => {
|
|
38
|
-
const assignment = expression.parent;
|
|
39
|
-
if (!isPropertyAssignment(assignment) || !isObjectLiteralExpression(assignment.parent)) return Option.none();
|
|
40
|
-
return Option.fromUndefinedOr(checker.getContextualType(assignment.parent)).pipe(Option.flatMap((objectType) => Option.fromUndefinedOr(objectType.getProperty(assignment.name.getText()))), Option.flatMap((property) => Array.head(declarationsOf(property))));
|
|
41
|
-
};
|
|
42
|
-
const variableSlot = (expression) => {
|
|
43
|
-
const declaration = expression.parent;
|
|
44
|
-
if (!isVariableDeclaration(declaration) || declaration.initializer !== expression) return Option.none();
|
|
45
|
-
return Option.some(declaration);
|
|
46
|
-
};
|
|
47
|
-
const slotOf = (checker) => (expression) => argumentSlot(checker)(expression).pipe(Option.orElse(() => propertySlot(checker)(expression)), Option.orElse(() => variableSlot(expression)));
|
|
48
|
-
const contextSymbolsOf = (checker) => (expression) => {
|
|
49
|
-
const alias = Option.fromUndefinedOr(checker.getContextualType(expression)).pipe(Option.flatMap((contextual) => Option.fromUndefinedOr(contextual.getAliasSymbol())));
|
|
50
|
-
if (Option.isSome(alias)) return [alias.value];
|
|
51
|
-
return slotOf(checker)(expression).pipe(Option.flatMap(annotationOf), Option.map((annotation) => referencedSymbols(checker)(annotation)), Option.getOrElse(() => []));
|
|
52
|
-
};
|
|
53
|
-
// src/values.ts
|
|
21
|
+
// src/shared/lib/values.ts
|
|
54
22
|
const SCHEMA_TYPE_PROPERTIES = ["Type", "_output"];
|
|
55
23
|
const MINIMUM_SET_SIZE = 2;
|
|
56
24
|
const DATA_FIRST_ARITY = 2;
|
|
@@ -95,123 +63,7 @@ const valueText = (value) => {
|
|
|
95
63
|
return String(value);
|
|
96
64
|
};
|
|
97
65
|
const formatValues = (values) => pipe(values, Array.map(valueText), Array.join(" | "));
|
|
98
|
-
// src/
|
|
99
|
-
const SCOPE_PREFIX$1 = "@";
|
|
100
|
-
const SCOPED_SEGMENTS$1 = 2;
|
|
101
|
-
const UNSCOPED_SEGMENTS = 1;
|
|
102
|
-
const MODULE_PREFIX = /^".*?"\./u;
|
|
103
|
-
const packageOf$1 = (fileName) => {
|
|
104
|
-
const afterModules = pipe(fileName, String$1.lastIndexOf(NODE_MODULES_SEGMENT), Option.match({
|
|
105
|
-
onNone: () => fileName,
|
|
106
|
-
onSome: (index) => String$1.slice(index + NODE_MODULES_SEGMENT.length)(fileName)
|
|
107
|
-
}));
|
|
108
|
-
const segments = String$1.split("/")(afterModules);
|
|
109
|
-
if (String$1.startsWith(SCOPE_PREFIX$1)(afterModules)) return pipe(Array.take(segments, SCOPED_SEGMENTS$1), Array.join("/"));
|
|
110
|
-
return pipe(Array.take(segments, UNSCOPED_SEGMENTS), Array.join("/"));
|
|
111
|
-
};
|
|
112
|
-
const externalDeclarationOf = (context) => (symbol) => Array.findFirst(declarationsOf(symbol), (declaration) => isExternalDeclaration(context.program)(declaration));
|
|
113
|
-
const aliasTarget = (context) => (type) => Option.fromUndefinedOr(type.getAliasSymbol()).pipe(Option.flatMap((alias) => externalDeclarationOf(context)(alias).pipe(Option.map((declaration) => `${String$1.replace(MODULE_PREFIX, "")(context.checker.getFullyQualifiedName(alias))} from ${packageOf$1(declaration.getSourceFile().fileName)}`))));
|
|
114
|
-
const isNamedContainer = (node) => isSignatureDeclaration(node) || isInterfaceDeclaration(node) || isClassDeclaration(node);
|
|
115
|
-
const slotTarget = (context) => (expression) => slotOf(context.checker)(expression).pipe(Option.filter((slot) => isExternalDeclaration(context.program)(slot)), Option.filter((slot) => Option.isSome(vocabularyOf(context.checker)(context.checker.getTypeAtLocation(slot)))), Option.map((slot) => {
|
|
116
|
-
const owner = Option.liftPredicate(slot.parent, isNamedContainer).pipe(Option.flatMap((container) => Option.fromUndefinedOr(getNameOfDeclaration(container))), Option.map((name) => ` of ${name.getText()}`), Option.getOrElse(() => ""));
|
|
117
|
-
return `${Option.fromUndefinedOr(getNameOfDeclaration(slot)).pipe(Option.map((found) => found.getText()), Option.getOrElse(() => "value"))}${owner} from ${packageOf$1(slot.getSourceFile().fileName)}`;
|
|
118
|
-
}));
|
|
119
|
-
const libraryTargetOf = (context) => (expression, contextual) => aliasTarget(context)(contextual).pipe(Option.orElse(() => slotTarget(context)(expression)));
|
|
120
|
-
const siteWithin = (context) => (node) => Array.findFirst(context.sites, (site) => contains(node)(site.node));
|
|
121
|
-
const aliasSite = (context) => (type) => Option.fromUndefinedOr(type.getAliasSymbol()).pipe(Option.flatMap((alias) => Array.findFirst(declarationsOf(alias), isTypeAliasDeclaration)), Option.flatMap(siteWithin(context)));
|
|
122
|
-
const annotationSite = (context) => (expression) => symbolAt(context.checker)(expression).pipe(Option.flatMap((symbol) => Option.fromUndefinedOr(symbol.valueDeclaration)), Option.flatMap((handle) => Option.fromUndefinedOr(handle.resolve())), Option.flatMap(annotationOf), Option.flatMap((annotation) => siteWithin(context)(annotation).pipe(Option.orElse(() => aliasSite(context)(context.checker.getTypeFromTypeNode(annotation))))));
|
|
123
|
-
const siteBehind = (context) => (expression) => aliasSite(context)(context.checker.getTypeAtLocation(expression)).pipe(Option.orElse(() => annotationSite(context)(expression)));
|
|
124
|
-
const isFlowSource = (node) => isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node);
|
|
125
|
-
const flowOf = (context) => (expression) => Option.fromUndefinedOr(context.checker.getContextualType(expression)).pipe(Option.flatMap((contextual) => Option.all([vocabularyOf(context.checker)(contextual), libraryTargetOf(context)(expression, contextual)])), Option.flatMap(([vocabulary, target]) => siteBehind(context)(expression).pipe(Option.filter((site) => isSubsetOf(site.values, vocabulary.values)), Option.map((site) => ({
|
|
126
|
-
site,
|
|
127
|
-
target
|
|
128
|
-
})))));
|
|
129
|
-
const flowsIn = (context) => (sourceFile) => Array.getSomes(pipe(descendantsOf(sourceFile), Array.filter((node) => isFlowSource(node)), Array.map((node) => flowOf(context)(node))));
|
|
130
|
-
// src/owners.ts
|
|
131
|
-
const OWNER_TAG = "msch";
|
|
132
|
-
const FIRST_OWNER_COUNT = 1;
|
|
133
|
-
const ownerKeyOf = (declaration) => {
|
|
134
|
-
if (!isVariableDeclaration(declaration) || !isIdentifier(declaration.name)) return Option.none();
|
|
135
|
-
return Option.some(`${declaration.getSourceFile().fileName}#${declaration.name.text}`);
|
|
136
|
-
};
|
|
137
|
-
const annotationsOf = (node) => pipe(getJSDocTags(node), Array.filter((tag) => tag.tagName.text === OWNER_TAG), Array.map((tag) => ({
|
|
138
|
-
node,
|
|
139
|
-
conceptId: String$1.trim(getTextOfJSDocComment(tag.comment) ?? "")
|
|
140
|
-
})));
|
|
141
|
-
const ANNOTATABLE_KINDS = /* @__PURE__ */ new Set([
|
|
142
|
-
SyntaxKind.VariableDeclaration,
|
|
143
|
-
SyntaxKind.FunctionDeclaration,
|
|
144
|
-
SyntaxKind.ClassDeclaration,
|
|
145
|
-
SyntaxKind.InterfaceDeclaration,
|
|
146
|
-
SyntaxKind.TypeAliasDeclaration,
|
|
147
|
-
SyntaxKind.EnumDeclaration,
|
|
148
|
-
SyntaxKind.PropertySignature,
|
|
149
|
-
SyntaxKind.PropertyAssignment,
|
|
150
|
-
SyntaxKind.PropertyDeclaration
|
|
151
|
-
]);
|
|
152
|
-
const isAnnotatable = (node) => ANNOTATABLE_KINDS.has(node.kind);
|
|
153
|
-
const isConstList = (list) => Option.fromUndefinedOr(list.getFirstToken()).pipe(Option.exists((token) => token.kind === SyntaxKind.ConstKeyword));
|
|
154
|
-
const isModuleStatementList = (list) => isVariableStatement(list.parent) && isSourceFile(list.parent.parent);
|
|
155
|
-
const isModuleConstList = (node) => isVariableDeclarationList(node) && isModuleStatementList(node) && isConstList(node);
|
|
156
|
-
const isModuleConst = (node) => isVariableDeclaration(node) && isIdentifier(node.name) && isModuleConstList(node.parent);
|
|
157
|
-
const objectValuesOf = (checker) => (type) => literalValuesOf(pipe(checker.getPropertiesOfType(type), Array.map((property) => checker.getTypeOfSymbol(property))));
|
|
158
|
-
const ownerValuesOf = (checker) => (declaration) => {
|
|
159
|
-
const type = checker.getTypeAtLocation(declaration.name);
|
|
160
|
-
return finiteValuesOf(checker)(type).pipe(Option.orElse(() => objectValuesOf(checker)(type)));
|
|
161
|
-
};
|
|
162
|
-
const annotationProblem = (message) => problemAt({
|
|
163
|
-
rule: "owner-annotation",
|
|
164
|
-
message
|
|
165
|
-
});
|
|
166
|
-
const scanned = (owners, problems) => ({
|
|
167
|
-
owners,
|
|
168
|
-
problems
|
|
169
|
-
});
|
|
170
|
-
const ownerOf$1 = (project) => (annotated) => {
|
|
171
|
-
const { node, conceptId } = annotated;
|
|
172
|
-
if (!isModuleConst(node)) return scanned([], [annotationProblem(`@${OWNER_TAG} registers an owner only on a module-scope const.`)(node)]);
|
|
173
|
-
if (conceptId === "") return scanned([], [annotationProblem(`@${OWNER_TAG} needs a concept id.`)(node)]);
|
|
174
|
-
const values = ownerValuesOf(project.checker)(node);
|
|
175
|
-
return Option.match(Option.all([values, ownerKeyOf(node)]), {
|
|
176
|
-
onNone: () => scanned([], [annotationProblem(`The owner of ${conceptId} holds no finite value set.`)(node)]),
|
|
177
|
-
onSome: ([ownedValues, key]) => scanned([{
|
|
178
|
-
conceptId,
|
|
179
|
-
key,
|
|
180
|
-
name: node.name.getText(),
|
|
181
|
-
file: node.getSourceFile().fileName,
|
|
182
|
-
line: lineOf(node),
|
|
183
|
-
column: columnOf(node),
|
|
184
|
-
packageName: project.packageName,
|
|
185
|
-
values: ownedValues
|
|
186
|
-
}], [])
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
const annotatedIn = (sourceFile) => pipe(descendantsOf(sourceFile), Array.filter((node) => isAnnotatable(node)), Array.flatMap((node) => annotationsOf(node)));
|
|
190
|
-
const ownerProblem = (message) => (owner) => ({
|
|
191
|
-
file: owner.file,
|
|
192
|
-
line: owner.line,
|
|
193
|
-
column: owner.column,
|
|
194
|
-
rule: "owner-annotation",
|
|
195
|
-
message
|
|
196
|
-
});
|
|
197
|
-
const conflictProblems = (owners) => pipe(owners, Array.flatMap((owner, index) => {
|
|
198
|
-
const earlier = Array.take(owners, index);
|
|
199
|
-
const sameConcept = pipe(earlier, Array.filter((other) => other.conceptId === owner.conceptId));
|
|
200
|
-
const sameSet = pipe(earlier, Array.filter((other) => other.conceptId !== owner.conceptId && sameValues(other.values, owner.values)));
|
|
201
|
-
return [...pipe(Array.take(sameConcept, FIRST_OWNER_COUNT), Array.map(() => ownerProblem(`The concept ${owner.conceptId} already has an owner.`)(owner))), ...pipe(Array.take(sameSet, FIRST_OWNER_COUNT), Array.map((other) => ownerProblem(`The values ${formatValues(owner.values)} are already owned by ${other.conceptId}.`)(owner)))];
|
|
202
|
-
}));
|
|
203
|
-
const ownersIn = (project) => {
|
|
204
|
-
const results = pipe(project.sourceFiles, Array.flatMap((sourceFile) => pipe(annotatedIn(sourceFile), Array.map((annotated) => ownerOf$1(project)(annotated)))));
|
|
205
|
-
return scanned(pipe(results, Array.flatMap((result) => result.owners)), pipe(results, Array.flatMap((result) => result.problems)));
|
|
206
|
-
};
|
|
207
|
-
const combineOwnerScans = (scans) => {
|
|
208
|
-
const owners = Array.dedupeWith(pipe(scans, Array.flatMap((scan) => scan.owners)), (left, right) => left.key === right.key);
|
|
209
|
-
return {
|
|
210
|
-
owners,
|
|
211
|
-
problems: [...pipe(scans, Array.flatMap((scan) => scan.problems)), ...conflictProblems(owners)]
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
// src/library.ts
|
|
66
|
+
// src/entities/project/model/library.ts
|
|
215
67
|
const NAMESPACE_DEPTH_LIMIT = 8;
|
|
216
68
|
const EMPTY_INDEX = {
|
|
217
69
|
vocabularies: [],
|
|
@@ -333,343 +185,42 @@ const indexEntry = (cache) => (checker) => (entry) => Effect.sync(() => cache.in
|
|
|
333
185
|
"msch.library.shapes": index.shapes.length
|
|
334
186
|
})), Effect.map(({ index }) => index), Effect.withSpan("indexLibraryEntry", { attributes: { "msch.library.specifier": entry.specifier } }));
|
|
335
187
|
const libraryIndex = (cache) => (checker) => (entries) => pipe(entries, Effect.forEach(indexEntry(cache)(checker)), Effect.map(mergeIndexes), Effect.withSpan("libraryIndex"));
|
|
336
|
-
// src/
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
const scopes = Array.prepend(contractOf(node), node);
|
|
345
|
-
return new Set(pipe(scopes, Array.flatMap((scope) => referencedSymbols(checker)(scope)), Array.flatMap((symbol) => declarationsOf(symbol)), Array.map((declaration) => declarationKey(locationOf(declaration)))));
|
|
346
|
-
};
|
|
347
|
-
// src/shapes.ts
|
|
348
|
-
const MINIMUM_SHAPE_PROPERTIES = 3;
|
|
349
|
-
const EXACT = 0;
|
|
350
|
-
const augmentsAModule = (node) => {
|
|
351
|
-
const block = node.parent;
|
|
352
|
-
return isModuleBlock(block) && isModuleDeclaration(block.parent) && isStringLiteral(block.parent.name);
|
|
353
|
-
};
|
|
354
|
-
const isPlainInterface = (node) => isInterfaceDeclaration(node) && !isGenericDeclaration(node) && !augmentsAModule(node);
|
|
355
|
-
const isPlainTypeLiteral = (node) => isTypeAliasDeclaration(node) && !isGenericDeclaration(node) && isTypeLiteralNode(node.type);
|
|
356
|
-
const isDeclaredShape = (node) => isPlainInterface(node) || isPlainTypeLiteral(node);
|
|
357
|
-
const declaredShapeOf = (checker) => (node) => Option.liftPredicate(node, isDeclaredShape).pipe(Option.map((declaration) => checker.getTypeAtLocation(declaration.name)));
|
|
358
|
-
const schemaShapeOf = (checker) => (node) => {
|
|
359
|
-
if (!isCallExpression(node)) return Option.none();
|
|
360
|
-
const { arguments: callArguments } = node;
|
|
361
|
-
if (!pipe(callArguments, Array.some((argument) => isObjectLiteralExpression(argument)))) return Option.none();
|
|
362
|
-
return schemaTypeOf(checker)(checker.getTypeAtLocation(node)).pipe(Option.filter((type) => isObjectType(checker)(type)));
|
|
363
|
-
};
|
|
364
|
-
const shapeSitesIn = (checker) => (sourceFile) => Array.getSomes(pipe(descendantsOf(sourceFile), Array.map((node) => declaredShapeOf(checker)(node).pipe(Option.orElse(() => schemaShapeOf(checker)(node)), Option.map((type) => ({
|
|
365
|
-
node,
|
|
366
|
-
type
|
|
367
|
-
}))))));
|
|
368
|
-
const openTypeIdsOf = (checker) => ({
|
|
369
|
-
any: checker.getAnyType().id,
|
|
370
|
-
unknown: checker.getUnknownType().id
|
|
188
|
+
// src/entities/project/model/telemetry.ts
|
|
189
|
+
const RSS_LINE = /^VmRSS:\s+(?<kib>\d+) kB$/mu;
|
|
190
|
+
const BYTES_PER_KIB = 1024;
|
|
191
|
+
const UNKNOWN_RSS = 0;
|
|
192
|
+
const kibibytesIn = (status) => Option.fromNullishOr(RSS_LINE.exec(status)).pipe(Option.flatMap((match) => Option.fromUndefinedOr(match.groups)), Option.flatMap((groups) => Option.fromUndefinedOr(groups["kib"])));
|
|
193
|
+
const residentBytesOf = (pid) => Effect.gen(function* residentBytes() {
|
|
194
|
+
const status = yield* (yield* RepositoryFiles).readFile(`/proc/${pid}/status`);
|
|
195
|
+
return pipe(status, Option.flatMap(kibibytesIn), Option.flatMap(Number$1.parse), Option.map((kib) => kib * BYTES_PER_KIB), Option.getOrElse(() => UNKNOWN_RSS));
|
|
371
196
|
});
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const libraryType = checker.getTypeOfSymbol(library);
|
|
388
|
-
return libraryType.id !== open.any && libraryType.id !== open.unknown && checker.isTypeAssignableTo(localType, libraryType) && checker.isTypeAssignableTo(libraryType, localType);
|
|
389
|
-
};
|
|
390
|
-
const matchOf = (context, open) => (locals, shape) => {
|
|
391
|
-
const { checker } = context;
|
|
392
|
-
if (!shapeTypeOf(context)(shape).pipe(Option.exists((shapeType) => pipe(locals, Array.every((local) => Option.fromUndefinedOr(checker.getPropertyOfType(shapeType, local.name)).pipe(Option.exists((library) => sameProperty(checker, open)(local.type, library)))))))) return Option.none();
|
|
393
|
-
return Option.some({
|
|
394
|
-
shape,
|
|
395
|
-
extra: shape.propertyNames.length - locals.length
|
|
197
|
+
const childPids = Effect.gen(function* childPids() {
|
|
198
|
+
const files = yield* RepositoryFiles;
|
|
199
|
+
const pid = String(process.pid);
|
|
200
|
+
const children = yield* files.readFile(`/proc/${pid}/task/${pid}/children`);
|
|
201
|
+
return pipe(children, Option.map((text) => pipe(String$1.trim(text), String$1.split(" "), Array.filter(String$1.isNonEmpty))), Option.getOrElse(() => []));
|
|
202
|
+
});
|
|
203
|
+
const annotateMemory = Effect.gen(function* annotateMemory() {
|
|
204
|
+
const own = yield* residentBytesOf(String(process.pid));
|
|
205
|
+
const pids = yield* childPids;
|
|
206
|
+
const children = yield* pipe(pids, Effect.forEach((pid) => residentBytesOf(pid)));
|
|
207
|
+
const { heapUsed } = process.memoryUsage();
|
|
208
|
+
yield* Effect.annotateCurrentSpan({
|
|
209
|
+
"process.memory.rss": own,
|
|
210
|
+
"process.memory.heap_used": heapUsed,
|
|
211
|
+
"msch.compiler.memory.rss": Number$1.sumAll(children)
|
|
396
212
|
});
|
|
397
|
-
};
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const advice = Option.match(Array.findFirst(matches, (match) => match.extra === EXACT), {
|
|
406
|
-
onNone: () => "Derive it from the library type, for example with Pick, instead of copying its properties.",
|
|
407
|
-
onSome: () => "Use the library type instead of copying it."
|
|
408
|
-
});
|
|
409
|
-
return problemAt({
|
|
410
|
-
rule: "library-shape",
|
|
411
|
-
message: `This shape copies ${shown}. ${advice}`
|
|
412
|
-
})(site.node);
|
|
413
|
-
};
|
|
414
|
-
const candidatesOf = (context, open) => (site, locals) => {
|
|
415
|
-
const derived = derivedDeclarationsOf(context.checker)(site.node);
|
|
416
|
-
const named = pipe(context.shapes, Array.filter(hasEveryName(locals)));
|
|
417
|
-
if (pipe(named, Array.some((shape) => derived.has(declarationKey(shape.declaration))))) return [];
|
|
418
|
-
const candidates = pipe(named, Array.map((shape) => matchOf(context, open)(locals, shape)), Array.getSomes);
|
|
419
|
-
return Array.sort(candidates, matchOrder);
|
|
420
|
-
};
|
|
421
|
-
const shapeProblemOf = (context, open) => (site) => {
|
|
422
|
-
const symbols = context.checker.getPropertiesOfType(site.type);
|
|
423
|
-
if (symbols.length < MINIMUM_SHAPE_PROPERTIES) return Option.none();
|
|
424
|
-
const locals = localPropertiesOf(context.checker)(symbols);
|
|
425
|
-
return Option.liftPredicate(candidatesOf(context, open)(site, locals), Array.isReadonlyArrayNonEmpty).pipe(Option.map((found) => shapeProblem(site, found)));
|
|
426
|
-
};
|
|
427
|
-
const shapeProblemsIn = (context) => (sourceFile) => {
|
|
428
|
-
const sites = shapeSitesIn(context.checker)(sourceFile);
|
|
429
|
-
if (!Array.isReadonlyArrayNonEmpty(sites)) return [];
|
|
430
|
-
const open = openTypeIdsOf(context.checker);
|
|
431
|
-
return Array.getSomes(pipe(sites, Array.map((site) => shapeProblemOf(context, open)(site))));
|
|
432
|
-
};
|
|
433
|
-
// src/sites.ts
|
|
434
|
-
const namedValuesOf = (checker) => (symbol) => {
|
|
435
|
-
if (pipe(declarationsOf(symbol), Array.some((declaration) => isTypeDeclaration(declaration)))) return finiteValuesOf(checker)(checker.getDeclaredTypeOfSymbol(symbol));
|
|
436
|
-
return finiteValuesOf(checker)(checker.getTypeOfSymbol(symbol));
|
|
437
|
-
};
|
|
438
|
-
const hasFiniteContext = (checker) => (node) => Option.fromUndefinedOr(checker.getContextualType(node)).pipe(Option.flatMap(finiteValuesOf(checker)), Option.isSome);
|
|
439
|
-
const isNamedValue = (element) => {
|
|
440
|
-
if (isSpreadElement(element)) return isNamedValue(element.expression);
|
|
441
|
-
return isIdentifier(element) || isPropertyAccessExpression(element) || isElementAccessExpression(element);
|
|
442
|
-
};
|
|
443
|
-
const namesEveryElement = (array) => pipe(array.elements, Array.every((element) => isNamedValue(element)));
|
|
444
|
-
const expressionValuesOf = (checker) => (node) => {
|
|
445
|
-
if (hasFiniteContext(checker)(node)) return Option.none();
|
|
446
|
-
const type = checker.getTypeAtLocation(node);
|
|
447
|
-
if (isArrayLiteralExpression(node)) return Option.liftPredicate(node, (array) => !namesEveryElement(array)).pipe(Option.flatMap(() => finiteValuesOf(checker)(type)));
|
|
448
|
-
return schemaTypeOf(checker)(type).pipe(Option.flatMap(literalUnionOf));
|
|
449
|
-
};
|
|
450
|
-
const selectsKeys = (checker) => (node, values) => {
|
|
451
|
-
const { parent } = node;
|
|
452
|
-
if (!isTypeReferenceNode(parent)) return false;
|
|
453
|
-
const typeArguments = parent.typeArguments ?? [];
|
|
454
|
-
return pipe(typeArguments, Array.filter((argument) => argument !== node), Array.some((argument) => isSubsetOf(values, propertyNamesOf(checker)(checker.getTypeFromTypeNode(argument)))));
|
|
455
|
-
};
|
|
456
|
-
const unionValuesOf = (checker) => (node) => literalUnionOf(checker.getTypeFromTypeNode(node)).pipe(Option.filter((values) => !selectsKeys(checker)(node, values)));
|
|
457
|
-
const isExpressionSite = (node) => isArrayLiteralExpression(node) || isCallExpression(node);
|
|
458
|
-
const expressionSiteValuesOf = (checker) => (node) => Option.liftPredicate(node, isExpressionSite).pipe(Option.flatMap(expressionValuesOf(checker)));
|
|
459
|
-
const siteValuesOf = (checker) => (node) => {
|
|
460
|
-
if (isUnionTypeNode(node)) return unionValuesOf(checker)(node);
|
|
461
|
-
if (isEnumDeclaration(node)) return literalUnionOf(checker.getTypeAtLocation(node.name));
|
|
462
|
-
return expressionSiteValuesOf(checker)(node);
|
|
463
|
-
};
|
|
464
|
-
const derivationScopeOf = (node) => {
|
|
465
|
-
if (isTypeReferenceNode(node.parent)) return node.parent;
|
|
466
|
-
return node;
|
|
467
|
-
};
|
|
468
|
-
const sourcesOf = (checker) => (node) => pipe(referencedSymbols(checker)(derivationScopeOf(node)), Array.filter((symbol) => Option.isSome(namedValuesOf(checker)(symbol))));
|
|
469
|
-
const sitesUnder = (checker) => (node) => {
|
|
470
|
-
const nested = pipe(childrenOf$2(node), Array.flatMap((child) => sitesUnder(checker)(child)));
|
|
471
|
-
if (Array.isReadonlyArrayNonEmpty(nested)) return nested;
|
|
472
|
-
return siteValuesOf(checker)(node).pipe(Option.map((values) => ({
|
|
473
|
-
node,
|
|
474
|
-
values,
|
|
475
|
-
sources: sourcesOf(checker)(node)
|
|
476
|
-
})), Option.toArray);
|
|
477
|
-
};
|
|
478
|
-
// src/value-checks.ts
|
|
479
|
-
const OWNER_SEARCH_DEPTH = 4;
|
|
480
|
-
const NOTHING_HIDDEN = 0;
|
|
481
|
-
const directOwners = (context) => (symbol) => {
|
|
482
|
-
const keys = Array.getSomes(pipe(declarationsOf(symbol), Array.map((declaration) => ownerKeyOf(declaration))));
|
|
483
|
-
return pipe(context.owners, Array.filter((owner) => keys.includes(owner.key)));
|
|
484
|
-
};
|
|
485
|
-
const isFollowable = (declaration) => !declaration.getSourceFile().isDeclarationFile && (isTypeAliasDeclaration(declaration) || isVariableDeclaration(declaration));
|
|
486
|
-
const ownersBehind = (context) => (symbol, ancestors) => {
|
|
487
|
-
const direct = directOwners(context)(symbol);
|
|
488
|
-
if (Array.isReadonlyArrayNonEmpty(direct) || ancestors.length >= OWNER_SEARCH_DEPTH) return direct;
|
|
489
|
-
const visited = [...ancestors, symbol];
|
|
490
|
-
return uniqueByReference(pipe(declarationsOf(symbol), Array.filter((declaration) => isFollowable(declaration)), Array.flatMap((declaration) => referencedSymbols(context.checker)(declaration)), Array.filter((referenced) => !visited.includes(referenced)), Array.flatMap((referenced) => ownersBehind(context)(referenced, visited))));
|
|
491
|
-
};
|
|
492
|
-
const describeOwners = (owners) => pipe(owners, Array.map((owner) => `${owner.conceptId} (${owner.name})`), Array.join(", "));
|
|
493
|
-
const verdict = (problems, unowned) => ({
|
|
494
|
-
problems,
|
|
495
|
-
unowned
|
|
496
|
-
});
|
|
497
|
-
const derivedVerdict = (context) => (site) => {
|
|
498
|
-
const owners = uniqueByReference(pipe(site.sources, Array.flatMap((source) => ownersBehind(context)(source, []))));
|
|
499
|
-
const held = pipe(owners, Array.flatMap((owner) => owner.values));
|
|
500
|
-
const added = pipe(site.values, Array.filter((value) => !isSubsetOf([value], held)));
|
|
501
|
-
if (!Array.isReadonlyArrayNonEmpty(owners) || !Array.isReadonlyArrayNonEmpty(added)) return verdict([], []);
|
|
502
|
-
const message = `This set adds ${formatValues(added)} to ${describeOwners(owners)}. Add the values to the owner, or register the wider set as its own concept.`;
|
|
503
|
-
return verdict([problemAt({
|
|
504
|
-
rule: "owner-extension",
|
|
505
|
-
message
|
|
506
|
-
})(site.node)], []);
|
|
507
|
-
};
|
|
508
|
-
const libraryCandidates = (context) => (site) => {
|
|
509
|
-
const flowing = Array.dedupe(pipe(context.flows, Array.filter((flow) => flow.site.node === site.node), Array.map((flow) => flow.target)));
|
|
510
|
-
if (Array.isReadonlyArrayNonEmpty(flowing)) return flowing;
|
|
511
|
-
if (!pipe(site.values, Array.some((value) => typeof value === "string"))) return [];
|
|
512
|
-
const imported = importedModulesOf(site.node.getSourceFile());
|
|
513
|
-
return Array.dedupe(pipe(context.vocabularies, Array.filter((library) => imported.includes(library.specifier)), Array.filter((library) => isSubsetOf(site.values, library.vocabulary.values)), Array.map((library) => describeLibraryType(library))));
|
|
514
|
-
};
|
|
515
|
-
const listCandidates = (candidates) => {
|
|
516
|
-
const shown = pipe(Array.take(candidates, 3), Array.join(", "));
|
|
517
|
-
const hidden = candidates.length - 3;
|
|
518
|
-
if (hidden > NOTHING_HIDDEN) return `${shown} and ${String(hidden)} more`;
|
|
519
|
-
return shown;
|
|
520
|
-
};
|
|
521
|
-
const originalVerdict = (context) => (site) => {
|
|
522
|
-
const owners = pipe(context.owners, Array.filter((owner) => isSubsetOf(site.values, owner.values)));
|
|
523
|
-
if (Array.isReadonlyArrayNonEmpty(owners)) {
|
|
524
|
-
const message = `The values ${formatValues(site.values)} are owned by ${describeOwners(owners)}. Derive this set from the owner instead of restating it.`;
|
|
525
|
-
return verdict([problemAt({
|
|
526
|
-
rule: "owner-value-set",
|
|
527
|
-
message
|
|
528
|
-
})(site.node)], []);
|
|
529
|
-
}
|
|
530
|
-
const candidates = libraryCandidates(context)(site);
|
|
531
|
-
if (Array.isReadonlyArrayNonEmpty(candidates)) {
|
|
532
|
-
const message = `The values ${formatValues(site.values)} restate a dependency type: ${listCandidates(candidates)}. Derive this set from the library type.`;
|
|
533
|
-
return verdict([problemAt({
|
|
534
|
-
rule: "library-value-set",
|
|
535
|
-
message
|
|
536
|
-
})(site.node)], []);
|
|
537
|
-
}
|
|
538
|
-
return verdict([], [site]);
|
|
539
|
-
};
|
|
540
|
-
const siteVerdict = (context) => (site) => {
|
|
541
|
-
if (Array.isReadonlyArrayNonEmpty(site.sources)) return derivedVerdict(context)(site);
|
|
542
|
-
return originalVerdict(context)(site);
|
|
543
|
-
};
|
|
544
|
-
const VALUE_PARENT_KINDS = /* @__PURE__ */ new Set([
|
|
545
|
-
SyntaxKind.ReturnStatement,
|
|
546
|
-
SyntaxKind.ArrayLiteralExpression,
|
|
547
|
-
SyntaxKind.ConditionalExpression,
|
|
548
|
-
SyntaxKind.ParenthesizedExpression,
|
|
549
|
-
SyntaxKind.ArrowFunction,
|
|
550
|
-
SyntaxKind.JsxExpression
|
|
551
|
-
]);
|
|
552
|
-
const isCallArgument = (node, parent) => (isCallExpression(parent) || isNewExpression(parent)) && parent.expression !== node;
|
|
553
|
-
const isInitializer = (node, parent) => (isPropertyAssignment(parent) || isVariableDeclaration(parent)) && parent.initializer === node;
|
|
554
|
-
const isRightOperand = (node, parent) => isBinaryExpression(parent) && parent.right === node;
|
|
555
|
-
const VALUE_SLOTS = [
|
|
556
|
-
isCallArgument,
|
|
557
|
-
isInitializer,
|
|
558
|
-
isRightOperand
|
|
559
|
-
];
|
|
560
|
-
const isValuePosition = (node) => {
|
|
561
|
-
const { parent } = node;
|
|
562
|
-
return VALUE_PARENT_KINDS.has(parent.kind) || pipe(VALUE_SLOTS, Array.some((isSlot) => isSlot(node, parent)));
|
|
563
|
-
};
|
|
564
|
-
const ownedLiteralProblem = (context) => (literal) => Option.fromUndefinedOr(context.checker.getContextualType(literal)).pipe(Option.filter((contextual) => vocabularyOf(context.checker)(contextual).pipe(Option.exists((vocabulary) => !vocabulary.admitsUnnamedValues))), Option.map(() => pipe(contextSymbolsOf(context.checker)(literal), Array.flatMap((symbol) => ownersBehind(context)(symbol, [])), uniqueByReference, Array.filter((owner) => isSubsetOf([literal.text], pipe(owner.values, Array.map(String)))))), Option.filter((owners) => Array.isReadonlyArrayNonEmpty(owners)), Option.map((owners) => problemAt({
|
|
565
|
-
rule: "owned-literal",
|
|
566
|
-
message: `${literal.getText()} is a value of ${describeOwners(owners)}. Write it through the owner's binding instead of as a literal.`
|
|
567
|
-
})(literal)));
|
|
568
|
-
const ownedLiteralProblems = (context) => (sourceFile, excluded) => Array.getSomes(pipe(descendantsOf(sourceFile), Array.filter((node) => isStringLiteral(node) || isNumericLiteral(node)), Array.filter((node) => isValuePosition(node)), Array.filter((node) => !pipe(excluded, Array.some((outer) => contains(outer)(node)))), Array.map((node) => ownedLiteralProblem(context)(node))));
|
|
569
|
-
// src/analysis.ts
|
|
570
|
-
const isVisibleTo = (project) => (owner) => pipe(project.sourceFiles, Array.some((sourceFile) => sourceFile.fileName === owner.file)) || Option.exists(owner.packageName, (name) => Option.contains(project.packageName, name) || project.workspaceDependencies.includes(name));
|
|
571
|
-
const ownerDeclarationsIn = (project, owners) => {
|
|
572
|
-
const keys = new Set(pipe(owners, Array.map((owner) => owner.key)));
|
|
573
|
-
return pipe(project.sourceFiles, Array.flatMap((sourceFile) => pipe(descendantsOf(sourceFile), Array.filter((node) => isVariableDeclaration(node)), Array.filter((declaration) => Option.exists(ownerKeyOf(declaration), (key) => keys.has(key))))));
|
|
574
|
-
};
|
|
575
|
-
const isInside = (outers) => (node) => pipe(outers, Array.some((outer) => contains(outer)(node)));
|
|
576
|
-
const sitesOutside = (checker) => (project, outers) => pipe(project.sourceFiles, Array.flatMap((sourceFile) => sitesUnder(checker)(sourceFile)), Array.filter((site) => !isInside(outers)(site.node)));
|
|
577
|
-
const nodesOf = (sites) => pipe(sites, Array.map((site) => site.node));
|
|
578
|
-
const analyzeProject = (owners) => (project) => {
|
|
579
|
-
const { checker } = project;
|
|
580
|
-
const ownerDeclarations = ownerDeclarationsIn(project, owners);
|
|
581
|
-
const sites = sitesOutside(checker)(project, ownerDeclarations);
|
|
582
|
-
const flowContext = {
|
|
583
|
-
checker,
|
|
584
|
-
program: project.program,
|
|
585
|
-
sites
|
|
586
|
-
};
|
|
587
|
-
const context = {
|
|
588
|
-
checker,
|
|
589
|
-
owners: pipe(owners, Array.filter((owner) => isVisibleTo(project)(owner))),
|
|
590
|
-
vocabularies: project.library.vocabularies,
|
|
591
|
-
flows: pipe(project.sourceFiles, Array.flatMap((sourceFile) => flowsIn(flowContext)(sourceFile)))
|
|
592
|
-
};
|
|
593
|
-
const verdicts = pipe(sites, Array.map((site) => siteVerdict(context)(site)));
|
|
594
|
-
const excluded = [...ownerDeclarations, ...nodesOf(sites)];
|
|
595
|
-
const shapeContext = {
|
|
596
|
-
checker,
|
|
597
|
-
program: project.program,
|
|
598
|
-
shapes: project.library.shapes
|
|
599
|
-
};
|
|
600
|
-
return {
|
|
601
|
-
problems: [...pipe(verdicts, Array.flatMap((found) => found.problems)), ...pipe(project.sourceFiles, Array.flatMap((sourceFile) => [...ownedLiteralProblems(context)(sourceFile, excluded), ...shapeProblemsIn(shapeContext)(sourceFile)]))],
|
|
602
|
-
unowned: pipe(verdicts, Array.flatMap((found) => found.unowned))
|
|
603
|
-
};
|
|
604
|
-
};
|
|
605
|
-
// src/duplicates.ts
|
|
606
|
-
const DUPLICATE_THRESHOLD = 1;
|
|
607
|
-
const unownedSiteOf = (scope) => (site) => ({
|
|
608
|
-
scope,
|
|
609
|
-
file: site.node.getSourceFile().fileName,
|
|
610
|
-
start: site.node.getStart(),
|
|
611
|
-
line: lineOf(site.node),
|
|
612
|
-
column: columnOf(site.node),
|
|
613
|
-
values: site.values
|
|
614
|
-
});
|
|
615
|
-
const canDerive = (left, right) => left.scope.name === right.scope.name || left.scope.dependencies.includes(right.scope.name) || right.scope.dependencies.includes(left.scope.name);
|
|
616
|
-
const siteKey = (site) => `${site.file}#${String(site.start)}`;
|
|
617
|
-
const valueSetKey = (site) => {
|
|
618
|
-
const keys = pipe(site.values, Array.map((value) => valueKey(value)));
|
|
619
|
-
return pipe(Array.sort(keys, Order.String), Array.join("\0"));
|
|
620
|
-
};
|
|
621
|
-
const duplicateProblems = (relative) => (sites) => {
|
|
622
|
-
const unique = Array.dedupeWith(sites, (left, right) => siteKey(left) === siteKey(right));
|
|
623
|
-
const groups = Record.values(Array.groupBy(unique, (site) => valueSetKey(site)));
|
|
624
|
-
return pipe(groups, Array.filter((group) => group.length > DUPLICATE_THRESHOLD), Array.flatMap((group) => pipe(group, Array.flatMap((site) => {
|
|
625
|
-
const related = pipe(group, Array.filter((other) => other !== site && canDerive(site, other)));
|
|
626
|
-
if (!Array.isReadonlyArrayNonEmpty(related)) return [];
|
|
627
|
-
const others = pipe(related, Array.map((other) => `${relative(other.file)}:${String(other.line)}`), Array.join(", "));
|
|
628
|
-
return [{
|
|
629
|
-
file: site.file,
|
|
630
|
-
line: site.line,
|
|
631
|
-
column: site.column,
|
|
632
|
-
rule: "duplicate-value-set",
|
|
633
|
-
message: `The values ${formatValues(site.values)} are also declared at ${others}. Register one owner with /** @${OWNER_TAG} <concept> */ and derive the others from it.`
|
|
634
|
-
}];
|
|
635
|
-
}))));
|
|
636
|
-
};
|
|
637
|
-
// src/telemetry.ts
|
|
638
|
-
const RSS_LINE = /^VmRSS:\s+(?<kib>\d+) kB$/mu;
|
|
639
|
-
const BYTES_PER_KIB = 1024;
|
|
640
|
-
const UNKNOWN_RSS = 0;
|
|
641
|
-
const kibibytesIn = (status) => Option.fromNullishOr(RSS_LINE.exec(status)).pipe(Option.flatMap((match) => Option.fromUndefinedOr(match.groups)), Option.flatMap((groups) => Option.fromUndefinedOr(groups["kib"])));
|
|
642
|
-
const residentBytesOf = (pid) => Effect.gen(function* residentBytes() {
|
|
643
|
-
const status = yield* (yield* RepositoryFiles).readFile(`/proc/${pid}/status`);
|
|
644
|
-
return pipe(status, Option.flatMap(kibibytesIn), Option.flatMap(Number$1.parse), Option.map((kib) => kib * BYTES_PER_KIB), Option.getOrElse(() => UNKNOWN_RSS));
|
|
645
|
-
});
|
|
646
|
-
const childPids = Effect.gen(function* childPids() {
|
|
647
|
-
const files = yield* RepositoryFiles;
|
|
648
|
-
const pid = String(process.pid);
|
|
649
|
-
const children = yield* files.readFile(`/proc/${pid}/task/${pid}/children`);
|
|
650
|
-
return pipe(children, Option.map((text) => pipe(String$1.trim(text), String$1.split(" "), Array.filter(String$1.isNonEmpty))), Option.getOrElse(() => []));
|
|
651
|
-
});
|
|
652
|
-
const annotateMemory = Effect.gen(function* annotateMemory() {
|
|
653
|
-
const own = yield* residentBytesOf(String(process.pid));
|
|
654
|
-
const pids = yield* childPids;
|
|
655
|
-
const children = yield* pipe(pids, Effect.forEach((pid) => residentBytesOf(pid)));
|
|
656
|
-
const { heapUsed } = process.memoryUsage();
|
|
657
|
-
yield* Effect.annotateCurrentSpan({
|
|
658
|
-
"process.memory.rss": own,
|
|
659
|
-
"process.memory.heap_used": heapUsed,
|
|
660
|
-
"msch.compiler.memory.rss": Number$1.sumAll(children)
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
const annotateResources = (api) => Effect.gen(function* annotateCompiler() {
|
|
664
|
-
yield* annotateMemory;
|
|
665
|
-
const { totals } = api.getTimingInfo();
|
|
666
|
-
yield* Effect.annotateCurrentSpan({
|
|
667
|
-
"msch.compiler.requests": totals.requestCount,
|
|
668
|
-
"msch.compiler.round_trip_ms": totals.roundTripMs,
|
|
669
|
-
"msch.compiler.server_ms": totals.serverTimeMs
|
|
213
|
+
});
|
|
214
|
+
const annotateResources = (api) => Effect.gen(function* annotateCompiler() {
|
|
215
|
+
yield* annotateMemory;
|
|
216
|
+
const { totals } = api.getTimingInfo();
|
|
217
|
+
yield* Effect.annotateCurrentSpan({
|
|
218
|
+
"msch.compiler.requests": totals.requestCount,
|
|
219
|
+
"msch.compiler.round_trip_ms": totals.roundTripMs,
|
|
220
|
+
"msch.compiler.server_ms": totals.serverTimeMs
|
|
670
221
|
});
|
|
671
222
|
});
|
|
672
|
-
// src/project.ts
|
|
223
|
+
// src/entities/project/model/project.ts
|
|
673
224
|
const CONFIG_PATHSPEC = `:(glob)**/tsconfig.json`;
|
|
674
225
|
const HIDDEN_PREFIX = ".";
|
|
675
226
|
const SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -763,62 +314,39 @@ const mentions$1 = (needle) => ({ api }) => (configPath) => Effect.gen(function*
|
|
|
763
314
|
const includesNeedle = String$1.includes(needle);
|
|
764
315
|
return pipe(texts, Array.some((text) => Option.exists(text, includesNeedle)));
|
|
765
316
|
});
|
|
766
|
-
// src/
|
|
767
|
-
const
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
});
|
|
772
|
-
const scopeOf = (project, configPath) => ({
|
|
773
|
-
name: Option.getOrElse(project.packageName, () => configPath),
|
|
774
|
-
dependencies: project.workspaceDependencies
|
|
775
|
-
});
|
|
776
|
-
const analyzeProjects = (workspace, owners) => (configPaths) => pipe(configPaths, Effect.forEach((configPath) => withProject(workspace)(configPath)((project) => Effect.sync(() => {
|
|
777
|
-
const analysis = analyzeProject(owners)(project);
|
|
778
|
-
const scope = scopeOf(project, configPath);
|
|
317
|
+
// src/shared/lib/text-position.ts
|
|
318
|
+
const START$6 = 0;
|
|
319
|
+
const FIRST_COLUMN$3 = 1;
|
|
320
|
+
const positionOf = (source) => (index) => {
|
|
321
|
+
const before = pipe(source, String$1.slice(START$6, index), String$1.split("\n"));
|
|
779
322
|
return {
|
|
780
|
-
|
|
781
|
-
|
|
323
|
+
line: before.length,
|
|
324
|
+
column: pipe(Array.last(before), Option.match({
|
|
325
|
+
onNone: () => FIRST_COLUMN$3,
|
|
326
|
+
onSome: (last) => last.length + FIRST_COLUMN$3
|
|
327
|
+
}))
|
|
782
328
|
};
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
const files = yield* RepositoryFiles;
|
|
786
|
-
const workspace = {
|
|
787
|
-
compiler: yield* typeScriptCompiler,
|
|
788
|
-
root,
|
|
789
|
-
generated: yield* files.generatedFiles(root)
|
|
790
|
-
};
|
|
791
|
-
const configPaths = yield* listConfigFiles(root);
|
|
792
|
-
const ownerScan = yield* scanOwners(workspace, configPaths);
|
|
793
|
-
const analyses = yield* analyzeProjects(workspace, ownerScan.owners)(configPaths);
|
|
794
|
-
const relative = (file) => files.relative(root, file);
|
|
795
|
-
const unowned = pipe(analyses, Array.flatMap((analysis) => analysis.unowned));
|
|
796
|
-
return sortProblems([
|
|
797
|
-
...ownerScan.problems,
|
|
798
|
-
...pipe(analyses, Array.flatMap((analysis) => analysis.problems)),
|
|
799
|
-
...duplicateProblems(relative)(unowned)
|
|
800
|
-
]);
|
|
801
|
-
}, Effect.scoped);
|
|
802
|
-
// src/import-graph.ts
|
|
329
|
+
};
|
|
330
|
+
// src/features/install-size/model/import-graph.ts
|
|
803
331
|
const RELATIVE = /^\.\.?(?:\/|$)/u;
|
|
804
332
|
const SUBPATH_IMPORT = "#";
|
|
805
333
|
const WILDCARD = "*";
|
|
806
334
|
const SCOPE$1 = "@";
|
|
807
|
-
const SEPARATOR$
|
|
335
|
+
const SEPARATOR$4 = "/";
|
|
808
336
|
const SOURCE_SUFFIXES = [
|
|
809
337
|
"",
|
|
810
338
|
".ts",
|
|
811
339
|
".tsx",
|
|
812
340
|
"/index.ts"
|
|
813
341
|
];
|
|
814
|
-
const SCOPED_SEGMENTS = 2;
|
|
342
|
+
const SCOPED_SEGMENTS$1 = 2;
|
|
815
343
|
const PLAIN_SEGMENTS = 1;
|
|
816
344
|
const ImportsField = Schema.Struct({ imports: Schema.optional(Schema.Record(Schema.String, Schema.String)) });
|
|
817
345
|
const decodeImports = Schema.decodeOption(Schema.fromJsonString(ImportsField));
|
|
818
346
|
const packageNameOf = (specifier) => {
|
|
819
|
-
const segments = String$1.split(specifier, SEPARATOR$
|
|
820
|
-
if (String$1.startsWith(SCOPE$1)(specifier)) return pipe(segments, Array.take(SCOPED_SEGMENTS), Array.join(SEPARATOR$
|
|
821
|
-
return pipe(segments, Array.take(PLAIN_SEGMENTS), Array.join(SEPARATOR$
|
|
347
|
+
const segments = String$1.split(specifier, SEPARATOR$4);
|
|
348
|
+
if (String$1.startsWith(SCOPE$1)(specifier)) return pipe(segments, Array.take(SCOPED_SEGMENTS$1), Array.join(SEPARATOR$4));
|
|
349
|
+
return pipe(segments, Array.take(PLAIN_SEGMENTS), Array.join(SEPARATOR$4));
|
|
822
350
|
};
|
|
823
351
|
const literalText = (specifier) => pipe(Option.liftPredicate(specifier, isStringLiteral), Option.map((literal) => literal.text));
|
|
824
352
|
const runtimeSpecifierOf = (statement) => {
|
|
@@ -902,7 +430,7 @@ const packagesByEntry = Effect.fn("packagesByEntry")(function* packagesByEntry(a
|
|
|
902
430
|
packages: HashSet.empty()
|
|
903
431
|
}).pipe(Effect.map((packages) => [entry, packages]))));
|
|
904
432
|
});
|
|
905
|
-
// src/installed-closure.ts
|
|
433
|
+
// src/features/install-size/model/installed-closure.ts
|
|
906
434
|
const EMPTY = 0;
|
|
907
435
|
const DependencyMap = Schema.optional(Schema.Record(Schema.String, Schema.String));
|
|
908
436
|
const PeerMetaEntry = Schema.Struct({ optional: Schema.optional(Schema.Boolean) });
|
|
@@ -976,20 +504,7 @@ const installedSize = (directory) => {
|
|
|
976
504
|
if (String$1.includes(`/node_modules/`)(directory)) return directorySize(directory);
|
|
977
505
|
return Effect.succeed(EMPTY);
|
|
978
506
|
};
|
|
979
|
-
// src/
|
|
980
|
-
const START$5 = 0;
|
|
981
|
-
const FIRST_COLUMN$2 = 1;
|
|
982
|
-
const positionOf = (source) => (index) => {
|
|
983
|
-
const before = pipe(source, String$1.slice(START$5, index), String$1.split("\n"));
|
|
984
|
-
return {
|
|
985
|
-
line: before.length,
|
|
986
|
-
column: pipe(Array.last(before), Option.match({
|
|
987
|
-
onNone: () => FIRST_COLUMN$2,
|
|
988
|
-
onSome: (last) => last.length + FIRST_COLUMN$2
|
|
989
|
-
}))
|
|
990
|
-
};
|
|
991
|
-
};
|
|
992
|
-
// src/install-size.ts
|
|
507
|
+
// src/features/install-size/model/install-size.ts
|
|
993
508
|
const INSTALL_SIZE = "install-size";
|
|
994
509
|
const STACK_DEPENDENCY = "stack-dependency";
|
|
995
510
|
const STACK_CATALOG = "catalog:stack";
|
|
@@ -999,11 +514,11 @@ const LISTED_LARGEST = 5;
|
|
|
999
514
|
const SIZE_CONCURRENCY = 32;
|
|
1000
515
|
const MEGABYTE = 1e6;
|
|
1001
516
|
const MEGABYTE_DIGITS = 1;
|
|
1002
|
-
const START$
|
|
517
|
+
const START$5 = 0;
|
|
1003
518
|
const SINGLE_ENTRY = 1;
|
|
1004
519
|
const megabytes = (bytes) => `${(bytes / MEGABYTE).toFixed(MEGABYTE_DIGITS)} MB`;
|
|
1005
520
|
const usageHint = (dependency, entryCount) => {
|
|
1006
|
-
if (!(entryCount > SINGLE_ENTRY && dependency.entries.length > START$
|
|
521
|
+
if (!(entryCount > SINGLE_ENTRY && dependency.entries.length > START$5 && dependency.entries.length < entryCount)) return "";
|
|
1007
522
|
return ` (imported only from ${Array.join(dependency.entries, ", ")})`;
|
|
1008
523
|
};
|
|
1009
524
|
const listed = ({ largest, entryCount }) => pipe(largest, Array.map((dependency) => `${dependency.name} ${megabytes(dependency.size)}${usageHint(dependency, entryCount)}`), Array.join(", "));
|
|
@@ -1012,7 +527,7 @@ const budgetProblem = Effect.fn("budgetProblem")(function* budgetProblem(overrun
|
|
|
1012
527
|
const { workspace, total } = overrun;
|
|
1013
528
|
const config = yield* files.readFile(workspace.configFile);
|
|
1014
529
|
const source = Option.getOrElse(config, () => "");
|
|
1015
|
-
const index = Option.getOrElse(String$1.indexOf(BUDGET_KEY)(source), () => START$
|
|
530
|
+
const index = Option.getOrElse(String$1.indexOf(BUDGET_KEY)(source), () => START$5);
|
|
1016
531
|
return {
|
|
1017
532
|
file: workspace.configFile,
|
|
1018
533
|
...positionOf(source)(index),
|
|
@@ -1029,7 +544,7 @@ const measure = Effect.fn("measure")(function* measure({ workspace, provided },
|
|
|
1029
544
|
const everything = pipe(closures, Array.flatMap(([, packages]) => Array.fromIterable(packages)), HashSet.fromIterable);
|
|
1030
545
|
const measured = yield* Effect.forEach(everything, (found) => installedSize(found).pipe(Effect.map((size) => [found, size])), { concurrency: SIZE_CONCURRENCY });
|
|
1031
546
|
const sizes = HashMap.fromIterable(measured);
|
|
1032
|
-
const sizeOf = (packages) => Number$1.sumAll(pipe(Array.fromIterable(packages), Array.map((found) => Option.getOrElse(HashMap.get(sizes, found), () => START$
|
|
547
|
+
const sizeOf = (packages) => Number$1.sumAll(pipe(Array.fromIterable(packages), Array.map((found) => Option.getOrElse(HashMap.get(sizes, found), () => START$5))));
|
|
1033
548
|
return {
|
|
1034
549
|
closures,
|
|
1035
550
|
sizeOf,
|
|
@@ -1062,11 +577,11 @@ const sizeProblems = Effect.fn("sizeProblems")(function* sizeProblems(published,
|
|
|
1062
577
|
})];
|
|
1063
578
|
});
|
|
1064
579
|
const stackProblems = (file, source, dependencies) => {
|
|
1065
|
-
const section = Option.getOrElse(String$1.indexOf(DEPENDENCIES_KEY)(source), () => START$
|
|
580
|
+
const section = Option.getOrElse(String$1.indexOf(DEPENDENCIES_KEY)(source), () => START$5);
|
|
1066
581
|
const rest = String$1.slice(section)(source);
|
|
1067
582
|
return pipe(Record.toEntries(dependencies), Array.filter(([, specifier]) => specifier === STACK_CATALOG), Array.map(([name]) => ({
|
|
1068
583
|
file,
|
|
1069
|
-
...positionOf(source)(section + Option.getOrElse(String$1.indexOf(`"${name}"`)(rest), () => START$
|
|
584
|
+
...positionOf(source)(section + Option.getOrElse(String$1.indexOf(`"${name}"`)(rest), () => START$5)),
|
|
1070
585
|
rule: STACK_DEPENDENCY,
|
|
1071
586
|
message: `${name} comes from the stack catalog, so every project that installs this package already has it. Move it to peerDependencies and keep it in devDependencies, so the installing project shares one copy.`
|
|
1072
587
|
})));
|
|
@@ -1078,7 +593,7 @@ const PublishedManifest = Schema.Struct({
|
|
|
1078
593
|
exports: Schema.optional(Schema.Unknown),
|
|
1079
594
|
bin: Schema.optional(Schema.Unknown)
|
|
1080
595
|
});
|
|
1081
|
-
const problemsOf = Effect.fn("problemsOf")(function* problemsOf(workspace, file, source) {
|
|
596
|
+
const problemsOf$1 = Effect.fn("problemsOf")(function* problemsOf(workspace, file, source) {
|
|
1082
597
|
const files = yield* RepositoryFiles;
|
|
1083
598
|
const manifest = Schema.decodeOption(Schema.fromJsonString(PublishedManifest))(source);
|
|
1084
599
|
if (Option.isNone(manifest)) return [];
|
|
@@ -1102,7 +617,7 @@ const workspaceProblems = Effect.fn("workspaceProblems")(function* workspaceProb
|
|
|
1102
617
|
const source = yield* files.readFile(file);
|
|
1103
618
|
return yield* Option.match(source, {
|
|
1104
619
|
onNone: () => Effect.succeed([]),
|
|
1105
|
-
onSome: (text) => problemsOf(workspace, file, text)
|
|
620
|
+
onSome: (text) => problemsOf$1(workspace, file, text)
|
|
1106
621
|
});
|
|
1107
622
|
});
|
|
1108
623
|
/** @internal */
|
|
@@ -1111,7 +626,7 @@ const checkPublishedPackages = Effect.fn("checkPublishedPackages")(function* che
|
|
|
1111
626
|
const found = yield* pipe(workspaces, Effect.forEach(workspaceProblems));
|
|
1112
627
|
return Array.flatten(found);
|
|
1113
628
|
});
|
|
1114
|
-
// src/override-findings.ts
|
|
629
|
+
// src/features/overrides/model/override-findings.ts
|
|
1115
630
|
const describeVersions = (versions) => Option.getOrElse(Option.liftPredicate(Array.join(versions, ","), (joined) => joined !== ""), () => "-");
|
|
1116
631
|
const describeChanges = (report) => {
|
|
1117
632
|
const versions = pipe(report.changes, Array.map((change) => `${change.name} ${describeVersions(change.before)} -> ${describeVersions(change.after)}`));
|
|
@@ -1136,7 +651,7 @@ const overrideProblem = (located) => (report) => {
|
|
|
1136
651
|
});
|
|
1137
652
|
return Option.none();
|
|
1138
653
|
};
|
|
1139
|
-
// src/override-resolution.ts
|
|
654
|
+
// src/features/overrides/model/override-resolution.ts
|
|
1140
655
|
const VerdictSchema = Schema.Literals([
|
|
1141
656
|
"unused",
|
|
1142
657
|
"keep",
|
|
@@ -1178,7 +693,7 @@ const AdvisorySchema = Schema.Struct({
|
|
|
1178
693
|
github_advisory_id: Schema.String
|
|
1179
694
|
});
|
|
1180
695
|
const AuditReport = Schema.fromJsonString(Schema.Struct({ advisories: Schema.Record(Schema.String, AdvisorySchema) }));
|
|
1181
|
-
const SCOPE_PREFIX = "@";
|
|
696
|
+
const SCOPE_PREFIX$1 = "@";
|
|
1182
697
|
const NAME_START = 0;
|
|
1183
698
|
const SEPARATOR_LENGTH = 1;
|
|
1184
699
|
const PEER_CONTEXT_START = "(";
|
|
@@ -1202,14 +717,14 @@ const advisoriesIn = (output) => Option.match(Schema.decodeOption(AuditReport)(o
|
|
|
1202
717
|
onSome: (report) => sorted(pipe(Record.values(report.advisories), Array.map((advisory) => `${advisory.module_name} ${advisory.github_advisory_id}`)))
|
|
1203
718
|
});
|
|
1204
719
|
const separatorOf = (key) => {
|
|
1205
|
-
if (!String$1.startsWith(SCOPE_PREFIX)(key)) return String$1.indexOf(SCOPE_PREFIX)(key);
|
|
1206
|
-
return pipe(String$1.slice(SEPARATOR_LENGTH)(key), String$1.indexOf(SCOPE_PREFIX), Option.map((index) => index + SEPARATOR_LENGTH));
|
|
720
|
+
if (!String$1.startsWith(SCOPE_PREFIX$1)(key)) return String$1.indexOf(SCOPE_PREFIX$1)(key);
|
|
721
|
+
return pipe(String$1.slice(SEPARATOR_LENGTH)(key), String$1.indexOf(SCOPE_PREFIX$1), Option.map((index) => index + SEPARATOR_LENGTH));
|
|
1207
722
|
};
|
|
1208
723
|
const withoutPeerContext = (version) => Option.match(String$1.indexOf(PEER_CONTEXT_START)(version), {
|
|
1209
724
|
onNone: () => version,
|
|
1210
725
|
onSome: (start) => String$1.slice(NAME_START, start)(version)
|
|
1211
726
|
});
|
|
1212
|
-
const packageOf = (key) => Option.map(separatorOf(key), (separator) => [String$1.slice(NAME_START, separator)(key), withoutPeerContext(String$1.slice(separator + SEPARATOR_LENGTH)(key))]);
|
|
727
|
+
const packageOf$1 = (key) => Option.map(separatorOf(key), (separator) => [String$1.slice(NAME_START, separator)(key), withoutPeerContext(String$1.slice(separator + SEPARATOR_LENGTH)(key))]);
|
|
1213
728
|
const keysOf = (node) => {
|
|
1214
729
|
if (!isMap(node)) return [];
|
|
1215
730
|
return pipe(node.items, Array.flatMap((pair) => {
|
|
@@ -1220,7 +735,7 @@ const keysOf = (node) => {
|
|
|
1220
735
|
const lockfileKeysOf = (lockfile, section) => pipe(parseAllDocuments(lockfile), Array.flatMap((document) => keysOf(document.get(section))));
|
|
1221
736
|
const resolutionOf = (findings) => (lockfile) => {
|
|
1222
737
|
const snapshots = lockfileKeysOf(lockfile, "snapshots");
|
|
1223
|
-
const packages = Array.getSomes(pipe([...lockfileKeysOf(lockfile, "packages"), ...snapshots], Array.map((key) => packageOf(key))));
|
|
738
|
+
const packages = Array.getSomes(pipe([...lockfileKeysOf(lockfile, "packages"), ...snapshots], Array.map((key) => packageOf$1(key))));
|
|
1224
739
|
const versions = Record.map(Array.groupBy(packages, ([name]) => name), (entries) => sorted(pipe(entries, Array.map(([, version]) => version))));
|
|
1225
740
|
return {
|
|
1226
741
|
...findings,
|
|
@@ -1290,12 +805,12 @@ const withBaselineProbe = (manifest) => {
|
|
|
1290
805
|
document.setIn([OVERRIDES, BASELINE_PROBE], REMOVED_DEPENDENCY);
|
|
1291
806
|
return document.toString();
|
|
1292
807
|
};
|
|
1293
|
-
// src/overrides.ts
|
|
1294
|
-
const WORKSPACE_FILE = "pnpm-workspace.yaml";
|
|
808
|
+
// src/features/overrides/model/overrides.ts
|
|
809
|
+
const WORKSPACE_FILE$1 = "pnpm-workspace.yaml";
|
|
1295
810
|
const LOCKFILE$1 = "pnpm-lock.yaml";
|
|
1296
811
|
const RESOLUTION_FILES = [
|
|
1297
812
|
"*package.json",
|
|
1298
|
-
WORKSPACE_FILE,
|
|
813
|
+
WORKSPACE_FILE$1,
|
|
1299
814
|
LOCKFILE$1,
|
|
1300
815
|
".npmrc",
|
|
1301
816
|
"patches/*"
|
|
@@ -1366,7 +881,7 @@ const resolutionWith = Effect.fn("resolutionWith")(function* resolutionWith(work
|
|
|
1366
881
|
const path = yield* Path.Path;
|
|
1367
882
|
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "msch-overrides-" });
|
|
1368
883
|
yield* copyFiles(workspace, directory);
|
|
1369
|
-
yield* fs.writeFileString(path.join(directory, WORKSPACE_FILE), manifest);
|
|
884
|
+
yield* fs.writeFileString(path.join(directory, WORKSPACE_FILE$1), manifest);
|
|
1370
885
|
const output = yield* resolveIn(directory, override);
|
|
1371
886
|
const lockfile = yield* fs.readFileString(path.join(directory, LOCKFILE$1));
|
|
1372
887
|
yield* Effect.annotateCurrentSpan({ "msch.override": override });
|
|
@@ -1385,7 +900,7 @@ const problemsFor = Effect.fn("problemsFor")(function* problemsFor(root, manifes
|
|
|
1385
900
|
};
|
|
1386
901
|
const baseline = yield* resolutionWith(workspace, BASELINE_PROBE, withBaselineProbe(manifest));
|
|
1387
902
|
const judgeAgainstBaseline = judge(baseline);
|
|
1388
|
-
const file = path.join(root, WORKSPACE_FILE);
|
|
903
|
+
const file = path.join(root, WORKSPACE_FILE$1);
|
|
1389
904
|
const problemOf = (located) => resolutionWith(workspace, located.key, withoutOverride(located.key)(manifest)).pipe(Effect.map((candidate) => overrideProblem({
|
|
1390
905
|
...located,
|
|
1391
906
|
file
|
|
@@ -1397,7 +912,7 @@ const problemsFor = Effect.fn("problemsFor")(function* problemsFor(root, manifes
|
|
|
1397
912
|
const checkOverrides = Effect.fn("checkOverrides")(function* checkOverrides(root) {
|
|
1398
913
|
const fs = yield* FileSystem.FileSystem;
|
|
1399
914
|
const path = yield* Path.Path;
|
|
1400
|
-
const manifest = yield* fs.readFileString(path.join(root, WORKSPACE_FILE)).pipe(Effect.option);
|
|
915
|
+
const manifest = yield* fs.readFileString(path.join(root, WORKSPACE_FILE$1)).pipe(Effect.option);
|
|
1401
916
|
const keys = Option.match(manifest, {
|
|
1402
917
|
onNone: () => [],
|
|
1403
918
|
onSome: overrideKeysOf
|
|
@@ -1405,10 +920,10 @@ const checkOverrides = Effect.fn("checkOverrides")(function* checkOverrides(root
|
|
|
1405
920
|
if (Option.isNone(manifest) || !Array.isReadonlyArrayNonEmpty(keys)) return [];
|
|
1406
921
|
return yield* problemsFor(root, manifest.value, keys);
|
|
1407
922
|
});
|
|
1408
|
-
// src/colocated-tests.ts
|
|
1409
|
-
const RULE$
|
|
923
|
+
// src/features/placement/model/colocated-tests.ts
|
|
924
|
+
const RULE$8 = "colocated-test";
|
|
1410
925
|
const FIRST$4 = 1;
|
|
1411
|
-
const READ_CONCURRENCY$
|
|
926
|
+
const READ_CONCURRENCY$8 = 64;
|
|
1412
927
|
const ROOT_SUBPATH = ".";
|
|
1413
928
|
const NAME_GROUP = "name";
|
|
1414
929
|
const SPECIFIER_GROUP = "specifier";
|
|
@@ -1432,12 +947,12 @@ const problemFor$2 = (test, message) => ({
|
|
|
1432
947
|
file: test.file,
|
|
1433
948
|
line: FIRST$4,
|
|
1434
949
|
column: FIRST$4,
|
|
1435
|
-
rule: RULE$
|
|
950
|
+
rule: RULE$8,
|
|
1436
951
|
message: `${test.base} ${message}`
|
|
1437
952
|
});
|
|
1438
953
|
const groupsOf = (source, pattern, group) => pipe(Array.fromIterable(String$1.matchAll(pattern)(source)), Array.map((match) => pipe(Option.fromUndefinedOr(match.groups), Option.flatMap((groups) => Option.fromUndefinedOr(groups[group])))), Array.getSomes);
|
|
1439
954
|
const namesSibling = (source) => pipe([...groupsOf(source, RELATIVE_REFERENCE, NAME_GROUP), ...groupsOf(source, DIRNAME_REFERENCE, NAME_GROUP)], Array.some((name) => !TEST_FILE.test(name)));
|
|
1440
|
-
const ownerOf = (packages, name) => {
|
|
955
|
+
const ownerOf$1 = (packages, name) => {
|
|
1441
956
|
const owners = pipe(packages, Array.filter((directory) => String$1.startsWith(directory)(name)));
|
|
1442
957
|
return Array.last(Array.sort(owners, byLength));
|
|
1443
958
|
};
|
|
@@ -1448,7 +963,7 @@ const specifiersBeside = ({ join, dirname, directory }) => (manifest) => pipe(Op
|
|
|
1448
963
|
}), Array.filter(({ source }) => dirname(source) === directory), Array.map(({ label }) => String$1.replace(ROOT_SUBPATH, name)(label)))), Option.getOrElse(() => []));
|
|
1449
964
|
const ownSpecifiers = Effect.fn("ownSpecifiers")(function* ownSpecifiers(context, test) {
|
|
1450
965
|
const files = yield* RepositoryFiles;
|
|
1451
|
-
const owner = ownerOf(context.packages, test.name);
|
|
966
|
+
const owner = ownerOf$1(context.packages, test.name);
|
|
1452
967
|
if (Option.isNone(owner)) return [];
|
|
1453
968
|
const text = yield* files.readFile(files.join(context.root, owner.value, MANIFEST_FILE));
|
|
1454
969
|
const join = (target) => files.join(context.root, owner.value, target);
|
|
@@ -1494,27 +1009,27 @@ const checkColocatedTests = Effect.fn("checkColocatedTests")(function* checkColo
|
|
|
1494
1009
|
directory: files.dirname(file)
|
|
1495
1010
|
};
|
|
1496
1011
|
}));
|
|
1497
|
-
const found = yield* Effect.forEach(tests, (test) => problemIn$3(context, test), { concurrency: READ_CONCURRENCY$
|
|
1012
|
+
const found = yield* Effect.forEach(tests, (test) => problemIn$3(context, test), { concurrency: READ_CONCURRENCY$8 });
|
|
1498
1013
|
return Array.getSomes(found);
|
|
1499
1014
|
});
|
|
1500
|
-
// src/nested-docs.ts
|
|
1501
|
-
const RULE$
|
|
1015
|
+
// src/features/placement/model/nested-docs.ts
|
|
1016
|
+
const RULE$7 = "nested-docs";
|
|
1502
1017
|
const CONFIG_FILE$4 = "vite.config.ts";
|
|
1503
|
-
const SEPARATOR$
|
|
1018
|
+
const SEPARATOR$3 = "/";
|
|
1504
1019
|
const FIRST$3 = 1;
|
|
1505
|
-
const READ_CONCURRENCY$
|
|
1020
|
+
const READ_CONCURRENCY$7 = 64;
|
|
1506
1021
|
const AGENT_DOCS = /^(?:AGENTS|CLAUDE)(?:\.[^/]+)?\.md$/iu;
|
|
1507
1022
|
const WORKSPACE_AGENT_DOC = "AGENTS.md";
|
|
1508
1023
|
const README$1 = /^README(?:\.[^/]+)?$/iu;
|
|
1509
1024
|
const RootConfig$1 = Schema.Struct({ msch: Schema.Struct({ workspaceAgentsMd: Schema.Literal(true) }) });
|
|
1510
1025
|
const taggedError$3 = Schema.TaggedError;
|
|
1511
1026
|
var RootConfigUnreadable = class extends taggedError$3()("RootConfigUnreadable", { file: Schema.String }) {};
|
|
1512
|
-
const isNested = (name) => String$1.includes(SEPARATOR$
|
|
1027
|
+
const isNested = (name) => String$1.includes(SEPARATOR$3)(name);
|
|
1513
1028
|
const problemFor$1 = (file, message) => ({
|
|
1514
1029
|
file,
|
|
1515
1030
|
line: FIRST$3,
|
|
1516
1031
|
column: FIRST$3,
|
|
1517
|
-
rule: RULE$
|
|
1032
|
+
rule: RULE$7,
|
|
1518
1033
|
message
|
|
1519
1034
|
});
|
|
1520
1035
|
const AGENT_DOCS_MESSAGE = "belongs only at the repository root. Move what agents need into the root AGENTS.md and delete this file.";
|
|
@@ -1560,18 +1075,18 @@ const checkNestedDocs = Effect.fn("checkNestedDocs")(function* checkNestedDocs(r
|
|
|
1560
1075
|
workspaces: pipe(nested, Array.filter((name) => files.basename(name) === MANIFEST_FILE), Array.map((name) => files.dirname(files.join(root, name))), HashSet.fromIterable),
|
|
1561
1076
|
workspaceAgentDocs
|
|
1562
1077
|
};
|
|
1563
|
-
const found = yield* Effect.forEach(nested, (name) => problemIn$2(root, allowed, name), { concurrency: READ_CONCURRENCY$
|
|
1078
|
+
const found = yield* Effect.forEach(nested, (name) => problemIn$2(root, allowed, name), { concurrency: READ_CONCURRENCY$7 });
|
|
1564
1079
|
return Array.getSomes(found);
|
|
1565
1080
|
});
|
|
1566
|
-
// src/root-readme.ts
|
|
1567
|
-
const RULE$
|
|
1568
|
-
const SEPARATOR$
|
|
1081
|
+
// src/features/placement/model/root-readme.ts
|
|
1082
|
+
const RULE$6 = "root-readme";
|
|
1083
|
+
const SEPARATOR$2 = "/";
|
|
1569
1084
|
const ALTERNATIVE = "|";
|
|
1570
1085
|
const SCOPE = /^@[^/]+\//u;
|
|
1571
1086
|
const README = /^README(?:\.[^/]+)?$/iu;
|
|
1572
1087
|
const SPECIAL = /[$()*+.?[\\\]^{|}]/gu;
|
|
1573
|
-
const READ_CONCURRENCY$
|
|
1574
|
-
const START$
|
|
1088
|
+
const READ_CONCURRENCY$6 = 16;
|
|
1089
|
+
const START$4 = 0;
|
|
1575
1090
|
const NamedManifest = Schema.fromJsonString(Schema.Struct({ name: Schema.optional(Schema.String) }));
|
|
1576
1091
|
const patternOf = (names) => {
|
|
1577
1092
|
const alternatives = pipe(names, Array.map(String$1.replaceAll(SPECIAL, String.raw`\$&`)));
|
|
@@ -1601,39 +1116,739 @@ const problemsIn$2 = (file, source) => ({ directory, pattern }) => {
|
|
|
1601
1116
|
const at = positionOf(source);
|
|
1602
1117
|
return pipe(Array.fromIterable(String$1.matchAll(pattern)(source)), Array.map((found) => ({
|
|
1603
1118
|
file,
|
|
1604
|
-
...at(found.index ?? START$
|
|
1605
|
-
rule: RULE$
|
|
1119
|
+
...at(found.index ?? START$4),
|
|
1120
|
+
rule: RULE$6,
|
|
1606
1121
|
message
|
|
1607
1122
|
})));
|
|
1608
1123
|
};
|
|
1609
|
-
const problemsInReadme = Effect.fn("problemsInReadme")(function* problemsInReadme(file, workspaces) {
|
|
1610
|
-
const text = yield* (yield* RepositoryFiles).readFile(file);
|
|
1611
|
-
return pipe(text, Option.match({
|
|
1612
|
-
onNone: () => [],
|
|
1613
|
-
onSome: (source) => pipe(workspaces, Array.flatMap(problemsIn$2(file, source)))
|
|
1614
|
-
}));
|
|
1615
|
-
});
|
|
1616
|
-
/** @internal */
|
|
1617
|
-
const checkRootReadme = Effect.fn("checkRootReadme")(function* checkRootReadme(root) {
|
|
1618
|
-
const files = yield* RepositoryFiles;
|
|
1619
|
-
const names = yield* files.listedFiles(root);
|
|
1620
|
-
const readmes = pipe(names, Array.filter((name) => README.test(name)));
|
|
1621
|
-
const manifests = pipe(names, Array.filter((name) => String$1.includes(SEPARATOR$
|
|
1622
|
-
const workspaces = yield* Effect.forEach(manifests, (name) => workspaceIn(root, name), { concurrency: READ_CONCURRENCY$
|
|
1623
|
-
const found = yield* Effect.forEach(readmes, (name) => problemsInReadme(files.join(root, name), workspaces), { concurrency: READ_CONCURRENCY$
|
|
1624
|
-
return Array.flatten(found);
|
|
1124
|
+
const problemsInReadme = Effect.fn("problemsInReadme")(function* problemsInReadme(file, workspaces) {
|
|
1125
|
+
const text = yield* (yield* RepositoryFiles).readFile(file);
|
|
1126
|
+
return pipe(text, Option.match({
|
|
1127
|
+
onNone: () => [],
|
|
1128
|
+
onSome: (source) => pipe(workspaces, Array.flatMap(problemsIn$2(file, source)))
|
|
1129
|
+
}));
|
|
1130
|
+
});
|
|
1131
|
+
/** @internal */
|
|
1132
|
+
const checkRootReadme = Effect.fn("checkRootReadme")(function* checkRootReadme(root) {
|
|
1133
|
+
const files = yield* RepositoryFiles;
|
|
1134
|
+
const names = yield* files.listedFiles(root);
|
|
1135
|
+
const readmes = pipe(names, Array.filter((name) => README.test(name)));
|
|
1136
|
+
const manifests = pipe(names, Array.filter((name) => String$1.includes(SEPARATOR$2)(name) && files.basename(name) === "package.json"));
|
|
1137
|
+
const workspaces = yield* Effect.forEach(manifests, (name) => workspaceIn(root, name), { concurrency: READ_CONCURRENCY$6 });
|
|
1138
|
+
const found = yield* Effect.forEach(readmes, (name) => problemsInReadme(files.join(root, name), workspaces), { concurrency: READ_CONCURRENCY$6 });
|
|
1139
|
+
return Array.flatten(found);
|
|
1140
|
+
});
|
|
1141
|
+
// src/features/placement/model/placement-checks.ts
|
|
1142
|
+
/** @internal */
|
|
1143
|
+
const checkPlacement = Effect.fn("checkPlacement")(function* checkPlacement(root) {
|
|
1144
|
+
const found = yield* Effect.all([
|
|
1145
|
+
checkNestedDocs(root),
|
|
1146
|
+
checkRootReadme(root),
|
|
1147
|
+
checkColocatedTests(root)
|
|
1148
|
+
], { concurrency: "unbounded" });
|
|
1149
|
+
return Array.flatten(found);
|
|
1150
|
+
});
|
|
1151
|
+
// src/features/repository-layout/model/crates.ts
|
|
1152
|
+
const RULE$5 = "unverified-crate";
|
|
1153
|
+
const CARGO_FILE = "Cargo.toml";
|
|
1154
|
+
const CONFIG_FILE$3 = "vite.config.ts";
|
|
1155
|
+
const SEPARATOR$1 = "/";
|
|
1156
|
+
const FIRST$2 = 1;
|
|
1157
|
+
const READ_CONCURRENCY$5 = 8;
|
|
1158
|
+
const CrateEntry = Schema.Struct({
|
|
1159
|
+
name: Schema.String,
|
|
1160
|
+
manifest_path: Schema.String
|
|
1161
|
+
});
|
|
1162
|
+
const CrateList = Schema.fromJsonString(Schema.Struct({ packages: Schema.Array(CrateEntry) }));
|
|
1163
|
+
const decodeCrateList = Schema.decodeUnknownEffect(CrateList);
|
|
1164
|
+
const cratesIn = Effect.fn("cratesIn")(function* cratesIn(root) {
|
|
1165
|
+
const output = yield* (yield* ChildProcess.make("cargo", [
|
|
1166
|
+
"metadata",
|
|
1167
|
+
"--no-deps",
|
|
1168
|
+
"--format-version",
|
|
1169
|
+
"1",
|
|
1170
|
+
"--offline"
|
|
1171
|
+
], {
|
|
1172
|
+
cwd: root,
|
|
1173
|
+
extendEnv: true,
|
|
1174
|
+
stdin: "ignore"
|
|
1175
|
+
})).stdout.pipe(Stream.decodeText(), Stream.mkString);
|
|
1176
|
+
const list = yield* decodeCrateList(output);
|
|
1177
|
+
return pipe(list.packages, Array.map((crate) => ({
|
|
1178
|
+
name: crate.name,
|
|
1179
|
+
manifest: crate.manifest_path
|
|
1180
|
+
})));
|
|
1181
|
+
}, Effect.scoped);
|
|
1182
|
+
const owningWorkspace = (directories) => (directory) => {
|
|
1183
|
+
const owners = pipe(directories, Array.filter((workspace) => directory === workspace || String$1.startsWith(`${workspace}${SEPARATOR$1}`)(directory)));
|
|
1184
|
+
return Array.last(Array.sort(owners, String$1.Order));
|
|
1185
|
+
};
|
|
1186
|
+
const problemFor = (crate, message) => ({
|
|
1187
|
+
file: crate.manifest,
|
|
1188
|
+
line: FIRST$2,
|
|
1189
|
+
column: FIRST$2,
|
|
1190
|
+
rule: RULE$5,
|
|
1191
|
+
message: `crate ${crate.name} ${message}, so vp run verify never checks it.`
|
|
1192
|
+
});
|
|
1193
|
+
const problemIn$1 = Effect.fn("problemIn")(function* problemIn(root, directories, crate) {
|
|
1194
|
+
const files = yield* RepositoryFiles;
|
|
1195
|
+
const workspace = owningWorkspace(directories)(files.relative(root, files.dirname(crate.manifest)));
|
|
1196
|
+
if (Option.isNone(workspace)) return Option.some(problemFor(crate, "is outside every workspace package"));
|
|
1197
|
+
if (yield* hasVerifyTask(files.join(root, workspace.value, CONFIG_FILE$3))) return Option.none();
|
|
1198
|
+
return Option.some(problemFor(crate, `is in ${workspace.value}, whose ${CONFIG_FILE$3} has no verify task`));
|
|
1199
|
+
});
|
|
1200
|
+
/** @internal */
|
|
1201
|
+
const checkCrates = Effect.fn("checkCrates")(function* checkCrates(root) {
|
|
1202
|
+
const files = yield* RepositoryFiles;
|
|
1203
|
+
if (!(yield* files.exists(files.join(root, CARGO_FILE)))) return [];
|
|
1204
|
+
const directories = yield* workspaceDirectories(root);
|
|
1205
|
+
const crates = yield* cratesIn(root);
|
|
1206
|
+
const found = yield* Effect.forEach(crates, (crate) => problemIn$1(root, directories, crate), { concurrency: READ_CONCURRENCY$5 });
|
|
1207
|
+
return Array.getSomes(found);
|
|
1208
|
+
});
|
|
1209
|
+
// src/features/repository-layout/model/hidden-verify.ts
|
|
1210
|
+
const RULE$4 = "hidden-verify";
|
|
1211
|
+
const CONFIG_FILE$2 = "vite.config.ts";
|
|
1212
|
+
const FIRST$1 = 1;
|
|
1213
|
+
const READ_CONCURRENCY$4 = 8;
|
|
1214
|
+
const problemIn = Effect.fn("problemIn")(function* problemIn(root, directory) {
|
|
1215
|
+
const config = yield* workspaceConfigOf(root, directory);
|
|
1216
|
+
if (Option.isNone(config)) return Option.none();
|
|
1217
|
+
const { file, program } = config.value;
|
|
1218
|
+
if (definesTask(VERIFY_TASK)(program)) return Option.none();
|
|
1219
|
+
const verified = yield* hasVerifyTask(file);
|
|
1220
|
+
return Option.some({
|
|
1221
|
+
file,
|
|
1222
|
+
line: FIRST$1,
|
|
1223
|
+
column: FIRST$1,
|
|
1224
|
+
rule: RULE$4,
|
|
1225
|
+
message: `${directory} gets its verify task from code outside ${CONFIG_FILE$2}. The root verify reads ${CONFIG_FILE$2} without running it, so it never runs this verify. Write run.tasks.verify in ${directory}/${CONFIG_FILE$2}.`
|
|
1226
|
+
}).pipe(Option.filter(() => verified));
|
|
1227
|
+
});
|
|
1228
|
+
/** @internal */
|
|
1229
|
+
const checkHiddenVerify = Effect.fn("checkHiddenVerify")(function* checkHiddenVerify(root) {
|
|
1230
|
+
const directories = yield* workspaceDirectories(root);
|
|
1231
|
+
const found = yield* Effect.forEach(directories, (directory) => problemIn(root, directory), { concurrency: READ_CONCURRENCY$4 });
|
|
1232
|
+
return Array.getSomes(found);
|
|
1233
|
+
});
|
|
1234
|
+
// src/features/repository-layout/model/root-workspace-paths.ts
|
|
1235
|
+
const RULE$3 = "root-workspace-path";
|
|
1236
|
+
const CONFIG_FILE$1 = "vite.config.ts";
|
|
1237
|
+
const PATH_CHARACTER = /[\w.@/-]/u;
|
|
1238
|
+
const NAME_CHARACTER = /[\w.@-]/u;
|
|
1239
|
+
const FIRST = 0;
|
|
1240
|
+
const NEXT$2 = 1;
|
|
1241
|
+
const StringNode = Schema.Union([Schema.Struct({
|
|
1242
|
+
type: Schema.Literal("Literal"),
|
|
1243
|
+
value: Schema.String,
|
|
1244
|
+
start: Schema.Finite
|
|
1245
|
+
}), Schema.Struct({
|
|
1246
|
+
type: Schema.Literal("TemplateElement"),
|
|
1247
|
+
value: Schema.Struct({ cooked: Schema.String }),
|
|
1248
|
+
start: Schema.Finite
|
|
1249
|
+
})]);
|
|
1250
|
+
const decodeStringNode = Schema.decodeUnknownOption(StringNode);
|
|
1251
|
+
const textOf = (node) => {
|
|
1252
|
+
if (node.type === "Literal") return node.value;
|
|
1253
|
+
return node.value.cooked;
|
|
1254
|
+
};
|
|
1255
|
+
const stringsIn = (node) => {
|
|
1256
|
+
return [...pipe(decodeStringNode(node), Option.map((found) => ({
|
|
1257
|
+
text: textOf(found),
|
|
1258
|
+
start: found.start
|
|
1259
|
+
})), Option.toArray), ...pipe(childrenOf$3(node), Array.flatMap(stringsIn))];
|
|
1260
|
+
};
|
|
1261
|
+
const isBoundary = (character, allowed) => character === "" || !allowed.test(character);
|
|
1262
|
+
const mentions = (directory) => (text) => {
|
|
1263
|
+
const parts = String$1.split(text, directory);
|
|
1264
|
+
return pipe(Array.drop(parts, NEXT$2), Array.some((after, index) => {
|
|
1265
|
+
const before = parts[index] ?? "";
|
|
1266
|
+
const previous = String$1.slice(before.length - NEXT$2)(before);
|
|
1267
|
+
const following = String$1.slice(FIRST, NEXT$2)(after);
|
|
1268
|
+
return isBoundary(previous, PATH_CHARACTER) && (following === "/" || isBoundary(following, NAME_CHARACTER));
|
|
1269
|
+
}));
|
|
1270
|
+
};
|
|
1271
|
+
const problemsIn$1 = (file, source, directories) => (found) => pipe(directories, Array.filter((directory) => mentions(directory)(found.text)), Array.map((directory) => ({
|
|
1272
|
+
file,
|
|
1273
|
+
...positionOf(source)(found.start),
|
|
1274
|
+
rule: RULE$3,
|
|
1275
|
+
message: `${directory} is a workspace. The root ${CONFIG_FILE$1} holds what applies to every workspace, so move what only ${directory} needs into ${directory}/${CONFIG_FILE$1}: msch.lint, msch.devDependencies or its verify task.`
|
|
1276
|
+
})));
|
|
1277
|
+
/** @internal */
|
|
1278
|
+
const checkRootWorkspacePaths = Effect.fn("checkRootWorkspacePaths")(function* checkRootWorkspacePaths(root) {
|
|
1279
|
+
const files = yield* RepositoryFiles;
|
|
1280
|
+
const file = files.join(root, CONFIG_FILE$1);
|
|
1281
|
+
const source = yield* files.readFile(file);
|
|
1282
|
+
if (Option.isNone(source)) return [];
|
|
1283
|
+
const directories = yield* workspaceDirectories(root);
|
|
1284
|
+
const parsed = yield* Effect.promise(() => parse(file, source.value, { lang: "ts" }));
|
|
1285
|
+
return pipe(stringsIn(parsed.program), Array.flatMap(problemsIn$1(file, source.value, directories)));
|
|
1286
|
+
});
|
|
1287
|
+
// src/features/repository-layout/model/shared-uncached-tasks.ts
|
|
1288
|
+
const RULE$2 = "shared-uncached-task";
|
|
1289
|
+
const TASKS_PATH = ["run", "tasks"];
|
|
1290
|
+
const READ_CONCURRENCY$3 = 8;
|
|
1291
|
+
const SHARED = 2;
|
|
1292
|
+
const OWN_PROGRAM = /^(?:node|vpx|bun|deno|tsx)$|\//u;
|
|
1293
|
+
const TaskProperty = Schema.Struct({
|
|
1294
|
+
type: Schema.Literal("Property"),
|
|
1295
|
+
computed: Schema.Literal(false),
|
|
1296
|
+
key: KeySchema,
|
|
1297
|
+
value: Schema.Unknown,
|
|
1298
|
+
start: Schema.Finite
|
|
1299
|
+
});
|
|
1300
|
+
const TaskObject = Schema.Struct({
|
|
1301
|
+
type: Schema.Literal("ObjectExpression"),
|
|
1302
|
+
properties: Schema.Array(Schema.Unknown)
|
|
1303
|
+
});
|
|
1304
|
+
const UncachedTask = Schema.Struct({
|
|
1305
|
+
cache: Schema.Literal(false),
|
|
1306
|
+
command: Schema.Union([Schema.String, Schema.NonEmptyArray(Schema.String)])
|
|
1307
|
+
});
|
|
1308
|
+
const decodeTaskProperty = Schema.decodeUnknownOption(TaskProperty);
|
|
1309
|
+
const decodeTaskObject = Schema.decodeUnknownOption(TaskObject);
|
|
1310
|
+
const decodeUncachedTask = Schema.decodeUnknownOption(UncachedTask);
|
|
1311
|
+
const encodeDefinition = Schema.encodeOption(Schema.fromJsonString(Schema.Unknown));
|
|
1312
|
+
const commandText = (command) => Array.join(Array.ensure(command), " && ");
|
|
1313
|
+
const runsOwnProgram = (command) => pipe(String$1.trim(command), String$1.split(/\s+/u), Array.head, Option.exists((program) => OWN_PROGRAM.test(program)));
|
|
1314
|
+
const definitionOf = ({ directory, file, source }) => (task) => Option.gen(function* uncachedDefinition() {
|
|
1315
|
+
const literal = yield* literalOf(task.value);
|
|
1316
|
+
const { command } = yield* decodeUncachedTask(literal);
|
|
1317
|
+
const text = commandText(command);
|
|
1318
|
+
if (runsOwnProgram(text)) return yield* Option.none();
|
|
1319
|
+
const definition = yield* encodeDefinition(literal);
|
|
1320
|
+
return {
|
|
1321
|
+
directory,
|
|
1322
|
+
file,
|
|
1323
|
+
position: positionOf(source)(task.start),
|
|
1324
|
+
name: keyName(task.key),
|
|
1325
|
+
command: text,
|
|
1326
|
+
definition
|
|
1327
|
+
};
|
|
1328
|
+
});
|
|
1329
|
+
const definitionsIn = Effect.fn("definitionsIn")(function* definitionsIn(root, directory) {
|
|
1330
|
+
const config = yield* workspaceConfigOf(root, directory);
|
|
1331
|
+
if (Option.isNone(config)) return [];
|
|
1332
|
+
const { file, source, program } = config.value;
|
|
1333
|
+
return pipe(nestedValues(TASKS_PATH)(program), Array.flatMap((tasks) => pipe(decodeTaskObject(tasks), Option.map(({ properties }) => properties), Option.getOrElse(() => []))), Array.flatMap((property) => pipe(decodeTaskProperty(property), Option.flatMap(definitionOf({
|
|
1334
|
+
directory,
|
|
1335
|
+
file,
|
|
1336
|
+
source
|
|
1337
|
+
})), Option.toArray)));
|
|
1338
|
+
});
|
|
1339
|
+
const problemsOf = (definitions) => {
|
|
1340
|
+
const directories = pipe(definitions, Array.map(({ directory }) => directory), Array.dedupe);
|
|
1341
|
+
if (directories.length < SHARED) return [];
|
|
1342
|
+
return pipe(definitions, Array.map(({ file, position, name, command }) => ({
|
|
1343
|
+
file,
|
|
1344
|
+
...position,
|
|
1345
|
+
rule: RULE$2,
|
|
1346
|
+
message: `The uncached task ${name} (${command}) is written the same way in ${Array.join(directories, ", ")}. Write it once in a shared helper and spread it into each run.tasks, so that a change to it reaches every workspace.`
|
|
1347
|
+
})));
|
|
1348
|
+
};
|
|
1349
|
+
/** @internal */
|
|
1350
|
+
const checkSharedUncachedTasks = Effect.fn("checkSharedUncachedTasks")(function* checkSharedUncachedTasks(root) {
|
|
1351
|
+
const directories = yield* workspaceDirectories(root);
|
|
1352
|
+
const found = yield* Effect.forEach(directories, (directory) => definitionsIn(root, directory), { concurrency: READ_CONCURRENCY$3 });
|
|
1353
|
+
return pipe(Array.flatten(found), Array.groupBy(({ name, definition }) => `${name}\u0000${definition}`), Record.values, Array.flatMap(problemsOf));
|
|
1354
|
+
});
|
|
1355
|
+
// src/features/repository-layout/model/workspace-checks.ts
|
|
1356
|
+
/** @internal */
|
|
1357
|
+
const checkWorkspaces = Effect.fn("checkWorkspaces")(function* checkWorkspaces(root) {
|
|
1358
|
+
const found = yield* Effect.all([
|
|
1359
|
+
checkCrates(root),
|
|
1360
|
+
checkHiddenVerify(root),
|
|
1361
|
+
checkRootWorkspacePaths(root),
|
|
1362
|
+
checkSharedUncachedTasks(root)
|
|
1363
|
+
], { concurrency: "unbounded" });
|
|
1364
|
+
return Array.flatten(found);
|
|
1365
|
+
});
|
|
1366
|
+
// src/features/value-owners/model/slots.ts
|
|
1367
|
+
const ANNOTATED_KINDS = /* @__PURE__ */ new Set([
|
|
1368
|
+
SyntaxKind.Parameter,
|
|
1369
|
+
SyntaxKind.VariableDeclaration,
|
|
1370
|
+
SyntaxKind.PropertySignature,
|
|
1371
|
+
SyntaxKind.PropertyDeclaration
|
|
1372
|
+
]);
|
|
1373
|
+
const isAnnotated = (declaration) => ANNOTATED_KINDS.has(declaration.kind);
|
|
1374
|
+
const annotationOf = (declaration) => Option.liftPredicate(declaration, isAnnotated).pipe(Option.flatMap((annotated) => Option.fromUndefinedOr(annotated.type)));
|
|
1375
|
+
const argumentSlot = (checker) => (expression) => {
|
|
1376
|
+
const call = expression.parent;
|
|
1377
|
+
if (!isCallExpression(call) && !isNewExpression(call)) return Option.none();
|
|
1378
|
+
const { arguments: listed } = call;
|
|
1379
|
+
const index = (listed ?? []).indexOf(expression);
|
|
1380
|
+
return Option.fromUndefinedOr(checker.getResolvedSignature(call).declaration).pipe(Option.flatMap((handle) => Option.fromUndefinedOr(handle.resolve())), Option.filter(isSignatureDeclaration), Option.flatMap((declaration) => Array.get(declaration.parameters, index)));
|
|
1381
|
+
};
|
|
1382
|
+
const propertySlot = (checker) => (expression) => {
|
|
1383
|
+
const assignment = expression.parent;
|
|
1384
|
+
if (!isPropertyAssignment(assignment) || !isObjectLiteralExpression(assignment.parent)) return Option.none();
|
|
1385
|
+
return Option.fromUndefinedOr(checker.getContextualType(assignment.parent)).pipe(Option.flatMap((objectType) => Option.fromUndefinedOr(objectType.getProperty(assignment.name.getText()))), Option.flatMap((property) => Array.head(declarationsOf(property))));
|
|
1386
|
+
};
|
|
1387
|
+
const variableSlot = (expression) => {
|
|
1388
|
+
const declaration = expression.parent;
|
|
1389
|
+
if (!isVariableDeclaration(declaration) || declaration.initializer !== expression) return Option.none();
|
|
1390
|
+
return Option.some(declaration);
|
|
1391
|
+
};
|
|
1392
|
+
const slotOf = (checker) => (expression) => argumentSlot(checker)(expression).pipe(Option.orElse(() => propertySlot(checker)(expression)), Option.orElse(() => variableSlot(expression)));
|
|
1393
|
+
const contextSymbolsOf = (checker) => (expression) => {
|
|
1394
|
+
const alias = Option.fromUndefinedOr(checker.getContextualType(expression)).pipe(Option.flatMap((contextual) => Option.fromUndefinedOr(contextual.getAliasSymbol())));
|
|
1395
|
+
if (Option.isSome(alias)) return [alias.value];
|
|
1396
|
+
return slotOf(checker)(expression).pipe(Option.flatMap(annotationOf), Option.map((annotation) => referencedSymbols(checker)(annotation)), Option.getOrElse(() => []));
|
|
1397
|
+
};
|
|
1398
|
+
// src/features/value-owners/model/flows.ts
|
|
1399
|
+
const SCOPE_PREFIX = "@";
|
|
1400
|
+
const SCOPED_SEGMENTS = 2;
|
|
1401
|
+
const UNSCOPED_SEGMENTS = 1;
|
|
1402
|
+
const MODULE_PREFIX = /^".*?"\./u;
|
|
1403
|
+
const packageOf = (fileName) => {
|
|
1404
|
+
const afterModules = pipe(fileName, String$1.lastIndexOf(NODE_MODULES_SEGMENT), Option.match({
|
|
1405
|
+
onNone: () => fileName,
|
|
1406
|
+
onSome: (index) => String$1.slice(index + NODE_MODULES_SEGMENT.length)(fileName)
|
|
1407
|
+
}));
|
|
1408
|
+
const segments = String$1.split("/")(afterModules);
|
|
1409
|
+
if (String$1.startsWith(SCOPE_PREFIX)(afterModules)) return pipe(Array.take(segments, SCOPED_SEGMENTS), Array.join("/"));
|
|
1410
|
+
return pipe(Array.take(segments, UNSCOPED_SEGMENTS), Array.join("/"));
|
|
1411
|
+
};
|
|
1412
|
+
const externalDeclarationOf = (context) => (symbol) => Array.findFirst(declarationsOf(symbol), (declaration) => isExternalDeclaration(context.program)(declaration));
|
|
1413
|
+
const aliasTarget = (context) => (type) => Option.fromUndefinedOr(type.getAliasSymbol()).pipe(Option.flatMap((alias) => externalDeclarationOf(context)(alias).pipe(Option.map((declaration) => `${String$1.replace(MODULE_PREFIX, "")(context.checker.getFullyQualifiedName(alias))} from ${packageOf(declaration.getSourceFile().fileName)}`))));
|
|
1414
|
+
const isNamedContainer = (node) => isSignatureDeclaration(node) || isInterfaceDeclaration(node) || isClassDeclaration(node);
|
|
1415
|
+
const slotTarget = (context) => (expression) => slotOf(context.checker)(expression).pipe(Option.filter((slot) => isExternalDeclaration(context.program)(slot)), Option.filter((slot) => Option.isSome(vocabularyOf(context.checker)(context.checker.getTypeAtLocation(slot)))), Option.map((slot) => {
|
|
1416
|
+
const owner = Option.liftPredicate(slot.parent, isNamedContainer).pipe(Option.flatMap((container) => Option.fromUndefinedOr(getNameOfDeclaration(container))), Option.map((name) => ` of ${name.getText()}`), Option.getOrElse(() => ""));
|
|
1417
|
+
return `${Option.fromUndefinedOr(getNameOfDeclaration(slot)).pipe(Option.map((found) => found.getText()), Option.getOrElse(() => "value"))}${owner} from ${packageOf(slot.getSourceFile().fileName)}`;
|
|
1418
|
+
}));
|
|
1419
|
+
const libraryTargetOf = (context) => (expression, contextual) => aliasTarget(context)(contextual).pipe(Option.orElse(() => slotTarget(context)(expression)));
|
|
1420
|
+
const siteWithin = (context) => (node) => Array.findFirst(context.sites, (site) => contains(node)(site.node));
|
|
1421
|
+
const aliasSite = (context) => (type) => Option.fromUndefinedOr(type.getAliasSymbol()).pipe(Option.flatMap((alias) => Array.findFirst(declarationsOf(alias), isTypeAliasDeclaration)), Option.flatMap(siteWithin(context)));
|
|
1422
|
+
const annotationSite = (context) => (expression) => symbolAt(context.checker)(expression).pipe(Option.flatMap((symbol) => Option.fromUndefinedOr(symbol.valueDeclaration)), Option.flatMap((handle) => Option.fromUndefinedOr(handle.resolve())), Option.flatMap(annotationOf), Option.flatMap((annotation) => siteWithin(context)(annotation).pipe(Option.orElse(() => aliasSite(context)(context.checker.getTypeFromTypeNode(annotation))))));
|
|
1423
|
+
const siteBehind = (context) => (expression) => aliasSite(context)(context.checker.getTypeAtLocation(expression)).pipe(Option.orElse(() => annotationSite(context)(expression)));
|
|
1424
|
+
const isFlowSource = (node) => isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node);
|
|
1425
|
+
const flowOf = (context) => (expression) => Option.fromUndefinedOr(context.checker.getContextualType(expression)).pipe(Option.flatMap((contextual) => Option.all([vocabularyOf(context.checker)(contextual), libraryTargetOf(context)(expression, contextual)])), Option.flatMap(([vocabulary, target]) => siteBehind(context)(expression).pipe(Option.filter((site) => isSubsetOf(site.values, vocabulary.values)), Option.map((site) => ({
|
|
1426
|
+
site,
|
|
1427
|
+
target
|
|
1428
|
+
})))));
|
|
1429
|
+
const flowsIn = (context) => (sourceFile) => Array.getSomes(pipe(descendantsOf(sourceFile), Array.filter((node) => isFlowSource(node)), Array.map((node) => flowOf(context)(node))));
|
|
1430
|
+
// src/features/value-owners/model/owners.ts
|
|
1431
|
+
const OWNER_TAG = "msch";
|
|
1432
|
+
const FIRST_OWNER_COUNT = 1;
|
|
1433
|
+
const ownerKeyOf = (declaration) => {
|
|
1434
|
+
if (!isVariableDeclaration(declaration) || !isIdentifier(declaration.name)) return Option.none();
|
|
1435
|
+
return Option.some(`${declaration.getSourceFile().fileName}#${declaration.name.text}`);
|
|
1436
|
+
};
|
|
1437
|
+
const annotationsOf = (node) => pipe(getJSDocTags(node), Array.filter((tag) => tag.tagName.text === OWNER_TAG), Array.map((tag) => ({
|
|
1438
|
+
node,
|
|
1439
|
+
conceptId: String$1.trim(getTextOfJSDocComment(tag.comment) ?? "")
|
|
1440
|
+
})));
|
|
1441
|
+
const ANNOTATABLE_KINDS = /* @__PURE__ */ new Set([
|
|
1442
|
+
SyntaxKind.VariableDeclaration,
|
|
1443
|
+
SyntaxKind.FunctionDeclaration,
|
|
1444
|
+
SyntaxKind.ClassDeclaration,
|
|
1445
|
+
SyntaxKind.InterfaceDeclaration,
|
|
1446
|
+
SyntaxKind.TypeAliasDeclaration,
|
|
1447
|
+
SyntaxKind.EnumDeclaration,
|
|
1448
|
+
SyntaxKind.PropertySignature,
|
|
1449
|
+
SyntaxKind.PropertyAssignment,
|
|
1450
|
+
SyntaxKind.PropertyDeclaration
|
|
1451
|
+
]);
|
|
1452
|
+
const isAnnotatable = (node) => ANNOTATABLE_KINDS.has(node.kind);
|
|
1453
|
+
const isConstList = (list) => Option.fromUndefinedOr(list.getFirstToken()).pipe(Option.exists((token) => token.kind === SyntaxKind.ConstKeyword));
|
|
1454
|
+
const isModuleStatementList = (list) => isVariableStatement(list.parent) && isSourceFile(list.parent.parent);
|
|
1455
|
+
const isModuleConstList = (node) => isVariableDeclarationList(node) && isModuleStatementList(node) && isConstList(node);
|
|
1456
|
+
const isModuleConst = (node) => isVariableDeclaration(node) && isIdentifier(node.name) && isModuleConstList(node.parent);
|
|
1457
|
+
const objectValuesOf = (checker) => (type) => literalValuesOf(pipe(checker.getPropertiesOfType(type), Array.map((property) => checker.getTypeOfSymbol(property))));
|
|
1458
|
+
const ownerValuesOf = (checker) => (declaration) => {
|
|
1459
|
+
const type = checker.getTypeAtLocation(declaration.name);
|
|
1460
|
+
return finiteValuesOf(checker)(type).pipe(Option.orElse(() => objectValuesOf(checker)(type)));
|
|
1461
|
+
};
|
|
1462
|
+
const annotationProblem = (message) => problemAt({
|
|
1463
|
+
rule: "owner-annotation",
|
|
1464
|
+
message
|
|
1465
|
+
});
|
|
1466
|
+
const scanned = (owners, problems) => ({
|
|
1467
|
+
owners,
|
|
1468
|
+
problems
|
|
1469
|
+
});
|
|
1470
|
+
const ownerOf = (project) => (annotated) => {
|
|
1471
|
+
const { node, conceptId } = annotated;
|
|
1472
|
+
if (!isModuleConst(node)) return scanned([], [annotationProblem(`@${OWNER_TAG} registers an owner only on a module-scope const.`)(node)]);
|
|
1473
|
+
if (conceptId === "") return scanned([], [annotationProblem(`@${OWNER_TAG} needs a concept id.`)(node)]);
|
|
1474
|
+
const values = ownerValuesOf(project.checker)(node);
|
|
1475
|
+
return Option.match(Option.all([values, ownerKeyOf(node)]), {
|
|
1476
|
+
onNone: () => scanned([], [annotationProblem(`The owner of ${conceptId} holds no finite value set.`)(node)]),
|
|
1477
|
+
onSome: ([ownedValues, key]) => scanned([{
|
|
1478
|
+
conceptId,
|
|
1479
|
+
key,
|
|
1480
|
+
name: node.name.getText(),
|
|
1481
|
+
file: node.getSourceFile().fileName,
|
|
1482
|
+
line: lineOf(node),
|
|
1483
|
+
column: columnOf(node),
|
|
1484
|
+
packageName: project.packageName,
|
|
1485
|
+
values: ownedValues
|
|
1486
|
+
}], [])
|
|
1487
|
+
});
|
|
1488
|
+
};
|
|
1489
|
+
const annotatedIn = (sourceFile) => pipe(descendantsOf(sourceFile), Array.filter((node) => isAnnotatable(node)), Array.flatMap((node) => annotationsOf(node)));
|
|
1490
|
+
const ownerProblem = (message) => (owner) => ({
|
|
1491
|
+
file: owner.file,
|
|
1492
|
+
line: owner.line,
|
|
1493
|
+
column: owner.column,
|
|
1494
|
+
rule: "owner-annotation",
|
|
1495
|
+
message
|
|
1496
|
+
});
|
|
1497
|
+
const conflictProblems = (owners) => pipe(owners, Array.flatMap((owner, index) => {
|
|
1498
|
+
const earlier = Array.take(owners, index);
|
|
1499
|
+
const sameConcept = pipe(earlier, Array.filter((other) => other.conceptId === owner.conceptId));
|
|
1500
|
+
const sameSet = pipe(earlier, Array.filter((other) => other.conceptId !== owner.conceptId && sameValues(other.values, owner.values)));
|
|
1501
|
+
return [...pipe(Array.take(sameConcept, FIRST_OWNER_COUNT), Array.map(() => ownerProblem(`The concept ${owner.conceptId} already has an owner.`)(owner))), ...pipe(Array.take(sameSet, FIRST_OWNER_COUNT), Array.map((other) => ownerProblem(`The values ${formatValues(owner.values)} are already owned by ${other.conceptId}.`)(owner)))];
|
|
1502
|
+
}));
|
|
1503
|
+
const ownersIn = (project) => {
|
|
1504
|
+
const results = pipe(project.sourceFiles, Array.flatMap((sourceFile) => pipe(annotatedIn(sourceFile), Array.map((annotated) => ownerOf(project)(annotated)))));
|
|
1505
|
+
return scanned(pipe(results, Array.flatMap((result) => result.owners)), pipe(results, Array.flatMap((result) => result.problems)));
|
|
1506
|
+
};
|
|
1507
|
+
const combineOwnerScans = (scans) => {
|
|
1508
|
+
const owners = Array.dedupeWith(pipe(scans, Array.flatMap((scan) => scan.owners)), (left, right) => left.key === right.key);
|
|
1509
|
+
return {
|
|
1510
|
+
owners,
|
|
1511
|
+
problems: [...pipe(scans, Array.flatMap((scan) => scan.problems)), ...conflictProblems(owners)]
|
|
1512
|
+
};
|
|
1513
|
+
};
|
|
1514
|
+
// src/features/value-owners/model/derivation.ts
|
|
1515
|
+
const contractOf = (node) => {
|
|
1516
|
+
const { parent } = node;
|
|
1517
|
+
if (isSatisfiesExpression(parent) && parent.expression === node) return [parent.type];
|
|
1518
|
+
if (isVariableDeclaration(parent) && parent.initializer === node) return Option.toArray(Option.fromUndefinedOr(parent.type));
|
|
1519
|
+
return [];
|
|
1520
|
+
};
|
|
1521
|
+
const derivedDeclarationsOf = (checker) => (node) => {
|
|
1522
|
+
const scopes = Array.prepend(contractOf(node), node);
|
|
1523
|
+
return new Set(pipe(scopes, Array.flatMap((scope) => referencedSymbols(checker)(scope)), Array.flatMap((symbol) => declarationsOf(symbol)), Array.map((declaration) => declarationKey(locationOf(declaration)))));
|
|
1524
|
+
};
|
|
1525
|
+
// src/features/value-owners/model/shapes.ts
|
|
1526
|
+
const MINIMUM_SHAPE_PROPERTIES = 3;
|
|
1527
|
+
const EXACT = 0;
|
|
1528
|
+
const augmentsAModule = (node) => {
|
|
1529
|
+
const block = node.parent;
|
|
1530
|
+
return isModuleBlock(block) && isModuleDeclaration(block.parent) && isStringLiteral(block.parent.name);
|
|
1531
|
+
};
|
|
1532
|
+
const isPlainInterface = (node) => isInterfaceDeclaration(node) && !isGenericDeclaration(node) && !augmentsAModule(node);
|
|
1533
|
+
const isPlainTypeLiteral = (node) => isTypeAliasDeclaration(node) && !isGenericDeclaration(node) && isTypeLiteralNode(node.type);
|
|
1534
|
+
const isDeclaredShape = (node) => isPlainInterface(node) || isPlainTypeLiteral(node);
|
|
1535
|
+
const declaredShapeOf = (checker) => (node) => Option.liftPredicate(node, isDeclaredShape).pipe(Option.map((declaration) => checker.getTypeAtLocation(declaration.name)));
|
|
1536
|
+
const schemaShapeOf = (checker) => (node) => {
|
|
1537
|
+
if (!isCallExpression(node)) return Option.none();
|
|
1538
|
+
const { arguments: callArguments } = node;
|
|
1539
|
+
if (!pipe(callArguments, Array.some((argument) => isObjectLiteralExpression(argument)))) return Option.none();
|
|
1540
|
+
return schemaTypeOf(checker)(checker.getTypeAtLocation(node)).pipe(Option.filter((type) => isObjectType(checker)(type)));
|
|
1541
|
+
};
|
|
1542
|
+
const shapeSitesIn = (checker) => (sourceFile) => Array.getSomes(pipe(descendantsOf(sourceFile), Array.map((node) => declaredShapeOf(checker)(node).pipe(Option.orElse(() => schemaShapeOf(checker)(node)), Option.map((type) => ({
|
|
1543
|
+
node,
|
|
1544
|
+
type
|
|
1545
|
+
}))))));
|
|
1546
|
+
const openTypeIdsOf = (checker) => ({
|
|
1547
|
+
any: checker.getAnyType().id,
|
|
1548
|
+
unknown: checker.getUnknownType().id
|
|
1549
|
+
});
|
|
1550
|
+
const isIndexedDeclaration = (node) => isTypeDeclaration(node) || isVariableDeclaration(node);
|
|
1551
|
+
const declarationAt = (program) => (location) => Option.fromUndefinedOr(program.getSourceFile(location.file)).pipe(Option.flatMap((sourceFile) => Array.findFirst(descendantsOf(sourceFile), (node) => node.pos === location.pos && node.kind === location.kind && isIndexedDeclaration(node))));
|
|
1552
|
+
const symbolOfDeclaration = (checker) => (declaration) => Option.fromUndefinedOr(checker.getSymbolAtLocation(declaration.name));
|
|
1553
|
+
const shapeTypeOf = (context) => (shape) => {
|
|
1554
|
+
const { checker } = context;
|
|
1555
|
+
return declarationAt(context.program)(shape.declaration).pipe(Option.flatMap((declaration) => symbolOfDeclaration(checker)(declaration).pipe(Option.flatMap((symbol) => {
|
|
1556
|
+
if (shape.form === "declared") return Option.some(checker.getDeclaredTypeOfSymbol(symbol));
|
|
1557
|
+
return schemaTypeOf(checker)(checker.getTypeOfSymbolAtLocation(symbol, declaration));
|
|
1558
|
+
}))));
|
|
1559
|
+
};
|
|
1560
|
+
const hasEveryName = (locals) => (shape) => {
|
|
1561
|
+
const names = new Set(shape.propertyNames);
|
|
1562
|
+
return pipe(locals, Array.every((local) => names.has(local.name)));
|
|
1563
|
+
};
|
|
1564
|
+
const sameProperty = (checker, open) => (localType, library) => {
|
|
1565
|
+
const libraryType = checker.getTypeOfSymbol(library);
|
|
1566
|
+
return libraryType.id !== open.any && libraryType.id !== open.unknown && checker.isTypeAssignableTo(localType, libraryType) && checker.isTypeAssignableTo(libraryType, localType);
|
|
1567
|
+
};
|
|
1568
|
+
const matchOf = (context, open) => (locals, shape) => {
|
|
1569
|
+
const { checker } = context;
|
|
1570
|
+
if (!shapeTypeOf(context)(shape).pipe(Option.exists((shapeType) => pipe(locals, Array.every((local) => Option.fromUndefinedOr(checker.getPropertyOfType(shapeType, local.name)).pipe(Option.exists((library) => sameProperty(checker, open)(local.type, library)))))))) return Option.none();
|
|
1571
|
+
return Option.some({
|
|
1572
|
+
shape,
|
|
1573
|
+
extra: shape.propertyNames.length - locals.length
|
|
1574
|
+
});
|
|
1575
|
+
};
|
|
1576
|
+
const localPropertiesOf = (checker) => (symbols) => pipe(Array.zip(symbols, checker.getTypeOfSymbol(symbols)), Array.map(([symbol, type]) => ({
|
|
1577
|
+
name: symbol.name,
|
|
1578
|
+
type
|
|
1579
|
+
})));
|
|
1580
|
+
const matchOrder = Order.mapInput(Order.Number, (match) => match.extra);
|
|
1581
|
+
const shapeProblem = (site, matches) => {
|
|
1582
|
+
const shown = pipe(Array.take(matches, 3), Array.map((match) => describeLibraryType(match.shape)), Array.join(", "));
|
|
1583
|
+
const advice = Option.match(Array.findFirst(matches, (match) => match.extra === EXACT), {
|
|
1584
|
+
onNone: () => "Derive it from the library type, for example with Pick, instead of copying its properties.",
|
|
1585
|
+
onSome: () => "Use the library type instead of copying it."
|
|
1586
|
+
});
|
|
1587
|
+
return problemAt({
|
|
1588
|
+
rule: "library-shape",
|
|
1589
|
+
message: `This shape copies ${shown}. ${advice}`
|
|
1590
|
+
})(site.node);
|
|
1591
|
+
};
|
|
1592
|
+
const candidatesOf = (context, open) => (site, locals) => {
|
|
1593
|
+
const derived = derivedDeclarationsOf(context.checker)(site.node);
|
|
1594
|
+
const named = pipe(context.shapes, Array.filter(hasEveryName(locals)));
|
|
1595
|
+
if (pipe(named, Array.some((shape) => derived.has(declarationKey(shape.declaration))))) return [];
|
|
1596
|
+
const candidates = pipe(named, Array.map((shape) => matchOf(context, open)(locals, shape)), Array.getSomes);
|
|
1597
|
+
return Array.sort(candidates, matchOrder);
|
|
1598
|
+
};
|
|
1599
|
+
const shapeProblemOf = (context, open) => (site) => {
|
|
1600
|
+
const symbols = context.checker.getPropertiesOfType(site.type);
|
|
1601
|
+
if (symbols.length < MINIMUM_SHAPE_PROPERTIES) return Option.none();
|
|
1602
|
+
const locals = localPropertiesOf(context.checker)(symbols);
|
|
1603
|
+
return Option.liftPredicate(candidatesOf(context, open)(site, locals), Array.isReadonlyArrayNonEmpty).pipe(Option.map((found) => shapeProblem(site, found)));
|
|
1604
|
+
};
|
|
1605
|
+
const shapeProblemsIn = (context) => (sourceFile) => {
|
|
1606
|
+
const sites = shapeSitesIn(context.checker)(sourceFile);
|
|
1607
|
+
if (!Array.isReadonlyArrayNonEmpty(sites)) return [];
|
|
1608
|
+
const open = openTypeIdsOf(context.checker);
|
|
1609
|
+
return Array.getSomes(pipe(sites, Array.map((site) => shapeProblemOf(context, open)(site))));
|
|
1610
|
+
};
|
|
1611
|
+
// src/features/value-owners/model/sites.ts
|
|
1612
|
+
const namedValuesOf = (checker) => (symbol) => {
|
|
1613
|
+
if (pipe(declarationsOf(symbol), Array.some((declaration) => isTypeDeclaration(declaration)))) return finiteValuesOf(checker)(checker.getDeclaredTypeOfSymbol(symbol));
|
|
1614
|
+
return finiteValuesOf(checker)(checker.getTypeOfSymbol(symbol));
|
|
1615
|
+
};
|
|
1616
|
+
const hasFiniteContext = (checker) => (node) => Option.fromUndefinedOr(checker.getContextualType(node)).pipe(Option.flatMap(finiteValuesOf(checker)), Option.isSome);
|
|
1617
|
+
const isNamedValue = (element) => {
|
|
1618
|
+
if (isSpreadElement(element)) return isNamedValue(element.expression);
|
|
1619
|
+
return isIdentifier(element) || isPropertyAccessExpression(element) || isElementAccessExpression(element);
|
|
1620
|
+
};
|
|
1621
|
+
const namesEveryElement = (array) => pipe(array.elements, Array.every((element) => isNamedValue(element)));
|
|
1622
|
+
const expressionValuesOf = (checker) => (node) => {
|
|
1623
|
+
if (hasFiniteContext(checker)(node)) return Option.none();
|
|
1624
|
+
const type = checker.getTypeAtLocation(node);
|
|
1625
|
+
if (isArrayLiteralExpression(node)) return Option.liftPredicate(node, (array) => !namesEveryElement(array)).pipe(Option.flatMap(() => finiteValuesOf(checker)(type)));
|
|
1626
|
+
return schemaTypeOf(checker)(type).pipe(Option.flatMap(literalUnionOf));
|
|
1627
|
+
};
|
|
1628
|
+
const selectsKeys = (checker) => (node, values) => {
|
|
1629
|
+
const { parent } = node;
|
|
1630
|
+
if (!isTypeReferenceNode(parent)) return false;
|
|
1631
|
+
const typeArguments = parent.typeArguments ?? [];
|
|
1632
|
+
return pipe(typeArguments, Array.filter((argument) => argument !== node), Array.some((argument) => isSubsetOf(values, propertyNamesOf(checker)(checker.getTypeFromTypeNode(argument)))));
|
|
1633
|
+
};
|
|
1634
|
+
const unionValuesOf = (checker) => (node) => literalUnionOf(checker.getTypeFromTypeNode(node)).pipe(Option.filter((values) => !selectsKeys(checker)(node, values)));
|
|
1635
|
+
const isExpressionSite = (node) => isArrayLiteralExpression(node) || isCallExpression(node);
|
|
1636
|
+
const expressionSiteValuesOf = (checker) => (node) => Option.liftPredicate(node, isExpressionSite).pipe(Option.flatMap(expressionValuesOf(checker)));
|
|
1637
|
+
const siteValuesOf = (checker) => (node) => {
|
|
1638
|
+
if (isUnionTypeNode(node)) return unionValuesOf(checker)(node);
|
|
1639
|
+
if (isEnumDeclaration(node)) return literalUnionOf(checker.getTypeAtLocation(node.name));
|
|
1640
|
+
return expressionSiteValuesOf(checker)(node);
|
|
1641
|
+
};
|
|
1642
|
+
const derivationScopeOf = (node) => {
|
|
1643
|
+
if (isTypeReferenceNode(node.parent)) return node.parent;
|
|
1644
|
+
return node;
|
|
1645
|
+
};
|
|
1646
|
+
const sourcesOf = (checker) => (node) => pipe(referencedSymbols(checker)(derivationScopeOf(node)), Array.filter((symbol) => Option.isSome(namedValuesOf(checker)(symbol))));
|
|
1647
|
+
const sitesUnder = (checker) => (node) => {
|
|
1648
|
+
const nested = pipe(childrenOf$2(node), Array.flatMap((child) => sitesUnder(checker)(child)));
|
|
1649
|
+
if (Array.isReadonlyArrayNonEmpty(nested)) return nested;
|
|
1650
|
+
return siteValuesOf(checker)(node).pipe(Option.map((values) => ({
|
|
1651
|
+
node,
|
|
1652
|
+
values,
|
|
1653
|
+
sources: sourcesOf(checker)(node)
|
|
1654
|
+
})), Option.toArray);
|
|
1655
|
+
};
|
|
1656
|
+
// src/features/value-owners/model/value-checks.ts
|
|
1657
|
+
const OWNER_SEARCH_DEPTH = 4;
|
|
1658
|
+
const NOTHING_HIDDEN = 0;
|
|
1659
|
+
const directOwners = (context) => (symbol) => {
|
|
1660
|
+
const keys = Array.getSomes(pipe(declarationsOf(symbol), Array.map((declaration) => ownerKeyOf(declaration))));
|
|
1661
|
+
return pipe(context.owners, Array.filter((owner) => keys.includes(owner.key)));
|
|
1662
|
+
};
|
|
1663
|
+
const isFollowable = (declaration) => !declaration.getSourceFile().isDeclarationFile && (isTypeAliasDeclaration(declaration) || isVariableDeclaration(declaration));
|
|
1664
|
+
const ownersBehind = (context) => (symbol, ancestors) => {
|
|
1665
|
+
const direct = directOwners(context)(symbol);
|
|
1666
|
+
if (Array.isReadonlyArrayNonEmpty(direct) || ancestors.length >= OWNER_SEARCH_DEPTH) return direct;
|
|
1667
|
+
const visited = [...ancestors, symbol];
|
|
1668
|
+
return uniqueByReference(pipe(declarationsOf(symbol), Array.filter((declaration) => isFollowable(declaration)), Array.flatMap((declaration) => referencedSymbols(context.checker)(declaration)), Array.filter((referenced) => !visited.includes(referenced)), Array.flatMap((referenced) => ownersBehind(context)(referenced, visited))));
|
|
1669
|
+
};
|
|
1670
|
+
const describeOwners = (owners) => pipe(owners, Array.map((owner) => `${owner.conceptId} (${owner.name})`), Array.join(", "));
|
|
1671
|
+
const verdict = (problems, unowned) => ({
|
|
1672
|
+
problems,
|
|
1673
|
+
unowned
|
|
1674
|
+
});
|
|
1675
|
+
const derivedVerdict = (context) => (site) => {
|
|
1676
|
+
const owners = uniqueByReference(pipe(site.sources, Array.flatMap((source) => ownersBehind(context)(source, []))));
|
|
1677
|
+
const held = pipe(owners, Array.flatMap((owner) => owner.values));
|
|
1678
|
+
const added = pipe(site.values, Array.filter((value) => !isSubsetOf([value], held)));
|
|
1679
|
+
if (!Array.isReadonlyArrayNonEmpty(owners) || !Array.isReadonlyArrayNonEmpty(added)) return verdict([], []);
|
|
1680
|
+
const message = `This set adds ${formatValues(added)} to ${describeOwners(owners)}. Add the values to the owner, or register the wider set as its own concept.`;
|
|
1681
|
+
return verdict([problemAt({
|
|
1682
|
+
rule: "owner-extension",
|
|
1683
|
+
message
|
|
1684
|
+
})(site.node)], []);
|
|
1685
|
+
};
|
|
1686
|
+
const libraryCandidates = (context) => (site) => {
|
|
1687
|
+
const flowing = Array.dedupe(pipe(context.flows, Array.filter((flow) => flow.site.node === site.node), Array.map((flow) => flow.target)));
|
|
1688
|
+
if (Array.isReadonlyArrayNonEmpty(flowing)) return flowing;
|
|
1689
|
+
if (!pipe(site.values, Array.some((value) => typeof value === "string"))) return [];
|
|
1690
|
+
const imported = importedModulesOf(site.node.getSourceFile());
|
|
1691
|
+
return Array.dedupe(pipe(context.vocabularies, Array.filter((library) => imported.includes(library.specifier)), Array.filter((library) => isSubsetOf(site.values, library.vocabulary.values)), Array.map((library) => describeLibraryType(library))));
|
|
1692
|
+
};
|
|
1693
|
+
const listCandidates = (candidates) => {
|
|
1694
|
+
const shown = pipe(Array.take(candidates, 3), Array.join(", "));
|
|
1695
|
+
const hidden = candidates.length - 3;
|
|
1696
|
+
if (hidden > NOTHING_HIDDEN) return `${shown} and ${String(hidden)} more`;
|
|
1697
|
+
return shown;
|
|
1698
|
+
};
|
|
1699
|
+
const originalVerdict = (context) => (site) => {
|
|
1700
|
+
const owners = pipe(context.owners, Array.filter((owner) => isSubsetOf(site.values, owner.values)));
|
|
1701
|
+
if (Array.isReadonlyArrayNonEmpty(owners)) {
|
|
1702
|
+
const message = `The values ${formatValues(site.values)} are owned by ${describeOwners(owners)}. Derive this set from the owner instead of restating it.`;
|
|
1703
|
+
return verdict([problemAt({
|
|
1704
|
+
rule: "owner-value-set",
|
|
1705
|
+
message
|
|
1706
|
+
})(site.node)], []);
|
|
1707
|
+
}
|
|
1708
|
+
const candidates = libraryCandidates(context)(site);
|
|
1709
|
+
if (Array.isReadonlyArrayNonEmpty(candidates)) {
|
|
1710
|
+
const message = `The values ${formatValues(site.values)} restate a dependency type: ${listCandidates(candidates)}. Derive this set from the library type.`;
|
|
1711
|
+
return verdict([problemAt({
|
|
1712
|
+
rule: "library-value-set",
|
|
1713
|
+
message
|
|
1714
|
+
})(site.node)], []);
|
|
1715
|
+
}
|
|
1716
|
+
return verdict([], [site]);
|
|
1717
|
+
};
|
|
1718
|
+
const siteVerdict = (context) => (site) => {
|
|
1719
|
+
if (Array.isReadonlyArrayNonEmpty(site.sources)) return derivedVerdict(context)(site);
|
|
1720
|
+
return originalVerdict(context)(site);
|
|
1721
|
+
};
|
|
1722
|
+
const VALUE_PARENT_KINDS = /* @__PURE__ */ new Set([
|
|
1723
|
+
SyntaxKind.ReturnStatement,
|
|
1724
|
+
SyntaxKind.ArrayLiteralExpression,
|
|
1725
|
+
SyntaxKind.ConditionalExpression,
|
|
1726
|
+
SyntaxKind.ParenthesizedExpression,
|
|
1727
|
+
SyntaxKind.ArrowFunction,
|
|
1728
|
+
SyntaxKind.JsxExpression
|
|
1729
|
+
]);
|
|
1730
|
+
const isCallArgument = (node, parent) => (isCallExpression(parent) || isNewExpression(parent)) && parent.expression !== node;
|
|
1731
|
+
const isInitializer = (node, parent) => (isPropertyAssignment(parent) || isVariableDeclaration(parent)) && parent.initializer === node;
|
|
1732
|
+
const isRightOperand = (node, parent) => isBinaryExpression(parent) && parent.right === node;
|
|
1733
|
+
const VALUE_SLOTS = [
|
|
1734
|
+
isCallArgument,
|
|
1735
|
+
isInitializer,
|
|
1736
|
+
isRightOperand
|
|
1737
|
+
];
|
|
1738
|
+
const isValuePosition = (node) => {
|
|
1739
|
+
const { parent } = node;
|
|
1740
|
+
return VALUE_PARENT_KINDS.has(parent.kind) || pipe(VALUE_SLOTS, Array.some((isSlot) => isSlot(node, parent)));
|
|
1741
|
+
};
|
|
1742
|
+
const ownedLiteralProblem = (context) => (literal) => Option.fromUndefinedOr(context.checker.getContextualType(literal)).pipe(Option.filter((contextual) => vocabularyOf(context.checker)(contextual).pipe(Option.exists((vocabulary) => !vocabulary.admitsUnnamedValues))), Option.map(() => pipe(contextSymbolsOf(context.checker)(literal), Array.flatMap((symbol) => ownersBehind(context)(symbol, [])), uniqueByReference, Array.filter((owner) => isSubsetOf([literal.text], pipe(owner.values, Array.map(String)))))), Option.filter((owners) => Array.isReadonlyArrayNonEmpty(owners)), Option.map((owners) => problemAt({
|
|
1743
|
+
rule: "owned-literal",
|
|
1744
|
+
message: `${literal.getText()} is a value of ${describeOwners(owners)}. Write it through the owner's binding instead of as a literal.`
|
|
1745
|
+
})(literal)));
|
|
1746
|
+
const ownedLiteralProblems = (context) => (sourceFile, excluded) => Array.getSomes(pipe(descendantsOf(sourceFile), Array.filter((node) => isStringLiteral(node) || isNumericLiteral(node)), Array.filter((node) => isValuePosition(node)), Array.filter((node) => !pipe(excluded, Array.some((outer) => contains(outer)(node)))), Array.map((node) => ownedLiteralProblem(context)(node))));
|
|
1747
|
+
// src/features/value-owners/model/analysis.ts
|
|
1748
|
+
const isVisibleTo = (project) => (owner) => pipe(project.sourceFiles, Array.some((sourceFile) => sourceFile.fileName === owner.file)) || Option.exists(owner.packageName, (name) => Option.contains(project.packageName, name) || project.workspaceDependencies.includes(name));
|
|
1749
|
+
const ownerDeclarationsIn = (project, owners) => {
|
|
1750
|
+
const keys = new Set(pipe(owners, Array.map((owner) => owner.key)));
|
|
1751
|
+
return pipe(project.sourceFiles, Array.flatMap((sourceFile) => pipe(descendantsOf(sourceFile), Array.filter((node) => isVariableDeclaration(node)), Array.filter((declaration) => Option.exists(ownerKeyOf(declaration), (key) => keys.has(key))))));
|
|
1752
|
+
};
|
|
1753
|
+
const isInside = (outers) => (node) => pipe(outers, Array.some((outer) => contains(outer)(node)));
|
|
1754
|
+
const sitesOutside = (checker) => (project, outers) => pipe(project.sourceFiles, Array.flatMap((sourceFile) => sitesUnder(checker)(sourceFile)), Array.filter((site) => !isInside(outers)(site.node)));
|
|
1755
|
+
const nodesOf = (sites) => pipe(sites, Array.map((site) => site.node));
|
|
1756
|
+
const analyzeProject = (owners) => (project) => {
|
|
1757
|
+
const { checker } = project;
|
|
1758
|
+
const ownerDeclarations = ownerDeclarationsIn(project, owners);
|
|
1759
|
+
const sites = sitesOutside(checker)(project, ownerDeclarations);
|
|
1760
|
+
const flowContext = {
|
|
1761
|
+
checker,
|
|
1762
|
+
program: project.program,
|
|
1763
|
+
sites
|
|
1764
|
+
};
|
|
1765
|
+
const context = {
|
|
1766
|
+
checker,
|
|
1767
|
+
owners: pipe(owners, Array.filter((owner) => isVisibleTo(project)(owner))),
|
|
1768
|
+
vocabularies: project.library.vocabularies,
|
|
1769
|
+
flows: pipe(project.sourceFiles, Array.flatMap((sourceFile) => flowsIn(flowContext)(sourceFile)))
|
|
1770
|
+
};
|
|
1771
|
+
const verdicts = pipe(sites, Array.map((site) => siteVerdict(context)(site)));
|
|
1772
|
+
const excluded = [...ownerDeclarations, ...nodesOf(sites)];
|
|
1773
|
+
const shapeContext = {
|
|
1774
|
+
checker,
|
|
1775
|
+
program: project.program,
|
|
1776
|
+
shapes: project.library.shapes
|
|
1777
|
+
};
|
|
1778
|
+
return {
|
|
1779
|
+
problems: [...pipe(verdicts, Array.flatMap((found) => found.problems)), ...pipe(project.sourceFiles, Array.flatMap((sourceFile) => [...ownedLiteralProblems(context)(sourceFile, excluded), ...shapeProblemsIn(shapeContext)(sourceFile)]))],
|
|
1780
|
+
unowned: pipe(verdicts, Array.flatMap((found) => found.unowned))
|
|
1781
|
+
};
|
|
1782
|
+
};
|
|
1783
|
+
// src/features/value-owners/model/duplicates.ts
|
|
1784
|
+
const DUPLICATE_THRESHOLD = 1;
|
|
1785
|
+
const unownedSiteOf = (scope) => (site) => ({
|
|
1786
|
+
scope,
|
|
1787
|
+
file: site.node.getSourceFile().fileName,
|
|
1788
|
+
start: site.node.getStart(),
|
|
1789
|
+
line: lineOf(site.node),
|
|
1790
|
+
column: columnOf(site.node),
|
|
1791
|
+
values: site.values
|
|
1792
|
+
});
|
|
1793
|
+
const canDerive = (left, right) => left.scope.name === right.scope.name || left.scope.dependencies.includes(right.scope.name) || right.scope.dependencies.includes(left.scope.name);
|
|
1794
|
+
const siteKey = (site) => `${site.file}#${String(site.start)}`;
|
|
1795
|
+
const valueSetKey = (site) => {
|
|
1796
|
+
const keys = pipe(site.values, Array.map((value) => valueKey(value)));
|
|
1797
|
+
return pipe(Array.sort(keys, Order.String), Array.join("\0"));
|
|
1798
|
+
};
|
|
1799
|
+
const duplicateProblems = (relative) => (sites) => {
|
|
1800
|
+
const unique = Array.dedupeWith(sites, (left, right) => siteKey(left) === siteKey(right));
|
|
1801
|
+
const groups = Record.values(Array.groupBy(unique, (site) => valueSetKey(site)));
|
|
1802
|
+
return pipe(groups, Array.filter((group) => group.length > DUPLICATE_THRESHOLD), Array.flatMap((group) => pipe(group, Array.flatMap((site) => {
|
|
1803
|
+
const related = pipe(group, Array.filter((other) => other !== site && canDerive(site, other)));
|
|
1804
|
+
if (!Array.isReadonlyArrayNonEmpty(related)) return [];
|
|
1805
|
+
const others = pipe(related, Array.map((other) => `${relative(other.file)}:${String(other.line)}`), Array.join(", "));
|
|
1806
|
+
return [{
|
|
1807
|
+
file: site.file,
|
|
1808
|
+
line: site.line,
|
|
1809
|
+
column: site.column,
|
|
1810
|
+
rule: "duplicate-value-set",
|
|
1811
|
+
message: `The values ${formatValues(site.values)} are also declared at ${others}. Register one owner with /** @${OWNER_TAG} <concept> */ and derive the others from it.`
|
|
1812
|
+
}];
|
|
1813
|
+
}))));
|
|
1814
|
+
};
|
|
1815
|
+
// src/features/value-owners/model/check.ts
|
|
1816
|
+
const scanOwners = Effect.fn("scanOwners")(function* scanOwners(workspace, configPaths) {
|
|
1817
|
+
const ownerConfigs = yield* pipe(configPaths, Effect.filter(mentions$1(`@${OWNER_TAG}`)(workspace.compiler)));
|
|
1818
|
+
const scans = yield* pipe(ownerConfigs, Effect.forEach((configPath) => withProject(workspace)(configPath)((project) => Effect.sync(() => ownersIn(project)))));
|
|
1819
|
+
return combineOwnerScans(Array.getSomes(scans));
|
|
1625
1820
|
});
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
const found = yield* Effect.all([
|
|
1630
|
-
checkNestedDocs(root),
|
|
1631
|
-
checkRootReadme(root),
|
|
1632
|
-
checkColocatedTests(root)
|
|
1633
|
-
], { concurrency: "unbounded" });
|
|
1634
|
-
return Array.flatten(found);
|
|
1821
|
+
const scopeOf = (project, configPath) => ({
|
|
1822
|
+
name: Option.getOrElse(project.packageName, () => configPath),
|
|
1823
|
+
dependencies: project.workspaceDependencies
|
|
1635
1824
|
});
|
|
1636
|
-
|
|
1825
|
+
const analyzeProjects = (workspace, owners) => (configPaths) => pipe(configPaths, Effect.forEach((configPath) => withProject(workspace)(configPath)((project) => Effect.sync(() => {
|
|
1826
|
+
const analysis = analyzeProject(owners)(project);
|
|
1827
|
+
const scope = scopeOf(project, configPath);
|
|
1828
|
+
return {
|
|
1829
|
+
problems: analysis.problems,
|
|
1830
|
+
unowned: pipe(analysis.unowned, Array.map(unownedSiteOf(scope)))
|
|
1831
|
+
};
|
|
1832
|
+
}).pipe(Effect.withSpan("analyzeProject")))), Effect.map(Array.getSomes));
|
|
1833
|
+
const checkRepository = Effect.fn("checkRepository")(function* checkRepository(root) {
|
|
1834
|
+
const files = yield* RepositoryFiles;
|
|
1835
|
+
const workspace = {
|
|
1836
|
+
compiler: yield* typeScriptCompiler,
|
|
1837
|
+
root,
|
|
1838
|
+
generated: yield* files.generatedFiles(root)
|
|
1839
|
+
};
|
|
1840
|
+
const configPaths = yield* listConfigFiles(root);
|
|
1841
|
+
const ownerScan = yield* scanOwners(workspace, configPaths);
|
|
1842
|
+
const analyses = yield* analyzeProjects(workspace, ownerScan.owners)(configPaths);
|
|
1843
|
+
const relative = (file) => files.relative(root, file);
|
|
1844
|
+
const unowned = pipe(analyses, Array.flatMap((analysis) => analysis.unowned));
|
|
1845
|
+
return sortProblems([
|
|
1846
|
+
...ownerScan.problems,
|
|
1847
|
+
...pipe(analyses, Array.flatMap((analysis) => analysis.problems)),
|
|
1848
|
+
...duplicateProblems(relative)(unowned)
|
|
1849
|
+
]);
|
|
1850
|
+
}, Effect.scoped);
|
|
1851
|
+
// src/features/comments/model/found-comment.ts
|
|
1637
1852
|
const taggedError$2 = Schema.TaggedError;
|
|
1638
1853
|
var CommentsUnreadable = class extends taggedError$2()("CommentsUnreadable", {
|
|
1639
1854
|
reader: Schema.String,
|
|
@@ -1647,8 +1862,8 @@ const trimmed = ({ index, text }) => ({
|
|
|
1647
1862
|
index,
|
|
1648
1863
|
text: String$1.trimEnd(text)
|
|
1649
1864
|
});
|
|
1650
|
-
// src/config-comments.ts
|
|
1651
|
-
const NEXT$
|
|
1865
|
+
// src/features/comments/model/config-comments.ts
|
|
1866
|
+
const NEXT$1 = 1;
|
|
1652
1867
|
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
1653
1868
|
const childrenOf = (value) => {
|
|
1654
1869
|
if (Array.isArray(value)) return value;
|
|
@@ -1690,7 +1905,7 @@ const sqlComments = (source) => Effect.try({
|
|
|
1690
1905
|
},
|
|
1691
1906
|
catch: unreadable("sql")
|
|
1692
1907
|
});
|
|
1693
|
-
const offsetAt = (lines) => ({ line, character }) => character + pipe(lines, Array.take(line), Array.map((text) => text.length + NEXT$
|
|
1908
|
+
const offsetAt = (lines) => ({ line, character }) => character + pipe(lines, Array.take(line), Array.map((text) => text.length + NEXT$1), Number$1.sumAll);
|
|
1694
1909
|
const dockerfileComments = (source) => Effect.try({
|
|
1695
1910
|
try: () => {
|
|
1696
1911
|
const lines = String$1.split(source, "\n");
|
|
@@ -1701,7 +1916,7 @@ const dockerfileComments = (source) => Effect.try({
|
|
|
1701
1916
|
},
|
|
1702
1917
|
catch: unreadable("dockerfile")
|
|
1703
1918
|
});
|
|
1704
|
-
// src/comment-readers.ts
|
|
1919
|
+
// src/features/comments/model/comment-readers.ts
|
|
1705
1920
|
const GRAMMARS = [
|
|
1706
1921
|
"bash",
|
|
1707
1922
|
"c-sharp",
|
|
@@ -1723,8 +1938,8 @@ const COMMENT_NODES = [
|
|
|
1723
1938
|
"block_comment",
|
|
1724
1939
|
"multiline_comment"
|
|
1725
1940
|
];
|
|
1726
|
-
const START$
|
|
1727
|
-
const NEXT
|
|
1941
|
+
const START$3 = 0;
|
|
1942
|
+
const NEXT = 1;
|
|
1728
1943
|
const NONE$1 = [];
|
|
1729
1944
|
const grammarFile = (grammar) => fileURLToPath(import.meta.resolve(`@vscode/tree-sitter-wasm/wasm/tree-sitter-${grammar}.wasm`));
|
|
1730
1945
|
const loadGrammar = (grammar) => Effect.tryPromise({
|
|
@@ -1782,11 +1997,11 @@ const markupComment = (source) => (node) => {
|
|
|
1782
1997
|
if (!isComment(node) || node.startIndex === null || node.endIndex === null) return NONE$1;
|
|
1783
1998
|
return [{
|
|
1784
1999
|
index: node.startIndex,
|
|
1785
|
-
text: String$1.slice(node.startIndex, node.endIndex + NEXT
|
|
2000
|
+
text: String$1.slice(node.startIndex, node.endIndex + NEXT)(source)
|
|
1786
2001
|
}];
|
|
1787
2002
|
};
|
|
1788
2003
|
const textComments = (grammars, grammar) => (text) => {
|
|
1789
|
-
const shift = shifted(text.startIndex ?? START$
|
|
2004
|
+
const shift = shifted(text.startIndex ?? START$3);
|
|
1790
2005
|
return syntaxComments(grammars, grammar)(text.data).pipe(Effect.map(Array.map(shift)));
|
|
1791
2006
|
};
|
|
1792
2007
|
const embeddedComments = (grammars) => (node) => {
|
|
@@ -1821,14 +2036,14 @@ const commentsWith = (grammars) => (reader, source) => {
|
|
|
1821
2036
|
dockerfile: dockerfileComments
|
|
1822
2037
|
}[reader](source);
|
|
1823
2038
|
};
|
|
1824
|
-
// src/comments.ts
|
|
1825
|
-
const RULE$
|
|
1826
|
-
const CONFIG_FILE
|
|
2039
|
+
// src/features/comments/model/comments.ts
|
|
2040
|
+
const RULE$1 = "comment";
|
|
2041
|
+
const CONFIG_FILE = "vite.config.ts";
|
|
1827
2042
|
const VENDORED_PATHSPEC = ":(attr:linguist-vendored)";
|
|
1828
|
-
const READ_CONCURRENCY$
|
|
1829
|
-
const START$
|
|
1830
|
-
const FIRST_LINE$
|
|
1831
|
-
const FIRST_COLUMN$
|
|
2043
|
+
const READ_CONCURRENCY$2 = 64;
|
|
2044
|
+
const START$2 = 0;
|
|
2045
|
+
const FIRST_LINE$2 = 1;
|
|
2046
|
+
const FIRST_COLUMN$2 = 1;
|
|
1832
2047
|
const READERS = [
|
|
1833
2048
|
[/\.(?:[cm]?jsx?)$/u, "javascript"],
|
|
1834
2049
|
[/\.(?:[cm]?ts)$/u, "typescript"],
|
|
@@ -1883,23 +2098,23 @@ const shebangReader = (source) => {
|
|
|
1883
2098
|
const readerOf = (name, source) => pipe(READERS, Array.findFirst(([pattern]) => pattern.test(name)), Option.orElse(() => shebangReader(source)), Option.map(([, reader]) => reader));
|
|
1884
2099
|
const valueOf = (text) => String$1.replaceAll(DELIMITERS, "")(text);
|
|
1885
2100
|
const lineBefore = (source, index) => {
|
|
1886
|
-
const lines = pipe(source, String$1.slice(START$
|
|
2101
|
+
const lines = pipe(source, String$1.slice(START$2, index), String$1.split("\n"));
|
|
1887
2102
|
return Option.getOrElse(Array.last(lines), () => "");
|
|
1888
2103
|
};
|
|
1889
2104
|
const isPinVersion = (source, { index, text }) => PIN.test(lineBefore(source, index)) && VERSION.test(valueOf(text));
|
|
1890
|
-
const isShebang = ({ index, text }) => index === START$
|
|
2105
|
+
const isShebang = ({ index, text }) => index === START$2 && String$1.startsWith(SHEBANG)(text);
|
|
1891
2106
|
const isAllowed = (source, directives) => (comment) => isShebang(comment) || directives.test(valueOf(comment.text)) || isPinVersion(source, comment);
|
|
1892
2107
|
const problemOf$1 = (file, source) => ({ index }) => ({
|
|
1893
2108
|
file,
|
|
1894
2109
|
...positionOf(source)(index),
|
|
1895
|
-
rule: RULE$
|
|
2110
|
+
rule: RULE$1,
|
|
1896
2111
|
message: MESSAGE
|
|
1897
2112
|
});
|
|
1898
2113
|
const unreadableProblem = (file, message) => ({
|
|
1899
2114
|
file,
|
|
1900
|
-
line: FIRST_LINE$
|
|
1901
|
-
column: FIRST_COLUMN$
|
|
1902
|
-
rule: RULE$
|
|
2115
|
+
line: FIRST_LINE$2,
|
|
2116
|
+
column: FIRST_COLUMN$2,
|
|
2117
|
+
rule: RULE$1,
|
|
1903
2118
|
message: `msch could not read the comments in this file: ${message}`
|
|
1904
2119
|
});
|
|
1905
2120
|
const settingsOf = ({ msch, lint }) => ({
|
|
@@ -1911,7 +2126,7 @@ const settingsOf = ({ msch, lint }) => ({
|
|
|
1911
2126
|
});
|
|
1912
2127
|
const rootSettings = Effect.fn("rootSettings")(function* rootSettings(root) {
|
|
1913
2128
|
const files = yield* RepositoryFiles;
|
|
1914
|
-
const file = files.join(root, CONFIG_FILE
|
|
2129
|
+
const file = files.join(root, CONFIG_FILE);
|
|
1915
2130
|
if (!(yield* files.exists(file))) return NO_SETTINGS;
|
|
1916
2131
|
const config = yield* Effect.tryPromise({
|
|
1917
2132
|
try: () => resolveConfigFromFile(file),
|
|
@@ -1954,28 +2169,28 @@ const checkComments = Effect.fn("checkComments")(function* checkComments(root) {
|
|
|
1954
2169
|
const found = yield* Effect.forEach(scanned, (entry) => files.readFile(entry.file).pipe(Effect.flatMap(Option.match({
|
|
1955
2170
|
onNone: () => Effect.succeed(NONE),
|
|
1956
2171
|
onSome: (source) => problemsIn(entry, source)
|
|
1957
|
-
}))), { concurrency: READ_CONCURRENCY$
|
|
2172
|
+
}))), { concurrency: READ_CONCURRENCY$2 });
|
|
1958
2173
|
return Array.flatten(found);
|
|
1959
2174
|
});
|
|
1960
|
-
// src/hidden-unicode.ts
|
|
2175
|
+
// src/features/invisible-characters/model/hidden-unicode.ts
|
|
1961
2176
|
const HIDDEN = /[\u00AD\u180E\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]|[\u{E0000}-\u{E007F}]/gu;
|
|
1962
2177
|
const NUL = "\0";
|
|
1963
|
-
const START = 0;
|
|
2178
|
+
const START$1 = 0;
|
|
1964
2179
|
const HEX = 16;
|
|
1965
2180
|
const CODE_POINT_WIDTH = 4;
|
|
1966
|
-
const READ_CONCURRENCY$
|
|
1967
|
-
const RULE
|
|
1968
|
-
const hexOf = (character) => pipe(String$1.codePointAt(START)(character), Option.getOrElse(() => START), (code) => code.toString(HEX), String$1.toUpperCase, String$1.padStart(CODE_POINT_WIDTH, "0"));
|
|
2181
|
+
const READ_CONCURRENCY$1 = 64;
|
|
2182
|
+
const RULE = "hidden-unicode";
|
|
2183
|
+
const hexOf = (character) => pipe(String$1.codePointAt(START$1)(character), Option.getOrElse(() => START$1), (code) => code.toString(HEX), String$1.toUpperCase, String$1.padStart(CODE_POINT_WIDTH, "0"));
|
|
1969
2184
|
const problemOf = (file, source) => (found) => {
|
|
1970
|
-
const hex = hexOf(found[START]);
|
|
2185
|
+
const hex = hexOf(found[START$1]);
|
|
1971
2186
|
return {
|
|
1972
2187
|
file,
|
|
1973
|
-
...positionOf(source)(found.index ?? START),
|
|
1974
|
-
rule: RULE
|
|
2188
|
+
...positionOf(source)(found.index ?? START$1),
|
|
2189
|
+
rule: RULE,
|
|
1975
2190
|
message: `U+${hex} is invisible in editors and reviews and can change what the text means. Remove it, or write it as the escape \\u${hex}.`
|
|
1976
2191
|
};
|
|
1977
2192
|
};
|
|
1978
|
-
const problemsIn
|
|
2193
|
+
const problemsIn = (file, source) => {
|
|
1979
2194
|
if (String$1.includes(NUL)(source)) return [];
|
|
1980
2195
|
return pipe(Array.fromIterable(String$1.matchAll(HIDDEN)(source)), Array.map(problemOf(file, source)));
|
|
1981
2196
|
};
|
|
@@ -1987,16 +2202,43 @@ const checkHiddenUnicode = Effect.fn("checkHiddenUnicode")(function* checkHidden
|
|
|
1987
2202
|
const file = files.join(root, name);
|
|
1988
2203
|
return files.readFile(file).pipe(Effect.map(Option.match({
|
|
1989
2204
|
onNone: () => [],
|
|
1990
|
-
onSome: (source) => problemsIn
|
|
2205
|
+
onSome: (source) => problemsIn(file, source)
|
|
1991
2206
|
})));
|
|
1992
|
-
}, { concurrency: READ_CONCURRENCY$
|
|
2207
|
+
}, { concurrency: READ_CONCURRENCY$1 });
|
|
1993
2208
|
return Array.flatten(found);
|
|
1994
2209
|
});
|
|
1995
|
-
// src/
|
|
1996
|
-
const PYTHON_FILE = /(?:\.(?:py|pyi|pyw|pyx|ipynb)|(?:^|\/)(?:pyproject\.toml|uv\.lock|uv\.toml|poetry\.lock|Pipfile|Pipfile\.lock|setup\.cfg|tox\.ini|pytest\.ini|\.python-version|requirements[^/]*\.txt))$/u;
|
|
2210
|
+
// src/shared/lib/scanned-files.ts
|
|
1997
2211
|
const SCANNED_FILE = /(?:\.(?:[cm]?[jt]sx?|jsonc?|toml|ya?ml|sh|bash|zsh|fish|rs|cs|go|mk)|(?:^|\/)(?:Dockerfile[^/]*|Makefile|justfile|\.tool-versions|[^./][^./]*))$/u;
|
|
1998
2212
|
const LOCKFILE = /(?:^|\/)(?:[^/]*\.lock|[^/]*-lock\.(?:json|ya?ml))$/u;
|
|
1999
2213
|
const TOOL_VERSIONS = /(?:^|\/)(?:\.?mise(?:\.[^/]+)?\.toml|\.tool-versions)$/u;
|
|
2214
|
+
const READ_CONCURRENCY = 64;
|
|
2215
|
+
const isScannedText = ({ name }) => SCANNED_FILE.test(name) && !LOCKFILE.test(name);
|
|
2216
|
+
const isToolVersions = ({ name }) => TOOL_VERSIONS.test(name);
|
|
2217
|
+
/** @internal */
|
|
2218
|
+
const listedFiles = Effect.fn("listedFiles")(function* listedFiles(root) {
|
|
2219
|
+
const files = yield* RepositoryFiles;
|
|
2220
|
+
const names = yield* files.listedFiles(root);
|
|
2221
|
+
return pipe(names, Array.map((name) => ({
|
|
2222
|
+
name,
|
|
2223
|
+
file: files.join(root, name)
|
|
2224
|
+
})));
|
|
2225
|
+
});
|
|
2226
|
+
/** @internal */
|
|
2227
|
+
const presentFiles = Effect.fn("presentFiles")(function* presentFiles(listed) {
|
|
2228
|
+
const files = yield* RepositoryFiles;
|
|
2229
|
+
return yield* pipe(listed, Effect.filter(({ file }) => files.exists(file)));
|
|
2230
|
+
});
|
|
2231
|
+
/** @internal */
|
|
2232
|
+
const scanText = Effect.fn("scanText")(function* scanText(listed, problemsIn) {
|
|
2233
|
+
const files = yield* RepositoryFiles;
|
|
2234
|
+
const found = yield* Effect.forEach(listed, (entry) => files.readFile(entry.file).pipe(Effect.map(Option.match({
|
|
2235
|
+
onNone: () => [],
|
|
2236
|
+
onSome: (source) => problemsIn(entry, source)
|
|
2237
|
+
}))), { concurrency: READ_CONCURRENCY });
|
|
2238
|
+
return Array.flatten(found);
|
|
2239
|
+
});
|
|
2240
|
+
// src/features/python/model/python.ts
|
|
2241
|
+
const PYTHON_FILE = /(?:\.(?:py|pyi|pyw|pyx|ipynb)|(?:^|\/)(?:pyproject\.toml|uv\.lock|uv\.toml|poetry\.lock|Pipfile|Pipfile\.lock|setup\.cfg|tox\.ini|pytest\.ini|\.python-version|requirements[^/]*\.txt))$/u;
|
|
2000
2242
|
const COMMAND_PATTERNS = [
|
|
2001
2243
|
/(?<![\w./@-])python[\d.]*[ \t]+(?:[-"'$./]|\S+\.py\b)/gu,
|
|
2002
2244
|
/(?<![\w./@-])pip3?[ \t]+(?:install|uninstall|download|freeze|wheel|compile|sync)\b/gu,
|
|
@@ -2007,208 +2249,169 @@ const COMMAND_PATTERNS = [
|
|
|
2007
2249
|
/(?:\bcommand["']?\s*[:=]\s*|(?:\bspawn\w*|\bexec\w*|\bexeca|Command::new|ChildProcess\.make|\$)\(\s*)["'`](?:python[\d.]*|pip3?|pipx|uvx?|poetry)["'`]/gu,
|
|
2008
2250
|
/\buses:\s*["']?(?:actions\/setup-python|astral-sh\/setup-uv|astral-sh\/ruff-action|pypa\/[\w.-]+|snok\/install-poetry|abatilo\/actions-poetry|conda-incubator\/setup-miniconda|mamba-org\/setup-micromamba|pdm-project\/setup-pdm)\b/gu
|
|
2009
2251
|
];
|
|
2010
|
-
const TOOL_PATTERNS = [/^[ \t]*["']?(?:python|uv|pipx|poetry|ruff|pdm|hatch|pipx:[^"'\s=]+)["']?[ \t]*(?:=|[ \t]+\S)/gmu];
|
|
2011
|
-
const
|
|
2012
|
-
const
|
|
2013
|
-
const
|
|
2014
|
-
const
|
|
2015
|
-
const FILE_RULE = "python-file";
|
|
2252
|
+
const TOOL_PATTERNS$1 = [/^[ \t]*["']?(?:python|uv|pipx|poetry|ruff|pdm|hatch|pipx:[^"'\s=]+)["']?[ \t]*(?:=|[ \t]+\S)/gmu];
|
|
2253
|
+
const FIRST_LINE$1 = 1;
|
|
2254
|
+
const FIRST_COLUMN$1 = 1;
|
|
2255
|
+
const WHOLE_MATCH$1 = 0;
|
|
2256
|
+
const FILE_RULE$1 = "python-file";
|
|
2016
2257
|
const COMMAND_RULE = "python-command";
|
|
2017
2258
|
const fileProblem = ({ file }) => ({
|
|
2018
2259
|
file,
|
|
2019
|
-
line: FIRST_LINE,
|
|
2020
|
-
column: FIRST_COLUMN,
|
|
2021
|
-
rule: FILE_RULE,
|
|
2260
|
+
line: FIRST_LINE$1,
|
|
2261
|
+
column: FIRST_COLUMN$1,
|
|
2262
|
+
rule: FILE_RULE$1,
|
|
2022
2263
|
message: "Python is not used in this repository. Replace this file with TypeScript or Rust."
|
|
2023
2264
|
});
|
|
2024
|
-
const patternsFor = (
|
|
2025
|
-
if (
|
|
2265
|
+
const patternsFor = (entry) => {
|
|
2266
|
+
if (isToolVersions(entry)) return [...COMMAND_PATTERNS, ...TOOL_PATTERNS$1];
|
|
2026
2267
|
return COMMAND_PATTERNS;
|
|
2027
2268
|
};
|
|
2028
2269
|
const commandProblem = ({ file }, source) => (found) => ({
|
|
2029
2270
|
file,
|
|
2030
|
-
...positionOf(source)(found.index ?? WHOLE_MATCH),
|
|
2271
|
+
...positionOf(source)(found.index ?? WHOLE_MATCH$1),
|
|
2031
2272
|
rule: COMMAND_RULE,
|
|
2032
|
-
message: `Python is not used in this repository. Remove \`${String$1.trim(found[WHOLE_MATCH])}\` and do the work in TypeScript or Rust.`
|
|
2273
|
+
message: `Python is not used in this repository. Remove \`${String$1.trim(found[WHOLE_MATCH$1])}\` and do the work in TypeScript or Rust.`
|
|
2033
2274
|
});
|
|
2034
|
-
const commandProblems = (entry, source) => pipe(patternsFor(entry
|
|
2275
|
+
const commandProblems = (entry, source) => pipe(patternsFor(entry), Array.flatMap((pattern) => Array.fromIterable(String$1.matchAll(pattern)(source))), Array.map(commandProblem(entry, source)));
|
|
2035
2276
|
const isPython = ({ name }) => PYTHON_FILE.test(name);
|
|
2036
|
-
const isScanned = (entry) => !isPython(entry) &&
|
|
2277
|
+
const isScanned = (entry) => !isPython(entry) && isScannedText(entry);
|
|
2037
2278
|
/** @internal */
|
|
2038
2279
|
const checkPython = Effect.fn("checkPython")(function* checkPython(root) {
|
|
2039
|
-
const
|
|
2040
|
-
const
|
|
2041
|
-
const
|
|
2042
|
-
|
|
2043
|
-
file: files.join(root, name)
|
|
2044
|
-
})));
|
|
2045
|
-
const problemsIn = (entry) => files.readFile(entry.file).pipe(Effect.map(Option.match({
|
|
2046
|
-
onNone: () => [],
|
|
2047
|
-
onSome: (source) => commandProblems(entry, source)
|
|
2048
|
-
})));
|
|
2049
|
-
const scanned = yield* Effect.forEach(pipe(listed, Array.filter(isScanned)), problemsIn, { concurrency: READ_CONCURRENCY$2 });
|
|
2050
|
-
const present = yield* Effect.filter(pipe(listed, Array.filter(isPython)), ({ file }) => files.exists(file));
|
|
2051
|
-
return [...pipe(present, Array.map(fileProblem)), ...Array.flatten(scanned)];
|
|
2052
|
-
});
|
|
2053
|
-
// src/tracked-text.ts
|
|
2054
|
-
/** @internal */
|
|
2055
|
-
const checkTrackedText = Effect.fn("checkTrackedText")(function* checkTrackedText(root) {
|
|
2056
|
-
const found = yield* Effect.all([
|
|
2057
|
-
checkHiddenUnicode(root),
|
|
2058
|
-
checkPython(root),
|
|
2059
|
-
checkComments(root)
|
|
2060
|
-
], { concurrency: "unbounded" });
|
|
2061
|
-
return Array.flatten(found);
|
|
2280
|
+
const listed = yield* listedFiles(root);
|
|
2281
|
+
const scanned = yield* scanText(pipe(listed, Array.filter(isScanned)), commandProblems);
|
|
2282
|
+
const present = yield* presentFiles(pipe(listed, Array.filter(isPython)));
|
|
2283
|
+
return [...pipe(present, Array.map(fileProblem)), ...scanned];
|
|
2062
2284
|
});
|
|
2063
|
-
// src/
|
|
2064
|
-
const
|
|
2065
|
-
const
|
|
2066
|
-
const CONFIG_FILE$2 = "vite.config.ts";
|
|
2285
|
+
// src/features/unneeded-files/model/unneeded-files.ts
|
|
2286
|
+
const WORKSPACE_FILE = "pnpm-workspace.yaml";
|
|
2287
|
+
const PNPM_DIRECTORY = ".pnpm/";
|
|
2067
2288
|
const SEPARATOR = "/";
|
|
2068
|
-
const
|
|
2069
|
-
const
|
|
2070
|
-
const
|
|
2071
|
-
|
|
2072
|
-
|
|
2289
|
+
const FOREIGN_LOCKFILE = /(?:^|\/)(?:package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|bun\.lockb?)$/u;
|
|
2290
|
+
const CARGO_MANIFEST_FILE = /(?:^|\/)Cargo\.toml$/u;
|
|
2291
|
+
const CARGO_LOCK_FILE = /(?:^|\/)Cargo\.lock$/u;
|
|
2292
|
+
const PNPM_OUTPUT = /(?:^|\/)\.pnpm\//u;
|
|
2293
|
+
const CARGO_WORKSPACE = /^\[workspace\]/mu;
|
|
2294
|
+
const LEGACY_CARGO_CONFIG = /(?:^|\/)\.cargo\/config$/u;
|
|
2295
|
+
const CARGO_CONFIG_FILE = /(?:^|\/)\.cargo\/config\.toml$/u;
|
|
2296
|
+
const PNPM_CARGO_START = /# >>> pnpm-managed cargo sources >>>/u;
|
|
2297
|
+
const PNPM_CARGO_BLOCK = /# >>> pnpm-managed cargo sources >>>[\s\S]*?# <<< pnpm-managed cargo sources <<<\n?/gu;
|
|
2298
|
+
const SETUP_PATTERNS = [
|
|
2299
|
+
/(?<![\w./@-])rustup[ \t]+(?:toolchain[ \t]+install|install|update|default|override[ \t]+set|target[ \t]+add|component[ \t]+add)\b/gu,
|
|
2300
|
+
/(?<![\w./@-])cargo[ \t]+(?:vendor|fetch)\b/gu,
|
|
2301
|
+
/\buses:\s*["']?(?:dtolnay\/rust-toolchain|actions-rust-lang\/setup-rust-toolchain|actions-rs\/toolchain|moonrepo\/setup-rust)\b/gu
|
|
2302
|
+
];
|
|
2303
|
+
const TOOL_PATTERNS = [/^[ \t]*["']?(?:rust|rustup)["']?[ \t]*(?:=|[ \t]+\S)/gmu];
|
|
2304
|
+
const START = 0;
|
|
2305
|
+
const LAST_SEGMENT = 1;
|
|
2306
|
+
const FIRST_LINE = 1;
|
|
2307
|
+
const FIRST_COLUMN = 1;
|
|
2308
|
+
const WHOLE_MATCH = 0;
|
|
2309
|
+
const FILE_RULE = "unneeded-file";
|
|
2310
|
+
const SETUP_RULE = "unneeded-setup";
|
|
2311
|
+
const CARGO_RULE = "cargo-outside-pnpm";
|
|
2312
|
+
const CargoSettings = Schema.Struct({ enabled: Schema.optionalKey(Schema.Boolean) });
|
|
2313
|
+
const WorkspaceFile = Schema.Struct({ cargo: Schema.optionalKey(CargoSettings) });
|
|
2314
|
+
const decodeWorkspaceFile = Schema.decodeUnknownOption(WorkspaceFile);
|
|
2315
|
+
const cargoEnabled = (text) => pipe(decodeWorkspaceFile(parse$1(text)), Option.flatMap(({ cargo }) => Option.fromUndefinedOr(cargo)), Option.flatMap(({ enabled }) => Option.fromUndefinedOr(enabled)), Option.getOrElse(() => false));
|
|
2316
|
+
const problemAtStart = (rule, message) => ({ file }) => ({
|
|
2317
|
+
file,
|
|
2318
|
+
line: FIRST_LINE,
|
|
2319
|
+
column: FIRST_COLUMN,
|
|
2320
|
+
rule,
|
|
2321
|
+
message
|
|
2073
2322
|
});
|
|
2074
|
-
const
|
|
2075
|
-
const
|
|
2076
|
-
const
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2323
|
+
const foreignLockfile = problemAtStart(FILE_RULE, "pnpm-lock.yaml is this repository's lockfile, and pnpm never reads this one. Delete it.");
|
|
2324
|
+
const nestedCargoLock = problemAtStart(FILE_RULE, "Cargo reads only the Cargo.lock beside the workspace's Cargo.toml, and pnpm install writes that one. Delete this one.");
|
|
2325
|
+
const legacyCargoConfig = problemAtStart(FILE_RULE, "pnpm install writes .cargo/config.toml, and Cargo warns when .cargo/config sits beside it. Move its settings into .cargo/config.toml and delete it.");
|
|
2326
|
+
const pnpmOutput = problemAtStart(FILE_RULE, "pnpm install writes .pnpm/ from Cargo.lock and rust-toolchain.toml. Add this .pnpm directory to .gitignore and keep it out of the repository.");
|
|
2327
|
+
const pnpmCargoConfig = problemAtStart(FILE_RULE, "pnpm install writes this .cargo/config.toml, and it holds nothing else. Add /.cargo/config.toml to .gitignore and keep it out of the repository.");
|
|
2328
|
+
const generatedCargoConfig = (entry, source) => {
|
|
2329
|
+
if (!CARGO_CONFIG_FILE.test(entry.name) || !PNPM_CARGO_START.test(source)) return [];
|
|
2330
|
+
if (String$1.isNonEmpty(String$1.trim(String$1.replaceAll(PNPM_CARGO_BLOCK, "")(source)))) return [];
|
|
2331
|
+
return [pnpmCargoConfig(entry)];
|
|
2332
|
+
};
|
|
2333
|
+
const cargoOutsidePnpm = problemAtStart(CARGO_RULE, `pnpm does not manage these crates. Set \`cargo: { enabled: true }\` in ${WORKSPACE_FILE} so pnpm install fetches the crates and the Rust toolchain.`);
|
|
2334
|
+
const setupProblem = ({ file }, source) => (found) => ({
|
|
2335
|
+
file,
|
|
2336
|
+
...positionOf(source)(found.index ?? WHOLE_MATCH),
|
|
2337
|
+
rule: SETUP_RULE,
|
|
2338
|
+
message: `pnpm install already installs the toolchain in rust-toolchain.toml and vendors the crates in Cargo.lock. Remove \`${String$1.trim(found[WHOLE_MATCH])}\`.`
|
|
2339
|
+
});
|
|
2340
|
+
const setupPatternsFor = (entry) => {
|
|
2341
|
+
if (isToolVersions(entry)) return [...SETUP_PATTERNS, ...TOOL_PATTERNS];
|
|
2342
|
+
return SETUP_PATTERNS;
|
|
2343
|
+
};
|
|
2344
|
+
const setupProblems = (entry, source) => pipe(setupPatternsFor(entry), Array.flatMap((pattern) => Array.fromIterable(String$1.matchAll(pattern)(source))), Array.map(setupProblem(entry, source)), Array.appendAll(generatedCargoConfig(entry, source)));
|
|
2345
|
+
const matches = (pattern) => ({ name }) => pattern.test(name);
|
|
2346
|
+
const isCargoManifest = matches(CARGO_MANIFEST_FILE);
|
|
2347
|
+
const isForeignLockfile = matches(FOREIGN_LOCKFILE);
|
|
2348
|
+
const isLegacyCargoConfig = matches(LEGACY_CARGO_CONFIG);
|
|
2349
|
+
const isPnpmOutput = matches(PNPM_OUTPUT);
|
|
2350
|
+
const directoryOf = (name) => pipe(String$1.split(name, SEPARATOR), Array.dropRight(LAST_SEGMENT), Array.join(SEPARATOR));
|
|
2351
|
+
const ancestorsOf = (directory) => {
|
|
2352
|
+
const parts = String$1.split(directory, SEPARATOR);
|
|
2353
|
+
return pipe(Array.makeBy(parts.length, (depth) => Array.join(Array.take(parts, depth), SEPARATOR)), Array.filter((ancestor) => ancestor !== directory));
|
|
2354
|
+
};
|
|
2355
|
+
const readsCargoLock = (manifests, workspaces) => ({ name }) => {
|
|
2356
|
+
const directory = directoryOf(name);
|
|
2357
|
+
const insideWorkspace = pipe(ancestorsOf(directory), Array.some((ancestor) => Array.contains(workspaces, ancestor)));
|
|
2358
|
+
return Array.contains(manifests, directory) && !insideWorkspace;
|
|
2359
|
+
};
|
|
2360
|
+
const isWorkspaceManifest = (source) => Option.exists(source, (text) => CARGO_WORKSPACE.test(text));
|
|
2361
|
+
const directoriesOf = (entries) => pipe(entries, Array.map(({ name }) => directoryOf(name)));
|
|
2362
|
+
const cargoWorkspaces = Effect.fn("cargoWorkspaces")(function* cargoWorkspaces(manifests) {
|
|
2363
|
+
const files = yield* RepositoryFiles;
|
|
2364
|
+
const roots = yield* pipe(manifests, Effect.filter(({ file }) => files.readFile(file).pipe(Effect.map(isWorkspaceManifest))));
|
|
2365
|
+
return directoriesOf(roots);
|
|
2366
|
+
});
|
|
2367
|
+
const pnpmDirectoryOf = ({ name }) => pipe(name, String$1.indexOf(PNPM_DIRECTORY), Option.getOrElse(() => START), (end) => String$1.slice(START, end)(name));
|
|
2368
|
+
const pnpmOutputs = (present) => pipe(present, Array.filter(isPnpmOutput), Array.dedupeWith((left, right) => pnpmDirectoryOf(left) === pnpmDirectoryOf(right)), Array.map(pnpmOutput));
|
|
2369
|
+
const byDepth = Order.mapInput(Order.Number, ({ name }) => String$1.split(name, "/").length);
|
|
2370
|
+
const cargoProblems = (present, enabled) => {
|
|
2371
|
+
if (!enabled) return Effect.succeed(pipe(present, Array.filter(isCargoManifest), Array.match({
|
|
2372
|
+
onEmpty: () => [],
|
|
2373
|
+
onNonEmpty: (manifests) => [cargoOutsidePnpm(Array.min(manifests, byDepth))]
|
|
2092
2374
|
})));
|
|
2093
|
-
|
|
2094
|
-
const
|
|
2095
|
-
|
|
2096
|
-
|
|
2375
|
+
return Effect.gen(function* enabledCargoProblems() {
|
|
2376
|
+
const manifests = pipe(present, Array.filter(isCargoManifest));
|
|
2377
|
+
const workspaces = yield* cargoWorkspaces(manifests);
|
|
2378
|
+
const reads = readsCargoLock(directoriesOf(manifests), workspaces);
|
|
2379
|
+
const setup = yield* scanText(pipe(present, Array.filter(isScannedText)), setupProblems);
|
|
2380
|
+
return [
|
|
2381
|
+
...pipe(present, Array.filter((entry) => CARGO_LOCK_FILE.test(entry.name) && !reads(entry)), Array.map(nestedCargoLock)),
|
|
2382
|
+
...pipe(present, Array.filter(isLegacyCargoConfig), Array.map(legacyCargoConfig)),
|
|
2383
|
+
...pnpmOutputs(present),
|
|
2384
|
+
...setup
|
|
2385
|
+
];
|
|
2386
|
+
});
|
|
2097
2387
|
};
|
|
2098
|
-
const
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
const problemIn$1 = Effect.fn("problemIn")(function* problemIn(root, directories, crate) {
|
|
2106
|
-
const files = yield* RepositoryFiles;
|
|
2107
|
-
const workspace = owningWorkspace(directories)(files.relative(root, files.dirname(crate.manifest)));
|
|
2108
|
-
if (Option.isNone(workspace)) return Option.some(problemFor(crate, "is outside every workspace package"));
|
|
2109
|
-
if (yield* hasVerifyTask(files.join(root, workspace.value, CONFIG_FILE$2))) return Option.none();
|
|
2110
|
-
return Option.some(problemFor(crate, `is in ${workspace.value}, whose ${CONFIG_FILE$2} has no verify task`));
|
|
2111
|
-
});
|
|
2112
|
-
/** @internal */
|
|
2113
|
-
const checkCrates = Effect.fn("checkCrates")(function* checkCrates(root) {
|
|
2114
|
-
const files = yield* RepositoryFiles;
|
|
2115
|
-
if (!(yield* files.exists(files.join(root, CARGO_FILE)))) return [];
|
|
2116
|
-
const directories = yield* workspaceDirectories(root);
|
|
2117
|
-
const crates = yield* cratesIn(root);
|
|
2118
|
-
const found = yield* Effect.forEach(crates, (crate) => problemIn$1(root, directories, crate), { concurrency: READ_CONCURRENCY$1 });
|
|
2119
|
-
return Array.getSomes(found);
|
|
2120
|
-
});
|
|
2121
|
-
// src/hidden-verify.ts
|
|
2122
|
-
const RULE$1 = "hidden-verify";
|
|
2123
|
-
const CONFIG_FILE$1 = "vite.config.ts";
|
|
2124
|
-
const FIRST$1 = 1;
|
|
2125
|
-
const READ_CONCURRENCY = 8;
|
|
2126
|
-
const problemIn = Effect.fn("problemIn")(function* problemIn(root, directory) {
|
|
2127
|
-
const files = yield* RepositoryFiles;
|
|
2128
|
-
const file = files.join(root, directory, CONFIG_FILE$1);
|
|
2129
|
-
const text = yield* files.readFile(file);
|
|
2130
|
-
if (Option.isNone(text)) return Option.none();
|
|
2131
|
-
const program = yield* programOf(file, text.value);
|
|
2132
|
-
if (definesTask(VERIFY_TASK)(program)) return Option.none();
|
|
2133
|
-
const verified = yield* hasVerifyTask(file);
|
|
2134
|
-
return Option.some({
|
|
2135
|
-
file,
|
|
2136
|
-
line: FIRST$1,
|
|
2137
|
-
column: FIRST$1,
|
|
2138
|
-
rule: RULE$1,
|
|
2139
|
-
message: `${directory} gets its verify task from code outside ${CONFIG_FILE$1}. The root verify reads ${CONFIG_FILE$1} without running it, so it never runs this verify. Write run.tasks.verify in ${directory}/${CONFIG_FILE$1}.`
|
|
2140
|
-
}).pipe(Option.filter(() => verified));
|
|
2141
|
-
});
|
|
2142
|
-
/** @internal */
|
|
2143
|
-
const checkHiddenVerify = Effect.fn("checkHiddenVerify")(function* checkHiddenVerify(root) {
|
|
2144
|
-
const directories = yield* workspaceDirectories(root);
|
|
2145
|
-
const found = yield* Effect.forEach(directories, (directory) => problemIn(root, directory), { concurrency: READ_CONCURRENCY });
|
|
2146
|
-
return Array.getSomes(found);
|
|
2388
|
+
const unneededIn = Effect.fn("unneededIn")(function* unneededIn(root, workspace) {
|
|
2389
|
+
const listed = yield* listedFiles(root);
|
|
2390
|
+
const present = yield* presentFiles(listed);
|
|
2391
|
+
const lockfiles = pipe(present, Array.filter(isForeignLockfile), Array.map(foreignLockfile));
|
|
2392
|
+
if (!pipe(present, Array.some(isCargoManifest))) return lockfiles;
|
|
2393
|
+
const cargo = yield* cargoProblems(present, cargoEnabled(workspace));
|
|
2394
|
+
return [...lockfiles, ...cargo];
|
|
2147
2395
|
});
|
|
2148
|
-
// src/root-workspace-paths.ts
|
|
2149
|
-
const RULE = "root-workspace-path";
|
|
2150
|
-
const CONFIG_FILE = "vite.config.ts";
|
|
2151
|
-
const PATH_CHARACTER = /[\w.@/-]/u;
|
|
2152
|
-
const NAME_CHARACTER = /[\w.@-]/u;
|
|
2153
|
-
const FIRST = 0;
|
|
2154
|
-
const NEXT = 1;
|
|
2155
|
-
const StringNode = Schema.Union([Schema.Struct({
|
|
2156
|
-
type: Schema.Literal("Literal"),
|
|
2157
|
-
value: Schema.String,
|
|
2158
|
-
start: Schema.Finite
|
|
2159
|
-
}), Schema.Struct({
|
|
2160
|
-
type: Schema.Literal("TemplateElement"),
|
|
2161
|
-
value: Schema.Struct({ cooked: Schema.String }),
|
|
2162
|
-
start: Schema.Finite
|
|
2163
|
-
})]);
|
|
2164
|
-
const decodeStringNode = Schema.decodeUnknownOption(StringNode);
|
|
2165
|
-
const textOf = (node) => {
|
|
2166
|
-
if (node.type === "Literal") return node.value;
|
|
2167
|
-
return node.value.cooked;
|
|
2168
|
-
};
|
|
2169
|
-
const stringsIn = (node) => {
|
|
2170
|
-
return [...pipe(decodeStringNode(node), Option.map((found) => ({
|
|
2171
|
-
text: textOf(found),
|
|
2172
|
-
start: found.start
|
|
2173
|
-
})), Option.toArray), ...pipe(childrenOf$3(node), Array.flatMap(stringsIn))];
|
|
2174
|
-
};
|
|
2175
|
-
const isBoundary = (character, allowed) => character === "" || !allowed.test(character);
|
|
2176
|
-
const mentions = (directory) => (text) => {
|
|
2177
|
-
const parts = String$1.split(text, directory);
|
|
2178
|
-
return pipe(Array.drop(parts, NEXT), Array.some((after, index) => {
|
|
2179
|
-
const before = parts[index] ?? "";
|
|
2180
|
-
const previous = String$1.slice(before.length - NEXT)(before);
|
|
2181
|
-
const following = String$1.slice(FIRST, NEXT)(after);
|
|
2182
|
-
return isBoundary(previous, PATH_CHARACTER) && (following === "/" || isBoundary(following, NAME_CHARACTER));
|
|
2183
|
-
}));
|
|
2184
|
-
};
|
|
2185
|
-
const problemsIn = (file, source, directories) => (found) => pipe(directories, Array.filter((directory) => mentions(directory)(found.text)), Array.map((directory) => ({
|
|
2186
|
-
file,
|
|
2187
|
-
...positionOf(source)(found.start),
|
|
2188
|
-
rule: RULE,
|
|
2189
|
-
message: `${directory} is a workspace. The root ${CONFIG_FILE} holds what applies to every workspace, so move what only ${directory} needs into ${directory}/${CONFIG_FILE}: msch.lint, msch.devDependencies or its verify task.`
|
|
2190
|
-
})));
|
|
2191
2396
|
/** @internal */
|
|
2192
|
-
const
|
|
2397
|
+
const checkUnneededFiles = Effect.fn("checkUnneededFiles")(function* checkUnneededFiles(root) {
|
|
2193
2398
|
const files = yield* RepositoryFiles;
|
|
2194
|
-
const
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
const directories = yield* workspaceDirectories(root);
|
|
2198
|
-
const parsed = yield* Effect.promise(() => parse(file, source.value, { lang: "ts" }));
|
|
2199
|
-
return pipe(stringsIn(parsed.program), Array.flatMap(problemsIn(file, source.value, directories)));
|
|
2399
|
+
const workspace = yield* files.readFile(files.join(root, WORKSPACE_FILE));
|
|
2400
|
+
if (Option.isNone(workspace)) return [];
|
|
2401
|
+
return yield* unneededIn(root, workspace.value);
|
|
2200
2402
|
});
|
|
2201
|
-
// src/
|
|
2403
|
+
// src/app/tracked-text.ts
|
|
2202
2404
|
/** @internal */
|
|
2203
|
-
const
|
|
2405
|
+
const checkTrackedText = Effect.fn("checkTrackedText")(function* checkTrackedText(root) {
|
|
2204
2406
|
const found = yield* Effect.all([
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2407
|
+
checkHiddenUnicode(root),
|
|
2408
|
+
checkPython(root),
|
|
2409
|
+
checkUnneededFiles(root),
|
|
2410
|
+
checkComments(root)
|
|
2208
2411
|
], { concurrency: "unbounded" });
|
|
2209
2412
|
return Array.flatten(found);
|
|
2210
2413
|
});
|
|
2211
|
-
// src/all-checks.ts
|
|
2414
|
+
// src/app/all-checks.ts
|
|
2212
2415
|
/** @internal */
|
|
2213
2416
|
const checkAll = Effect.fn("checkAll")(function* checkAll(root) {
|
|
2214
2417
|
const found = yield* Effect.all([
|
|
@@ -2221,7 +2424,7 @@ const checkAll = Effect.fn("checkAll")(function* checkAll(root) {
|
|
|
2221
2424
|
], { concurrency: "unbounded" });
|
|
2222
2425
|
return Array.flatten(found);
|
|
2223
2426
|
});
|
|
2224
|
-
// src/output.ts
|
|
2427
|
+
// src/app/output.ts
|
|
2225
2428
|
const taggedError = Schema.TaggedError;
|
|
2226
2429
|
var ProblemsFound = class extends taggedError()("ProblemsFound", { count: Schema.Finite }) {};
|
|
2227
2430
|
/** @internal */
|
|
@@ -2229,19 +2432,20 @@ const writeStdout = Effect.fn("writeStdout")(function* writeStdout(text) {
|
|
|
2229
2432
|
const stdio = yield* Stdio.Stdio;
|
|
2230
2433
|
yield* Stream.make(text).pipe(Stream.run(stdio.stdout()), Effect.orDie);
|
|
2231
2434
|
});
|
|
2232
|
-
// src/runtime.ts
|
|
2435
|
+
// src/app/runtime.ts
|
|
2233
2436
|
const reportFailure = (cause) => Effect.gen(function* report() {
|
|
2234
2437
|
const stdio = yield* Stdio.Stdio;
|
|
2235
2438
|
if (Cause.findErrorOption(cause).pipe(Option.exists(Schema.is(ProblemsFound)))) return;
|
|
2236
2439
|
yield* Stream.make(`${Cause.pretty(cause)}\n`).pipe(Stream.run(stdio.stderr()), Effect.orDie);
|
|
2237
2440
|
});
|
|
2238
2441
|
const tracing = Otlp.layerFromConfig({ resource: { serviceName: "msch" } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
|
|
2442
|
+
/** @internal */
|
|
2239
2443
|
const runCli = (program) => {
|
|
2240
2444
|
const services = Layer.mergeAll(nodeRepositoryFiles, tracing).pipe(Layer.provideMerge(nodeServicesLayer));
|
|
2241
2445
|
const main = Layer.build(services).pipe(Effect.flatMap((context) => Effect.provideContext(program.pipe(Effect.tapCause(reportFailure)), context)), Effect.scoped);
|
|
2242
2446
|
runMain(main, { disableErrorReporting: true });
|
|
2243
2447
|
};
|
|
2244
|
-
// src/cli.ts
|
|
2448
|
+
// src/app/cli.ts
|
|
2245
2449
|
const NO_PROBLEMS = 0;
|
|
2246
2450
|
const reportText = (root, problems) => Effect.gen(function* report() {
|
|
2247
2451
|
const files = yield* RepositoryFiles;
|