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