@effected/workspaces 0.43.0 → 0.44.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.
package/PackedInstall.js CHANGED
@@ -639,9 +639,8 @@ var PackedInstall = class PackedInstall {
639
639
  * (default `{ directory: "dist/prod/npm/pkg" }`), the same file whose
640
640
  * absence makes the run fail `PackSourceMissing`. Under `packFrom: "source"`
641
641
  * the packer builds nothing of its own, so nothing is checked and the
642
- * result is ready. A package a bundler's dev build produced is no
643
- * substitute: the prod output exists only after the prod build, which a
644
- * test job's usual `build:dev` pre-step does not run. Pair it with
642
+ * result is ready. The output exists only after the build, which a test job
643
+ * has to run first. Pair it with
645
644
  * {@link PackedInstall.gate} to skip locally and fail under CI.
646
645
  *
647
646
  * Fails as `closure` does, plus `Io` when a path cannot be inspected.
@@ -693,9 +692,8 @@ var PackedInstall = class PackedInstall {
693
692
  * unreadable `CI` counts as unset. Ready is always `"run"`;
694
693
  * missing is `"skip"` off CI and `"fail"` on it, so a CI job that never ran
695
694
  * the prod build cannot pass by silently skipping the proof. The message
696
- * names every missing path. The test job must run the prod build
697
- * (`build:prod` for a `@savvy-web/bundler` package) before the packed-install
698
- * tests: a dev build leaves `dist/prod` absent.
695
+ * names every missing path. The test job must run the build (`build` for an
696
+ * `@effected/bundler` package) before the packed-install tests.
699
697
  *
700
698
  * @example
701
699
  * ```ts
@@ -727,7 +725,7 @@ var PackedInstall = class PackedInstall {
727
725
  "0",
728
726
  "false"
729
727
  ].includes(ci.value.toLowerCase());
730
- const message = `the pack source is missing: ${preflight.missing.join(", ")}; run the prod build (build:prod) before the packed-install tests`;
728
+ const message = `the pack source is missing: ${preflight.missing.join(", ")}; run pnpm build --filter <package> before the packed-install tests`;
731
729
  return underCi ? {
732
730
  action: "fail",
733
731
  message: `${message}; it must not be skipped under CI`
@@ -0,0 +1,535 @@
1
+ import { stringsOf } from "./internal/patterns.js";
2
+ import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
3
+ import { GlobSet } from "@effected/glob";
4
+ import { Yaml } from "@effected/yaml";
5
+ import { Walker } from "@effected/walker";
6
+
7
+ // src/PnpmSettings.ts
8
+ /**
9
+ * A pnpm settings file could not be used.
10
+ *
11
+ * @remarks
12
+ * `reason` routes: `"read"` — the file exists but could not be read (the
13
+ * platform failure is the `cause`); `"parse"` — the file is not valid YAML (the
14
+ * `YamlParseError` is the `cause`); `"shape"` — the file is valid YAML but its
15
+ * document is not a mapping (a list or a scalar), which pnpm refuses too;
16
+ * `"membership"` — the workspace's `packages:` patterns each compile alone but
17
+ * fail as a set (they share one compile budget; the `GlobError` is the
18
+ * `cause`), so whether the directory is a member cannot be decided and the
19
+ * load fails rather than reading the workspace file as not applying. A
20
+ * file that does not exist is not an error: pnpm skips it, and so does
21
+ * {@link PnpmSettings.load}. An empty file is an empty mapping.
22
+ *
23
+ * @public
24
+ */
25
+ var PnpmSettingsError = class extends Schema.TaggedError()("PnpmSettingsError", {
26
+ /** Why the file could not be used. */
27
+ reason: Schema.Literals([
28
+ "read",
29
+ "parse",
30
+ "shape",
31
+ "membership"
32
+ ]),
33
+ /** The file involved, when the source named one. */
34
+ path: Schema.optionalKey(Schema.String),
35
+ /** The underlying failure, for `"read"`, `"parse"` and `"membership"`. */
36
+ cause: Schema.optionalKey(Schema.Defect())
37
+ }) {
38
+ get message() {
39
+ const where = this.path === void 0 ? "pnpm settings file" : `pnpm settings file ${this.path}`;
40
+ return this.reason === "read" ? `Could not read ${where}` : this.reason === "membership" ? `The \`packages:\` patterns in ${where} compile one by one but not as a set, so workspace membership cannot be decided` : this.reason === "parse" ? `Could not parse ${where} as YAML` : `The document in ${where} is not a mapping of settings`;
41
+ }
42
+ };
43
+ /** A setting name as pnpm spells it in YAML: camelCase, from an npmrc-style kebab-case key. */
44
+ const settingName = (key) => key.startsWith("@") || key.startsWith("/") ? key : key.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase());
45
+ /** A lower snake-case env suffix as the camelCase setting it names (`minimum_release_age` → `minimumReleaseAge`). */
46
+ const camelFromSnake = (snake) => snake.replace(/_([a-z0-9])/g, (_, char) => char.toUpperCase());
47
+ /** pnpm's two accepted spellings: all-lowercase or all-uppercase prefix and suffix, no empty segment. */
48
+ const LOWER_ENV = /^pnpm_config_([a-z0-9]+(?:_[a-z0-9]+)*)$/;
49
+ const UPPER_ENV = /^PNPM_CONFIG_([A-Z0-9]+(?:_[A-Z0-9]+)*)$/;
50
+ /** Defines an own, enumerable data property, so a `__proto__` key never reaches a prototype. */
51
+ const define = (target, key, value) => {
52
+ Object.defineProperty(target, key, {
53
+ value,
54
+ writable: true,
55
+ enumerable: true,
56
+ configurable: true
57
+ });
58
+ };
59
+ /**
60
+ * The environment's pnpm settings, keyed by camelCase setting name. An empty
61
+ * value is unset, and the uppercase spelling wins over the lowercase one when
62
+ * both are present, as pnpm 12 resolves them.
63
+ */
64
+ const environmentSettings = (env) => {
65
+ const lower = {};
66
+ const upper = {};
67
+ for (const [name, value] of Object.entries(env)) {
68
+ if (value === void 0 || value === "") continue;
69
+ const lowerMatch = LOWER_ENV.exec(name);
70
+ if (lowerMatch !== null) define(lower, camelFromSnake(lowerMatch[1]), value);
71
+ const upperMatch = UPPER_ENV.exec(name);
72
+ if (upperMatch !== null) define(upper, camelFromSnake(upperMatch[1].toLowerCase()), value);
73
+ }
74
+ const merged = {};
75
+ for (const [key, value] of Object.entries(lower)) define(merged, key, value);
76
+ for (const [key, value] of Object.entries(upper)) define(merged, key, value);
77
+ return merged;
78
+ };
79
+ /** One YAML settings file as its top-level mapping: an empty document is `{}`, a non-mapping fails `"shape"`. */
80
+ const mappingOf = (source) => {
81
+ if (source === void 0) return Result.succeed({});
82
+ const at = source.path === void 0 ? {} : { path: source.path };
83
+ const parsed = Yaml.parseResult(source.text);
84
+ if (Result.isFailure(parsed)) return Result.fail(new PnpmSettingsError({
85
+ reason: "parse",
86
+ ...at,
87
+ cause: parsed.failure
88
+ }));
89
+ const document = parsed.success;
90
+ if (document === null || document === void 0) return Result.succeed({});
91
+ if (typeof document !== "object" || Array.isArray(document)) return Result.fail(new PnpmSettingsError({
92
+ reason: "shape",
93
+ ...at
94
+ }));
95
+ const mapping = {};
96
+ for (const [key, value] of Object.entries(document)) define(mapping, key, value);
97
+ return Result.succeed(mapping);
98
+ };
99
+ /** A canonical decimal: optional `-`, no leading zero, no `+`, hex, exponent or digit separator. */
100
+ const DECIMAL = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
101
+ /** A canonical unsigned integer, the only form pnpm 12 reads for an integer setting. */
102
+ const UNSIGNED = /^(?:0|[1-9][0-9]*)$/;
103
+ /** A trimmed canonical decimal string as a finite number, or `undefined`. */
104
+ const numberFromText = (text) => {
105
+ const trimmed = text.trim();
106
+ if (!DECIMAL.test(trimmed)) return void 0;
107
+ const value = Number(trimmed);
108
+ return Number.isFinite(value) ? value : void 0;
109
+ };
110
+ /** A trimmed canonical unsigned integer string, within the safe-integer range, or `undefined`. */
111
+ const unsignedFromText = (text) => {
112
+ const trimmed = text.trim();
113
+ if (!UNSIGNED.test(trimmed)) return void 0;
114
+ const value = Number(trimmed);
115
+ return Number.isSafeInteger(value) ? value : void 0;
116
+ };
117
+ /** A file value as a non-negative safe integer: a number (never `-0`) or a canonical unsigned string. */
118
+ const unsignedFromValue = (value) => typeof value === "number" ? Number.isSafeInteger(value) && value >= 0 && !Object.is(value, -0) ? value : void 0 : typeof value === "string" ? unsignedFromText(value) : void 0;
119
+ const numberFromValue = (value) => typeof value === "number" ? Number.isFinite(value) ? value : void 0 : typeof value === "string" ? numberFromText(value) : void 0;
120
+ const stringsFromValue = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : void 0;
121
+ /** An environment value as a list: a JSON array of strings, the one form pnpm 11 and 12 both read as a list. */
122
+ const stringsFromText = (text) => {
123
+ let parsed;
124
+ try {
125
+ parsed = JSON.parse(text);
126
+ } catch {
127
+ return;
128
+ }
129
+ return stringsFromValue(parsed);
130
+ };
131
+ /** An environment value as a boolean: exactly `true` or `false` once trimmed, as pnpm 12 reads it. */
132
+ const booleanFromText = (text) => {
133
+ const trimmed = text.trim();
134
+ return trimmed === "true" ? true : trimmed === "false" ? false : void 0;
135
+ };
136
+ /** The strings pnpm 12 coerces to a boolean in a settings file, compared trimmed and case-insensitively. */
137
+ const TRUTHY = /* @__PURE__ */ new Set([
138
+ "true",
139
+ "yes",
140
+ "y",
141
+ "on"
142
+ ]);
143
+ const FALSY = /* @__PURE__ */ new Set([
144
+ "false",
145
+ "no",
146
+ "n",
147
+ "off"
148
+ ]);
149
+ /** A file value as a boolean: a YAML boolean, or one of the strings pnpm 12 coerces. */
150
+ const booleanFromValue = (value) => {
151
+ if (typeof value === "boolean") return value;
152
+ if (typeof value !== "string") return void 0;
153
+ const word = value.trim().toLowerCase();
154
+ return TRUTHY.has(word) ? true : FALSY.has(word) ? false : void 0;
155
+ };
156
+ /** The one name pnpm accepts for a workspace manifest. */
157
+ const WORKSPACE_MANIFEST = "pnpm-workspace.yaml";
158
+ /** The files that make a directory a project for pnpm's membership check. */
159
+ const PROJECT_MANIFESTS = [
160
+ "package.json",
161
+ "package.json5",
162
+ "package.yaml"
163
+ ];
164
+ /** Directory names that keep a directory out of every workspace, as pnpm 11 rules. */
165
+ const IGNORED_SEGMENTS = /* @__PURE__ */ new Set(["node_modules", "bower_components"]);
166
+ /** A POSIX pattern body with empty and `.` segments dropped and `..` folded, as `path.posix.normalize` would. */
167
+ const normalizeBody = (body) => {
168
+ const out = [];
169
+ for (const segment of body.split("/")) {
170
+ if (segment === "" || segment === ".") continue;
171
+ if (segment === ".." && out.length > 0 && out[out.length - 1] !== "..") out.pop();
172
+ else out.push(segment);
173
+ }
174
+ return out.join("/");
175
+ };
176
+ /**
177
+ * Whether a project directory at `relative` (a non-empty POSIX path below the
178
+ * workspace root) is a member under the manifest's `packages:` value, by
179
+ * pnpm's rule: each pattern names a directory whose `package.json` must match,
180
+ * a `!` pattern excludes, a pattern starting with `/` is skipped, and an absent
181
+ * list is `["."]`, the root alone. A single pattern that does not compile
182
+ * matches nothing; a set that compiles pattern by pattern but fails as a whole
183
+ * (the members share one compile budget) is neither member nor non-member, so
184
+ * it fails `"membership"` rather than answering `false`.
185
+ */
186
+ const isWorkspaceMember = (relative, packages) => {
187
+ if (relative.split("/").some((segment) => IGNORED_SEGMENTS.has(segment))) return Result.succeed(false);
188
+ const patterns = stringsOf(packages) ?? ["."];
189
+ const globs = [];
190
+ for (const pattern of patterns) {
191
+ const negated = pattern.startsWith("!");
192
+ const body = negated ? pattern.slice(1) : pattern;
193
+ if (body.startsWith("/")) continue;
194
+ const normalized = normalizeBody(body);
195
+ const glob = `${negated ? "!" : ""}${normalized === "" ? "" : `${normalized}/`}package.json`;
196
+ if (Result.isSuccess(GlobSet.compileResult([glob]))) globs.push(glob);
197
+ }
198
+ const set = GlobSet.compileResult(globs);
199
+ return Result.isSuccess(set) ? Result.succeed(set.success.matches(`${relative}/package.json`)) : Result.fail(new PnpmSettingsError({
200
+ reason: "membership",
201
+ cause: set.failure
202
+ }));
203
+ };
204
+ /** The first non-empty value of the named variables, read as own properties. */
205
+ const firstEnv = (env, names) => {
206
+ for (const name of names) {
207
+ const value = Object.hasOwn(env, name) ? env[name] : void 0;
208
+ if (value !== void 0 && value !== "") return value;
209
+ }
210
+ };
211
+ /**
212
+ * pnpm's effective settings: the values `pnpm config get <key>` reports for a
213
+ * pnpm setting, merged from the sources pnpm reads with pnpm's precedence.
214
+ *
215
+ * @remarks
216
+ * Build one with {@link PnpmSettings.load} (finds and reads the files through
217
+ * `FileSystem`) or {@link PnpmSettings.fromSourcesResult} (from text you
218
+ * already hold), then read a setting by name:
219
+ *
220
+ * ```ts
221
+ * settings.minimumReleaseAge; // Option<number>
222
+ * settings.minimumReleaseAgeExclude; // ReadonlyArray<string>
223
+ * settings.getBoolean("minimumReleaseAgeStrict");
224
+ * ```
225
+ *
226
+ * **Precedence, highest first**: a `pnpm_config_<name>` or
227
+ * `PNPM_CONFIG_<NAME>` environment variable, the workspace root's
228
+ * `pnpm-workspace.yaml`, then pnpm's global `config.yaml`. A higher source
229
+ * replaces a lower one's value whole; lists are not merged. This is the order
230
+ * pnpm 11 and pnpm 12 apply to settings such as `minimumReleaseAge` and
231
+ * `minimumReleaseAgeExclude`.
232
+ *
233
+ * **What pnpm does not read for a pnpm setting, this does not read either.**
234
+ * `.npmrc` files (project, user and global), `npm_config_*` variables and
235
+ * the old global `rc` file carry no pnpm setting for pnpm 11 and 12: pnpm
236
+ * takes only registry and auth keys from `.npmrc`. A registry or a credential
237
+ * is `@effected/npm`'s `NpmConfig`, not this. Command-line `--config.*`
238
+ * flags, pnpm's built-in defaults (`minimumReleaseAge` reads as unset here,
239
+ * as `pnpm config get` reports it, though pnpm applies a default when it
240
+ * installs), and the per-setting source restrictions pnpm applies to a few
241
+ * machine-level settings (a `pnpm-workspace.yaml` cannot set `globalDir`, for
242
+ * example) are not modelled.
243
+ *
244
+ * **Keys.** Every accessor takes the camelCase name pnpm writes in YAML
245
+ * (`minimumReleaseAge`) or the kebab-case one an npmrc would use
246
+ * (`minimum-release-age`); both name the same setting. An environment
247
+ * variable names a setting in snake case: `pnpm_config_minimum_release_age`
248
+ * all lowercase, or `PNPM_CONFIG_MINIMUM_RELEASE_AGE` all uppercase. A mixed
249
+ * spelling is not a pnpm setting and is ignored, and an empty value is unset.
250
+ * When both spellings are set, the uppercase one wins, as in pnpm 12.
251
+ *
252
+ * **Typed reads.** An environment value is text, read as the type the
253
+ * accessor asks for: a number as a canonical decimal, a boolean as `true` or
254
+ * `false`, a list as a JSON array of strings. An environment value that does
255
+ * not read as that type is skipped, and the next source answers, as pnpm 12
256
+ * skips it. In a file, pnpm 12 coerces boolean words (`yes`, `on`, `"true"`)
257
+ * and digit strings (`"15"`), and so does this. A file value that still does
258
+ * not read as the type answers `None` instead of falling through, because
259
+ * pnpm 12 refuses to load a file with a mistyped setting; {@link
260
+ * PnpmSettings.get} shows the raw value. A `null` in a file is unset.
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * import { PnpmSettings } from "@effected/workspaces";
265
+ * import { Effect, Option } from "effect";
266
+ *
267
+ * const cutoffMinutes = Effect.gen(function* () {
268
+ * const settings = yield* PnpmSettings.load({
269
+ * cwd: process.cwd(),
270
+ * env: process.env,
271
+ * platform: process.platform,
272
+ * });
273
+ * // Unset means pnpm's own default, 1440 minutes, not an open gate.
274
+ * return Option.getOrElse(settings.minimumReleaseAge, () => 1440);
275
+ * });
276
+ * ```
277
+ *
278
+ * @public
279
+ */
280
+ var PnpmSettings = class PnpmSettings extends Schema.Class("PnpmSettings")({
281
+ /** The environment's pnpm settings, keyed by camelCase name, as written. */
282
+ environment: Schema.Record(Schema.String, Schema.String),
283
+ /** The top-level settings of the workspace's `pnpm-workspace.yaml`. */
284
+ workspace: Schema.Record(Schema.String, Schema.Unknown),
285
+ /** The top-level settings of pnpm's global `config.yaml`. */
286
+ global: Schema.Record(Schema.String, Schema.Unknown),
287
+ /** The settings files that were read, lowest precedence first. */
288
+ files: Schema.Array(Schema.String)
289
+ }) {
290
+ /**
291
+ * A setting's raw value from the highest source that sets it, or `None`.
292
+ *
293
+ * @remarks
294
+ * An environment value is the string as written; a file value is the
295
+ * decoded YAML (a number, a list, a mapping). Use the typed accessors to
296
+ * read it as a type.
297
+ *
298
+ * @param key - The setting, camelCase or kebab-case.
299
+ */
300
+ get(key) {
301
+ const name = settingName(key);
302
+ if (Object.hasOwn(this.environment, name)) return Option.some(this.environment[name]);
303
+ for (const layer of [this.workspace, this.global]) {
304
+ const value = Object.hasOwn(layer, name) ? layer[name] : void 0;
305
+ if (value !== void 0 && value !== null) return Option.some(value);
306
+ }
307
+ return Option.none();
308
+ }
309
+ /**
310
+ * Which source {@link PnpmSettings.get} answers a setting from, or `None`
311
+ * when no source sets it.
312
+ *
313
+ * @param key - The setting, camelCase or kebab-case.
314
+ */
315
+ origin(key) {
316
+ const name = settingName(key);
317
+ if (Object.hasOwn(this.environment, name)) return Option.some("environment");
318
+ if (Object.hasOwn(this.workspace, name) && this.workspace[name] != null) return Option.some("workspace");
319
+ if (Object.hasOwn(this.global, name) && this.global[name] != null) return Option.some("global");
320
+ return Option.none();
321
+ }
322
+ /**
323
+ * A string setting: an environment value as written, or a string in a file.
324
+ *
325
+ * @param key - The setting, camelCase or kebab-case.
326
+ */
327
+ getString(key) {
328
+ return this.read(key, (text) => text, (value) => typeof value === "string" ? value : void 0);
329
+ }
330
+ /**
331
+ * A numeric setting: a finite number, or a canonical decimal string, in any
332
+ * source.
333
+ *
334
+ * @remarks
335
+ * A canonical decimal is an optional `-`, digits with no leading zero, and
336
+ * an optional fraction: `05`, `+5`, `0x10`, `1e2` and `1_000` are not
337
+ * numbers here, as pnpm 12 does not read them from the environment. An
338
+ * integer setting such as {@link PnpmSettings.minimumReleaseAge} is
339
+ * stricter still.
340
+ *
341
+ * @param key - The setting, camelCase or kebab-case.
342
+ */
343
+ getNumber(key) {
344
+ return this.read(key, numberFromText, numberFromValue);
345
+ }
346
+ /**
347
+ * A boolean setting: `true` or `false` in the environment, a YAML boolean
348
+ * or a boolean word in a file.
349
+ *
350
+ * @remarks
351
+ * In a file, the strings `true`, `yes`, `y` and `on` read as `true` and
352
+ * `false`, `no`, `n` and `off` as `false`, trimmed and in any case, as
353
+ * pnpm 12 coerces them. A number (`1`, `0`) or any other string answers
354
+ * `None`; pnpm 12 refuses it as an invalid boolean. The environment is
355
+ * stricter: only `true` or `false`, trimmed and lowercase.
356
+ *
357
+ * @param key - The setting, camelCase or kebab-case.
358
+ */
359
+ getBoolean(key) {
360
+ return this.read(key, booleanFromText, booleanFromValue);
361
+ }
362
+ /**
363
+ * A list setting: a JSON array of strings in the environment, a YAML list
364
+ * of strings in a file.
365
+ *
366
+ * @remarks
367
+ * A comma-separated environment value is not a list: pnpm 12 ignores it,
368
+ * and this skips it to the next source.
369
+ *
370
+ * @param key - The setting, camelCase or kebab-case.
371
+ */
372
+ getStringArray(key) {
373
+ return this.read(key, stringsFromText, stringsFromValue);
374
+ }
375
+ /**
376
+ * `minimumReleaseAge`: the minutes a version must have been published before
377
+ * pnpm installs it, or `None` when no source sets it. `None` is not an
378
+ * open gate: pnpm then applies its built-in default of 1440 minutes.
379
+ *
380
+ * @remarks
381
+ * Only a non-negative safe integer counts, as pnpm 12 reads the setting
382
+ * (an unsigned 64-bit integer, here bounded by `Number.MAX_SAFE_INTEGER`).
383
+ * Text, in the environment or a quoted file value, must be canonical digits
384
+ * once trimmed: `" 30 "` reads as 30, while `05`, `+5`, `-0`, `5.0`, `0x10`
385
+ * and `1e2` do not read at all. Such an environment value is skipped to the
386
+ * next source; such a file value answers `None`. A YAML number is read as
387
+ * decoded, so an unquoted `5.0` or `1e2` in a file reads as 5 or 100 where
388
+ * pnpm 12 refuses the file.
389
+ */
390
+ get minimumReleaseAge() {
391
+ return this.read("minimumReleaseAge", unsignedFromText, unsignedFromValue);
392
+ }
393
+ /**
394
+ * `minimumReleaseAgeExclude`: the package patterns exempt from
395
+ * {@link PnpmSettings.minimumReleaseAge}, empty when no source sets them.
396
+ *
397
+ * @remarks
398
+ * An explicitly empty list in a higher source shadows a lower source's
399
+ * entries, as in pnpm.
400
+ */
401
+ get minimumReleaseAgeExclude() {
402
+ return Option.getOrElse(this.getStringArray("minimumReleaseAgeExclude"), () => []);
403
+ }
404
+ /**
405
+ * The typed read every accessor shares: an environment value that does not
406
+ * parse falls through; the first file that sets the key decides.
407
+ */
408
+ read(key, fromText, fromValue) {
409
+ const name = settingName(key);
410
+ if (Object.hasOwn(this.environment, name)) {
411
+ const parsed = fromText(this.environment[name]);
412
+ if (parsed !== void 0) return Option.some(parsed);
413
+ }
414
+ for (const layer of [this.workspace, this.global]) {
415
+ const value = Object.hasOwn(layer, name) ? layer[name] : void 0;
416
+ if (value === void 0 || value === null) continue;
417
+ return Option.fromUndefinedOr(fromValue(value));
418
+ }
419
+ return Option.none();
420
+ }
421
+ /**
422
+ * Merges pnpm's settings sources, with no IO.
423
+ *
424
+ * @remarks
425
+ * Parses each YAML file, keeps the environment's `pnpm_config_*` and
426
+ * `PNPM_CONFIG_*` variables, and records the named files in
427
+ * `PnpmSettings.files`. Fails `"parse"` for a file that is not YAML
428
+ * and `"shape"` for one whose document is not a mapping.
429
+ *
430
+ * @param sources - The workspace file, the global file and the environment.
431
+ */
432
+ static fromSourcesResult(sources) {
433
+ const global = mappingOf(sources.global);
434
+ if (Result.isFailure(global)) return Result.fail(global.failure);
435
+ const workspace = mappingOf(sources.workspace);
436
+ if (Result.isFailure(workspace)) return Result.fail(workspace.failure);
437
+ const files = [];
438
+ for (const source of [sources.global, sources.workspace]) if (source?.path !== void 0) files.push(source.path);
439
+ return Result.succeed(PnpmSettings.make({
440
+ environment: environmentSettings(sources.env ?? {}),
441
+ workspace: workspace.success,
442
+ global: global.success,
443
+ files
444
+ }));
445
+ }
446
+ /**
447
+ * Loads the settings pnpm would use when run in `options.cwd`.
448
+ *
449
+ * @remarks
450
+ * The workspace file is found as pnpm finds it. When a
451
+ * `PNPM_CONFIG_WORKSPACE_DIR` / `NPM_CONFIG_WORKSPACE_DIR` variable names a
452
+ * directory (resolved against `cwd`), its `pnpm-workspace.yaml` is the
453
+ * file, unconditionally. Otherwise `cwd` is resolved through
454
+ * `FileSystem.realPath` (the lexical path when that fails, as in pnpm), and
455
+ * the nearest `pnpm-workspace.yaml` at or above it is taken. A misnamed
456
+ * manifest (`pnpm-workspace.yml`, `.pnpm-workspace.yaml`) is not a
457
+ * workspace manifest and the ascent passes it, as pnpm 12 does; pnpm 11
458
+ * refuses to run below one. That workspace applies only when `cwd` belongs
459
+ * to it: `cwd`
460
+ * is its root, `cwd` holds no project manifest (`package.json`,
461
+ * `package.json5` or `package.yaml`), or `cwd` matches the manifest's
462
+ * `packages:` patterns. A manifest with no `packages:` key has the root as
463
+ * its only member, so a nested project with its own `package.json` (an
464
+ * example app, a fixture) reads no workspace file, exactly as pnpm skips
465
+ * it. A directory under `node_modules` or `bower_components` is never a
466
+ * member.
467
+ *
468
+ * The global file is `config.yaml` in pnpm's global config directory:
469
+ * {@link PnpmSettingsLoadOptions.globalConfigDir}, else
470
+ * `$XDG_CONFIG_HOME/pnpm`, else the platform default (see
471
+ * {@link PnpmSettingsLoadOptions.platform}). A file that does not exist is
472
+ * skipped; one that cannot be read fails `"read"` (so does a project
473
+ * manifest probe that fails other than not-found), and one that does not
474
+ * parse fails as {@link PnpmSettings.fromSourcesResult} does.
475
+ *
476
+ * @param options - See {@link PnpmSettingsLoadOptions}.
477
+ */
478
+ static load = Effect.fn("PnpmSettings.load")(function* (options) {
479
+ const fs = yield* FileSystem.FileSystem;
480
+ const path = yield* Path.Path;
481
+ const env = options.env;
482
+ const cwd = path.resolve(options.cwd);
483
+ const realCwd = yield* fs.realPath(cwd).pipe(Effect.orElseSucceed(() => cwd));
484
+ const home = options.home ?? firstEnv(env, ["HOME", "USERPROFILE"]);
485
+ const read = (file) => fs.readFileString(file).pipe(Effect.map((text) => ({
486
+ text,
487
+ path: file
488
+ })), Effect.catchTag("PlatformError", (error) => error.reason._tag === "NotFound" ? Effect.succeed(void 0) : Effect.fail(new PnpmSettingsError({
489
+ reason: "read",
490
+ path: file,
491
+ cause: error
492
+ }))));
493
+ const workspaceDir = firstEnv(env, [
494
+ "PNPM_CONFIG_WORKSPACE_DIR",
495
+ "pnpm_config_workspace_dir",
496
+ "NPM_CONFIG_WORKSPACE_DIR",
497
+ "npm_config_workspace_dir"
498
+ ]);
499
+ const hasProjectManifest = (dir) => Effect.forEach(PROJECT_MANIFESTS, (name) => {
500
+ const file = path.join(dir, name);
501
+ return fs.exists(file).pipe(Effect.mapError((cause) => new PnpmSettingsError({
502
+ reason: "read",
503
+ path: file,
504
+ cause
505
+ })));
506
+ }).pipe(Effect.map((found) => found.some(Boolean)));
507
+ const ascendToWorkspace = Effect.gen(function* () {
508
+ const chain = yield* Walker.ascend(realCwd);
509
+ const found = yield* Walker.findUpward(chain, (dir) => [path.join(dir, WORKSPACE_MANIFEST)]);
510
+ if (Option.isNone(found)) return void 0;
511
+ const file = found.value;
512
+ const source = yield* read(file);
513
+ if (source === void 0) return void 0;
514
+ const relative = path.relative(path.dirname(file), realCwd).split(path.sep).join("/");
515
+ if (relative === "" || !(yield* hasProjectManifest(realCwd))) return source;
516
+ const mapping = yield* Effect.fromResult(mappingOf(source));
517
+ const packages = Object.hasOwn(mapping, "packages") ? mapping.packages : void 0;
518
+ return (yield* Effect.fromResult(isWorkspaceMember(relative, packages))) ? source : void 0;
519
+ });
520
+ const workspaceFile = workspaceDir !== void 0 ? path.join(path.resolve(cwd, workspaceDir), WORKSPACE_MANIFEST) : void 0;
521
+ const workspace = workspaceFile === void 0 ? yield* ascendToWorkspace : yield* read(workspaceFile);
522
+ const xdg = firstEnv(env, ["XDG_CONFIG_HOME"]);
523
+ const localAppData = firstEnv(env, ["LOCALAPPDATA"]);
524
+ const configDir = options.globalConfigDir ?? (xdg !== void 0 ? path.join(xdg, "pnpm") : options.platform === "win32" && localAppData !== void 0 ? path.join(localAppData, "pnpm", "config") : home === void 0 ? void 0 : options.platform === "darwin" ? path.join(home, "Library", "Preferences", "pnpm") : path.join(home, ".config", "pnpm"));
525
+ const globalFile = configDir === void 0 ? void 0 : path.join(configDir, "config.yaml");
526
+ const global = globalFile === void 0 || globalFile === workspace?.path ? void 0 : yield* read(globalFile);
527
+ return yield* Effect.fromResult(PnpmSettings.fromSourcesResult({
528
+ workspace,
529
+ global,
530
+ env
531
+ }));
532
+ });
533
+ };
534
+
535
+ export { PnpmSettings, PnpmSettingsError };
package/README.md CHANGED
@@ -158,6 +158,39 @@ const program = Effect.gen(function* () {
158
158
 
159
159
  A specifier the workspace cannot answer fails typed as `UnresolvedDependencyError`: at the manifest level "no catalog entry" means the manifest cannot be projected to concrete ranges.
160
160
 
161
+ ## pnpm settings
162
+
163
+ `PnpmSettings.load({ cwd, env, platform })` reads pnpm's effective settings, the values `pnpm config get <key>` reports, from the sources pnpm 11 and 12 read for a pnpm setting:
164
+
165
+ 1. a `pnpm_config_<name>` or `PNPM_CONFIG_<NAME>` environment variable (highest);
166
+ 2. the workspace root's `pnpm-workspace.yaml`: the one in the directory `PNPM_CONFIG_WORKSPACE_DIR` / `NPM_CONFIG_WORKSPACE_DIR` names, or else the nearest one at or above the real path of `cwd`, when `cwd` belongs to that workspace;
167
+ 3. pnpm's global `config.yaml`, in `$XDG_CONFIG_HOME/pnpm`, else `~/Library/Preferences/pnpm` on macOS, `%LOCALAPPDATA%\pnpm\config` on Windows and `~/.config/pnpm` elsewhere (lowest).
168
+
169
+ A higher source replaces a lower one's value whole, so a workspace `minimumReleaseAgeExclude` list replaces the global one rather than adding to it.
170
+
171
+ `cwd` belongs to the workspace, as pnpm decides it, when it is the root, when it holds no project manifest (`package.json`, `package.json5` or `package.yaml`), or when it matches the manifest's `packages:` patterns. A manifest with no `packages:` key has the root as its only member, so an example app or fixture with its own `package.json` inside a single-package repo reads no workspace settings, exactly as pnpm skips them. A misnamed manifest (`pnpm-workspace.yml`, `.pnpm-workspace.yaml`) is not a workspace file, and the ascent passes it, as pnpm 12 does.
172
+
173
+ ```ts
174
+ import { NodeServices } from "@effect/platform-node";
175
+ import { PnpmSettings } from "@effected/workspaces";
176
+ import { Effect, Option } from "effect";
177
+
178
+ const program = Effect.gen(function* () {
179
+ const settings = yield* PnpmSettings.load({ cwd: process.cwd(), env: process.env, platform: process.platform });
180
+ return {
181
+ cutoffMinutes: Option.getOrUndefined(settings.minimumReleaseAge), // number | undefined
182
+ exclude: settings.minimumReleaseAgeExclude, // ReadonlyArray<string>, [] when unset
183
+ strict: settings.getBoolean("minimumReleaseAgeStrict"), // Option<boolean>
184
+ };
185
+ }).pipe(Effect.provide(NodeServices.layer));
186
+ ```
187
+
188
+ `get(key)` returns a setting's raw value and `origin(key)` says which source it came from; `getString`, `getNumber`, `getBoolean` and `getStringArray` read it as a type. A key is the camelCase name pnpm writes in YAML or the kebab-case one an npmrc uses, and both name the same setting. An environment value is text, read as the type the accessor asks for: canonical digits for `minimumReleaseAge` (`05`, `+5`, `0x10` and `1e2` do not count), a canonical decimal for `getNumber`, exactly `true` or `false` for a boolean, or a JSON array of strings for a list. One that does not read as that type is skipped, so the next source answers, as pnpm 12 skips it. A comma-separated list is not a list. In a file, a boolean setting also reads the words pnpm 12 coerces (`yes`, `y`, `on`, `no`, `n`, `off`, quoted or not, in any case), and an integer setting a quoted digit string. A file value that still has the wrong type answers `None`, because pnpm 12 refuses to load such a file. A `null` in a file is unset.
189
+
190
+ pnpm 11 and 12 read no pnpm setting from `.npmrc` (only registry and auth keys), from `npm_config_*` variables or from the old global `rc` file, so neither does `PnpmSettings`. For registries and credentials, use `@effected/npm`'s `NpmConfig`. pnpm's built-in defaults are not applied: an unset `minimumReleaseAge` is `None`, which is also what `pnpm config get` reports. Command-line `--config.*` flags are not modelled either. `WorkspaceCatalogs.releaseAgeGate()` is a different question: the gate the workspace file and replayed config-dependency hooks declare, with no environment or global layer.
191
+
192
+ `PnpmSettings.fromSourcesResult({ workspace, global, env })` does the same merge over text you already hold, with no IO. A file that exists but cannot be read, is not YAML, or whose document is not a mapping fails `PnpmSettingsError` (`reason` `"read"`, `"parse"` or `"shape"`). A missing file is skipped.
193
+
161
194
  ## Peer dependency checking
162
195
 
163
196
  `PeerCheck.run(lockfile, options?)` reports unsatisfied peer dependencies as a pure value: no IO, no error channel, nothing in `R`, and no per-manager traversal logic. It reads `lockfile.format` once, to reject a format whose lockfile does not record peer resolution; past that gate the walk is the same for every manager. The answer comes from the resolved graph `@effected/lockfiles` normalizes, not from shelling out to a package manager's own peer command — bun has none, so the subprocess route cannot answer for every manager the rest of this package supports.
@@ -567,7 +600,7 @@ const program = Effect.gen(function* () {
567
600
  );
568
601
  ```
569
602
 
570
- `WorkspaceRootNotFoundError`, `WorkspaceDiscoveryError`, `WorkspacePatternError`, `PackageNotFoundError`, `WorkspaceManifestError`, `PackageManagerDetectionError`, `CatalogAssemblyError`, `LockfileReadError`, `CyclicDependencyError` and `ChangeDetectionError` each name one thing that can actually go wrong, and each method's error channel is narrowed to the ones it can produce. `CatalogAssemblyError` is defined in `@effected/npm`, beside the resolver contract that names it in its channel — import it from there. Change detection additionally surfaces `@effected/git`'s typed git errors, such as `NotARepositoryError`.
603
+ `WorkspaceRootNotFoundError`, `WorkspaceDiscoveryError`, `WorkspacePatternError`, `PackageNotFoundError`, `WorkspaceManifestError`, `PackageManagerDetectionError`, `CatalogAssemblyError`, `LockfileReadError`, `CyclicDependencyError`, `ChangeDetectionError` and `PnpmSettingsError` each name one thing that can actually go wrong, and each method's error channel is narrowed to the ones it can produce. `CatalogAssemblyError` is defined in `@effected/npm`, beside the resolver contract that names it in its channel — import it from there. Change detection additionally surfaces `@effected/git`'s typed git errors, such as `NotARepositoryError`.
571
604
 
572
605
  ## Testing
573
606
 
@@ -607,6 +640,7 @@ A name miss in the derived `getPackage` fails with the service's own typed `Pack
607
640
  - `DependencyGraph` — a value class over discovered packages: `levels()` for parallel build tiers, the flattened topological order, `toMermaid()` for a deterministic Mermaid `flowchart TD` of the whole graph, and `CyclicDependencyError` — naming the cycle's actual members — when there is no order.
608
641
  - `PackageManagerDetector` — npm, pnpm, yarn or bun from lockfiles and the `packageManager` field.
609
642
  - `WorkspaceCatalogs` — pnpm catalog assembly and `catalog:` resolution, on pnpm's own catalog packages; `releaseAgeGate()` assembles the effective `@effected/npm` `ReleaseAgeGate` from inline `pnpm-workspace.yaml` release-age keys and replayed hook contributions, strictest-wins, in the same pass as the catalogs.
643
+ - `PnpmSettings` — pnpm's effective settings as `pnpm config get` resolves them (`PNPM_CONFIG_*` variables, then `pnpm-workspace.yaml`, then the global `config.yaml`), with typed accessors and the `minimumReleaseAge` / `minimumReleaseAgeExclude` pair.
610
644
  - `LockfileReader` — locate and parse the workspace's lockfile through `@effected/lockfiles`.
611
645
  - `PeerCheck` — unsatisfied peer-dependency detection as a pure, total value over a parsed lockfile, with `UnsatisfiedPeer` and `PeerParent` as the report's rows. Read `supported`, `unresolvedImporters` and `unverified` alongside `unsatisfied`: an empty finding list is a clean bill of health only when those three say so.
612
646
  - `NoPeerDependencyRules` / `PeerDependencyRules` — the effective pnpm suppression policy `WorkspaceCatalogs.peerDependencyRules()` assembles, and the "I assert none apply" value for callers that have checked.
package/index.d.ts CHANGED
@@ -3062,6 +3062,326 @@ export declare class PeerCheck extends PeerCheck_base {
3062
3062
  */
3063
3063
  static run(lockfile: Lockfile, options?: PeerCheckOptions): PeerCheck;
3064
3064
  }
3065
+ declare const PnpmSettingsError_base: Schema.Class<PnpmSettingsError, Schema.TaggedStruct<"PnpmSettingsError", {
3066
+ /** Why the file could not be used. */
3067
+ readonly reason: Schema.Literals<readonly ["read", "parse", "shape", "membership"]>;
3068
+ /** The file involved, when the source named one. */
3069
+ readonly path: Schema.optionalKey<Schema.String>;
3070
+ /** The underlying failure, for `"read"`, `"parse"` and `"membership"`. */
3071
+ readonly cause: Schema.optionalKey<Schema.Defect>;
3072
+ }>, import("effect/Cause").YieldableError>;
3073
+ /**
3074
+ * A pnpm settings file could not be used.
3075
+ *
3076
+ * @remarks
3077
+ * `reason` routes: `"read"` — the file exists but could not be read (the
3078
+ * platform failure is the `cause`); `"parse"` — the file is not valid YAML (the
3079
+ * `YamlParseError` is the `cause`); `"shape"` — the file is valid YAML but its
3080
+ * document is not a mapping (a list or a scalar), which pnpm refuses too;
3081
+ * `"membership"` — the workspace's `packages:` patterns each compile alone but
3082
+ * fail as a set (they share one compile budget; the `GlobError` is the
3083
+ * `cause`), so whether the directory is a member cannot be decided and the
3084
+ * load fails rather than reading the workspace file as not applying. A
3085
+ * file that does not exist is not an error: pnpm skips it, and so does
3086
+ * {@link PnpmSettings.load}. An empty file is an empty mapping.
3087
+ *
3088
+ * @public
3089
+ */
3090
+ export declare class PnpmSettingsError extends PnpmSettingsError_base {
3091
+ get message(): string;
3092
+ }
3093
+ /**
3094
+ * Where a setting's value came from, highest precedence first: a
3095
+ * `pnpm_config_*` / `PNPM_CONFIG_*` environment variable, the workspace's
3096
+ * `pnpm-workspace.yaml`, or pnpm's global `config.yaml`.
3097
+ *
3098
+ * @public
3099
+ */
3100
+ type PnpmSettingOrigin = "environment" | "workspace" | "global";
3101
+ /**
3102
+ * One YAML settings file for {@link PnpmSettings.fromSourcesResult}: its text
3103
+ * and, for errors and `PnpmSettings.files`, where it came from.
3104
+ *
3105
+ * @public
3106
+ */
3107
+ interface PnpmSettingsSource {
3108
+ /** The YAML text. */
3109
+ readonly text: string;
3110
+ /** Where it was read from. */
3111
+ readonly path?: string | undefined;
3112
+ }
3113
+ /**
3114
+ * The inputs {@link PnpmSettings.fromSourcesResult} merges.
3115
+ *
3116
+ * @public
3117
+ */
3118
+ interface PnpmSettingsSources {
3119
+ /** The workspace root's `pnpm-workspace.yaml`. */
3120
+ readonly workspace?: PnpmSettingsSource | undefined;
3121
+ /** pnpm's global `config.yaml`. */
3122
+ readonly global?: PnpmSettingsSource | undefined;
3123
+ /** The environment, read for `pnpm_config_*` and `PNPM_CONFIG_*` variables. */
3124
+ readonly env?: Readonly<Record<string, string | undefined>> | undefined;
3125
+ }
3126
+ /**
3127
+ * Options for {@link PnpmSettings.load}.
3128
+ *
3129
+ * @public
3130
+ */
3131
+ interface PnpmSettingsLoadOptions {
3132
+ /**
3133
+ * Where pnpm would run. The workspace file is the nearest
3134
+ * `pnpm-workspace.yaml` at or above its real path, when this directory
3135
+ * belongs to that workspace, unless the environment names a workspace
3136
+ * directory (`PNPM_CONFIG_WORKSPACE_DIR`, then `NPM_CONFIG_WORKSPACE_DIR`,
3137
+ * each in either case). See {@link PnpmSettings.load} for the membership
3138
+ * rule.
3139
+ */
3140
+ readonly cwd: string;
3141
+ /**
3142
+ * The environment, as a plain record (pass `process.env` at the edge). Read
3143
+ * for `pnpm_config_*` settings, the workspace-directory override,
3144
+ * `XDG_CONFIG_HOME`, `LOCALAPPDATA` and `HOME`.
3145
+ */
3146
+ readonly env: Readonly<Record<string, string | undefined>>;
3147
+ /**
3148
+ * The platform pnpm runs on (pass `process.platform` at the edge). It picks
3149
+ * pnpm's default global config directory when `XDG_CONFIG_HOME` is unset:
3150
+ * `~/Library/Preferences/pnpm` on `"darwin"`, `%LOCALAPPDATA%\pnpm\config`
3151
+ * on `"win32"`, `~/.config/pnpm` elsewhere.
3152
+ */
3153
+ readonly platform: string;
3154
+ /**
3155
+ * The home directory. Defaults to `env.HOME`, then `env.USERPROFILE`; with
3156
+ * neither, and no `XDG_CONFIG_HOME` (or `LOCALAPPDATA` on win32), no global
3157
+ * config file is read.
3158
+ */
3159
+ readonly home?: string | undefined;
3160
+ /**
3161
+ * pnpm's global config directory, holding `config.yaml`. Overrides the
3162
+ * directory derived from the environment and platform.
3163
+ */
3164
+ readonly globalConfigDir?: string | undefined;
3165
+ }
3166
+ declare const PnpmSettings_base: Schema.Class<PnpmSettings, Schema.Struct<{
3167
+ /** The environment's pnpm settings, keyed by camelCase name, as written. */
3168
+ readonly environment: Schema.$Record<Schema.String, Schema.String>;
3169
+ /** The top-level settings of the workspace's `pnpm-workspace.yaml`. */
3170
+ readonly workspace: Schema.$Record<Schema.String, Schema.Unknown>;
3171
+ /** The top-level settings of pnpm's global `config.yaml`. */
3172
+ readonly global: Schema.$Record<Schema.String, Schema.Unknown>;
3173
+ /** The settings files that were read, lowest precedence first. */
3174
+ readonly files: Schema.$Array<Schema.String>;
3175
+ }>, {}>;
3176
+ /**
3177
+ * pnpm's effective settings: the values `pnpm config get <key>` reports for a
3178
+ * pnpm setting, merged from the sources pnpm reads with pnpm's precedence.
3179
+ *
3180
+ * @remarks
3181
+ * Build one with {@link PnpmSettings.load} (finds and reads the files through
3182
+ * `FileSystem`) or {@link PnpmSettings.fromSourcesResult} (from text you
3183
+ * already hold), then read a setting by name:
3184
+ *
3185
+ * ```ts
3186
+ * settings.minimumReleaseAge; // Option<number>
3187
+ * settings.minimumReleaseAgeExclude; // ReadonlyArray<string>
3188
+ * settings.getBoolean("minimumReleaseAgeStrict");
3189
+ * ```
3190
+ *
3191
+ * **Precedence, highest first**: a `pnpm_config_<name>` or
3192
+ * `PNPM_CONFIG_<NAME>` environment variable, the workspace root's
3193
+ * `pnpm-workspace.yaml`, then pnpm's global `config.yaml`. A higher source
3194
+ * replaces a lower one's value whole; lists are not merged. This is the order
3195
+ * pnpm 11 and pnpm 12 apply to settings such as `minimumReleaseAge` and
3196
+ * `minimumReleaseAgeExclude`.
3197
+ *
3198
+ * **What pnpm does not read for a pnpm setting, this does not read either.**
3199
+ * `.npmrc` files (project, user and global), `npm_config_*` variables and
3200
+ * the old global `rc` file carry no pnpm setting for pnpm 11 and 12: pnpm
3201
+ * takes only registry and auth keys from `.npmrc`. A registry or a credential
3202
+ * is `@effected/npm`'s `NpmConfig`, not this. Command-line `--config.*`
3203
+ * flags, pnpm's built-in defaults (`minimumReleaseAge` reads as unset here,
3204
+ * as `pnpm config get` reports it, though pnpm applies a default when it
3205
+ * installs), and the per-setting source restrictions pnpm applies to a few
3206
+ * machine-level settings (a `pnpm-workspace.yaml` cannot set `globalDir`, for
3207
+ * example) are not modelled.
3208
+ *
3209
+ * **Keys.** Every accessor takes the camelCase name pnpm writes in YAML
3210
+ * (`minimumReleaseAge`) or the kebab-case one an npmrc would use
3211
+ * (`minimum-release-age`); both name the same setting. An environment
3212
+ * variable names a setting in snake case: `pnpm_config_minimum_release_age`
3213
+ * all lowercase, or `PNPM_CONFIG_MINIMUM_RELEASE_AGE` all uppercase. A mixed
3214
+ * spelling is not a pnpm setting and is ignored, and an empty value is unset.
3215
+ * When both spellings are set, the uppercase one wins, as in pnpm 12.
3216
+ *
3217
+ * **Typed reads.** An environment value is text, read as the type the
3218
+ * accessor asks for: a number as a canonical decimal, a boolean as `true` or
3219
+ * `false`, a list as a JSON array of strings. An environment value that does
3220
+ * not read as that type is skipped, and the next source answers, as pnpm 12
3221
+ * skips it. In a file, pnpm 12 coerces boolean words (`yes`, `on`, `"true"`)
3222
+ * and digit strings (`"15"`), and so does this. A file value that still does
3223
+ * not read as the type answers `None` instead of falling through, because
3224
+ * pnpm 12 refuses to load a file with a mistyped setting; {@link
3225
+ * PnpmSettings.get} shows the raw value. A `null` in a file is unset.
3226
+ *
3227
+ * @example
3228
+ * ```ts
3229
+ * import { PnpmSettings } from "@effected/workspaces";
3230
+ * import { Effect, Option } from "effect";
3231
+ *
3232
+ * const cutoffMinutes = Effect.gen(function* () {
3233
+ * const settings = yield* PnpmSettings.load({
3234
+ * cwd: process.cwd(),
3235
+ * env: process.env,
3236
+ * platform: process.platform,
3237
+ * });
3238
+ * // Unset means pnpm's own default, 1440 minutes, not an open gate.
3239
+ * return Option.getOrElse(settings.minimumReleaseAge, () => 1440);
3240
+ * });
3241
+ * ```
3242
+ *
3243
+ * @public
3244
+ */
3245
+ export declare class PnpmSettings extends PnpmSettings_base {
3246
+ /**
3247
+ * A setting's raw value from the highest source that sets it, or `None`.
3248
+ *
3249
+ * @remarks
3250
+ * An environment value is the string as written; a file value is the
3251
+ * decoded YAML (a number, a list, a mapping). Use the typed accessors to
3252
+ * read it as a type.
3253
+ *
3254
+ * @param key - The setting, camelCase or kebab-case.
3255
+ */
3256
+ get(key: string): Option.Option<unknown>;
3257
+ /**
3258
+ * Which source {@link PnpmSettings.get} answers a setting from, or `None`
3259
+ * when no source sets it.
3260
+ *
3261
+ * @param key - The setting, camelCase or kebab-case.
3262
+ */
3263
+ origin(key: string): Option.Option<PnpmSettingOrigin>;
3264
+ /**
3265
+ * A string setting: an environment value as written, or a string in a file.
3266
+ *
3267
+ * @param key - The setting, camelCase or kebab-case.
3268
+ */
3269
+ getString(key: string): Option.Option<string>;
3270
+ /**
3271
+ * A numeric setting: a finite number, or a canonical decimal string, in any
3272
+ * source.
3273
+ *
3274
+ * @remarks
3275
+ * A canonical decimal is an optional `-`, digits with no leading zero, and
3276
+ * an optional fraction: `05`, `+5`, `0x10`, `1e2` and `1_000` are not
3277
+ * numbers here, as pnpm 12 does not read them from the environment. An
3278
+ * integer setting such as {@link PnpmSettings.minimumReleaseAge} is
3279
+ * stricter still.
3280
+ *
3281
+ * @param key - The setting, camelCase or kebab-case.
3282
+ */
3283
+ getNumber(key: string): Option.Option<number>;
3284
+ /**
3285
+ * A boolean setting: `true` or `false` in the environment, a YAML boolean
3286
+ * or a boolean word in a file.
3287
+ *
3288
+ * @remarks
3289
+ * In a file, the strings `true`, `yes`, `y` and `on` read as `true` and
3290
+ * `false`, `no`, `n` and `off` as `false`, trimmed and in any case, as
3291
+ * pnpm 12 coerces them. A number (`1`, `0`) or any other string answers
3292
+ * `None`; pnpm 12 refuses it as an invalid boolean. The environment is
3293
+ * stricter: only `true` or `false`, trimmed and lowercase.
3294
+ *
3295
+ * @param key - The setting, camelCase or kebab-case.
3296
+ */
3297
+ getBoolean(key: string): Option.Option<boolean>;
3298
+ /**
3299
+ * A list setting: a JSON array of strings in the environment, a YAML list
3300
+ * of strings in a file.
3301
+ *
3302
+ * @remarks
3303
+ * A comma-separated environment value is not a list: pnpm 12 ignores it,
3304
+ * and this skips it to the next source.
3305
+ *
3306
+ * @param key - The setting, camelCase or kebab-case.
3307
+ */
3308
+ getStringArray(key: string): Option.Option<ReadonlyArray<string>>;
3309
+ /**
3310
+ * `minimumReleaseAge`: the minutes a version must have been published before
3311
+ * pnpm installs it, or `None` when no source sets it. `None` is not an
3312
+ * open gate: pnpm then applies its built-in default of 1440 minutes.
3313
+ *
3314
+ * @remarks
3315
+ * Only a non-negative safe integer counts, as pnpm 12 reads the setting
3316
+ * (an unsigned 64-bit integer, here bounded by `Number.MAX_SAFE_INTEGER`).
3317
+ * Text, in the environment or a quoted file value, must be canonical digits
3318
+ * once trimmed: `" 30 "` reads as 30, while `05`, `+5`, `-0`, `5.0`, `0x10`
3319
+ * and `1e2` do not read at all. Such an environment value is skipped to the
3320
+ * next source; such a file value answers `None`. A YAML number is read as
3321
+ * decoded, so an unquoted `5.0` or `1e2` in a file reads as 5 or 100 where
3322
+ * pnpm 12 refuses the file.
3323
+ */
3324
+ get minimumReleaseAge(): Option.Option<number>;
3325
+ /**
3326
+ * `minimumReleaseAgeExclude`: the package patterns exempt from
3327
+ * {@link PnpmSettings.minimumReleaseAge}, empty when no source sets them.
3328
+ *
3329
+ * @remarks
3330
+ * An explicitly empty list in a higher source shadows a lower source's
3331
+ * entries, as in pnpm.
3332
+ */
3333
+ get minimumReleaseAgeExclude(): ReadonlyArray<string>;
3334
+ /**
3335
+ * The typed read every accessor shares: an environment value that does not
3336
+ * parse falls through; the first file that sets the key decides.
3337
+ */
3338
+ private read;
3339
+ /**
3340
+ * Merges pnpm's settings sources, with no IO.
3341
+ *
3342
+ * @remarks
3343
+ * Parses each YAML file, keeps the environment's `pnpm_config_*` and
3344
+ * `PNPM_CONFIG_*` variables, and records the named files in
3345
+ * `PnpmSettings.files`. Fails `"parse"` for a file that is not YAML
3346
+ * and `"shape"` for one whose document is not a mapping.
3347
+ *
3348
+ * @param sources - The workspace file, the global file and the environment.
3349
+ */
3350
+ static fromSourcesResult(sources: PnpmSettingsSources): Result.Result<PnpmSettings, PnpmSettingsError>;
3351
+ /**
3352
+ * Loads the settings pnpm would use when run in `options.cwd`.
3353
+ *
3354
+ * @remarks
3355
+ * The workspace file is found as pnpm finds it. When a
3356
+ * `PNPM_CONFIG_WORKSPACE_DIR` / `NPM_CONFIG_WORKSPACE_DIR` variable names a
3357
+ * directory (resolved against `cwd`), its `pnpm-workspace.yaml` is the
3358
+ * file, unconditionally. Otherwise `cwd` is resolved through
3359
+ * `FileSystem.realPath` (the lexical path when that fails, as in pnpm), and
3360
+ * the nearest `pnpm-workspace.yaml` at or above it is taken. A misnamed
3361
+ * manifest (`pnpm-workspace.yml`, `.pnpm-workspace.yaml`) is not a
3362
+ * workspace manifest and the ascent passes it, as pnpm 12 does; pnpm 11
3363
+ * refuses to run below one. That workspace applies only when `cwd` belongs
3364
+ * to it: `cwd`
3365
+ * is its root, `cwd` holds no project manifest (`package.json`,
3366
+ * `package.json5` or `package.yaml`), or `cwd` matches the manifest's
3367
+ * `packages:` patterns. A manifest with no `packages:` key has the root as
3368
+ * its only member, so a nested project with its own `package.json` (an
3369
+ * example app, a fixture) reads no workspace file, exactly as pnpm skips
3370
+ * it. A directory under `node_modules` or `bower_components` is never a
3371
+ * member.
3372
+ *
3373
+ * The global file is `config.yaml` in pnpm's global config directory:
3374
+ * {@link PnpmSettingsLoadOptions.globalConfigDir}, else
3375
+ * `$XDG_CONFIG_HOME/pnpm`, else the platform default (see
3376
+ * {@link PnpmSettingsLoadOptions.platform}). A file that does not exist is
3377
+ * skipped; one that cannot be read fails `"read"` (so does a project
3378
+ * manifest probe that fails other than not-found), and one that does not
3379
+ * parse fails as {@link PnpmSettings.fromSourcesResult} does.
3380
+ *
3381
+ * @param options - See {@link PnpmSettingsLoadOptions}.
3382
+ */
3383
+ static readonly load: (options: PnpmSettingsLoadOptions) => Effect.Effect<PnpmSettings, PnpmSettingsError, FileSystem.FileSystem | Path.Path>;
3384
+ }
3065
3385
  declare const PublishTarget_base: Schema.Class<PublishTarget, Schema.Struct<{
3066
3386
  /** The package name being published. */
3067
3387
  readonly name: Schema.NonEmptyString;
@@ -5074,5 +5394,5 @@ export declare const detectPackageManagerSync: (root: string, options: Workspace
5074
5394
  * @public
5075
5395
  */
5076
5396
  export declare const localExecContextSync: (cwd: string, options: FindWorkspaceRootSyncOptions) => Result.Result<Option.Option<ExecContext>, LocalExecError>;
5077
- export type { CatalogAssemblyFailure, ChangeDetectionFailure, ChangeDetectorShape, ClassifyOptions, ConfigDependencyHooksShape, DependencyDiff, DuplicateCheckOptions, FindWorkspaceRootOptions, FindWorkspaceRootSyncOptions, GetWorkspacePackagesSyncOptions, HookInjection, HookReplay, HookReplayContext, HookReplaySource, ImporterVersions, LockfileReadFailure, LockfileReaderOptions, LockfileReaderShape, PackageManagerDetectionFailure, PackageManagerDetectorShape, PackageRelease, PeerCheckOptions, PeerDependencyRules, PublishabilityDetectorShape, SyncDirectoryEntry, SyncFileSystem, SyncPath, TagClassification, TagFormatOptions, TrackingTagOptions, UnverifiedReason, VersioningDetectOptions, WorkspaceCatalogsOptions, WorkspaceCatalogsShape, WorkspaceDiscoveryFailure, WorkspaceDiscoveryOptions, WorkspaceDiscoveryShape, WorkspaceDiscoverySkip, WorkspaceDiscoverySkipKind, WorkspaceLookupFailure, WorkspaceRootShape, WorkspaceSnapshotAtFailure, WorkspaceSnapshotWorktreeFailure, WorkspaceSnapshotsOptions, WorkspaceSnapshotsShape, WorkspacesGitOptions, WorkspacesOptions, WorkspacesServices, WorkspacesSyncOptions };
5397
+ export type { CatalogAssemblyFailure, ChangeDetectionFailure, ChangeDetectorShape, ClassifyOptions, ConfigDependencyHooksShape, DependencyDiff, DuplicateCheckOptions, FindWorkspaceRootOptions, FindWorkspaceRootSyncOptions, GetWorkspacePackagesSyncOptions, HookInjection, HookReplay, HookReplayContext, HookReplaySource, ImporterVersions, LockfileReadFailure, LockfileReaderOptions, LockfileReaderShape, PackageManagerDetectionFailure, PackageManagerDetectorShape, PackageRelease, PeerCheckOptions, PeerDependencyRules, PnpmSettingOrigin, PnpmSettingsLoadOptions, PnpmSettingsSource, PnpmSettingsSources, PublishabilityDetectorShape, SyncDirectoryEntry, SyncFileSystem, SyncPath, TagClassification, TagFormatOptions, TrackingTagOptions, UnverifiedReason, VersioningDetectOptions, WorkspaceCatalogsOptions, WorkspaceCatalogsShape, WorkspaceDiscoveryFailure, WorkspaceDiscoveryOptions, WorkspaceDiscoveryShape, WorkspaceDiscoverySkip, WorkspaceDiscoverySkipKind, WorkspaceLookupFailure, WorkspaceRootShape, WorkspaceSnapshotAtFailure, WorkspaceSnapshotWorktreeFailure, WorkspaceSnapshotsOptions, WorkspaceSnapshotsShape, WorkspacesGitOptions, WorkspacesOptions, WorkspacesServices, WorkspacesSyncOptions };
5078
5398
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -6,6 +6,7 @@ import { Dependent, DuplicateCheck, DuplicateInstance, DuplicatedPackage, Duplic
6
6
  import { LockfileReadError, LockfileReader } from "./LockfileReader.js";
7
7
  import { DetectedPackageManager, PackageManagerDetectionError, PackageManagerDetector, PackageManagerEvidence, PackageManagerName } from "./PackageManagerName.js";
8
8
  import { PeerCheck, PeerParent, UnsatisfiedPeer } from "./PeerCheck.js";
9
+ import { PnpmSettings, PnpmSettingsError } from "./PnpmSettings.js";
9
10
  import { PublishTarget, PublishabilityDetector } from "./Publishability.js";
10
11
  import { ReleaseTag, TagStyle, TrackingTag, classifyTag } from "./ReleaseTag.js";
11
12
  import { VersioningStrategy, VersioningStrategyType } from "./VersioningStrategy.js";
@@ -19,4 +20,4 @@ import { PackageStateSnapshot, WorkspaceStateSnapshot } from "./WorkspaceStateSn
19
20
  import { Workspaces } from "./Workspaces.js";
20
21
  import { detectPackageManagerSync, findWorkspaceRootSync, getWorkspacePackagesSync, localExecContextSync, locateWorkspaceRootSync } from "./WorkspacesSync.js";
21
22
 
22
- export { CatalogSet, ChangeDetectionError, ChangeDetectionOptions, ChangeDetector, ConfigDependencyHooks, ConfigDependencySpec, CyclicDependencyError, DependencyGraph, Dependent, DetectedPackageManager, DuplicateCheck, DuplicateInstance, DuplicatedPackage, DuplicatedVersion, InvalidConfigDependencySpecError, LockfileReadError, LockfileReader, NoPeerDependencyRules, PackageManagerDetectionError, PackageManagerDetector, PackageManagerEvidence, PackageManagerName, PackageNotFoundError, PackageStateSnapshot, PeerCheck, PeerParent, PublishConfig, PublishTarget, PublishabilityDetector, ReleaseTag, TagStyle, TrackingTag, UnsatisfiedPeer, VersioningStrategy, VersioningStrategyType, WORKSPACE_MARKERS, WorkspaceCatalogs, WorkspaceDiscovery, WorkspaceDiscoveryError, WorkspaceInfo, WorkspaceManifestError, WorkspaceMarker, WorkspacePackage, WorkspacePatternError, WorkspaceRoot, WorkspaceRootMatch, WorkspaceRootNotFoundError, WorkspaceSnapshots, WorkspaceStateSnapshot, Workspaces, classifyTag, detectPackageManagerSync, findWorkspaceRootSync, getWorkspacePackagesSync, localExecContextSync, locateWorkspaceRootSync };
23
+ export { CatalogSet, ChangeDetectionError, ChangeDetectionOptions, ChangeDetector, ConfigDependencyHooks, ConfigDependencySpec, CyclicDependencyError, DependencyGraph, Dependent, DetectedPackageManager, DuplicateCheck, DuplicateInstance, DuplicatedPackage, DuplicatedVersion, InvalidConfigDependencySpecError, LockfileReadError, LockfileReader, NoPeerDependencyRules, PackageManagerDetectionError, PackageManagerDetector, PackageManagerEvidence, PackageManagerName, PackageNotFoundError, PackageStateSnapshot, PeerCheck, PeerParent, PnpmSettings, PnpmSettingsError, PublishConfig, PublishTarget, PublishabilityDetector, ReleaseTag, TagStyle, TrackingTag, UnsatisfiedPeer, VersioningStrategy, VersioningStrategyType, WORKSPACE_MARKERS, WorkspaceCatalogs, WorkspaceDiscovery, WorkspaceDiscoveryError, WorkspaceInfo, WorkspaceManifestError, WorkspaceMarker, WorkspacePackage, WorkspacePatternError, WorkspaceRoot, WorkspaceRootMatch, WorkspaceRootNotFoundError, WorkspaceSnapshots, WorkspaceStateSnapshot, Workspaces, classifyTag, detectPackageManagerSync, findWorkspaceRootSync, getWorkspacePackagesSync, localExecContextSync, locateWorkspaceRootSync };
@@ -7,6 +7,7 @@ import { PackageJsonFormat } from "@effected/package-json";
7
7
  const TRAPS = /* @__PURE__ */ new Set([
8
8
  "CI",
9
9
  "INIT_CWD",
10
+ "NODE_OPTIONS",
10
11
  "NODE_V8_COVERAGE",
11
12
  "PNPM_SCRIPT_SRC_DIR",
12
13
  "PNPM_PACKAGE_NAME"
@@ -21,8 +22,15 @@ const TRAP_PREFIXES = /^(npm_|pnpm_config_|yarn_)/i;
21
22
  * among them), every `YARN_*` variable (Berry lets them override
22
23
  * `.yarnrc.yml`, so `YARN_NODE_LINKER=pnp` would defeat the consumer's
23
24
  * `nodeLinker`), `CI` (Yarn Berry turns on immutable installs), `INIT_CWD`,
24
- * and `NODE_V8_COVERAGE` (a spawned manager writes coverage files that race
25
- * vitest's V8 provider).
25
+ * `NODE_V8_COVERAGE` (a spawned manager writes coverage files that race
26
+ * vitest's V8 provider), and `NODE_OPTIONS` (a workspace's `nodeOptions`, such
27
+ * as `--import=tsx`, is injected into every script a manager runs; the scratch
28
+ * consumer has no such package, so every child would die on start). Node reads
29
+ * only the exact name `NODE_OPTIONS`; the `npm_config_node_options` and
30
+ * `pnpm_config_node_options` spellings are already stripped by prefix.
31
+ * `NODE_OPTIONS` cannot be told apart from an explicit one in a whole
32
+ * `process.env`, so it is dropped outright; a bin that needs it gets it
33
+ * through `RunBinOptions.env`, which is layered after this scrub.
26
34
  *
27
35
  * Stripping `CI` does not make the child believe it runs locally: ci-info
28
36
  * also reads provider variables such as `GITHUB_ACTIONS`, which stay. That is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/workspaces",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "private": false,
5
5
  "description": "Monorepo workspace tooling as Effect services — root discovery, package enumeration, the dependency graph, package-manager detection, pnpm catalog resolution, lockfile IO and git-based change detection.",
6
6
  "keywords": [
@@ -53,13 +53,13 @@
53
53
  "dependencies": {
54
54
  "@effected/commands": "^0.20.0",
55
55
  "@effected/git": "^0.30.0",
56
- "@effected/glob": "^0.19.0",
56
+ "@effected/glob": "^0.20.0",
57
57
  "@effected/jsonc": "^0.24.0",
58
- "@effected/lockfiles": "^0.22.1",
59
- "@effected/npm": "^0.30.1",
60
- "@effected/package-json": "^0.30.0",
58
+ "@effected/lockfiles": "^0.23.1",
59
+ "@effected/npm": "^0.32.0",
60
+ "@effected/package-json": "^0.31.1",
61
61
  "@effected/semver": "^0.22.0",
62
- "@effected/walker": "^0.25.1",
62
+ "@effected/walker": "^0.26.0",
63
63
  "@effected/yaml": "^0.29.0",
64
64
  "@pnpm/catalogs.config": "^1100.0.5",
65
65
  "@pnpm/catalogs.protocol-parser": "^1100.0.0",
package/testing.d.ts CHANGED
@@ -1302,14 +1302,13 @@ export type PackageManagerName = typeof PackageManagerName.Type;
1302
1302
  * @remarks
1303
1303
  * `{ directory }` runs `npm pack` in that subdirectory of each package, whose
1304
1304
  * manifest must already be publish-ready. The default,
1305
- * `{ directory: "dist/prod/npm/pkg" }`, is `@savvy-web/bundler`'s prod npm
1305
+ * `{ directory: "dist/prod/npm/pkg" }`, is `@effected/bundler`'s npm
1306
1306
  * output: the same file list a release publishes.
1307
1307
  *
1308
1308
  * `"source"` runs `pnpm pack` in the package directory: pnpm honours
1309
1309
  * `publishConfig.directory` and rewrites `workspace:` and `catalog:`
1310
- * specifiers. Two costs. Under `@savvy-web/bundler`, `publishConfig.directory`
1311
- * names the DEV build, so source mode proves the dev artifact, not the
1312
- * published one. And pnpm can rewrite a `workspace:` specifier only in a
1310
+ * specifiers. A package that sets `publishConfig.directory` to anything but its
1311
+ * release output proves that directory, not the published one. And pnpm can rewrite a `workspace:` specifier only in a
1313
1312
  * workspace that has been `pnpm install`ed: in a never-installed one the pack
1314
1313
  * fails with `ERR_PNPM_CANNOT_RESOLVE_WORKSPACE_PROTOCOL`, which
1315
1314
  * `PackedInstall.run` reports as a `PackFailed` error naming the missing
@@ -1348,7 +1347,7 @@ interface PackedInstallClosureOptions {
1348
1347
  * For a closure member that imports a surface of a dependency existing
1349
1348
  * only in a sibling checkout's unreleased build, which the registry's copy
1350
1349
  * lacks. A directory is `npm pack`ed, so it must be
1351
- * publish-ready (for a package built by `@savvy-web/bundler`, its
1350
+ * publish-ready (for a package built by `@effected/bundler`, its
1352
1351
  * `dist/prod/npm/pkg`); a `.tgz` is used as it is. Either way the packed
1353
1352
  * manifest must be named as its key, carry no specifier only a workspace
1354
1353
  * could resolve, and it joins `PackedInstallResult.tarballs`. Each
@@ -1976,9 +1975,8 @@ export declare class PackedInstall {
1976
1975
  * (default `{ directory: "dist/prod/npm/pkg" }`), the same file whose
1977
1976
  * absence makes the run fail `PackSourceMissing`. Under `packFrom: "source"`
1978
1977
  * the packer builds nothing of its own, so nothing is checked and the
1979
- * result is ready. A package a bundler's dev build produced is no
1980
- * substitute: the prod output exists only after the prod build, which a
1981
- * test job's usual `build:dev` pre-step does not run. Pair it with
1978
+ * result is ready. The output exists only after the build, which a test job
1979
+ * has to run first. Pair it with
1982
1980
  * {@link PackedInstall.gate} to skip locally and fail under CI.
1983
1981
  *
1984
1982
  * Fails as `closure` does, plus `Io` when a path cannot be inspected.
@@ -2012,9 +2010,8 @@ export declare class PackedInstall {
2012
2010
  * unreadable `CI` counts as unset. Ready is always `"run"`;
2013
2011
  * missing is `"skip"` off CI and `"fail"` on it, so a CI job that never ran
2014
2012
  * the prod build cannot pass by silently skipping the proof. The message
2015
- * names every missing path. The test job must run the prod build
2016
- * (`build:prod` for a `@savvy-web/bundler` package) before the packed-install
2017
- * tests: a dev build leaves `dist/prod` absent.
2013
+ * names every missing path. The test job must run the build (`build` for an
2014
+ * `@effected/bundler` package) before the packed-install tests.
2018
2015
  *
2019
2016
  * @example
2020
2017
  * ```ts