@savvy-web/silk-effects 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +37 -2
  2. package/index.d.ts +6736 -325
  3. package/index.js +5399 -198
  4. package/package.json +17 -2
package/README.md CHANGED
@@ -9,7 +9,7 @@ Shared [Effect](https://effect.website/) library providing Silk Suite convention
9
9
 
10
10
  - Detect a package's publish targets from its `package.json` `publishConfig`, with multi-registry support and a changeset-ignore-aware override for `workspaces-effect`'s `PublishabilityDetector`
11
11
  - Read changeset config through a typed accessor service that reports silk vs vanilla mode, ignore patterns and fixed groups
12
- - Manage tool-owned sections in user-editable files without clobbering surrounding content
12
+ - Manage tool-owned sections in user-editable files without clobbering surrounding content, including ordered multi-section sync for composing several managed regions per file
13
13
  - Discover and resolve CLI tools globally or locally with version enforcement and caching
14
14
  - Detect versioning strategy and format git tags from changeset configuration
15
15
  - Locate config files and keep Biome schema URLs in sync across workspaces
@@ -166,7 +166,7 @@ Manage tool-owned delimited sections inside user-editable files. Sections are bo
166
166
 
167
167
  `SectionBlock` represents the content between markers. It supports `diff()`, `prepend()` and `append()` operations and uses normalized content for equality comparison.
168
168
 
169
- Methods: `read`, `write`, `sync`, `check`, `isManaged` — all support dual API (data-first and data-last) for pipe composition.
169
+ Methods: `read`, `write`, `sync`, `syncMany`, `check`, `remove`, `isManaged` — all support dual API (data-first and data-last) for pipe composition. `sync` manages one section; `syncMany` manages several ordered sections in one file; `remove` deletes a section including its markers.
170
170
 
171
171
  ```typescript
172
172
  import { Effect } from "effect";
@@ -192,6 +192,10 @@ await Effect.runPromise(
192
192
  // Check: compare file content against expected block
193
193
  const check = yield* ms.check(".husky/pre-commit", block);
194
194
  // => CheckResult: Found | NotFound
195
+
196
+ // Remove: delete the section and its markers, collapsing the leftover blank line
197
+ const removed = yield* ms.remove(".husky/pre-commit", def);
198
+ // => true if a section was removed, false if none was present
195
199
  }).pipe(
196
200
  Effect.provide(ManagedSectionLive),
197
201
  Effect.provide(NodeContext.layer),
@@ -207,6 +211,37 @@ const jsDef = SectionDefinition.make({ toolName: "MY-TOOL", commentStyle: "//" }
207
211
 
208
212
  Use `ShellSectionDefinition` when the comment style is always `#` and should not be configurable.
209
213
 
214
+ `syncMany` keeps several sections in one file in their declared relative order. It updates existing sections in place, inserts a missing section next to its declared sibling, normalizes order when sections drift out of order and preserves user content and unrelated tool sections. It returns one `SyncResult` per input block in input order and is idempotent.
215
+
216
+ The `SavvySections` exports compose ordered managed sections per husky hook file. A base section defines shared shell, then each consumer layers its own one-line tool section on top:
217
+
218
+ - `SavvyBaseSection` is a `ShellSectionDefinition` (tool name `savvy-base`); pair it with `savvyBasePreamble()`, which defines `ROOT`, the `in_ci` predicate, `PM` via package-manager detection and `pm_exec`.
219
+ - `SavvyHooksSection` (tool name `savvy-hooks`) pairs with `savvyHooksHygiene()`, a self-guarded repo-hygiene block that runs outside CI.
220
+ - `savvyToolSection(toolName, command)` builds a consumer's one-line tool section whose content is exactly `in_ci || pm_exec <command>` — the command is appended verbatim, so shell tokens like `$ROOT` and `$1` survive into the output. A `savvy-base` section must precede it in the same hook file, so pass both to `syncMany` in that order.
221
+
222
+ ```typescript
223
+ import { Effect } from "effect";
224
+ import { NodeContext } from "@effect/platform-node";
225
+ import {
226
+ ManagedSection, ManagedSectionLive,
227
+ SavvyBaseSection, savvyBasePreamble, savvyToolSection,
228
+ } from "@savvy-web/silk-effects";
229
+
230
+ await Effect.runPromise(
231
+ Effect.gen(function* () {
232
+ const ms = yield* ManagedSection;
233
+ const results = yield* ms.syncMany(".husky/commit-msg", [
234
+ SavvyBaseSection.block(savvyBasePreamble()),
235
+ savvyToolSection("savvy-commit", 'commitlint --config "$ROOT/lib/configs/commitlint.config.ts" --edit "$1"'),
236
+ ]);
237
+ // => ReadonlyArray<SyncResult>, one per input block in declared order
238
+ }).pipe(
239
+ Effect.provide(ManagedSectionLive),
240
+ Effect.provide(NodeContext.layer),
241
+ ),
242
+ );
243
+ ```
244
+
210
245
  #### VersioningStrategy
211
246
 
212
247
  Classify the versioning strategy from changeset configuration. Outputs `"single"` (0-1 publishable packages), `"fixed-group"` (all packages in one fixed group) or `"independent"` (multiple packages, not in a single group). Falls back gracefully if config is missing.