@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/dist/cli.mjs CHANGED
@@ -1,73 +1,156 @@
1
1
  #!/usr/bin/env node
2
- import { a as locateBinary, c as ZIZMOR, n as finish, o as ACTIONLINT, r as writeTo, s as BETTERLEAKS, t as runCli } from "./run-cli-DspfTYgh.mjs";
3
- import { t as loadSection } from "./config-C8pUNPt5.mjs";
4
- import { a as toolFailed, r as checksFailed, t as attempt } from "./attempt-5nU57gc3.mjs";
5
- import { Array, Effect, FileSystem, Option, Path, Predicate, Record, Schema, Stdio, String, pipe } from "effect";
6
- import { stringify } from "smol-toml";
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/betterleaks.ts
20
- const toBetterleaksToml = (config) => {
21
- const { ignoredSecrets: _ignoredSecrets, ...rest } = config;
22
- return stringify(rest);
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 toIgnoreFile = (config) => pipe(config.ignoredSecrets ?? [], Array.map((digest) => `${digest}\n`), Array.join(""));
25
- // src/binary-commands.ts
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 runVendored = ({ root, binary, args, env = {} }) => Effect.gen(function* run() {
28
- const file = yield* locateBinary(binary);
29
- const exitCode = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(file, args, {
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: "inherit",
34
- stdout: "inherit",
35
- stderr: "inherit"
59
+ stdin: stdinOf(input)
36
60
  }));
37
- return yield* finish({
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 passThrough = (binary) => (root, args) => runVendored({
103
+ const decodeSmells = Schema.decodeUnknownEffect(Schema.fromJsonString(COMPONENT_SMELLS));
104
+ const componentSmells = (root, configFile) => runCaptured({
43
105
  root,
44
- binary,
45
- args
46
- });
47
- const runActionlint = passThrough(ACTIONLINT);
48
- const runZizmor = passThrough(ZIZMOR);
49
- // src/betterleaks-command.ts
50
- const BETTERLEAKS_USAGE = "Usage: vpa betterleaks <betterleaks arguments...>";
51
- const ignoreFileArgs = (config) => Effect.gen(function* ignoreFile() {
52
- const digests = toIgnoreFile(config);
53
- if (digests === "") return [];
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 file = yield* fs.makeTempFileScoped({ prefix: "betterleaksignore-" });
56
- yield* fs.writeFileString(file, digests);
57
- return ["--ignore-file", file];
58
- });
59
- const runBetterleaks = (root, args) => Effect.gen(function* betterleaks() {
60
- const config = yield* loadSection(root, "betterleaks");
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
- binary: BETTERLEAKS,
66
- args: [...args, ...ignore],
67
- env: { BETTERLEAKS_CONFIG_TOML: toBetterleaksToml(config) }
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 listGitFiles = (root, pathspecs) => Effect.gen(function* list() {
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 Specifiers = Schema.optionalKey(Schema.Record(Schema.String, Schema.String));
153
- const Manifest = Schema.Struct({
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) => (specifiers) => pipe(DEPENDENCY_FIELDS, Array.flatMap((field) => pipe(Record.toEntries(specifiers[field] ?? {}), Array.map(([name, specifier]) => ({
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.map(dependenciesOf(manifest)))));
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-commands.ts
190
- const runDependencies = (root) => Effect.gen(function* dependencies() {
191
- const rules = yield* loadSection(root, "dependencyRules");
192
- const problems = checkDependencies(rules, yield* listDependencies(root));
193
- return yield* finish({
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 lintOptionsOf = (loaded) => ({
207
- parserOpts: parserOptionsOf(loaded),
208
- plugins: loaded.plugins,
209
- ignores: loaded.ignores ?? [],
210
- defaultIgnores: loaded.defaultIgnores ?? true
211
- });
212
- const lintCommitMessages = (config, root, messages) => Effect.gen(function* lintMessages() {
213
- const loaded = yield* attempt("commitlint")(() => load(config, { cwd: root }));
214
- const results = yield* pipe(messages, Effect.forEach((message) => attempt("commitlint")(() => lint(message, loaded.rules, lintOptionsOf(loaded)))));
215
- return {
216
- valid: pipe(results, Array.every((result) => result.valid)),
217
- output: format({ results }, { color: false })
218
- };
219
- });
220
- const lintCommitMessageFile = (config, root, messageFile) => Effect.gen(function* read() {
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
- // src/steiger.ts
225
- const formatDiagnostic = (relative) => (diagnostic) => `${diagnostic.severity} ${relative(diagnostic.location.path)}: ${diagnostic.message} (${diagnostic.ruleName})`;
226
- const reportOf = (diagnostics, relative) => ({
227
- valid: pipe(diagnostics, Array.every((diagnostic) => diagnostic.severity !== "error")),
228
- output: pipe(diagnostics, Array.map(formatDiagnostic(relative)), Array.join("\n"))
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 checkSlices = (config, root, targets) => Effect.gen(function* check() {
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
- processConfiguration([...config], root);
233
- const perTarget = yield* pipe(targets, Effect.forEach((target) => attempt("steiger")(() => linter.run(path.resolve(root, target)))));
234
- return reportOf(Array.flatten(perTarget), (file) => path.relative(root, file));
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
- // src/text-commands.ts
266
- const PRINT_FILES = "--print-files";
267
- const RANGE = "--range";
268
- const RANGE_ARGS = 2;
269
- const FILE_ARGS = 1;
270
- const COMMITLINT_USAGE = "Usage: vpa commitlint <commit message file> | vpa commitlint --range <revision range>";
271
- const runTextlint = (root, args) => Effect.gen(function* textlint() {
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 startsWithRange = (args) => pipe(Array.head(args), Option.exists((arg) => arg === RANGE));
280
- const isRangeArgs = (args) => args.length === RANGE_ARGS && startsWithRange(args);
281
- const isFileArgs = (args) => args.length === FILE_ARGS && !startsWithRange(args);
282
- const runCommitlint = (root, args) => Effect.gen(function* commitlint() {
283
- const config = yield* loadSection(root, "commitlint");
284
- if (isRangeArgs(args)) {
285
- const [, range] = args;
286
- const messages = yield* listCommitMessages(root, range);
287
- return yield* finish(yield* lintCommitMessages(config, root, messages));
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
- if (isFileArgs(args)) {
290
- const [messageFile] = args;
291
- return yield* finish(yield* lintCommitMessageFile(config, root, messageFile));
292
- }
293
- return yield* Effect.fail(checksFailed(COMMITLINT_USAGE));
294
- });
295
- const runSteiger = (root, targets) => Effect.gen(function* steiger() {
296
- const config = yield* loadSection(root, "steiger");
297
- return yield* finish(yield* checkSlices(config, root, targets));
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
- // src/commands.ts
300
- const COMMANDS = {
301
- actionlint: runActionlint,
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
- // src/cli.ts
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 <command> [args]",
312
- " actionlint [actionlint arguments...]",
313
- " betterleaks <betterleaks arguments...>",
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 vpTools = Effect.gen(function* main() {
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 [name = "", ...rest] = yield* stdio.args;
324
- return yield* pipe(Record.get(COMMANDS, name), Option.match({
325
- onNone: () => Effect.fail(checksFailed(USAGE)),
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