@r_masseater/vite-plus-adopt 0.2.0 → 0.3.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 +68 -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 +385 -164
- 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
|
-
|
|
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
|
|
26
49
|
const SUCCESS = 0;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
61
|
+
const [text, exitCode] = yield* Effect.all([handle[output].pipe(Stream.decodeText, Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
|
|
62
|
+
return {
|
|
38
63
|
valid: exitCode === SUCCESS,
|
|
39
|
-
output:
|
|
40
|
-
}
|
|
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,125 @@ 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
|
-
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const message = yield* (yield* FileSystem.FileSystem).readFileString(messageFile);
|
|
222
|
-
return yield* lintCommitMessages(config, root, [message]);
|
|
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];
|
|
223
312
|
});
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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 betterleaksCheck = withSection("betterleaks", (config, { root, base }) => scanSecrets({
|
|
328
|
+
config,
|
|
329
|
+
root,
|
|
330
|
+
args: [
|
|
331
|
+
"git",
|
|
332
|
+
".",
|
|
333
|
+
`--revision=${base}..HEAD`
|
|
334
|
+
]
|
|
335
|
+
}));
|
|
336
|
+
const STAGED_DIFF = [
|
|
337
|
+
"diff",
|
|
338
|
+
"--cached",
|
|
339
|
+
"--no-ext-diff",
|
|
340
|
+
"--no-textconv",
|
|
341
|
+
"--no-color",
|
|
342
|
+
"--src-prefix=a/",
|
|
343
|
+
"--dst-prefix=b/"
|
|
344
|
+
];
|
|
345
|
+
const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$1, (config, root) => Effect.gen(function* staged() {
|
|
346
|
+
const diff = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", STAGED_DIFF, { cwd: root }));
|
|
347
|
+
return yield* scanSecrets({
|
|
348
|
+
config,
|
|
349
|
+
root,
|
|
350
|
+
args: ["stdin", "--git-diff"],
|
|
351
|
+
input: diff
|
|
352
|
+
});
|
|
353
|
+
}));
|
|
354
|
+
// src/markdownlint.ts
|
|
355
|
+
const DATA_FIRST_ARITY_3$1 = 3;
|
|
356
|
+
const formatError = (file) => (error) => {
|
|
357
|
+
const detail = pipe([error.errorDetail, error.errorContext], Array.filter((part) => part !== null && part !== ""), Array.map((part) => ` [${part}]`), Array.join(""));
|
|
358
|
+
return `${file}:${error.lineNumber} ${Array.join(error.ruleNames, "/")} ${error.ruleDescription}${detail}`;
|
|
359
|
+
};
|
|
360
|
+
const optionsOf = (config, files) => ({
|
|
361
|
+
files: [...files],
|
|
362
|
+
...pipe(Option.fromNullishOr(config.config), Option.match({
|
|
363
|
+
onNone: () => ({}),
|
|
364
|
+
onSome: (rules) => ({ config: rules })
|
|
365
|
+
})),
|
|
366
|
+
...pipe(Option.fromNullishOr(config.customRules), Option.match({
|
|
367
|
+
onNone: () => ({}),
|
|
368
|
+
onSome: (rules) => ({ customRules: [...rules] })
|
|
369
|
+
}))
|
|
229
370
|
});
|
|
230
|
-
const
|
|
371
|
+
const lintMarkdown = Function.dual(DATA_FIRST_ARITY_3$1, (config, root, files) => Effect.gen(function* markdown() {
|
|
231
372
|
const path = yield* Path.Path;
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
373
|
+
const absolute = pipe(files, Array.map((file) => path.join(root, file)));
|
|
374
|
+
const results = yield* attempt("markdownlint")(() => lint$1(optionsOf(config, absolute)));
|
|
375
|
+
const linesOf = ([file, errors]) => {
|
|
376
|
+
const format = formatError(path.relative(root, file));
|
|
377
|
+
return pipe(errors, Array.map(format));
|
|
378
|
+
};
|
|
379
|
+
const lines = pipe(Record.toEntries(results), Array.flatMap(linesOf));
|
|
380
|
+
return {
|
|
381
|
+
valid: Array.isArrayEmpty(lines),
|
|
382
|
+
output: Array.join(lines, "\n")
|
|
383
|
+
};
|
|
384
|
+
}));
|
|
236
385
|
// src/textlint.ts
|
|
386
|
+
const DATA_FIRST_ARITY_3 = 3;
|
|
237
387
|
const descriptorOf = (loaded, root) => {
|
|
238
388
|
if (!loaded.ok) return Effect.fail(toolFailed("textlint")(loaded.error.message));
|
|
239
389
|
return Effect.succeed(new TextlintKernelDescriptor({
|
|
@@ -243,7 +393,7 @@ const descriptorOf = (loaded, root) => {
|
|
|
243
393
|
configBaseDir: root
|
|
244
394
|
}));
|
|
245
395
|
};
|
|
246
|
-
const lintTexts = (config, root, files) => Effect.gen(function* lint() {
|
|
396
|
+
const lintTexts = Function.dual(DATA_FIRST_ARITY_3, (config, root, files) => Effect.gen(function* lint() {
|
|
247
397
|
const path = yield* Path.Path;
|
|
248
398
|
const { ignores: _ignores, ...rawConfig } = config;
|
|
249
399
|
const loaded = yield* attempt("textlint")(() => loadPackagesFromRawConfig({
|
|
@@ -261,72 +411,143 @@ const lintTexts = (config, root, files) => Effect.gen(function* lint() {
|
|
|
261
411
|
valid: pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
|
|
262
412
|
output: formatter.format(results)
|
|
263
413
|
};
|
|
414
|
+
}));
|
|
415
|
+
// src/text-checks.ts
|
|
416
|
+
const MARKDOWN = "*.md";
|
|
417
|
+
const markdownFiles = (root, ignores = []) => listGitFiles(root, [MARKDOWN, ...pipe(ignores, Array.map((glob) => `:(glob,exclude)${glob}`))]);
|
|
418
|
+
const textlintCheck = withSection("textlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintTexts(config, root, files))));
|
|
419
|
+
const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
|
|
420
|
+
const commitlintCheck = withSection("commitlint", (config, { root, base }) => listCommitMessages(root, `${base}..HEAD`).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
|
|
421
|
+
// src/workflow-checks.ts
|
|
422
|
+
const WORKFLOWS = ".github/workflows";
|
|
423
|
+
const onWorkflows = (binary, args) => ({ root }) => Effect.gen(function* workflows() {
|
|
424
|
+
const fs = yield* FileSystem.FileSystem;
|
|
425
|
+
const path = yield* Path.Path;
|
|
426
|
+
if (!(yield* fs.exists(path.join(root, WORKFLOWS)))) return Option.none();
|
|
427
|
+
const resolvedArgs = yield* args;
|
|
428
|
+
const ran = yield* runVendored(binary, {
|
|
429
|
+
root,
|
|
430
|
+
args: resolvedArgs
|
|
431
|
+
});
|
|
432
|
+
return Option.some(ran);
|
|
264
433
|
});
|
|
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));
|
|
434
|
+
const actionlintCheck = onWorkflows(ACTIONLINT, Effect.succeed([]));
|
|
435
|
+
const zizmorArgs = Effect.gen(function* zizmorArgs() {
|
|
436
|
+
const remote = yield* Config.option(Config.String("CLAUDE_CODE_REMOTE")).pipe(Effect.orDie);
|
|
437
|
+
return pipe(remote, Option.match({
|
|
438
|
+
onNone: () => [".github"],
|
|
439
|
+
onSome: () => ["--no-online-audits", ".github"]
|
|
440
|
+
}));
|
|
278
441
|
});
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
442
|
+
const zizmorCheck = onWorkflows(ZIZMOR, zizmorArgs);
|
|
443
|
+
// src/checks.ts
|
|
444
|
+
const CHECKS = [
|
|
445
|
+
{
|
|
446
|
+
name: "betterleaks",
|
|
447
|
+
run: betterleaksCheck
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
name: "commitlint",
|
|
451
|
+
run: commitlintCheck
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
name: "actionlint",
|
|
455
|
+
run: actionlintCheck
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: "zizmor",
|
|
459
|
+
run: zizmorCheck
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: "dependencies",
|
|
463
|
+
run: dependenciesCheck
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
name: "steiger",
|
|
467
|
+
run: steigerCheck
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: "textlint",
|
|
471
|
+
run: textlintCheck
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
name: "markdownlint",
|
|
475
|
+
run: markdownlintCheck
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
name: "fallow",
|
|
479
|
+
run: fallowCheck
|
|
288
480
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
481
|
+
];
|
|
482
|
+
// src/run-checks.ts
|
|
483
|
+
const DEFAULT_BASE = "origin/main";
|
|
484
|
+
const RESOLVED = 0;
|
|
485
|
+
const isCommit = (root, revision) => Effect.gen(function* verify() {
|
|
486
|
+
return (yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("git", [
|
|
487
|
+
"rev-parse",
|
|
488
|
+
"-q",
|
|
489
|
+
"--verify",
|
|
490
|
+
`${revision}^{commit}`
|
|
491
|
+
], { cwd: root }))) === RESOLVED;
|
|
492
|
+
}).pipe(Effect.orElseSucceed(() => false));
|
|
493
|
+
const resolveBase = (root) => Effect.gen(function* base() {
|
|
494
|
+
const configured = yield* Config.option(Config.String("VPA_BASE")).pipe(Effect.orDie);
|
|
495
|
+
if (Option.isSome(configured) && (yield* isCommit(root, configured.value))) return configured.value;
|
|
496
|
+
return DEFAULT_BASE;
|
|
298
497
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
betterleaks: runBetterleaks,
|
|
303
|
-
commitlint: runCommitlint,
|
|
304
|
-
dependencies: runDependencies,
|
|
305
|
-
steiger: runSteiger,
|
|
306
|
-
textlint: runTextlint,
|
|
307
|
-
zizmor: runZizmor
|
|
498
|
+
const describe = ({ name, report }) => {
|
|
499
|
+
if (report.valid) return `✓ ${name}`;
|
|
500
|
+
return `✗ ${name}\n${report.output}`;
|
|
308
501
|
};
|
|
309
|
-
|
|
502
|
+
const runCheck = (context) => ({ name, run }) => run(context).pipe(Effect.map(Option.map((report) => ({
|
|
503
|
+
name,
|
|
504
|
+
report
|
|
505
|
+
}))));
|
|
506
|
+
const runAllChecks = (root) => Effect.gen(function* all() {
|
|
507
|
+
const config = yield* loadViteConfig(root);
|
|
508
|
+
const base = yield* resolveBase(root);
|
|
509
|
+
const outcomes = yield* pipe(CHECKS, Effect.forEach(runCheck({
|
|
510
|
+
root,
|
|
511
|
+
config,
|
|
512
|
+
base
|
|
513
|
+
}), { concurrency: "unbounded" }), Effect.map(Array.getSomes));
|
|
514
|
+
yield* writeTo("stdout", `${pipe(outcomes, Array.map(describe), Array.join("\n"))}\n`);
|
|
515
|
+
return yield* pipe(outcomes, Array.filter(({ report }) => !report.valid), Array.map(({ name }) => name), Array.match({
|
|
516
|
+
onEmpty: () => Effect.void,
|
|
517
|
+
onNonEmpty: (failed) => Effect.fail(checksFailed(`Failed: ${Array.join(failed, ", ")}`))
|
|
518
|
+
}));
|
|
519
|
+
});
|
|
520
|
+
// src/vpa.ts
|
|
521
|
+
const DATA_FIRST_ARITY = 2;
|
|
310
522
|
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...]"
|
|
523
|
+
"Usage: vpa run every check configured in vite.config.ts",
|
|
524
|
+
" vpa --staged scan the staged changes for secrets (pre-commit)",
|
|
525
|
+
" vpa --commit-msg <file> lint a commit message (commit-msg)"
|
|
319
526
|
], Array.join("\n"));
|
|
320
|
-
const
|
|
527
|
+
const usage = Effect.fail(checksFailed(USAGE));
|
|
528
|
+
const stagedSecrets = (root) => loadSection(root, "betterleaks").pipe(Effect.flatMap((config) => scanStagedSecrets(config, root)), Effect.flatMap(finish));
|
|
529
|
+
const commitMessage = (root, rest) => pipe(Array.head(rest), Option.match({
|
|
530
|
+
onNone: () => usage,
|
|
531
|
+
onSome: (file) => loadSection(root, "commitlint").pipe(Effect.flatMap((config) => lintCommitMessageFile(config, root, file)), Effect.flatMap(finish))
|
|
532
|
+
}));
|
|
533
|
+
const HOOKS = {
|
|
534
|
+
"--staged": stagedSecrets,
|
|
535
|
+
"--commit-msg": commitMessage
|
|
536
|
+
};
|
|
537
|
+
const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.match({
|
|
538
|
+
onEmpty: () => runAllChecks(root),
|
|
539
|
+
onNonEmpty: ([flag, ...rest]) => pipe(Record.get(HOOKS, flag), Option.match({
|
|
540
|
+
onNone: () => usage,
|
|
541
|
+
onSome: (hook) => hook(root, rest)
|
|
542
|
+
}))
|
|
543
|
+
})));
|
|
544
|
+
// src/cli.ts
|
|
545
|
+
runCli(Effect.gen(function* main() {
|
|
321
546
|
const stdio = yield* Stdio.Stdio;
|
|
322
547
|
const path = yield* Path.Path;
|
|
323
|
-
const
|
|
324
|
-
return yield*
|
|
325
|
-
|
|
326
|
-
onSome: (command) => command(path.resolve("."), rest)
|
|
327
|
-
}));
|
|
328
|
-
});
|
|
329
|
-
runCli(vpTools);
|
|
548
|
+
const args = yield* stdio.args;
|
|
549
|
+
return yield* runVpa(path.resolve("."), args);
|
|
550
|
+
}));
|
|
330
551
|
export {};
|
|
331
552
|
|
|
332
553
|
//# sourceMappingURL=cli.mjs.map
|