@r_masseater/vite-plus-adopt 0.7.0 → 0.8.1

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.
@@ -1,22 +1,23 @@
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";
1
+ import { c as ZIZMOR, d as checksFailed, f as configMissing, i as runCaptured, l as attempt, n as writeTo, o as ACTIONLINT, p as toolFailed, r as runVendored, s as BETTERLEAKS, t as finish } from "./output-DKrfYl9Q.mjs";
2
+ import { n as toJson } from "./json-QtVKpodH.mjs";
3
+ import { Array, Config, Effect, FileSystem, Function, Option, Path, Predicate, Record, Schema, String, pipe } from "effect";
4
4
  import { resolveConfigFromFile } from "vite-plus";
5
5
  import format from "@commitlint/format";
6
6
  import lint from "@commitlint/lint";
7
7
  import load from "@commitlint/load";
8
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
9
  import { lint as lint$1 } from "markdownlint/promise";
15
10
  import { loadPackagesFromRawConfig } from "@textlint/config-loader";
16
11
  import { TextlintKernelDescriptor } from "@textlint/kernel";
17
12
  import { createLinter, loadLinterFormatter } from "textlint";
18
13
  import { builtInPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
19
- // src/config.ts
14
+ import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";
15
+ import { stringify } from "smol-toml";
16
+ import { minimatch } from "minimatch";
17
+ import { parse } from "yaml";
18
+ import { intersects, valid, validRange } from "semver";
19
+ import { linter, processConfiguration } from "steiger";
20
+ // src/entities/vite-config/model/config.ts
20
21
  const CONFIG_FILES = [
21
22
  "vite.config.ts",
22
23
  "vite.config.mts",
@@ -34,7 +35,7 @@ const loadViteConfig = (root) => findConfigFile(root).pipe(Effect.flatMap((file)
34
35
  const requireSection = (key) => (config) => Effect.fromOption(Option.fromNullishOr(config[key])).pipe(Effect.mapError(() => configMissing(`vite.config has no "${key}" section`)));
35
36
  /** @internal */
36
37
  const loadSection = Function.dual(2, (root, key) => loadViteConfig(root).pipe(Effect.flatMap(requireSection(key))));
37
- // src/commitlint.ts
38
+ // src/features/lint-text/model/commitlint.ts
38
39
  const DATA_FIRST_ARITY_3$3 = 3;
39
40
  const COMMENT_CHAR = "#";
40
41
  const parserOptionsOf = (loaded) => {
@@ -62,164 +63,12 @@ Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messageFile) => Effect.gen(fu
62
63
  const message = yield* (yield* FileSystem.FileSystem).readFileString(messageFile);
63
64
  return yield* lintCommitMessages(config, root, [message]);
64
65
  }));
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
66
  /** @internal */
86
67
  const withSection = Function.dual(2, (key, run) => (context) => pipe(Option.fromNullishOr(context.config[key]), Option.match({
87
68
  onNone: () => Effect.succeedNone,
88
69
  onSome: (section) => Effect.asSome(run(section, context))
89
70
  })));
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
71
+ // src/shared/lib/git.ts
223
72
  const DATA_FIRST_ARITY$3 = 2;
224
73
  /** @internal */
225
74
  const listGitFiles = Function.dual(DATA_FIRST_ARITY$3, (root, pathspecs) => Effect.gen(function* list() {
@@ -247,86 +96,126 @@ const listCommitMessages = Function.dual(DATA_FIRST_ARITY$3, (root, range) => Ef
247
96
  ], { cwd: root }));
248
97
  return pipe(String.split(output, "\0"), Array.filter(String.isNonEmpty));
249
98
  }));
250
- // src/steiger.ts
99
+ // src/features/lint-text/model/markdownlint.ts
251
100
  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"))
101
+ const formatError = (file) => (error) => {
102
+ const detail = pipe([error.errorDetail, error.errorContext], Array.filter((part) => part !== null && part !== ""), Array.map((part) => ` [${part}]`), Array.join(""));
103
+ return `${file}:${error.lineNumber} ${Array.join(error.ruleNames, "/")} ${error.ruleDescription}${detail}`;
104
+ };
105
+ const optionsOf = (config, files) => ({
106
+ files: [...files],
107
+ ...pipe(Option.fromNullishOr(config.config), Option.match({
108
+ onNone: () => ({}),
109
+ onSome: (rules) => ({ config: rules })
110
+ })),
111
+ ...pipe(Option.fromNullishOr(config.customRules), Option.match({
112
+ onNone: () => ({}),
113
+ onSome: (rules) => ({ customRules: [...rules] })
114
+ }))
256
115
  });
257
116
  /** @internal */
258
- const checkSlices = Function.dual(DATA_FIRST_ARITY_3$2, (config, root, targets) => Effect.gen(function* check() {
117
+ const lintMarkdown = Function.dual(DATA_FIRST_ARITY_3$2, (config, root, files) => Effect.gen(function* markdown() {
259
118
  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));
119
+ const absolute = pipe(files, Array.map((file) => path.join(root, file)));
120
+ const results = yield* attempt("markdownlint")(() => lint$1(optionsOf(config, absolute)));
121
+ const linesOf = ([file, errors]) => {
122
+ const format = formatError(path.relative(root, file));
123
+ return pipe(errors, Array.map(format));
124
+ };
125
+ const lines = pipe(Record.toEntries(results), Array.flatMap(linesOf));
126
+ return {
127
+ valid: Array.isArrayEmpty(lines),
128
+ output: Array.join(lines, "\n")
129
+ };
263
130
  }));
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`;
131
+ // src/features/lint-text/model/textlint-presets.ts
132
+ const NO_OPTIONS = {};
133
+ const isRuleOptions = Predicate.or(Predicate.isBoolean, Predicate.isReadonlyObject);
134
+ /** @internal */
135
+ const presetRulesOf = (config) => {
136
+ const settings = config.rules ?? {};
137
+ return pipe(Record.toEntries(config.presets ?? {}), Array.filter(([name]) => Boolean(settings[name])), Array.flatMap(([name, preset]) => {
138
+ const userOptions = pipe(Option.liftPredicate(settings[name], Predicate.isReadonlyObject), Option.getOrElse(() => NO_OPTIONS));
139
+ return pipe(Record.toEntries(preset.rules), Array.map(([key, rule]) => ({
140
+ ruleId: normalizeTextlintPresetSubRuleKey({
141
+ preset: name,
142
+ rule: key
143
+ }),
144
+ rule,
145
+ options: pipe(Record.get(userOptions, key), Option.filter((value) => value !== true), Option.filter(isRuleOptions), Option.getOrElse(() => preset.rulesConfig[key] ?? true))
146
+ })), Array.filter(({ options }) => options !== false));
147
+ }));
280
148
  };
281
- const listManifests = (root) => Effect.gen(function* list() {
282
- const fs = yield* FileSystem.FileSystem;
149
+ /** @internal */
150
+ const rawConfigOf = (config) => {
151
+ const { ignores: _ignores, presets = {}, sources: _sources, ...rawConfig } = config;
152
+ return {
153
+ ...rawConfig,
154
+ rules: pipe(rawConfig.rules ?? {}, Record.filter((_setting, name) => !Record.has(presets, name)))
155
+ };
156
+ };
157
+ // src/features/lint-text/model/textlint.ts
158
+ const DATA_FIRST_ARITY_3$1 = 3;
159
+ const descriptorOf = (loaded, root, config) => {
160
+ if (!loaded.ok) return Effect.fail(toolFailed("textlint")(loaded.error.message));
161
+ return Effect.succeed(new TextlintKernelDescriptor({
162
+ rules: [...loaded.config.rules, ...presetRulesOf(config)],
163
+ filterRules: loaded.config.filterRules,
164
+ plugins: [...builtInPlugins, ...loaded.config.plugins],
165
+ configBaseDir: root
166
+ }));
167
+ };
168
+ /** @internal */
169
+ const lintTexts = Function.dual(DATA_FIRST_ARITY_3$1, (config, root, files) => Effect.gen(function* lint() {
283
170
  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)];
171
+ yield* attempt("textlint")(() => import("vite-plus/register"));
172
+ const loaded = yield* attempt("textlint")(() => loadPackagesFromRawConfig({
173
+ rawConfig: rawConfigOf(config),
174
+ node_moduleDir: path.join(root, "node_modules")
175
+ }));
176
+ const descriptor = yield* descriptorOf(loaded, root, config);
177
+ const absolute = pipe(files, Array.map((file) => path.join(root, file)));
178
+ const results = yield* attempt("textlint")(() => createLinter({ descriptor }).lintFiles([...absolute]));
179
+ const formatter = yield* attempt("textlint")(() => loadLinterFormatter({
180
+ formatterName: "stylish",
181
+ color: false
182
+ }));
183
+ return {
184
+ valid: pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
185
+ output: formatter.format(results)
186
+ };
187
+ }));
188
+ // src/features/lint-text/model/text-checks.ts
189
+ const MARKDOWN = "*.md";
190
+ const GLOB_PATHSPEC = ":(glob)";
191
+ const markdownFiles = (root, ignores = []) => listGitFiles(root, [MARKDOWN, ...pipe(ignores, Array.map((glob) => `:(glob,exclude)${glob}`))]);
192
+ const sourceFiles = (root, files) => listGitFiles(root, pipe(files, Array.map((glob) => `${GLOB_PATHSPEC}${glob}`)));
193
+ const mergeReports = (reports) => ({
194
+ valid: pipe(reports, Array.every((report) => report.valid)),
195
+ output: pipe(reports, Array.map((report) => report.output), Array.filter(String.isNonEmpty), Array.join("\n"))
289
196
  });
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
197
  /** @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);
198
+ const textlintCheck = withSection("textlint", (config, { root }) => {
199
+ const markdown = markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintTexts(config, root, files)));
200
+ const presets = config.presets ?? {};
201
+ const sources = pipe(config.sources ?? [], Array.map(({ files, ...source }) => Effect.flatMap(sourceFiles(root, files), (listed) => lintTexts({
202
+ ...source,
203
+ presets
204
+ }, root, listed))));
205
+ return Effect.all([markdown, ...sources]).pipe(Effect.map(mergeReports));
303
206
  });
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
207
  /** @internal */
308
- const steigerCheck = withSection("steiger", (section, { root }) => layeredDirectories(root, section.paths).pipe(Effect.flatMap((targets) => checkSlices(section.rules, root, targets))));
208
+ const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
309
209
  /** @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
210
+ const commitlintCheck = withSection("commitlint", (config, { root, base }) => listCommitMessages(root, `${base}..HEAD`).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
211
+ // src/features/scan-secrets/model/betterleaks.ts
318
212
  const toBetterleaksToml = (config) => {
319
213
  const { ignoredSecrets: _ignoredSecrets, ...rest } = config;
320
214
  return stringify(rest);
321
215
  };
322
216
  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;
217
+ // src/features/scan-secrets/model/secret-checks.ts
218
+ const DATA_FIRST_ARITY$2 = 2;
330
219
  const ignoreFileArgs = (config) => Effect.gen(function* ignoreFile() {
331
220
  const digests = toIgnoreFile(config);
332
221
  if (digests === "") return [];
@@ -412,7 +301,7 @@ const STAGED_DIFF = [
412
301
  "--dst-prefix=b/"
413
302
  ];
414
303
  /** @internal */
415
- const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$1, (config, root) => Effect.gen(function* staged() {
304
+ const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$2, (config, root) => Effect.gen(function* staged() {
416
305
  const diff = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", STAGED_DIFF, { cwd: root }));
417
306
  return yield* scanSecrets({
418
307
  config,
@@ -421,102 +310,125 @@ const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$1, (config, root) => Ef
421
310
  input: diff
422
311
  });
423
312
  }));
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}`;
313
+ // src/shared/lib/workspace.ts
314
+ const DEPENDENCY_FIELDS = [
315
+ "dependencies",
316
+ "devDependencies",
317
+ "optionalDependencies",
318
+ "peerDependencies"
319
+ ];
320
+ const Manifest = Schema.Record(Schema.String, Schema.Unknown);
321
+ const decodeSpecifiers = Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.String));
322
+ const Workspace = Schema.Struct({ packages: Schema.optionalKey(Schema.Array(Schema.String)) });
323
+ const decodeManifest = Schema.decodeEffect(Schema.fromJsonString(Manifest));
324
+ const decodeWorkspace = Schema.decodeUnknownEffect(Workspace);
325
+ const NEGATION = "!";
326
+ const manifestPathspec = (pattern) => {
327
+ if (String.startsWith(NEGATION)(pattern)) return `:(glob,exclude)${String.slice(1)(pattern)}/package.json`;
328
+ return `:(glob)${pattern}/package.json`;
429
329
  };
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
- }))
330
+ const listManifests = (root) => Effect.gen(function* list() {
331
+ const fs = yield* FileSystem.FileSystem;
332
+ const path = yield* Path.Path;
333
+ const text = yield* fs.readFileString(path.join(root, "pnpm-workspace.yaml"));
334
+ const raw = parse(text);
335
+ const workspace = yield* decodeWorkspace(raw);
336
+ const found = yield* listGitFiles(root, pipe(workspace.packages ?? [], Array.map(manifestPathspec)));
337
+ return ["package.json", ...Array.sort(found, String.Order)];
440
338
  });
339
+ 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]) => ({
340
+ manifest,
341
+ field,
342
+ name,
343
+ specifier
344
+ })))))), Effect.map(Array.flatten));
441
345
  /** @internal */
442
- const lintMarkdown = Function.dual(DATA_FIRST_ARITY_3$1, (config, root, files) => Effect.gen(function* markdown() {
346
+ const listDependencies = (root) => Effect.gen(function* list() {
347
+ const fs = yield* FileSystem.FileSystem;
443
348
  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
- };
349
+ const manifests = yield* listManifests(root);
350
+ const parsed = yield* pipe(manifests, Effect.forEach((manifest) => fs.readFileString(path.join(root, manifest)).pipe(Effect.flatMap(decodeManifest), Effect.flatMap(dependenciesOf(manifest)))));
351
+ return Array.flatten(parsed);
352
+ });
353
+ // src/features/check-repository/model/dependency-rules.ts
354
+ const DATA_FIRST_ARITY$1 = 2;
355
+ const SINGLE = 1;
356
+ const bannedBy = (dependencies) => ([reason, globs]) => {
357
+ const isBanned = (name) => pipe(globs, Array.some((glob) => minimatch(name, glob)));
358
+ return pipe(dependencies, Array.filter((dependency) => isBanned(dependency.name)), Array.map((dependency) => `${dependency.manifest} ${dependency.field}.${dependency.name} is banned: ${reason}`));
359
+ };
360
+ const MANIFEST = "package.json";
361
+ const matchesAny = (globs) => (value) => pipe(globs, Array.some((glob) => minimatch(value, glob)));
362
+ const inWorkspace = (globs) => (dependency) => pipe(globs, Array.some((glob) => minimatch(dependency.manifest, `${glob}/${MANIFEST}`)));
363
+ const inFields = (fields) => (dependency) => pipe(Option.fromNullishOr(fields), Option.match({
364
+ onNone: () => true,
365
+ onSome: (names) => Array.contains(names, dependency.field)
455
366
  }));
456
- // src/textlint-presets.ts
457
- const NO_OPTIONS = {};
458
- const isRuleOptions = Predicate.or(Predicate.isBoolean, Predicate.isReadonlyObject);
459
- /** @internal */
460
- const presetRulesOf = (config) => {
461
- const settings = config.rules ?? {};
462
- return pipe(Record.toEntries(config.presets ?? {}), Array.filter(([name]) => Boolean(settings[name])), Array.flatMap(([name, preset]) => {
463
- const userOptions = pipe(Option.liftPredicate(settings[name], Predicate.isReadonlyObject), Option.getOrElse(() => NO_OPTIONS));
464
- return pipe(Record.toEntries(preset.rules), Array.map(([key, rule]) => ({
465
- ruleId: `${name}/${key}`,
466
- rule,
467
- options: pipe(Record.get(userOptions, key), Option.filter((value) => value !== true), Option.filter(isRuleOptions), Option.getOrElse(() => preset.rulesConfig[key] ?? true))
468
- })), Array.filter(({ options }) => options !== false));
469
- }));
367
+ const allowedBy = (dependency) => ({ workspaces, dependencies, fields }) => inWorkspace(workspaces)(dependency) && matchesAny(dependencies)(dependency.name) && inFields(fields)(dependency);
368
+ const isAllowed = (rules) => (dependency) => pipe(Record.values(rules.allowed ?? {}), Array.some(allowedBy(dependency)));
369
+ const bannedProblems = (rules, dependencies) => {
370
+ const allowed = isAllowed(rules);
371
+ const checked = pipe(dependencies, Array.filter(Predicate.not(allowed)));
372
+ return pipe(Record.toEntries(rules.banned ?? {}), Array.flatMap(bannedBy(checked)));
470
373
  };
471
- /** @internal */
472
- const rawConfigOf = (config) => {
473
- const { ignores: _ignores, presets = {}, ...rawConfig } = config;
474
- return {
475
- ...rawConfig,
476
- rules: pipe(rawConfig.rules ?? {}, Record.filter((_setting, name) => !Record.has(presets, name)))
477
- };
374
+ const inWorkspaces = (globs) => (dependency) => dependency.field === "dependencies" && inWorkspace(globs)(dependency);
375
+ const exactGlobs = (rules) => pipe(Record.values(rules.exactDependencies ?? {}), Array.flatten);
376
+ 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}`));
377
+ const exactProblems = (rules, dependencies) => pipe(Record.toEntries(rules.exactDependencies ?? {}), Array.flatMap(notExactBy(dependencies)));
378
+ const groupByName = (dependencies) => Record.values(Array.groupBy(dependencies, ({ name }) => name));
379
+ const describe$1 = (dependencies) => {
380
+ return `${pipe(Array.head(dependencies), Option.match({
381
+ onNone: () => "",
382
+ onSome: (dependency) => dependency.name
383
+ }))}: ${pipe(dependencies, Array.map((dependency) => `${dependency.manifest} ${dependency.field} ${dependency.specifier}`), Array.join(", "))}`;
478
384
  };
479
- // src/textlint.ts
480
- const DATA_FIRST_ARITY_3 = 3;
481
- const descriptorOf = (loaded, root, config) => {
482
- if (!loaded.ok) return Effect.fail(toolFailed("textlint")(loaded.error.message));
483
- return Effect.succeed(new TextlintKernelDescriptor({
484
- rules: [...loaded.config.rules, ...presetRulesOf(config)],
485
- filterRules: loaded.config.filterRules,
486
- plugins: [...builtInPlugins, ...loaded.config.plugins],
487
- configBaseDir: root
488
- }));
385
+ 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)}`));
386
+ const isDisjoint = (ranges) => pipe(ranges, Array.some((left) => pipe(ranges, Array.some((right) => !intersects(left.specifier, right.specifier)))));
387
+ 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)}`));
388
+ const isPeer = ({ field }) => field === "peerDependencies";
389
+ const versionProblems = (rules, pinned) => {
390
+ if (rules.peerRanges !== "intersect") return mismatchProblems(pinned);
391
+ const others = pipe(pinned, Array.filter(Predicate.not(isPeer)));
392
+ const peers = pipe(pinned, Array.filter(isPeer));
393
+ return [...mismatchProblems(others), ...disjointRangeProblems(peers)];
489
394
  };
395
+ const comparedDependencies = (rules, dependencies) => {
396
+ const isExact = inWorkspaces(exactGlobs(rules));
397
+ return pipe(dependencies, Array.filter(({ specifier }) => !String.startsWith("workspace:")(specifier)), Array.filter(Predicate.not(isExact)));
398
+ };
399
+ const checkDependencies = Function.dual(DATA_FIRST_ARITY$1, (rules, dependencies) => [
400
+ ...bannedProblems(rules, dependencies),
401
+ ...exactProblems(rules, dependencies),
402
+ ...versionProblems(rules, comparedDependencies(rules, dependencies))
403
+ ]);
404
+ // src/features/check-repository/model/steiger.ts
405
+ const DATA_FIRST_ARITY_3 = 3;
406
+ const formatDiagnostic = (relative) => (diagnostic) => `${diagnostic.severity} ${relative(diagnostic.location.path)}: ${diagnostic.message} (${diagnostic.ruleName})`;
407
+ const reportOf = (diagnostics, relative) => ({
408
+ valid: pipe(diagnostics, Array.every((diagnostic) => diagnostic.severity !== "error")),
409
+ output: pipe(diagnostics, Array.map(formatDiagnostic(relative)), Array.join("\n"))
410
+ });
490
411
  /** @internal */
491
- const lintTexts = Function.dual(DATA_FIRST_ARITY_3, (config, root, files) => Effect.gen(function* lint() {
412
+ const checkSlices = Function.dual(DATA_FIRST_ARITY_3, (config, root, targets) => Effect.gen(function* check() {
492
413
  const path = yield* Path.Path;
493
- yield* attempt("textlint")(() => import("vite-plus/register"));
494
- const loaded = yield* attempt("textlint")(() => loadPackagesFromRawConfig({
495
- rawConfig: rawConfigOf(config),
496
- node_moduleDir: path.join(root, "node_modules")
497
- }));
498
- const descriptor = yield* descriptorOf(loaded, root, config);
499
- const absolute = pipe(files, Array.map((file) => path.join(root, file)));
500
- const results = yield* attempt("textlint")(() => createLinter({ descriptor }).lintFiles([...absolute]));
501
- const formatter = yield* attempt("textlint")(() => loadLinterFormatter({
502
- formatterName: "stylish",
503
- color: false
504
- }));
505
- return {
506
- valid: pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
507
- output: formatter.format(results)
508
- };
414
+ processConfiguration([...config], root);
415
+ const perTarget = yield* pipe(targets, Effect.forEach((target) => attempt("steiger")(() => linter.run(path.resolve(root, target)))));
416
+ return reportOf(Array.flatten(perTarget), (file) => path.relative(root, file));
509
417
  }));
510
- // src/text-checks.ts
511
- const MARKDOWN = "*.md";
512
- const markdownFiles = (root, ignores = []) => listGitFiles(root, [MARKDOWN, ...pipe(ignores, Array.map((glob) => `:(glob,exclude)${glob}`))]);
513
- /** @internal */
514
- const textlintCheck = withSection("textlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintTexts(config, root, files))));
418
+ // src/features/check-repository/model/repository-checks.ts
419
+ const LAYER_FOLDER = /\/(?:app|pages|widgets|features|entities|shared)\//gu;
420
+ 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)))))));
515
421
  /** @internal */
516
- const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
422
+ const steigerCheck = withSection("steiger", (section, { root }) => layeredDirectories(root, section.paths).pipe(Effect.flatMap((targets) => checkSlices(section.rules, root, targets))));
517
423
  /** @internal */
518
- const commitlintCheck = withSection("commitlint", (config, { root, base }) => listCommitMessages(root, `${base}..HEAD`).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
519
- // src/workflow-checks.ts
424
+ const dependenciesCheck = withSection("dependencyRules", (rules, { root }) => listDependencies(root).pipe(Effect.map((dependencies) => {
425
+ const problems = checkDependencies(rules, dependencies);
426
+ return {
427
+ valid: Array.isReadonlyArrayEmpty(problems),
428
+ output: Array.join(problems, "\n")
429
+ };
430
+ })));
431
+ // src/features/check-workflows/model/workflow-checks.ts
520
432
  const WORKFLOWS = ".github/workflows";
521
433
  const onWorkflows = (binary, args) => ({ root }) => Effect.gen(function* workflows() {
522
434
  const fs = yield* FileSystem.FileSystem;
@@ -540,7 +452,88 @@ const zizmorArgs = Effect.gen(function* zizmorArgs() {
540
452
  });
541
453
  /** @internal */
542
454
  const zizmorCheck = onWorkflows(ZIZMOR, zizmorArgs);
543
- // src/checks.ts
455
+ // src/features/run-fallow/model/fallow-check.ts
456
+ const QUIET = [
457
+ "--fail-on-issues",
458
+ "--quiet",
459
+ "--format",
460
+ "compact"
461
+ ];
462
+ const RUNS = [
463
+ [
464
+ "--skip",
465
+ "dupes",
466
+ ...QUIET
467
+ ],
468
+ [
469
+ "dead-code",
470
+ "--no-production",
471
+ ...QUIET
472
+ ],
473
+ ["dupes", ...QUIET],
474
+ [
475
+ "security",
476
+ "--fail-on-issues",
477
+ "--quiet"
478
+ ]
479
+ ];
480
+ const SMELLS = Schema.Array(Schema.Unknown).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])));
481
+ const COMPONENT_SMELLS = Schema.Struct({
482
+ prop_drilling_chains: SMELLS,
483
+ thin_wrappers: SMELLS,
484
+ duplicate_prop_shapes: SMELLS
485
+ });
486
+ const decodeSmells = Schema.decodeUnknownEffect(Schema.fromJsonString(COMPONENT_SMELLS));
487
+ const componentSmells = (root, configFile) => runCaptured({
488
+ root,
489
+ file: "fallow",
490
+ args: [
491
+ "dead-code",
492
+ "--no-production",
493
+ "--quiet",
494
+ "--format",
495
+ "json",
496
+ "-c",
497
+ configFile
498
+ ],
499
+ output: "stdout"
500
+ }).pipe(Effect.flatMap((report) => decodeSmells(report.output)), Effect.map((smells) => {
501
+ const found = [
502
+ ...smells.prop_drilling_chains,
503
+ ...smells.thin_wrappers,
504
+ ...smells.duplicate_prop_shapes
505
+ ];
506
+ return {
507
+ valid: Array.isReadonlyArrayEmpty(found),
508
+ output: toJson(smells)
509
+ };
510
+ }));
511
+ const runFallow = (config, root) => Effect.gen(function* fallow() {
512
+ const fs = yield* FileSystem.FileSystem;
513
+ const path = yield* Path.Path;
514
+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "vpa-fallow-" });
515
+ const configFile = path.join(directory, ".fallowrc.json");
516
+ const configText = yield* Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(config).pipe(Effect.orDie);
517
+ yield* fs.writeFileString(configFile, configText);
518
+ const reports = yield* pipe(RUNS, Effect.forEach((args) => runCaptured({
519
+ root,
520
+ file: "fallow",
521
+ args: [
522
+ ...args,
523
+ "-c",
524
+ configFile
525
+ ]
526
+ })));
527
+ const smells = yield* componentSmells(root, configFile);
528
+ const all = [...reports, smells];
529
+ return {
530
+ valid: pipe(all, Array.every((report) => report.valid)),
531
+ output: pipe(all, Array.filter((report) => !report.valid), Array.map((report) => report.output), Array.join("\n"))
532
+ };
533
+ }).pipe(Effect.scoped);
534
+ /** @internal */
535
+ const fallowCheck = withSection("fallow", (config, { root }) => runFallow(config, root));
536
+ // src/app/checks.ts
544
537
  const CHECKS = [
545
538
  {
546
539
  name: "betterleaks",
@@ -579,7 +572,7 @@ const CHECKS = [
579
572
  run: fallowCheck
580
573
  }
581
574
  ];
582
- // src/run-checks.ts
575
+ // src/app/run-checks.ts
583
576
  const DEFAULT_BASE = "origin/main";
584
577
  const RESOLVED = 0;
585
578
  const isCommit = (root, revision) => Effect.gen(function* verify() {
@@ -618,7 +611,7 @@ const runAllChecks = (root) => Effect.gen(function* all() {
618
611
  onNonEmpty: (failed) => Effect.fail(checksFailed(`Failed: ${Array.join(failed, ", ")}`))
619
612
  }));
620
613
  });
621
- // src/vpa.ts
614
+ // src/app/vpa.ts
622
615
  const DATA_FIRST_ARITY = 2;
623
616
  const USAGE = pipe([
624
617
  "Usage: vpa run every check configured in vite.config.ts",
@@ -653,4 +646,4 @@ const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.
653
646
  })));
654
647
  export { loadViteConfig as n, runVpa as t };
655
648
 
656
- //# sourceMappingURL=vpa-Cq7jIoC7.mjs.map
649
+ //# sourceMappingURL=vpa-Cvkfsskf.mjs.map