@r_masseater/vite-plus-adopt 0.2.0 → 0.3.1
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 +69 -51
- package/dist/{attempt-5nU57gc3.mjs → attempt-B93fjWiJ.mjs} +5 -2
- package/dist/{attempt-5nU57gc3.mjs.map → attempt-B93fjWiJ.mjs.map} +1 -1
- package/dist/attw.mjs +518 -411
- package/dist/attw.mjs.map +1 -1
- package/dist/cli.mjs +429 -165
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-C8pUNPt5.mjs → config-BdAPwzCc.mjs} +6 -12
- package/dist/config-BdAPwzCc.mjs.map +1 -0
- package/dist/fsd.d.mts +1 -1
- package/dist/fsd.mjs +5 -4
- package/dist/fsd.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{run-cli-DspfTYgh.mjs → install-COdnLosP.mjs} +46 -37
- package/dist/install-COdnLosP.mjs.map +1 -0
- package/dist/json-D-rhjlSM.mjs +9 -0
- package/dist/json-D-rhjlSM.mjs.map +1 -0
- package/dist/postinstall.mjs +6 -4
- package/dist/postinstall.mjs.map +1 -1
- package/dist/{types-BtHVwMCx.d.mts → types-LygeEwCK.d.mts} +21 -4
- package/package.json +10 -10
- package/dist/config-C8pUNPt5.mjs.map +0 -1
- package/dist/run-cli-DspfTYgh.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,73 +1,156 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
8
|
-
import { minimatch } from "minimatch";
|
|
9
|
-
import { intersects, valid, validRange } from "semver";
|
|
10
|
-
import { parse } from "yaml";
|
|
2
|
+
import { a as ZIZMOR, c as writeTo, i as BETTERLEAKS, n as locateBinary, o as runCli, r as ACTIONLINT, s as finish } from "./install-COdnLosP.mjs";
|
|
3
|
+
import { a as toolFailed, r as checksFailed, t as attempt } from "./attempt-B93fjWiJ.mjs";
|
|
4
|
+
import { n as loadViteConfig, t as loadSection } from "./config-BdAPwzCc.mjs";
|
|
5
|
+
import { n as toJson } from "./json-D-rhjlSM.mjs";
|
|
6
|
+
import { Array, Config, Effect, FileSystem, Function, Option, Path, Predicate, Record, Schema, Stdio, Stream, String, pipe } from "effect";
|
|
11
7
|
import format from "@commitlint/format";
|
|
12
8
|
import lint from "@commitlint/lint";
|
|
13
9
|
import load from "@commitlint/load";
|
|
10
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
11
|
+
import { minimatch } from "minimatch";
|
|
12
|
+
import { intersects, valid, validRange } from "semver";
|
|
14
13
|
import { linter, processConfiguration } from "steiger";
|
|
14
|
+
import { parse } from "yaml";
|
|
15
|
+
import { stringify } from "smol-toml";
|
|
16
|
+
import { lint as lint$1 } from "markdownlint/promise";
|
|
15
17
|
import { loadPackagesFromRawConfig } from "@textlint/config-loader";
|
|
16
18
|
import { TextlintKernelDescriptor } from "@textlint/kernel";
|
|
17
19
|
import { createLinter, loadLinterFormatter } from "textlint";
|
|
18
20
|
import { builtInPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
|
|
19
|
-
// src/
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// src/commitlint.ts
|
|
22
|
+
const DATA_FIRST_ARITY_3$3 = 3;
|
|
23
|
+
const COMMENT_CHAR = "#";
|
|
24
|
+
const parserOptionsOf = (loaded) => {
|
|
25
|
+
return {
|
|
26
|
+
...pipe(Option.fromNullishOr(loaded.parserPreset), Option.map(({ parserOpts }) => parserOpts), Option.filter(Predicate.isObject), Option.getOrElse(() => ({}))),
|
|
27
|
+
commentChar: COMMENT_CHAR
|
|
28
|
+
};
|
|
23
29
|
};
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const lintOptionsOf = (loaded) => ({
|
|
31
|
+
parserOpts: parserOptionsOf(loaded),
|
|
32
|
+
plugins: loaded.plugins,
|
|
33
|
+
ignores: loaded.ignores ?? [],
|
|
34
|
+
defaultIgnores: loaded.defaultIgnores ?? true
|
|
35
|
+
});
|
|
36
|
+
const lintCommitMessages = Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messages) => Effect.gen(function* lintMessages() {
|
|
37
|
+
const loaded = yield* attempt("commitlint")(() => load(config, { cwd: root }));
|
|
38
|
+
const results = yield* pipe(messages, Effect.forEach((message) => attempt("commitlint")(() => lint(message, loaded.rules, lintOptionsOf(loaded)))));
|
|
39
|
+
return {
|
|
40
|
+
valid: pipe(results, Array.every((result) => result.valid)),
|
|
41
|
+
output: format({ results }, { color: false })
|
|
42
|
+
};
|
|
43
|
+
}));
|
|
44
|
+
const lintCommitMessageFile = Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messageFile) => Effect.gen(function* read() {
|
|
45
|
+
const message = yield* (yield* FileSystem.FileSystem).readFileString(messageFile);
|
|
46
|
+
return yield* lintCommitMessages(config, root, [message]);
|
|
47
|
+
}));
|
|
48
|
+
// src/process.ts
|
|
49
|
+
const SUCCESS$1 = 0;
|
|
50
|
+
const stdinOf = (input) => pipe(Option.fromNullishOr(input), Option.match({
|
|
51
|
+
onNone: () => "ignore",
|
|
52
|
+
onSome: (text) => Stream.make(new TextEncoder().encode(text))
|
|
53
|
+
}));
|
|
54
|
+
const runCaptured = ({ root, file, args, env = {}, input, output = "all" }) => Effect.gen(function* run() {
|
|
55
|
+
const handle = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(ChildProcess.make(file, args, {
|
|
30
56
|
cwd: root,
|
|
31
57
|
env,
|
|
32
58
|
extendEnv: true,
|
|
33
|
-
stdin:
|
|
34
|
-
stdout: "inherit",
|
|
35
|
-
stderr: "inherit"
|
|
59
|
+
stdin: stdinOf(input)
|
|
36
60
|
}));
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
const [text, exitCode] = yield* Effect.all([handle[output].pipe(Stream.decodeText, Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
|
|
62
|
+
return {
|
|
63
|
+
valid: exitCode === SUCCESS$1,
|
|
64
|
+
output: text
|
|
65
|
+
};
|
|
66
|
+
}).pipe(Effect.scoped);
|
|
67
|
+
// src/section-check.ts
|
|
68
|
+
const withSection = Function.dual(2, (key, run) => (context) => pipe(Option.fromNullishOr(context.config[key]), Option.match({
|
|
69
|
+
onNone: () => Effect.succeedNone,
|
|
70
|
+
onSome: (section) => Effect.asSome(run(section, context))
|
|
71
|
+
})));
|
|
72
|
+
// src/fallow-check.ts
|
|
73
|
+
const QUIET = [
|
|
74
|
+
"--fail-on-issues",
|
|
75
|
+
"--quiet",
|
|
76
|
+
"--format",
|
|
77
|
+
"compact"
|
|
78
|
+
];
|
|
79
|
+
const RUNS = [
|
|
80
|
+
[
|
|
81
|
+
"--skip",
|
|
82
|
+
"dupes",
|
|
83
|
+
...QUIET
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
"dead-code",
|
|
87
|
+
"--no-production",
|
|
88
|
+
...QUIET
|
|
89
|
+
],
|
|
90
|
+
["dupes", ...QUIET],
|
|
91
|
+
[
|
|
92
|
+
"security",
|
|
93
|
+
"--fail-on-issues",
|
|
94
|
+
"--quiet"
|
|
95
|
+
]
|
|
96
|
+
];
|
|
97
|
+
const SMELLS = Schema.Array(Schema.Unknown).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])));
|
|
98
|
+
const COMPONENT_SMELLS = Schema.Struct({
|
|
99
|
+
prop_drilling_chains: SMELLS,
|
|
100
|
+
thin_wrappers: SMELLS,
|
|
101
|
+
duplicate_prop_shapes: SMELLS
|
|
41
102
|
});
|
|
42
|
-
const
|
|
103
|
+
const decodeSmells = Schema.decodeUnknownEffect(Schema.fromJsonString(COMPONENT_SMELLS));
|
|
104
|
+
const componentSmells = (root, configFile) => runCaptured({
|
|
43
105
|
root,
|
|
44
|
-
|
|
45
|
-
args
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
106
|
+
file: "fallow",
|
|
107
|
+
args: [
|
|
108
|
+
"dead-code",
|
|
109
|
+
"--no-production",
|
|
110
|
+
"--quiet",
|
|
111
|
+
"--format",
|
|
112
|
+
"json",
|
|
113
|
+
"-c",
|
|
114
|
+
configFile
|
|
115
|
+
],
|
|
116
|
+
output: "stdout"
|
|
117
|
+
}).pipe(Effect.flatMap((report) => decodeSmells(report.output)), Effect.map((smells) => {
|
|
118
|
+
const found = [
|
|
119
|
+
...smells.prop_drilling_chains,
|
|
120
|
+
...smells.thin_wrappers,
|
|
121
|
+
...smells.duplicate_prop_shapes
|
|
122
|
+
];
|
|
123
|
+
return {
|
|
124
|
+
valid: Array.isReadonlyArrayEmpty(found),
|
|
125
|
+
output: toJson(smells)
|
|
126
|
+
};
|
|
127
|
+
}));
|
|
128
|
+
const runFallow = (config, root) => Effect.gen(function* fallow() {
|
|
54
129
|
const fs = yield* FileSystem.FileSystem;
|
|
55
|
-
const
|
|
56
|
-
yield* fs.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (!Array.isReadonlyArrayNonEmpty(args)) return yield* Effect.fail(checksFailed(BETTERLEAKS_USAGE));
|
|
62
|
-
const ignore = yield* ignoreFileArgs(config);
|
|
63
|
-
return yield* runVendored({
|
|
130
|
+
const path = yield* Path.Path;
|
|
131
|
+
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "vpa-fallow-" });
|
|
132
|
+
const configFile = path.join(directory, ".fallowrc.json");
|
|
133
|
+
const configText = yield* Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(config).pipe(Effect.orDie);
|
|
134
|
+
yield* fs.writeFileString(configFile, configText);
|
|
135
|
+
const reports = yield* pipe(RUNS, Effect.forEach((args) => runCaptured({
|
|
64
136
|
root,
|
|
65
|
-
|
|
66
|
-
args: [
|
|
67
|
-
|
|
68
|
-
|
|
137
|
+
file: "fallow",
|
|
138
|
+
args: [
|
|
139
|
+
...args,
|
|
140
|
+
"-c",
|
|
141
|
+
configFile
|
|
142
|
+
]
|
|
143
|
+
})));
|
|
144
|
+
const smells = yield* componentSmells(root, configFile);
|
|
145
|
+
const all = [...reports, smells];
|
|
146
|
+
return {
|
|
147
|
+
valid: pipe(all, Array.every((report) => report.valid)),
|
|
148
|
+
output: pipe(all, Array.filter((report) => !report.valid), Array.map((report) => report.output), Array.join("\n"))
|
|
149
|
+
};
|
|
69
150
|
}).pipe(Effect.scoped);
|
|
151
|
+
const fallowCheck = withSection("fallow", (config, { root }) => runFallow(config, root));
|
|
70
152
|
// src/dependency-rules.ts
|
|
153
|
+
const DATA_FIRST_ARITY$3 = 2;
|
|
71
154
|
const SINGLE = 1;
|
|
72
155
|
const bannedBy = (dependencies) => ([reason, globs]) => {
|
|
73
156
|
const isBanned = (name) => pipe(globs, Array.some((glob) => minimatch(name, glob)));
|
|
@@ -92,15 +175,15 @@ const exactGlobs = (rules) => pipe(Record.values(rules.exactDependencies ?? {}),
|
|
|
92
175
|
const notExactBy = (dependencies) => ([reason, globs]) => pipe(dependencies, Array.filter(inWorkspaces(globs)), Array.filter((dependency) => valid(dependency.specifier) === null), Array.map((dependency) => `${dependency.manifest} dependencies.${dependency.name} must be an exact version: ${reason}`));
|
|
93
176
|
const exactProblems = (rules, dependencies) => pipe(Record.toEntries(rules.exactDependencies ?? {}), Array.flatMap(notExactBy(dependencies)));
|
|
94
177
|
const groupByName = (dependencies) => Record.values(Array.groupBy(dependencies, ({ name }) => name));
|
|
95
|
-
const describe = (dependencies) => {
|
|
178
|
+
const describe$1 = (dependencies) => {
|
|
96
179
|
return `${pipe(Array.head(dependencies), Option.match({
|
|
97
180
|
onNone: () => "",
|
|
98
181
|
onSome: (dependency) => dependency.name
|
|
99
182
|
}))}: ${pipe(dependencies, Array.map((dependency) => `${dependency.manifest} ${dependency.field} ${dependency.specifier}`), Array.join(", "))}`;
|
|
100
183
|
};
|
|
101
|
-
const mismatchProblems = (dependencies) => pipe(groupByName(dependencies), Array.filter((group) => new Set(pipe(group, Array.map(({ specifier }) => specifier))).size > SINGLE), Array.map((group) => `different specifiers for ${describe(group)}`));
|
|
184
|
+
const mismatchProblems = (dependencies) => pipe(groupByName(dependencies), Array.filter((group) => new Set(pipe(group, Array.map(({ specifier }) => specifier))).size > SINGLE), Array.map((group) => `different specifiers for ${describe$1(group)}`));
|
|
102
185
|
const isDisjoint = (ranges) => pipe(ranges, Array.some((left) => pipe(ranges, Array.some((right) => !intersects(left.specifier, right.specifier)))));
|
|
103
|
-
const disjointRangeProblems = (peers) => pipe(groupByName(peers), Array.map((group) => pipe(group, Array.filter(({ specifier }) => validRange(specifier) !== null))), Array.filter(isDisjoint), Array.map((ranges) => `peer ranges do not intersect for ${describe(ranges)}`));
|
|
186
|
+
const disjointRangeProblems = (peers) => pipe(groupByName(peers), Array.map((group) => pipe(group, Array.filter(({ specifier }) => validRange(specifier) !== null))), Array.filter(isDisjoint), Array.map((ranges) => `peer ranges do not intersect for ${describe$1(ranges)}`));
|
|
104
187
|
const isPeer = ({ field }) => field === "peerDependencies";
|
|
105
188
|
const versionProblems = (rules, pinned) => {
|
|
106
189
|
if (rules.peerRanges !== "intersect") return mismatchProblems(pinned);
|
|
@@ -112,13 +195,14 @@ const comparedDependencies = (rules, dependencies) => {
|
|
|
112
195
|
const isExact = inWorkspaces(exactGlobs(rules));
|
|
113
196
|
return pipe(dependencies, Array.filter(({ specifier }) => !String.startsWith("workspace:")(specifier)), Array.filter(Predicate.not(isExact)));
|
|
114
197
|
};
|
|
115
|
-
const checkDependencies = (rules, dependencies) => [
|
|
198
|
+
const checkDependencies = Function.dual(DATA_FIRST_ARITY$3, (rules, dependencies) => [
|
|
116
199
|
...bannedProblems(rules, dependencies),
|
|
117
200
|
...exactProblems(rules, dependencies),
|
|
118
201
|
...versionProblems(rules, comparedDependencies(rules, dependencies))
|
|
119
|
-
];
|
|
202
|
+
]);
|
|
120
203
|
// src/git.ts
|
|
121
|
-
const
|
|
204
|
+
const DATA_FIRST_ARITY$2 = 2;
|
|
205
|
+
const listGitFiles = Function.dual(DATA_FIRST_ARITY$2, (root, pathspecs) => Effect.gen(function* list() {
|
|
122
206
|
const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
|
|
123
207
|
"-c",
|
|
124
208
|
"core.quotePath=false",
|
|
@@ -130,8 +214,8 @@ const listGitFiles = (root, pathspecs) => Effect.gen(function* list() {
|
|
|
130
214
|
...pathspecs
|
|
131
215
|
], { cwd: root }));
|
|
132
216
|
return pipe(String.split(output, "\0"), Array.filter(String.isNonEmpty));
|
|
133
|
-
});
|
|
134
|
-
const listCommitMessages = (root, range) => Effect.gen(function* messages() {
|
|
217
|
+
}));
|
|
218
|
+
const listCommitMessages = Function.dual(DATA_FIRST_ARITY$2, (root, range) => Effect.gen(function* messages() {
|
|
135
219
|
const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
|
|
136
220
|
"log",
|
|
137
221
|
"-z",
|
|
@@ -141,7 +225,20 @@ const listCommitMessages = (root, range) => Effect.gen(function* messages() {
|
|
|
141
225
|
"--"
|
|
142
226
|
], { cwd: root }));
|
|
143
227
|
return pipe(String.split(output, "\0"), Array.filter(String.isNonEmpty));
|
|
228
|
+
}));
|
|
229
|
+
// src/steiger.ts
|
|
230
|
+
const DATA_FIRST_ARITY_3$2 = 3;
|
|
231
|
+
const formatDiagnostic = (relative) => (diagnostic) => `${diagnostic.severity} ${relative(diagnostic.location.path)}: ${diagnostic.message} (${diagnostic.ruleName})`;
|
|
232
|
+
const reportOf = (diagnostics, relative) => ({
|
|
233
|
+
valid: pipe(diagnostics, Array.every((diagnostic) => diagnostic.severity !== "error")),
|
|
234
|
+
output: pipe(diagnostics, Array.map(formatDiagnostic(relative)), Array.join("\n"))
|
|
144
235
|
});
|
|
236
|
+
const checkSlices = Function.dual(DATA_FIRST_ARITY_3$2, (config, root, targets) => Effect.gen(function* check() {
|
|
237
|
+
const path = yield* Path.Path;
|
|
238
|
+
processConfiguration([...config], root);
|
|
239
|
+
const perTarget = yield* pipe(targets, Effect.forEach((target) => attempt("steiger")(() => linter.run(path.resolve(root, target)))));
|
|
240
|
+
return reportOf(Array.flatten(perTarget), (file) => path.relative(root, file));
|
|
241
|
+
}));
|
|
145
242
|
// src/workspace.ts
|
|
146
243
|
const DEPENDENCY_FIELDS = [
|
|
147
244
|
"dependencies",
|
|
@@ -149,13 +246,8 @@ const DEPENDENCY_FIELDS = [
|
|
|
149
246
|
"optionalDependencies",
|
|
150
247
|
"peerDependencies"
|
|
151
248
|
];
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
dependencies: Specifiers,
|
|
155
|
-
devDependencies: Specifiers,
|
|
156
|
-
optionalDependencies: Specifiers,
|
|
157
|
-
peerDependencies: Specifiers
|
|
158
|
-
});
|
|
249
|
+
const Manifest = Schema.Record(Schema.String, Schema.Unknown);
|
|
250
|
+
const decodeSpecifiers = Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.String));
|
|
159
251
|
const Workspace = Schema.Struct({ packages: Schema.optionalKey(Schema.Array(Schema.String)) });
|
|
160
252
|
const decodeManifest = Schema.decodeEffect(Schema.fromJsonString(Manifest));
|
|
161
253
|
const decodeWorkspace = Schema.decodeUnknownEffect(Workspace);
|
|
@@ -173,67 +265,168 @@ const listManifests = (root) => Effect.gen(function* list() {
|
|
|
173
265
|
const found = yield* listGitFiles(root, pipe(workspace.packages ?? [], Array.map(manifestPathspec)));
|
|
174
266
|
return ["package.json", ...Array.sort(found, String.Order)];
|
|
175
267
|
});
|
|
176
|
-
const dependenciesOf = (manifest) => (
|
|
268
|
+
const dependenciesOf = (manifest) => (fields) => pipe(DEPENDENCY_FIELDS, Effect.forEach((field) => decodeSpecifiers(fields[field] ?? {}).pipe(Effect.map((specifiers) => pipe(Record.toEntries(specifiers), Array.map(([name, specifier]) => ({
|
|
177
269
|
manifest,
|
|
178
270
|
field,
|
|
179
271
|
name,
|
|
180
272
|
specifier
|
|
181
|
-
})))));
|
|
273
|
+
})))))), Effect.map(Array.flatten));
|
|
182
274
|
const listDependencies = (root) => Effect.gen(function* list() {
|
|
183
275
|
const fs = yield* FileSystem.FileSystem;
|
|
184
276
|
const path = yield* Path.Path;
|
|
185
277
|
const manifests = yield* listManifests(root);
|
|
186
|
-
const parsed = yield* pipe(manifests, Effect.forEach((manifest) => fs.readFileString(path.join(root, manifest)).pipe(Effect.flatMap(decodeManifest), Effect.
|
|
278
|
+
const parsed = yield* pipe(manifests, Effect.forEach((manifest) => fs.readFileString(path.join(root, manifest)).pipe(Effect.flatMap(decodeManifest), Effect.flatMap(dependenciesOf(manifest)))));
|
|
187
279
|
return Array.flatten(parsed);
|
|
188
280
|
});
|
|
189
|
-
// src/repository-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
281
|
+
// src/repository-checks.ts
|
|
282
|
+
const ancestorsOf = (file) => pipe(String.split(file, "/"), Array.initNonEmpty, Array.scan("", (parent, segment) => Array.join(Array.filter([parent, segment], String.isNonEmpty), "/")), Array.filter(String.isNonEmpty));
|
|
283
|
+
const matchingDirectories = (root, patterns) => listGitFiles(root, []).pipe(Effect.map((files) => pipe(files, Array.flatMap(ancestorsOf), Array.dedupe, Array.filter((directory) => pipe(patterns, Array.some((pattern) => minimatch(directory, pattern)))))));
|
|
284
|
+
const steigerCheck = withSection("steiger", (section, { root }) => matchingDirectories(root, section.paths).pipe(Effect.flatMap((targets) => checkSlices(section.rules, root, targets))));
|
|
285
|
+
const dependenciesCheck = withSection("dependencyRules", (rules, { root }) => listDependencies(root).pipe(Effect.map((dependencies) => {
|
|
286
|
+
const problems = checkDependencies(rules, dependencies);
|
|
287
|
+
return {
|
|
194
288
|
valid: Array.isReadonlyArrayEmpty(problems),
|
|
195
289
|
output: Array.join(problems, "\n")
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
// src/commitlint.ts
|
|
199
|
-
const COMMENT_CHAR = "#";
|
|
200
|
-
const parserOptionsOf = (loaded) => {
|
|
201
|
-
return {
|
|
202
|
-
...pipe(Option.fromNullishOr(loaded.parserPreset), Option.map(({ parserOpts }) => parserOpts), Option.filter(Predicate.isObject), Option.getOrElse(() => ({}))),
|
|
203
|
-
commentChar: COMMENT_CHAR
|
|
204
290
|
};
|
|
291
|
+
})));
|
|
292
|
+
// src/betterleaks.ts
|
|
293
|
+
const toBetterleaksToml = (config) => {
|
|
294
|
+
const { ignoredSecrets: _ignoredSecrets, ...rest } = config;
|
|
295
|
+
return stringify(rest);
|
|
205
296
|
};
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
};
|
|
297
|
+
const toIgnoreFile = (config) => pipe(config.ignoredSecrets ?? [], Array.map((digest) => `${digest}\n`), Array.join(""));
|
|
298
|
+
// src/vendored.ts
|
|
299
|
+
const runVendored = Function.dual(2, (binary, invocation) => locateBinary(binary).pipe(Effect.flatMap((file) => runCaptured({
|
|
300
|
+
...invocation,
|
|
301
|
+
file
|
|
302
|
+
}))));
|
|
303
|
+
// src/secret-checks.ts
|
|
304
|
+
const DATA_FIRST_ARITY$1 = 2;
|
|
305
|
+
const ignoreFileArgs = (config) => Effect.gen(function* ignoreFile() {
|
|
306
|
+
const digests = toIgnoreFile(config);
|
|
307
|
+
if (digests === "") return [];
|
|
308
|
+
const fs = yield* FileSystem.FileSystem;
|
|
309
|
+
const file = yield* fs.makeTempFileScoped({ prefix: "betterleaksignore-" });
|
|
310
|
+
yield* fs.writeFileString(file, digests);
|
|
311
|
+
return ["--ignore-file", file];
|
|
219
312
|
});
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
return yield*
|
|
313
|
+
const scanSecrets = ({ config, root, args, input }) => Effect.gen(function* scan() {
|
|
314
|
+
const ignore = yield* ignoreFileArgs(config);
|
|
315
|
+
return yield* runVendored(BETTERLEAKS, {
|
|
316
|
+
root,
|
|
317
|
+
args: [
|
|
318
|
+
...args,
|
|
319
|
+
"--redact",
|
|
320
|
+
"--no-banner",
|
|
321
|
+
...ignore
|
|
322
|
+
],
|
|
323
|
+
env: { BETTERLEAKS_CONFIG_TOML: toBetterleaksToml(config) },
|
|
324
|
+
input
|
|
325
|
+
});
|
|
326
|
+
}).pipe(Effect.scoped);
|
|
327
|
+
const SUCCESS = 0;
|
|
328
|
+
const lacksHistory = (root) => Effect.gen(function* history() {
|
|
329
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
330
|
+
const shallow = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "--is-shallow-repository"], { cwd: root }));
|
|
331
|
+
const promisor = yield* spawner.exitCode(ChildProcess.make("git", [
|
|
332
|
+
"config",
|
|
333
|
+
"--get",
|
|
334
|
+
"remote.origin.promisor"
|
|
335
|
+
], { cwd: root }));
|
|
336
|
+
return String.trim(shallow) === "true" || promisor === SUCCESS;
|
|
223
337
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
338
|
+
const succeeded = (tool, run) => run.pipe(Effect.flatMap((code) => {
|
|
339
|
+
if (code === SUCCESS) return Effect.void;
|
|
340
|
+
return Effect.fail(toolFailed(tool)(`exit code ${code}`));
|
|
341
|
+
}));
|
|
342
|
+
const scanCommittedTree = (config, root) => Effect.gen(function* tree() {
|
|
343
|
+
const fs = yield* FileSystem.FileSystem;
|
|
344
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
345
|
+
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "vpa-betterleaks-" });
|
|
346
|
+
const archive = `${directory}.tar`;
|
|
347
|
+
yield* succeeded("git archive", spawner.exitCode(ChildProcess.make("git", [
|
|
348
|
+
"archive",
|
|
349
|
+
"--format=tar",
|
|
350
|
+
"-o",
|
|
351
|
+
archive,
|
|
352
|
+
"HEAD"
|
|
353
|
+
], { cwd: root })));
|
|
354
|
+
yield* succeeded("tar", spawner.exitCode(ChildProcess.make("tar", [
|
|
355
|
+
"-xf",
|
|
356
|
+
archive,
|
|
357
|
+
"-C",
|
|
358
|
+
directory
|
|
359
|
+
])));
|
|
360
|
+
yield* fs.remove(archive);
|
|
361
|
+
return yield* scanSecrets({
|
|
362
|
+
config,
|
|
363
|
+
root,
|
|
364
|
+
args: ["dir", directory]
|
|
365
|
+
});
|
|
366
|
+
}).pipe(Effect.scoped);
|
|
367
|
+
const betterleaksCheck = withSection("betterleaks", (config, { root, base }) => lacksHistory(root).pipe(Effect.flatMap((partial) => {
|
|
368
|
+
if (partial) return scanCommittedTree(config, root);
|
|
369
|
+
return scanSecrets({
|
|
370
|
+
config,
|
|
371
|
+
root,
|
|
372
|
+
args: [
|
|
373
|
+
"git",
|
|
374
|
+
".",
|
|
375
|
+
`--revision=${base}..HEAD`
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
})));
|
|
379
|
+
const STAGED_DIFF = [
|
|
380
|
+
"diff",
|
|
381
|
+
"--cached",
|
|
382
|
+
"--no-ext-diff",
|
|
383
|
+
"--no-textconv",
|
|
384
|
+
"--no-color",
|
|
385
|
+
"--src-prefix=a/",
|
|
386
|
+
"--dst-prefix=b/"
|
|
387
|
+
];
|
|
388
|
+
const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$1, (config, root) => Effect.gen(function* staged() {
|
|
389
|
+
const diff = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", STAGED_DIFF, { cwd: root }));
|
|
390
|
+
return yield* scanSecrets({
|
|
391
|
+
config,
|
|
392
|
+
root,
|
|
393
|
+
args: ["stdin", "--git-diff"],
|
|
394
|
+
input: diff
|
|
395
|
+
});
|
|
396
|
+
}));
|
|
397
|
+
// src/markdownlint.ts
|
|
398
|
+
const DATA_FIRST_ARITY_3$1 = 3;
|
|
399
|
+
const formatError = (file) => (error) => {
|
|
400
|
+
const detail = pipe([error.errorDetail, error.errorContext], Array.filter((part) => part !== null && part !== ""), Array.map((part) => ` [${part}]`), Array.join(""));
|
|
401
|
+
return `${file}:${error.lineNumber} ${Array.join(error.ruleNames, "/")} ${error.ruleDescription}${detail}`;
|
|
402
|
+
};
|
|
403
|
+
const optionsOf = (config, files) => ({
|
|
404
|
+
files: [...files],
|
|
405
|
+
...pipe(Option.fromNullishOr(config.config), Option.match({
|
|
406
|
+
onNone: () => ({}),
|
|
407
|
+
onSome: (rules) => ({ config: rules })
|
|
408
|
+
})),
|
|
409
|
+
...pipe(Option.fromNullishOr(config.customRules), Option.match({
|
|
410
|
+
onNone: () => ({}),
|
|
411
|
+
onSome: (rules) => ({ customRules: [...rules] })
|
|
412
|
+
}))
|
|
229
413
|
});
|
|
230
|
-
const
|
|
414
|
+
const lintMarkdown = Function.dual(DATA_FIRST_ARITY_3$1, (config, root, files) => Effect.gen(function* markdown() {
|
|
231
415
|
const path = yield* Path.Path;
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
416
|
+
const absolute = pipe(files, Array.map((file) => path.join(root, file)));
|
|
417
|
+
const results = yield* attempt("markdownlint")(() => lint$1(optionsOf(config, absolute)));
|
|
418
|
+
const linesOf = ([file, errors]) => {
|
|
419
|
+
const format = formatError(path.relative(root, file));
|
|
420
|
+
return pipe(errors, Array.map(format));
|
|
421
|
+
};
|
|
422
|
+
const lines = pipe(Record.toEntries(results), Array.flatMap(linesOf));
|
|
423
|
+
return {
|
|
424
|
+
valid: Array.isArrayEmpty(lines),
|
|
425
|
+
output: Array.join(lines, "\n")
|
|
426
|
+
};
|
|
427
|
+
}));
|
|
236
428
|
// src/textlint.ts
|
|
429
|
+
const DATA_FIRST_ARITY_3 = 3;
|
|
237
430
|
const descriptorOf = (loaded, root) => {
|
|
238
431
|
if (!loaded.ok) return Effect.fail(toolFailed("textlint")(loaded.error.message));
|
|
239
432
|
return Effect.succeed(new TextlintKernelDescriptor({
|
|
@@ -243,7 +436,7 @@ const descriptorOf = (loaded, root) => {
|
|
|
243
436
|
configBaseDir: root
|
|
244
437
|
}));
|
|
245
438
|
};
|
|
246
|
-
const lintTexts = (config, root, files) => Effect.gen(function* lint() {
|
|
439
|
+
const lintTexts = Function.dual(DATA_FIRST_ARITY_3, (config, root, files) => Effect.gen(function* lint() {
|
|
247
440
|
const path = yield* Path.Path;
|
|
248
441
|
const { ignores: _ignores, ...rawConfig } = config;
|
|
249
442
|
const loaded = yield* attempt("textlint")(() => loadPackagesFromRawConfig({
|
|
@@ -261,72 +454,143 @@ const lintTexts = (config, root, files) => Effect.gen(function* lint() {
|
|
|
261
454
|
valid: pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
|
|
262
455
|
output: formatter.format(results)
|
|
263
456
|
};
|
|
457
|
+
}));
|
|
458
|
+
// src/text-checks.ts
|
|
459
|
+
const MARKDOWN = "*.md";
|
|
460
|
+
const markdownFiles = (root, ignores = []) => listGitFiles(root, [MARKDOWN, ...pipe(ignores, Array.map((glob) => `:(glob,exclude)${glob}`))]);
|
|
461
|
+
const textlintCheck = withSection("textlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintTexts(config, root, files))));
|
|
462
|
+
const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
|
|
463
|
+
const commitlintCheck = withSection("commitlint", (config, { root, base }) => listCommitMessages(root, `${base}..HEAD`).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
|
|
464
|
+
// src/workflow-checks.ts
|
|
465
|
+
const WORKFLOWS = ".github/workflows";
|
|
466
|
+
const onWorkflows = (binary, args) => ({ root }) => Effect.gen(function* workflows() {
|
|
467
|
+
const fs = yield* FileSystem.FileSystem;
|
|
468
|
+
const path = yield* Path.Path;
|
|
469
|
+
if (!(yield* fs.exists(path.join(root, WORKFLOWS)))) return Option.none();
|
|
470
|
+
const resolvedArgs = yield* args;
|
|
471
|
+
const ran = yield* runVendored(binary, {
|
|
472
|
+
root,
|
|
473
|
+
args: resolvedArgs
|
|
474
|
+
});
|
|
475
|
+
return Option.some(ran);
|
|
264
476
|
});
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const config = yield* loadSection(root, "textlint");
|
|
273
|
-
const excluded = pipe(config.ignores ?? [], Array.map((glob) => `:(glob,exclude)${glob}`));
|
|
274
|
-
const pathspecs = pipe(args, Array.filter((arg) => arg !== PRINT_FILES));
|
|
275
|
-
const files = yield* listGitFiles(root, [...pathspecs, ...excluded]);
|
|
276
|
-
if (Array.contains(args, PRINT_FILES)) return yield* writeTo("stdout", pipe(files, Array.map((file) => `${file}\0`), Array.join("")));
|
|
277
|
-
return yield* finish(yield* lintTexts(config, root, files));
|
|
477
|
+
const actionlintCheck = onWorkflows(ACTIONLINT, Effect.succeed([]));
|
|
478
|
+
const zizmorArgs = Effect.gen(function* zizmorArgs() {
|
|
479
|
+
const remote = yield* Config.option(Config.String("CLAUDE_CODE_REMOTE")).pipe(Effect.orDie);
|
|
480
|
+
return pipe(remote, Option.match({
|
|
481
|
+
onNone: () => [".github"],
|
|
482
|
+
onSome: () => ["--no-online-audits", ".github"]
|
|
483
|
+
}));
|
|
278
484
|
});
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
485
|
+
const zizmorCheck = onWorkflows(ZIZMOR, zizmorArgs);
|
|
486
|
+
// src/checks.ts
|
|
487
|
+
const CHECKS = [
|
|
488
|
+
{
|
|
489
|
+
name: "betterleaks",
|
|
490
|
+
run: betterleaksCheck
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
name: "commitlint",
|
|
494
|
+
run: commitlintCheck
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
name: "actionlint",
|
|
498
|
+
run: actionlintCheck
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
name: "zizmor",
|
|
502
|
+
run: zizmorCheck
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
name: "dependencies",
|
|
506
|
+
run: dependenciesCheck
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
name: "steiger",
|
|
510
|
+
run: steigerCheck
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: "textlint",
|
|
514
|
+
run: textlintCheck
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: "markdownlint",
|
|
518
|
+
run: markdownlintCheck
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: "fallow",
|
|
522
|
+
run: fallowCheck
|
|
292
523
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
524
|
+
];
|
|
525
|
+
// src/run-checks.ts
|
|
526
|
+
const DEFAULT_BASE = "origin/main";
|
|
527
|
+
const RESOLVED = 0;
|
|
528
|
+
const isCommit = (root, revision) => Effect.gen(function* verify() {
|
|
529
|
+
return (yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("git", [
|
|
530
|
+
"rev-parse",
|
|
531
|
+
"-q",
|
|
532
|
+
"--verify",
|
|
533
|
+
`${revision}^{commit}`
|
|
534
|
+
], { cwd: root }))) === RESOLVED;
|
|
535
|
+
}).pipe(Effect.orElseSucceed(() => false));
|
|
536
|
+
const resolveBase = (root) => Effect.gen(function* base() {
|
|
537
|
+
const configured = yield* Config.option(Config.String("VPA_BASE")).pipe(Effect.orDie);
|
|
538
|
+
if (Option.isSome(configured) && (yield* isCommit(root, configured.value))) return configured.value;
|
|
539
|
+
return DEFAULT_BASE;
|
|
298
540
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
betterleaks: runBetterleaks,
|
|
303
|
-
commitlint: runCommitlint,
|
|
304
|
-
dependencies: runDependencies,
|
|
305
|
-
steiger: runSteiger,
|
|
306
|
-
textlint: runTextlint,
|
|
307
|
-
zizmor: runZizmor
|
|
541
|
+
const describe = ({ name, report }) => {
|
|
542
|
+
if (report.valid) return `✓ ${name}`;
|
|
543
|
+
return `✗ ${name}\n${report.output}`;
|
|
308
544
|
};
|
|
309
|
-
|
|
545
|
+
const runCheck = (context) => ({ name, run }) => run(context).pipe(Effect.map(Option.map((report) => ({
|
|
546
|
+
name,
|
|
547
|
+
report
|
|
548
|
+
}))));
|
|
549
|
+
const runAllChecks = (root) => Effect.gen(function* all() {
|
|
550
|
+
const config = yield* loadViteConfig(root);
|
|
551
|
+
const base = yield* resolveBase(root);
|
|
552
|
+
const outcomes = yield* pipe(CHECKS, Effect.forEach(runCheck({
|
|
553
|
+
root,
|
|
554
|
+
config,
|
|
555
|
+
base
|
|
556
|
+
}), { concurrency: "unbounded" }), Effect.map(Array.getSomes));
|
|
557
|
+
yield* writeTo("stdout", `${pipe(outcomes, Array.map(describe), Array.join("\n"))}\n`);
|
|
558
|
+
return yield* pipe(outcomes, Array.filter(({ report }) => !report.valid), Array.map(({ name }) => name), Array.match({
|
|
559
|
+
onEmpty: () => Effect.void,
|
|
560
|
+
onNonEmpty: (failed) => Effect.fail(checksFailed(`Failed: ${Array.join(failed, ", ")}`))
|
|
561
|
+
}));
|
|
562
|
+
});
|
|
563
|
+
// src/vpa.ts
|
|
564
|
+
const DATA_FIRST_ARITY = 2;
|
|
310
565
|
const USAGE = pipe([
|
|
311
|
-
"Usage: vpa
|
|
312
|
-
"
|
|
313
|
-
"
|
|
314
|
-
" commitlint <message-file> | --range <revision-range>",
|
|
315
|
-
" dependencies",
|
|
316
|
-
" steiger <dir...>",
|
|
317
|
-
" textlint [--print-files] <pathspec...>",
|
|
318
|
-
" zizmor [zizmor arguments...]"
|
|
566
|
+
"Usage: vpa run every check configured in vite.config.ts",
|
|
567
|
+
" vpa --staged scan the staged changes for secrets (pre-commit)",
|
|
568
|
+
" vpa --commit-msg <file> lint a commit message (commit-msg)"
|
|
319
569
|
], Array.join("\n"));
|
|
320
|
-
const
|
|
570
|
+
const usage = Effect.fail(checksFailed(USAGE));
|
|
571
|
+
const stagedSecrets = (root) => loadSection(root, "betterleaks").pipe(Effect.flatMap((config) => scanStagedSecrets(config, root)), Effect.flatMap(finish));
|
|
572
|
+
const commitMessage = (root, rest) => pipe(Array.head(rest), Option.match({
|
|
573
|
+
onNone: () => usage,
|
|
574
|
+
onSome: (file) => loadSection(root, "commitlint").pipe(Effect.flatMap((config) => lintCommitMessageFile(config, root, file)), Effect.flatMap(finish))
|
|
575
|
+
}));
|
|
576
|
+
const HOOKS = {
|
|
577
|
+
"--staged": stagedSecrets,
|
|
578
|
+
"--commit-msg": commitMessage
|
|
579
|
+
};
|
|
580
|
+
const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.match({
|
|
581
|
+
onEmpty: () => runAllChecks(root),
|
|
582
|
+
onNonEmpty: ([flag, ...rest]) => pipe(Record.get(HOOKS, flag), Option.match({
|
|
583
|
+
onNone: () => usage,
|
|
584
|
+
onSome: (hook) => hook(root, rest)
|
|
585
|
+
}))
|
|
586
|
+
})));
|
|
587
|
+
// src/cli.ts
|
|
588
|
+
runCli(Effect.gen(function* main() {
|
|
321
589
|
const stdio = yield* Stdio.Stdio;
|
|
322
590
|
const path = yield* Path.Path;
|
|
323
|
-
const
|
|
324
|
-
return yield*
|
|
325
|
-
|
|
326
|
-
onSome: (command) => command(path.resolve("."), rest)
|
|
327
|
-
}));
|
|
328
|
-
});
|
|
329
|
-
runCli(vpTools);
|
|
591
|
+
const args = yield* stdio.args;
|
|
592
|
+
return yield* runVpa(path.resolve("."), args);
|
|
593
|
+
}));
|
|
330
594
|
export {};
|
|
331
595
|
|
|
332
596
|
//# sourceMappingURL=cli.mjs.map
|