@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/dist/cli.mjs CHANGED
@@ -1,590 +1,7 @@
1
1
  #!/usr/bin/env node
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-C-6lZ_z7.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";
7
- import format from "@commitlint/format";
8
- import lint from "@commitlint/lint";
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";
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";
17
- import { loadPackagesFromRawConfig } from "@textlint/config-loader";
18
- import { TextlintKernelDescriptor } from "@textlint/kernel";
19
- import { createLinter, loadLinterFormatter } from "textlint";
20
- import { builtInPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
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
- };
29
- };
30
- const lintOptionsOf = (loaded) => ({
31
- parserOpts: parserOptionsOf(loaded),
32
- plugins: loaded.plugins,
33
- ignores: loaded.ignores ?? [],
34
- defaultIgnores: loaded.defaultIgnores ?? true
35
- });
36
- const lintCommitMessages = Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messages) => Effect.gen(function* lintMessages() {
37
- const loaded = yield* attempt("commitlint")(() => load(config, { cwd: root }));
38
- const results = yield* pipe(messages, Effect.forEach((message) => attempt("commitlint")(() => lint(message, loaded.rules, lintOptionsOf(loaded)))));
39
- return {
40
- valid: pipe(results, Array.every((result) => result.valid)),
41
- output: format({ results }, { color: false })
42
- };
43
- }));
44
- const lintCommitMessageFile = Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messageFile) => Effect.gen(function* read() {
45
- const message = yield* (yield* FileSystem.FileSystem).readFileString(messageFile);
46
- return yield* lintCommitMessages(config, root, [message]);
47
- }));
48
- // src/process.ts
49
- const SUCCESS$1 = 0;
50
- const stdinOf = (input) => pipe(Option.fromNullishOr(input), Option.match({
51
- onNone: () => "ignore",
52
- onSome: (text) => Stream.make(new TextEncoder().encode(text))
53
- }));
54
- const runCaptured = ({ root, file, args, env = {}, input, output = "all" }) => Effect.gen(function* run() {
55
- const handle = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(ChildProcess.make(file, args, {
56
- cwd: root,
57
- env,
58
- extendEnv: true,
59
- stdin: stdinOf(input)
60
- }));
61
- const [text, exitCode] = yield* Effect.all([handle[output].pipe(Stream.decodeText, Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
62
- return {
63
- valid: exitCode === SUCCESS$1,
64
- output: text
65
- };
66
- }).pipe(Effect.scoped);
67
- // src/section-check.ts
68
- const withSection = Function.dual(2, (key, run) => (context) => pipe(Option.fromNullishOr(context.config[key]), Option.match({
69
- onNone: () => Effect.succeedNone,
70
- onSome: (section) => Effect.asSome(run(section, context))
71
- })));
72
- // src/fallow-check.ts
73
- const QUIET = [
74
- "--fail-on-issues",
75
- "--quiet",
76
- "--format",
77
- "compact"
78
- ];
79
- const RUNS = [
80
- [
81
- "--skip",
82
- "dupes",
83
- ...QUIET
84
- ],
85
- [
86
- "dead-code",
87
- "--no-production",
88
- ...QUIET
89
- ],
90
- ["dupes", ...QUIET],
91
- [
92
- "security",
93
- "--fail-on-issues",
94
- "--quiet"
95
- ]
96
- ];
97
- const SMELLS = Schema.Array(Schema.Unknown).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])));
98
- const COMPONENT_SMELLS = Schema.Struct({
99
- prop_drilling_chains: SMELLS,
100
- thin_wrappers: SMELLS,
101
- duplicate_prop_shapes: SMELLS
102
- });
103
- const decodeSmells = Schema.decodeUnknownEffect(Schema.fromJsonString(COMPONENT_SMELLS));
104
- const componentSmells = (root, configFile) => runCaptured({
105
- root,
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() {
129
- const fs = yield* FileSystem.FileSystem;
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({
136
- root,
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
- };
150
- }).pipe(Effect.scoped);
151
- const fallowCheck = withSection("fallow", (config, { root }) => runFallow(config, root));
152
- // src/dependency-rules.ts
153
- const DATA_FIRST_ARITY$3 = 2;
154
- const SINGLE = 1;
155
- const bannedBy = (dependencies) => ([reason, globs]) => {
156
- const isBanned = (name) => pipe(globs, Array.some((glob) => minimatch(name, glob)));
157
- return pipe(dependencies, Array.filter((dependency) => isBanned(dependency.name)), Array.map((dependency) => `${dependency.manifest} ${dependency.field}.${dependency.name} is banned: ${reason}`));
158
- };
159
- const MANIFEST = "package.json";
160
- const matchesAny = (globs) => (value) => pipe(globs, Array.some((glob) => minimatch(value, glob)));
161
- const inWorkspace = (globs) => (dependency) => pipe(globs, Array.some((glob) => minimatch(dependency.manifest, `${glob}/${MANIFEST}`)));
162
- const inFields = (fields) => (dependency) => pipe(Option.fromNullishOr(fields), Option.match({
163
- onNone: () => true,
164
- onSome: (names) => Array.contains(names, dependency.field)
165
- }));
166
- const allowedBy = (dependency) => ({ workspaces, dependencies, fields }) => inWorkspace(workspaces)(dependency) && matchesAny(dependencies)(dependency.name) && inFields(fields)(dependency);
167
- const isAllowed = (rules) => (dependency) => pipe(Record.values(rules.allowed ?? {}), Array.some(allowedBy(dependency)));
168
- const bannedProblems = (rules, dependencies) => {
169
- const allowed = isAllowed(rules);
170
- const checked = pipe(dependencies, Array.filter(Predicate.not(allowed)));
171
- return pipe(Record.toEntries(rules.banned ?? {}), Array.flatMap(bannedBy(checked)));
172
- };
173
- const inWorkspaces = (globs) => (dependency) => dependency.field === "dependencies" && inWorkspace(globs)(dependency);
174
- const exactGlobs = (rules) => pipe(Record.values(rules.exactDependencies ?? {}), Array.flatten);
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}`));
176
- const exactProblems = (rules, dependencies) => pipe(Record.toEntries(rules.exactDependencies ?? {}), Array.flatMap(notExactBy(dependencies)));
177
- const groupByName = (dependencies) => Record.values(Array.groupBy(dependencies, ({ name }) => name));
178
- const describe$1 = (dependencies) => {
179
- return `${pipe(Array.head(dependencies), Option.match({
180
- onNone: () => "",
181
- onSome: (dependency) => dependency.name
182
- }))}: ${pipe(dependencies, Array.map((dependency) => `${dependency.manifest} ${dependency.field} ${dependency.specifier}`), Array.join(", "))}`;
183
- };
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)}`));
185
- const isDisjoint = (ranges) => pipe(ranges, Array.some((left) => pipe(ranges, Array.some((right) => !intersects(left.specifier, right.specifier)))));
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)}`));
187
- const isPeer = ({ field }) => field === "peerDependencies";
188
- const versionProblems = (rules, pinned) => {
189
- if (rules.peerRanges !== "intersect") return mismatchProblems(pinned);
190
- const others = pipe(pinned, Array.filter(Predicate.not(isPeer)));
191
- const peers = pipe(pinned, Array.filter(isPeer));
192
- return [...mismatchProblems(others), ...disjointRangeProblems(peers)];
193
- };
194
- const comparedDependencies = (rules, dependencies) => {
195
- const isExact = inWorkspaces(exactGlobs(rules));
196
- return pipe(dependencies, Array.filter(({ specifier }) => !String.startsWith("workspace:")(specifier)), Array.filter(Predicate.not(isExact)));
197
- };
198
- const checkDependencies = Function.dual(DATA_FIRST_ARITY$3, (rules, dependencies) => [
199
- ...bannedProblems(rules, dependencies),
200
- ...exactProblems(rules, dependencies),
201
- ...versionProblems(rules, comparedDependencies(rules, dependencies))
202
- ]);
203
- // src/git.ts
204
- const DATA_FIRST_ARITY$2 = 2;
205
- const listGitFiles = Function.dual(DATA_FIRST_ARITY$2, (root, pathspecs) => Effect.gen(function* list() {
206
- const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
207
- "-c",
208
- "core.quotePath=false",
209
- "ls-files",
210
- "-co",
211
- "--exclude-standard",
212
- "-z",
213
- "--",
214
- ...pathspecs
215
- ], { cwd: root }));
216
- return pipe(String.split(output, "\0"), Array.filter(String.isNonEmpty));
217
- }));
218
- const listCommitMessages = Function.dual(DATA_FIRST_ARITY$2, (root, range) => Effect.gen(function* messages() {
219
- const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
220
- "log",
221
- "-z",
222
- "--first-parent",
223
- "--format=%B",
224
- range,
225
- "--"
226
- ], { cwd: root }));
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"))
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
- }));
242
- // src/workspace.ts
243
- const DEPENDENCY_FIELDS = [
244
- "dependencies",
245
- "devDependencies",
246
- "optionalDependencies",
247
- "peerDependencies"
248
- ];
249
- const Manifest = Schema.Record(Schema.String, Schema.Unknown);
250
- const decodeSpecifiers = Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.String));
251
- const Workspace = Schema.Struct({ packages: Schema.optionalKey(Schema.Array(Schema.String)) });
252
- const decodeManifest = Schema.decodeEffect(Schema.fromJsonString(Manifest));
253
- const decodeWorkspace = Schema.decodeUnknownEffect(Workspace);
254
- const NEGATION = "!";
255
- const manifestPathspec = (pattern) => {
256
- if (String.startsWith(NEGATION)(pattern)) return `:(glob,exclude)${String.slice(1)(pattern)}/package.json`;
257
- return `:(glob)${pattern}/package.json`;
258
- };
259
- const listManifests = (root) => Effect.gen(function* list() {
260
- const fs = yield* FileSystem.FileSystem;
261
- const path = yield* Path.Path;
262
- const text = yield* fs.readFileString(path.join(root, "pnpm-workspace.yaml"));
263
- const raw = parse(text);
264
- const workspace = yield* decodeWorkspace(raw);
265
- const found = yield* listGitFiles(root, pipe(workspace.packages ?? [], Array.map(manifestPathspec)));
266
- return ["package.json", ...Array.sort(found, String.Order)];
267
- });
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]) => ({
269
- manifest,
270
- field,
271
- name,
272
- specifier
273
- })))))), Effect.map(Array.flatten));
274
- const listDependencies = (root) => Effect.gen(function* list() {
275
- const fs = yield* FileSystem.FileSystem;
276
- const path = yield* Path.Path;
277
- const manifests = yield* listManifests(root);
278
- const parsed = yield* pipe(manifests, Effect.forEach((manifest) => fs.readFileString(path.join(root, manifest)).pipe(Effect.flatMap(decodeManifest), Effect.flatMap(dependenciesOf(manifest)))));
279
- return Array.flatten(parsed);
280
- });
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 {
288
- valid: Array.isReadonlyArrayEmpty(problems),
289
- output: Array.join(problems, "\n")
290
- };
291
- })));
292
- // src/betterleaks.ts
293
- const toBetterleaksToml = (config) => {
294
- const { ignoredSecrets: _ignoredSecrets, ...rest } = config;
295
- return stringify(rest);
296
- };
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];
312
- });
313
- const scanSecrets = ({ config, root, args, input }) => Effect.gen(function* scan() {
314
- const ignore = yield* ignoreFileArgs(config);
315
- return yield* runVendored(BETTERLEAKS, {
316
- root,
317
- args: [
318
- ...args,
319
- "--redact",
320
- "--no-banner",
321
- ...ignore
322
- ],
323
- env: { BETTERLEAKS_CONFIG_TOML: toBetterleaksToml(config) },
324
- input
325
- });
326
- }).pipe(Effect.scoped);
327
- const SUCCESS = 0;
328
- const lacksHistory = (root) => Effect.gen(function* history() {
329
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
330
- const shallow = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "--is-shallow-repository"], { cwd: root }));
331
- const promisor = yield* spawner.exitCode(ChildProcess.make("git", [
332
- "config",
333
- "--get",
334
- "remote.origin.promisor"
335
- ], { cwd: root }));
336
- return String.trim(shallow) === "true" || promisor === SUCCESS;
337
- });
338
- const succeeded = (tool, run) => run.pipe(Effect.flatMap((code) => {
339
- if (code === SUCCESS) return Effect.void;
340
- return Effect.fail(toolFailed(tool)(`exit code ${code}`));
341
- }));
342
- const scanCommittedTree = (config, root) => Effect.gen(function* tree() {
343
- const fs = yield* FileSystem.FileSystem;
344
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
345
- const directory = yield* fs.makeTempDirectoryScoped({ prefix: "vpa-betterleaks-" });
346
- const archive = `${directory}.tar`;
347
- yield* succeeded("git archive", spawner.exitCode(ChildProcess.make("git", [
348
- "archive",
349
- "--format=tar",
350
- "-o",
351
- archive,
352
- "HEAD"
353
- ], { cwd: root })));
354
- yield* succeeded("tar", spawner.exitCode(ChildProcess.make("tar", [
355
- "-xf",
356
- archive,
357
- "-C",
358
- directory
359
- ])));
360
- yield* fs.remove(archive);
361
- return yield* scanSecrets({
362
- config,
363
- root,
364
- args: [directory]
365
- });
366
- }).pipe(Effect.scoped);
367
- const betterleaksCheck = withSection("betterleaks", (config, { root, base }) => lacksHistory(root).pipe(Effect.flatMap((partial) => {
368
- if (partial) return scanCommittedTree(config, root);
369
- return scanSecrets({
370
- config,
371
- root,
372
- args: [
373
- "git",
374
- ".",
375
- `--revision=${base}..HEAD`
376
- ]
377
- });
378
- })));
379
- const STAGED_DIFF = [
380
- "diff",
381
- "--cached",
382
- "--no-ext-diff",
383
- "--no-textconv",
384
- "--no-color",
385
- "--src-prefix=a/",
386
- "--dst-prefix=b/"
387
- ];
388
- const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$1, (config, root) => Effect.gen(function* staged() {
389
- const diff = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", STAGED_DIFF, { cwd: root }));
390
- return yield* scanSecrets({
391
- config,
392
- root,
393
- args: ["stdin", "--git-diff"],
394
- input: diff
395
- });
396
- }));
397
- // src/markdownlint.ts
398
- const DATA_FIRST_ARITY_3$1 = 3;
399
- const formatError = (file) => (error) => {
400
- const detail = pipe([error.errorDetail, error.errorContext], Array.filter((part) => part !== null && part !== ""), Array.map((part) => ` [${part}]`), Array.join(""));
401
- return `${file}:${error.lineNumber} ${Array.join(error.ruleNames, "/")} ${error.ruleDescription}${detail}`;
402
- };
403
- const optionsOf = (config, files) => ({
404
- files: [...files],
405
- ...pipe(Option.fromNullishOr(config.config), Option.match({
406
- onNone: () => ({}),
407
- onSome: (rules) => ({ config: rules })
408
- })),
409
- ...pipe(Option.fromNullishOr(config.customRules), Option.match({
410
- onNone: () => ({}),
411
- onSome: (rules) => ({ customRules: [...rules] })
412
- }))
413
- });
414
- const lintMarkdown = Function.dual(DATA_FIRST_ARITY_3$1, (config, root, files) => Effect.gen(function* markdown() {
415
- const path = yield* Path.Path;
416
- const absolute = pipe(files, Array.map((file) => path.join(root, file)));
417
- const results = yield* attempt("markdownlint")(() => lint$1(optionsOf(config, absolute)));
418
- const linesOf = ([file, errors]) => {
419
- const format = formatError(path.relative(root, file));
420
- return pipe(errors, Array.map(format));
421
- };
422
- const lines = pipe(Record.toEntries(results), Array.flatMap(linesOf));
423
- return {
424
- valid: Array.isArrayEmpty(lines),
425
- output: Array.join(lines, "\n")
426
- };
427
- }));
428
- // src/textlint.ts
429
- const DATA_FIRST_ARITY_3 = 3;
430
- const descriptorOf = (loaded, root) => {
431
- if (!loaded.ok) return Effect.fail(toolFailed("textlint")(loaded.error.message));
432
- return Effect.succeed(new TextlintKernelDescriptor({
433
- rules: loaded.config.rules,
434
- filterRules: loaded.config.filterRules,
435
- plugins: [...builtInPlugins, ...loaded.config.plugins],
436
- configBaseDir: root
437
- }));
438
- };
439
- const lintTexts = Function.dual(DATA_FIRST_ARITY_3, (config, root, files) => Effect.gen(function* lint() {
440
- const path = yield* Path.Path;
441
- const { ignores: _ignores, ...rawConfig } = config;
442
- yield* attempt("textlint")(() => import("vite-plus/register"));
443
- const loaded = yield* attempt("textlint")(() => loadPackagesFromRawConfig({
444
- rawConfig,
445
- node_moduleDir: path.join(root, "node_modules")
446
- }));
447
- const descriptor = yield* descriptorOf(loaded, root);
448
- const absolute = pipe(files, Array.map((file) => path.join(root, file)));
449
- const results = yield* attempt("textlint")(() => createLinter({ descriptor }).lintFiles([...absolute]));
450
- const formatter = yield* attempt("textlint")(() => loadLinterFormatter({
451
- formatterName: "stylish",
452
- color: false
453
- }));
454
- return {
455
- valid: pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
456
- output: formatter.format(results)
457
- };
458
- }));
459
- // src/text-checks.ts
460
- const MARKDOWN = "*.md";
461
- const markdownFiles = (root, ignores = []) => listGitFiles(root, [MARKDOWN, ...pipe(ignores, Array.map((glob) => `:(glob,exclude)${glob}`))]);
462
- const textlintCheck = withSection("textlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintTexts(config, root, files))));
463
- const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
464
- const commitlintCheck = withSection("commitlint", (config, { root, base }) => listCommitMessages(root, `${base}..HEAD`).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
465
- // src/workflow-checks.ts
466
- const WORKFLOWS = ".github/workflows";
467
- const onWorkflows = (binary, args) => ({ root }) => Effect.gen(function* workflows() {
468
- const fs = yield* FileSystem.FileSystem;
469
- const path = yield* Path.Path;
470
- if (!(yield* fs.exists(path.join(root, WORKFLOWS)))) return Option.none();
471
- const resolvedArgs = yield* args;
472
- const ran = yield* runVendored(binary, {
473
- root,
474
- args: resolvedArgs
475
- });
476
- return Option.some(ran);
477
- });
478
- const actionlintCheck = onWorkflows(ACTIONLINT, Effect.succeed([]));
479
- const zizmorArgs = Effect.gen(function* zizmorArgs() {
480
- const remote = yield* Config.option(Config.String("CLAUDE_CODE_REMOTE")).pipe(Effect.orDie);
481
- return pipe(remote, Option.match({
482
- onNone: () => [".github"],
483
- onSome: () => ["--no-online-audits", ".github"]
484
- }));
485
- });
486
- const zizmorCheck = onWorkflows(ZIZMOR, zizmorArgs);
487
- // src/checks.ts
488
- const CHECKS = [
489
- {
490
- name: "betterleaks",
491
- run: betterleaksCheck
492
- },
493
- {
494
- name: "commitlint",
495
- run: commitlintCheck
496
- },
497
- {
498
- name: "actionlint",
499
- run: actionlintCheck
500
- },
501
- {
502
- name: "zizmor",
503
- run: zizmorCheck
504
- },
505
- {
506
- name: "dependencies",
507
- run: dependenciesCheck
508
- },
509
- {
510
- name: "steiger",
511
- run: steigerCheck
512
- },
513
- {
514
- name: "textlint",
515
- run: textlintCheck
516
- },
517
- {
518
- name: "markdownlint",
519
- run: markdownlintCheck
520
- },
521
- {
522
- name: "fallow",
523
- run: fallowCheck
524
- }
525
- ];
526
- // src/run-checks.ts
527
- const DEFAULT_BASE = "origin/main";
528
- const RESOLVED = 0;
529
- const isCommit = (root, revision) => Effect.gen(function* verify() {
530
- return (yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("git", [
531
- "rev-parse",
532
- "-q",
533
- "--verify",
534
- `${revision}^{commit}`
535
- ], { cwd: root }))) === RESOLVED;
536
- }).pipe(Effect.orElseSucceed(() => false));
537
- const resolveBase = (root) => Effect.gen(function* base() {
538
- const configured = yield* Config.option(Config.String("VPA_BASE")).pipe(Effect.orDie);
539
- if (Option.isSome(configured) && (yield* isCommit(root, configured.value))) return configured.value;
540
- return DEFAULT_BASE;
541
- });
542
- const describe = ({ name, report }) => {
543
- if (report.valid) return `✓ ${name}`;
544
- return `✗ ${name}\n${report.output}`;
545
- };
546
- const runCheck = (context) => ({ name, run }) => run(context).pipe(Effect.map(Option.map((report) => ({
547
- name,
548
- report
549
- }))));
550
- const runAllChecks = (root) => Effect.gen(function* all() {
551
- const config = yield* loadViteConfig(root);
552
- const base = yield* resolveBase(root);
553
- const outcomes = yield* pipe(CHECKS, Effect.forEach(runCheck({
554
- root,
555
- config,
556
- base
557
- }), { concurrency: "unbounded" }), Effect.map(Array.getSomes));
558
- yield* writeTo("stdout", `${pipe(outcomes, Array.map(describe), Array.join("\n"))}\n`);
559
- return yield* pipe(outcomes, Array.filter(({ report }) => !report.valid), Array.map(({ name }) => name), Array.match({
560
- onEmpty: () => Effect.void,
561
- onNonEmpty: (failed) => Effect.fail(checksFailed(`Failed: ${Array.join(failed, ", ")}`))
562
- }));
563
- });
564
- // src/vpa.ts
565
- const DATA_FIRST_ARITY = 2;
566
- const USAGE = pipe([
567
- "Usage: vpa run every check configured in vite.config.ts",
568
- " vpa --staged scan the staged changes for secrets (pre-commit)",
569
- " vpa --commit-msg <file> lint a commit message (commit-msg)"
570
- ], Array.join("\n"));
571
- const usage = Effect.fail(checksFailed(USAGE));
572
- const stagedSecrets = (root) => loadSection(root, "betterleaks").pipe(Effect.flatMap((config) => scanStagedSecrets(config, root)), Effect.flatMap(finish));
573
- const commitMessage = (root, rest) => pipe(Array.head(rest), Option.match({
574
- onNone: () => usage,
575
- onSome: (file) => loadSection(root, "commitlint").pipe(Effect.flatMap((config) => lintCommitMessageFile(config, root, file)), Effect.flatMap(finish))
576
- }));
577
- const HOOKS = {
578
- "--staged": stagedSecrets,
579
- "--commit-msg": commitMessage
580
- };
581
- const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.match({
582
- onEmpty: () => runAllChecks(root),
583
- onNonEmpty: ([flag, ...rest]) => pipe(Record.get(HOOKS, flag), Option.match({
584
- onNone: () => usage,
585
- onSome: (hook) => hook(root, rest)
586
- }))
587
- })));
2
+ import { t as runCli } from "./run-cli-CSEt6b4a.mjs";
3
+ import { t as runVpa } from "./vpa-DvIGHBf6.mjs";
4
+ import { Effect, Path, Stdio } from "effect";
588
5
  // src/cli.ts
589
6
  runCli(Effect.gen(function* main() {
590
7
  const stdio = yield* Stdio.Stdio;