@r_masseater/msch 0.78.2 → 0.81.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/README.md +1 -0
- package/dist/cli.mjs +36 -50
- package/dist/cli.mjs.map +1 -1
- package/dist/config-C3jRfgJ9.mjs +7 -0
- package/dist/config-C3jRfgJ9.mjs.map +1 -0
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +3 -2
- package/dist/config.mjs.map +1 -1
- package/dist/decision-rules.d.mts +1 -1
- package/dist/decision-rules.mjs +1 -1
- package/dist/{define-lint-preset-Bawe3IU5.mjs → define-lint-preset-Cmdgaxwj.mjs} +12 -3
- package/dist/define-lint-preset-Cmdgaxwj.mjs.map +1 -0
- package/dist/exits.mjs +1 -1
- package/dist/{index-DEuWKkok.d.mts → index-DKwEdtfw.d.mts} +31 -2
- package/dist/lint-rules.mjs +453 -18
- package/dist/lint-rules.mjs.map +1 -1
- package/dist/lint.d.mts +2 -2
- package/dist/lint.mjs +1 -1
- package/dist/registry-releases-E0PE3Wq-.mjs +54 -0
- package/dist/registry-releases-E0PE3Wq-.mjs.map +1 -0
- package/dist/{upstream-exits-CJehIR2f.mjs → upstream-exits-2ut4fmJv.mjs} +4 -48
- package/dist/upstream-exits-2ut4fmJv.mjs.map +1 -0
- package/dist/upstream-record-CSbML0KF.mjs +136 -0
- package/dist/upstream-record-CSbML0KF.mjs.map +1 -0
- package/dist/upstream.d.mts +1 -0
- package/dist/upstream.mjs +104 -0
- package/dist/upstream.mjs.map +1 -0
- package/package.json +12 -11
- package/skills/msch-checks/SKILL.md +17 -0
- package/skills/msch-repository-config/SKILL.md +21 -0
- package/dist/config-CvPuqi4L.mjs +0 -5
- package/dist/config-CvPuqi4L.mjs.map +0 -1
- package/dist/define-lint-preset-Bawe3IU5.mjs.map +0 -1
- package/dist/upstream-exits-CJehIR2f.mjs.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { a as groupOf, n as RepositoryFiles } from "./repository-files-C2gVviac.mjs";
|
|
2
2
|
import { a as problemAtPosition } from "./problem-OJg859cN.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { n as githubToken, r as jsonLookup, t as fetched } from "./lookup-DjQU0W6q.mjs";
|
|
4
|
+
import { t as registryRelease } from "./registry-releases-E0PE3Wq-.mjs";
|
|
4
5
|
import { Array, Effect, HashMap, HashSet, Match, Option, Record, Schema, String as String$1, pipe } from "effect";
|
|
5
6
|
import { parseTOML } from "toml-eslint-parser";
|
|
6
7
|
import { Parser, parseDocument } from "yaml";
|
|
@@ -226,56 +227,11 @@ const describeCondition = (condition) => Match.value(condition).pipe(Match.discr
|
|
|
226
227
|
}));
|
|
227
228
|
const isUnused = (condition) => condition.kind === "unused";
|
|
228
229
|
// src/features/check-upstream-exits/model/met-exits.ts
|
|
229
|
-
const NPM = "https://registry.npmjs.org/";
|
|
230
|
-
const CRATES = "https://crates.io/api/v1/crates/";
|
|
231
230
|
const GITHUB = "https://api.github.com/repos/";
|
|
232
231
|
const LOOKUP_CONCURRENCY = 4;
|
|
233
232
|
const RANGE_OPTIONS = { includePrerelease: true };
|
|
234
|
-
const DECLARING_SECTIONS = [
|
|
235
|
-
"optionalDependencies",
|
|
236
|
-
"peerDependencies",
|
|
237
|
-
"dependencies"
|
|
238
|
-
];
|
|
239
|
-
const Dependencies = Schema.Record(Schema.String, Schema.String);
|
|
240
|
-
const NpmVersion = Schema.Record(Schema.String, Schema.Unknown);
|
|
241
|
-
const decodeDependencies = Schema.decodeUnknownOption(Dependencies);
|
|
242
|
-
const NpmPackument = Schema.Struct({
|
|
243
|
-
"dist-tags": Schema.Struct({ latest: Schema.String }),
|
|
244
|
-
versions: Schema.Record(Schema.String, NpmVersion)
|
|
245
|
-
});
|
|
246
|
-
const Crate = Schema.Struct({
|
|
247
|
-
crate: Schema.Struct({
|
|
248
|
-
max_stable_version: Schema.NullOr(Schema.String),
|
|
249
|
-
newest_version: Schema.String
|
|
250
|
-
}),
|
|
251
|
-
versions: Schema.Array(Schema.Struct({
|
|
252
|
-
num: Schema.String,
|
|
253
|
-
yanked: Schema.Boolean
|
|
254
|
-
}))
|
|
255
|
-
});
|
|
256
|
-
const CrateDependencies = Schema.Struct({ dependencies: Schema.Array(Schema.Struct({
|
|
257
|
-
crate_id: Schema.String,
|
|
258
|
-
req: Schema.String
|
|
259
|
-
})) });
|
|
260
233
|
const Issue = Schema.Struct({ state: Schema.String });
|
|
261
|
-
const
|
|
262
|
-
const npmRelease = (name) => fetched(publicLookup(`${NPM}${String$1.replace("/", "%2f")(name)}`)).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(NpmPackument)), Effect.map(({ "dist-tags": tags, versions }) => ({
|
|
263
|
-
versions: Record.keys(versions),
|
|
264
|
-
latestDependencies: pipe(Record.get(versions, tags.latest), Option.map(declaredBy), Option.getOrElse(() => ({})))
|
|
265
|
-
})));
|
|
266
|
-
const crateRelease = Effect.fn("crateRelease")(function* lookupCrate(name) {
|
|
267
|
-
const found = yield* fetched(publicLookup(`${CRATES}${name}`)).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Crate)));
|
|
268
|
-
const latest = found.crate.max_stable_version ?? found.crate.newest_version;
|
|
269
|
-
const { dependencies } = yield* fetched(publicLookup(`${CRATES}${name}/${latest}/dependencies`)).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(CrateDependencies)));
|
|
270
|
-
return {
|
|
271
|
-
versions: pipe(found.versions, Array.filter(({ yanked }) => !yanked), Array.map(({ num }) => num)),
|
|
272
|
-
latestDependencies: Record.fromEntries(pipe(dependencies, Array.map(({ crate_id: crateId, req }) => [crateId, req])))
|
|
273
|
-
};
|
|
274
|
-
});
|
|
275
|
-
const releaseOf = (condition) => {
|
|
276
|
-
if (condition.registry === "npm") return npmRelease(condition.name);
|
|
277
|
-
return crateRelease(condition.name);
|
|
278
|
-
};
|
|
234
|
+
const releaseOf = (condition) => registryRelease(condition.registry, condition.name);
|
|
279
235
|
const declaresMet = (release) => (condition) => {
|
|
280
236
|
const declared = Record.get(release.latestDependencies, condition.dependency);
|
|
281
237
|
if (condition.relation === "drops") return Option.isNone(declared);
|
|
@@ -398,4 +354,4 @@ const upstreamExitsMet = Effect.fn("upstreamExitsMet")(function* upstreamExitsMe
|
|
|
398
354
|
});
|
|
399
355
|
export { workspaceDeviations as a, tomlSourceComments as c, problemAtIndex as d, cargoDeviations as i, yamlSourceComments as l, upstreamExitsMet as n, collectNodes as o, WORKSPACE_SECTIONS as r, isRecord as s, checkUpstreamExits as t, positionOf as u };
|
|
400
356
|
|
|
401
|
-
//# sourceMappingURL=upstream-exits-
|
|
357
|
+
//# sourceMappingURL=upstream-exits-2ut4fmJv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-exits-2ut4fmJv.mjs","names":["Str","Arr","Arr","Rec","YamlParser","Str","Arr","Str","Arr","Rec","Arr","Arr"],"sources":["../src/shared/lib/text-position.ts","../src/shared/lib/config-comments.ts","../src/features/check-upstream-exits/model/deviation-entries.ts","../src/features/check-upstream-exits/model/exit-condition.ts","../src/features/check-upstream-exits/model/met-exits.ts","../src/features/check-upstream-exits/model/upstream-exits.ts"],"sourcesContent":["import { Array as Arr, Option, String as Str, pipe } from \"effect\";\n\nimport { problemAtPosition } from \"./problem.ts\";\nimport type { Problem, RuleName } from \"./problem.ts\";\n\nconst START = 0;\nconst FIRST_COLUMN = 1;\n\nexport const positionOf =\n (source: string) =>\n (index: number): Pick<Problem, \"line\" | \"column\"> => {\n const before = pipe(source, Str.slice(START, index), Str.split(\"\\n\"));\n return {\n line: before.length,\n column: pipe(\n Arr.last(before),\n Option.match({ onNone: () => FIRST_COLUMN, onSome: (last) => last.length + FIRST_COLUMN }),\n ),\n };\n };\n\nexport const problemAtIndex =\n (rule: RuleName) =>\n (file: string, source: string) =>\n (index: number, message: string): Problem =>\n problemAtPosition(rule)(file, positionOf(source)(index), message);\n","import { Array as Arr, Record as Rec, String as Str, pipe } from \"effect\";\nimport { parseTOML } from \"toml-eslint-parser\";\nimport { Parser as YamlParser } from \"yaml\";\n\nexport interface SourceComment {\n readonly index: number;\n readonly text: string;\n}\n\nexport const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>\n typeof value === \"object\" && value !== null;\n\nconst childrenOf = (value: unknown): readonly unknown[] => {\n if (Arr.isArray(value)) {\n return value;\n }\n if (isRecord(value)) {\n return Rec.values(value);\n }\n return [];\n};\n\nexport const collectNodes =\n <Item>(isItem: (value: unknown) => value is Item) =>\n (value: unknown): readonly Item[] => {\n if (isItem(value)) {\n return [value];\n }\n return pipe(childrenOf(value), Arr.flatMap(collectNodes(isItem)));\n };\n\ninterface YamlSourceToken {\n readonly offset: number;\n readonly source: string;\n}\n\nconst isYamlComment = (value: unknown): value is YamlSourceToken =>\n isRecord(value) &&\n value[\"type\"] === \"comment\" &&\n typeof value[\"offset\"] === \"number\" &&\n typeof value[\"source\"] === \"string\";\n\nexport const yamlSourceComments = (source: string): readonly SourceComment[] =>\n pipe(\n Arr.fromIterable(new YamlParser().parse(source)),\n Arr.flatMap(collectNodes(isYamlComment)),\n Arr.map((token) => ({ index: token.offset, text: token.source })),\n );\n\nexport const tomlSourceComments = (source: string): readonly SourceComment[] =>\n pipe(\n parseTOML(source).comments,\n Arr.map(({ range: [start, end] }) => ({\n index: start,\n text: Str.slice(start, end)(source),\n })),\n );\n","import { Array as Arr, HashMap, Option, Schema, pipe } from \"effect\";\nimport { parseTOML } from \"toml-eslint-parser\";\nimport { parseDocument } from \"yaml\";\n\nimport { tomlSourceComments, yamlSourceComments } from \"#/shared/lib/config-comments.ts\";\nimport type { SourceComment } from \"#/shared/lib/config-comments.ts\";\nimport { positionOf } from \"#/shared/lib/text-position.ts\";\n\nexport const WORKSPACE_SECTIONS = [\n \"overrides\",\n \"patchedDependencies\",\n \"packageExtensions\",\n] as const;\nconst CARGO_PATCH = \"patch\";\nconst KEY_SEPARATOR = \".\";\nconst PATCH_SOURCE_DEPTH = 2;\n\nexport type Section = (typeof WORKSPACE_SECTIONS)[number] | typeof CARGO_PATCH;\n\nexport interface DeviationEntry {\n readonly section: Section;\n readonly key: string;\n readonly index: number;\n readonly line: number;\n}\n\nexport interface LineComment extends SourceComment {\n readonly line: number;\n}\n\nexport interface Deviations {\n readonly entries: readonly DeviationEntry[];\n readonly comments: readonly LineComment[];\n}\n\nconst NONE: Deviations = { entries: [], comments: [] };\n\nconst KeyValue = Schema.Union([Schema.String, Schema.Finite]);\nconst Positions = Schema.Array(Schema.Finite);\nconst YamlKey = Schema.Struct({ value: KeyValue, range: Positions });\nconst YamlMap = Schema.Struct({ items: Schema.Array(Schema.Struct({ key: YamlKey })) });\n\nconst KeyPart = Schema.Union([\n Schema.Struct({ type: Schema.Literal(\"TOMLBare\"), name: Schema.String }),\n Schema.Struct({ type: Schema.Literal(\"TOMLQuoted\"), value: Schema.String }),\n]);\nconst Located = {\n range: Schema.Array(Schema.Finite),\n loc: Schema.Struct({ start: Schema.Struct({ line: Schema.Finite }) }),\n};\nconst TomlKeyValue = Schema.Struct({\n ...Located,\n type: Schema.Literal(\"TOMLKeyValue\"),\n key: Schema.Struct({ keys: Schema.Array(KeyPart) }),\n});\nconst TomlTable = Schema.Struct({\n ...Located,\n type: Schema.Literal(\"TOMLTable\"),\n resolvedKey: Schema.Array(Schema.Union([Schema.String, Schema.Finite])),\n body: Schema.Array(TomlKeyValue),\n});\nconst TomlNode = Schema.Union([TomlTable, TomlKeyValue]);\nconst TomlTop = Schema.Array(Schema.Struct({ body: Schema.Array(TomlNode) }));\n\ntype TomlTableType = typeof TomlTable.Type;\ntype KeyPartType = typeof KeyPart.Type;\n\nconst decodeYamlMap = Schema.decodeUnknownOption(YamlMap);\nconst decodeTomlTop = Schema.decodeUnknownOption(TomlTop);\nconst FIRST = 0;\n\nconst lineComments = (source: string, comments: readonly SourceComment[]): readonly LineComment[] =>\n pipe(\n comments,\n Arr.map((comment) => ({ ...comment, line: positionOf(source)(comment.index).line })),\n );\n\nconst startOf = (range: readonly number[]): number =>\n Option.getOrElse(Arr.get(range, FIRST), () => FIRST);\n\nconst sectionEntries =\n (source: string, sectionNode: (section: string) => unknown) =>\n (section: (typeof WORKSPACE_SECTIONS)[number]): readonly DeviationEntry[] =>\n pipe(\n decodeYamlMap(sectionNode(section)),\n Option.match({\n onNone: () => [],\n onSome: ({ items }) =>\n pipe(\n items,\n Arr.map(({ key }) => {\n const index = startOf(key.range);\n return {\n section,\n key: String(key.value),\n index,\n line: positionOf(source)(index).line,\n };\n }),\n ),\n }),\n );\n\nexport const workspaceDeviations = (source: string): Deviations => {\n const document = parseDocument(source);\n if (Arr.isReadonlyArrayNonEmpty(document.errors)) {\n return NONE;\n }\n const sectionNode = (section: string): unknown => document.get(section, true);\n return {\n entries: pipe(WORKSPACE_SECTIONS, Arr.flatMap(sectionEntries(source, sectionNode))),\n comments: lineComments(source, yamlSourceComments(source)),\n };\n};\n\nconst partName = (part: KeyPartType): string => {\n if (part.type === \"TOMLBare\") {\n return part.name;\n }\n return part.value;\n};\n\nconst patchEntries = (table: TomlTableType): readonly DeviationEntry[] => {\n const tableKey = pipe(table.resolvedKey, Arr.map(String));\n if (!Option.exists(Arr.get(tableKey, FIRST), (part) => part === CARGO_PATCH)) {\n return [];\n }\n if (tableKey.length > PATCH_SOURCE_DEPTH) {\n return [\n {\n section: CARGO_PATCH,\n key: Arr.join(tableKey, KEY_SEPARATOR),\n index: startOf(table.range),\n line: table.loc.start.line,\n },\n ];\n }\n return pipe(\n table.body,\n Arr.map((value) => ({\n section: CARGO_PATCH,\n key: Arr.join([...tableKey, ...pipe(value.key.keys, Arr.map(partName))], KEY_SEPARATOR),\n index: startOf(value.range),\n line: value.loc.start.line,\n })),\n );\n};\n\nconst isTable = (node: TomlTableType | typeof TomlKeyValue.Type): node is TomlTableType =>\n node.type === \"TOMLTable\";\n\nexport const cargoDeviations = (source: string): Deviations =>\n pipe(\n Option.liftThrowable(() => parseTOML(source).body)(),\n Option.flatMap(decodeTomlTop),\n Option.match({\n onNone: () => NONE,\n onSome: (tops) => ({\n entries: pipe(\n tops,\n Arr.flatMap(({ body }) => body),\n Arr.filter(isTable),\n Arr.flatMap(patchEntries),\n ),\n comments: lineComments(source, tomlSourceComments(source)),\n }),\n }),\n );\n\nexport const commentsByLine = (\n comments: readonly LineComment[],\n): HashMap.HashMap<number, LineComment> =>\n HashMap.fromIterable(\n pipe(\n comments,\n Arr.map((comment) => [comment.line, comment] as const),\n ),\n );\n","import { groupOf } from \"@masseater.dev/lint-host/collections\";\nimport { Array as Arr, Match, Option, String as Str, pipe } from \"effect\";\nimport semver from \"semver\";\n\nimport type { Registry } from \"#/shared/lib/registry-releases.ts\";\n\nexport type Relation = \"drops\" | \"allows\" | \"requires\";\n\nexport interface Unused {\n readonly kind: \"unused\";\n}\n\nexport interface Published {\n readonly kind: \"published\";\n readonly registry: Registry;\n readonly name: string;\n readonly range: string;\n}\n\nexport interface Declares {\n readonly kind: \"declares\";\n readonly registry: Registry;\n readonly name: string;\n readonly relation: Relation;\n readonly dependency: string;\n readonly range: string;\n}\n\nexport interface Closed {\n readonly kind: \"closed\";\n readonly owner: string;\n readonly repo: string;\n readonly number: number;\n}\n\nexport type ExitCondition = Unused | Published | Declares | Closed;\n\nconst ALTERNATIVE = \" || \";\nconst UNUSED = \"unused\";\nconst ANY_RANGE = \"*\";\nconst EXIT_COMMENT = /^#?\\s*exit:\\s*(?<condition>.*?)\\s*$/u;\nconst PACKAGE = String.raw`(?:@[^\\s/@]+\\/)?[^\\s@]+`;\nconst REGISTRY_CONDITION = new RegExp(\n String.raw`^(?<registry>npm|crate):(?<name>${PACKAGE})(?:@(?<range>.+)| (?<relation>drops|allows|requires) (?<dependency>${PACKAGE})(?:@(?<dependencyRange>.+))?)$`,\n \"u\",\n);\nconst GITHUB_CONDITION = /^github:(?<owner>[\\w.-]+)\\/(?<repo>[\\w.-]+)#(?<number>[1-9]\\d*)$/u;\n\nexport const GRAMMAR =\n \"`unused`, `npm:<package>@<range>`, `npm:<package> drops <dependency>`, `npm:<package> allows <dependency>@<range>`, `npm:<package> requires <dependency>@<range>` (the same forms with `crate:`), or `github:<owner>/<repo>#<number>`, joined with ` || `\";\n\nconst isRegistry = (value: string): value is Registry => value === \"npm\" || value === \"crate\";\n\nconst isRelation = (value: string): value is Relation =>\n value === \"drops\" || value === \"allows\" || value === \"requires\";\n\nconst validRange = (range: string): Option.Option<string> =>\n Option.liftPredicate(range, (candidate) => semver.validRange(candidate) !== null);\n\ninterface Subject {\n readonly registry: Registry;\n readonly name: string;\n}\n\nconst declared = (subject: Subject, found: RegExpExecArray): Option.Option<ExitCondition> => {\n const relation = Option.filter(groupOf(\"relation\")(found), isRelation);\n const dependency = groupOf(\"dependency\")(found);\n const range = groupOf(\"dependencyRange\")(found);\n if (Option.isNone(relation) || Option.isNone(dependency)) {\n return Option.none();\n }\n const base = {\n kind: \"declares\",\n ...subject,\n relation: relation.value,\n dependency: dependency.value,\n } as const;\n if (relation.value === \"drops\") {\n return Option.match(range, {\n onNone: () => Option.some({ ...base, range: ANY_RANGE }),\n onSome: () => Option.none(),\n });\n }\n return pipe(\n range,\n Option.flatMap(validRange),\n Option.map((valid): ExitCondition => ({ ...base, range: valid })),\n );\n};\n\nconst registryCondition = (text: string): Option.Option<ExitCondition> => {\n const found = REGISTRY_CONDITION.exec(text);\n if (found === null) {\n return Option.none();\n }\n const subject = Option.all({\n registry: Option.filter(groupOf(\"registry\")(found), isRegistry),\n name: groupOf(\"name\")(found),\n });\n const range = groupOf(\"range\")(found);\n const conditionOf = (resolved: Subject): Option.Option<ExitCondition> =>\n Option.match(range, {\n onNone: () => declared(resolved, found),\n onSome: (published) =>\n Option.map(validRange(published), (valid): ExitCondition => ({\n kind: \"published\",\n ...resolved,\n range: valid,\n })),\n });\n return pipe(subject, Option.flatMap(conditionOf));\n};\n\nconst githubCondition = (text: string): Option.Option<ExitCondition> => {\n const found = GITHUB_CONDITION.exec(text);\n const issueNumber = pipe(groupOf(\"number\")(found), Option.map(Number));\n return pipe(\n Option.all({\n owner: groupOf(\"owner\")(found),\n repo: groupOf(\"repo\")(found),\n number: issueNumber,\n }),\n Option.map((issue): ExitCondition => ({ kind: \"closed\", ...issue })),\n );\n};\n\nconst alternativeOf = (text: string): Option.Option<ExitCondition> => {\n if (text === UNUSED) {\n return Option.some({ kind: \"unused\" });\n }\n return Option.orElse(registryCondition(text), () => githubCondition(text));\n};\n\nexport const parseCondition = (text: string): Option.Option<readonly ExitCondition[]> =>\n pipe(\n Str.split(text, ALTERNATIVE),\n Arr.map((alternative) => alternativeOf(Str.trim(alternative))),\n Option.all,\n );\n\nexport const exitTextOf = (comment: string): Option.Option<string> =>\n groupOf(\"condition\")(EXIT_COMMENT.exec(Str.trim(comment)));\n\nconst describeDeclares = (condition: Declares): string => {\n const subject = `${condition.registry}:${condition.name} ${condition.relation} ${condition.dependency}`;\n if (condition.relation === \"drops\") {\n return subject;\n }\n return `${subject}@${condition.range}`;\n};\n\nexport const describeCondition = (condition: ExitCondition): string =>\n Match.value(condition).pipe(\n Match.discriminatorsExhaustive(\"kind\")({\n unused: () => UNUSED,\n published: ({ registry, name, range }) => `${registry}:${name}@${range}`,\n declares: describeDeclares,\n closed: ({ owner, repo, number }) => `github:${owner}/${repo}#${String(number)}`,\n }),\n );\n\nexport const isUnused = (condition: ExitCondition): boolean => condition.kind === \"unused\";\n","import { Array as Arr, Effect, HashMap, Match, Option, Record as Rec, Schema, pipe } from \"effect\";\nimport { HttpClientResponse } from \"effect/http\";\nimport type { HttpClient } from \"effect/http\";\nimport semver from \"semver\";\n\nimport { fetched, githubToken, jsonLookup } from \"#/shared/lib/lookup.ts\";\nimport { registryRelease } from \"#/shared/lib/registry-releases.ts\";\nimport type { LookupError, Release } from \"#/shared/lib/registry-releases.ts\";\n\nimport { commentsByLine } from \"./deviation-entries.ts\";\nimport type { DeviationEntry, Deviations, Section } from \"./deviation-entries.ts\";\nimport { describeCondition, exitTextOf, parseCondition } from \"./exit-condition.ts\";\nimport type { Closed, Declares, ExitCondition, Published } from \"./exit-condition.ts\";\n\nconst GITHUB = \"https://api.github.com/repos/\";\nconst LOOKUP_CONCURRENCY = 4;\nconst RANGE_OPTIONS = { includePrerelease: true } as const;\n\nconst Issue = Schema.Struct({ state: Schema.String });\n\n/** @internal */\nexport interface ExitEntry {\n readonly line: number;\n readonly section: Section;\n readonly key: string;\n readonly conditions: readonly ExitCondition[];\n}\n\n/** @internal */\nexport interface MetExit {\n readonly entry: ExitEntry;\n readonly condition: string;\n readonly outcome: \"met\" | \"unchecked\";\n}\n\nconst releaseOf = (\n condition: Published | Declares,\n): Effect.Effect<Release, LookupError, HttpClient.HttpClient> =>\n registryRelease(condition.registry, condition.name);\n\nconst declaresMet =\n (release: Release) =>\n (condition: Declares): boolean => {\n const declared = Rec.get(release.latestDependencies, condition.dependency);\n if (condition.relation === \"drops\") {\n return Option.isNone(declared);\n }\n return Option.exists(declared, (range) => {\n if (semver.validRange(range) === null) {\n return false;\n }\n if (condition.relation === \"allows\") {\n return semver.intersects(range, condition.range, RANGE_OPTIONS);\n }\n return semver.subset(range, condition.range, RANGE_OPTIONS);\n });\n };\n\n/** @internal */\nexport const isMet =\n (release: Release) =>\n (condition: ExitCondition): boolean =>\n Match.value(condition).pipe(\n Match.discriminatorsExhaustive(\"kind\")({\n unused: () => false,\n closed: () => false,\n published: ({ range }) =>\n pipe(\n release.versions,\n Arr.some((version) => semver.satisfies(version, range)),\n ),\n declares: declaresMet(release),\n }),\n );\n\nconst issueClosed = Effect.fn(\"issueClosed\")(function* lookupIssue(condition: Closed) {\n const token = yield* githubToken;\n const issue = yield* fetched(\n jsonLookup({\n url: `${GITHUB}${condition.owner}/${condition.repo}/issues/${String(condition.number)}`,\n token,\n }),\n ).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Issue)));\n return issue.state === \"closed\";\n});\n\nconst conditionMet = (\n condition: ExitCondition,\n): Effect.Effect<boolean, LookupError, HttpClient.HttpClient> =>\n Match.value(condition).pipe(\n Match.discriminatorsExhaustive(\"kind\")({\n unused: () => Effect.succeed(false),\n closed: issueClosed,\n published: (published) =>\n Effect.map(releaseOf(published), (release) => isMet(release)(published)),\n declares: (declares) =>\n Effect.map(releaseOf(declares), (release) => isMet(release)(declares)),\n }),\n );\n\n/** @internal */\nexport const exitEntries = (deviations: Deviations): readonly ExitEntry[] => {\n const comments = commentsByLine(deviations.comments);\n const entryOf = ({ line, section, key }: DeviationEntry): readonly ExitEntry[] =>\n pipe(\n HashMap.get(comments, line),\n Option.flatMap(({ text }) => exitTextOf(text)),\n Option.flatMap(parseCondition),\n Option.map((conditions): ExitEntry => ({ line, section, key, conditions })),\n Option.toArray,\n );\n return pipe(deviations.entries, Arr.flatMap(entryOf));\n};\n\nconst metOf = (\n entry: ExitEntry,\n condition: ExitCondition,\n): Effect.Effect<Option.Option<MetExit>, never, HttpClient.HttpClient> => {\n const described = describeCondition(condition);\n return conditionMet(condition).pipe(\n Effect.match({\n onSuccess: (met) =>\n Option.liftPredicate({ entry, condition: described, outcome: \"met\" } as const, () => met),\n onFailure: (error) =>\n Option.some({\n entry,\n condition: `${described} (${String(error)})`,\n outcome: \"unchecked\",\n } as const),\n }),\n );\n};\n\n/** @internal */\nexport const metExits = Effect.fn(\"metExits\")(function* metExits(entries: readonly ExitEntry[]) {\n const checksOf = (entry: ExitEntry): readonly ReturnType<typeof metOf>[] =>\n pipe(\n entry.conditions,\n Arr.map((condition) => metOf(entry, condition)),\n );\n const checks = pipe(entries, Arr.flatMap(checksOf));\n const results = yield* Effect.all(checks, { concurrency: LOOKUP_CONCURRENCY });\n return Arr.getSomes(results);\n});\n","import { Array as Arr, Effect, HashMap, HashSet, Option, pipe } from \"effect\";\n\nimport type { Problem, RuleName } from \"#/shared/lib/problem.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\nimport { problemAtIndex } from \"#/shared/lib/text-position.ts\";\n\nimport { cargoDeviations, commentsByLine, workspaceDeviations } from \"./deviation-entries.ts\";\nimport type { DeviationEntry, Deviations } from \"./deviation-entries.ts\";\nimport { GRAMMAR, exitTextOf, isUnused, parseCondition } from \"./exit-condition.ts\";\nimport { exitEntries, metExits } from \"./met-exits.ts\";\nimport type { ExitEntry, MetExit } from \"./met-exits.ts\";\n\nconst RULE: RuleName = \"upstream-exit\";\nconst ROOT_FILES = [\n { name: \"pnpm-workspace.yaml\", deviationsOf: workspaceDeviations },\n { name: \"Cargo.toml\", deviationsOf: cargoDeviations },\n] as const;\nconst REASON =\n \"Every deviation from an upstream package is temporary, and the comment says when to go back to the official package so that msch-exits can tell.\";\nconst STRAY =\n \"An exit condition belongs at the end of the line of an overrides, patchedDependencies, packageExtensions or [patch] entry. Move it there or delete it.\";\n\ninterface ReadFile {\n readonly file: string;\n readonly source: string;\n readonly deviations: Deviations;\n}\n\nconst messageFor = (\n entry: DeviationEntry,\n exitText: Option.Option<string>,\n): Option.Option<string> => {\n if (Option.isNone(exitText)) {\n return Option.some(\n `${entry.section} entry ${entry.key} has no exit condition. ${REASON} Add \\`# exit: <condition>\\` at the end of the line, where the condition is ${GRAMMAR}.`,\n );\n }\n const conditions = parseCondition(exitText.value);\n if (Option.isNone(conditions)) {\n return Option.some(\n `The exit condition \\`${exitText.value}\\` of ${entry.key} is not one msch-exits can check. Write ${GRAMMAR}.`,\n );\n }\n if (entry.section !== \"overrides\" && pipe(conditions.value, Arr.some(isUnused))) {\n return Option.some(\n `\\`unused\\` is checked only for overrides, by the unused-override and removable-override checks. Give ${entry.key} a condition on a release or an issue.`,\n );\n }\n return Option.none();\n};\n\nconst entryProblems = (read: ReadFile): readonly Problem[] => {\n const comments = commentsByLine(read.deviations.comments);\n return pipe(\n read.deviations.entries,\n Arr.flatMap((entry) => {\n const exitText = pipe(\n HashMap.get(comments, entry.line),\n Option.flatMap(({ text }) => exitTextOf(text)),\n );\n return pipe(\n messageFor(entry, exitText),\n Option.map((message) => problemAtIndex(RULE)(read.file, read.source)(entry.index, message)),\n Option.toArray,\n );\n }),\n );\n};\n\nconst strayProblems = (read: ReadFile): readonly Problem[] => {\n const entryLines = HashSet.fromIterable(\n pipe(\n read.deviations.entries,\n Arr.map(({ line }) => line),\n ),\n );\n return pipe(\n read.deviations.comments,\n Arr.filter(\n (comment) =>\n Option.isSome(exitTextOf(comment.text)) && !HashSet.has(entryLines, comment.line),\n ),\n Arr.map((comment) => problemAtIndex(RULE)(read.file, read.source)(comment.index, STRAY)),\n );\n};\n\nconst readRootFiles = Effect.fn(\"readRootFiles\")(function* readRootFiles(root: string) {\n const files = yield* RepositoryFiles;\n const read = yield* Effect.forEach(\n ROOT_FILES,\n ({ name, deviationsOf }) => {\n const file = files.join(root, name);\n return Effect.map(\n files.readFile(file),\n Option.map((source): ReadFile => ({ file, source, deviations: deviationsOf(source) })),\n );\n },\n { concurrency: \"unbounded\" },\n );\n return Arr.getSomes(read);\n});\n\n/** @internal */\nexport const checkUpstreamExits = Effect.fn(\"checkUpstreamExits\")(function* checkUpstreamExits(\n root: string,\n) {\n const read = yield* readRootFiles(root);\n return pipe(\n read,\n Arr.flatMap((file) => [...entryProblems(file), ...strayProblems(file)]),\n );\n});\n\n/** @internal */\nexport interface FileExit {\n readonly file: string;\n readonly met: MetExit;\n}\n\n/** @internal */\nexport const upstreamExitsMet = Effect.fn(\"upstreamExitsMet\")(function* upstreamExitsMet(\n root: string,\n) {\n const read = yield* readRootFiles(root);\n const perFile = yield* Effect.forEach(\n read,\n ({ file, deviations }) => {\n const entries: readonly ExitEntry[] = exitEntries(deviations);\n return Effect.map(\n metExits(entries),\n Arr.map((met): FileExit => ({ file, met })),\n );\n },\n { concurrency: 1 },\n );\n return Arr.flatten(perFile);\n});\n"],"mappings":";;;;;;;;;;AAKA,MAAM,QAAQ;AACd,MAAM,eAAe;AAErB,MAAa,cACV,YACA,UAAoD;CACnD,MAAM,SAAS,KAAK,QAAQA,SAAI,MAAM,OAAO,KAAK,GAAGA,SAAI,MAAM,IAAI,CAAC;CACpE,OAAO;EACL,MAAM,OAAO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,OAAO;AAC5B,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { a as groupOf, n as RepositoryFiles } from "./repository-files-C2gVviac.mjs";
|
|
2
|
+
import { Array, Effect, Match, Option, Record, Schema, String as String$1, pipe } from "effect";
|
|
3
|
+
import { PACKAGE_JSON_FILE } from "@r_masseater/kestrion";
|
|
4
|
+
import semver from "semver";
|
|
5
|
+
// src/shared/lib/scanned-files.ts
|
|
6
|
+
const SCANNED_FILE = /(?:\.(?:[cm]?[jt]sx?|jsonc?|toml|ya?ml|sh|bash|zsh|fish|rs|cs|go|mk)|(?:^|\/)(?:(?:Dockerfile|Containerfile)[^/]*|Makefile|justfile|\.tool-versions|[^./][^./]*))$/u;
|
|
7
|
+
const LOCKFILE = /(?:^|\/)(?:[^/]*\.lock|[^/]*-lock\.(?:json|ya?ml))$/u;
|
|
8
|
+
const TOOL_VERSIONS = /(?:^|\/)(?:\.?mise(?:\.[^/]+)?\.toml|\.tool-versions)$/u;
|
|
9
|
+
const READ_CONCURRENCY = 64;
|
|
10
|
+
const isScannedText = ({ name }) => SCANNED_FILE.test(name) && !LOCKFILE.test(name);
|
|
11
|
+
const isToolVersions = ({ name }) => TOOL_VERSIONS.test(name);
|
|
12
|
+
/** @internal */
|
|
13
|
+
const listedFiles = Effect.fn("listedFiles")(function* listedFiles(root) {
|
|
14
|
+
const files = yield* RepositoryFiles;
|
|
15
|
+
const names = yield* files.ownedFiles(root);
|
|
16
|
+
return pipe(names, Array.map((name) => ({
|
|
17
|
+
name,
|
|
18
|
+
file: files.join(root, name)
|
|
19
|
+
})));
|
|
20
|
+
});
|
|
21
|
+
/** @internal */
|
|
22
|
+
const presentFiles = Effect.fn("presentFiles")(function* presentFiles(listed) {
|
|
23
|
+
const files = yield* RepositoryFiles;
|
|
24
|
+
return yield* pipe(listed, Effect.filter(({ file }) => files.exists(file)));
|
|
25
|
+
});
|
|
26
|
+
/** @internal */
|
|
27
|
+
const scanText = Effect.fn("scanText")(function* scanText(listed, foundIn) {
|
|
28
|
+
const files = yield* RepositoryFiles;
|
|
29
|
+
const found = yield* Effect.forEach(listed, (entry) => files.readFile(entry.file).pipe(Effect.map(Option.match({
|
|
30
|
+
onNone: () => [],
|
|
31
|
+
onSome: (source) => foundIn(entry, source)
|
|
32
|
+
}))), { concurrency: READ_CONCURRENCY });
|
|
33
|
+
return Array.flatten(found);
|
|
34
|
+
});
|
|
35
|
+
// src/features/check-upstream-updates/model/upstream-source.ts
|
|
36
|
+
const PACKAGE = String.raw`(?:@[^\s/@]+\/)?[^\s/@]+`;
|
|
37
|
+
const SOURCE = new RegExp(String.raw`^(?:(?<registry>npm|crate):(?<name>${PACKAGE})|github:(?<owner>[\w.-]+)\/(?<repo>[\w.-]+))$`, "u");
|
|
38
|
+
/** @internal */
|
|
39
|
+
const SOURCE_GRAMMAR = "`npm:<package>`, `crate:<crate>` or `github:<owner>/<repo>`";
|
|
40
|
+
const isRegistry = (value) => value === "npm" || value === "crate";
|
|
41
|
+
const registrySource = (found) => Option.all({
|
|
42
|
+
registry: Option.filter(groupOf("registry")(found), isRegistry),
|
|
43
|
+
name: groupOf("name")(found)
|
|
44
|
+
}).pipe(Option.map((source) => ({
|
|
45
|
+
kind: "registry",
|
|
46
|
+
...source
|
|
47
|
+
})));
|
|
48
|
+
const githubSource = (found) => Option.all({
|
|
49
|
+
owner: groupOf("owner")(found),
|
|
50
|
+
repo: groupOf("repo")(found)
|
|
51
|
+
}).pipe(Option.map((source) => ({
|
|
52
|
+
kind: "github",
|
|
53
|
+
...source
|
|
54
|
+
})));
|
|
55
|
+
/** @internal */
|
|
56
|
+
const parseSource = (text) => pipe(Option.fromNullishOr(SOURCE.exec(text)), Option.flatMap((found) => Option.orElse(registrySource(found), () => githubSource(found))));
|
|
57
|
+
/** @internal */
|
|
58
|
+
const describeSource = (source) => Match.value(source).pipe(Match.discriminatorsExhaustive("kind")({
|
|
59
|
+
registry: ({ registry, name }) => `${registry}:${name}`,
|
|
60
|
+
github: ({ owner, repo }) => `github:${owner}/${repo}`
|
|
61
|
+
}));
|
|
62
|
+
// src/features/check-upstream-updates/model/upstream-record.ts
|
|
63
|
+
const RULE = "upstream-record";
|
|
64
|
+
const EXCLUDED = [":(exclude,attr:linguist-vendored)", ":(exclude,attr:linguist-generated)"];
|
|
65
|
+
const FIRST_INDEX = 0;
|
|
66
|
+
const LINE_OFFSET = 1;
|
|
67
|
+
const FIRST_COLUMN = 1;
|
|
68
|
+
/** @internal */
|
|
69
|
+
const VERDICTS = [
|
|
70
|
+
"adopted",
|
|
71
|
+
"skipped",
|
|
72
|
+
"changed"
|
|
73
|
+
];
|
|
74
|
+
const Entry = Schema.Struct({
|
|
75
|
+
reviewed: Schema.String,
|
|
76
|
+
verdict: Schema.Literals(VERDICTS),
|
|
77
|
+
reason: Schema.String.check(Schema.isNonEmpty())
|
|
78
|
+
});
|
|
79
|
+
const Manifest = Schema.Struct({ upstream: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)) });
|
|
80
|
+
const decodeManifest = Schema.decodeUnknownOption(Schema.fromJsonString(Manifest));
|
|
81
|
+
const decodeEntry = Schema.decodeUnknownOption(Entry);
|
|
82
|
+
const REASON = "A workspace that reimplements something records its upstream so that msch-upstream can tell when the upstream moves on without a decision.";
|
|
83
|
+
const SHAPE = `Write \`"<source>": { "reviewed": "<version>", "verdict": ${pipe(VERDICTS, Array.map((verdict) => `"${verdict}"`), Array.join(" | "))}, "reason": "<why>" }\``;
|
|
84
|
+
const lineOf = ({ source, key }) => {
|
|
85
|
+
const lines = String$1.split("\n")(source);
|
|
86
|
+
const section = pipe(lines, Array.findFirstIndex(String$1.includes("\"upstream\"")), Option.getOrElse(() => FIRST_INDEX));
|
|
87
|
+
return section + pipe(lines, Array.drop(section), Array.findFirstIndex(String$1.includes(`"${key}"`)), Option.getOrElse(() => FIRST_INDEX)) + LINE_OFFSET;
|
|
88
|
+
};
|
|
89
|
+
const problemOf = (place, message) => ({
|
|
90
|
+
record: Option.none(),
|
|
91
|
+
problem: Option.some({
|
|
92
|
+
file: place.file,
|
|
93
|
+
line: lineOf(place),
|
|
94
|
+
column: FIRST_COLUMN,
|
|
95
|
+
rule: RULE,
|
|
96
|
+
message
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
const foundFrom = (place, value) => {
|
|
100
|
+
const upstream = parseSource(place.key);
|
|
101
|
+
if (Option.isNone(upstream)) return problemOf(place, `The upstream \`${place.key}\` is not a source msch-upstream can look up. ${REASON} Write ${SOURCE_GRAMMAR}.`);
|
|
102
|
+
const entry = decodeEntry(value);
|
|
103
|
+
if (Option.isNone(entry)) return problemOf(place, `The record of the upstream \`${describeSource(upstream.value)}\` is incomplete. ${REASON} ${SHAPE}.`);
|
|
104
|
+
if (semver.valid(entry.value.reviewed) !== entry.value.reviewed) return problemOf(place, `\`reviewed\` of the upstream \`${place.key}\` is \`${entry.value.reviewed}\`, which is not a plain version such as \`1.7.12\`. Write the last upstream version whose changes were decided on, without a \`v\`.`);
|
|
105
|
+
return {
|
|
106
|
+
record: Option.some({
|
|
107
|
+
file: place.file,
|
|
108
|
+
line: lineOf(place),
|
|
109
|
+
key: place.key,
|
|
110
|
+
source: upstream.value,
|
|
111
|
+
reviewed: entry.value.reviewed
|
|
112
|
+
}),
|
|
113
|
+
problem: Option.none()
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const foundIn = (file, source) => pipe(decodeManifest(source), Option.flatMap(({ upstream }) => Option.fromUndefinedOr(upstream)), Option.map(Record.toEntries), Option.getOrElse(() => []), Array.map(([key, value]) => foundFrom({
|
|
117
|
+
file,
|
|
118
|
+
source,
|
|
119
|
+
key
|
|
120
|
+
}, value)));
|
|
121
|
+
/** @internal */
|
|
122
|
+
const upstreamRecords = Effect.fn("upstreamRecords")(function* upstreamRecords(root) {
|
|
123
|
+
const files = yield* RepositoryFiles;
|
|
124
|
+
const names = yield* files.matchingFiles(root, [`:(glob)**/${PACKAGE_JSON_FILE}`, ...EXCLUDED]);
|
|
125
|
+
const all = yield* scanText(pipe(names, Array.map((name) => ({
|
|
126
|
+
name,
|
|
127
|
+
file: files.join(root, name)
|
|
128
|
+
}))), ({ file }, source) => foundIn(file, source));
|
|
129
|
+
return {
|
|
130
|
+
records: pipe(all, Array.flatMap(({ record }) => Option.toArray(record))),
|
|
131
|
+
problems: pipe(all, Array.flatMap(({ problem }) => Option.toArray(problem)))
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
export { presentFiles as a, listedFiles as i, isScannedText as n, scanText as o, isToolVersions as r, upstreamRecords as t };
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=upstream-record-CSbML0KF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-record-CSbML0KF.mjs","names":["Arr","Arr","Str","Rec"],"sources":["../src/shared/lib/scanned-files.ts","../src/features/check-upstream-updates/model/upstream-source.ts","../src/features/check-upstream-updates/model/upstream-record.ts"],"sourcesContent":["import { Array as Arr, Effect, Option, pipe } from \"effect\";\n\nimport { RepositoryFiles } from \"./repository-files.ts\";\n\nconst SCANNED_FILE =\n /(?:\\.(?:[cm]?[jt]sx?|jsonc?|toml|ya?ml|sh|bash|zsh|fish|rs|cs|go|mk)|(?:^|\\/)(?:(?:Dockerfile|Containerfile)[^/]*|Makefile|justfile|\\.tool-versions|[^./][^./]*))$/u;\n\nconst LOCKFILE = /(?:^|\\/)(?:[^/]*\\.lock|[^/]*-lock\\.(?:json|ya?ml))$/u;\n\nconst TOOL_VERSIONS = /(?:^|\\/)(?:\\.?mise(?:\\.[^/]+)?\\.toml|\\.tool-versions)$/u;\n\nconst READ_CONCURRENCY = 64;\n\nexport interface Listed {\n readonly name: string;\n readonly file: string;\n}\n\nexport const isScannedText = ({ name }: Listed): boolean =>\n SCANNED_FILE.test(name) && !LOCKFILE.test(name);\n\nexport const isToolVersions = ({ name }: Listed): boolean => TOOL_VERSIONS.test(name);\n\n/** @internal */\nexport const listedFiles = Effect.fn(\"listedFiles\")(function* listedFiles(root: string) {\n const files = yield* RepositoryFiles;\n const names = yield* files.ownedFiles(root);\n return pipe(\n names,\n Arr.map((name): Listed => ({ name, file: files.join(root, name) })),\n );\n});\n\n/** @internal */\nexport const presentFiles = Effect.fn(\"presentFiles\")(function* presentFiles(\n listed: readonly Listed[],\n) {\n const files = yield* RepositoryFiles;\n return yield* pipe(\n listed,\n Effect.filter(({ file }) => files.exists(file)),\n );\n});\n\n/** @internal */\nexport const scanText = Effect.fn(\"scanText\")(function* scanText<Found>(\n listed: readonly Listed[],\n foundIn: (entry: Listed, source: string) => readonly Found[],\n) {\n const files = yield* RepositoryFiles;\n const found = yield* Effect.forEach(\n listed,\n (entry) =>\n files.readFile(entry.file).pipe(\n Effect.map(\n Option.match({\n onNone: (): readonly Found[] => [],\n onSome: (source) => foundIn(entry, source),\n }),\n ),\n ),\n { concurrency: READ_CONCURRENCY },\n );\n return Arr.flatten(found);\n});\n","import { groupOf } from \"@masseater.dev/lint-host/collections\";\nimport { Match, Option, pipe } from \"effect\";\n\nimport type { Registry } from \"#/shared/lib/registry-releases.ts\";\n\nconst PACKAGE = String.raw`(?:@[^\\s/@]+\\/)?[^\\s/@]+`;\nconst SOURCE = new RegExp(\n String.raw`^(?:(?<registry>npm|crate):(?<name>${PACKAGE})|github:(?<owner>[\\w.-]+)\\/(?<repo>[\\w.-]+))$`,\n \"u\",\n);\n\n/** @internal */\nexport interface RegistrySource {\n readonly kind: \"registry\";\n readonly registry: Registry;\n readonly name: string;\n}\n\n/** @internal */\nexport interface GithubSource {\n readonly kind: \"github\";\n readonly owner: string;\n readonly repo: string;\n}\n\n/** @internal */\nexport type UpstreamSource = RegistrySource | GithubSource;\n\n/** @internal */\nexport const SOURCE_GRAMMAR = \"`npm:<package>`, `crate:<crate>` or `github:<owner>/<repo>`\";\n\nconst isRegistry = (value: string): value is Registry => value === \"npm\" || value === \"crate\";\n\nconst registrySource = (found: RegExpExecArray): Option.Option<UpstreamSource> =>\n Option.all({\n registry: Option.filter(groupOf(\"registry\")(found), isRegistry),\n name: groupOf(\"name\")(found),\n }).pipe(Option.map((source): UpstreamSource => ({ kind: \"registry\", ...source })));\n\nconst githubSource = (found: RegExpExecArray): Option.Option<UpstreamSource> =>\n Option.all({ owner: groupOf(\"owner\")(found), repo: groupOf(\"repo\")(found) }).pipe(\n Option.map((source): UpstreamSource => ({ kind: \"github\", ...source })),\n );\n\n/** @internal */\nexport const parseSource = (text: string): Option.Option<UpstreamSource> =>\n pipe(\n Option.fromNullishOr(SOURCE.exec(text)),\n Option.flatMap((found) => Option.orElse(registrySource(found), () => githubSource(found))),\n );\n\n/** @internal */\nexport const describeSource = (source: UpstreamSource): string =>\n Match.value(source).pipe(\n Match.discriminatorsExhaustive(\"kind\")({\n registry: ({ registry, name }) => `${registry}:${name}`,\n github: ({ owner, repo }) => `github:${owner}/${repo}`,\n }),\n );\n","import { PACKAGE_JSON_FILE } from \"@r_masseater/kestrion\";\nimport { Array as Arr, Effect, Option, Record as Rec, Schema, String as Str, pipe } from \"effect\";\nimport semver from \"semver\";\n\nimport type { Problem, RuleName } from \"#/shared/lib/problem.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\nimport { scanText } from \"#/shared/lib/scanned-files.ts\";\nimport type { Listed } from \"#/shared/lib/scanned-files.ts\";\n\nimport { SOURCE_GRAMMAR, describeSource, parseSource } from \"./upstream-source.ts\";\nimport type { UpstreamSource } from \"./upstream-source.ts\";\n\nconst RULE: RuleName = \"upstream-record\";\nconst EXCLUDED = [\":(exclude,attr:linguist-vendored)\", \":(exclude,attr:linguist-generated)\"];\nconst FIRST_INDEX = 0;\nconst LINE_OFFSET = 1;\nconst FIRST_COLUMN = 1;\n\n/** @internal */\nexport const VERDICTS = [\"adopted\", \"skipped\", \"changed\"] as const;\n\nconst Entry = Schema.Struct({\n reviewed: Schema.String,\n verdict: Schema.Literals(VERDICTS),\n reason: Schema.String.check(Schema.isNonEmpty()),\n});\n\nconst Manifest = Schema.Struct({\n upstream: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n});\n\nconst decodeManifest = Schema.decodeUnknownOption(Schema.fromJsonString(Manifest));\nconst decodeEntry = Schema.decodeUnknownOption(Entry);\n\nconst REASON =\n \"A workspace that reimplements something records its upstream so that msch-upstream can tell when the upstream moves on without a decision.\";\nconst VERDICT_CHOICES = pipe(\n VERDICTS,\n Arr.map((verdict) => `\"${verdict}\"`),\n Arr.join(\" | \"),\n);\nconst SHAPE = `Write \\`\"<source>\": { \"reviewed\": \"<version>\", \"verdict\": ${VERDICT_CHOICES}, \"reason\": \"<why>\" }\\``;\n\n/** @internal */\nexport interface UpstreamRecord {\n readonly file: string;\n readonly line: number;\n readonly key: string;\n readonly source: UpstreamSource;\n readonly reviewed: string;\n}\n\n/** @internal */\nexport interface UpstreamRecords {\n readonly records: readonly UpstreamRecord[];\n readonly problems: readonly Problem[];\n}\n\ninterface Found {\n readonly record: Option.Option<UpstreamRecord>;\n readonly problem: Option.Option<Problem>;\n}\n\ninterface Place {\n readonly file: string;\n readonly source: string;\n readonly key: string;\n}\n\nconst lineOf = ({ source, key }: Place): number => {\n const lines = Str.split(\"\\n\")(source);\n const section = pipe(\n lines,\n Arr.findFirstIndex(Str.includes('\"upstream\"')),\n Option.getOrElse(() => FIRST_INDEX),\n );\n const offset = pipe(\n lines,\n Arr.drop(section),\n Arr.findFirstIndex(Str.includes(`\"${key}\"`)),\n Option.getOrElse(() => FIRST_INDEX),\n );\n return section + offset + LINE_OFFSET;\n};\n\nconst problemOf = (place: Place, message: string): Found => ({\n record: Option.none(),\n problem: Option.some({\n file: place.file,\n line: lineOf(place),\n column: FIRST_COLUMN,\n rule: RULE,\n message,\n }),\n});\n\nconst foundFrom = (place: Place, value: unknown): Found => {\n const upstream = parseSource(place.key);\n if (Option.isNone(upstream)) {\n return problemOf(\n place,\n `The upstream \\`${place.key}\\` is not a source msch-upstream can look up. ${REASON} Write ${SOURCE_GRAMMAR}.`,\n );\n }\n const entry = decodeEntry(value);\n if (Option.isNone(entry)) {\n return problemOf(\n place,\n `The record of the upstream \\`${describeSource(upstream.value)}\\` is incomplete. ${REASON} ${SHAPE}.`,\n );\n }\n if (semver.valid(entry.value.reviewed) !== entry.value.reviewed) {\n return problemOf(\n place,\n `\\`reviewed\\` of the upstream \\`${place.key}\\` is \\`${entry.value.reviewed}\\`, which is not a plain version such as \\`1.7.12\\`. Write the last upstream version whose changes were decided on, without a \\`v\\`.`,\n );\n }\n return {\n record: Option.some({\n file: place.file,\n line: lineOf(place),\n key: place.key,\n source: upstream.value,\n reviewed: entry.value.reviewed,\n }),\n problem: Option.none(),\n };\n};\n\nconst foundIn = (file: string, source: string): readonly Found[] =>\n pipe(\n decodeManifest(source),\n Option.flatMap(({ upstream }) => Option.fromUndefinedOr(upstream)),\n Option.map(Rec.toEntries),\n Option.getOrElse((): readonly (readonly [string, unknown])[] => []),\n Arr.map(([key, value]) => foundFrom({ file, source, key }, value)),\n );\n\n/** @internal */\nexport const upstreamRecords = Effect.fn(\"upstreamRecords\")(function* upstreamRecords(\n root: string,\n) {\n const files = yield* RepositoryFiles;\n const names = yield* files.matchingFiles(root, [`:(glob)**/${PACKAGE_JSON_FILE}`, ...EXCLUDED]);\n const all = yield* scanText(\n pipe(\n names,\n Arr.map((name): Listed => ({ name, file: files.join(root, name) })),\n ),\n ({ file }, source) => foundIn(file, source),\n );\n const upstreams: UpstreamRecords = {\n records: pipe(\n all,\n Arr.flatMap(({ record }) => Option.toArray(record)),\n ),\n problems: pipe(\n all,\n Arr.flatMap(({ problem }) => Option.toArray(problem)),\n ),\n };\n return upstreams;\n});\n"],"mappings":";;;;;AAIA,MAAM,eACJ;AAEF,MAAM,WAAW;AAEjB,MAAM,gBAAgB;AAEtB,MAAM,mBAAmB;AAOzB,MAAa,iBAAiB,EAAE,WAC9B,aAAa,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,IAAI;AAEhD,MAAa,kBAAkB,EAAE,WAA4B,cAAc,KAAK,IAAI;;A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,CAAC,GACjE,OAAO,IAAIC,OAAI,SAAS,GACxB,OAAO,gBAAyD,CAAC,CAAC,GAClEF,MAAI,KAAK,CAAC,KAAK,WAAW,UAAU;CAAE;CAAM;CAAQ;AAAI,GAAG,KAAK,CAAC,CACnE;;AAGF,MAAa,kBAAkB,OAAO,GAAG,iBAAiB,CAAC,CAAC,UAAU,gBACpE,MACA;CACA,MAAM,QAAQ,OAAO;CACrB,MAAM,QAAQ,OAAO,MAAM,cAAc,MAAM,CAAC,aAAa,qBAAqB,GAAG,QAAQ,CAAC;CAC9F,MAAM,MAAM,OAAO,SACjB,KACE,OACAA,MAAI,KAAK,UAAkB;EAAE;EAAM,MAAM,MAAM,KAAK,MAAM,IAAI;CAAE,EAAE,CACpE,IACC,EAAE,QAAQ,WAAW,QAAQ,MAAM,MAAM,CAC5C;CAWA,OAAO;EATL,SAAS,KACP,KACAA,MAAI,SAAS,EAAE,aAAa,OAAO,QAAQ,MAAM,CAAC,CACpD;EACA,UAAU,KACR,KACAA,MAAI,SAAS,EAAE,cAAc,OAAO,QAAQ,OAAO,CAAC,CACtD;CAEa;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as lookupReport } from "./lookup-report-BdUByHMt.mjs";
|
|
3
|
+
import { t as runCli } from "./runtime-CFZ41rB0.mjs";
|
|
4
|
+
import { a as groupOf } from "./repository-files-C2gVviac.mjs";
|
|
5
|
+
import { n as githubToken, r as jsonLookup, t as fetched } from "./lookup-DjQU0W6q.mjs";
|
|
6
|
+
import { t as registryRelease } from "./registry-releases-E0PE3Wq-.mjs";
|
|
7
|
+
import { t as upstreamRecords } from "./upstream-record-CSbML0KF.mjs";
|
|
8
|
+
import { Array, Effect, Option, Order, Schema, pipe } from "effect";
|
|
9
|
+
import semver from "semver";
|
|
10
|
+
import { HttpClientResponse } from "effect/http";
|
|
11
|
+
// src/features/check-upstream-updates/model/newer-versions.ts
|
|
12
|
+
const versionOrder = Order.make((left, right) => semver.compare(left, right));
|
|
13
|
+
const isVersion = (text) => Option.isSome(Option.fromNullishOr(semver.valid(text)));
|
|
14
|
+
const isPrerelease = (version) => Option.isSome(Option.fromNullishOr(semver.prerelease(version)));
|
|
15
|
+
/** @internal */
|
|
16
|
+
const newerVersions = (reviewed) => (versions) => {
|
|
17
|
+
const followsPrereleases = isPrerelease(reviewed);
|
|
18
|
+
return pipe(versions, Array.filter((version) => isVersion(version) && semver.gt(version, reviewed) && (followsPrereleases || !isPrerelease(version))), Array.sortWith((version) => version, versionOrder));
|
|
19
|
+
};
|
|
20
|
+
// src/features/check-upstream-updates/model/released-versions.ts
|
|
21
|
+
const GITHUB = "https://api.github.com/repos/";
|
|
22
|
+
const PAGE = "per_page=100";
|
|
23
|
+
const VERSION_AT_END = /(?<version>\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/u;
|
|
24
|
+
const Releases = Schema.Array(Schema.Struct({
|
|
25
|
+
tag_name: Schema.String,
|
|
26
|
+
draft: Schema.Boolean
|
|
27
|
+
}));
|
|
28
|
+
const Tags = Schema.Array(Schema.Struct({ name: Schema.String }));
|
|
29
|
+
/** @internal */
|
|
30
|
+
const versionOfTag = (tag) => pipe(Option.fromNullishOr(VERSION_AT_END.exec(tag)), Option.flatMap(groupOf("version")));
|
|
31
|
+
const githubLookup = Effect.fn("githubLookup")(function* githubLookup(url) {
|
|
32
|
+
const token = yield* githubToken;
|
|
33
|
+
return yield* fetched(jsonLookup({
|
|
34
|
+
url,
|
|
35
|
+
token
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
const githubVersions = Effect.fn("githubVersions")(function* githubVersions({ owner, repo }) {
|
|
39
|
+
const base = `${GITHUB}${owner}/${repo}`;
|
|
40
|
+
const releases = yield* githubLookup(`${base}/releases?${PAGE}`).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Releases)));
|
|
41
|
+
const released = pipe(releases, Array.filter(({ draft }) => !draft), Array.flatMap(({ tag_name: tag }) => Option.toArray(versionOfTag(tag))));
|
|
42
|
+
if (Array.isReadonlyArrayNonEmpty(released)) return released;
|
|
43
|
+
const tags = yield* githubLookup(`${base}/tags?${PAGE}`).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Tags)));
|
|
44
|
+
return pipe(tags, Array.flatMap(({ name }) => Option.toArray(versionOfTag(name))));
|
|
45
|
+
});
|
|
46
|
+
/** @internal */
|
|
47
|
+
const releasedVersions = (source) => {
|
|
48
|
+
if (source.kind === "github") return githubVersions(source);
|
|
49
|
+
return registryRelease(source.registry, source.name).pipe(Effect.map(({ versions }) => versions));
|
|
50
|
+
};
|
|
51
|
+
// src/features/check-upstream-updates/model/undecided-updates.ts
|
|
52
|
+
const LOOKUP_CONCURRENCY = 4;
|
|
53
|
+
const releasesText = (count, latest) => `${String(count)} newer, the latest is ${latest}`;
|
|
54
|
+
const updateOf = (record) => {
|
|
55
|
+
const base = {
|
|
56
|
+
file: record.file,
|
|
57
|
+
line: record.line,
|
|
58
|
+
upstream: record.key,
|
|
59
|
+
reviewed: record.reviewed
|
|
60
|
+
};
|
|
61
|
+
return releasedVersions(record.source).pipe(Effect.match({
|
|
62
|
+
onSuccess: (versions) => {
|
|
63
|
+
const newer = newerVersions(record.reviewed)(versions);
|
|
64
|
+
return pipe(Array.last(newer), Option.map((latest) => ({
|
|
65
|
+
...base,
|
|
66
|
+
outcome: "undecided",
|
|
67
|
+
detail: releasesText(newer.length, latest)
|
|
68
|
+
})));
|
|
69
|
+
},
|
|
70
|
+
onFailure: (error) => Option.some({
|
|
71
|
+
...base,
|
|
72
|
+
outcome: "unchecked",
|
|
73
|
+
detail: String(error)
|
|
74
|
+
})
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
/** @internal */
|
|
78
|
+
const undecidedUpdates = Effect.fn("undecidedUpdates")(function* undecidedUpdates(root) {
|
|
79
|
+
const { records } = yield* upstreamRecords(root);
|
|
80
|
+
const found = yield* Effect.forEach(records, updateOf, { concurrency: LOOKUP_CONCURRENCY });
|
|
81
|
+
return Array.getSomes(found);
|
|
82
|
+
});
|
|
83
|
+
// bin/msch-upstream.ts
|
|
84
|
+
const Row = Schema.Struct({
|
|
85
|
+
file: Schema.String,
|
|
86
|
+
line: Schema.Finite,
|
|
87
|
+
upstream: Schema.String,
|
|
88
|
+
reviewed: Schema.String,
|
|
89
|
+
outcome: Schema.Literals(["undecided", "unchecked"]),
|
|
90
|
+
detail: Schema.String
|
|
91
|
+
});
|
|
92
|
+
const VERDICTS = {
|
|
93
|
+
undecided: "has changes nobody decided on. Read them, then set reviewed, verdict and reason of the record.",
|
|
94
|
+
unchecked: "could not be checked. Check it by hand or rerun where the lookup is reachable."
|
|
95
|
+
};
|
|
96
|
+
const describeRow = (row) => `${row.file}:${String(row.line)} upstream ${row.upstream} after ${row.reviewed}: ${row.detail}. It ${VERDICTS[row.outcome]}`;
|
|
97
|
+
runCli("msch-upstream")(lookupReport({
|
|
98
|
+
row: Row,
|
|
99
|
+
rows: undecidedUpdates,
|
|
100
|
+
describe: describeRow
|
|
101
|
+
}));
|
|
102
|
+
export {};
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=upstream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream.mjs","names":["Arr","Arr","Arr"],"sources":["../src/features/check-upstream-updates/model/newer-versions.ts","../src/features/check-upstream-updates/model/released-versions.ts","../src/features/check-upstream-updates/model/undecided-updates.ts","../bin/msch-upstream.ts"],"sourcesContent":["import { Array as Arr, Option, Order, pipe } from \"effect\";\nimport semver from \"semver\";\n\nconst versionOrder = Order.make<string>((left, right) => semver.compare(left, right));\n\nconst isVersion = (text: string): boolean =>\n Option.isSome(Option.fromNullishOr(semver.valid(text)));\n\nconst isPrerelease = (version: string): boolean =>\n Option.isSome(Option.fromNullishOr(semver.prerelease(version)));\n\n/** @internal */\nexport const newerVersions =\n (reviewed: string) =>\n (versions: readonly string[]): readonly string[] => {\n const followsPrereleases = isPrerelease(reviewed);\n return pipe(\n versions,\n Arr.filter(\n (version) =>\n isVersion(version) &&\n semver.gt(version, reviewed) &&\n (followsPrereleases || !isPrerelease(version)),\n ),\n Arr.sortWith((version: string) => version, versionOrder),\n );\n };\n","import { groupOf } from \"@masseater.dev/lint-host/collections\";\nimport { Array as Arr, Effect, Option, Schema, pipe } from \"effect\";\nimport { HttpClientResponse } from \"effect/http\";\nimport type { HttpClient } from \"effect/http\";\n\nimport { fetched, githubToken, jsonLookup } from \"#/shared/lib/lookup.ts\";\nimport { registryRelease } from \"#/shared/lib/registry-releases.ts\";\nimport type { LookupError } from \"#/shared/lib/registry-releases.ts\";\n\nimport type { GithubSource, UpstreamSource } from \"./upstream-source.ts\";\n\nconst GITHUB = \"https://api.github.com/repos/\";\nconst PAGE = \"per_page=100\";\nconst VERSION_AT_END = /(?<version>\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?)$/u;\n\nconst Releases = Schema.Array(Schema.Struct({ tag_name: Schema.String, draft: Schema.Boolean }));\nconst Tags = Schema.Array(Schema.Struct({ name: Schema.String }));\n\n/** @internal */\nexport const versionOfTag = (tag: string): Option.Option<string> =>\n pipe(Option.fromNullishOr(VERSION_AT_END.exec(tag)), Option.flatMap(groupOf(\"version\")));\n\nconst githubLookup = Effect.fn(\"githubLookup\")(function* githubLookup(url: string) {\n const token = yield* githubToken;\n return yield* fetched(jsonLookup({ url, token }));\n});\n\nconst githubVersions = Effect.fn(\"githubVersions\")(function* githubVersions({\n owner,\n repo,\n}: GithubSource) {\n const base = `${GITHUB}${owner}/${repo}`;\n const releases = yield* githubLookup(`${base}/releases?${PAGE}`).pipe(\n Effect.flatMap(HttpClientResponse.schemaBodyJson(Releases)),\n );\n const released = pipe(\n releases,\n Arr.filter(({ draft }) => !draft),\n Arr.flatMap(({ tag_name: tag }) => Option.toArray(versionOfTag(tag))),\n );\n if (Arr.isReadonlyArrayNonEmpty(released)) {\n return released;\n }\n const tags = yield* githubLookup(`${base}/tags?${PAGE}`).pipe(\n Effect.flatMap(HttpClientResponse.schemaBodyJson(Tags)),\n );\n return pipe(\n tags,\n Arr.flatMap(({ name }) => Option.toArray(versionOfTag(name))),\n );\n});\n\n/** @internal */\nexport const releasedVersions = (\n source: UpstreamSource,\n): Effect.Effect<readonly string[], LookupError, HttpClient.HttpClient> => {\n if (source.kind === \"github\") {\n return githubVersions(source);\n }\n return registryRelease(source.registry, source.name).pipe(Effect.map(({ versions }) => versions));\n};\n","import { Array as Arr, Effect, Option, pipe } from \"effect\";\nimport type { HttpClient } from \"effect/http\";\n\nimport { newerVersions } from \"./newer-versions.ts\";\nimport { releasedVersions } from \"./released-versions.ts\";\nimport { upstreamRecords } from \"./upstream-record.ts\";\nimport type { UpstreamRecord } from \"./upstream-record.ts\";\n\nconst LOOKUP_CONCURRENCY = 4;\n\n/** @internal */\nexport interface UndecidedUpdate {\n readonly file: string;\n readonly line: number;\n readonly upstream: string;\n readonly reviewed: string;\n readonly outcome: \"undecided\" | \"unchecked\";\n readonly detail: string;\n}\n\nconst releasesText = (count: number, latest: string): string =>\n `${String(count)} newer, the latest is ${latest}`;\n\nconst updateOf = (\n record: UpstreamRecord,\n): Effect.Effect<Option.Option<UndecidedUpdate>, never, HttpClient.HttpClient> => {\n const base = {\n file: record.file,\n line: record.line,\n upstream: record.key,\n reviewed: record.reviewed,\n };\n return releasedVersions(record.source).pipe(\n Effect.match({\n onSuccess: (versions) => {\n const newer = newerVersions(record.reviewed)(versions);\n return pipe(\n Arr.last(newer),\n Option.map((latest): UndecidedUpdate => ({\n ...base,\n outcome: \"undecided\",\n detail: releasesText(newer.length, latest),\n })),\n );\n },\n onFailure: (error) =>\n Option.some<UndecidedUpdate>({ ...base, outcome: \"unchecked\", detail: String(error) }),\n }),\n );\n};\n\n/** @internal */\nexport const undecidedUpdates = Effect.fn(\"undecidedUpdates\")(function* undecidedUpdates(\n root: string,\n) {\n const { records } = yield* upstreamRecords(root);\n const found = yield* Effect.forEach(records, updateOf, { concurrency: LOOKUP_CONCURRENCY });\n return Arr.getSomes(found);\n});\n","#!/usr/bin/env node\nimport { Schema } from \"effect\";\n\nimport { lookupReport } from \"#/app/lookup-report.ts\";\nimport { runCli } from \"#/app/runtime.ts\";\nimport { undecidedUpdates } from \"#/features/check-upstream-updates/index.ts\";\n\nconst Row = Schema.Struct({\n file: Schema.String,\n line: Schema.Finite,\n upstream: Schema.String,\n reviewed: Schema.String,\n outcome: Schema.Literals([\"undecided\", \"unchecked\"]),\n detail: Schema.String,\n});\n\ntype RowType = typeof Row.Type;\n\nconst VERDICTS: Readonly<Record<RowType[\"outcome\"], string>> = {\n undecided:\n \"has changes nobody decided on. Read them, then set reviewed, verdict and reason of the record.\",\n unchecked: \"could not be checked. Check it by hand or rerun where the lookup is reachable.\",\n};\n\nconst describeRow = (row: RowType): string =>\n `${row.file}:${String(row.line)} upstream ${row.upstream} after ${row.reviewed}: ${row.detail}. It ${VERDICTS[row.outcome]}`;\n\nrunCli(\"msch-upstream\")(lookupReport({ row: Row, rows: undecidedUpdates, describe: describeRow }));\n"],"mappings":";;;;;;;;;;;AAGA,MAAM,eAAe,MAAM,MAAc,MAAM,UAAU,OAAO,QAAQ,MAAM,KAAK,CAAC;AAEpF,MAAM,aAAa,SACjB,OAAO,OAAO,OAAO,cAAc,OAAO,MAAM,IAAI,CAAC,CAAC;AAExD,MAAM,gBAAgB,YACpB,OAAO,OAAO,OAAO,cAAc,OAAO,WAAW,OAAO,CAAC,CAAC;;AAGhE,MAAa,iBACV,cACA,aAAmD;CAClD,MAAM,qBAAqB,aAAa,QAAQ;CAChD,OAAO,KACL,UACAA,MAAI,QACD,YACC,UAAU,OAAO,KACjB,OAAO,GAAG,SAAS,QAAQ,MAC1B,sBAAsB,CAAC,aAAa,OAAO,EAChD,GACAA,MAAI,UAAU,YAAoB,SAAS,YAAY,CACzD;AACF;;ACfF,MAAM,SAAS;AACf,MAAM,OA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AAI,SAAS,SAAS,IAAI,SAAS,IAAI,IAAI,OAAO,OAAO,SAAS,IAAI;AAEpH,OAAO,eAAe,CAAC,CAAC,aAAa;CAAE,KAAK;CAAK,MAAM;CAAkB,UAAU;AAAY,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/msch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.0",
|
|
4
4
|
"description": "masseater's check policy: points every finite value set and object shape at its one owner, and ships the oxlint preset of plugins and rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lint",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"msch-published": "./dist/published.mjs",
|
|
27
27
|
"msch-refs": "./dist/refs.mjs",
|
|
28
28
|
"msch-unbumped": "./dist/unbumped.mjs",
|
|
29
|
+
"msch-upstream": "./dist/upstream.mjs",
|
|
29
30
|
"msch-wake": "./dist/wake.mjs"
|
|
30
31
|
},
|
|
31
32
|
"files": [
|
|
@@ -91,8 +92,8 @@
|
|
|
91
92
|
},
|
|
92
93
|
"dependencies": {
|
|
93
94
|
"@commitlint/config-conventional": "^21.2.4",
|
|
94
|
-
"@effect/platform-node": "^4.1.
|
|
95
|
-
"@effect/platform-node-shared": "^4.1.
|
|
95
|
+
"@effect/platform-node": "^4.1.6",
|
|
96
|
+
"@effect/platform-node-shared": "^4.1.6",
|
|
96
97
|
"@html-eslint/eslint-plugin-react": "^0.69.0",
|
|
97
98
|
"@npmcli/package-json": "^8.0.1",
|
|
98
99
|
"@pnpm/deps.path": "^1101.0.11",
|
|
@@ -101,13 +102,13 @@
|
|
|
101
102
|
"@pnpm/workspace.projects-reader": "^1101.1.9",
|
|
102
103
|
"@pnpm/workspace.workspace-manifest-reader": "^1100.3.4",
|
|
103
104
|
"@pnpm/workspace.workspace-manifest-writer": "^1100.2.13",
|
|
104
|
-
"@r_masseater/fu4": "^0.3.
|
|
105
|
+
"@r_masseater/fu4": "^0.3.4",
|
|
105
106
|
"@r_masseater/kestrion": "^0.1.0",
|
|
106
107
|
"@r_masseater/oxlint-plugin-decision": "^0.8.3",
|
|
107
|
-
"@r_masseater/oxlint-typed-rules": "^0.6.
|
|
108
|
+
"@r_masseater/oxlint-typed-rules": "^0.6.3",
|
|
108
109
|
"@r_masseater/textlint-rule-preset-ja": "^0.3.2",
|
|
109
|
-
"@r_masseater/wism": "^0.4.
|
|
110
|
-
"@r_masseater/y8": "^0.7.
|
|
110
|
+
"@r_masseater/wism": "^0.4.5",
|
|
111
|
+
"@r_masseater/y8": "^0.7.2",
|
|
111
112
|
"@shadcn/lint": "^0.2.5",
|
|
112
113
|
"@tanstack/intent": "^0.5.6",
|
|
113
114
|
"@textlint-ja/textlint-rule-preset-ai-writing": "^1.7.2",
|
|
@@ -129,17 +130,17 @@
|
|
|
129
130
|
},
|
|
130
131
|
"devDependencies": {
|
|
131
132
|
"@effect/tsgo": "0.73.7",
|
|
132
|
-
"@effect/vitest": "4.1.
|
|
133
|
+
"@effect/vitest": "4.1.6",
|
|
133
134
|
"@masseater.dev/lint-host": "0.0.0",
|
|
134
135
|
"@masseater.dev/path-kit": "0.0.0",
|
|
135
136
|
"@r_masseater/github-workflow": "0.1.1",
|
|
136
|
-
"@r_masseater/h56m": "0.3.
|
|
137
|
+
"@r_masseater/h56m": "0.3.6",
|
|
137
138
|
"@r_masseater/node-main": "0.2.1",
|
|
138
|
-
"@r_masseater/vite-plus-adopt": "0.
|
|
139
|
+
"@r_masseater/vite-plus-adopt": "0.21.0",
|
|
139
140
|
"@r_masseater/vitest-otlp": "0.2.2",
|
|
140
141
|
"@types/node": "26.6.11",
|
|
141
142
|
"@types/semver": "7.8.0",
|
|
142
|
-
"effect": "4.1.
|
|
143
|
+
"effect": "4.1.6",
|
|
143
144
|
"oxlint": "1.95.0",
|
|
144
145
|
"tsrs": "7.1.0-beta.tsrs5",
|
|
145
146
|
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
|
|
@@ -12,6 +12,7 @@ sources:
|
|
|
12
12
|
- src/app/**
|
|
13
13
|
- bin/msch-exits.ts
|
|
14
14
|
- bin/msch-unbumped.ts
|
|
15
|
+
- bin/msch-upstream.ts
|
|
15
16
|
---
|
|
16
17
|
|
|
17
18
|
# msch-checks
|
|
@@ -38,6 +39,22 @@ Run `vp exec msch-exits` at the repository root to look the conditions up on npm
|
|
|
38
39
|
|
|
39
40
|
For a met condition, remove the entry and its patch file and run verify. If verify still needs the deviation, keep it and replace the condition with the next event that could end it.
|
|
40
41
|
|
|
42
|
+
## Upstream of a reimplementation
|
|
43
|
+
|
|
44
|
+
A workspace that reimplements something records what it follows in the `upstream` field of its `package.json`, keyed by `npm:<package>`, `crate:<crate>` or `github:<owner>/<repo>`:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
"upstream": {
|
|
48
|
+
"github:rhysd/actionlint": { "reviewed": "1.7.12", "verdict": "adopted", "reason": "The conformance fixtures were recorded from it." }
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`reviewed` is the last upstream version whose changes were decided on, written without a `v`. `verdict` is `adopted` when the workspace now follows that version, `skipped` when the changes were read and nothing was taken, and `changed` when the way the workspace follows the upstream changed. `reason` says why. msch reports a record it cannot read as `upstream-record`.
|
|
53
|
+
|
|
54
|
+
Run `vp exec msch-upstream` at the repository root to look up the releases after `reviewed`. It exits with 1 when an upstream released since or could not be checked, and `--json` prints the results as JSON. The root `daily` task runs it, with the same token handling as `msch-refs`. Prereleases count only when `reviewed` is one.
|
|
55
|
+
|
|
56
|
+
To clear a report, read the upstream changes, decide, and write the version you decided on, the verdict and the reason into the record.
|
|
57
|
+
|
|
41
58
|
## Reference links
|
|
42
59
|
|
|
43
60
|
A Markdown link whose destination is `github:<owner>/<repo>[/<path>][#<symbol>]` or `npm:<package>[@<version>]` points at a source. The version is an exact version or a dist-tag, not a range. The `docs/source-reference` rule of the y8 markdown check reports a destination in a form that cannot be looked up. A link to a path of a branch on github.com (`https://github.com/<owner>/<repo>/blob/<branch>/<path>`) is checked as the same kind of pointer, so a README can keep a link that readers can click.
|
|
@@ -86,6 +86,27 @@ They also apply `decisionTestRules` to `*.test.ts`.
|
|
|
86
86
|
| `decisionRules` | Each check costs a request, so the preset leaves them off. Name them only where needed |
|
|
87
87
|
| `tracedRules` | Worker code that records spans with @r_masseater/workers-tracing |
|
|
88
88
|
| `remotionRules` | Workspaces that build videos with Remotion |
|
|
89
|
+
| `videoRules` | Video scripts: the words of each line and the rules of each series, given as options |
|
|
90
|
+
|
|
91
|
+
## Video script rules
|
|
92
|
+
|
|
93
|
+
`videoRules({ say, series, banned })` returns the rule set for video scripts.
|
|
94
|
+
A script is an object literal with `cuts`, whose cuts have `say` arrays.
|
|
95
|
+
|
|
96
|
+
`msch-lint/video-say` checks each `say` string.
|
|
97
|
+
It removes a space between Japanese and Latin letters or digits, and replaces each `say.terms` word outside `{漢字|よみ}` ruby.
|
|
98
|
+
It reports each `say.banned` word with its reason, and more than `say.maxEmphasis` `**` runs in one line.
|
|
99
|
+
|
|
100
|
+
`msch-lint/video-readings` reports a Latin word in a line that no key of the script's `readings` covers.
|
|
101
|
+
|
|
102
|
+
`msch-lint/video-series` reads the script's `series` string and applies the options of that series.
|
|
103
|
+
It sets each `values` entry to the given source text and removes every property named in `banned`.
|
|
104
|
+
It checks every cut's `voice` against `voices`, and the first and last speaker against `opener` and `closer`.
|
|
105
|
+
With `intro: "beats"`, the `intro` cut needs `at` and `|` parts. With `intro: "plain"`, both are removed.
|
|
106
|
+
|
|
107
|
+
`afterIntro` gives the source text that each property of the cut after the `intro` cut must have. Use it for a fixed start time. A missing or different value is fixed.
|
|
108
|
+
|
|
109
|
+
Run `vp lint --fix` to apply the fixes.
|
|
89
110
|
|
|
90
111
|
## Common mistakes
|
|
91
112
|
|
package/dist/config-CvPuqi4L.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-CvPuqi4L.mjs","names":[],"sources":["../src/shared/config/index.ts"],"sourcesContent":["export const JAPANESE = /[\\p{Script=Hiragana}\\p{Script=Katakana}\\p{Script=Han}]/u;\n"],"mappings":";AAAA,MAAa,WAAW"}
|