@r_masseater/msch 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +7 -0
  2. package/dist/cargo-inputs.d.mts +14 -0
  3. package/dist/cargo-inputs.mjs +226 -0
  4. package/dist/cargo-inputs.mjs.map +1 -0
  5. package/dist/{cli-contract-8SnKqhGw.mjs → cli-contract-DdTV5DaG.mjs} +2 -2
  6. package/dist/{cli-contract-8SnKqhGw.mjs.map → cli-contract-DdTV5DaG.mjs.map} +1 -1
  7. package/dist/cli.mjs +475 -462
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/config.d.mts +2 -2
  10. package/dist/config.mjs +9 -6
  11. package/dist/config.mjs.map +1 -1
  12. package/dist/decision-rules.d.mts +1 -1
  13. package/dist/decision-rules.mjs +1 -1
  14. package/dist/{define-lint-preset-BYMl7wof.mjs → define-lint-preset-DKJku2ZR.mjs} +124 -85
  15. package/dist/define-lint-preset-DKJku2ZR.mjs.map +1 -0
  16. package/dist/ignored-directories-CfACwIvu.mjs +50 -0
  17. package/dist/ignored-directories-CfACwIvu.mjs.map +1 -0
  18. package/dist/{index-lM4Pphgz.d.mts → index-BwiAHe_u.d.mts} +21 -16
  19. package/dist/{index-CcVKuHBw.d.mts → index-DdJXnW1q.d.mts} +2 -2
  20. package/dist/lint.d.mts +2 -2
  21. package/dist/lint.mjs +1 -1
  22. package/dist/oxlint.mjs +1 -1
  23. package/dist/{package-A62qq8pE.mjs → package-vbK0Qycn.mjs} +2 -2
  24. package/dist/{package-A62qq8pE.mjs.map → package-vbK0Qycn.mjs.map} +1 -1
  25. package/dist/publish.d.mts +1 -0
  26. package/dist/publish.mjs +578 -0
  27. package/dist/publish.mjs.map +1 -0
  28. package/dist/{repository-files-CorshdqY.mjs → repository-files-CPfBA4mf.mjs} +7 -1
  29. package/dist/repository-files-CPfBA4mf.mjs.map +1 -0
  30. package/dist/runtime-Dc5gCUSF.mjs +29 -0
  31. package/dist/runtime-Dc5gCUSF.mjs.map +1 -0
  32. package/dist/workspace-settings.d.mts +1 -1
  33. package/dist/workspace-settings.mjs +6 -63
  34. package/dist/workspace-settings.mjs.map +1 -1
  35. package/package.json +17 -7
  36. package/skills/msch-checks/SKILL.md +0 -5
  37. package/skills/publishing/SKILL.md +44 -0
  38. package/skills/repository-config/SKILL.md +8 -7
  39. package/src/app/vite.d.ts +4 -0
  40. package/dist/define-lint-preset-BYMl7wof.mjs.map +0 -1
  41. package/dist/repository-files-CorshdqY.mjs.map +0 -1
package/README.md CHANGED
@@ -2,11 +2,17 @@
2
2
 
3
3
  msch packages the check policy shared across masseater's repositories. It requires Vite+ and Node.js 26 or later.
4
4
 
5
+ ```sh
6
+ vp add -D @r_masseater/msch
7
+ vp exec msch
8
+ ```
9
+
5
10
  Guidance for agents ships in the package as TanStack Intent skills. Load one with `vp exec intent load @r_masseater/msch#<skill>`.
6
11
 
7
12
  | Skill | When to use |
8
13
  | -------------------- | ------------------------------------------- |
9
14
  | `msch-checks` | Running msch and fixing what it reports |
15
+ | `publishing` | Releasing a workspace to npm or GitHub |
10
16
  | `repository-config` | Building the root `vite.config.ts` |
11
17
  | `workspace-settings` | Changing the settings of a single workspace |
12
18
 
@@ -15,6 +21,7 @@ The package has these entry points.
15
21
  | Entry point | Contents |
16
22
  | -------------------------------------- | ------------------------------------------------------------ |
17
23
  | `msch` (bin) | Runs every check against the repository |
24
+ | `msch-publish` (bin) | Plans and publishes a workspace to npm and GitHub Releases |
18
25
  | `@r_masseater/msch/config` | `repositoryConfig`, which builds the root `vite.config.ts` |
19
26
  | `@r_masseater/msch/workspace-settings` | `workspaceSettings`, which loads the settings of a workspace |
20
27
  | `@r_masseater/msch/lint` | The oxlint preset and rule sets |
@@ -0,0 +1,14 @@
1
+ import { Option, Schema } from "effect";
2
+ type CargoInput = {
3
+ readonly pattern: string;
4
+ readonly base: "workspace";
5
+ } | {
6
+ readonly auto: true;
7
+ };
8
+ interface CargoInputOptions {
9
+ readonly directory: string;
10
+ readonly extras?: readonly string[];
11
+ }
12
+ export declare const cargoInputs: (options: CargoInputOptions) => Promise<readonly CargoInput[]>;
13
+ export type { CargoInput, CargoInputOptions };
14
+ //# sourceMappingURL=cargo-inputs.d.mts.map
@@ -0,0 +1,226 @@
1
+ import { t as collectIgnoredDirectories } from "./ignored-directories-CfACwIvu.mjs";
2
+ import { i as nodeServicesLayer, n as RepositoryFiles, r as nodeRepositoryFiles, t as NODE_MODULES } from "./repository-files-CPfBA4mf.mjs";
3
+ import { Array, Effect, Layer, Option, Record, Schema, Stream, String, pipe } from "effect";
4
+ import { ChildProcess } from "effect/process";
5
+ const LOCK_FILE = "Cargo.lock";
6
+ const MANIFEST_FILE = "Cargo.toml";
7
+ const IGNORE_FILE = ".gitignore";
8
+ const LAST_SEGMENT = /\/[^/]*$/u;
9
+ const NEXT = 1;
10
+ const IgnoredDirectory = Schema.Struct({
11
+ pattern: Schema.String,
12
+ base: Schema.Literal("workspace")
13
+ });
14
+ const CargoPackageSchema = Schema.Struct({
15
+ id: Schema.String,
16
+ manifest_path: Schema.String,
17
+ source: Schema.NullOr(Schema.String)
18
+ });
19
+ const CargoNode = Schema.Struct({
20
+ id: Schema.String,
21
+ deps: Schema.Array(Schema.Struct({ pkg: Schema.String }))
22
+ });
23
+ const CargoMetadataSchema = Schema.Struct({
24
+ packages: Schema.Array(CargoPackageSchema),
25
+ resolve: Schema.Struct({ nodes: Schema.Array(CargoNode) }),
26
+ workspace_members: Schema.Array(Schema.String),
27
+ workspace_root: Schema.String
28
+ });
29
+ const CargoWorkspaceSchema = Schema.Struct({
30
+ metadata: CargoMetadataSchema,
31
+ ignored: Schema.Array(IgnoredDirectory)
32
+ });
33
+ const normalized = String.replaceAll("\\", "/");
34
+ const relativeTo = (root) => (file) => {
35
+ const prefix = `${normalized(root)}/`;
36
+ const path = normalized(file);
37
+ return Option.some(String.slice(prefix.length)(path)).pipe(Option.filter(() => String.startsWith(prefix)(path)));
38
+ };
39
+ const directoryOf = (file) => pipe(normalized(file), String.replace(LAST_SEGMENT, ""));
40
+ const isWithin = (directory) => (path) => String.isEmpty(directory) || path === directory || String.startsWith(`${directory}/`)(path);
41
+ const isLocal = (entry) => entry.source === null;
42
+ const reachable = (edges, seen, frontier) => {
43
+ const fresh = pipe(frontier, Array.dedupe, Array.filter((id) => !Array.contains(seen, id)));
44
+ if (Array.isReadonlyArrayEmpty(fresh)) return seen;
45
+ const next = pipe(fresh, Array.flatMap((id) => edges[id] ?? []));
46
+ return reachable(edges, [...seen, ...fresh], next);
47
+ };
48
+ const closureOf = (metadata) => (roots) => {
49
+ const edges = Record.fromEntries(pipe(metadata.resolve.nodes, Array.map((node) => [node.id, pipe(node.deps, Array.map(({ pkg }) => pkg))])));
50
+ const ids = new Set(reachable(edges, [], roots));
51
+ return pipe(metadata.packages, Array.filter((entry) => ids.has(entry.id)));
52
+ };
53
+ const ancestorsOf = (directory) => {
54
+ const parts = String.split(directory, "/");
55
+ return pipe(parts, Array.map((_part, index) => pipe(parts, Array.take(index + NEXT), Array.join("/"))));
56
+ };
57
+ const keysOf = (metadata) => {
58
+ const relative = relativeTo(metadata.workspace_root);
59
+ const ignoreFiles = pipe(metadata.packages, Array.filter(isLocal), Array.flatMap((entry) => Option.toArray(relative(directoryOf(entry.manifest_path)))), Array.flatMap(ancestorsOf), Array.map((directory) => `${directory}/${IGNORE_FILE}`));
60
+ return Array.sort(Array.dedupe([
61
+ LOCK_FILE,
62
+ MANIFEST_FILE,
63
+ IGNORE_FILE,
64
+ ...ignoreFiles
65
+ ]), String.Order);
66
+ };
67
+ // src/features/derive-cargo-inputs/model/cargo-inputs.ts
68
+ const NEGATION = "!";
69
+ const CONTENTS = "/**";
70
+ const ANYWHERE = "**/";
71
+ const CLOSURE_DIRECTORY = "node_modules/.cache/msch/cargo-inputs";
72
+ const CLOSURE_SUFFIX = ".lock";
73
+ const ROOT_SLUG = "root";
74
+ const SLUG_SEPARATOR = "__";
75
+ const LINE = "\n";
76
+ const WORKSPACE_FILES = [
77
+ "Cargo.toml",
78
+ "rust-toolchain.toml",
79
+ ".cargo/**"
80
+ ];
81
+ const GENERATED = ["node_modules", "dist"];
82
+ const workspaceInput = (pattern) => ({
83
+ pattern,
84
+ base: "workspace"
85
+ });
86
+ const withoutContents = String.replace(CONTENTS, "");
87
+ const slugOf = (owner) => Option.match(Option.liftPredicate(owner, String.isNonEmpty), {
88
+ onNone: () => ROOT_SLUG,
89
+ onSome: String.replaceAll("/", SLUG_SEPARATOR)
90
+ });
91
+ const ownedRoots = (metadata, owner) => {
92
+ const relative = relativeTo(metadata.workspace_root);
93
+ const owned = new Set(pipe(metadata.packages, Array.filter((entry) => pipe(relative(directoryOf(entry.manifest_path)), Option.exists(isWithin(owner)))), Array.map((entry) => entry.id)));
94
+ return pipe(metadata.workspace_members, Array.filter((id) => owned.has(id)));
95
+ };
96
+ const scopedExtra = (owner) => (extra) => {
97
+ if (String.startsWith(NEGATION)(extra)) return `${NEGATION}${owner}/${String.slice(1)(extra)}`;
98
+ return `${owner}/${extra}`;
99
+ };
100
+ const excludedFrom = (workspace, walked, kept) => pipe(workspace.ignored, Array.filter(({ pattern }) => {
101
+ const covered = withoutContents(String.slice(1)(pattern));
102
+ return (String.startsWith(ANYWHERE)(covered) || pipe(walked, Array.some((dir) => isWithin(dir)(covered)))) && !pipe(kept, Array.some(isWithin(covered)));
103
+ }));
104
+ const generatedIn = (walked) => pipe(walked, Array.flatMap((dir) => pipe(GENERATED, Array.map((name) => `${NEGATION}${dir}/${ANYWHERE}${name}${CONTENTS}`))));
105
+ const externalIds = (closure) => pipe(closure, Array.filter((entry) => !isLocal(entry)), Array.map((entry) => entry.id));
106
+ /** @internal */
107
+ const cargoInputsOf = ({ workspace, directory, extras }) => {
108
+ const { metadata } = workspace;
109
+ const relative = relativeTo(metadata.workspace_root);
110
+ const owner = Option.getOrElse(relative(directory), () => "");
111
+ const closure = closureOf(metadata)(ownedRoots(metadata, owner));
112
+ const walked = Array.sort(pipe(closure, Array.filter(isLocal), Array.flatMap((entry) => Option.toArray(relative(directoryOf(entry.manifest_path))))), String.Order);
113
+ const added = pipe(extras, Array.map(scopedExtra(owner)));
114
+ const kept = pipe(added, Array.filter((extra) => !String.startsWith(NEGATION)(extra)), Array.map(withoutContents));
115
+ const closureFile = `${CLOSURE_DIRECTORY}/${slugOf(owner)}${CLOSURE_SUFFIX}`;
116
+ return {
117
+ inputs: [
118
+ ...pipe(walked, Array.map((dir) => workspaceInput(`${dir}${CONTENTS}`))),
119
+ workspaceInput(closureFile),
120
+ ...pipe(WORKSPACE_FILES, Array.map(workspaceInput)),
121
+ ...excludedFrom(workspace, walked, kept),
122
+ ...pipe(generatedIn(walked), Array.map(workspaceInput)),
123
+ ...pipe(added, Array.map(workspaceInput))
124
+ ],
125
+ closureFile,
126
+ closure: Array.join(Array.sort(externalIds(closure), String.Order), LINE)
127
+ };
128
+ };
129
+ // src/features/derive-cargo-inputs/model/derive.ts
130
+ const KEY_SEPARATOR = "\0";
131
+ const READ_CONCURRENCY = 16;
132
+ const CACHE_FILE = [
133
+ NODE_MODULES,
134
+ ".cache",
135
+ "msch",
136
+ "cargo-workspace.json"
137
+ ];
138
+ const METADATA_ARGS = [
139
+ "metadata",
140
+ "--format-version",
141
+ "1",
142
+ "--offline",
143
+ "--locked"
144
+ ];
145
+ const CachedWorkspace = Schema.fromJsonString(Schema.Struct({
146
+ fingerprint: Schema.String,
147
+ keys: Schema.Array(Schema.String),
148
+ workspace: CargoWorkspaceSchema
149
+ }));
150
+ const decodeMetadata = Schema.decodeUnknownEffect(Schema.fromJsonString(CargoMetadataSchema));
151
+ const decodeCached = Schema.decodeUnknownOption(CachedWorkspace);
152
+ const encodeCached = Schema.encodeEffect(CachedWorkspace);
153
+ const AUTO = [{ auto: true }];
154
+ const nodeLayer = Layer.provideMerge(nodeRepositoryFiles, nodeServicesLayer);
155
+ const fingerprintOf = Effect.fn("fingerprintOf")(function* fingerprintOf(root, keys) {
156
+ const files = yield* RepositoryFiles;
157
+ const texts = yield* Effect.forEach(keys, (key) => files.readFile(files.join(root, key)), { concurrency: READ_CONCURRENCY });
158
+ const joined = pipe(keys, Array.zip(texts), Array.map(([key, text]) => `${key}${KEY_SEPARATOR}${Option.getOrElse(text, () => "")}`), Array.join(KEY_SEPARATOR));
159
+ return yield* files.hash(joined);
160
+ });
161
+ const cachedWorkspace = Effect.fn("cachedWorkspace")(function* cachedWorkspace(root) {
162
+ const files = yield* RepositoryFiles;
163
+ const text = yield* files.readFile(files.join(root, ...CACHE_FILE));
164
+ const cached = pipe(text, Option.flatMap(decodeCached));
165
+ if (Option.isNone(cached)) return Option.none();
166
+ const fingerprint = yield* fingerprintOf(root, cached.value.keys);
167
+ return Option.some(cached.value.workspace).pipe(Option.filter(() => fingerprint === cached.value.fingerprint));
168
+ });
169
+ const readWorkspace = Effect.fn("readWorkspace")(function* readWorkspace(root) {
170
+ const files = yield* RepositoryFiles;
171
+ const output = yield* (yield* ChildProcess.make("cargo", METADATA_ARGS, {
172
+ cwd: root,
173
+ extendEnv: true,
174
+ stdin: "ignore"
175
+ })).stdout.pipe(Stream.decodeText(), Stream.mkString);
176
+ const metadata = yield* decodeMetadata(output);
177
+ const workspace = {
178
+ metadata,
179
+ ignored: yield* collectIgnoredDirectories(root)
180
+ };
181
+ const keys = keysOf(metadata);
182
+ const fingerprint = yield* fingerprintOf(root, keys);
183
+ const text = yield* encodeCached({
184
+ fingerprint,
185
+ keys,
186
+ workspace
187
+ });
188
+ yield* files.writeFile(files.join(root, ...CACHE_FILE), text);
189
+ return workspace;
190
+ }, Effect.scoped);
191
+ const lockDirectory = (directory) => Effect.gen(function* findLockDirectory() {
192
+ const files = yield* RepositoryFiles;
193
+ if (yield* files.exists(files.join(directory, "Cargo.lock"))) return Option.some(directory);
194
+ const parent = files.dirname(directory);
195
+ if (parent === directory) return Option.none();
196
+ return yield* lockDirectory(parent);
197
+ });
198
+ const inputsIn = Effect.fn("inputsIn")(function* inputsIn(root, directory, extras) {
199
+ const files = yield* RepositoryFiles;
200
+ const cached = yield* cachedWorkspace(root);
201
+ const workspace = yield* Option.match(cached, {
202
+ onNone: () => readWorkspace(root),
203
+ onSome: Effect.succeed
204
+ });
205
+ const derived = cargoInputsOf({
206
+ workspace,
207
+ directory,
208
+ extras
209
+ });
210
+ const file = files.join(root, derived.closureFile);
211
+ const written = yield* files.readFile(file);
212
+ if (!Option.exists(written, (text) => text === derived.closure)) yield* files.writeFile(file, derived.closure);
213
+ return derived.inputs;
214
+ });
215
+ const deriveCargoInputs = Effect.fn("deriveCargoInputs")(function* deriveCargoInputs({ directory, extras = [] }) {
216
+ const absolute = (yield* RepositoryFiles).resolve(directory);
217
+ const root = yield* lockDirectory(absolute);
218
+ return yield* Option.match(root, {
219
+ onNone: () => Effect.succeed(AUTO),
220
+ onSome: (found) => inputsIn(found, absolute, extras)
221
+ });
222
+ });
223
+ const cargoInputs = (options) => Effect.runPromise(deriveCargoInputs(options).pipe(Effect.orElseSucceed(() => AUTO), Effect.provide(nodeLayer)));
224
+ export { cargoInputs };
225
+
226
+ //# sourceMappingURL=cargo-inputs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cargo-inputs.mjs","names":["Str","Arr","Rec","Str","Arr","Arr"],"sources":["../src/features/derive-cargo-inputs/model/cargo-metadata.ts","../src/features/derive-cargo-inputs/model/cargo-inputs.ts","../src/features/derive-cargo-inputs/model/derive.ts"],"sourcesContent":["import { Array as Arr, Option, Record as Rec, Schema, String as Str, pipe } from \"effect\";\n\nexport const SEPARATOR = \"/\";\nexport const LOCK_FILE = \"Cargo.lock\";\nexport const MANIFEST_FILE = \"Cargo.toml\";\nconst IGNORE_FILE = \".gitignore\";\nconst LAST_SEGMENT = /\\/[^/]*$/u;\nconst NEXT = 1;\n\nconst IgnoredDirectory = Schema.Struct({\n pattern: Schema.String,\n base: Schema.Literal(\"workspace\"),\n});\nconst CargoPackageSchema = Schema.Struct({\n id: Schema.String,\n manifest_path: Schema.String,\n source: Schema.NullOr(Schema.String),\n});\nconst CargoNode = Schema.Struct({\n id: Schema.String,\n deps: Schema.Array(Schema.Struct({ pkg: Schema.String })),\n});\nexport const CargoMetadataSchema = Schema.Struct({\n packages: Schema.Array(CargoPackageSchema),\n resolve: Schema.Struct({ nodes: Schema.Array(CargoNode) }),\n workspace_members: Schema.Array(Schema.String),\n workspace_root: Schema.String,\n});\nexport const CargoWorkspaceSchema = Schema.Struct({\n metadata: CargoMetadataSchema,\n ignored: Schema.Array(IgnoredDirectory),\n});\nexport type CargoMetadata = typeof CargoMetadataSchema.Type;\nexport type CargoWorkspace = typeof CargoWorkspaceSchema.Type;\nexport type CargoPackage = typeof CargoPackageSchema.Type;\n\nconst normalized = Str.replaceAll(\"\\\\\", SEPARATOR);\n\nexport const relativeTo =\n (root: string) =>\n (file: string): Option.Option<string> => {\n const prefix = `${normalized(root)}${SEPARATOR}`;\n const path = normalized(file);\n return Option.some(Str.slice(prefix.length)(path)).pipe(\n Option.filter(() => Str.startsWith(prefix)(path)),\n );\n };\n\nexport const directoryOf = (file: string): string =>\n pipe(normalized(file), Str.replace(LAST_SEGMENT, \"\"));\n\nexport const isWithin =\n (directory: string) =>\n (path: string): boolean =>\n Str.isEmpty(directory) ||\n path === directory ||\n Str.startsWith(`${directory}${SEPARATOR}`)(path);\n\nexport const isLocal = (entry: CargoPackage): boolean => entry.source === null;\n\nconst reachable = (\n edges: Readonly<Record<string, readonly string[]>>,\n seen: readonly string[],\n frontier: readonly string[],\n): readonly string[] => {\n const fresh = pipe(\n frontier,\n Arr.dedupe,\n Arr.filter((id) => !Arr.contains(seen, id)),\n );\n if (Arr.isReadonlyArrayEmpty(fresh)) {\n return seen;\n }\n const next = pipe(\n fresh,\n Arr.flatMap((id) => edges[id] ?? []),\n );\n return reachable(edges, [...seen, ...fresh], next);\n};\n\nexport const closureOf =\n (metadata: CargoMetadata) =>\n (roots: readonly string[]): readonly CargoPackage[] => {\n const edges = Rec.fromEntries(\n pipe(\n metadata.resolve.nodes,\n Arr.map(\n (node) =>\n [\n node.id,\n pipe(\n node.deps,\n Arr.map(({ pkg }) => pkg),\n ),\n ] as const,\n ),\n ),\n );\n const ids = new Set(reachable(edges, [], roots));\n return pipe(\n metadata.packages,\n Arr.filter((entry) => ids.has(entry.id)),\n );\n };\n\nconst ancestorsOf = (directory: string): readonly string[] => {\n const parts = Str.split(directory, SEPARATOR);\n return pipe(\n parts,\n Arr.map((_part, index) => pipe(parts, Arr.take(index + NEXT), Arr.join(SEPARATOR))),\n );\n};\n\nexport const keysOf = (metadata: CargoMetadata): readonly string[] => {\n const relative = relativeTo(metadata.workspace_root);\n const ignoreFiles = pipe(\n metadata.packages,\n Arr.filter(isLocal),\n Arr.flatMap((entry) => Option.toArray(relative(directoryOf(entry.manifest_path)))),\n Arr.flatMap(ancestorsOf),\n Arr.map((directory) => `${directory}${SEPARATOR}${IGNORE_FILE}`),\n );\n return Arr.sort(Arr.dedupe([LOCK_FILE, MANIFEST_FILE, IGNORE_FILE, ...ignoreFiles]), Str.Order);\n};\n","import { Array as Arr, Option, String as Str, pipe } from \"effect\";\n\nimport {\n SEPARATOR,\n closureOf,\n directoryOf,\n isLocal,\n isWithin,\n relativeTo,\n} from \"./cargo-metadata.ts\";\nimport type { CargoMetadata, CargoPackage, CargoWorkspace } from \"./cargo-metadata.ts\";\n\nconst NEGATION = \"!\";\nconst CONTENTS = \"/**\";\nconst ANYWHERE = \"**/\";\nconst CLOSURE_DIRECTORY = \"node_modules/.cache/msch/cargo-inputs\";\nconst CLOSURE_SUFFIX = \".lock\";\nconst ROOT_SLUG = \"root\";\nconst SLUG_SEPARATOR = \"__\";\nconst LINE = \"\\n\";\nconst WORKSPACE_FILES = [\"Cargo.toml\", \"rust-toolchain.toml\", \".cargo/**\"] as const;\nconst GENERATED = [\"node_modules\", \"dist\"] as const;\n\nexport type CargoInput =\n | { readonly pattern: string; readonly base: \"workspace\" }\n | { readonly auto: true };\n\nexport interface DerivedInputs {\n readonly inputs: readonly CargoInput[];\n readonly closureFile: string;\n readonly closure: string;\n}\n\nexport interface CargoInputRequest {\n readonly workspace: CargoWorkspace;\n readonly directory: string;\n readonly extras: readonly string[];\n}\n\nconst workspaceInput = (pattern: string): CargoInput => ({ pattern, base: \"workspace\" });\n\nconst withoutContents = Str.replace(CONTENTS, \"\");\n\nconst slugOf = (owner: string): string =>\n Option.match(Option.liftPredicate(owner, Str.isNonEmpty), {\n onNone: () => ROOT_SLUG,\n onSome: Str.replaceAll(SEPARATOR, SLUG_SEPARATOR),\n });\n\nconst ownedRoots = (metadata: CargoMetadata, owner: string): readonly string[] => {\n const relative = relativeTo(metadata.workspace_root);\n const owned = new Set(\n pipe(\n metadata.packages,\n Arr.filter((entry) =>\n pipe(relative(directoryOf(entry.manifest_path)), Option.exists(isWithin(owner))),\n ),\n Arr.map((entry) => entry.id),\n ),\n );\n return pipe(\n metadata.workspace_members,\n Arr.filter((id) => owned.has(id)),\n );\n};\n\nconst scopedExtra =\n (owner: string) =>\n (extra: string): string => {\n if (Str.startsWith(NEGATION)(extra)) {\n return `${NEGATION}${owner}${SEPARATOR}${Str.slice(NEGATION.length)(extra)}`;\n }\n return `${owner}${SEPARATOR}${extra}`;\n };\n\nconst excludedFrom = (\n workspace: CargoWorkspace,\n walked: readonly string[],\n kept: readonly string[],\n): readonly CargoInput[] =>\n pipe(\n workspace.ignored,\n Arr.filter(({ pattern }) => {\n const covered = withoutContents(Str.slice(NEGATION.length)(pattern));\n const applies =\n Str.startsWith(ANYWHERE)(covered) ||\n pipe(\n walked,\n Arr.some((dir) => isWithin(dir)(covered)),\n );\n return applies && !pipe(kept, Arr.some(isWithin(covered)));\n }),\n );\n\nconst generatedIn = (walked: readonly string[]): readonly string[] =>\n pipe(\n walked,\n Arr.flatMap((dir) =>\n pipe(\n GENERATED,\n Arr.map((name) => `${NEGATION}${dir}${SEPARATOR}${ANYWHERE}${name}${CONTENTS}`),\n ),\n ),\n );\n\nconst externalIds = (closure: readonly CargoPackage[]): readonly string[] =>\n pipe(\n closure,\n Arr.filter((entry) => !isLocal(entry)),\n Arr.map((entry) => entry.id),\n );\n\n/** @internal */\nexport const cargoInputsOf = ({\n workspace,\n directory,\n extras,\n}: CargoInputRequest): DerivedInputs => {\n const { metadata } = workspace;\n const relative = relativeTo(metadata.workspace_root);\n const owner = Option.getOrElse(relative(directory), () => \"\");\n const closure = closureOf(metadata)(ownedRoots(metadata, owner));\n const walked = Arr.sort(\n pipe(\n closure,\n Arr.filter(isLocal),\n Arr.flatMap((entry) => Option.toArray(relative(directoryOf(entry.manifest_path)))),\n ),\n Str.Order,\n );\n const added = pipe(extras, Arr.map(scopedExtra(owner)));\n const kept = pipe(\n added,\n Arr.filter((extra) => !Str.startsWith(NEGATION)(extra)),\n Arr.map(withoutContents),\n );\n const closureFile = `${CLOSURE_DIRECTORY}${SEPARATOR}${slugOf(owner)}${CLOSURE_SUFFIX}`;\n return {\n inputs: [\n ...pipe(\n walked,\n Arr.map((dir) => workspaceInput(`${dir}${CONTENTS}`)),\n ),\n workspaceInput(closureFile),\n ...pipe(WORKSPACE_FILES, Arr.map(workspaceInput)),\n ...excludedFrom(workspace, walked, kept),\n ...pipe(generatedIn(walked), Arr.map(workspaceInput)),\n ...pipe(added, Arr.map(workspaceInput)),\n ],\n closureFile,\n closure: Arr.join(Arr.sort(externalIds(closure), Str.Order), LINE),\n };\n};\n","import { Array as Arr, Effect, Layer, Option, Schema, Stream, pipe } from \"effect\";\nimport { ChildProcess } from \"effect/process\";\n\nimport { collectIgnoredDirectories } from \"#/shared/lib/ignored-directories.ts\";\nimport {\n NODE_MODULES,\n RepositoryFiles,\n nodeRepositoryFiles,\n nodeServicesLayer,\n} from \"#/shared/lib/repository-files.ts\";\n\nimport { cargoInputsOf } from \"./cargo-inputs.ts\";\nimport type { CargoInput } from \"./cargo-inputs.ts\";\nimport { CargoMetadataSchema, CargoWorkspaceSchema, LOCK_FILE, keysOf } from \"./cargo-metadata.ts\";\nimport type { CargoWorkspace } from \"./cargo-metadata.ts\";\n\nconst KEY_SEPARATOR = \"\\u0000\";\nconst READ_CONCURRENCY = 16;\nconst CACHE_FILE = [NODE_MODULES, \".cache\", \"msch\", \"cargo-workspace.json\"] as const;\nconst METADATA_ARGS = [\"metadata\", \"--format-version\", \"1\", \"--offline\", \"--locked\"];\n\nconst CachedWorkspace = Schema.fromJsonString(\n Schema.Struct({\n fingerprint: Schema.String,\n keys: Schema.Array(Schema.String),\n workspace: CargoWorkspaceSchema,\n }),\n);\nconst decodeMetadata = Schema.decodeUnknownEffect(Schema.fromJsonString(CargoMetadataSchema));\nconst decodeCached = Schema.decodeUnknownOption(CachedWorkspace);\nconst encodeCached = Schema.encodeEffect(CachedWorkspace);\n\nconst AUTO: readonly CargoInput[] = [{ auto: true }];\nconst nodeLayer = Layer.provideMerge(nodeRepositoryFiles, nodeServicesLayer);\n\nexport interface CargoInputOptions {\n readonly directory: string;\n readonly extras?: readonly string[];\n}\n\nconst fingerprintOf = Effect.fn(\"fingerprintOf\")(function* fingerprintOf(\n root: string,\n keys: readonly string[],\n) {\n const files = yield* RepositoryFiles;\n const texts = yield* Effect.forEach(keys, (key) => files.readFile(files.join(root, key)), {\n concurrency: READ_CONCURRENCY,\n });\n const joined = pipe(\n keys,\n Arr.zip(texts),\n Arr.map(([key, text]) => `${key}${KEY_SEPARATOR}${Option.getOrElse(text, () => \"\")}`),\n Arr.join(KEY_SEPARATOR),\n );\n return yield* files.hash(joined);\n});\n\nconst cachedWorkspace = Effect.fn(\"cachedWorkspace\")(function* cachedWorkspace(root: string) {\n const files = yield* RepositoryFiles;\n const text = yield* files.readFile(files.join(root, ...CACHE_FILE));\n const cached = pipe(text, Option.flatMap(decodeCached));\n if (Option.isNone(cached)) {\n return Option.none<CargoWorkspace>();\n }\n const fingerprint = yield* fingerprintOf(root, cached.value.keys);\n return Option.some(cached.value.workspace).pipe(\n Option.filter(() => fingerprint === cached.value.fingerprint),\n );\n});\n\nconst readWorkspace = Effect.fn(\"readWorkspace\")(function* readWorkspace(root: string) {\n const files = yield* RepositoryFiles;\n const handle = yield* ChildProcess.make(\"cargo\", METADATA_ARGS, {\n cwd: root,\n extendEnv: true,\n stdin: \"ignore\",\n });\n const output = yield* handle.stdout.pipe(Stream.decodeText(), Stream.mkString);\n const metadata = yield* decodeMetadata(output);\n const workspace: CargoWorkspace = {\n metadata,\n ignored: yield* collectIgnoredDirectories(root),\n };\n const keys = keysOf(metadata);\n const fingerprint = yield* fingerprintOf(root, keys);\n const text = yield* encodeCached({ fingerprint, keys, workspace });\n yield* files.writeFile(files.join(root, ...CACHE_FILE), text);\n return workspace;\n}, Effect.scoped);\n\nconst lockDirectory = (\n directory: string,\n): Effect.Effect<Option.Option<string>, never, RepositoryFiles> =>\n Effect.gen(function* findLockDirectory() {\n const files = yield* RepositoryFiles;\n if (yield* files.exists(files.join(directory, LOCK_FILE))) {\n return Option.some(directory);\n }\n const parent = files.dirname(directory);\n if (parent === directory) {\n return Option.none<string>();\n }\n return yield* lockDirectory(parent);\n });\n\nconst inputsIn = Effect.fn(\"inputsIn\")(function* inputsIn(\n root: string,\n directory: string,\n extras: readonly string[],\n) {\n const files = yield* RepositoryFiles;\n const cached = yield* cachedWorkspace(root);\n const workspace = yield* Option.match(cached, {\n onNone: () => readWorkspace(root),\n onSome: Effect.succeed,\n });\n const derived = cargoInputsOf({ workspace, directory, extras });\n const file = files.join(root, derived.closureFile);\n const written = yield* files.readFile(file);\n if (!Option.exists(written, (text) => text === derived.closure)) {\n yield* files.writeFile(file, derived.closure);\n }\n return derived.inputs;\n});\n\nconst deriveCargoInputs = Effect.fn(\"deriveCargoInputs\")(function* deriveCargoInputs({\n directory,\n extras = [],\n}: CargoInputOptions) {\n const files = yield* RepositoryFiles;\n const absolute = files.resolve(directory);\n const root = yield* lockDirectory(absolute);\n return yield* Option.match(root, {\n onNone: () => Effect.succeed(AUTO),\n onSome: (found) => inputsIn(found, absolute, extras),\n });\n});\n\nexport const cargoInputs = (options: CargoInputOptions): Promise<readonly CargoInput[]> =>\n Effect.runPromise(\n deriveCargoInputs(options).pipe(\n Effect.orElseSucceed(() => AUTO),\n Effect.provide(nodeLayer),\n ),\n );\n"],"mappings":";;;;AAGA,MAAa,YAAY;AACzB,MAAa,gBAAgB;AAC7B,MAAM,cAAc;AACpB,MAAM,eAAe;AACrB,MAAM,OAAO;AAEb,MAAM,mBAAmB,OAAO,OAAO;CACrC,SAAS,OAAO;CAChB,MAAM,OAAO,QAAQ,WAAW;AAClC,CAAC;AACD,MAAM,qBAAqB,OAAO,OAAO;CACvC,IAAI,OAAO;CACX,eAAe,OAAO;CACtB,QAAQ,OAAO,OAAO,OAAO,MAAM;AACrC,CAAC;AACD,MAAM,YAAY,OAAO,OAAO;CAC9B,IAAI,OAAO;CACX,MAAM,OAAO,MAAM,OAAO,OAAO,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC;AAC1D,CAAC;AACD,MAAa,sBAAsB,OAAO,OAAO;CAC/C,UAAU,OAAO,MAAM,kBAAkB;CACzC,SAAS,OAAO,OAAO,EAAE,OAAO,OAAO,MAAM,SAAS,EAAE,CAAC;CACzD,mBAAmB,OAAO,MAAM,OAAO,MAAM;CAC7C,gBAAgB,OAAO;AACzB,CAAC;AACD,MAAa,uBAAuB,OAAO,OAAO;CAChD,UAAU;CACV,SAAS,OAAO,MAAM,gBAAgB;AACxC,CAAC;AAKD,MAAM,aAAaA,OAAI,WAAW,MAAA,GAAe;AAEjD,MAAa,cACV,UACA,SAAwC;CACvC,MAAM,SAAS,GAAG,WAAW,IAAI;CACjC,MAAM,OAAO,WAAW,IAAI;CAC5B,OAAO,OAAO,KAAKA,OAAI,MAAM,OAAO,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KACjD,OAAO,aAAaA,OAAI,WAAW,MAAM,CAAC,CAAC,IAAI,CAAC,CAClD;AACF;AAEF,MAAa,eAAe,SAC1B,KAAK,WAAW,IAAI,GAAGA,OAAI,QAAQ,cAAc,EAAE,CAAC;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s";
1
+ import { t as NODE_MODULES } from "./repository-files-CPfBA4mf.mjs";
2
2
  import { Array, Option, Order, Schema, String as String$1, pipe } from "effect";
3
3
  import { InternalSymbolName, SyntaxKind, getJSDocTags, getLeadingCommentRanges, getNameOfDeclaration, getTextOfJSDocComment } from "typescript/ast";
4
4
  import { isArrayLiteralExpression, isArrowFunction, isBinaryExpression, isBlock, isCallExpression, isClassDeclaration, isElementAccessExpression, isEnumDeclaration, isExportAssignment, isExportDeclaration, isFunctionDeclaration, isFunctionExpression, isIdentifier, isImportDeclaration, isInterfaceDeclaration, isModuleBlock, isModuleDeclaration, isNewExpression, isNumericLiteral, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isPropertyAssignment, isReturnStatement, isSatisfiesExpression, isSignatureDeclaration, isSourceFile, isSpreadElement, isStringLiteral, isTypeAliasDeclaration, isTypeLiteralNode, isTypeReferenceNode, isUnionTypeNode, isVariableDeclaration, isVariableDeclarationList, isVariableStatement } from "typescript/ast/is";
@@ -106,4 +106,4 @@ const formatProblem = (relative) => (problem) => `${relative(problem.file)}:${St
106
106
  const JSON_FLAG = "--json";
107
107
  export { isPropertyAccessExpression as $, getLeadingCommentRanges as A, isEnumDeclaration as B, uniqueByReference as C, SignatureKind as D, InternalSymbolName as E, isBinaryExpression as F, isImportDeclaration as G, isFunctionDeclaration as H, isBlock as I, isModuleDeclaration as J, isInterfaceDeclaration as K, isCallExpression as L, getTextOfJSDocComment as M, isArrayLiteralExpression as N, SyntaxKind as O, isArrowFunction as P, isParenthesizedExpression as Q, isClassDeclaration as R, symbolAt as S, IndexKind as T, isFunctionExpression as U, isExportDeclaration as V, isIdentifier as W, isNumericLiteral as X, isNewExpression as Y, isObjectLiteralExpression as Z, lineOf as _, problemAt as a, isSpreadElement as at, referencedSymbols as b, columnOf as c, isTypeLiteralNode as ct, descendantsOf as d, isVariableDeclaration as dt, isPropertyAssignment as et, importedModulesOf as f, isVariableDeclarationList as ft, isTypeDeclaration as g, isInsideAny as h, formatProblem as i, isSourceFile as it, getNameOfDeclaration as j, getJSDocTags as k, contains as l, isTypeReferenceNode as lt, isGenericDeclaration as m, ProblemList as n, isSatisfiesExpression as nt, sortProblems as o, isStringLiteral as ot, isExternalDeclaration as p, isVariableStatement as pt, isModuleBlock as q, describeFinding as r, isSignatureDeclaration as rt, childrenOf as s, isTypeAliasDeclaration as st, JSON_FLAG as t, isReturnStatement as tt, declarationsOf as u, isUnionTypeNode as ut, packageOf as v, API as w, resolvedSymbol as x, propertyNamesOf as y, isElementAccessExpression as z };
108
108
 
109
- //# sourceMappingURL=cli-contract-8SnKqhGw.mjs.map
109
+ //# sourceMappingURL=cli-contract-DdTV5DaG.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-contract-8SnKqhGw.mjs","names":["Arr","Str","Arr"],"sources":["../src/shared/lib/syntax.ts","../src/shared/lib/problem.ts","../src/shared/lib/cli-contract.ts"],"sourcesContent":["import { Array as Arr, Option, String as Str, pipe } from \"effect\";\n\nimport {\n isEnumDeclaration,\n isExportAssignment,\n isExportDeclaration,\n isIdentifier,\n isImportDeclaration,\n isInterfaceDeclaration,\n isPropertyAccessExpression,\n isStringLiteral,\n isTypeAliasDeclaration,\n SyntaxKind,\n} from \"./compiler.ts\";\nimport type {\n Checker,\n Declaration,\n EnumDeclaration,\n Expression,\n InterfaceDeclaration,\n Node,\n Program,\n SourceFile,\n TypeSymbol,\n Type,\n TypeAliasDeclaration,\n} from \"./compiler.ts\";\nimport { NODE_MODULES } from \"./repository-files.ts\";\n\nconst NODE_MODULES_SEGMENT = `/${NODE_MODULES}/`;\n\nexport const POSITION_BASE = 1;\n\nexport const uniqueByReference = <Item>(items: readonly Item[]): readonly Item[] =>\n Arr.dedupeWith(items, (left, right) => left === right);\n\nexport const childrenOf = (node: Node): readonly Node[] => {\n const children: Node[] = [];\n node.forEachChild((child) => {\n children.push(child);\n });\n return children;\n};\n\nconst SCOPE_PREFIX = \"@\";\nconst SCOPED_SEGMENTS = 2;\nconst UNSCOPED_SEGMENTS = 1;\n\nexport const packageOf = (fileName: string): string => {\n const afterModules = pipe(\n fileName,\n Str.lastIndexOf(NODE_MODULES_SEGMENT),\n Option.match({\n onNone: () => fileName,\n onSome: (index) => Str.slice(index + NODE_MODULES_SEGMENT.length)(fileName),\n }),\n );\n const segments = Str.split(\"/\")(afterModules);\n if (Str.startsWith(SCOPE_PREFIX)(afterModules)) {\n return pipe(Arr.take(segments, SCOPED_SEGMENTS), Arr.join(\"/\"));\n }\n return pipe(Arr.take(segments, UNSCOPED_SEGMENTS), Arr.join(\"/\"));\n};\n\nexport const descendantsOf = (node: Node): readonly Node[] =>\n pipe(\n childrenOf(node),\n Arr.flatMap((child) => Arr.prepend(descendantsOf(child), child)),\n );\n\nconst isExternalFile =\n (program: Program) =>\n (sourceFile: SourceFile): boolean =>\n !program.isSourceFileDefaultLibrary(sourceFile) &&\n (Str.includes(NODE_MODULES_SEGMENT)(sourceFile.fileName) ||\n program.isSourceFileFromExternalLibrary(sourceFile));\n\nexport const isExternalDeclaration =\n (program: Program) =>\n (declaration: Node): boolean =>\n isExternalFile(program)(declaration.getSourceFile());\n\nconst ALIAS_KINDS: ReadonlySet<SyntaxKind> = new Set([\n SyntaxKind.ImportSpecifier,\n SyntaxKind.ImportClause,\n SyntaxKind.NamespaceImport,\n SyntaxKind.ExportSpecifier,\n SyntaxKind.ImportEqualsDeclaration,\n SyntaxKind.ExportAssignment,\n]);\n\nexport const declarationsOf = (symbol: TypeSymbol): readonly Declaration[] =>\n pipe(\n symbol.declarations,\n Arr.flatMap((handle) => Option.toArray(Option.fromUndefinedOr(handle.resolve()))),\n );\n\nconst isEntityName = (expression: Expression): boolean =>\n isIdentifier(expression) ||\n (isPropertyAccessExpression(expression) && isEntityName(expression.expression));\n\nconst aliasesAnEntity = (declaration: Node): boolean =>\n !isExportAssignment(declaration) || isEntityName(declaration.expression);\n\nconst isAliasDeclaration = (declaration: Node): boolean =>\n ALIAS_KINDS.has(declaration.kind) && aliasesAnEntity(declaration);\n\nexport const resolvedSymbol =\n (checker: Checker) =>\n (symbol: TypeSymbol): TypeSymbol => {\n if (\n !pipe(\n declarationsOf(symbol),\n Arr.some((declaration) => isAliasDeclaration(declaration)),\n )\n ) {\n return symbol;\n }\n return checker.getAliasedSymbol(symbol);\n };\n\nexport const symbolAt =\n (checker: Checker) =>\n (node: Node): Option.Option<TypeSymbol> =>\n Option.fromUndefinedOr(checker.getSymbolAtLocation(node)).pipe(\n Option.map(resolvedSymbol(checker)),\n );\n\nexport const referencedSymbols =\n (checker: Checker) =>\n (node: Node): readonly TypeSymbol[] => {\n const identifiers = pipe(\n Arr.prepend(descendantsOf(node), node),\n Arr.filter((candidate) => isIdentifier(candidate)),\n );\n const symbols = pipe(\n checker.getSymbolAtLocation(identifiers),\n Arr.flatMap((symbol) => Option.toArray(Option.fromUndefinedOr(symbol))),\n Arr.map(resolvedSymbol(checker)),\n );\n return uniqueByReference(symbols);\n };\n\nexport const lineOf = (node: Node): number => {\n const sourceFile = node.getSourceFile();\n return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + POSITION_BASE;\n};\n\nexport const columnOf = (node: Node): number => {\n const sourceFile = node.getSourceFile();\n return (\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).character + POSITION_BASE\n );\n};\n\nexport const contains =\n (outer: Node) =>\n (inner: Node): boolean =>\n outer.getSourceFile().fileName === inner.getSourceFile().fileName &&\n outer.getStart() <= inner.getStart() &&\n inner.getEnd() <= outer.getEnd();\n\nexport const isInsideAny =\n (outers: readonly Node[]) =>\n (node: Node): boolean =>\n pipe(\n outers,\n Arr.some((outer) => contains(outer)(node)),\n );\n\nexport const isTypeDeclaration = (\n declaration: Node,\n): declaration is TypeAliasDeclaration | InterfaceDeclaration | EnumDeclaration =>\n isTypeAliasDeclaration(declaration) ||\n isInterfaceDeclaration(declaration) ||\n isEnumDeclaration(declaration);\n\nexport const isGenericDeclaration = (declaration: Node): boolean =>\n (isTypeAliasDeclaration(declaration) || isInterfaceDeclaration(declaration)) &&\n Arr.isReadonlyArrayNonEmpty(declaration.typeParameters ?? []);\n\nexport const propertyNamesOf =\n (checker: Checker) =>\n (type: Type): readonly string[] =>\n pipe(\n checker.getPropertiesOfType(type),\n Arr.map((property) => property.name),\n );\n\nconst moduleSpecifierOf = (statement: Node): Option.Option<string> => {\n if (!isImportDeclaration(statement) && !isExportDeclaration(statement)) {\n return Option.none();\n }\n return Option.fromUndefinedOr(statement.moduleSpecifier).pipe(\n Option.filter((specifier) => isStringLiteral(specifier)),\n Option.map((specifier) => specifier.text),\n );\n};\n\nexport const importedModulesOf = (sourceFile: SourceFile): readonly string[] =>\n pipe(\n sourceFile.statements,\n Arr.map((statement) => moduleSpecifierOf(statement)),\n Arr.getSomes,\n );\n","import { Array as Arr, Order, Schema, pipe } from \"effect\";\n\nimport type { Node } from \"./compiler.ts\";\nimport { columnOf, lineOf } from \"./syntax.ts\";\n\nconst RuleNameSchema = Schema.String.check(Schema.isPattern(/^[a-z]+(?:-[a-z]+)*$/u));\n\nexport type RuleName = typeof RuleNameSchema.Type;\n\nconst ProblemSchema = Schema.Struct({\n file: Schema.String,\n line: Schema.Int,\n column: Schema.Int,\n rule: RuleNameSchema,\n message: Schema.String,\n});\n\nexport type Problem = typeof ProblemSchema.Type;\n\nexport const ProblemList = Schema.Array(ProblemSchema);\n\nexport const CANDIDATE_LIMIT = 3;\n\nexport interface Finding {\n readonly rule: RuleName;\n readonly message: string;\n}\n\nexport const problemAt =\n ({ rule, message }: Finding) =>\n (node: Node): Problem => ({\n file: node.getSourceFile().fileName,\n line: lineOf(node),\n column: columnOf(node),\n rule,\n message,\n });\n\nconst problemOrder: Order.Order<Problem> = Order.combineAll([\n Order.mapInput(Order.String, (problem: Problem) => problem.file),\n Order.mapInput(Order.Number, (problem: Problem) => problem.line),\n Order.mapInput(Order.Number, (problem: Problem) => problem.column),\n Order.mapInput(Order.String, (problem: Problem) => problem.rule),\n Order.mapInput(Order.String, (problem: Problem) => problem.message),\n]);\n\nconst problemKey = (problem: Problem): string =>\n pipe(\n [problem.file, String(problem.line), String(problem.column), problem.rule, problem.message],\n Arr.join(\"\\0\"),\n );\n\nexport const sortProblems = (problems: readonly Problem[]): readonly Problem[] =>\n Arr.sort(\n Arr.dedupeWith(problems, (left, right) => problemKey(left) === problemKey(right)),\n problemOrder,\n );\n\nexport const describeFinding = (problem: Problem): string => `[${problem.rule}] ${problem.message}`;\n\nexport const formatProblem =\n (relative: (file: string) => string) =>\n (problem: Problem): string =>\n `${relative(problem.file)}:${String(problem.line)}:${String(problem.column)} ${describeFinding(problem)}`;\n","export const JSON_FLAG = \"--json\";\n"],"mappings":";;;;;;AA6BA,MAAM,uBAAuB,IAAI,aAAa;AAI9C,MAAa,qBAA2B,UACtCA,MAAI,WAAW,QAAQ,MAAM,UAAU,SAAS,KAAK;AAEvD,MAAa,cAAc,SAAgC;CACzD,MAAM,WAAmB,CAAC;CAC1B,KAAK,cAAc,UAAU;EAC3B,SAAS,KAAK,KAAK;CACrB,CAAC;CACD,OAAO;AACT;AAEA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAE1B,MAAa,aAAa,aAA6B;CACrD,MAAM,eAAe,KACnB,UACAC,SAAI,YAAY,oBAAoB,GACpC,OAAO,MAAM;EACX,cAAc;EACd,SAAS,UAAUA,SAAI,MAAM,QAAQ,qBAAqB,MAAM,CAAC,CAAC,QAAQ;CAC5E,CAAC,CACH;CACA,MAAM,WAAWA,SAAI,MAAM,GAAG,CAAC,CAAC,YAAY;CAC5C,IAAIA,SAAI,WAAW,YAAY,CAAC,CAAC,YAAY,GAC3C,OAAO,KAAKD,MAAI,KAAK,UAAU,eAAe,GAAGA,MAAI,KAAK,GAAG,CAAC;CAEhE,OAAO,KAAKA,MAAI,KAAK,UAAU,iBAAiB,GAAGA,MAAI,KAAK,GAAG,CAAC;AAClE;AAEA,MAAa,iBAAiB,SAC5B,KACE,WAAW,IAAI,GAC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,MAAa,YAAY"}
1
+ {"version":3,"file":"cli-contract-DdTV5DaG.mjs","names":["Arr","Str","Arr"],"sources":["../src/shared/lib/syntax.ts","../src/shared/lib/problem.ts","../src/shared/lib/cli-contract.ts"],"sourcesContent":["import { Array as Arr, Option, String as Str, pipe } from \"effect\";\n\nimport {\n isEnumDeclaration,\n isExportAssignment,\n isExportDeclaration,\n isIdentifier,\n isImportDeclaration,\n isInterfaceDeclaration,\n isPropertyAccessExpression,\n isStringLiteral,\n isTypeAliasDeclaration,\n SyntaxKind,\n} from \"./compiler.ts\";\nimport type {\n Checker,\n Declaration,\n EnumDeclaration,\n Expression,\n InterfaceDeclaration,\n Node,\n Program,\n SourceFile,\n TypeSymbol,\n Type,\n TypeAliasDeclaration,\n} from \"./compiler.ts\";\nimport { NODE_MODULES } from \"./repository-files.ts\";\n\nconst NODE_MODULES_SEGMENT = `/${NODE_MODULES}/`;\n\nexport const POSITION_BASE = 1;\n\nexport const uniqueByReference = <Item>(items: readonly Item[]): readonly Item[] =>\n Arr.dedupeWith(items, (left, right) => left === right);\n\nexport const childrenOf = (node: Node): readonly Node[] => {\n const children: Node[] = [];\n node.forEachChild((child) => {\n children.push(child);\n });\n return children;\n};\n\nconst SCOPE_PREFIX = \"@\";\nconst SCOPED_SEGMENTS = 2;\nconst UNSCOPED_SEGMENTS = 1;\n\nexport const packageOf = (fileName: string): string => {\n const afterModules = pipe(\n fileName,\n Str.lastIndexOf(NODE_MODULES_SEGMENT),\n Option.match({\n onNone: () => fileName,\n onSome: (index) => Str.slice(index + NODE_MODULES_SEGMENT.length)(fileName),\n }),\n );\n const segments = Str.split(\"/\")(afterModules);\n if (Str.startsWith(SCOPE_PREFIX)(afterModules)) {\n return pipe(Arr.take(segments, SCOPED_SEGMENTS), Arr.join(\"/\"));\n }\n return pipe(Arr.take(segments, UNSCOPED_SEGMENTS), Arr.join(\"/\"));\n};\n\nexport const descendantsOf = (node: Node): readonly Node[] =>\n pipe(\n childrenOf(node),\n Arr.flatMap((child) => Arr.prepend(descendantsOf(child), child)),\n );\n\nconst isExternalFile =\n (program: Program) =>\n (sourceFile: SourceFile): boolean =>\n !program.isSourceFileDefaultLibrary(sourceFile) &&\n (Str.includes(NODE_MODULES_SEGMENT)(sourceFile.fileName) ||\n program.isSourceFileFromExternalLibrary(sourceFile));\n\nexport const isExternalDeclaration =\n (program: Program) =>\n (declaration: Node): boolean =>\n isExternalFile(program)(declaration.getSourceFile());\n\nconst ALIAS_KINDS: ReadonlySet<SyntaxKind> = new Set([\n SyntaxKind.ImportSpecifier,\n SyntaxKind.ImportClause,\n SyntaxKind.NamespaceImport,\n SyntaxKind.ExportSpecifier,\n SyntaxKind.ImportEqualsDeclaration,\n SyntaxKind.ExportAssignment,\n]);\n\nexport const declarationsOf = (symbol: TypeSymbol): readonly Declaration[] =>\n pipe(\n symbol.declarations,\n Arr.flatMap((handle) => Option.toArray(Option.fromUndefinedOr(handle.resolve()))),\n );\n\nconst isEntityName = (expression: Expression): boolean =>\n isIdentifier(expression) ||\n (isPropertyAccessExpression(expression) && isEntityName(expression.expression));\n\nconst aliasesAnEntity = (declaration: Node): boolean =>\n !isExportAssignment(declaration) || isEntityName(declaration.expression);\n\nconst isAliasDeclaration = (declaration: Node): boolean =>\n ALIAS_KINDS.has(declaration.kind) && aliasesAnEntity(declaration);\n\nexport const resolvedSymbol =\n (checker: Checker) =>\n (symbol: TypeSymbol): TypeSymbol => {\n if (\n !pipe(\n declarationsOf(symbol),\n Arr.some((declaration) => isAliasDeclaration(declaration)),\n )\n ) {\n return symbol;\n }\n return checker.getAliasedSymbol(symbol);\n };\n\nexport const symbolAt =\n (checker: Checker) =>\n (node: Node): Option.Option<TypeSymbol> =>\n Option.fromUndefinedOr(checker.getSymbolAtLocation(node)).pipe(\n Option.map(resolvedSymbol(checker)),\n );\n\nexport const referencedSymbols =\n (checker: Checker) =>\n (node: Node): readonly TypeSymbol[] => {\n const identifiers = pipe(\n Arr.prepend(descendantsOf(node), node),\n Arr.filter((candidate) => isIdentifier(candidate)),\n );\n const symbols = pipe(\n checker.getSymbolAtLocation(identifiers),\n Arr.flatMap((symbol) => Option.toArray(Option.fromUndefinedOr(symbol))),\n Arr.map(resolvedSymbol(checker)),\n );\n return uniqueByReference(symbols);\n };\n\nexport const lineOf = (node: Node): number => {\n const sourceFile = node.getSourceFile();\n return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + POSITION_BASE;\n};\n\nexport const columnOf = (node: Node): number => {\n const sourceFile = node.getSourceFile();\n return (\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).character + POSITION_BASE\n );\n};\n\nexport const contains =\n (outer: Node) =>\n (inner: Node): boolean =>\n outer.getSourceFile().fileName === inner.getSourceFile().fileName &&\n outer.getStart() <= inner.getStart() &&\n inner.getEnd() <= outer.getEnd();\n\nexport const isInsideAny =\n (outers: readonly Node[]) =>\n (node: Node): boolean =>\n pipe(\n outers,\n Arr.some((outer) => contains(outer)(node)),\n );\n\nexport const isTypeDeclaration = (\n declaration: Node,\n): declaration is TypeAliasDeclaration | InterfaceDeclaration | EnumDeclaration =>\n isTypeAliasDeclaration(declaration) ||\n isInterfaceDeclaration(declaration) ||\n isEnumDeclaration(declaration);\n\nexport const isGenericDeclaration = (declaration: Node): boolean =>\n (isTypeAliasDeclaration(declaration) || isInterfaceDeclaration(declaration)) &&\n Arr.isReadonlyArrayNonEmpty(declaration.typeParameters ?? []);\n\nexport const propertyNamesOf =\n (checker: Checker) =>\n (type: Type): readonly string[] =>\n pipe(\n checker.getPropertiesOfType(type),\n Arr.map((property) => property.name),\n );\n\nconst moduleSpecifierOf = (statement: Node): Option.Option<string> => {\n if (!isImportDeclaration(statement) && !isExportDeclaration(statement)) {\n return Option.none();\n }\n return Option.fromUndefinedOr(statement.moduleSpecifier).pipe(\n Option.filter((specifier) => isStringLiteral(specifier)),\n Option.map((specifier) => specifier.text),\n );\n};\n\nexport const importedModulesOf = (sourceFile: SourceFile): readonly string[] =>\n pipe(\n sourceFile.statements,\n Arr.map((statement) => moduleSpecifierOf(statement)),\n Arr.getSomes,\n );\n","import { Array as Arr, Order, Schema, pipe } from \"effect\";\n\nimport type { Node } from \"./compiler.ts\";\nimport { columnOf, lineOf } from \"./syntax.ts\";\n\nconst RuleNameSchema = Schema.String.check(Schema.isPattern(/^[a-z]+(?:-[a-z]+)*$/u));\n\nexport type RuleName = typeof RuleNameSchema.Type;\n\nconst ProblemSchema = Schema.Struct({\n file: Schema.String,\n line: Schema.Int,\n column: Schema.Int,\n rule: RuleNameSchema,\n message: Schema.String,\n});\n\nexport type Problem = typeof ProblemSchema.Type;\n\nexport const ProblemList = Schema.Array(ProblemSchema);\n\nexport const CANDIDATE_LIMIT = 3;\n\nexport interface Finding {\n readonly rule: RuleName;\n readonly message: string;\n}\n\nexport const problemAt =\n ({ rule, message }: Finding) =>\n (node: Node): Problem => ({\n file: node.getSourceFile().fileName,\n line: lineOf(node),\n column: columnOf(node),\n rule,\n message,\n });\n\nconst problemOrder: Order.Order<Problem> = Order.combineAll([\n Order.mapInput(Order.String, (problem: Problem) => problem.file),\n Order.mapInput(Order.Number, (problem: Problem) => problem.line),\n Order.mapInput(Order.Number, (problem: Problem) => problem.column),\n Order.mapInput(Order.String, (problem: Problem) => problem.rule),\n Order.mapInput(Order.String, (problem: Problem) => problem.message),\n]);\n\nconst problemKey = (problem: Problem): string =>\n pipe(\n [problem.file, String(problem.line), String(problem.column), problem.rule, problem.message],\n Arr.join(\"\\0\"),\n );\n\nexport const sortProblems = (problems: readonly Problem[]): readonly Problem[] =>\n Arr.sort(\n Arr.dedupeWith(problems, (left, right) => problemKey(left) === problemKey(right)),\n problemOrder,\n );\n\nexport const describeFinding = (problem: Problem): string => `[${problem.rule}] ${problem.message}`;\n\nexport const formatProblem =\n (relative: (file: string) => string) =>\n (problem: Problem): string =>\n `${relative(problem.file)}:${String(problem.line)}:${String(problem.column)} ${describeFinding(problem)}`;\n","export const JSON_FLAG = \"--json\";\n"],"mappings":";;;;;;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