@milkenjoyer/toolchain 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -16
- package/dist/effect-plugin-BsrW5_nI.mjs +79 -0
- package/dist/effect-plugin.d.mts +2 -3966
- package/dist/effect-plugin.mjs +1 -1
- package/dist/fmt-BaECz64m.mjs +8 -0
- package/dist/fmt.mjs +1 -8
- package/dist/formal.mjs +1 -1
- package/dist/guard-Doqk4Fju.mjs +143 -0
- package/dist/guard.mjs +1 -96
- package/dist/{lint-IhmtnBbx.mjs → lint-CfztB4u8.mjs} +1 -1
- package/dist/lint.mjs +1 -1
- package/dist/standard.mjs +557 -4
- package/package.json +4 -9
- package/src/arithmetic.ts +60 -0
- package/src/compatible.ts +512 -0
- package/src/conformance.ts +56 -0
- package/src/effect-plugin.ts +24 -0
- package/src/effect-tsgo.ts +44 -0
- package/src/exceptions.ts +17 -0
- package/src/fmt.ts +13 -0
- package/src/foldkit-plugin.ts +51 -0
- package/src/formal/z3.ts +18 -1
- package/src/guard.ts +307 -0
- package/src/hooks.ts +205 -0
- package/src/index.ts +1 -0
- package/src/knip.ts +25 -0
- package/src/lint.ts +170 -0
- package/src/plugin.ts +21 -0
- package/src/rules/no-comments.ts +36 -0
- package/src/rules/no-process-env.ts +68 -0
- package/src/rules/prefer-accessible-scene-locators.ts +227 -0
- package/src/rules/require-command-answer-names.ts +144 -0
- package/src/rules/require-past-tense-messages.ts +201 -0
- package/src/rules/use-temp-file-scoped.ts +132 -0
- package/src/rules.ts +121 -0
- package/src/shared/foldkit-api.ts +51 -0
- package/src/shared/member-path.ts +106 -0
- package/src/shared/syntax.ts +47 -0
- package/src/standard/alchemy.ts +70 -0
- package/src/standard/checks.ts +10 -1
- package/src/standard/config.ts +84 -0
- package/src/standard/domain-rules.ts +204 -0
- package/src/standard/domain.ts +296 -0
- package/src/standard/infra.ts +486 -0
- package/src/versions.ts +221 -0
- package/dist/effect-plugin-BXUx9PPu.mjs +0 -3561
- package/dist/manifest-xQwgnYI1.mjs +0 -53
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
4
|
+
import * as R from "effect/Record";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import {
|
|
7
|
+
type Argument,
|
|
8
|
+
type ArrayExpressionElement,
|
|
9
|
+
type Expression,
|
|
10
|
+
type ModuleExportName,
|
|
11
|
+
parseSync,
|
|
12
|
+
Visitor,
|
|
13
|
+
} from "oxc-parser";
|
|
14
|
+
|
|
15
|
+
import { read, type Finding, type Rule } from "./repo.ts";
|
|
16
|
+
|
|
17
|
+
type Words = ReadonlyArray<Option.Option<string>>;
|
|
18
|
+
|
|
19
|
+
const COMMAND_WORD = /^[a-z][\w-]*$/u;
|
|
20
|
+
|
|
21
|
+
const commandPath = (words: Words): ReadonlyArray<string> =>
|
|
22
|
+
Arr.takeWhile(
|
|
23
|
+
words,
|
|
24
|
+
(word) => Option.isSome(word) && COMMAND_WORD.test(word.value)
|
|
25
|
+
).flatMap(Option.toArray);
|
|
26
|
+
|
|
27
|
+
const CF_READ_VERB = /^(?:get|list|query|search)$/u;
|
|
28
|
+
|
|
29
|
+
const CF_WRITE_VERB =
|
|
30
|
+
/^(?:ack|add|apply|bind|cancel|create|delete|deploy|disable|edit|enable|import|peek|publish|pull|purge|push|put|remove|rename|reset|retry|rm|rollback|rotate|send|set|start|stop|unbind|update|upload|write)$/u;
|
|
31
|
+
|
|
32
|
+
const cfReads = (words: Words): boolean => {
|
|
33
|
+
const path = commandPath(words);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
words.some(
|
|
37
|
+
(word, index) =>
|
|
38
|
+
Option.contains(word, "--dry-run") &&
|
|
39
|
+
!Option.contains(words[index + 1] ?? Option.none(), "=") &&
|
|
40
|
+
!Option.contains(words[index + 1] ?? Option.none(), "false")
|
|
41
|
+
) ||
|
|
42
|
+
Arr.head(path).pipe(Option.getOrUndefined) === "schema" ||
|
|
43
|
+
(Arr.some(path, (word) => CF_READ_VERB.test(word)) &&
|
|
44
|
+
!Arr.some(path, (word) => CF_WRITE_VERB.test(word)))
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const PROVIDER_CLIS = {
|
|
49
|
+
wrangler: (): boolean => false,
|
|
50
|
+
pscale: (words: Words): boolean =>
|
|
51
|
+
["sql", "auth", "org"].includes(
|
|
52
|
+
Arr.head(commandPath(words)).pipe(Option.getOrElse(() => ""))
|
|
53
|
+
),
|
|
54
|
+
cf: cfReads,
|
|
55
|
+
} satisfies Record<string, (words: Words) => boolean>;
|
|
56
|
+
|
|
57
|
+
type ProviderCli = keyof typeof PROVIDER_CLIS;
|
|
58
|
+
|
|
59
|
+
const reachOf = (cli: ProviderCli, words: Words): ReadonlyArray<string> => {
|
|
60
|
+
const path = commandPath(words);
|
|
61
|
+
|
|
62
|
+
return PROVIDER_CLIS[cli](words)
|
|
63
|
+
? []
|
|
64
|
+
: [
|
|
65
|
+
`${cli} ${Arr.match(path, {
|
|
66
|
+
onEmpty: () => "<unknown>",
|
|
67
|
+
onNonEmpty: (command) => command.join(" "),
|
|
68
|
+
})}`,
|
|
69
|
+
];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const CLOUDFLARE = "cloudflare";
|
|
73
|
+
|
|
74
|
+
const PROVIDERS = [CLOUDFLARE, "planetscale"];
|
|
75
|
+
|
|
76
|
+
const PROVIDER_HOST = new RegExp(
|
|
77
|
+
String.raw`\bapi\.(?:${PROVIDERS.join("|")})\.com\b`,
|
|
78
|
+
"u"
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const hexDigits = (code: number, width: number): string =>
|
|
82
|
+
code
|
|
83
|
+
.toString(16)
|
|
84
|
+
.padStart(width, "0")
|
|
85
|
+
.replaceAll(/[a-f]/gu, (digit) => `[${digit}${digit.toUpperCase()}]`);
|
|
86
|
+
|
|
87
|
+
const IDENTITY_ESCAPED = /^[^\dbfnrtuvx]$/u;
|
|
88
|
+
|
|
89
|
+
const LINE_CONTINUATIONS = String.raw`(?:\\(?:\r\n?|[\n\u2028\u2029]))*`;
|
|
90
|
+
|
|
91
|
+
const spelled = (word: string): string =>
|
|
92
|
+
Array.from(word, (char) => {
|
|
93
|
+
const code = char.codePointAt(0) ?? 0;
|
|
94
|
+
const plain = char === "." ? String.raw`\.` : char;
|
|
95
|
+
|
|
96
|
+
const escapes = [
|
|
97
|
+
`x${hexDigits(code, 2)}`,
|
|
98
|
+
`u${hexDigits(code, 4)}`,
|
|
99
|
+
String.raw`u\{0*${hexDigits(code, 1)}\}`,
|
|
100
|
+
`0*${code.toString(8)}`,
|
|
101
|
+
...(IDENTITY_ESCAPED.test(char) ? [plain] : []),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
return String.raw`${LINE_CONTINUATIONS}(?:${plain}|\\(?:${escapes.join("|")}))`;
|
|
105
|
+
}).join("");
|
|
106
|
+
|
|
107
|
+
const IDENTIFIER_PART = String.raw`[\p{ID_Continue}$\u200c\u200d]`;
|
|
108
|
+
|
|
109
|
+
const SHELL_WORD_CHAR = String.raw`[\w./@-]`;
|
|
110
|
+
|
|
111
|
+
const ESCAPE_END = String.raw`\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|[0-7]{1,3}|[^])`;
|
|
112
|
+
|
|
113
|
+
const SHELL_WORD_BEFORE = String.raw`(?:^|\/|(?!${SHELL_WORD_CHAR})[^]|${ESCAPE_END})`;
|
|
114
|
+
|
|
115
|
+
const SHELL_WORD_AFTER = String.raw`(?!${SHELL_WORD_CHAR})`;
|
|
116
|
+
|
|
117
|
+
const MEMBER_ACCESS_BEFORE = String.raw`(?:(?<!\.)\.|\d\.\.|[[\/\n\r\u2028\u2029])\s*`;
|
|
118
|
+
|
|
119
|
+
const MEMBER_ACCESS_AFTER = String.raw`(?!${IDENTIFIER_PART})(?=\s*\]?\s*(?:\??\.|[[\/]))`;
|
|
120
|
+
|
|
121
|
+
const spelledBetween = (before: string, word: string, after: string): string =>
|
|
122
|
+
String.raw`${spelled(word)}${after}(?<=${before}${spelled(word)})`;
|
|
123
|
+
|
|
124
|
+
const MAY_REACH = new RegExp(
|
|
125
|
+
[
|
|
126
|
+
...[
|
|
127
|
+
"@distilled.cloud/",
|
|
128
|
+
...PROVIDERS.map((provider) => `api.${provider}.com`),
|
|
129
|
+
].map(spelled),
|
|
130
|
+
...R.keys(PROVIDER_CLIS).map((cli) =>
|
|
131
|
+
spelledBetween(SHELL_WORD_BEFORE, cli, SHELL_WORD_AFTER)
|
|
132
|
+
),
|
|
133
|
+
`["']${spelled(CLOUDFLARE)}`,
|
|
134
|
+
spelledBetween(MEMBER_ACCESS_BEFORE, "rest", MEMBER_ACCESS_AFTER),
|
|
135
|
+
].join("|"),
|
|
136
|
+
"u"
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const MANAGEMENT_CLIENT = new RegExp(
|
|
140
|
+
String.raw`^(?:@distilled\.cloud\/[^/]+(?:\/(?!Credentials$|Errors$|Retry$)[^/]+)?|${CLOUDFLARE}(?:\/.*)?)$`,
|
|
141
|
+
"u"
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const RUNTIME_CLIENTS = new Set([
|
|
145
|
+
"@distilled.cloud/boat-dev",
|
|
146
|
+
"@distilled.cloud/stripe",
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
const RUNTIME_REST = new Map([
|
|
150
|
+
["git", new Set(["createBlob", "createTree", "createCommit", "createRef"])],
|
|
151
|
+
["repos", new Set(["createCommitStatus"])],
|
|
152
|
+
[
|
|
153
|
+
"issues",
|
|
154
|
+
new Set([
|
|
155
|
+
"addAssignees",
|
|
156
|
+
"addLabels",
|
|
157
|
+
"create",
|
|
158
|
+
"createComment",
|
|
159
|
+
"deleteComment",
|
|
160
|
+
"lock",
|
|
161
|
+
"removeAllLabels",
|
|
162
|
+
"removeAssignees",
|
|
163
|
+
"removeLabel",
|
|
164
|
+
"setLabels",
|
|
165
|
+
"unlock",
|
|
166
|
+
"update",
|
|
167
|
+
"updateComment",
|
|
168
|
+
]),
|
|
169
|
+
],
|
|
170
|
+
[
|
|
171
|
+
"pulls",
|
|
172
|
+
new Set([
|
|
173
|
+
"create",
|
|
174
|
+
"createReplyForReviewComment",
|
|
175
|
+
"createReview",
|
|
176
|
+
"createReviewComment",
|
|
177
|
+
"deletePendingReview",
|
|
178
|
+
"deleteReviewComment",
|
|
179
|
+
"dismissReview",
|
|
180
|
+
"merge",
|
|
181
|
+
"removeRequestedReviewers",
|
|
182
|
+
"requestReviewers",
|
|
183
|
+
"submitReview",
|
|
184
|
+
"update",
|
|
185
|
+
"updateBranch",
|
|
186
|
+
"updateReview",
|
|
187
|
+
"updateReviewComment",
|
|
188
|
+
]),
|
|
189
|
+
],
|
|
190
|
+
]);
|
|
191
|
+
|
|
192
|
+
const packageOf = (source: string): string =>
|
|
193
|
+
source.split("/").slice(0, 2).join("/");
|
|
194
|
+
|
|
195
|
+
const chainOf = (node: Expression): ReadonlyArray<string> | undefined => {
|
|
196
|
+
if (node.type === "Identifier") {
|
|
197
|
+
return [node.name];
|
|
198
|
+
}
|
|
199
|
+
if (node.type !== "MemberExpression" || node.computed) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
const head = chainOf(node.object);
|
|
203
|
+
return head === undefined ? undefined : [...head, node.property.name];
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const READ_METHOD = /^(?:get|list|query|compare)(?:[A-Z_]|$)/iu;
|
|
207
|
+
|
|
208
|
+
type Operand = NonNullable<
|
|
209
|
+
Argument | ArrayExpressionElement | ModuleExportName
|
|
210
|
+
>;
|
|
211
|
+
|
|
212
|
+
const textOf = (node: Option.Option<Operand>): Option.Option<string> => {
|
|
213
|
+
if (Option.isNone(node)) {
|
|
214
|
+
return Option.none();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const { value } = node;
|
|
218
|
+
|
|
219
|
+
if (value.type === "Literal") {
|
|
220
|
+
return Schema.is(Schema.String)(value.value)
|
|
221
|
+
? Option.some(value.value)
|
|
222
|
+
: Option.none();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return value.type === "TemplateLiteral"
|
|
226
|
+
? Option.some(value.quasis.map((quasi) => quasi.value.raw).join(" "))
|
|
227
|
+
: Option.none();
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const ProviderCli = Schema.Literals(R.keys(PROVIDER_CLIS));
|
|
231
|
+
|
|
232
|
+
const cliOf = (word: string): Option.Option<ProviderCli> => {
|
|
233
|
+
const name = word.slice(word.lastIndexOf("/") + 1);
|
|
234
|
+
|
|
235
|
+
return Schema.is(ProviderCli)(name) ? Option.some(name) : Option.none();
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const SHELL_TOKEN = new RegExp(
|
|
239
|
+
String.raw`[;&|\n\x60()]|["'$=]|${SHELL_WORD_CHAR}+`,
|
|
240
|
+
"gu"
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const SEPARATOR = /^[;&|\n`()]$/u;
|
|
244
|
+
|
|
245
|
+
const shellFindings = (text: string): ReadonlyArray<string> => {
|
|
246
|
+
const tokens = text.match(SHELL_TOKEN) ?? [];
|
|
247
|
+
|
|
248
|
+
return tokens.flatMap((token, index) => {
|
|
249
|
+
const cli = cliOf(token);
|
|
250
|
+
|
|
251
|
+
return Option.isNone(cli)
|
|
252
|
+
? []
|
|
253
|
+
: reachOf(
|
|
254
|
+
cli.value,
|
|
255
|
+
Arr.takeWhile(
|
|
256
|
+
tokens.slice(index + 1),
|
|
257
|
+
(word) => !SEPARATOR.test(word)
|
|
258
|
+
).map(Option.some)
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export const providerReaches = (
|
|
264
|
+
file: string,
|
|
265
|
+
source: string
|
|
266
|
+
): ReadonlyArray<string> => {
|
|
267
|
+
if (!MAY_REACH.test(source)) {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const found: Array<string> = [];
|
|
272
|
+
const clients = new Set<string>();
|
|
273
|
+
const instances = new Set<string>();
|
|
274
|
+
const commands = new Set<Operand>();
|
|
275
|
+
|
|
276
|
+
const invocation = (
|
|
277
|
+
operands: ReadonlyArray<Option.Option<Operand>>
|
|
278
|
+
): void => {
|
|
279
|
+
for (const [index, operand] of operands.entries()) {
|
|
280
|
+
const cli = cliOf(
|
|
281
|
+
Option.getOrElse(
|
|
282
|
+
Option.map(textOf(operand), (text) => text.trim()),
|
|
283
|
+
() => ""
|
|
284
|
+
)
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (Option.isSome(operand) && Option.isSome(cli)) {
|
|
288
|
+
const after = operands[index + 1] ?? Option.none();
|
|
289
|
+
|
|
290
|
+
const words = (
|
|
291
|
+
Option.isSome(after) && after.value.type === "ArrayExpression"
|
|
292
|
+
? after.value.elements.map(Option.fromNullishOr)
|
|
293
|
+
: operands.slice(index + 1)
|
|
294
|
+
).map(textOf);
|
|
295
|
+
|
|
296
|
+
commands.add(operand.value);
|
|
297
|
+
found.push(...reachOf(cli.value, words));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const literal = (node: Operand): void => {
|
|
303
|
+
const text = textOf(Option.some(node));
|
|
304
|
+
|
|
305
|
+
if (Option.isNone(text) || commands.has(node)) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (PROVIDER_HOST.test(text.value)) {
|
|
310
|
+
found.push(`host ${text.value}`);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
found.push(
|
|
314
|
+
...(Option.isNone(cliOf(text.value.trim()))
|
|
315
|
+
? shellFindings(text.value)
|
|
316
|
+
: [`${text.value.trim()} <unknown>`])
|
|
317
|
+
);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
new Visitor({
|
|
321
|
+
ImportDeclaration: (node): void => {
|
|
322
|
+
if (
|
|
323
|
+
node.importKind === "type" ||
|
|
324
|
+
!MANAGEMENT_CLIENT.test(node.source.value) ||
|
|
325
|
+
RUNTIME_CLIENTS.has(packageOf(node.source.value))
|
|
326
|
+
) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
for (const specifier of node.specifiers) {
|
|
331
|
+
if (specifier.type !== "ImportSpecifier") {
|
|
332
|
+
clients.add(specifier.local.name);
|
|
333
|
+
} else if (specifier.importKind !== "type") {
|
|
334
|
+
const imported =
|
|
335
|
+
specifier.imported.type === "Identifier"
|
|
336
|
+
? specifier.imported.name
|
|
337
|
+
: specifier.imported.value;
|
|
338
|
+
|
|
339
|
+
if (!READ_METHOD.test(imported)) {
|
|
340
|
+
found.push(`imports ${imported}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
VariableDeclarator: (node): void => {
|
|
346
|
+
const init =
|
|
347
|
+
node.init?.type === "AwaitExpression" ? node.init.argument : node.init;
|
|
348
|
+
const callee =
|
|
349
|
+
init?.type === "NewExpression" || init?.type === "CallExpression"
|
|
350
|
+
? init.callee
|
|
351
|
+
: undefined;
|
|
352
|
+
if (
|
|
353
|
+
node.id.type === "Identifier" &&
|
|
354
|
+
callee?.type === "Identifier" &&
|
|
355
|
+
clients.has(callee.name)
|
|
356
|
+
) {
|
|
357
|
+
instances.add(node.id.name);
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
CallExpression: (node): void => {
|
|
361
|
+
invocation(node.arguments.map(Option.some));
|
|
362
|
+
const chain = chainOf(node.callee);
|
|
363
|
+
const [root, ...path] = chain ?? [];
|
|
364
|
+
const method = path.at(-1);
|
|
365
|
+
if (
|
|
366
|
+
root !== undefined &&
|
|
367
|
+
method !== undefined &&
|
|
368
|
+
instances.has(root) &&
|
|
369
|
+
!READ_METHOD.test(method)
|
|
370
|
+
) {
|
|
371
|
+
found.push(`calls ${[root, ...path].join(".")}`);
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
NewExpression: (node): void => invocation(node.arguments.map(Option.some)),
|
|
375
|
+
ArrayExpression: (node): void =>
|
|
376
|
+
invocation(node.elements.map(Option.fromNullishOr)),
|
|
377
|
+
Literal: (node): void => literal(node),
|
|
378
|
+
TemplateLiteral: (node): void => literal(node),
|
|
379
|
+
MemberExpression: (node): void => {
|
|
380
|
+
if (node.computed || node.property.type !== "Identifier") {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const method = node.property.name;
|
|
385
|
+
const { object } = node;
|
|
386
|
+
|
|
387
|
+
const client =
|
|
388
|
+
object.type === "Identifier" && clients.has(object.name)
|
|
389
|
+
? object.name
|
|
390
|
+
: undefined;
|
|
391
|
+
|
|
392
|
+
const namespace =
|
|
393
|
+
object.type === "MemberExpression" &&
|
|
394
|
+
object.object.type === "MemberExpression" &&
|
|
395
|
+
object.object.property.type === "Identifier" &&
|
|
396
|
+
object.object.property.name === "rest"
|
|
397
|
+
? !object.computed && object.property.type === "Identifier"
|
|
398
|
+
? object.property.name
|
|
399
|
+
: "<computed>"
|
|
400
|
+
: undefined;
|
|
401
|
+
|
|
402
|
+
const target =
|
|
403
|
+
client ??
|
|
404
|
+
(namespace === undefined ||
|
|
405
|
+
namespace === "search" ||
|
|
406
|
+
RUNTIME_REST.get(namespace)?.has(method) === true
|
|
407
|
+
? undefined
|
|
408
|
+
: `rest.${namespace}`);
|
|
409
|
+
|
|
410
|
+
if (target !== undefined && !READ_METHOD.test(method)) {
|
|
411
|
+
found.push(`calls ${target}.${method}`);
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
}).visit(parseSync(file, source).program);
|
|
415
|
+
|
|
416
|
+
return found;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const PackageScripts = Schema.fromJsonString(
|
|
420
|
+
Schema.Struct({
|
|
421
|
+
scripts: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
422
|
+
})
|
|
423
|
+
);
|
|
424
|
+
const Workflow = Schema.Struct({
|
|
425
|
+
jobs: Schema.Record(
|
|
426
|
+
Schema.String,
|
|
427
|
+
Schema.Struct({
|
|
428
|
+
steps: Schema.optionalKey(
|
|
429
|
+
Schema.Array(
|
|
430
|
+
Schema.Struct({
|
|
431
|
+
run: Schema.optionalKey(Schema.String),
|
|
432
|
+
})
|
|
433
|
+
)
|
|
434
|
+
),
|
|
435
|
+
})
|
|
436
|
+
),
|
|
437
|
+
});
|
|
438
|
+
const SCRIPT = /\.[cm]?[jt]sx?$/u;
|
|
439
|
+
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/u;
|
|
440
|
+
|
|
441
|
+
export const infra: Rule = (repo) =>
|
|
442
|
+
Effect.gen(function* () {
|
|
443
|
+
const findings: Finding[] = [];
|
|
444
|
+
for (const file of repo.tracked) {
|
|
445
|
+
if (/(?:^|\/)wrangler\.(?:jsonc?|toml)$/u.test(file)) {
|
|
446
|
+
findings.push({
|
|
447
|
+
file,
|
|
448
|
+
message:
|
|
449
|
+
"provision infrastructure with native Alchemy resources instead of a Wrangler config",
|
|
450
|
+
});
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (
|
|
454
|
+
!SCRIPT.test(file) &&
|
|
455
|
+
!file.endsWith(".sh") &&
|
|
456
|
+
!/(?:^|\/)package\.json$/u.test(file) &&
|
|
457
|
+
!WORKFLOW.test(file)
|
|
458
|
+
)
|
|
459
|
+
continue;
|
|
460
|
+
const input = yield* read(repo, file, (text) => {
|
|
461
|
+
if (SCRIPT.test(file)) return providerReaches(file, text);
|
|
462
|
+
if (file.endsWith(".sh")) return shellFindings(text);
|
|
463
|
+
const scripts = WORKFLOW.test(file)
|
|
464
|
+
? Object.values(
|
|
465
|
+
Schema.decodeUnknownSync(Workflow)(Bun.YAML.parse(text)).jobs
|
|
466
|
+
).flatMap((job) =>
|
|
467
|
+
(job.steps ?? []).flatMap((step) =>
|
|
468
|
+
step.run === undefined ? [] : [step.run]
|
|
469
|
+
)
|
|
470
|
+
)
|
|
471
|
+
: Object.values(
|
|
472
|
+
Schema.decodeSync(PackageScripts)(text).scripts ?? {}
|
|
473
|
+
);
|
|
474
|
+
return scripts.flatMap(shellFindings);
|
|
475
|
+
});
|
|
476
|
+
findings.push(
|
|
477
|
+
...(input.ok
|
|
478
|
+
? input.value.map((reach) => ({
|
|
479
|
+
file,
|
|
480
|
+
message: `${reach}; provision infrastructure with native Alchemy resources`,
|
|
481
|
+
}))
|
|
482
|
+
: input.findings)
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
return findings;
|
|
486
|
+
});
|
package/src/versions.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
2
|
+
import { dual } from "effect/Function";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
4
|
+
import * as R from "effect/Record";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Str from "effect/String";
|
|
7
|
+
|
|
8
|
+
export type Family = {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly version: string;
|
|
11
|
+
readonly packages: ReadonlyArray<string>;
|
|
12
|
+
readonly scopes: ReadonlyArray<string>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type Fixed = {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly version: string;
|
|
18
|
+
readonly by: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const nodeVersion = "26.13.0";
|
|
22
|
+
|
|
23
|
+
export const families: ReadonlyArray<Family> = [
|
|
24
|
+
{
|
|
25
|
+
name: "vite-plus",
|
|
26
|
+
version: "1.5.0",
|
|
27
|
+
packages: ["vite-plus"],
|
|
28
|
+
scopes: [],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "alchemy",
|
|
32
|
+
version: "2.0.0-beta.85",
|
|
33
|
+
packages: [
|
|
34
|
+
"@alchemy.run/domain",
|
|
35
|
+
"alchemy",
|
|
36
|
+
"@alchemy.run/github",
|
|
37
|
+
"@alchemy.run/test",
|
|
38
|
+
],
|
|
39
|
+
scopes: ["@alchemy.run/"],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "foldkit",
|
|
43
|
+
version: "0.170.0",
|
|
44
|
+
packages: ["foldkit", "@foldkit/ui"],
|
|
45
|
+
scopes: [],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "@foldkit/vite-plugin",
|
|
49
|
+
version: "0.29.0",
|
|
50
|
+
packages: ["@foldkit/vite-plugin"],
|
|
51
|
+
scopes: [],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "@foldkit/devtools-mcp",
|
|
55
|
+
version: "0.26.0",
|
|
56
|
+
packages: ["@foldkit/devtools-mcp"],
|
|
57
|
+
scopes: [],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "@foldkit/oxlint-plugin",
|
|
61
|
+
version: "0.15.4",
|
|
62
|
+
packages: ["@foldkit/oxlint-plugin"],
|
|
63
|
+
scopes: [],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "effect",
|
|
67
|
+
version: "4.1.2",
|
|
68
|
+
packages: [
|
|
69
|
+
"effect",
|
|
70
|
+
"@effect/platform-browser",
|
|
71
|
+
"@effect/platform-bun",
|
|
72
|
+
"@effect/platform-node",
|
|
73
|
+
"@effect/platform-node-shared",
|
|
74
|
+
"@effect/vitest",
|
|
75
|
+
],
|
|
76
|
+
scopes: ["@effect/"],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "@effect/tsgo",
|
|
80
|
+
version: "0.67.3",
|
|
81
|
+
packages: ["@effect/tsgo"],
|
|
82
|
+
scopes: [],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "ultracite",
|
|
86
|
+
version: "8.1.1",
|
|
87
|
+
packages: ["ultracite"],
|
|
88
|
+
scopes: [],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "@mpsuesser/oxlint-plugin-effect",
|
|
92
|
+
version: "0.6.0",
|
|
93
|
+
packages: ["@mpsuesser/oxlint-plugin-effect"],
|
|
94
|
+
scopes: [],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "effect-oxlint",
|
|
98
|
+
version: "0.4.0",
|
|
99
|
+
packages: ["effect-oxlint"],
|
|
100
|
+
scopes: [],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "typescript",
|
|
104
|
+
version: "7.0.2",
|
|
105
|
+
packages: ["typescript"],
|
|
106
|
+
scopes: [],
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
export const fixed: ReadonlyArray<Fixed> = [
|
|
111
|
+
{ name: "oxlint", version: "1.91.0", by: "vite-plus" },
|
|
112
|
+
{ name: "@oxlint/plugins", version: "1.91.0", by: "vite-plus" },
|
|
113
|
+
{ name: "oxlint-tsgolint", version: "7.0.2005", by: "vite-plus" },
|
|
114
|
+
{ name: "oxfmt", version: "0.76.0", by: "vite-plus" },
|
|
115
|
+
{ name: "vitest", version: "5.1.0", by: "vite-plus" },
|
|
116
|
+
{
|
|
117
|
+
name: "vite",
|
|
118
|
+
version: "npm:@voidzero-dev/vite-plus-core@1.5.0",
|
|
119
|
+
by: "vite-plus",
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
export type Catalog = {
|
|
124
|
+
readonly families: ReadonlyArray<Family>;
|
|
125
|
+
readonly fixed: ReadonlyArray<Fixed>;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const catalog: Catalog = { families, fixed };
|
|
129
|
+
|
|
130
|
+
export const lead = (family: Family): string =>
|
|
131
|
+
family.packages[0] ?? family.name;
|
|
132
|
+
|
|
133
|
+
const inScope = (current: Catalog, family: Family, name: string): boolean =>
|
|
134
|
+
Arr.some(family.scopes, (scope) => Str.startsWith(scope)(name)) &&
|
|
135
|
+
Arr.every(
|
|
136
|
+
current.families,
|
|
137
|
+
(other) => other === family || !other.packages.includes(name)
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
export const familyOf: {
|
|
141
|
+
(current?: Catalog): (name: string) => Option.Option<Family>;
|
|
142
|
+
(name: string, current?: Catalog): Option.Option<Family>;
|
|
143
|
+
} = dual(
|
|
144
|
+
(args) => Schema.is(Schema.String)(args[0]),
|
|
145
|
+
(name: string, current: Catalog = catalog): Option.Option<Family> =>
|
|
146
|
+
Option.orElse(
|
|
147
|
+
Arr.findFirst(current.families, (family) =>
|
|
148
|
+
family.packages.includes(name)
|
|
149
|
+
),
|
|
150
|
+
() =>
|
|
151
|
+
Arr.findFirst(current.families, (family) =>
|
|
152
|
+
inScope(current, family, name)
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
type NamedLookup<A> = {
|
|
158
|
+
(current?: Catalog): (name: string) => Option.Option<A>;
|
|
159
|
+
(name: string, current?: Catalog): Option.Option<A>;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const lookupNamed = <A extends { readonly name: string }>(
|
|
163
|
+
entries: (current: Catalog) => ReadonlyArray<A>
|
|
164
|
+
): NamedLookup<A> =>
|
|
165
|
+
dual(
|
|
166
|
+
(args) => Schema.is(Schema.String)(args[0]),
|
|
167
|
+
(name: string, current: Catalog = catalog) =>
|
|
168
|
+
Arr.findFirst(entries(current), (entry) => entry.name === name)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
export const fixedOf = lookupNamed(
|
|
172
|
+
(current): ReadonlyArray<Fixed> => current.fixed
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
export const familyNamed = lookupNamed(
|
|
176
|
+
(current): ReadonlyArray<Family> => current.families
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
export const fixedBy: {
|
|
180
|
+
(current?: Catalog): (family: string) => ReadonlyArray<Fixed>;
|
|
181
|
+
(family: string, current?: Catalog): ReadonlyArray<Fixed>;
|
|
182
|
+
} = dual(
|
|
183
|
+
(args) => Schema.is(Schema.String)(args[0]),
|
|
184
|
+
(family: string, current: Catalog = catalog): ReadonlyArray<Fixed> =>
|
|
185
|
+
Arr.filter(current.fixed, (entry) => entry.by === family)
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
export const ownerOf: {
|
|
189
|
+
(current?: Catalog): (name: string) => Option.Option<Family>;
|
|
190
|
+
(name: string, current?: Catalog): Option.Option<Family>;
|
|
191
|
+
} = dual(
|
|
192
|
+
(args) => Schema.is(Schema.String)(args[0]),
|
|
193
|
+
(name: string, current: Catalog = catalog): Option.Option<Family> =>
|
|
194
|
+
Option.orElse(familyOf(name, current), () =>
|
|
195
|
+
Option.flatMap(fixedOf(name, current), (entry) =>
|
|
196
|
+
familyNamed(entry.by, current)
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
export const versionOf: {
|
|
202
|
+
(current?: Catalog): (name: string) => Option.Option<string>;
|
|
203
|
+
(name: string, current?: Catalog): Option.Option<string>;
|
|
204
|
+
} = dual(
|
|
205
|
+
(args) => Schema.is(Schema.String)(args[0]),
|
|
206
|
+
(name: string, current: Catalog = catalog): Option.Option<string> =>
|
|
207
|
+
Option.orElse(
|
|
208
|
+
Option.map(familyOf(name, current), (family) => family.version),
|
|
209
|
+
() => Option.map(fixedOf(name, current), (entry) => entry.version)
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
export const pinned = (current: Catalog): Readonly<Record<string, string>> =>
|
|
214
|
+
R.fromEntries([
|
|
215
|
+
...Arr.flatMap(current.families, (family) =>
|
|
216
|
+
Arr.map(family.packages, (name) => [name, family.version] as const)
|
|
217
|
+
),
|
|
218
|
+
...Arr.map(current.fixed, (entry) => [entry.name, entry.version] as const),
|
|
219
|
+
]);
|
|
220
|
+
|
|
221
|
+
export const versions: Readonly<Record<string, string>> = pinned(catalog);
|