@milkenjoyer/toolchain 0.0.0-stage → 0.6.5
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 +36 -2
- package/dist/array-method-C_XYdjLZ.mjs +178 -0
- package/dist/compatible.d.mts +91 -0
- package/dist/compatible.mjs +160 -0
- package/dist/effect-plugin-DARbVmA3.mjs +3493 -0
- package/dist/effect-plugin.d.mts +3967 -0
- package/dist/effect-plugin.mjs +1 -0
- package/dist/effect-tsgo.d.mts +10 -0
- package/dist/effect-tsgo.mjs +16 -0
- package/dist/exceptions.d.mts +6 -0
- package/dist/exceptions.mjs +16 -0
- package/dist/fmt.d.mts +5 -0
- package/dist/fmt.mjs +8 -0
- package/dist/foldkit.d.mts +3 -0
- package/dist/foldkit.mjs +17 -0
- package/dist/guard.d.mts +32 -0
- package/dist/guard.mjs +131 -0
- package/dist/hooks.d.mts +16 -0
- package/dist/hooks.mjs +137 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +3 -0
- package/dist/knip.d.mts +7 -0
- package/dist/knip.mjs +15 -0
- package/dist/lint.d.mts +9 -0
- package/dist/lint.mjs +113 -0
- package/dist/plugin-CBUJ7Tgd.mjs +927 -0
- package/dist/plugin.d.mts +19 -0
- package/dist/plugin.mjs +1 -0
- package/dist/rikalabs-hPKWFZ1P.mjs +362 -0
- package/dist/rikalabs.d.mts +80 -0
- package/dist/rikalabs.mjs +1 -0
- package/dist/rules.d.mts +246 -0
- package/dist/rules.mjs +234 -0
- package/dist/versions.d.mts +46 -0
- package/dist/versions.mjs +148 -0
- package/licenses/anti-slop.txt +21 -0
- package/licenses/oxlint-plugin-effect.txt +21 -0
- package/node-version +1 -0
- package/package.json +114 -4
- package/renovate.json +78 -0
- package/tsconfig.base.json +34 -0
- package/vscode/extensions.json +3 -0
- package/vscode/settings.json +6 -0
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Shared lint boundaries
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared lint rules resolve imported Effect and runtime bindings through unchanged `const` identifier and member aliases. Mutable aliases, destructuring aliases and arbitrary wrapper return values do not establish runtime identity. A runtime boundary permits provision only as the direct first argument of genuine BunRuntime or NodeRuntime `runMain`, or as a direct operator in that argument's `.pipe`.
|
|
4
|
+
|
|
5
|
+
Raw Promise detection follows global `Promise`, `globalThis.Promise`, unchanged `const` and `let` Promise bindings, native Promise factories including `Promise.try`, global `fetch` calls and their unchanged `const` aliases, chains, `Promise<T>` bindings, and calls to local async or explicitly Promise-returning functions. It does not infer arbitrary library return types or object methods. Construction and each chain invocation report separately; a factory call alone does not report.
|
|
6
|
+
|
|
7
|
+
A runtime value import from exactly `vite-plus/test/browser` or `vitest/browser` establishes a browser execution target for Foldkit's server-global rule. Type imports, filenames, DOM compiler libraries, providers and configuration imports do not establish that target. Other Foldkit rules retain their upstream behavior.
|
|
8
|
+
|
|
9
|
+
# Configure pre-push hooks
|
|
10
|
+
|
|
11
|
+
A shared absolute Git hooks path must dispatch through the invoking worktree. `@milkenjoyer/toolchain/hooks` supplies `configurePrePush` to run native Vite+ setup and install that dispatcher as one operation.
|
|
12
|
+
|
|
13
|
+
Create the composition entrypoint `scripts/composition/configure-hooks.ts` and replace the existing `vp config` prepare step with `bun scripts/composition/configure-hooks.ts`. Keep the other prepare steps in their current order.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
17
|
+
import { configurePrePush } from "@milkenjoyer/toolchain/hooks";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
|
|
20
|
+
if (import.meta.main) {
|
|
21
|
+
NodeRuntime.runMain(
|
|
22
|
+
configurePrePush({ cwd: process.cwd(), agent: true }).pipe(
|
|
23
|
+
Effect.provide(NodeServices.layer)
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Call `NodeRuntime.runMain` directly inside the entrypoint guard. For VibeBattler, the prepare command is `effect-tsgo patch --oxlint && bun scripts/composition/configure-hooks.ts && vp run @vibebattler/plugin#build`.
|
|
30
|
+
|
|
31
|
+
Use `agent: false` where the old command used `--no-agent`. The product moves its package pin to the released toolchain version. It imports the shared implementation rather than copying it.
|
|
32
|
+
|
|
33
|
+
The program runs the local `vp config --hooks`, retains an absolute shared hooks path, replaces only the generated `.vite-hooks/_/pre-push`, and verifies the active Git dispatcher before returning success. Native `h`, other hook stubs and the tracked `.vite-hooks/pre-push` checks retain their behavior. The dispatcher requires the invoking worktree's executable `node_modules/.bin/vp` and tracked `.vite-hooks/pre-push`. It preserves stdin, arguments, cwd and the check's exit status.
|
|
34
|
+
|
|
35
|
+
Use this same prepare entrypoint for regeneration. A bare native `vp config` or `vp hooks enable` restores the upstream stub. The supported setup entrypoint regenerates and reinstalls the corrected stub together. A worktree whose shared active dispatcher belongs to another checkout cannot silently repair that checkout. Setup must reject a stale shared dispatcher until the parent updates the primary through the reviewed deployment.
|
|
36
|
+
|
|
37
|
+
Before deployment, save the active generated stub's bytes and executable mode. Compare the replacement with the released `worktreePrePush` export. Rollback restores those saved bytes and mode. The old stub reintroduces the diagnosed executable/config mismatch, so keep affected worktree pushes held after rollback.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
2
|
+
import { dual } from "effect/Function";
|
|
3
|
+
import * as HashSet from "effect/HashSet";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Str from "effect/String";
|
|
7
|
+
// src/shared/scope.ts
|
|
8
|
+
const resolveBinding = dual(2, (sourceCode, node) => {
|
|
9
|
+
if (node.type !== "Identifier") return Option.none();
|
|
10
|
+
const findBinding = (scope) => Option.flatMap(scope, (current) => Option.orElse(Option.fromUndefinedOr(current.set.get(node.name)), () => findBinding(Option.fromNullishOr(current.upper))));
|
|
11
|
+
return findBinding(Option.fromNullishOr(sourceCode.getScope(node)));
|
|
12
|
+
});
|
|
13
|
+
const importBinding = dual(3, (sourceCode, declaration, local) => {
|
|
14
|
+
const declared = sourceCode.getDeclaredVariables(declaration);
|
|
15
|
+
return Option.orElse(Arr.findFirst(declared, (variable) => Arr.some(variable.identifiers, (identifier) => identifier.start === local.start)), () => resolveBinding(sourceCode, local));
|
|
16
|
+
});
|
|
17
|
+
// src/shared/tagged-values.ts
|
|
18
|
+
const MATCH_METHODS = HashSet.fromIterable(["not", "when"]);
|
|
19
|
+
const DATA_TAG_EXPORTS = HashSet.fromIterable([
|
|
20
|
+
"TaggedClass",
|
|
21
|
+
"TaggedError",
|
|
22
|
+
"taggedEnum"
|
|
23
|
+
]);
|
|
24
|
+
const SCHEMA_TAG_EXPORTS = HashSet.fromIterable([
|
|
25
|
+
"TaggedClass",
|
|
26
|
+
"TaggedError",
|
|
27
|
+
"TaggedStruct",
|
|
28
|
+
"TaggedUnion",
|
|
29
|
+
"tag"
|
|
30
|
+
]);
|
|
31
|
+
const moduleForSource = (source) => {
|
|
32
|
+
const normalized = Str.replace(/\/$/u, "")(Str.replace(/\.(?:c|m)?[jt]sx?$/u, "")(source));
|
|
33
|
+
if (normalized === "effect") return Option.some("root");
|
|
34
|
+
if (normalized === "effect/Data") return Option.some("Data");
|
|
35
|
+
if (normalized === "effect/Effect") return Option.some("Effect");
|
|
36
|
+
if (normalized === "effect/Match") return Option.some("Match");
|
|
37
|
+
if (normalized === "effect/Schema") return Option.some("Schema");
|
|
38
|
+
if (Str.startsWith("effect/")(normalized)) return Option.some("other");
|
|
39
|
+
return Option.none();
|
|
40
|
+
};
|
|
41
|
+
const bindingsWhere = (imports, keep) => Arr.flatMap(imports, (entry) => keep(entry) ? [entry.binding] : []);
|
|
42
|
+
const named = (entry, module, names) => entry.module === module && Option.exists(entry.imported, names);
|
|
43
|
+
const namespacesOf = (imports, module) => bindingsWhere(imports, (entry) => entry.module === module && Option.isNone(entry.imported) || named(entry, "root", (name) => name === module));
|
|
44
|
+
const importInfo = (imports) => {
|
|
45
|
+
const dataNamespaces = namespacesOf(imports, "Data");
|
|
46
|
+
const schemaNamespaces = namespacesOf(imports, "Schema");
|
|
47
|
+
const tagConstructors = bindingsWhere(imports, (entry) => named(entry, "Data", (name) => HashSet.has(DATA_TAG_EXPORTS, name)) || named(entry, "Schema", (name) => HashSet.has(SCHEMA_TAG_EXPORTS, name)));
|
|
48
|
+
return {
|
|
49
|
+
rootNamespaces: bindingsWhere(imports, (entry) => entry.module === "root" && Option.isNone(entry.imported)),
|
|
50
|
+
effectNamespaces: namespacesOf(imports, "Effect"),
|
|
51
|
+
effectFunctions: Arr.flatMap(imports, (entry) => entry.module === "Effect" && Option.isSome(entry.imported) ? [[entry.binding, entry.imported.value]] : []),
|
|
52
|
+
matchNamespaces: namespacesOf(imports, "Match"),
|
|
53
|
+
matchFunctions: bindingsWhere(imports, (entry) => named(entry, "Match", (name) => HashSet.has(MATCH_METHODS, name))),
|
|
54
|
+
dataNamespaces,
|
|
55
|
+
schemaNamespaces,
|
|
56
|
+
tagConstructors,
|
|
57
|
+
hasTagApi: Arr.isReadonlyArrayNonEmpty(dataNamespaces) || Arr.isReadonlyArrayNonEmpty(schemaNamespaces) || Arr.isReadonlyArrayNonEmpty(tagConstructors)
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const collectEffectImports = (sourceCode) => importInfo(Arr.flatMap(sourceCode.ast.body, (statement) => {
|
|
61
|
+
if (statement.type !== "ImportDeclaration" || statement.importKind === "type") return [];
|
|
62
|
+
const module = moduleForSource(statement.source.value);
|
|
63
|
+
if (Option.isNone(module)) return [];
|
|
64
|
+
return Arr.flatMap(statement.specifiers, (specifier) => {
|
|
65
|
+
const binding = importBinding(sourceCode, statement, specifier.local);
|
|
66
|
+
if (Option.isNone(binding) || specifier.type === "ImportDefaultSpecifier" || specifier.type === "ImportSpecifier" && /^\s*type\b/u.test(sourceCode.getText(specifier))) return [];
|
|
67
|
+
return [{
|
|
68
|
+
module: module.value,
|
|
69
|
+
imported: specifier.type === "ImportSpecifier" ? Option.some(specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) : Option.none(),
|
|
70
|
+
binding: binding.value
|
|
71
|
+
}];
|
|
72
|
+
});
|
|
73
|
+
}));
|
|
74
|
+
const isStringLiteral = (node) => node.type === "Literal" && Schema.is(Schema.String)(node.value);
|
|
75
|
+
const memberPropertyName = (node) => {
|
|
76
|
+
if (!node.computed && node.property.type === "Identifier") return Option.some(node.property.name);
|
|
77
|
+
return node.computed && isStringLiteral(node.property) ? Option.some(node.property.value) : Option.none();
|
|
78
|
+
};
|
|
79
|
+
const memberPath = (node) => {
|
|
80
|
+
const property = memberPropertyName(node);
|
|
81
|
+
if (Option.isNone(property)) return Option.none();
|
|
82
|
+
if (node.object.type === "MemberExpression") {
|
|
83
|
+
const parentPath = memberPath(node.object);
|
|
84
|
+
return Option.map(parentPath, (path) => [...path, property.value]);
|
|
85
|
+
}
|
|
86
|
+
return node.object.type === "Identifier" ? Option.some([node.object.name, property.value]) : Option.none();
|
|
87
|
+
};
|
|
88
|
+
const memberRoot = (node) => {
|
|
89
|
+
if (node.type === "MemberExpression") return memberRoot(node.object);
|
|
90
|
+
return node.type === "Identifier" ? Option.some(node) : Option.none();
|
|
91
|
+
};
|
|
92
|
+
const hasBinding = (bindings, node, sourceCode) => {
|
|
93
|
+
const binding = resolveBinding(sourceCode, node);
|
|
94
|
+
return Option.isSome(binding) && bindings.includes(binding.value);
|
|
95
|
+
};
|
|
96
|
+
const effectReferenceName = dual(3, (node, imports, sourceCode) => {
|
|
97
|
+
if (node.type === "Identifier") return Option.flatMap(resolveBinding(sourceCode, node), (binding) => Arr.some(binding.references, (reference) => reference.identifier.start === node.start) ? Option.map(Arr.findFirst(imports.effectFunctions, ([variable]) => variable === binding), ([, name]) => name) : Option.none());
|
|
98
|
+
if (node.type !== "MemberExpression") return Option.none();
|
|
99
|
+
const path = memberPath(node);
|
|
100
|
+
const root = memberRoot(node);
|
|
101
|
+
if (Option.isNone(path) || Option.isNone(root)) return Option.none();
|
|
102
|
+
if (path.value.length === 2 && hasBinding(imports.effectNamespaces, root.value, sourceCode) || path.value.length === 3 && path.value[1] === "Effect" && hasBinding(imports.rootNamespaces, root.value, sourceCode)) return memberPropertyName(node);
|
|
103
|
+
return Option.none();
|
|
104
|
+
});
|
|
105
|
+
const propertyName = (property) => {
|
|
106
|
+
if (!property.computed && property.key.type === "Identifier") return Option.some(property.key.name);
|
|
107
|
+
return isStringLiteral(property.key) ? Option.some(property.key.value) : Option.none();
|
|
108
|
+
};
|
|
109
|
+
const isMatchPatternObject = dual(3, (node, imports, sourceCode) => {
|
|
110
|
+
const call = node.parent;
|
|
111
|
+
if (call.type !== "CallExpression" || !call.arguments.includes(node)) return false;
|
|
112
|
+
if (call.callee.type === "Identifier") return hasBinding(imports.matchFunctions, call.callee, sourceCode);
|
|
113
|
+
if (call.callee.type !== "MemberExpression") return false;
|
|
114
|
+
const path = memberPath(call.callee);
|
|
115
|
+
const root = memberRoot(call.callee);
|
|
116
|
+
if (Option.isNone(path) || Option.isNone(root)) return false;
|
|
117
|
+
if (path.value.length === 2) return hasBinding(imports.matchNamespaces, root.value, sourceCode);
|
|
118
|
+
return path.value.length === 3 && path.value[1] === "Match" && hasBinding(imports.rootNamespaces, root.value, sourceCode);
|
|
119
|
+
});
|
|
120
|
+
// src/shared/array-method.ts
|
|
121
|
+
const ARRAY_RETURNING_METHODS = HashSet.fromIterable([
|
|
122
|
+
"concat",
|
|
123
|
+
"filter",
|
|
124
|
+
"flatMap",
|
|
125
|
+
"map",
|
|
126
|
+
"slice",
|
|
127
|
+
"toReversed",
|
|
128
|
+
"toSorted",
|
|
129
|
+
"toSpliced"
|
|
130
|
+
]);
|
|
131
|
+
const unwrapExpression = (node) => {
|
|
132
|
+
if (node.type === "ParenthesizedExpression" || node.type === "ChainExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression") return unwrapExpression(node.expression);
|
|
133
|
+
return node;
|
|
134
|
+
};
|
|
135
|
+
const arrayMethodTarget = (node) => {
|
|
136
|
+
const current = unwrapExpression(node);
|
|
137
|
+
if (current.type !== "MemberExpression") return Option.none();
|
|
138
|
+
const { property } = current;
|
|
139
|
+
if (!current.computed && property.type === "Identifier") return Option.some({
|
|
140
|
+
name: property.name,
|
|
141
|
+
object: current.object
|
|
142
|
+
});
|
|
143
|
+
if (current.computed && property.type === "Literal" && Schema.is(Schema.String)(property.value)) return Option.some({
|
|
144
|
+
name: property.value,
|
|
145
|
+
object: current.object
|
|
146
|
+
});
|
|
147
|
+
return Option.none();
|
|
148
|
+
};
|
|
149
|
+
const isArrayAnnotation = (type) => {
|
|
150
|
+
if (type.type === "TSArrayType" || type.type === "TSTupleType") return true;
|
|
151
|
+
if (type.type === "TSParenthesizedType") return isArrayAnnotation(type.typeAnnotation);
|
|
152
|
+
if (type.type === "TSTypeOperator" && type.operator === "readonly") return isArrayAnnotation(type.typeAnnotation);
|
|
153
|
+
return type.type === "TSTypeReference" && type.typeName.type === "Identifier" && (type.typeName.name === "Array" || type.typeName.name === "ReadonlyArray");
|
|
154
|
+
};
|
|
155
|
+
const isKnownArrayExpression = dual((args) => "getScope" in args[0], (sourceCode, node, visited = []) => {
|
|
156
|
+
const current = unwrapExpression(node);
|
|
157
|
+
if (current.type === "ArrayExpression") return true;
|
|
158
|
+
if (current.type === "CallExpression") {
|
|
159
|
+
const method = arrayMethodTarget(current.callee);
|
|
160
|
+
return Option.isSome(method) && HashSet.has(ARRAY_RETURNING_METHODS, method.value.name) && isKnownArrayExpression(sourceCode, method.value.object, visited);
|
|
161
|
+
}
|
|
162
|
+
if (current.type !== "Identifier") return false;
|
|
163
|
+
const binding = resolveBinding(sourceCode, current);
|
|
164
|
+
if (Option.isNone(binding) || visited.includes(binding.value)) return false;
|
|
165
|
+
const variable = binding.value;
|
|
166
|
+
const nextVisited = [...visited, variable];
|
|
167
|
+
if (Arr.some(variable.references, (reference) => reference.isWrite() && !reference.init)) return false;
|
|
168
|
+
const annotation = Arr.findFirst(variable.identifiers, (identifier) => Option.fromUndefinedOr(identifier.typeAnnotation?.typeAnnotation));
|
|
169
|
+
if (Option.isSome(annotation)) return isArrayAnnotation(annotation.value);
|
|
170
|
+
return Option.getOrElse(Arr.findFirst(variable.defs, (definition) => {
|
|
171
|
+
if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier" && definition.node.init !== null && definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") {
|
|
172
|
+
const initial = definition.node.init;
|
|
173
|
+
return Option.some(isKnownArrayExpression(sourceCode, initial, nextVisited));
|
|
174
|
+
}
|
|
175
|
+
return Option.none();
|
|
176
|
+
}), () => false);
|
|
177
|
+
});
|
|
178
|
+
export { effectReferenceName as a, memberPropertyName as c, collectEffectImports as i, propertyName as l, isKnownArrayExpression as n, isMatchPatternObject as o, unwrapExpression as r, isStringLiteral as s, arrayMethodTarget as t, resolveBinding as u };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Catalog, Family } from "./versions.mjs";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
export declare const VersionManifest: Schema.Struct<{
|
|
6
|
+
readonly dependencies: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
7
|
+
readonly peerDependencies: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
8
|
+
readonly bundledVersions: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
9
|
+
}>;
|
|
10
|
+
export type VersionManifest = typeof VersionManifest.Type;
|
|
11
|
+
export declare const Packument: Schema.Struct<{
|
|
12
|
+
readonly "dist-tags": Schema.$Record<Schema.String, Schema.String>;
|
|
13
|
+
readonly versions: Schema.$Record<Schema.String, Schema.Struct<{
|
|
14
|
+
readonly dependencies: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
15
|
+
readonly peerDependencies: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
16
|
+
readonly bundledVersions: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
17
|
+
}>>;
|
|
18
|
+
}>;
|
|
19
|
+
export type Packument = typeof Packument.Type;
|
|
20
|
+
export declare const Packuments: Schema.$Record<Schema.String, Schema.Struct<{
|
|
21
|
+
readonly "dist-tags": Schema.$Record<Schema.String, Schema.String>;
|
|
22
|
+
readonly versions: Schema.$Record<Schema.String, Schema.Struct<{
|
|
23
|
+
readonly dependencies: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
24
|
+
readonly peerDependencies: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
25
|
+
readonly bundledVersions: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
26
|
+
}>>;
|
|
27
|
+
}>>;
|
|
28
|
+
export type Packuments = typeof Packuments.Type;
|
|
29
|
+
type UnmetFields = {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly version: string;
|
|
32
|
+
readonly needs: string;
|
|
33
|
+
readonly range: string;
|
|
34
|
+
readonly actual: string;
|
|
35
|
+
};
|
|
36
|
+
export type Conflict = Data.TaggedEnum<{
|
|
37
|
+
Unpublished: {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly version: string;
|
|
40
|
+
};
|
|
41
|
+
Unmet: UnmetFields;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const Conflict: Data.TaggedEnum.Constructor<{
|
|
44
|
+
readonly _tag: "Unmet";
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly version: string;
|
|
47
|
+
readonly needs: string;
|
|
48
|
+
readonly range: string;
|
|
49
|
+
readonly actual: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly _tag: "Unpublished";
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly version: string;
|
|
54
|
+
}>;
|
|
55
|
+
export type Solution = {
|
|
56
|
+
readonly resolved: boolean;
|
|
57
|
+
readonly catalog: Catalog;
|
|
58
|
+
readonly latest: Readonly<Record<string, string>>;
|
|
59
|
+
readonly blockers: Readonly<Record<string, string>>;
|
|
60
|
+
readonly conflicts: ReadonlyArray<Conflict>;
|
|
61
|
+
};
|
|
62
|
+
export declare const latestOf: {
|
|
63
|
+
(family: Family): (registry: Packuments) => Option.Option<string>;
|
|
64
|
+
(registry: Packuments, family: Family): Option.Option<string>;
|
|
65
|
+
};
|
|
66
|
+
export declare const otherTags: {
|
|
67
|
+
(family: Family): (registry: Packuments) => ReadonlyArray<readonly [string, string]>;
|
|
68
|
+
(registry: Packuments, family: Family): ReadonlyArray<readonly [string, string]>;
|
|
69
|
+
};
|
|
70
|
+
export declare const aliasTarget: (alias: string) => Option.Option<readonly [string, string]>;
|
|
71
|
+
export declare const fixedRange: {
|
|
72
|
+
(family: Family, name: string): (registry: Packuments) => Option.Option<string>;
|
|
73
|
+
(registry: Packuments, family: Family, name: string): Option.Option<string>;
|
|
74
|
+
};
|
|
75
|
+
export declare const conflicts: {
|
|
76
|
+
(registry: Packuments): (current: Catalog) => ReadonlyArray<Conflict>;
|
|
77
|
+
(current: Catalog, registry: Packuments): ReadonlyArray<Conflict>;
|
|
78
|
+
};
|
|
79
|
+
export declare const onLatestLine: {
|
|
80
|
+
(latest: string): (version: string) => boolean;
|
|
81
|
+
(version: string, latest: string): boolean;
|
|
82
|
+
};
|
|
83
|
+
export declare const describeConflict: {
|
|
84
|
+
(current: Catalog): (conflict: Conflict) => string;
|
|
85
|
+
(conflict: Conflict, current: Catalog): string;
|
|
86
|
+
};
|
|
87
|
+
export declare const solve: {
|
|
88
|
+
(start?: Catalog): (registry: Packuments) => Solution;
|
|
89
|
+
(registry: Packuments, start?: Catalog): Solution;
|
|
90
|
+
};
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { catalog, familyNamed, familyOf, fixedBy, fixedOf, lead, ownerOf, versionOf } from "./versions.mjs";
|
|
2
|
+
import * as Arr from "effect/Array";
|
|
3
|
+
import * as Data from "effect/Data";
|
|
4
|
+
import { dual } from "effect/Function";
|
|
5
|
+
import * as HashSet from "effect/HashSet";
|
|
6
|
+
import * as Match from "effect/Match";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
import * as R from "effect/Record";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Str from "effect/String";
|
|
11
|
+
import semver from "semver";
|
|
12
|
+
// src/compatible.ts
|
|
13
|
+
const Ranges = Schema.optionalKey(Schema.Record(Schema.String, Schema.String));
|
|
14
|
+
const VersionManifest = Schema.Struct({
|
|
15
|
+
dependencies: Ranges,
|
|
16
|
+
peerDependencies: Ranges,
|
|
17
|
+
bundledVersions: Ranges
|
|
18
|
+
});
|
|
19
|
+
const Packument = Schema.Struct({
|
|
20
|
+
"dist-tags": Schema.Record(Schema.String, Schema.String),
|
|
21
|
+
versions: Schema.Record(Schema.String, VersionManifest)
|
|
22
|
+
});
|
|
23
|
+
const Packuments = Schema.Record(Schema.String, Packument);
|
|
24
|
+
const Conflict = Data.taggedEnum();
|
|
25
|
+
const ALIAS = /^npm:(?<target>(?:@[^/@]+\/)?[^@]+)@(?<version>.+)$/u;
|
|
26
|
+
const manifestOf = (registry, name, version) => Option.flatMap(R.get(registry, name), (packument) => R.get(packument.versions, version));
|
|
27
|
+
const latestOf = dual(2, (registry, family) => Option.flatMap(R.get(registry, lead(family)), (packument) => R.get(packument["dist-tags"], "latest")));
|
|
28
|
+
const otherTags = dual(2, (registry, family) => Arr.flatMap(family.packages, (name) => Option.match(R.get(registry, name), {
|
|
29
|
+
onNone: () => [],
|
|
30
|
+
onSome: (packument) => Arr.filter(R.toEntries(packument["dist-tags"]), ([tag]) => tag !== "latest")
|
|
31
|
+
})));
|
|
32
|
+
const aliasTarget = (alias) => Option.flatMap(Option.fromNullishOr(ALIAS.exec(alias)?.groups), (groups) => Option.all([Option.fromNullishOr(groups.target), Option.fromNullishOr(groups.version)]));
|
|
33
|
+
const fixedRange = dual(3, (registry, family, name) => Option.flatMap(manifestOf(registry, lead(family), family.version), ({ dependencies = {} }) => R.get(dependencies, name)));
|
|
34
|
+
const anchored = (start, name) => Option.exists(ownerOf(name, start), (owner) => Arr.isReadonlyArrayNonEmpty(fixedBy(owner.name, start)));
|
|
35
|
+
const requirements = (start, name, manifest) => {
|
|
36
|
+
const { dependencies = {}, peerDependencies = {} } = manifest;
|
|
37
|
+
return [...anchored(start, name) ? R.toEntries(dependencies) : [], ...R.toEntries(peerDependencies)];
|
|
38
|
+
};
|
|
39
|
+
const holds = (registry, needs, actual, range) => Option.match(aliasTarget(actual), {
|
|
40
|
+
onNone: () => semver.validRange(range) !== null && semver.satisfies(actual, Str.replace(/^=/u, "")(range)),
|
|
41
|
+
onSome: ([target, version]) => range === actual || Option.exists(Option.flatMap(manifestOf(registry, target, version), ({ bundledVersions = {} }) => R.get(bundledVersions, needs)), (bundled) => semver.satisfies(bundled, range))
|
|
42
|
+
});
|
|
43
|
+
const conflictsForManifest = (registry, start, lookup, family, name, manifest) => Arr.flatMap(requirements(start, name, manifest), ([needs, range]) => Option.match(lookup(needs), {
|
|
44
|
+
onNone: () => [],
|
|
45
|
+
onSome: (actual) => holds(registry, needs, actual, range) ? [] : [Conflict.Unmet({
|
|
46
|
+
name,
|
|
47
|
+
version: family.version,
|
|
48
|
+
needs,
|
|
49
|
+
range,
|
|
50
|
+
actual
|
|
51
|
+
})]
|
|
52
|
+
}));
|
|
53
|
+
const memberConflicts = (registry, start, lookup, family, name) => Option.match(manifestOf(registry, name, family.version), {
|
|
54
|
+
onNone: () => R.has(registry, name) ? [Conflict.Unpublished({
|
|
55
|
+
name,
|
|
56
|
+
version: family.version
|
|
57
|
+
})] : [],
|
|
58
|
+
onSome: (manifest) => conflictsForManifest(registry, start, lookup, family, name, manifest)
|
|
59
|
+
});
|
|
60
|
+
const conflictsAmong = (registry, start, picked, lookup) => Arr.flatMap(picked, (family) => Arr.flatMap(family.packages, (name) => memberConflicts(registry, start, lookup, family, name)));
|
|
61
|
+
const conflicts = dual(2, (current, registry) => conflictsAmong(registry, current, current.families, (name) => versionOf(name, current)));
|
|
62
|
+
const fixedVersion = (registry, family, entry) => Option.match(fixedRange(registry, family, entry.name), {
|
|
63
|
+
onNone: () => entry,
|
|
64
|
+
onSome: (range) => ({
|
|
65
|
+
...entry,
|
|
66
|
+
version: Str.replace(/^=/u, "")(range)
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
const onLatestLine = dual(2, (version, latest) => semver.lte(version, latest) && (semver.prerelease(latest) !== null || semver.prerelease(version) === null));
|
|
70
|
+
const published = (registry, family) => Option.match(R.get(registry, lead(family)), {
|
|
71
|
+
onNone: () => [],
|
|
72
|
+
onSome: (packument) => R.keys(packument.versions)
|
|
73
|
+
});
|
|
74
|
+
const rises = (family, latest, tagged, version) => semver.valid(version) !== null && semver.gt(version, family.version) && onLatestLine(version, latest) && (version === latest || !HashSet.has(tagged, version));
|
|
75
|
+
const ladder = (registry, family) => {
|
|
76
|
+
const tagged = HashSet.fromIterable(Arr.map(otherTags(registry, family), ([, version]) => version));
|
|
77
|
+
const above = Option.match(latestOf(registry, family), {
|
|
78
|
+
onNone: () => [],
|
|
79
|
+
onSome: (latest) => Arr.filter(published(registry, family), (version) => rises(family, latest, tagged, version) && Arr.every(family.packages, (name) => !R.has(registry, name) || Option.isSome(manifestOf(registry, name, version))))
|
|
80
|
+
});
|
|
81
|
+
return [...Arr.sort(above, semver.rcompare), family.version];
|
|
82
|
+
};
|
|
83
|
+
const assemble = (registry, start, picked) => ({
|
|
84
|
+
families: picked,
|
|
85
|
+
fixed: Arr.flatMap(start.fixed, (entry) => Arr.fromOption(Option.map(familyNamed(entry.by, {
|
|
86
|
+
...start,
|
|
87
|
+
families: picked
|
|
88
|
+
}), (family) => fixedVersion(registry, family, entry))))
|
|
89
|
+
});
|
|
90
|
+
const pickedVersion = (registry, start, picked, name) => {
|
|
91
|
+
const owner = ownerOf(name, start);
|
|
92
|
+
if (Option.isNone(owner)) return Option.none();
|
|
93
|
+
const chosen = familyNamed(owner.value.name, {
|
|
94
|
+
...start,
|
|
95
|
+
families: picked
|
|
96
|
+
});
|
|
97
|
+
if (Option.isNone(chosen)) return Option.none();
|
|
98
|
+
if (Option.isSome(familyOf(name, start))) return Option.some(chosen.value.version);
|
|
99
|
+
return Option.map(fixedOf(name, start), (entry) => fixedVersion(registry, chosen.value, entry).version);
|
|
100
|
+
};
|
|
101
|
+
const search = (registry, start, rungs, picked) => Arr.matchLeft(rungs, {
|
|
102
|
+
onEmpty: () => Option.some(picked),
|
|
103
|
+
onNonEmpty: ([family, versions], rest) => Arr.findFirst(versions, (version) => {
|
|
104
|
+
const next = [...picked, {
|
|
105
|
+
...family,
|
|
106
|
+
version
|
|
107
|
+
}];
|
|
108
|
+
return Arr.isReadonlyArrayEmpty(conflictsAmong(registry, start, next, (name) => pickedVersion(registry, start, next, name))) ? search(registry, start, rest, next) : Option.none();
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
const describeConflict = dual(2, (conflict, current) => Match.value(conflict).pipe(Match.tag("Unpublished", ({ name, version }) => `${name} ${version} is not published`), Match.tag("Unmet", ({ name, version, needs, range, actual }) => {
|
|
112
|
+
return `${name} ${version} needs ${needs} ${range}, and the set has ${needs} ${actual}${Option.match(fixedOf(needs, current), {
|
|
113
|
+
onNone: () => "",
|
|
114
|
+
onSome: (entry) => `, which ${entry.by} fixes`
|
|
115
|
+
})}`;
|
|
116
|
+
}), Match.exhaustive));
|
|
117
|
+
const involves = (conflict, family, current) => family.packages.includes(conflict.name) || Match.value(conflict).pipe(Match.tag("Unmet", ({ needs }) => Option.exists(ownerOf(needs, current), (owner) => owner.name === family.name)), Match.orElse(() => false));
|
|
118
|
+
const familyBlocker = (registry, solved, family, latest) => {
|
|
119
|
+
const families = Arr.map(solved.families, (entry) => entry.name === family.name ? {
|
|
120
|
+
...entry,
|
|
121
|
+
version: latest
|
|
122
|
+
} : entry);
|
|
123
|
+
const trial = assemble(registry, solved, families);
|
|
124
|
+
const relevant = Arr.filter(conflicts(trial, registry), (conflict) => involves(conflict, family, trial));
|
|
125
|
+
return Arr.match(relevant, {
|
|
126
|
+
onEmpty: () => {
|
|
127
|
+
if (ladder(registry, family).includes(latest)) return `no compatible set includes ${family.name} ${latest}`;
|
|
128
|
+
return `${family.name} ${latest} is below the catalog or not published for every package in its family`;
|
|
129
|
+
},
|
|
130
|
+
onNonEmpty: ([first]) => describeConflict(first, trial)
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const blockersOf = (registry, solved, latest) => R.fromEntries(Arr.flatMap(solved.families, (family) => Option.match(R.get(latest, family.name), {
|
|
134
|
+
onNone: () => [],
|
|
135
|
+
onSome: (version) => version === family.version ? [] : [[family.name, familyBlocker(registry, solved, family, version)]]
|
|
136
|
+
})));
|
|
137
|
+
const solve = dual((args) => Schema.is(Packuments)(args[0]), (registry, start = catalog) => {
|
|
138
|
+
const latest = R.fromEntries(Arr.flatMap(start.families, (family) => Arr.fromOption(Option.map(latestOf(registry, family), (version) => [family.name, version]))));
|
|
139
|
+
const rungs = Arr.map(start.families, (family) => [family, ladder(registry, family)]);
|
|
140
|
+
return Option.match(search(registry, start, rungs, []), {
|
|
141
|
+
onNone: () => ({
|
|
142
|
+
resolved: false,
|
|
143
|
+
catalog: start,
|
|
144
|
+
latest,
|
|
145
|
+
blockers: {},
|
|
146
|
+
conflicts: conflicts(start, registry)
|
|
147
|
+
}),
|
|
148
|
+
onSome: (picked) => {
|
|
149
|
+
const solved = assemble(registry, start, picked);
|
|
150
|
+
return {
|
|
151
|
+
resolved: true,
|
|
152
|
+
catalog: solved,
|
|
153
|
+
latest,
|
|
154
|
+
blockers: blockersOf(registry, solved, latest),
|
|
155
|
+
conflicts: []
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
export { Conflict, Packument, Packuments, VersionManifest, aliasTarget, conflicts, describeConflict, fixedRange, latestOf, onLatestLine, otherTags, solve };
|