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