@milkenjoyer/toolchain 0.14.1 → 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.
Files changed (46) hide show
  1. package/README.md +13 -17
  2. package/dist/effect-plugin-BsrW5_nI.mjs +79 -0
  3. package/dist/effect-plugin.d.mts +2 -3966
  4. package/dist/effect-plugin.mjs +1 -1
  5. package/dist/fmt-BaECz64m.mjs +8 -0
  6. package/dist/fmt.mjs +1 -8
  7. package/dist/formal.mjs +1 -1
  8. package/dist/guard-Doqk4Fju.mjs +143 -0
  9. package/dist/guard.mjs +1 -96
  10. package/dist/{lint-IhmtnBbx.mjs → lint-CfztB4u8.mjs} +1 -1
  11. package/dist/lint.mjs +1 -1
  12. package/dist/standard.mjs +557 -4
  13. package/package.json +4 -9
  14. package/src/arithmetic.ts +60 -0
  15. package/src/compatible.ts +512 -0
  16. package/src/conformance.ts +56 -0
  17. package/src/effect-plugin.ts +24 -0
  18. package/src/effect-tsgo.ts +44 -0
  19. package/src/exceptions.ts +17 -0
  20. package/src/fmt.ts +13 -0
  21. package/src/foldkit-plugin.ts +51 -0
  22. package/src/guard.ts +307 -0
  23. package/src/hooks.ts +205 -0
  24. package/src/index.ts +1 -0
  25. package/src/knip.ts +25 -0
  26. package/src/lint.ts +170 -0
  27. package/src/plugin.ts +21 -0
  28. package/src/rules/no-comments.ts +36 -0
  29. package/src/rules/no-process-env.ts +68 -0
  30. package/src/rules/prefer-accessible-scene-locators.ts +227 -0
  31. package/src/rules/require-command-answer-names.ts +144 -0
  32. package/src/rules/require-past-tense-messages.ts +201 -0
  33. package/src/rules/use-temp-file-scoped.ts +132 -0
  34. package/src/rules.ts +121 -0
  35. package/src/shared/foldkit-api.ts +51 -0
  36. package/src/shared/member-path.ts +106 -0
  37. package/src/shared/syntax.ts +47 -0
  38. package/src/standard/alchemy.ts +70 -0
  39. package/src/standard/checks.ts +10 -1
  40. package/src/standard/config.ts +84 -0
  41. package/src/standard/domain-rules.ts +204 -0
  42. package/src/standard/domain.ts +296 -0
  43. package/src/standard/infra.ts +486 -0
  44. package/src/versions.ts +221 -0
  45. package/dist/effect-plugin-BXUx9PPu.mjs +0 -3561
  46. package/dist/manifest-xQwgnYI1.mjs +0 -53
@@ -0,0 +1,17 @@
1
+ export type Exception = {
2
+ readonly files: ReadonlyArray<string>;
3
+ readonly rules: ReadonlyArray<string>;
4
+ readonly issue: string;
5
+ };
6
+
7
+ export const exceptions: ReadonlyArray<Exception> = [
8
+ {
9
+ files: ["packages/toolchain/src/conformance.ts"],
10
+ rules: [
11
+ "eslint/no-restricted-imports",
12
+ "vitest/no-disabled-tests",
13
+ "vitest/no-conditional-tests",
14
+ ],
15
+ issue: "https://github.com/birbprophet/agent-kit/issues/278",
16
+ },
17
+ ];
package/src/fmt.ts ADDED
@@ -0,0 +1,13 @@
1
+ import ultraciteFmt from "ultracite/oxfmt";
2
+ import type { OxfmtConfig } from "vite-plus/fmt";
3
+
4
+ export type FmtOptions = {
5
+ readonly ignores?: ReadonlyArray<string>;
6
+ };
7
+
8
+ const { ignorePatterns: coreIgnores = [] } = ultraciteFmt;
9
+
10
+ export const fmt = ({ ignores = [] }: FmtOptions = {}): OxfmtConfig => ({
11
+ ...ultraciteFmt,
12
+ ignorePatterns: [...coreIgnores, ...ignores],
13
+ });
@@ -0,0 +1,51 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+
4
+ import upstream from "@foldkit/oxlint-plugin";
5
+ import type { CreateRule } from "effect-oxlint";
6
+ import * as Arr from "effect/Array";
7
+ import * as Effect from "effect/Effect";
8
+ import * as R from "effect/Record";
9
+ import * as Schema from "effect/Schema";
10
+
11
+ const Dependencies = Schema.Record(Schema.String, Schema.Unknown).pipe(
12
+ Schema.withDecodingDefaultKey(Effect.succeed({}))
13
+ );
14
+ const Manifest = Schema.fromJsonString(
15
+ Schema.Struct({
16
+ dependencies: Dependencies,
17
+ devDependencies: Dependencies,
18
+ peerDependencies: Dependencies,
19
+ })
20
+ );
21
+
22
+ const packages = new Map<string, boolean>();
23
+
24
+ const usesFoldkit = (directory: string): boolean => {
25
+ const cached = packages.get(directory);
26
+ if (cached !== undefined) return cached;
27
+ const file = join(directory, "package.json");
28
+ const parent = dirname(directory);
29
+ const enabled = existsSync(file)
30
+ ? Arr.some(
31
+ R.values(Schema.decodeSync(Manifest)(readFileSync(file, "utf8"))),
32
+ (dependencies) => R.has(dependencies, "foldkit")
33
+ )
34
+ : parent !== directory && usesFoldkit(parent);
35
+ packages.set(directory, enabled);
36
+ return enabled;
37
+ };
38
+
39
+ const plugin: {
40
+ readonly meta: typeof upstream.meta;
41
+ readonly rules: Record<string, CreateRule>;
42
+ } = {
43
+ meta: upstream.meta,
44
+ rules: R.map(upstream.rules, (rule) => ({
45
+ ...rule,
46
+ create: (context): ReturnType<CreateRule["create"]> =>
47
+ usesFoldkit(dirname(context.filename)) ? rule.create(context) : {},
48
+ })),
49
+ };
50
+
51
+ export default plugin;
package/src/guard.ts ADDED
@@ -0,0 +1,307 @@
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 R from "effect/Record";
6
+ import * as Schema from "effect/Schema";
7
+ import * as Str from "effect/String";
8
+ import type { OxlintConfig, OxlintOverride } from "vite-plus/lint";
9
+
10
+ import {
11
+ latestOf,
12
+ onLatestLine,
13
+ otherTags,
14
+ type Packuments,
15
+ } from "./compatible.ts";
16
+ import { enforcedTsgoRules } from "./effect-tsgo.ts";
17
+ import { type Exception, exceptions as shared } from "./exceptions.ts";
18
+ import {
19
+ birbprophetRules,
20
+ effectRules,
21
+ foldkitPreset,
22
+ toolchainScopes,
23
+ } from "./lint.ts";
24
+ import { manifestRanges, type Ranges } from "./standard/manifest.ts";
25
+ export { exactFindings, manifestRanges } from "./standard/manifest.ts";
26
+ import { type Catalog, type Family, lead, versionOf } from "./versions.ts";
27
+
28
+ const DEPENDENCY_FIELDS = HashSet.fromIterable([
29
+ "dependencies",
30
+ "devDependencies",
31
+ "peerDependencies",
32
+ "optionalDependencies",
33
+ ]);
34
+
35
+ const VITE_CONFIG = /(?:^|\/)vite\.config\.[cm]?[jt]s$/u;
36
+
37
+ const MANIFEST = /(?:^|\/)package\.json$/u;
38
+
39
+ const VITE_PLUGIN = /["'`]@foldkit\/vite-plugin["'`]/u;
40
+
41
+ const folderOf = (file: string): string =>
42
+ Str.slice(
43
+ 0,
44
+ Str.lastIndexOf("/")(file).pipe(Option.getOrElse(() => -1)) + 1
45
+ )(file);
46
+
47
+ export const isFoldkitViteInput = (file: string): boolean =>
48
+ MANIFEST.test(file) || VITE_CONFIG.test(file);
49
+
50
+ export const foldkitViteFindings = (
51
+ files: ReadonlyArray<readonly [string, string]>
52
+ ): ReadonlyArray<string> => {
53
+ const foldkitFolders = HashSet.fromIterable(
54
+ Arr.flatMap(files, ([file, text]) =>
55
+ MANIFEST.test(file) &&
56
+ Arr.some(
57
+ manifestRanges(text),
58
+ ([field, ranges]) =>
59
+ HashSet.has(DEPENDENCY_FIELDS, field) && R.has(ranges, "foldkit")
60
+ )
61
+ ? [folderOf(file)]
62
+ : []
63
+ )
64
+ );
65
+
66
+ return Arr.flatMap(files, ([config, source]) =>
67
+ VITE_CONFIG.test(config) &&
68
+ HashSet.has(foldkitFolders, folderOf(config)) &&
69
+ !VITE_PLUGIN.test(source)
70
+ ? [
71
+ `${config} builds a foldkit package without @foldkit/vite-plugin, so view identity isn't stamped and keyed patching breaks`,
72
+ ]
73
+ : []
74
+ );
75
+ };
76
+
77
+ export const pinFindings: {
78
+ (text: string, rootCatalog?: Ranges): (file: string) => ReadonlyArray<string>;
79
+ (file: string, text: string, rootCatalog?: Ranges): ReadonlyArray<string>;
80
+ } = dual(
81
+ (args) => Schema.is(Schema.String)(args[1]),
82
+ (
83
+ file: string,
84
+ text: string,
85
+ rootCatalog: Ranges = {}
86
+ ): ReadonlyArray<string> =>
87
+ Arr.flatMap(manifestRanges(text), ([field, ranges]) =>
88
+ Arr.flatMap(R.toEntries(ranges), ([name, written]) =>
89
+ Option.match(versionOf(name), {
90
+ onNone: () => [],
91
+ onSome: (pinnedVersion) => {
92
+ const actual =
93
+ written === "catalog:"
94
+ ? Option.getOrElse(R.get(rootCatalog, name), () => written)
95
+ : written;
96
+
97
+ return actual === pinnedVersion ||
98
+ Str.startsWith("workspace:")(written)
99
+ ? []
100
+ : [
101
+ `${file} ${field} ${name}: ${actual} is not the toolchain catalog's ${pinnedVersion}`,
102
+ ];
103
+ },
104
+ })
105
+ )
106
+ )
107
+ );
108
+
109
+ type RuleSetting = NonNullable<NonNullable<OxlintConfig["rules"]>[string]>;
110
+
111
+ const severityOf = (setting: RuleSetting): string =>
112
+ String(
113
+ Schema.is(Schema.Array(Schema.Unknown))(setting) ? setting[0] : setting
114
+ );
115
+
116
+ const atError = (setting: RuleSetting): boolean =>
117
+ ["error", "deny", "2"].includes(severityOf(setting));
118
+
119
+ const settingOf = (
120
+ rules: OxlintConfig["rules"],
121
+ rule: string
122
+ ): Option.Option<RuleSetting> => Option.fromNullishOr(rules?.[rule]);
123
+
124
+ const guarded: ReadonlyArray<string> = [
125
+ ...R.keys(R.filter(foldkitPreset.rules, (setting) => setting === "error")),
126
+ ...R.keys(effectRules),
127
+ ...R.keys(birbprophetRules),
128
+ ...enforcedTsgoRules,
129
+ ];
130
+
131
+ type Scope = Pick<Exception, "files" | "rules">;
132
+
133
+ const presetScopes: ReadonlyArray<Scope> = Arr.map(
134
+ [...foldkitPreset.overrides, ...toolchainScopes],
135
+ ({ files, rules = {} }) => ({
136
+ files,
137
+ rules: R.keys(R.filter(rules, (setting) => setting === "off")),
138
+ })
139
+ );
140
+
141
+ const scopedGuards: ReadonlyArray<
142
+ Scope & { readonly excludeFiles: ReadonlyArray<string> }
143
+ > = Arr.map(foldkitPreset.overrides, ({ files, excludeFiles = [], rules }) => ({
144
+ files,
145
+ excludeFiles,
146
+ rules: R.keys(R.filter(rules, (setting) => setting === "error")),
147
+ }));
148
+
149
+ const guardedInOverrides: ReadonlyArray<string> = Arr.dedupe([
150
+ ...guarded,
151
+ ...Arr.flatMap(scopedGuards, ({ rules }) => rules),
152
+ ]);
153
+
154
+ const sameFiles = (
155
+ files: ReadonlyArray<string>,
156
+ other: ReadonlyArray<string>
157
+ ): boolean =>
158
+ files.length === other.length &&
159
+ Arr.every(files, (file) => other.includes(file));
160
+
161
+ const excepted = (
162
+ override: OxlintOverride,
163
+ rule: string,
164
+ list: ReadonlyArray<Scope>
165
+ ): boolean =>
166
+ Arr.some(
167
+ [...presetScopes, ...list],
168
+ (exception) =>
169
+ exception.rules.includes(rule) &&
170
+ sameFiles(override.files, exception.files)
171
+ );
172
+
173
+ const scopeFindings = (
174
+ overrides: ReadonlyArray<OxlintOverride>
175
+ ): ReadonlyArray<string> =>
176
+ Arr.flatMap(scopedGuards, ({ files, excludeFiles, rules }) =>
177
+ Arr.flatMap(rules, (rule) =>
178
+ Arr.some(
179
+ overrides,
180
+ (override) =>
181
+ sameFiles(override.files, files) &&
182
+ sameFiles(override.excludeFiles ?? [], excludeFiles) &&
183
+ Option.exists(settingOf(override.rules, rule), atError)
184
+ )
185
+ ? []
186
+ : [`${rule} is not at error for ${Arr.join(files, ", ")}`]
187
+ )
188
+ );
189
+
190
+ const overrideFindings = (
191
+ where: string,
192
+ overrides: ReadonlyArray<OxlintOverride>,
193
+ list: ReadonlyArray<Exception>
194
+ ): ReadonlyArray<string> =>
195
+ Arr.flatMap(overrides, (override) =>
196
+ Arr.flatMap(guardedInOverrides, (rule) =>
197
+ Option.match(settingOf(override.rules, rule), {
198
+ onNone: () => [],
199
+ onSome: (setting) =>
200
+ atError(setting) || excepted(override, rule, list)
201
+ ? []
202
+ : [
203
+ `${where} override for ${Arr.join(override.files, ", ")} sets ${rule} to ${severityOf(setting)} outside a named-file exception`,
204
+ ],
205
+ })
206
+ )
207
+ );
208
+
209
+ const inheritedFindings = (
210
+ where: string,
211
+ { extends: extendedConfigs = [] }: OxlintConfig
212
+ ): ReadonlyArray<string> =>
213
+ Arr.flatMap(extendedConfigs, ({ overrides = [], ...extended }, index) => {
214
+ const path = `${where}extends[${index}]`;
215
+
216
+ return [
217
+ ...overrideFindings(path, overrides, []),
218
+ ...inheritedFindings(`${path}.`, extended),
219
+ ];
220
+ });
221
+
222
+ export const ruleFindings: {
223
+ (
224
+ list?: ReadonlyArray<Exception>
225
+ ): (config: OxlintConfig) => ReadonlyArray<string>;
226
+ (
227
+ config: OxlintConfig,
228
+ list?: ReadonlyArray<Exception>
229
+ ): ReadonlyArray<string>;
230
+ } = dual(
231
+ (args) =>
232
+ args[0] !== undefined && !Schema.is(Schema.Array(Schema.Unknown))(args[0]),
233
+ (
234
+ { overrides = [], ...config }: OxlintConfig,
235
+ list: ReadonlyArray<Exception> = shared
236
+ ): ReadonlyArray<string> => [
237
+ ...Arr.flatMap(guarded, (rule) =>
238
+ Option.match(settingOf(config.rules, rule), {
239
+ onNone: () => [`${rule} is not set`],
240
+ onSome: (setting) =>
241
+ atError(setting) ? [] : [`${rule} is ${severityOf(setting)}`],
242
+ })
243
+ ),
244
+ ...overrideFindings("the config's", overrides, list),
245
+ ...scopeFindings(overrides),
246
+ ...inheritedFindings("", config),
247
+ ]
248
+ );
249
+
250
+ const GLOB = /[*?[\]{}!]/u;
251
+
252
+ const ISSUE = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+$/u;
253
+
254
+ export const exceptionFindings = (
255
+ list: ReadonlyArray<Exception> = shared
256
+ ): ReadonlyArray<string> =>
257
+ Arr.flatMap(list, (exception, index) => [
258
+ ...(Arr.isReadonlyArrayEmpty(exception.files)
259
+ ? [`exception ${index} names no file`]
260
+ : []),
261
+ ...Arr.flatMap(exception.files, (file) =>
262
+ GLOB.test(file)
263
+ ? [`exception ${index} names ${file}, a pattern rather than a file`]
264
+ : []
265
+ ),
266
+ ...(Arr.isReadonlyArrayEmpty(exception.rules)
267
+ ? [`exception ${index} names no rule`]
268
+ : []),
269
+ ...(ISSUE.test(exception.issue)
270
+ ? []
271
+ : [`exception ${index} has no issue link: ${exception.issue}`]),
272
+ ]);
273
+
274
+ const familyTagFindings = (
275
+ registry: Packuments,
276
+ family: Family
277
+ ): ReadonlyArray<string> =>
278
+ Option.match(latestOf(registry, family), {
279
+ onNone: () => [`${lead(family)} has no latest tag in the registry record`],
280
+ onSome: (latest) =>
281
+ family.version === latest
282
+ ? []
283
+ : Option.match(
284
+ Arr.findFirst(
285
+ otherTags(registry, family),
286
+ ([, version]) => version === family.version
287
+ ),
288
+ {
289
+ onSome: ([tag]) => [
290
+ `${family.name} ${family.version} comes from the ${tag} tag`,
291
+ ],
292
+ onNone: () =>
293
+ onLatestLine(family.version, latest)
294
+ ? []
295
+ : [
296
+ `${family.name} ${family.version} is not on npm's latest line (${latest})`,
297
+ ],
298
+ }
299
+ ),
300
+ });
301
+
302
+ export const tagFindings: {
303
+ (registry: Packuments): (current: Catalog) => ReadonlyArray<string>;
304
+ (current: Catalog, registry: Packuments): ReadonlyArray<string>;
305
+ } = dual(2, (current: Catalog, registry: Packuments): ReadonlyArray<string> =>
306
+ Arr.flatMap(current.families, (family) => familyTagFindings(registry, family))
307
+ );
package/src/hooks.ts ADDED
@@ -0,0 +1,205 @@
1
+ import * as Arr from "effect/Array";
2
+ import * as Effect from "effect/Effect";
3
+ import { FileSystem } from "effect/FileSystem";
4
+ import { Path } from "effect/Path";
5
+ import { ChildProcess } from "effect/process";
6
+ import * as Schema from "effect/Schema";
7
+ import * as Stream from "effect/Stream";
8
+ import * as Str from "effect/String";
9
+
10
+ export const worktreePrePush = `#!/bin/sh
11
+ if ! root=$(git rev-parse --show-toplevel); then
12
+ printf '%s\\n' 'pre-push: could not determine the invoking worktree root' >&2
13
+ exit 1
14
+ fi
15
+ if [ ! -f "$root/node_modules/.bin/vp" ] || [ ! -x "$root/node_modules/.bin/vp" ]; then
16
+ printf '%s\\n' "pre-push: missing or nonexecutable $root/node_modules/.bin/vp" >&2
17
+ exit 1
18
+ fi
19
+ if [ ! -f "$root/.vite-hooks/pre-push" ]; then
20
+ printf '%s\\n' "pre-push: missing $root/.vite-hooks/pre-push" >&2
21
+ exit 1
22
+ fi
23
+ if ! git -C "$root" ls-files --error-unmatch .vite-hooks/pre-push >/dev/null 2>&1; then
24
+ printf '%s\\n' "pre-push: untracked $root/.vite-hooks/pre-push" >&2
25
+ exit 1
26
+ fi
27
+ export PATH="$root/node_modules/.bin:$PATH"
28
+ exec /bin/sh -e "$root/.vite-hooks/pre-push" "$@"
29
+ `;
30
+
31
+ class Setup extends Schema.TaggedError<
32
+ Setup,
33
+ { readonly brand: unique symbol }
34
+ >()("Setup", {
35
+ message: Schema.String,
36
+ }) {}
37
+
38
+ const execute = Effect.fn("Hooks.execute")(function* (
39
+ command: ChildProcess.StandardCommand
40
+ ) {
41
+ const child = yield* command;
42
+
43
+ const [code, stdout, stderr] = yield* Effect.all(
44
+ [
45
+ child.exitCode,
46
+ child.stdout.pipe(Stream.decodeText, Stream.mkString),
47
+ child.stderr.pipe(Stream.decodeText, Stream.mkString),
48
+ ],
49
+ { concurrency: "unbounded" }
50
+ );
51
+
52
+ if (Number(code) !== 0) {
53
+ return yield* Setup.make({
54
+ message: `${command.command} ${Arr.join(Arr.map(command.args, String), " ")} exited ${code}: ${stdout}${stderr}`,
55
+ });
56
+ }
57
+
58
+ return { stdout, stderr };
59
+ });
60
+
61
+ const git = Effect.fn("Hooks.git")(function* (
62
+ cwd: string,
63
+ args: ReadonlyArray<string>
64
+ ) {
65
+ return yield* execute(
66
+ ChildProcess.make("git", args, { cwd, stdin: "ignore" })
67
+ );
68
+ });
69
+
70
+ const localVp = Effect.fn("Hooks.localVp")(function* (
71
+ root: string,
72
+ args: ReadonlyArray<string>
73
+ ) {
74
+ return yield* execute(
75
+ ChildProcess.make(`${root}/node_modules/.bin/vp`, args, {
76
+ cwd: root,
77
+ stdin: "ignore",
78
+ })
79
+ );
80
+ });
81
+
82
+ const requireFile = Effect.fn("Hooks.requireFile")(function* (file: string) {
83
+ const fs = yield* FileSystem;
84
+ const stat = yield* fs.stat(file);
85
+
86
+ if (stat.type !== "File") {
87
+ return yield* Setup.make({
88
+ message: `Required pre-push setup file is not a file: ${file}`,
89
+ });
90
+ }
91
+
92
+ return stat;
93
+ });
94
+
95
+ const requireExecutable = Effect.fn("Hooks.requireExecutable")(function* (
96
+ file: string
97
+ ) {
98
+ const stat = yield* requireFile(file);
99
+
100
+ const executable = Arr.some(
101
+ [0o100, 0o010, 0o001],
102
+ (permission) => Math.floor(stat.mode / permission) % 2 === 1
103
+ );
104
+
105
+ if (!executable) {
106
+ return yield* Setup.make({
107
+ message: `Required pre-push setup file is not executable: ${file}`,
108
+ });
109
+ }
110
+
111
+ return stat;
112
+ });
113
+
114
+ const installPrePush = Effect.fn("Hooks.installPrePush")(function* (
115
+ root: string
116
+ ) {
117
+ const fs = yield* FileSystem;
118
+ const path = yield* Path;
119
+ const generated = path.join(root, ".vite-hooks", "_");
120
+ yield* requireFile(path.join(generated, "h"));
121
+ const dispatcher = path.join(generated, "pre-push");
122
+ yield* requireFile(dispatcher);
123
+ yield* git(root, ["config", "--local", "core.hooksPath", generated]);
124
+ yield* fs.writeFileString(dispatcher, worktreePrePush);
125
+ yield* fs.chmod(dispatcher, 0o755);
126
+ });
127
+
128
+ const verifyActivePrePush = Effect.fn("Hooks.verifyActivePrePush")(function* (
129
+ root: string
130
+ ) {
131
+ const fs = yield* FileSystem;
132
+ const path = yield* Path;
133
+
134
+ const active = yield* git(root, [
135
+ "rev-parse",
136
+ "--path-format=absolute",
137
+ "--git-path",
138
+ "hooks",
139
+ ]);
140
+
141
+ const activeHook = path.join(Str.trim(active.stdout), "pre-push");
142
+ const bytes = yield* fs.readFile(activeHook);
143
+ const expected = new TextEncoder().encode(worktreePrePush);
144
+
145
+ if (
146
+ bytes.length !== expected.length ||
147
+ bytes.some((byte, index) => byte !== expected[index])
148
+ ) {
149
+ return yield* Setup.make({
150
+ message: `Active pre-push has wrong bytes: ${activeHook}`,
151
+ });
152
+ }
153
+
154
+ return yield* requireExecutable(activeHook).pipe(Effect.asVoid);
155
+ });
156
+
157
+ export const configurePrePush = Effect.fn("Hooks.configurePrePush")(function* ({
158
+ cwd,
159
+ agent,
160
+ }: {
161
+ readonly cwd: string;
162
+ readonly agent: boolean;
163
+ }) {
164
+ const path = yield* Path;
165
+
166
+ const rootResult = yield* git(cwd, ["rev-parse", "--show-toplevel"]);
167
+
168
+ const root = Str.trim(rootResult.stdout);
169
+ const vp = path.join(root, "node_modules", ".bin", "vp");
170
+ yield* requireExecutable(vp);
171
+ const tracked = path.join(root, ".vite-hooks", "pre-push");
172
+ yield* requireFile(tracked);
173
+ yield* git(root, ["ls-files", "--error-unmatch", ".vite-hooks/pre-push"]);
174
+
175
+ yield* localVp(root, ["config", "--hooks", agent ? "--agent" : "--no-agent"]);
176
+
177
+ const active = yield* git(root, [
178
+ "rev-parse",
179
+ "--path-format=absolute",
180
+ "--git-path",
181
+ "hooks",
182
+ ]);
183
+
184
+ const generated = path.join(root, ".vite-hooks", "_");
185
+
186
+ const disabled = yield* git(root, [
187
+ "config",
188
+ "--type=bool",
189
+ "--default=false",
190
+ "--get",
191
+ "vp.hooks.disabled",
192
+ ]);
193
+
194
+ if (Str.trim(disabled.stdout) === "true") {
195
+ return yield* Setup.make({
196
+ message: "Native pre-push setup has hooks disabled",
197
+ });
198
+ }
199
+
200
+ if (Str.trim(active.stdout) === generated) {
201
+ yield* installPrePush(root);
202
+ }
203
+
204
+ return yield* verifyActivePrePush(root);
205
+ }, Effect.scoped);
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export const packageName = "@milkenjoyer/toolchain";
package/src/knip.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { KnipConfiguration } from "knip";
2
+
3
+ export type KnipOptions = {
4
+ readonly entry?: ReadonlyArray<string>;
5
+ readonly ignoreDependencies?: ReadonlyArray<string>;
6
+ readonly workspaces?: KnipConfiguration["workspaces"];
7
+ };
8
+
9
+ const baseEntry = [
10
+ "*.run.ts",
11
+ "scripts/*.ts",
12
+ "tests/fixtures/**/*.ts",
13
+ "**/*.proof.ts",
14
+ ];
15
+
16
+ const toolchainPlugins = ["@effect/language-service", "@foldkit/oxlint-plugin"];
17
+
18
+ export const knip = ({
19
+ entry = [],
20
+ ignoreDependencies = [],
21
+ workspaces = {},
22
+ }: KnipOptions = {}): KnipConfiguration => ({
23
+ ignoreDependencies: [...toolchainPlugins, ...ignoreDependencies],
24
+ workspaces: { ".": { entry: [...baseEntry, ...entry] }, ...workspaces },
25
+ });