@r_masseater/msch 0.13.0 → 0.15.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
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-B5LCnsRC.mjs";
3
- import { i as nodeServicesLayer, n as RepositoryFiles, r as nodeRepositoryFiles, t as NODE_MODULES } from "./repository-files-DcTnXciI.mjs";
4
- import { C as publishedWorkspaces, D as readManifest, E as dependencyEntries, O as workspaceDependencies, T as MANIFEST_FILE, _ as childrenOf$3, a as hasVerifyTask, b as nestedValues, g as KeySchema, h as workspaceConfigOf, i as definesTask, l as workspaceDirectories, r as VERIFY_TASK, t as namedWorkspaces, v as keyName, w as publicEntriesOf, y as literalOf } from "./workspace-B1-fCPnh.mjs";
5
- import { t as COMMENT_DIRECTIVES } from "./comment-directives-TN0dNEbg.mjs";
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-PUlrIOu9.mjs";
3
+ import { i as nodeServicesLayer, n as RepositoryFiles, r as nodeRepositoryFiles, t as NODE_MODULES } from "./repository-files-BiKs7S7N.mjs";
4
+ import { C as publishedWorkspaces, D as readManifest, E as dependencyEntries, O as workspaceDependencies, T as MANIFEST_FILE, _ as childrenOf$3, a as hasVerifyTask, b as nestedValues, g as KeySchema, h as workspaceConfigOf, i as definesTask, l as workspaceDirectories, r as VERIFY_TASK, t as namedWorkspaces, v as keyName, w as publicEntriesOf, y as literalOf } from "./workspace-aMPb8EA_.mjs";
5
+ import { t as COMMENT_DIRECTIVES } from "./comment-directives-WcDqvLwJ.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";
@@ -222,13 +222,13 @@ const annotateResources = (api) => Effect.gen(function* annotateCompiler() {
222
222
  });
223
223
  // src/entities/project/model/project.ts
224
224
  const CONFIG_PATHSPEC = `:(glob)**/tsconfig.json`;
225
- const HIDDEN_PREFIX = ".";
225
+ const HIDDEN_PREFIX$1 = ".";
226
226
  const SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([
227
227
  NODE_MODULES,
228
228
  "dist",
229
229
  "coverage"
230
230
  ]);
231
- const isVisible = (file) => pipe(String$1.split(file, "/"), Array.every((segment) => !String$1.startsWith(HIDDEN_PREFIX)(segment) && !SKIPPED_DIRECTORIES.has(segment)));
231
+ const isVisible = (file) => pipe(String$1.split(file, "/"), Array.every((segment) => !String$1.startsWith(HIDDEN_PREFIX$1)(segment) && !SKIPPED_DIRECTORIES.has(segment)));
232
232
  const listConfigFiles = (root) => Effect.gen(function* configFilesUnder() {
233
233
  const files = yield* RepositoryFiles;
234
234
  const listed = yield* files.matchingFiles(root, [CONFIG_PATHSPEC]);
@@ -243,6 +243,7 @@ const nearestPackageDirectory = (directory, root) => Effect.gen(function* neares
243
243
  if (hasManifest || directory === root || parent === directory) return directory;
244
244
  return yield* nearestPackageDirectory(parent, root);
245
245
  });
246
+ const packageDirectoryOf = (root) => (directory) => nearestPackageDirectory(directory, root);
246
247
  const packageInfoOf = Effect.fn("packageInfoOf")(function* packageInfoOf(configPath, root) {
247
248
  const files = yield* RepositoryFiles;
248
249
  const directory = yield* nearestPackageDirectory(files.dirname(configPath), root);
@@ -314,6 +315,88 @@ const mentions$1 = (needle) => ({ api }) => (configPath) => Effect.gen(function*
314
315
  const includesNeedle = String$1.includes(needle);
315
316
  return pipe(texts, Array.some((text) => Option.exists(text, includesNeedle)));
316
317
  });
318
+ // src/entities/project/model/inputs.ts
319
+ const SEPARATOR$6 = "/";
320
+ const SCOPE_PREFIX$2 = "@";
321
+ const HIDDEN_PREFIX = ".";
322
+ const encodeOptions = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
323
+ const nearestManifestDirectory = Effect.fn("nearestManifestDirectory")(function* nearestManifestDirectory(start) {
324
+ const files = yield* RepositoryFiles;
325
+ let directory = start;
326
+ let parent = files.dirname(directory);
327
+ while (parent !== directory && !(yield* files.exists(files.join(directory, "package.json")))) {
328
+ directory = parent;
329
+ parent = files.dirname(directory);
330
+ }
331
+ return directory;
332
+ });
333
+ const dependenciesOf = Effect.fn("dependenciesOf")(function* dependenciesOf(directory) {
334
+ const files = yield* RepositoryFiles;
335
+ const manifest = yield* readManifest(directory);
336
+ const names = Option.match(manifest, {
337
+ onNone: () => [],
338
+ onSome: workspaceDependencies
339
+ });
340
+ return yield* pipe(names, Effect.forEach((name) => files.realPath(files.join(directory, NODE_MODULES, name))));
341
+ });
342
+ const workspaceClosure = Effect.fn("workspaceClosure")(function* workspaceClosure(start) {
343
+ const seen = /* @__PURE__ */ new Set([start]);
344
+ const queue = [start];
345
+ for (const directory of queue) {
346
+ const next = yield* dependenciesOf(directory);
347
+ for (const dependency of next) if (!seen.has(dependency)) {
348
+ seen.add(dependency);
349
+ queue.push(dependency);
350
+ }
351
+ }
352
+ return [...seen];
353
+ });
354
+ const isUnder = (prefixes) => (file) => pipe(prefixes, Array.some((prefix) => String$1.startsWith(prefix)(file)));
355
+ const closureOf$1 = Effect.fn("closureOf")(function* closureOf(root, configPath) {
356
+ const files = yield* RepositoryFiles;
357
+ const directory = yield* packageDirectoryOf(root)(files.dirname(configPath));
358
+ const directories = yield* workspaceClosure(directory);
359
+ return {
360
+ directories,
361
+ prefixes: pipe(directories, Array.map((found) => `${files.relative(root, found)}${SEPARATOR$6}`))
362
+ };
363
+ });
364
+ const scopedNames = (modules) => (name) => Effect.gen(function* listScope() {
365
+ const files = yield* RepositoryFiles;
366
+ if (!String$1.startsWith(SCOPE_PREFIX$2)(name)) return [name];
367
+ const scoped = yield* files.readDirectory(files.join(modules, name));
368
+ return pipe(scoped, Array.map((entry) => `${name}${SEPARATOR$6}${entry}`));
369
+ });
370
+ const installedNames$1 = Effect.fn("installedNames")(function* installedNames(modules) {
371
+ const listed = yield* (yield* RepositoryFiles).readDirectory(modules);
372
+ const nested = yield* pipe(listed, Array.filter((name) => !String$1.startsWith(HIDDEN_PREFIX)(name)), Effect.forEach(scopedNames(modules)));
373
+ return Array.flatten(nested);
374
+ });
375
+ const installedPackages = Effect.fn("installedPackages")(function* installedPackages(root, directory) {
376
+ const files = yield* RepositoryFiles;
377
+ const modules = files.join(directory, NODE_MODULES);
378
+ const names = yield* installedNames$1(modules);
379
+ return yield* pipe(names, Effect.forEach((name) => files.realPath(files.join(modules, name)).pipe(Effect.map((found) => files.relative(root, found)))));
380
+ });
381
+ const dependencyVersions = Effect.fn("dependencyVersions")(function* dependencyVersions(root, directories) {
382
+ const installed = yield* pipe(Array.dedupe([root, ...directories]), Effect.forEach((directory) => installedPackages(root, directory)));
383
+ return Array.sort(Array.dedupe(Array.flatten(installed)), Order.String);
384
+ });
385
+ const projectInputs = ({ workspace: { compiler, root }, listed }) => (configPath) => Effect.gen(function* collectInputs() {
386
+ const files = yield* RepositoryFiles;
387
+ const parsed = parseConfig(compiler.api)(configPath);
388
+ if (Option.isNone(parsed)) return Option.none();
389
+ const closure = yield* closureOf$1(root, configPath);
390
+ const dependencies = yield* dependencyVersions(root, closure.directories);
391
+ const options = yield* encodeOptions(parsed.value.options).pipe(Effect.orElseSucceed(() => ""));
392
+ const sources = pipe(parsed.value.fileNames, Array.map((fileName) => files.relative(root, fileName)));
393
+ const shared = pipe(listed, Array.filter(isUnder(closure.prefixes)));
394
+ return Option.some({
395
+ options,
396
+ files: Array.sort(Array.dedupe([...sources, ...shared]), Order.String),
397
+ dependencies
398
+ });
399
+ });
317
400
  // src/shared/lib/text-position.ts
318
401
  const START$7 = 0;
319
402
  const FIRST_COLUMN$3 = 1;
@@ -431,7 +514,7 @@ const packagesByEntry = Effect.fn("packagesByEntry")(function* packagesByEntry(a
431
514
  }).pipe(Effect.map((packages) => [entry, packages]))));
432
515
  });
433
516
  // src/features/install-size/model/installed-closure.ts
434
- const EMPTY = 0;
517
+ const EMPTY$1 = 0;
435
518
  const DependencyMap = Schema.optional(Schema.Record(Schema.String, Schema.String));
436
519
  const PeerMetaEntry = Schema.Struct({ optional: Schema.optional(Schema.Boolean) });
437
520
  const PeerMeta = Schema.optional(Schema.Record(Schema.String, PeerMetaEntry));
@@ -490,7 +573,7 @@ const directorySize = (directory) => Effect.gen(function* sizeOfDirectory() {
490
573
  const names = yield* files.readDirectory(directory);
491
574
  const entries = pipe(names, Array.filter((name) => name !== NODE_MODULES), Array.map((name) => files.join(directory, name)));
492
575
  const sizes = yield* pipe(entries, Effect.forEach((entry) => files.isDirectory(entry).pipe(Effect.flatMap((kind) => {
493
- if (Option.isNone(kind)) return Effect.succeed(EMPTY);
576
+ if (Option.isNone(kind)) return Effect.succeed(EMPTY$1);
494
577
  if (kind.value) return directorySize(entry);
495
578
  return files.fileSize(entry);
496
579
  }))));
@@ -502,7 +585,7 @@ const installedClosure = ({ provided, from, name }) => closureOf(provided, {
502
585
  });
503
586
  const installedSize = (directory) => {
504
587
  if (String$1.includes(`/node_modules/`)(directory)) return directorySize(directory);
505
- return Effect.succeed(EMPTY);
588
+ return Effect.succeed(EMPTY$1);
506
589
  };
507
590
  // src/features/install-size/model/install-size.ts
508
591
  const INSTALL_SIZE = "install-size";
@@ -1111,6 +1194,8 @@ const RULE$9 = "root-readme";
1111
1194
  const ROOT_DOC = /^(?:README(?:\.[^/]+)?|AGENTS\.md|CLAUDE\.md)$/iu;
1112
1195
  const READ_CONCURRENCY$9 = 16;
1113
1196
  const START$5 = 0;
1197
+ const CHECK_POLICY = "@r_masseater/msch";
1198
+ const isCheckPolicy = ({ packageName }) => Option.contains(packageName, CHECK_POLICY);
1114
1199
  const messageFor = (directory) => `names the workspace ${directory}. The root README, AGENTS.md and CLAUDE.md describe the repository as a whole. Write what belongs to the workspace in ${directory}/README.md, or for agents in ${directory}/AGENTS.md.`;
1115
1200
  const problemsIn$4 = (file, source) => ({ directory, pattern }) => {
1116
1201
  const message = messageFor(directory);
@@ -1134,7 +1219,8 @@ const checkRootReadme = Effect.fn("checkRootReadme")(function* checkRootReadme(r
1134
1219
  const files = yield* RepositoryFiles;
1135
1220
  const names = yield* files.listedFiles(root);
1136
1221
  const readmes = pipe(names, Array.filter((name) => ROOT_DOC.test(name)));
1137
- const workspaces = yield* namedWorkspaces(root);
1222
+ const named = yield* namedWorkspaces(root);
1223
+ const workspaces = pipe(named, Array.filter((workspace) => !isCheckPolicy(workspace)));
1138
1224
  const found = yield* Effect.forEach(readmes, (name) => problemsInReadme(files.join(root, name), workspaces), { concurrency: READ_CONCURRENCY$9 });
1139
1225
  return Array.flatten(found);
1140
1226
  });
@@ -2107,6 +2193,116 @@ const analyzeProject = (owners) => (project) => {
2107
2193
  unowned: pipe(verdicts, Array.flatMap((found) => found.unowned))
2108
2194
  };
2109
2195
  };
2196
+ // src/features/value-owners/model/cache.ts
2197
+ const CACHE_DIRECTORY = [
2198
+ NODE_MODULES,
2199
+ ".cache",
2200
+ "msch",
2201
+ "value-owners"
2202
+ ];
2203
+ const CACHE_SUFFIX = ".json";
2204
+ const MANIFEST_ENTRY = "package.json";
2205
+ const FINGERPRINTED = ["src", "dist"];
2206
+ const EMPTY = "";
2207
+ const FIELD_SEPARATOR = "\0";
2208
+ const LINE_SEPARATOR = "\n";
2209
+ const ValueSchema = Schema.Union([Schema.String, Schema.Finite]);
2210
+ const UnownedSiteSchema = Schema.Struct({
2211
+ scope: Schema.Struct({
2212
+ name: Schema.String,
2213
+ dependencies: Schema.Array(Schema.String)
2214
+ }),
2215
+ file: Schema.String,
2216
+ start: Schema.Int,
2217
+ line: Schema.Int,
2218
+ column: Schema.Int,
2219
+ values: Schema.Array(ValueSchema)
2220
+ });
2221
+ const AnalysisSchema = Schema.Struct({
2222
+ problems: ProblemList,
2223
+ unowned: Schema.Array(UnownedSiteSchema)
2224
+ });
2225
+ const AnalysisJson = Schema.fromJsonString(AnalysisSchema);
2226
+ const hasher = Effect.gen(function* currentHasher() {
2227
+ return (yield* RepositoryFiles).hash;
2228
+ });
2229
+ const entryOf = (file, found) => `${file}${FIELD_SEPARATOR}${found}`;
2230
+ const fileDigest = (hash) => {
2231
+ const digests = /* @__PURE__ */ new Map();
2232
+ return (file) => Option.match(Option.fromUndefinedOr(digests.get(file)), {
2233
+ onSome: Effect.succeed,
2234
+ onNone: () => Effect.gen(function* readDigest() {
2235
+ const text = yield* (yield* RepositoryFiles).readFile(file);
2236
+ const found = yield* hash(Option.getOrElse(text, () => EMPTY));
2237
+ digests.set(file, found);
2238
+ return found;
2239
+ })
2240
+ });
2241
+ };
2242
+ const digestEntries = (digestFile) => (named) => pipe(named, Effect.forEach(([name, file]) => digestFile(file).pipe(Effect.map((found) => entryOf(name, found)))));
2243
+ const fingerprintedFiles = Effect.fn("fingerprintedFiles")(function* fingerprintedFiles(root) {
2244
+ const files = yield* RepositoryFiles;
2245
+ const nested = yield* pipe(FINGERPRINTED, Effect.forEach((entry) => {
2246
+ const base = files.join(root, entry);
2247
+ return files.walkDirectory(base).pipe(Effect.map(Array.map((file) => files.join(base, file))));
2248
+ }));
2249
+ return Array.sort([files.join(root, MANIFEST_ENTRY), ...Array.flatten(nested)], String$1.Order);
2250
+ });
2251
+ const fingerprintOf = Effect.fn("fingerprintOf")(function* fingerprintOf(hash) {
2252
+ const root = yield* nearestManifestDirectory(import.meta.dirname);
2253
+ const listed = yield* fingerprintedFiles(root);
2254
+ const entries = yield* digestEntries(fileDigest(hash))(pipe(listed, Array.map((file) => [file, file])));
2255
+ return yield* hash(Array.join(entries, LINE_SEPARATOR));
2256
+ });
2257
+ const analysisCache = Effect.fn("analysisCache")(function* analysisCache(root, owners) {
2258
+ const files = yield* RepositoryFiles;
2259
+ const hash = yield* hasher;
2260
+ const fingerprint = yield* fingerprintOf(hash);
2261
+ const salt = yield* hash(Array.join([fingerprint, owners], FIELD_SEPARATOR));
2262
+ return {
2263
+ root,
2264
+ directory: files.join(root, ...CACHE_DIRECTORY),
2265
+ salt,
2266
+ digestFile: fileDigest(hash),
2267
+ hash
2268
+ };
2269
+ });
2270
+ const keyOf = (cache) => (configPath, inputs) => Effect.gen(function* deriveKey() {
2271
+ const files = yield* RepositoryFiles;
2272
+ const entries = yield* digestEntries(cache.digestFile)(pipe(inputs.files, Array.map((file) => [file, files.join(cache.root, file)])));
2273
+ const header = [
2274
+ cache.salt,
2275
+ files.relative(cache.root, configPath),
2276
+ inputs.options
2277
+ ];
2278
+ return yield* cache.hash(Array.join([
2279
+ ...header,
2280
+ ...inputs.dependencies,
2281
+ ...entries
2282
+ ], LINE_SEPARATOR));
2283
+ });
2284
+ const entryFile = (cache, key) => `${cache.directory}/${key}${CACHE_SUFFIX}`;
2285
+ const readAnalysis = (cache) => (key) => Effect.gen(function* readCached() {
2286
+ const text = yield* (yield* RepositoryFiles).readFile(entryFile(cache, key));
2287
+ return yield* Option.match(text, {
2288
+ onNone: () => Effect.succeedNone,
2289
+ onSome: (found) => Schema.decodeEffect(AnalysisJson)(found).pipe(Effect.option)
2290
+ });
2291
+ });
2292
+ const writeAnalysis = (cache) => (key, analysis) => Effect.gen(function* writeCached() {
2293
+ const files = yield* RepositoryFiles;
2294
+ const text = yield* Schema.encodeEffect(AnalysisJson)(analysis).pipe(Effect.option);
2295
+ yield* Option.match(text, {
2296
+ onNone: () => Effect.void,
2297
+ onSome: (found) => files.writeFile(entryFile(cache, key), found)
2298
+ });
2299
+ });
2300
+ const pruneAnalyses = (cache) => (kept) => Effect.gen(function* pruneCached() {
2301
+ const files = yield* RepositoryFiles;
2302
+ const keep = new Set(pipe(kept, Array.map((key) => `${key}${CACHE_SUFFIX}`)));
2303
+ const present = yield* files.readDirectory(cache.directory);
2304
+ yield* pipe(present, Array.filter((name) => !keep.has(name)), Effect.forEach((name) => files.removeFile(files.join(cache.directory, name))), Effect.asVoid);
2305
+ });
2110
2306
  // src/features/value-owners/model/duplicates.ts
2111
2307
  const DUPLICATE_THRESHOLD = 1;
2112
2308
  const unownedSiteOf = (scope) => (site) => ({
@@ -2149,14 +2345,54 @@ const scopeOf = (project, configPath) => ({
2149
2345
  name: Option.getOrElse(project.packageName, () => configPath),
2150
2346
  dependencies: project.workspaceDependencies
2151
2347
  });
2152
- const analyzeProjects = (workspace, owners) => (configPaths) => pipe(configPaths, Effect.forEach((configPath) => withProject(workspace)(configPath)((project) => Effect.sync(() => {
2348
+ const freshAnalysis = ({ workspace, owners }) => (configPath) => withProject(workspace)(configPath)((project) => Effect.sync(() => {
2153
2349
  const analysis = analyzeProject(owners)(project);
2154
2350
  const scope = scopeOf(project, configPath);
2155
2351
  return {
2156
2352
  problems: analysis.problems,
2157
2353
  unowned: pipe(analysis.unowned, Array.map(unownedSiteOf(scope)))
2158
2354
  };
2159
- }).pipe(Effect.withSpan("analyzeProject")))), Effect.map(Array.getSomes));
2355
+ }).pipe(Effect.withSpan("analyzeProject")));
2356
+ const keyedAnalysis = (context) => (configPath, key) => Effect.gen(function* lookupAnalysis() {
2357
+ const cached = yield* readAnalysis(context.cache)(key);
2358
+ if (Option.isSome(cached)) return cached;
2359
+ const fresh = yield* freshAnalysis(context)(configPath);
2360
+ yield* Option.match(fresh, {
2361
+ onNone: () => Effect.void,
2362
+ onSome: (analysis) => writeAnalysis(context.cache)(key, analysis)
2363
+ });
2364
+ return fresh;
2365
+ });
2366
+ const analyzeConfig = (context) => (configPath) => Effect.gen(function* analyzeOne() {
2367
+ const inputs = yield* projectInputs(context)(configPath);
2368
+ if (Option.isNone(inputs)) return Option.none();
2369
+ const key = yield* keyOf(context.cache)(configPath, inputs.value);
2370
+ const analysis = yield* keyedAnalysis(context)(configPath, key);
2371
+ return pipe(analysis, Option.map((found) => [key, found]));
2372
+ });
2373
+ const encodeOwners = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
2374
+ const cacheFor = Effect.fn("cacheFor")(function* cacheFor(root, owners) {
2375
+ const plain = pipe(owners, Array.map((owner) => ({
2376
+ ...owner,
2377
+ packageName: Option.getOrNull(owner.packageName)
2378
+ })));
2379
+ const encoded = yield* encodeOwners(plain).pipe(Effect.orElseSucceed(() => ""));
2380
+ return yield* analysisCache(root, encoded);
2381
+ });
2382
+ const analyzeProjects = Effect.fn("analyzeProjects")(function* analyzeProjects(workspace, owners, configPaths) {
2383
+ const files = yield* RepositoryFiles;
2384
+ const cache = yield* cacheFor(workspace.root, owners);
2385
+ const listed = yield* files.listedFiles(workspace.root);
2386
+ const keyed = yield* pipe(configPaths, Effect.forEach(analyzeConfig({
2387
+ workspace,
2388
+ owners,
2389
+ cache,
2390
+ listed
2391
+ })));
2392
+ const found = Array.getSomes(keyed);
2393
+ yield* pruneAnalyses(cache)(pipe(found, Array.map(([key]) => key)));
2394
+ return pipe(found, Array.map(([, analysis]) => analysis));
2395
+ });
2160
2396
  const checkRepository = Effect.fn("checkRepository")(function* checkRepository(root) {
2161
2397
  const files = yield* RepositoryFiles;
2162
2398
  const workspace = {
@@ -2166,7 +2402,7 @@ const checkRepository = Effect.fn("checkRepository")(function* checkRepository(r
2166
2402
  };
2167
2403
  const configPaths = yield* listConfigFiles(root);
2168
2404
  const ownerScan = yield* scanOwners(workspace, configPaths);
2169
- const analyses = yield* analyzeProjects(workspace, ownerScan.owners)(configPaths);
2405
+ const analyses = yield* analyzeProjects(workspace, ownerScan.owners, configPaths);
2170
2406
  const relative = (file) => files.relative(root, file);
2171
2407
  const unowned = pipe(analyses, Array.flatMap((analysis) => analysis.unowned));
2172
2408
  return sortProblems([
@@ -2627,6 +2863,7 @@ const SETUP_PATTERNS = [
2627
2863
  /(?<![\w./@-])cargo[ \t]+(?:vendor|fetch)\b/gu,
2628
2864
  /\buses:\s*["']?(?:dtolnay\/rust-toolchain|actions-rust-lang\/setup-rust-toolchain|actions-rs\/toolchain|moonrepo\/setup-rust)\b/gu
2629
2865
  ];
2866
+ const INSTALL_PATTERNS = [/(?<![\w./@-])cargo[ \t]+b?install\b/gu];
2630
2867
  const TOOL_PATTERNS = [/^[ \t]*["']?(?:rust|rustup)["']?[ \t]*(?:=|[ \t]+\S)/gmu];
2631
2868
  const START = 0;
2632
2869
  const LAST_SEGMENT = 1;
@@ -2658,17 +2895,24 @@ const generatedCargoConfig = (entry, source) => {
2658
2895
  return [pnpmCargoConfig(entry)];
2659
2896
  };
2660
2897
  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.`);
2661
- const setupProblem = ({ file }, source) => (found) => ({
2898
+ const setupProblem = ({ file }, source, advice) => (found) => ({
2662
2899
  file,
2663
2900
  ...positionOf(source)(found.index ?? WHOLE_MATCH),
2664
2901
  rule: SETUP_RULE,
2665
- 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])}\`.`
2902
+ message: advice(String$1.trim(found[WHOLE_MATCH]))
2666
2903
  });
2904
+ const removeSetup = (command) => `pnpm install already installs the toolchain in rust-toolchain.toml and vendors the crates in Cargo.lock. Remove \`${command}\`.`;
2905
+ const buildInstead = (command) => `\`${command}\` fetches crates that pnpm does not vendor. Add the tool as a dependency of a Cargo workspace that pnpm vendors, and build its binary there with \`cargo build -p <crate> --bin <name>\`.`;
2667
2906
  const setupPatternsFor = (entry) => {
2668
2907
  if (isToolVersions(entry)) return [...SETUP_PATTERNS, ...TOOL_PATTERNS];
2669
2908
  return SETUP_PATTERNS;
2670
2909
  };
2671
- 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)));
2910
+ const matchesOf = (source) => (patterns) => pipe(patterns, Array.flatMap((pattern) => Array.fromIterable(String$1.matchAll(pattern)(source))));
2911
+ const setupProblems = (entry, source) => {
2912
+ const found = matchesOf(source);
2913
+ const installs = pipe(found(INSTALL_PATTERNS), Array.map(setupProblem(entry, source, buildInstead)));
2914
+ return pipe(found(setupPatternsFor(entry)), Array.map(setupProblem(entry, source, removeSetup)), Array.appendAll(installs), Array.appendAll(generatedCargoConfig(entry, source)));
2915
+ };
2672
2916
  const matches = (pattern) => ({ name }) => pattern.test(name);
2673
2917
  const isCargoManifest = matches(CARGO_MANIFEST_FILE);
2674
2918
  const isForeignLockfile = matches(FOREIGN_LOCKFILE);
@@ -2682,7 +2926,7 @@ const ancestorsOf = (directory) => {
2682
2926
  const readsCargoLock = (manifests, workspaces) => ({ name }) => {
2683
2927
  const directory = directoryOf(name);
2684
2928
  const insideWorkspace = pipe(ancestorsOf(directory), Array.some((ancestor) => Array.contains(workspaces, ancestor)));
2685
- return Array.contains(manifests, directory) && !insideWorkspace;
2929
+ return Array.contains(manifests, directory) && (Array.contains(workspaces, directory) || !insideWorkspace);
2686
2930
  };
2687
2931
  const isWorkspaceManifest = (source) => Option.exists(source, (text) => CARGO_WORKSPACE.test(text));
2688
2932
  const directoriesOf = (entries) => pipe(entries, Array.map(({ name }) => directoryOf(name)));