@r_masseater/vite-plus-adopt 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -121,6 +121,10 @@ export default defineConfig({
121
121
 
122
122
  The Renovate preset updates `version` of each GitHub key and of `dotnet`. A new version has no entry in `vpa-lock.json` yet, so `vpa --prepare` records it.
123
123
 
124
+ ## GitHub Actions caches
125
+
126
+ `vpa ci` puts the shared `setup` action of [typescript-template](https://github.com/masseater/typescript-template) into every job that runs `vp`, and removes what that action replaces: hand-written `actions/cache` steps for the pnpm store, the pnpm metadata, the vpa tools and msch, the `voidzero-dev/setup-vp` step and the `vp install --frozen-lockfile` step. Comments and formatting around the edited steps stay. It pins every template action and workflow to one commit, and calls `maintain-caches.yml` from `.github/workflows/cache.yml`, which saves the pnpm store on the default branch and deletes cache entries that it no longer needs. A local action in `.github/actions/` that wraps the shared one keeps its extra steps, and `vpa ci` forwards the inputs `cache`, `save` and `session-path` that it declares. Run it again after a new `vpa` version to move the pins. The library entry exports `findCiDrift(root)`, which lists the files `vpa ci` would change and the files whose template pins differ.
127
+
124
128
  ## Replacement for @arethetypeswrong/core
125
129
 
126
130
  `@r_masseater/vite-plus-adopt/attw` provides the same API as [@arethetypeswrong/core][attw] 0.18.5, on TypeScript 7.1 alone.
package/dist/cli.mjs CHANGED
@@ -1,22 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { i as VpToolsError, n as writeTo, t as runVpa } from "./vpa-Br-ls0AQ.mjs";
3
- import { Cause, Effect, Layer, Option, Path, Schema, Stdio, pipe } from "effect";
4
- import { runMainWith } from "@r_masseater/node-main";
2
+ import { t as runVpa } from "./vpa-mR96ZDOS.mjs";
3
+ import { Effect, Path, Stdio } from "effect";
4
+ import { runMain } from "@r_masseater/node-main";
5
5
  // src/app/run-cli.ts
6
- const reportFailure = (cause) => {
7
- const message = pipe(Cause.findErrorOption(cause), Option.filter(Schema.is(VpToolsError)), Option.match({
8
- onNone: () => Cause.pretty(cause),
9
- onSome: (error) => error.message
10
- }));
11
- return writeTo("stderr", `${message}\n`);
12
- };
13
6
  /** @internal */
14
7
  const runCli = (program) => {
15
- runMainWith({
16
- serviceName: "vpa",
17
- services: Layer.empty,
18
- onFailure: reportFailure
19
- })(program);
8
+ runMain("vpa")(program);
20
9
  };
21
10
  // src/app/cli.ts
22
11
  runCli(Effect.gen(function* main() {
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":[],"sources":["../src/app/run-cli.ts","../src/app/cli.ts"],"sourcesContent":["import { runMainWith } from \"@r_masseater/node-main\";\nimport { Cause, Layer, Option, Schema, pipe } from \"effect\";\nimport type { Effect, Stdio } from \"effect\";\n\nimport type { CommandServices } from \"#/shared/lib/command.ts\";\nimport { VpToolsError } from \"#/shared/lib/errors.ts\";\nimport { writeTo } from \"#/shared/lib/output.ts\";\n\nconst reportFailure = <Failure>(\n cause: Cause.Cause<Failure>,\n): Effect.Effect<void, never, Stdio.Stdio> => {\n const message = pipe(\n Cause.findErrorOption(cause),\n Option.filter(Schema.is(VpToolsError)),\n Option.match({\n onNone: () => Cause.pretty(cause),\n onSome: (error) => error.message,\n }),\n );\n return writeTo(\"stderr\", `${message}\\n`);\n};\n\n/** @internal */\nexport const runCli = <Failure>(program: Effect.Effect<void, Failure, CommandServices>): void => {\n runMainWith({\n serviceName: \"vpa\",\n services: Layer.empty,\n onFailure: reportFailure,\n })(program);\n};\n","import { Effect, Path, Stdio } from \"effect\";\n\nimport { runCli } from \"./run-cli.ts\";\nimport { runVpa } from \"./vpa.ts\";\n\nrunCli(\n Effect.gen(function* main() {\n const stdio = yield* Stdio.Stdio;\n const path = yield* Path.Path;\n const args = yield* stdio.args;\n return yield* runVpa(path.resolve(\".\"), args);\n }),\n);\n"],"mappings":";;;;;AAQA,MAAM,iBACJ,UAC4C;CAC5C,MAAM,UAAU,KACd,MAAM,gBAAgB,KAAK,GAC3B,OAAO,OAAO,OAAO,GAAG,YAAY,CAAC,GACrC,OAAO,MAAM;EACX,cAAc,MAAM,OAAO,KAAK;EAChC,SAAS,UAAU,MAAM;CAC3B,CAAC,CACH;CACA,OAAO,QAAQ,UAAU,GAAG,QAAQ,GAAG;AACzC;;AAGA,MAAa,UAAmB,YAAiE;CAC/F,YAAY;EACV,aAAa;EACb,UAAU,MAAM;EAChB,WAAW;CACb,CAAC,CAAC,CAAC,OAAO;AACZ;;ACxBA,OACE,OAAO,IAAI,UAAU,OAAO;CAC1B,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,OAAO,MAAM;CAC1B,OAAO,OAAO,OAAO,KAAK,QAAQ,GAAG,GAAG,IAAI;AAC9C,CAAC,CACH"}
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../src/app/run-cli.ts","../src/app/cli.ts"],"sourcesContent":["import { runMain } from \"@r_masseater/node-main\";\nimport type { Effect } from \"effect\";\n\nimport type { CommandServices } from \"#/shared/lib/command.ts\";\n\n/** @internal */\nexport const runCli = <Failure>(program: Effect.Effect<void, Failure, CommandServices>): void => {\n runMain(\"vpa\")(program);\n};\n","import { Effect, Path, Stdio } from \"effect\";\n\nimport { runCli } from \"./run-cli.ts\";\nimport { runVpa } from \"./vpa.ts\";\n\nrunCli(\n Effect.gen(function* main() {\n const stdio = yield* Stdio.Stdio;\n const path = yield* Path.Path;\n const args = yield* stdio.args;\n return yield* runVpa(path.resolve(\".\"), args);\n }),\n);\n"],"mappings":";;;;;;AAMA,MAAa,UAAmB,YAAiE;CAC/F,QAAQ,KAAK,CAAC,CAAC,OAAO;AACxB;;ACHA,OACE,OAAO,IAAI,UAAU,OAAO;CAC1B,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,OAAO,MAAM;CAC1B,OAAO,OAAO,OAAO,KAAK,QAAQ,GAAG,GAAG,IAAI;AAC9C,CAAC,CACH"}
package/dist/index.d.mts CHANGED
@@ -85,5 +85,14 @@ export declare const runVpa: {
85
85
  (args: readonly string[]): (root: string) => CommandEffect;
86
86
  (root: string, args: readonly string[]): CommandEffect;
87
87
  };
88
- export type { CommitlintConfig, DependencyRules, FallowConfig, SkillsSection, TextlintConfig, ToolSections };
88
+ /** @internal */
89
+ interface CiDrift {
90
+ readonly file: string;
91
+ readonly reason: "setup" | "ref";
92
+ }
93
+ /** @internal */
94
+ type Services = FileSystem.FileSystem | Path.Path;
95
+ /** @internal */
96
+ export declare const findCiDrift: (root: string) => Effect.Effect<readonly CiDrift[], never, Services>;
97
+ export type { CiDrift, CommitlintConfig, DependencyRules, FallowConfig, SkillsSection, TextlintConfig, ToolSections };
89
98
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { i as VpToolsError, r as loadViteConfig, t as runVpa } from "./vpa-Br-ls0AQ.mjs";
1
+ export { i as VpToolsError, n as findCiDrift, r as loadViteConfig, t as runVpa } from "./vpa-mR96ZDOS.mjs";
@@ -1,5 +1,5 @@
1
1
  import { n as toJson } from "./json-QtVKpodH.mjs";
2
- import { Array, Boolean as Boolean$1, Config, Context, Effect, Exit, FileSystem, Function, Layer, Match, Option, Order, Path, Predicate, Record, Redacted, Schedule, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
2
+ import { Array, Boolean as Boolean$1, Config, Context, Effect, Exit, FileSystem, Function, Layer, Match, Number, Option, Order, Path, Predicate, Record, Redacted, Schedule, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
3
3
  import { resolveConfigFromFile } from "vite-plus";
4
4
  import format from "@commitlint/format";
5
5
  import lint from "@commitlint/lint";
@@ -11,9 +11,9 @@ import { TextlintKernelDescriptor } from "@textlint/kernel";
11
11
  import { loadBuiltinPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
12
12
  import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";
13
13
  import { format as format$1, makeDetector } from "@r_masseater/h56m";
14
+ import { isMap, isPair, isScalar, isSeq, parse, parseDocument, visit } from "yaml";
14
15
  import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
15
16
  import { minimatch } from "minimatch";
16
- import { parse } from "yaml";
17
17
  import { Tar } from "effect/encoding";
18
18
  import { findWorkspaceProjectsNoCheck } from "@pnpm/workspace.projects-reader";
19
19
  import { readWorkspaceManifest } from "@pnpm/workspace.workspace-manifest-reader";
@@ -183,13 +183,13 @@ const descriptorOf = ({ root, config, wrap }) => Effect.gen(function* descriptor
183
183
  });
184
184
  // src/features/check-text/model/unused-directives.ts
185
185
  const WILDCARD = "*";
186
- const FIRST = 1;
186
+ const FIRST$2 = 1;
187
187
  const START$2 = 0;
188
188
  const positionOf = (text, index) => {
189
189
  const before = pipe(text, String$1.slice(START$2, index), String$1.split("\n"));
190
190
  return {
191
191
  line: before.length,
192
- column: pipe(Array.last(before), Option.getOrElse(() => ""), String$1.length) + FIRST
192
+ column: pipe(Array.last(before), Option.getOrElse(() => ""), String$1.length) + FIRST$2
193
193
  };
194
194
  };
195
195
  const ruleIdOf = (optional) => Match.value(optional["ruleId"]).pipe(Match.when(Match.string, (ruleId) => ruleId), Match.orElse(() => WILDCARD));
@@ -361,6 +361,335 @@ const finish = (report) => {
361
361
  if (report.output === "") return Effect.void;
362
362
  return writeTo("stdout", `${report.output}\n`);
363
363
  };
364
+ // src/features/sync-ci/model/template.ts
365
+ const TEMPLATE_REF = "a841e00930f7f6c21b8eb7249a429f1c16f53356";
366
+ const TEMPLATE = "masseater/typescript-template/.github";
367
+ const SETUP_ACTION = `${TEMPLATE}/actions/setup`;
368
+ const MAINTAIN_WORKFLOW = `${TEMPLATE}/workflows/maintain-caches.yml`;
369
+ const TEMPLATE_USE = new RegExp(String.raw`^${TEMPLATE}/(?:actions|workflows)/[^@]+@`, "u");
370
+ const pinned = (path) => `${path}@${TEMPLATE_REF}`;
371
+ const CACHE_WORKFLOW = "cache.yml";
372
+ const DEFAULT_BRANCH_ONLY = "github.ref == format('refs/heads/{0}', github.event.repository.default_branch)";
373
+ const REGISTRY_ACCESS = `\${{ secrets.TAKUMI_GUARD_TOKEN }}`;
374
+ const CACHE_WORKFLOW_SOURCE = Array.join([
375
+ "name: cache",
376
+ "",
377
+ "on:",
378
+ " schedule:",
379
+ " - cron: \"47 * * * *\"",
380
+ " workflow_dispatch:",
381
+ "",
382
+ "permissions: {}",
383
+ "",
384
+ "jobs:",
385
+ " caches:",
386
+ ` if: ${DEFAULT_BRANCH_ONLY}`,
387
+ " permissions:",
388
+ " actions: write",
389
+ " contents: read",
390
+ ` uses: ${pinned(MAINTAIN_WORKFLOW)}`,
391
+ " secrets:",
392
+ ` TAKUMI_GUARD_TOKEN: ${REGISTRY_ACCESS}`,
393
+ ""
394
+ ], "\n");
395
+ const PINNED_USE = new RegExp(String.raw`(?<use>${TEMPLATE}/(?:actions|workflows)/[^@\s]+)@(?<ref>[0-9a-f]{40})`, "gu");
396
+ const refsIn = (source) => pipe(source, String$1.matchAll(PINNED_USE), Array.fromIterable, Array.flatMap(({ groups }) => pipe(Option.fromNullishOr(groups), Option.flatMap(Record.get("ref")), Option.toArray)));
397
+ const withoutRefs = (source) => pipe(source, String$1.replaceAll(PINNED_USE, "$<use>"));
398
+ // src/features/sync-ci/model/yaml-nodes.ts
399
+ const EMPTY = "";
400
+ const ByStartDescending = Order.mapInput(Order.flip(Number.Order), ({ start }) => start);
401
+ const NEWLINE = "\n";
402
+ const FIRST$1 = 0;
403
+ const NEXT$1 = 1;
404
+ const RANGE_END = 2;
405
+ /** @internal */
406
+ const scalarText = (node) => pipe(Option.liftPredicate(node, isScalar), Option.map(({ value }) => value), Option.filter(Predicate.isString), Option.getOrElse(() => EMPTY));
407
+ /** @internal */
408
+ const fieldOf = (key) => (node) => pipe(Option.liftPredicate(node, isMap), Option.map((map) => scalarText(map.get(key, true))), Option.getOrElse(() => EMPTY));
409
+ /** @internal */
410
+ const usesOf = fieldOf("uses");
411
+ /** @internal */
412
+ const lineStart = ({ source, offset }) => pipe(source, String$1.slice(FIRST$1, offset), String$1.lastIndexOf(NEWLINE), Option.map((index) => index + NEXT$1), Option.getOrElse(() => FIRST$1));
413
+ /** @internal */
414
+ const startOf = (node) => pipe(Option.liftPredicate(node, isMap), Option.flatMapNullishOr(({ range }) => range), Option.map(([start]) => start));
415
+ /** @internal */
416
+ const endOf = (node) => pipe(Option.liftPredicate(node, isMap), Option.flatMapNullishOr(({ range }) => range), Option.map((range) => range[RANGE_END]));
417
+ const insertAt = (text) => ({ start, end, text: insert }) => pipe(text, String$1.slice(FIRST$1, start)) + insert + pipe(text, String$1.slice(end));
418
+ /** @internal */
419
+ const applyEdits = ({ source, edits }) => pipe(Array.sort(edits, ByStartDescending), Array.match({
420
+ onEmpty: () => source,
421
+ onNonEmpty: ([edit, ...rest]) => applyEdits({
422
+ source: insertAt(source)(edit),
423
+ edits: rest
424
+ })
425
+ }));
426
+ /** @internal */
427
+ const itemsOf = (node) => pipe(Option.liftPredicate(node, isSeq), Option.map(({ items }) => items), Option.getOrElse(() => []));
428
+ // src/features/sync-ci/model/cache-workflow.ts
429
+ const INDENT$1 = " ";
430
+ const CALL = "caches";
431
+ const jobText = (jobs) => pipe([
432
+ "",
433
+ `${INDENT$1}${CALL}:`,
434
+ `${INDENT$1}${INDENT$1}needs: [${pipe(jobs, Array.join(", "))}]`,
435
+ `${INDENT$1}${INDENT$1}if: always() && ${DEFAULT_BRANCH_ONLY}`,
436
+ `${INDENT$1}${INDENT$1}permissions:`,
437
+ `${INDENT$1}${INDENT$1}${INDENT$1}actions: write`,
438
+ `${INDENT$1}${INDENT$1}${INDENT$1}contents: read`,
439
+ `${INDENT$1}${INDENT$1}uses: ${pinned(MAINTAIN_WORKFLOW)}`,
440
+ `${INDENT$1}${INDENT$1}secrets:`,
441
+ `${INDENT$1}${INDENT$1}${INDENT$1}TAKUMI_GUARD_TOKEN: ${REGISTRY_ACCESS}`
442
+ ], Array.map((line) => `${line}\n`), Array.join(""));
443
+ /** @internal */
444
+ const addMaintainJob = ({ source, jobs, telemetryNeeds }) => pipe(Option.liftPredicate(parseDocument(source).get("jobs", true), isMap), Option.flatMap(endOf), Option.match({
445
+ onNone: () => source,
446
+ onSome: (at) => applyEdits({
447
+ source,
448
+ edits: [{
449
+ start: at,
450
+ end: at,
451
+ text: jobText(jobs)
452
+ }, ...pipe(telemetryNeeds, Array.map((start) => ({
453
+ start,
454
+ end: start,
455
+ text: `, ${CALL}`
456
+ })))]
457
+ })
458
+ }));
459
+ // src/features/sync-ci/model/rewrite-steps.ts
460
+ const CACHE_USE = /^actions\/cache(?:\/(?:restore|save))?@/u;
461
+ const SETUP_VP_USE = "voidzero-dev/setup-vp@";
462
+ const CHECKOUT_USE = "actions/checkout@";
463
+ const LOCAL_USE = /^(?:\$|\.)\/\.github\/actions\/(?<name>[^/@\s]+)$/u;
464
+ const MANAGED_PATH = /\.cache\/pnpm|vpa\/tools|\.cache\/msch|store-path/u;
465
+ const MANAGED_RUN = /npm\.flatt\.tech|vp install --frozen-lockfile|pnpm store (?:path|prune)|\.cache\/pnpm\/v/u;
466
+ const VP_COMMAND = /(?:^|[\s;&|(])vpx?\s/u;
467
+ const FORWARDED_INPUTS = [
468
+ "cache",
469
+ "save",
470
+ "session-path"
471
+ ];
472
+ const INDENT = " ";
473
+ const FIRST = 0;
474
+ const runOf = fieldOf("run");
475
+ const pathOf = (step) => pipe(Option.liftPredicate(step, isMap), Option.map((map) => scalarText(map.getIn(["with", "path"], true))), Option.getOrElse(() => ""));
476
+ const isManaged = (step) => pipe(usesOf(step), String$1.startsWith(SETUP_VP_USE)) || CACHE_USE.test(usesOf(step)) && MANAGED_PATH.test(pathOf(step)) || MANAGED_RUN.test(runOf(step));
477
+ const localAction = (step) => pipe(LOCAL_USE.exec(usesOf(step)), Option.fromNullishOr, Option.flatMapNullishOr(({ groups }) => groups), Option.flatMap(Record.get("name")));
478
+ const isSetup = (localSetups) => (step) => pipe(usesOf(step), String$1.startsWith(`masseater/typescript-template/.github/actions/setup@`)) || pipe(localAction(step), Option.exists((name) => localSetups.has(name)));
479
+ const runsVp = (step) => pipe(usesOf(step), String$1.startsWith(`masseater/typescript-template/.github/actions/verify@`)) || VP_COMMAND.test(runOf(step));
480
+ const forwardedLines = (inputs, pad) => pipe(FORWARDED_INPUTS, Array.filter((name) => pipe(inputs, Array.contains(name))), Array.map((name) => `${pad}${INDENT}${name}: \${{ inputs.${name} }}`), Array.match({
481
+ onEmpty: () => [],
482
+ onNonEmpty: (lines) => [`${pad}with:`, ...lines]
483
+ }));
484
+ const prefixOf = (source, step) => pipe(startOf(step), Option.map((start) => pipe(source, String$1.slice(lineStart({
485
+ source,
486
+ offset: start
487
+ }), start))), Option.getOrElse(() => ""));
488
+ const setupText = ({ source, inputs }, sample) => {
489
+ const prefix = prefixOf(source, sample);
490
+ const pad = pipe(" ", String$1.repeat(prefix.length));
491
+ return pipe([`${prefix}uses: ${pinned(SETUP_ACTION)}`, ...forwardedLines(inputs, pad)], Array.map((line) => `${line}\n`), Array.join(""));
492
+ };
493
+ const removal = (source, step) => Option.zipWith(startOf(step), endOf(step), (start, end) => ({
494
+ start: lineStart({
495
+ source,
496
+ offset: start
497
+ }),
498
+ end,
499
+ text: ""
500
+ }));
501
+ const replacement = (rewrite, step) => Option.map(removal(rewrite.source, step), (edit) => ({
502
+ ...edit,
503
+ text: setupText(rewrite, step)
504
+ }));
505
+ const insertion = (rewrite, items) => {
506
+ const offset = pipe(items, Array.findFirst((step) => pipe(usesOf(step), String$1.startsWith(CHECKOUT_USE))), Option.flatMap(endOf), Option.orElse(() => pipe(Array.head(items), Option.flatMap(startOf), Option.map((start) => lineStart({
507
+ source: rewrite.source,
508
+ offset: start
509
+ })))));
510
+ return Option.zipWith(offset, Array.head(items), (at, head) => ({
511
+ start: at,
512
+ end: at,
513
+ text: setupText(rewrite, head)
514
+ }));
515
+ };
516
+ const managedEdits = (rewrite, items) => {
517
+ const hasSetup = pipe(items, Array.some(isSetup(rewrite.localSetups)));
518
+ return pipe(items, Array.filter(isManaged), Array.map((step, index) => {
519
+ if (index === FIRST && !hasSetup) return replacement(rewrite, step);
520
+ return removal(rewrite.source, step);
521
+ }), Array.getSomes);
522
+ };
523
+ /** @internal */
524
+ const stepEdits = (rewrite) => {
525
+ if (!isSeq(rewrite.steps)) return [];
526
+ const items = rewrite.steps.items;
527
+ if (pipe(items, Array.some(isManaged))) return managedEdits(rewrite, items);
528
+ const needsSetup = pipe(items, Array.some(runsVp));
529
+ const hasSetup = pipe(items, Array.some(isSetup(rewrite.localSetups)));
530
+ if (needsSetup && !hasSetup) return pipe(insertion(rewrite, items), Option.toArray);
531
+ return [];
532
+ };
533
+ // src/features/sync-ci/model/rewrite-document.ts
534
+ const AFTER_REF = /@.*$/u;
535
+ const CLOSING_BRACKET = 1;
536
+ const TELEMETRY_USE = /\/actions\/ci-telemetry@/u;
537
+ const pinEdits = (document, source) => {
538
+ const found = [];
539
+ visit(document, { Pair: (_key, pair) => {
540
+ if (isPair(pair) && scalarText(pair.key) === "uses" && isScalar(pair.value) && TEMPLATE_USE.test(scalarText(pair.value))) pipe(Option.fromNullishOr(pair.value.range), Option.map(([start, end]) => ({
541
+ start,
542
+ end,
543
+ text: pipe(source, String$1.slice(start, end), String$1.replace(AFTER_REF, `@${TEMPLATE_REF}`))
544
+ })), Option.map((edit) => found.push(edit)));
545
+ } });
546
+ return found;
547
+ };
548
+ const tableAt = (document, path) => pipe(Option.liftPredicate(document.getIn(path, true), isMap), Option.map(({ items }) => pipe(items, Array.map(({ key, value }) => [scalarText(key), value]))), Option.getOrElse(() => []));
549
+ const jobsOf = (document) => pipe(tableAt(document, ["jobs"]), Array.map(([, job]) => job), Array.filter(isMap));
550
+ const stepsOf = (job) => pipe(Option.liftPredicate(job, isMap), Option.map((map) => itemsOf(map.get("steps", true))), Option.getOrElse(() => []));
551
+ const actionSteps = (document) => {
552
+ const steps = document.getIn(["runs", "steps"], true);
553
+ return itemsOf(steps);
554
+ };
555
+ const allSteps = (document) => pipe(jobsOf(document), Array.flatMap(stepsOf), Array.appendAll(actionSteps(document)));
556
+ const includesSetup = (document) => pipe(allSteps(document), Array.some((step) => pipe(usesOf(step), String$1.startsWith(`${SETUP_ACTION}@`))));
557
+ const callsMaintain = (document) => pipe(jobsOf(document), Array.some((job) => pipe(usesOf(job), String$1.startsWith(`${MAINTAIN_WORKFLOW}@`))));
558
+ const reportsTelemetry = (job) => pipe(stepsOf(job), Array.some((step) => TELEMETRY_USE.test(usesOf(step))));
559
+ const telemetryNeedsAt = (document) => pipe(jobsOf(document), Array.filter(reportsTelemetry), Array.flatMap((job) => pipe(Option.liftPredicate(job.getIn(["needs"], true), isSeq), Option.filter(({ flow }) => flow === true), Option.flatMap(({ range }) => Option.fromNullishOr(range)), Option.map(([, valueEnd]) => valueEnd - CLOSING_BRACKET), Option.toArray)));
560
+ const inputNames = (document) => pipe(tableAt(document, ["inputs"]), Array.map(([name]) => name));
561
+ /** @internal */
562
+ const rewriteDocument = ({ source, localSetups }) => {
563
+ const document = parseDocument(source);
564
+ const inputs = inputNames(document);
565
+ const edits = pipe([...pipe(jobsOf(document), Array.map((job) => job.get("steps", true))), document.getIn(["runs", "steps"], true)], Array.flatMap((steps) => stepEdits({
566
+ steps,
567
+ source,
568
+ localSetups,
569
+ inputs
570
+ })), Array.appendAll(pinEdits(document, source)));
571
+ const rewritten = applyEdits({
572
+ source,
573
+ edits
574
+ });
575
+ const result = parseDocument(rewritten);
576
+ return {
577
+ source: rewritten,
578
+ includesSetup: includesSetup(result),
579
+ callsMaintain: callsMaintain(result),
580
+ telemetryNeeds: telemetryNeedsAt(result),
581
+ jobs: pipe(tableAt(result, ["jobs"]), Array.filter(([, job]) => !reportsTelemetry(job)), Array.map(([name]) => name))
582
+ };
583
+ };
584
+ // src/features/sync-ci/model/sync-ci.ts
585
+ const WORKFLOWS = ".github/workflows";
586
+ const ACTIONS = ".github/actions";
587
+ const YAML_FILE = /\.ya?ml$/u;
588
+ const ACTION_FILES = ["action.yml", "action.yaml"];
589
+ const SEQUENTIAL = { concurrency: 1 };
590
+ const SINGLE_REF = 1;
591
+ const entriesOf = (directory) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => fs.readDirectory(directory)), Effect.map((entries) => Array.sort(entries, String$1.Order)), Effect.orElseSucceed(() => []));
592
+ const readSource = (file, name) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => fs.readFileString(file)), Effect.map((source) => ({
593
+ file,
594
+ name,
595
+ source
596
+ })), Effect.orDie);
597
+ const workflowSources = (root) => Effect.gen(function* readWorkflows() {
598
+ const path = yield* Path.Path;
599
+ const directory = path.join(root, WORKFLOWS);
600
+ const entries = yield* entriesOf(directory);
601
+ return yield* Effect.forEach(pipe(entries, Array.filter((entry) => YAML_FILE.test(entry))), (entry) => readSource(path.join(directory, entry), entry), SEQUENTIAL);
602
+ });
603
+ const actionFile = (directory, name) => Effect.gen(function* findActionFile() {
604
+ const fs = yield* FileSystem.FileSystem;
605
+ const path = yield* Path.Path;
606
+ const found = yield* Effect.findFirst(pipe(ACTION_FILES, Array.map((file) => path.join(directory, name, file))), (candidate) => fs.exists(candidate).pipe(Effect.orElseSucceed(() => false)));
607
+ return yield* Option.match(found, {
608
+ onNone: () => Effect.succeedNone,
609
+ onSome: (file) => readSource(file, name).pipe(Effect.asSome)
610
+ });
611
+ });
612
+ const actionSources = (root) => Effect.gen(function* readActions() {
613
+ const directory = (yield* Path.Path).join(root, ACTIONS);
614
+ const names = yield* entriesOf(directory);
615
+ const found = yield* Effect.forEach(names, (name) => actionFile(directory, name), SEQUENTIAL);
616
+ return Array.getSomes(found);
617
+ });
618
+ const settle = (actions, known) => {
619
+ const next = new Set(pipe(actions, Array.filter(({ source }) => rewriteDocument({
620
+ source,
621
+ localSetups: known
622
+ }).includesSetup), Array.map(({ name }) => name)));
623
+ if (next.size === known.size) return known;
624
+ return settle(actions, next);
625
+ };
626
+ const rewriteAll = (sources, localSetups) => pipe(sources, Array.map((found) => ({
627
+ ...found,
628
+ rewritten: rewriteDocument({
629
+ source: found.source,
630
+ localSetups
631
+ })
632
+ })));
633
+ const cacheWorkflow = (root, workflows) => Effect.gen(function* planCacheWorkflow() {
634
+ const path = yield* Path.Path;
635
+ if (pipe(workflows, Array.some(({ rewritten }) => rewritten.callsMaintain))) return [];
636
+ return [pipe(workflows, Array.findFirst(({ name }) => name === CACHE_WORKFLOW), Option.match({
637
+ onNone: () => ({
638
+ file: path.join(root, WORKFLOWS, CACHE_WORKFLOW),
639
+ previous: "",
640
+ source: CACHE_WORKFLOW_SOURCE
641
+ }),
642
+ onSome: ({ file, rewritten, source }) => ({
643
+ file,
644
+ previous: source,
645
+ source: addMaintainJob({
646
+ source: rewritten.source,
647
+ jobs: rewritten.jobs,
648
+ telemetryNeeds: rewritten.telemetryNeeds
649
+ })
650
+ })
651
+ }))];
652
+ });
653
+ const write = (root, { file, source }) => Effect.gen(function* writeChanged() {
654
+ const fs = yield* FileSystem.FileSystem;
655
+ const path = yield* Path.Path;
656
+ yield* fs.writeFileString(file, source);
657
+ yield* writeTo("stdout", `Updated ${path.relative(root, file)}\n`);
658
+ });
659
+ const planned = (root) => Effect.gen(function* plan() {
660
+ const workflows = yield* workflowSources(root);
661
+ const actions = yield* actionSources(root);
662
+ const localSetups = settle(actions, /* @__PURE__ */ new Set());
663
+ const rewrittenWorkflows = rewriteAll(workflows, localSetups);
664
+ const created = yield* cacheWorkflow(root, rewrittenWorkflows);
665
+ return {
666
+ changes: pipe([...rewriteAll(actions, localSetups), ...rewrittenWorkflows], Array.filter(({ rewritten, source }) => rewritten.source !== source), Array.map(({ file, rewritten, source }) => ({
667
+ file,
668
+ previous: source,
669
+ source: rewritten.source
670
+ })), Array.filter(({ file }) => !pipe(created, Array.some((change) => change.file === file))), Array.appendAll(created)),
671
+ sources: [...actions, ...workflows]
672
+ };
673
+ });
674
+ const refDrift = (sources) => {
675
+ const pinned = pipe(sources, Array.filter(({ source }) => !Array.isReadonlyArrayEmpty(refsIn(source))));
676
+ if (new Set(pipe(pinned, Array.flatMap(({ source }) => refsIn(source)))).size <= SINGLE_REF) return [];
677
+ return pipe(pinned, Array.map(({ file }) => ({
678
+ file,
679
+ reason: "ref"
680
+ })));
681
+ };
682
+ const setupDrift = (changes) => pipe(changes, Array.filter(({ previous, source }) => withoutRefs(previous) !== withoutRefs(source)), Array.map(({ file }) => ({
683
+ file,
684
+ reason: "setup"
685
+ })));
686
+ /** @internal */
687
+ const findCiDrift = (root) => planned(root).pipe(Effect.map(({ changes, sources }) => [...setupDrift(changes), ...refDrift(sources)]));
688
+ /** @internal */
689
+ const syncCi = (root) => planned(root).pipe(Effect.flatMap(({ changes }) => Effect.forEach(changes, (change) => write(root, change), {
690
+ ...SEQUENTIAL,
691
+ discard: true
692
+ })));
364
693
  // src/shared/config/skills.ts
365
694
  const Repository = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*\/[\w.-]+$/u));
366
695
  const LocalDirectory = Schema.String.check(Schema.isPattern(/^\.\/[\w.-]+(?:\/[\w.-]+)*$/u));
@@ -1312,6 +1641,7 @@ const runAllChecks = (root) => Effect.gen(function* all() {
1312
1641
  const DATA_FIRST_ARITY = 2;
1313
1642
  const USAGE = pipe([
1314
1643
  "Usage: vpa run every check configured in vite.config.ts",
1644
+ " vpa ci put the shared setup action into every job and workflow that runs vp, and drop the hand-written Actions caches",
1315
1645
  " vpa --prepare install the skills and tools in vite.config.ts (prepare)",
1316
1646
  " vpa --staged scan the staged changes for secrets (pre-commit)",
1317
1647
  " vpa --commit-msg <file> lint a commit message (commit-msg)",
@@ -1330,6 +1660,7 @@ const lintMessage = (toMessage) => (root, rest) => pipe(Array.head(rest), Option
1330
1660
  }));
1331
1661
  const readMessage = (file) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => fs.readFileString(file)));
1332
1662
  const HOOKS = {
1663
+ ci: syncCi,
1333
1664
  "--prepare": prepare,
1334
1665
  "--staged": stagedSecrets,
1335
1666
  "--commit-msg": lintMessage(readMessage),
@@ -1343,6 +1674,6 @@ const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.
1343
1674
  onSome: (hook) => hook(root, rest)
1344
1675
  }))
1345
1676
  })));
1346
- export { VpToolsError as i, writeTo as n, loadViteConfig as r, runVpa as t };
1677
+ export { VpToolsError as i, findCiDrift as n, loadViteConfig as r, runVpa as t };
1347
1678
 
1348
- //# sourceMappingURL=vpa-Br-ls0AQ.mjs.map
1679
+ //# sourceMappingURL=vpa-mR96ZDOS.mjs.map