@effected/workspaces 0.36.1 → 0.37.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/LockfileReader.js CHANGED
@@ -2,7 +2,8 @@ import { findLayerRoot } from "./internal/layerRoot.js";
2
2
  import { WorkspaceRoot } from "./WorkspaceRoot.js";
3
3
  import { WorkspaceDiscovery } from "./WorkspaceDiscovery.js";
4
4
  import { PackageManagerDetector } from "./PackageManagerName.js";
5
- import { Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Schema } from "effect";
5
+ import { Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Result, Schema } from "effect";
6
+ import { PackageJsonFormat } from "@effected/package-json";
6
7
  import { Lockfile, LockfileFormat, LockfileIntegrity, filenameFor } from "@effected/lockfiles";
7
8
 
8
9
  // src/LockfileReader.ts
@@ -85,13 +86,10 @@ var LockfileReader = class LockfileReader extends Context.Service()("@effected/w
85
86
  const readName = (manifestPath) => Effect.gen(function* () {
86
87
  const content = yield* fs.readFileString(manifestPath).pipe(Effect.orElseSucceed(() => ""));
87
88
  if (content === "") return Option.none();
88
- const parsed = yield* Effect.try({
89
- try: () => JSON.parse(content),
90
- catch: () => void 0
91
- }).pipe(Effect.orElseSucceed(() => void 0));
92
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return Option.none();
93
- const name = parsed.name;
94
- return typeof name === "string" && name.length > 0 ? Option.some(name) : Option.none();
89
+ return Option.flatMap(Result.getSuccess(PackageJsonFormat.parseObjectResult(content)), (parsed) => {
90
+ const name = parsed.name;
91
+ return typeof name === "string" && name.length > 0 ? Option.some(name) : Option.none();
92
+ });
95
93
  });
96
94
  const [resolveOnce, invalidate] = yield* Effect.cachedInvalidateWithTTL(init, Duration.infinity);
97
95
  const memo = Effect.onExit(resolveOnce, (exit) => Exit.isSuccess(exit) ? Effect.void : invalidate);
@@ -1,6 +1,6 @@
1
1
  import { WorkspaceManifestError } from "./WorkspacePackage.js";
2
- import { Context, Effect, FileSystem, Layer, Option, Path, Schema } from "effect";
3
- import { PackageManager } from "@effected/package-json";
2
+ import { Context, Effect, FileSystem, Layer, Option, Path, Predicate, Schema } from "effect";
3
+ import { PackageJsonFormat, PackageManager } from "@effected/package-json";
4
4
 
5
5
  // src/PackageManagerName.ts
6
6
  /**
@@ -75,8 +75,6 @@ var DetectedPackageManager = class extends Schema.Class("DetectedPackageManager"
75
75
  /** The rung of the priority order that decided the name. */
76
76
  evidence: PackageManagerEvidence
77
77
  }) {};
78
- /** Whether `value` is a non-null, non-array object — corepack's own shape test. */
79
- const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
80
78
  /**
81
79
  * The exact version a `name` + `version` pair denotes, or none when the version
82
80
  * is not an exact version.
@@ -100,9 +98,9 @@ const exactVersionOf = (name, version) => Schema.decodeUnknownOption(PackageMana
100
98
  */
101
99
  const devEnginesHint = (manifest) => {
102
100
  const devEngines = manifest.devEngines;
103
- if (!isPlainObject(devEngines)) return Option.none();
101
+ if (!Predicate.isObject(devEngines)) return Option.none();
104
102
  const slot = devEngines.packageManager;
105
- if (!isPlainObject(slot)) return Option.none();
103
+ if (!Predicate.isObject(slot)) return Option.none();
106
104
  const name = slot.name;
107
105
  if (typeof name !== "string" || name === "" || name.includes("@")) return Option.none();
108
106
  const version = slot.version;
@@ -206,19 +204,11 @@ var PackageManagerDetector = class PackageManagerDetector extends Context.Servic
206
204
  kind: "read",
207
205
  cause
208
206
  })));
209
- const parsed = yield* Effect.try({
210
- try: () => JSON.parse(content),
211
- catch: (cause) => new WorkspaceManifestError({
212
- packageJsonPath,
213
- kind: "decode",
214
- cause
215
- })
216
- });
217
- if (!isPlainObject(parsed)) return yield* Effect.fail(new WorkspaceManifestError({
207
+ const parsed = yield* Effect.fromResult(PackageJsonFormat.parseObjectResult(content)).pipe(Effect.mapError((cause) => new WorkspaceManifestError({
218
208
  packageJsonPath,
219
209
  kind: "decode",
220
- cause: /* @__PURE__ */ new Error("package.json is not a JSON object")
221
- }));
210
+ cause
211
+ })));
222
212
  return Option.some(parsed);
223
213
  });
224
214
  /**
package/PackedInstall.js CHANGED
@@ -2,6 +2,7 @@ import { WorkspaceDiscovery } from "./WorkspaceDiscovery.js";
2
2
  import { PackageManagerName } from "./PackageManagerName.js";
3
3
  import { binConflict, binTargetOf, closureOf, consumerFiles, fileOverridesOf, installArgs, overridePath, readPackedManifest, scrubEnv, versionOf } from "./internal/packedInstallPlan.js";
4
4
  import { Config, Duration, Effect, FileSystem, Option, Path, Redacted, Result, Schema, Stream } from "effect";
5
+ import { PackageJsonFormat } from "@effected/package-json";
5
6
  import { Yaml } from "@effected/yaml";
6
7
  import { Run } from "@effected/commands";
7
8
  import { ChildProcess } from "effect/process";
@@ -129,11 +130,12 @@ var InstalledConsumer = class extends Schema.Class("InstalledConsumer")({
129
130
  const manifest = path.join(dir, "package.json");
130
131
  if (!(yield* fs.exists(manifest).pipe(Effect.mapError(io(`could not inspect ${manifest}`))))) continue;
131
132
  const text = yield* fs.readFileString(manifest).pipe(Effect.mapError(io(`could not read ${manifest}`)));
132
- const parsed = yield* Effect.try({
133
- try: () => JSON.parse(text),
134
- catch: io(`${manifest} is not JSON`)
135
- });
136
- const named = typeof parsed === "object" && parsed !== null ? parsed.name : void 0;
133
+ const parsed = PackageJsonFormat.parseObjectResult(text);
134
+ if (Result.isFailure(parsed)) {
135
+ if (parsed.failure.reason === "invalid-json") return yield* io(`${manifest} is not JSON`)(parsed.failure);
136
+ continue;
137
+ }
138
+ const named = parsed.success.name;
137
139
  if (typeof named === "string") return {
138
140
  package: named,
139
141
  target
@@ -1,3 +1,4 @@
1
+ import { isStringRecord } from "./internal/guards.js";
1
2
  import { findLayerRoot } from "./internal/layerRoot.js";
2
3
  import { WorkspaceRoot } from "./WorkspaceRoot.js";
3
4
  import { inlineCatalogs, merge, normalize, rangeOf } from "./internal/catalogs.js";
@@ -5,8 +6,9 @@ import { ConfigDependencyHooks, NoPeerDependencyRules } from "./ConfigDependency
5
6
  import { LockfileReader } from "./LockfileReader.js";
6
7
  import { importerVersionsOf } from "./internal/importerVersions.js";
7
8
  import { configDependenciesOf, inlinePeerDependencyRules } from "./internal/workspaceYaml.js";
8
- import { Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, PlatformError, Schema } from "effect";
9
+ import { Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, PlatformError, Predicate, Schema } from "effect";
9
10
  import { CatalogAssemblyError, CatalogResolver, DependencyResolutionError, PartialReleaseAgeGate, ReleaseAgeGate } from "@effected/npm";
11
+ import { PackageJsonFormat } from "@effected/package-json";
10
12
  import { Yaml } from "@effected/yaml";
11
13
  import { filenameFor } from "@effected/lockfiles";
12
14
 
@@ -86,9 +88,9 @@ entries: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.String
86
88
  */
87
89
  static fromBunBlocks(blocks) {
88
90
  const raw = {};
89
- if (isObject(blocks.catalogs)) Object.assign(raw, blocks.catalogs);
90
- if (isObject(blocks.catalog)) raw.default = {
91
- ...isObject(raw.default) ? raw.default : {},
91
+ if (Predicate.isObject(blocks.catalogs)) Object.assign(raw, blocks.catalogs);
92
+ if (Predicate.isObject(blocks.catalog)) raw.default = {
93
+ ...Predicate.isObject(raw.default) ? raw.default : {},
92
94
  ...blocks.catalog
93
95
  };
94
96
  return CatalogSet.fromCatalogs(raw);
@@ -111,19 +113,11 @@ entries: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.String
111
113
  * @param text - The raw root `package.json` text.
112
114
  */
113
115
  static fromManifestWorkspaces = Effect.fn("CatalogSet.fromManifestWorkspaces")(function* (text) {
114
- const manifest = yield* Effect.try({
115
- try: () => JSON.parse(text),
116
- catch: (cause) => new CatalogAssemblyError({
117
- source: "manifest",
118
- path: "package.json",
119
- cause
120
- })
121
- });
122
- if (!isObject(manifest)) return yield* Effect.fail(new CatalogAssemblyError({
116
+ const manifest = yield* Effect.fromResult(PackageJsonFormat.parseObjectResult(text)).pipe(Effect.mapError((cause) => new CatalogAssemblyError({
123
117
  source: "manifest",
124
118
  path: "package.json",
125
- cause: /* @__PURE__ */ new Error("package.json is not a JSON object")
126
- }));
119
+ cause
120
+ })));
127
121
  const blocks = yield* manifestCatalogBlocks(manifest.workspaces);
128
122
  return CatalogSet.fromBunBlocks(blocks);
129
123
  });
@@ -163,10 +157,6 @@ entries: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.String
163
157
  return Option.fromUndefinedOr(this.entries[name]?.[dependency]);
164
158
  }
165
159
  };
166
- /** Whether `value` is a non-null, non-array object. */
167
- const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
168
- /** Whether every value in an object is a string — a usable `dependency → range` catalog. */
169
- const isStringRecord = (value) => isObject(value) && Object.values(value).every((entry) => typeof entry === "string");
170
160
  /** The `catalog` / `catalogs` blocks of a parsed pnpm-workspace document. */
171
161
  const catalogBlocksOf = (document) => {
172
162
  if (document === null || typeof document !== "object") return {};
@@ -196,7 +186,7 @@ const catalogBlocksOf = (document) => {
196
186
  * authority, exactly as on the hook path.
197
187
  */
198
188
  const inlineReleaseAge = (document) => {
199
- if (!isObject(document)) return Effect.succeed({});
189
+ if (!Predicate.isObject(document)) return Effect.succeed({});
200
190
  const raw = {};
201
191
  if (document.minimumReleaseAge !== void 0 && document.minimumReleaseAge !== null) raw.ageMinutes = document.minimumReleaseAge;
202
192
  if (document.minimumReleaseAgeExclude !== void 0 && document.minimumReleaseAgeExclude !== null) raw.exclude = document.minimumReleaseAgeExclude;
@@ -233,7 +223,7 @@ const validatedCatalogBlocks = (catalog, catalogs, labels) => {
233
223
  }
234
224
  let validCatalogs;
235
225
  if (catalogs !== void 0 && catalogs !== null) {
236
- if (!isObject(catalogs)) return Effect.fail(malformed("catalog", labels.catalogs, `"${labels.catalogs}" must map catalog names to catalogs`));
226
+ if (!Predicate.isObject(catalogs)) return Effect.fail(malformed("catalog", labels.catalogs, `"${labels.catalogs}" must map catalog names to catalogs`));
237
227
  for (const [name, entries] of Object.entries(catalogs)) if (!isStringRecord(entries)) return Effect.fail(malformed("catalog", `${labels.catalogs}.${name}`, `"${labels.catalogs}.${name}" must map dependency names to version strings`));
238
228
  validCatalogs = catalogs;
239
229
  }
@@ -249,7 +239,7 @@ const validatedCatalogBlocks = (catalog, catalogs, labels) => {
249
239
  */
250
240
  const manifestCatalogBlocks = (workspaces) => {
251
241
  if (workspaces === void 0 || workspaces === null || Array.isArray(workspaces)) return Effect.succeed({});
252
- if (!isObject(workspaces)) return Effect.fail(malformed("manifest", "package.json", `"workspaces" must be an array or object, got ${typeof workspaces}`));
242
+ if (!Predicate.isObject(workspaces)) return Effect.fail(malformed("manifest", "package.json", `"workspaces" must be an array or object, got ${typeof workspaces}`));
253
243
  if (workspaces.packages !== void 0 && workspaces.packages !== null) {
254
244
  const packages = workspaces.packages;
255
245
  if (!Array.isArray(packages) || !packages.every((entry) => typeof entry === "string")) return Effect.fail(malformed("manifest", "package.json", `"workspaces.packages" must be an array of strings`));
@@ -273,7 +263,7 @@ const manifestCatalogBlocks = (workspaces) => {
273
263
  * `inlineCatalogs` path.
274
264
  */
275
265
  const validatePnpmWorkspaceCatalogs = (document) => {
276
- if (!isObject(document)) return Effect.void;
266
+ if (!Predicate.isObject(document)) return Effect.void;
277
267
  return Effect.asVoid(validatedCatalogBlocks(document.catalog, document.catalogs, {
278
268
  catalog: "catalog",
279
269
  catalogs: "catalogs"
@@ -1,4 +1,5 @@
1
1
  import { enumerate } from "./internal/enumerate.js";
2
+ import { isStringRecord } from "./internal/guards.js";
2
3
  import { findLayerRoot } from "./internal/layerRoot.js";
3
4
  import { readPatterns } from "./internal/patterns.js";
4
5
  import { WorkspacePackage } from "./WorkspacePackage.js";
@@ -6,6 +7,7 @@ import { WorkspaceRoot } from "./WorkspaceRoot.js";
6
7
  import { Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Schema } from "effect";
7
8
  import { GlobSet } from "@effected/glob";
8
9
  import { DependencyResolutionError, WorkspaceResolver } from "@effected/npm";
10
+ import { PackageJsonFormat } from "@effected/package-json";
9
11
 
10
12
  // src/WorkspaceDiscovery.ts
11
13
  /**
@@ -118,9 +120,9 @@ const patternKindOf = (kind) => kind;
118
120
  * the lifetime of the layer. A Vitest reporter that builds the layer per call
119
121
  * site and never queries it pays nothing.
120
122
  *
121
- * The memo is **success-only**: a failure or interrupt is not cached, so an
122
- * init interrupted by an unrelated timeout cannot brick the layer, and the next
123
- * call retries.
123
+ * The memo is **success-only**: a failure is not cached, so the next call
124
+ * re-runs the init. A cached failure would replay forever, and a caller's
125
+ * `Effect.retry` could never re-run it.
124
126
  *
125
127
  * @example
126
128
  * ```ts
@@ -154,22 +156,12 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
154
156
  kind: "read",
155
157
  cause
156
158
  })));
157
- const parsed = yield* Effect.try({
158
- try: () => JSON.parse(content),
159
- catch: (cause) => new WorkspaceDiscoveryError({
160
- root,
161
- path: packageJsonPath,
162
- kind: "invalidJson",
163
- cause
164
- })
165
- });
166
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return yield* Effect.fail(new WorkspaceDiscoveryError({
159
+ const raw = yield* Effect.fromResult(PackageJsonFormat.parseObjectResult(content)).pipe(Effect.mapError((cause) => new WorkspaceDiscoveryError({
167
160
  root,
168
161
  path: packageJsonPath,
169
- kind: "invalidShape",
170
- cause: /* @__PURE__ */ new Error("package.json is not a JSON object")
171
- }));
172
- const raw = parsed;
162
+ kind: cause.reason === "invalid-json" ? "invalidJson" : "invalidShape",
163
+ cause
164
+ })));
173
165
  const name = raw.name;
174
166
  if (typeof name !== "string" || name.length === 0) return yield* Effect.fail(new WorkspaceDiscoveryError({
175
167
  root,
@@ -555,6 +547,5 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
555
547
  } };
556
548
  }));
557
549
  };
558
- const isStringRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && Object.values(value).every((entry) => typeof entry === "string");
559
550
 
560
551
  export { PackageNotFoundError, WorkspaceDiscovery, WorkspaceDiscoveryError, WorkspaceInfo, WorkspacePatternError };
@@ -1,7 +1,7 @@
1
1
  import { Effect, FileSystem, Option, Schema } from "effect";
2
2
  import { GlobPattern } from "@effected/glob";
3
+ import { Package, PackageJsonFormat } from "@effected/package-json";
3
4
  import { WorkspaceManifest } from "@effected/lockfiles";
4
- import { Package } from "@effected/package-json";
5
5
 
6
6
  // src/WorkspacePackage.ts
7
7
  const EMPTY = Object.freeze(Object.create(null));
@@ -282,14 +282,11 @@ var WorkspacePackage = class WorkspacePackage extends Schema.Class("WorkspacePac
282
282
  kind: "read",
283
283
  cause
284
284
  })));
285
- const raw = yield* Effect.try({
286
- try: () => JSON.parse(content),
287
- catch: (cause) => new WorkspaceManifestError({
288
- packageJsonPath: self.packageJsonPath,
289
- kind: "decode",
290
- cause
291
- })
292
- });
285
+ const raw = yield* Effect.fromResult(PackageJsonFormat.parseObjectResult(content)).pipe(Effect.mapError((cause) => new WorkspaceManifestError({
286
+ packageJsonPath: self.packageJsonPath,
287
+ kind: "decode",
288
+ cause
289
+ })));
293
290
  return yield* Package.decode(raw).pipe(Effect.mapError((cause) => new WorkspaceManifestError({
294
291
  packageJsonPath: self.packageJsonPath,
295
292
  kind: "decode",
package/WorkspaceRoot.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Context, Effect, FileSystem, Layer, Option, Path, Schema } from "effect";
1
+ import { Context, Effect, FileSystem, Layer, Option, Path, Result, Schema } from "effect";
2
+ import { PackageJsonFormat } from "@effected/package-json";
2
3
  import { Walker } from "@effected/walker";
3
4
 
4
5
  // src/WorkspaceRoot.ts
@@ -56,11 +57,8 @@ const isWorkspaceRoot = (dir) => Effect.gen(function* () {
56
57
  const packageJson = path.join(dir, "package.json");
57
58
  if (!(yield* fs.exists(packageJson).pipe(Effect.orElseSucceed(() => false)))) return false;
58
59
  const content = yield* fs.readFileString(packageJson).pipe(Effect.orElseSucceed(() => "{}"));
59
- const parsed = yield* Effect.try({
60
- try: () => JSON.parse(content),
61
- catch: () => void 0
62
- }).pipe(Effect.orElseSucceed(() => ({})));
63
- return parsed.workspaces !== void 0 && parsed.workspaces !== null;
60
+ const parsed = PackageJsonFormat.parseObjectResult(content);
61
+ return Result.isSuccess(parsed) && parsed.success.workspaces !== void 0 && parsed.success.workspaces !== null;
64
62
  });
65
63
  /** Whether `descendant` is `ancestor` itself or lies beneath it, on POSIX or win32 separators. */
66
64
  const isAtOrBelow = (descendant, ancestor) => {
@@ -152,7 +150,7 @@ var WorkspaceRoot = class WorkspaceRoot extends Context.Service()("@effected/wor
152
150
  static makeTest = (root) => Effect.gen(function* () {
153
151
  const path = yield* Path.Path;
154
152
  return { find: (cwd, options) => options?.stopAt !== void 0 && !isAtOrBelow(root, path.resolve(options.stopAt)) ? Effect.fail(new WorkspaceRootNotFoundError({
155
- searchPath: cwd,
153
+ searchPath: path.resolve(cwd),
156
154
  markers: WORKSPACE_MARKERS,
157
155
  stopAt: options.stopAt
158
156
  })) : Effect.succeed(root) };
@@ -1,3 +1,4 @@
1
+ import { isStringRecord } from "./internal/guards.js";
1
2
  import { findLayerRoot } from "./internal/layerRoot.js";
2
3
  import { manifestPatternsOf, pnpmPatternsOf } from "./internal/patterns.js";
3
4
  import { WorkspaceRoot } from "./WorkspaceRoot.js";
@@ -7,9 +8,10 @@ import { importerVersionsOf } from "./internal/importerVersions.js";
7
8
  import { CatalogSet, WorkspaceCatalogs, injectFromDocument } from "./WorkspaceCatalogs.js";
8
9
  import { PackageStateSnapshot, WorkspaceStateSnapshot } from "./WorkspaceStateSnapshot.js";
9
10
  import { Git } from "@effected/git";
10
- import { Context, Duration, Effect, Exit, Layer, Option } from "effect";
11
+ import { Context, Duration, Effect, Exit, Layer, Option, Predicate, Result } from "effect";
11
12
  import { GlobSet } from "@effected/glob";
12
13
  import { CatalogAssemblyError } from "@effected/npm";
14
+ import { PackageJsonFormat } from "@effected/package-json";
13
15
  import { Yaml } from "@effected/yaml";
14
16
  import { Lockfile, filenameFor } from "@effected/lockfiles";
15
17
 
@@ -25,23 +27,12 @@ const hookVersionsOf = (replays) => {
25
27
  for (const [name, replay] of Object.entries(replays)) versions[name] = replay.version;
26
28
  return versions;
27
29
  };
28
- /** Whether `value` is a non-null, non-array object. */
29
- const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
30
- /** Whether every value in a record is a string — a usable dependency map. */
31
- const isStringRecord = (value) => isObject(value) && Object.values(value).every((entry) => typeof entry === "string");
32
30
  /**
33
31
  * Parse JSON tolerantly into a plain object. At-ref content is not ours to fix:
34
32
  * a corrupt or non-object manifest degrades to `{}` rather than failing the
35
33
  * whole snapshot, matching the tolerant projection discovery already uses.
36
34
  */
37
- const parseJsonObject = (text) => {
38
- try {
39
- const parsed = JSON.parse(text);
40
- return isObject(parsed) ? parsed : {};
41
- } catch {
42
- return {};
43
- }
44
- };
35
+ const parseJsonObject = (text) => Result.getOrElse(PackageJsonFormat.parseObjectResult(text), () => ({}));
45
36
  /**
46
37
  * Project one `package.json` text (as read at a ref) into a
47
38
  * {@link PackageStateSnapshot}. An absent path, unparseable content, or a
@@ -72,7 +63,7 @@ const snapshotOf = (content, relativePath) => {
72
63
  */
73
64
  const bunInlineCatalogs = (manifest) => {
74
65
  const workspaces = manifest.workspaces;
75
- if (!isObject(workspaces)) return CatalogSet.empty();
66
+ if (!Predicate.isObject(workspaces)) return CatalogSet.empty();
76
67
  return CatalogSet.fromBunBlocks({
77
68
  catalog: workspaces.catalog,
78
69
  catalogs: workspaces.catalogs
package/Workspaces.js CHANGED
@@ -47,7 +47,7 @@ const localExecLayer = (options) => Layer.effect(LocalExec, Effect.gen(function*
47
47
  const roots = yield* WorkspaceRoot;
48
48
  const detector = yield* PackageManagerDetector;
49
49
  return { context: Effect.gen(function* () {
50
- const cwd = options?.cwd ?? globalThis.process?.cwd?.() ?? "/";
50
+ const cwd = options?.cwd ?? ".";
51
51
  const stopAt = options?.stopAt;
52
52
  const root = yield* roots.find(cwd, stopAt === void 0 ? void 0 : { stopAt }).pipe(Effect.asSome, Effect.orElseSucceed(Option.none));
53
53
  if (Option.isNone(root)) return Option.none();
@@ -290,6 +290,13 @@ var Workspaces = class {
290
290
  * ceiling with no root at or below it is the same `Option.none()` as no
291
291
  * root at all.
292
292
  *
293
+ * An omitted `cwd` is `"."`, which `WorkspaceRoot.find` resolves through
294
+ * the injected core `Path` on every call — this layer reads no `process`
295
+ * itself. Core's `Path.resolve` takes the working directory from
296
+ * `process.cwd()`, so the default needs a host that exposes `process`. On
297
+ * a host without one, an omitted `cwd` is a defect (core `Path.resolve`
298
+ * throws), not a typed failure, so pass `cwd` explicitly there.
299
+ *
293
300
  * A consumer with no monorepo never needs this layer, and therefore never
294
301
  * installs this package — `LocalExec.layerNone` and `LocalExec.layerFor`
295
302
  * are one-liners in `@effected/commands`.
@@ -327,7 +334,8 @@ var Workspaces = class {
327
334
  * @remarks
328
335
  * Composes `manifest.resolve()` with a fresh {@link Workspaces.resolverLayer}
329
336
  * per call, so the workspace root is re-discovered from `options.cwd` (or
330
- * the current `process.cwd()`) on every invocation. Consumers processing
337
+ * `"."`, the current working directory resolved through `Path`) on every
338
+ * invocation. Consumers processing
331
339
  * many manifests should check `manifest.needsResolution` first and skip
332
340
  * the call entirely when no dependency field carries a
333
341
  * `catalog:`/`workspace:` specifier — that predicate is pure and avoids
@@ -361,7 +369,8 @@ var Workspaces = class {
361
369
  * This is deliberately a **parameterized layer function, and the fresh
362
370
  * layer per call is the feature**: layers memoize by reference, so each
363
371
  * call mints an unmemoized layer whose root discovery re-runs — including
364
- * a per-call `process.cwd()` read when `options.cwd` is omitted. A build
372
+ * a per-call resolution of `"."` through `Path` when `options.cwd` is
373
+ * omitted. A build
365
374
  * tool that changes directory between manifests gets a correct
366
375
  * re-discovery each time precisely because nothing is shared across
367
376
  * calls. When you *want* sharing, bind one call's result to a `const` and
package/WorkspacesSync.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { Traversal, badMaxDepthMessage, isPruned, isValidMaxDepth, joinRelative } from "./internal/traverse.js";
2
+ import { isStringRecord } from "./internal/guards.js";
2
3
  import { manifestPatternsOf, pnpmPatternsOf } from "./internal/patterns.js";
3
4
  import { PublishConfig, WorkspacePackage } from "./WorkspacePackage.js";
4
- import { Effect, Exit, Schema } from "effect";
5
+ import { Effect, Exit, Result, Schema } from "effect";
5
6
  import { GlobSet } from "@effected/glob";
7
+ import { PackageJsonFormat } from "@effected/package-json";
6
8
  import { Yaml } from "@effected/yaml";
7
9
 
8
10
  // src/WorkspacesSync.ts
@@ -24,18 +26,11 @@ const readManifest = (fileSystem, file) => {
24
26
  cause
25
27
  };
26
28
  }
27
- let parsed;
28
- try {
29
- parsed = JSON.parse(text);
30
- } catch (cause) {
31
- return {
32
- kind: "invalidJson",
33
- cause
34
- };
35
- }
36
- return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? { raw: parsed } : {
37
- kind: "invalidShape",
38
- cause: /* @__PURE__ */ new Error("package.json is not a JSON object")
29
+ const parsed = PackageJsonFormat.parseObjectResult(text);
30
+ if (Result.isSuccess(parsed)) return { raw: parsed.success };
31
+ return {
32
+ kind: parsed.failure.reason === "invalid-json" ? "invalidJson" : "invalidShape",
33
+ cause: parsed.failure
39
34
  };
40
35
  };
41
36
  /**
@@ -51,13 +46,13 @@ const readManifest = (fileSystem, file) => {
51
46
  * syntax error — an unusable manifest either way.
52
47
  */
53
48
  const readJson = (fileSystem, file) => {
54
- let parsed;
49
+ let text;
55
50
  try {
56
- parsed = JSON.parse(fileSystem.readFile(file));
51
+ text = fileSystem.readFile(file);
57
52
  } catch {
58
53
  return;
59
54
  }
60
- return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
55
+ return Result.getOrUndefined(PackageJsonFormat.parseObjectResult(text));
61
56
  };
62
57
  /** Whether `dir` is a directory. Never throws — a throwing consumer op reads as `false`. */
63
58
  const isDirectory = (fileSystem, dir) => {
@@ -218,7 +213,7 @@ const readPackageSync = (options, root, directory, relativePath) => {
218
213
  kind: "invalidShape",
219
214
  cause: /* @__PURE__ */ new Error("version must be a non-empty string")
220
215
  };
221
- const stringRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && Object.values(value).every((entry) => typeof entry === "string") ? value : void 0;
216
+ const stringRecord = (value) => isStringRecord(value) ? value : void 0;
222
217
  const publishConfig = raw.publishConfig;
223
218
  const config = publishConfig !== null && typeof publishConfig === "object" ? Effect.runSyncExit(Schema.decodeUnknownEffect(PublishConfig)(publishConfig)) : void 0;
224
219
  return WorkspacePackage.make({
package/index.d.ts CHANGED
@@ -533,9 +533,10 @@ interface WorkspaceDiscoveryOptions {
533
533
  /**
534
534
  * The directory the workspace root is resolved from.
535
535
  *
536
- * @defaultValue `process.cwd()`, read lazily on first use — so a
537
- * `process.chdir` between providing the layer and the first call is
538
- * honoured.
536
+ * @defaultValue `"."`, resolved through the injected core `Path` on each
537
+ * use — so a `process.chdir` between providing the layer and the first
538
+ * call is honoured. `Path.resolve` reads `process.cwd()`, so the default
539
+ * needs a host that exposes `process`.
539
540
  */
540
541
  readonly cwd?: string;
541
542
  /**
@@ -655,9 +656,9 @@ declare const WorkspaceDiscovery_base: Context.ServiceClass<WorkspaceDiscovery,
655
656
  * the lifetime of the layer. A Vitest reporter that builds the layer per call
656
657
  * site and never queries it pays nothing.
657
658
  *
658
- * The memo is **success-only**: a failure or interrupt is not cached, so an
659
- * init interrupted by an unrelated timeout cannot brick the layer, and the next
660
- * call retries.
659
+ * The memo is **success-only**: a failure is not cached, so the next call
660
+ * re-runs the init. A cached failure would replay forever, and a caller's
661
+ * `Effect.retry` could never re-run it.
661
662
  *
662
663
  * @example
663
664
  * ```ts
@@ -2051,7 +2052,8 @@ interface LockfileReaderOptions {
2051
2052
  /**
2052
2053
  * The directory the workspace root is resolved from.
2053
2054
  *
2054
- * @defaultValue `process.cwd()`, read lazily on first use.
2055
+ * @defaultValue `"."`, resolved through the injected core `Path` on each
2056
+ * use (the working directory on a host that exposes `process`).
2055
2057
  */
2056
2058
  readonly cwd?: string;
2057
2059
  /**
@@ -2392,7 +2394,8 @@ interface WorkspaceCatalogsOptions {
2392
2394
  /**
2393
2395
  * The directory the workspace root is resolved from.
2394
2396
  *
2395
- * @defaultValue `process.cwd()`, read lazily on first use.
2397
+ * @defaultValue `"."`, resolved through the injected core `Path` on each
2398
+ * use (the working directory on a host that exposes `process`).
2396
2399
  */
2397
2400
  readonly cwd?: string;
2398
2401
  /**
@@ -3830,9 +3833,10 @@ interface WorkspaceSnapshotsOptions {
3830
3833
  /**
3831
3834
  * The directory `at(ref)` resolves the workspace root from.
3832
3835
  *
3833
- * @defaultValue `process.cwd()`, read lazily on first use inside
3834
- * `Effect.suspend`, so a `process.chdir` between providing the layer and the
3835
- * first call is honoured.
3836
+ * @defaultValue `"."`, resolved through the injected core `Path` on each
3837
+ * use, so a `process.chdir` between providing the layer and the first call
3838
+ * is honoured. `Path.resolve` reads `process.cwd()`, so the default needs
3839
+ * a host that exposes `process`.
3836
3840
  */
3837
3841
  readonly cwd?: string;
3838
3842
  /**
@@ -4032,7 +4036,8 @@ interface WorkspacesOptions extends WorkspaceDiscoveryOptions, LockfileReaderOpt
4032
4036
  * The directory every root-consuming service resolves the workspace root
4033
4037
  * from — one explicit concern, applied uniformly.
4034
4038
  *
4035
- * @defaultValue `process.cwd()`, read lazily on first use.
4039
+ * @defaultValue `"."`, resolved through the injected core `Path` on
4040
+ * first use — the working directory on a host that exposes `process`.
4036
4041
  */
4037
4042
  readonly cwd?: string;
4038
4043
  /**
@@ -4297,6 +4302,13 @@ export declare class Workspaces {
4297
4302
  * ceiling with no root at or below it is the same `Option.none()` as no
4298
4303
  * root at all.
4299
4304
  *
4305
+ * An omitted `cwd` is `"."`, which `WorkspaceRoot.find` resolves through
4306
+ * the injected core `Path` on every call — this layer reads no `process`
4307
+ * itself. Core's `Path.resolve` takes the working directory from
4308
+ * `process.cwd()`, so the default needs a host that exposes `process`. On
4309
+ * a host without one, an omitted `cwd` is a defect (core `Path.resolve`
4310
+ * throws), not a typed failure, so pass `cwd` explicitly there.
4311
+ *
4300
4312
  * A consumer with no monorepo never needs this layer, and therefore never
4301
4313
  * installs this package — `LocalExec.layerNone` and `LocalExec.layerFor`
4302
4314
  * are one-liners in `@effected/commands`.
@@ -4337,7 +4349,8 @@ export declare class Workspaces {
4337
4349
  * @remarks
4338
4350
  * Composes `manifest.resolve()` with a fresh {@link Workspaces.resolverLayer}
4339
4351
  * per call, so the workspace root is re-discovered from `options.cwd` (or
4340
- * the current `process.cwd()`) on every invocation. Consumers processing
4352
+ * `"."`, the current working directory resolved through `Path`) on every
4353
+ * invocation. Consumers processing
4341
4354
  * many manifests should check `manifest.needsResolution` first and skip
4342
4355
  * the call entirely when no dependency field carries a
4343
4356
  * `catalog:`/`workspace:` specifier — that predicate is pure and avoids
@@ -4371,7 +4384,8 @@ export declare class Workspaces {
4371
4384
  * This is deliberately a **parameterized layer function, and the fresh
4372
4385
  * layer per call is the feature**: layers memoize by reference, so each
4373
4386
  * call mints an unmemoized layer whose root discovery re-runs — including
4374
- * a per-call `process.cwd()` read when `options.cwd` is omitted. A build
4387
+ * a per-call resolution of `"."` through `Path` when `options.cwd` is
4388
+ * omitted. A build
4375
4389
  * tool that changes directory between manifests gets a correct
4376
4390
  * re-discovery each time precisely because nothing is shared across
4377
4391
  * calls. When you *want* sharing, bind one call's result to a `const` and
@@ -4577,9 +4591,14 @@ type WorkspaceDiscoverySkipKind = Exclude<WorkspaceDiscoveryError["kind"], "inva
4577
4591
  * plausible empty array indistinguishable from "no workspaces configured". The
4578
4592
  * fields mirror
4579
4593
  * `WorkspaceDiscoveryError`: `root`, `path`, `kind`, and on `cause` either the
4580
- * caught throwable (`read` / `invalidJson`) or an `Error` carrying the same
4581
- * sentence the Effect surface fails with (`invalidShape`). Only `missingName`
4582
- * has `cause: undefined` — the field is simply absent, and nothing threw.
4594
+ * value the consumer's `readFile` threw (`read`) or the same
4595
+ * `PackageJsonSyntaxError` from `@effected/package-json` that the Effect
4596
+ * surface attaches (`invalidJson`, reason `"invalid-json"`, with the
4597
+ * `SyntaxError` on its own `cause`; `invalidShape` for a manifest that is not
4598
+ * an object, reason `"not-an-object"`), or, for an `invalidShape` `version`, an
4599
+ * `Error` carrying the same sentence the Effect surface fails with. Only
4600
+ * `missingName` has `cause: undefined` — the field is simply absent, and
4601
+ * nothing threw.
4583
4602
  *
4584
4603
  * @public
4585
4604
  */
@@ -4591,9 +4610,10 @@ interface WorkspaceDiscoverySkip {
4591
4610
  /** Why it was skipped. */
4592
4611
  readonly kind: WorkspaceDiscoverySkipKind;
4593
4612
  /**
4594
- * The thrown value for `read` and `invalidJson`, an `Error` whose message
4595
- * matches the Effect surface's for `invalidShape`, and `undefined` for
4596
- * `missingName` alone.
4613
+ * The thrown value for `read`; a `PackageJsonSyntaxError` for `invalidJson`
4614
+ * (the JSON `SyntaxError` sits on its `cause`) and for a non-object
4615
+ * `invalidShape`; an `Error` whose message matches the Effect surface's for
4616
+ * an `invalidShape` `version`; and `undefined` for `missingName` alone.
4597
4617
  */
4598
4618
  readonly cause: unknown;
4599
4619
  }
@@ -1,6 +1,6 @@
1
1
  import { carries, hooksError, ioOrNone, manifestVersion, sideLabel } from "./configDependencyShared.js";
2
2
  import { splitConfigDependencySpec } from "./configDependencySpecGrammar.js";
3
- import { Array, Duration, Effect, Exit, Option, Predicate, Result } from "effect";
3
+ import { Array, Config, Duration, Effect, Exit, Option, Predicate, Result } from "effect";
4
4
  import { PackageManagerCache } from "@effected/npm";
5
5
  import { Yaml } from "@effected/yaml";
6
6
  import { PnpmEnvLockfile } from "@effected/lockfiles";
@@ -99,25 +99,48 @@ const storesFromLinks = (root) => Effect.gen(function* () {
99
99
  return stores;
100
100
  });
101
101
  /**
102
- * Rung 3 of store discovery: the conventional store roots — `$PNPM_HOME/store`,
103
- * `$XDG_DATA_HOME/pnpm/store`, `%LOCALAPPDATA%\pnpm\store` on Windows, then
104
- * the platform default from `@effected/npm`'s cache table — each expanded to
105
- * its `v*` subdirectories (a store root holds one directory per store
106
- * version, `v11` today).
102
+ * An environment variable through `Config`, as an `Option`. Unset and empty
103
+ * are both none: core's env provider already maps `""` to missing, and the
104
+ * explicit filter keeps that true under any provider (`if (env.X)` treated
105
+ * `""` as unset, and `join("", "store")` would be a cwd-relative path). A
106
+ * provider failure is absorbed too — store discovery is best-effort.
107
107
  */
108
- const storesFromEnvironment = (root) => Effect.gen(function* () {
109
- const env = process.env;
108
+ const envVar = (name) => Config.option(Config.String(name)).pipe(Effect.map(Option.filter((value) => value !== "")), Effect.orElseSucceed(() => Option.none()));
109
+ /**
110
+ * The conventional store ROOTS rung 3 searches, in order — before any of them
111
+ * is expanded to its `v*` subdirectories. The environment is read through
112
+ * `Config`, so a test swaps `ConfigProvider` instead of mutating
113
+ * `process.env`; the platform and home directory stay ambient (this module is
114
+ * Node-coupled by design, see the header).
115
+ *
116
+ * @internal
117
+ */
118
+ const environmentStoreRoots = Effect.gen(function* () {
119
+ const pnpmHome = yield* envVar("PNPM_HOME");
120
+ const xdgDataHome = yield* envVar("XDG_DATA_HOME");
121
+ const localAppData = yield* envVar("LOCALAPPDATA");
110
122
  const platform = process.platform;
111
123
  const roots = [];
112
- if (env.PNPM_HOME) roots.push(join(env.PNPM_HOME, "store"));
113
- if (env.XDG_DATA_HOME) roots.push(join(env.XDG_DATA_HOME, "pnpm", "store"));
114
- if (platform === "win32" && env.LOCALAPPDATA) roots.push(join(env.LOCALAPPDATA, "pnpm", "store"));
124
+ if (Option.isSome(pnpmHome)) roots.push(join(pnpmHome.value, "store"));
125
+ if (Option.isSome(xdgDataHome)) roots.push(join(xdgDataHome.value, "pnpm", "store"));
126
+ if (platform === "win32" && Option.isSome(localAppData)) roots.push(join(localAppData.value, "pnpm", "store"));
115
127
  const home = homedir();
116
128
  roots.push(PackageManagerCache.defaultDirectory("pnpm", {
117
129
  platform,
118
130
  home
119
131
  }));
120
132
  if (platform !== "win32") roots.push(join(home, ".local", "share", "pnpm", "store"));
133
+ return roots;
134
+ });
135
+ /**
136
+ * Rung 3 of store discovery: the conventional store roots — `$PNPM_HOME/store`,
137
+ * `$XDG_DATA_HOME/pnpm/store`, `%LOCALAPPDATA%\pnpm\store` on Windows, then
138
+ * the platform default from `@effected/npm`'s cache table — each expanded to
139
+ * its `v*` subdirectories (a store root holds one directory per store
140
+ * version, `v11` today).
141
+ */
142
+ const storesFromEnvironment = (root) => Effect.gen(function* () {
143
+ const roots = yield* environmentStoreRoots;
121
144
  const stores = [];
122
145
  for (const storeRoot of roots) {
123
146
  const versions = (yield* entriesOf(root, storeRoot)).filter((entry) => /^v\d+$/.test(entry)).sort((a, b) => Number(b.slice(1)) - Number(a.slice(1)));
@@ -330,4 +353,4 @@ const lookupPnpmfiles = (entries, configDependencies) => Effect.flatMap(declared
330
353
  });
331
354
  }));
332
355
 
333
- export { lookupPnpmfiles, resolvePnpmfiles };
356
+ export { environmentStoreRoots, lookupPnpmfiles, resolvePnpmfiles };
@@ -1,5 +1,6 @@
1
- import { Effect, Option, Predicate } from "effect";
1
+ import { Effect, Option, Predicate, Result } from "effect";
2
2
  import { CatalogAssemblyError } from "@effected/npm";
3
+ import { PackageJsonFormat } from "@effected/package-json";
3
4
  import { readFile } from "node:fs/promises";
4
5
  import { join } from "node:path";
5
6
 
@@ -38,13 +39,13 @@ const carries = (manifest, declared) => manifest._tag === "version" && manifest.
38
39
  */
39
40
  const manifestVersion = (name, dir) => ioOrNone(name, () => readFile(join(dir, "package.json"), "utf8")).pipe(Effect.flatMap((text) => {
40
41
  if (Option.isNone(text)) return Effect.succeed(ABSENT);
41
- return Effect.try({
42
- try: () => JSON.parse(text.value),
43
- catch: (cause) => hooksError(name, cause)
44
- }).pipe(Effect.map((parsed) => Predicate.isObject(parsed) && typeof parsed.version === "string" && parsed.version !== "" ? {
42
+ const parsed = PackageJsonFormat.parseObjectResult(text.value);
43
+ if (Result.isFailure(parsed)) return parsed.failure.reason === "invalid-json" ? Effect.fail(hooksError(name, parsed.failure)) : Effect.succeed(UNVERSIONED);
44
+ const version = parsed.success.version;
45
+ return Effect.succeed(typeof version === "string" && version !== "" ? {
45
46
  _tag: "version",
46
- version: parsed.version
47
- } : UNVERSIONED));
47
+ version
48
+ } : UNVERSIONED);
48
49
  }));
49
50
 
50
51
  export { carries, hooksError, ioOrNone, manifestVersion, messageOf, sideLabel };
@@ -0,0 +1,12 @@
1
+ import { Predicate } from "effect";
2
+
3
+ // src/internal/guards.ts
4
+ /**
5
+ * Whether `value` is a plain object (not `null`, not an array) whose every own
6
+ * enumerable value is a string — the shape of a dependency or catalog map.
7
+ *
8
+ * @internal
9
+ */
10
+ const isStringRecord = (value) => Predicate.isObject(value) && Object.values(value).every(Predicate.isString);
11
+
12
+ export { isStringRecord };
@@ -1,13 +1,19 @@
1
- import { Effect } from "effect";
2
-
3
1
  // src/internal/layerRoot.ts
4
2
  /**
5
- * Resolve the workspace root a layer's options name. `Effect.suspend` so the
6
- * ambient `process.cwd()` is read at first use, not at layer construction.
3
+ * Resolve the workspace root a layer's options name.
4
+ *
5
+ * An omitted `cwd` is passed to `find` as `"."`, which the live
6
+ * `WorkspaceRoot` resolves through the injected core `Path` at call time — so
7
+ * no `process` read happens here, a `process.chdir` between provide and first
8
+ * use is honoured, and a test can swap `Path` to control the default. Core's
9
+ * `Path.resolve` reads the working directory from `process.cwd()`, so the
10
+ * default still needs a host that exposes `process`: on a host without one,
11
+ * an omitted `cwd` is a defect (core `Path.resolve` throws), not a typed
12
+ * failure — pass `cwd` explicitly there.
7
13
  */
8
- const findLayerRoot = (roots, options) => Effect.suspend(() => {
14
+ const findLayerRoot = (roots, options) => {
9
15
  const stopAt = options?.stopAt;
10
- return roots.find(options?.cwd ?? process.cwd(), stopAt === void 0 ? void 0 : { stopAt });
11
- });
16
+ return roots.find(options?.cwd ?? ".", stopAt === void 0 ? void 0 : { stopAt });
17
+ };
12
18
 
13
19
  export { findLayerRoot };
@@ -1,5 +1,6 @@
1
1
  import { RUNTIME_DEPENDENCY_FIELDS } from "./dependencyFields.js";
2
2
  import { Predicate, Result } from "effect";
3
+ import { PackageJsonFormat } from "@effected/package-json";
3
4
 
4
5
  // src/internal/packedInstallPlan.ts
5
6
  /** Variables that carry the PARENT run's context into a child package manager. */
@@ -166,16 +167,9 @@ const installArgs = (manager, version) => {
166
167
  * is left alone: it resolves wherever the file exists.
167
168
  */
168
169
  const UNRESOLVABLE = /^(?:workspace:|catalog:|link:|file:(?!\/))/;
169
- /** Parse a packed manifest into the facts the run checks; the failure is the parse error or a non-object. */
170
- const readPackedManifest = (manifestJson) => {
171
- let manifest;
172
- try {
173
- manifest = JSON.parse(manifestJson);
174
- } catch (cause) {
175
- return Result.fail(cause);
176
- }
177
- if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) return Result.fail(/* @__PURE__ */ new Error("package.json is not an object"));
178
- const record = manifest;
170
+ /** Parse a packed manifest into the facts the run checks; the failure says whether it was not JSON or not an object. */
171
+ const readPackedManifest = (manifestJson) => Result.map(PackageJsonFormat.parseObjectResult(manifestJson), factsOf);
172
+ const factsOf = (record) => {
179
173
  const name = typeof record.name === "string" ? record.name : void 0;
180
174
  const unresolved = RUNTIME_DEPENDENCY_FIELDS.flatMap((field) => {
181
175
  const block = record[field];
@@ -183,12 +177,11 @@ const readPackedManifest = (manifestJson) => {
183
177
  return Object.entries(block).filter(([, spec]) => typeof spec === "string" && UNRESOLVABLE.test(spec)).map(([dependency, spec]) => `${field}.${dependency}: ${String(spec)}`);
184
178
  });
185
179
  const bin = record.bin;
186
- const bins = typeof bin === "string" ? name === void 0 ? [] : [name.replace(/^@[^/]+\//, "")] : typeof bin === "object" && bin !== null && !Array.isArray(bin) ? Object.keys(bin) : [];
187
- return Result.succeed({
180
+ return {
188
181
  name,
189
182
  unresolved,
190
- bins
191
- });
183
+ bins: typeof bin === "string" ? name === void 0 ? [] : [name.replace(/^@[^/]+\//, "")] : Predicate.isObject(bin) ? Object.keys(bin) : []
184
+ };
192
185
  };
193
186
  /**
194
187
  * The file a manifest's `bin` declares for `name`: a `bin` object's entry, or
@@ -196,16 +189,12 @@ const readPackedManifest = (manifestJson) => {
196
189
  * the manifest is not a JSON object or declares no such bin.
197
190
  */
198
191
  const binTargetOf = (manifestJson, name) => {
199
- let manifest;
200
- try {
201
- manifest = JSON.parse(manifestJson);
202
- } catch {
203
- return;
204
- }
205
- if (!Predicate.isObject(manifest) || Array.isArray(manifest)) return void 0;
192
+ const parsed = PackageJsonFormat.parseObjectResult(manifestJson);
193
+ if (Result.isFailure(parsed)) return void 0;
194
+ const manifest = parsed.success;
206
195
  const bin = manifest.bin;
207
196
  if (typeof bin === "string") return typeof manifest.name === "string" && manifest.name.replace(/^@[^/]+\//, "") === name ? bin : void 0;
208
- if (!Predicate.isObject(bin) || Array.isArray(bin)) return void 0;
197
+ if (!Predicate.isObject(bin)) return void 0;
209
198
  const target = bin[name];
210
199
  return typeof target === "string" && Object.hasOwn(bin, name) ? target : void 0;
211
200
  };
@@ -238,7 +227,7 @@ const BARE_NAME = /^(?:@[^/@\s>]+\/)?[^/@\s>]+$/;
238
227
  */
239
228
  const fileOverridesOf = (document) => {
240
229
  const out = Object.create(null);
241
- if (!Predicate.isObject(document) || !Predicate.isObject(document.overrides) || Array.isArray(document.overrides)) return out;
230
+ if (!Predicate.isObject(document) || !Predicate.isObject(document.overrides)) return out;
242
231
  for (const [name, spec] of Object.entries(document.overrides)) {
243
232
  if (name === "__proto__") continue;
244
233
  if (typeof spec === "string" && spec.startsWith("file:") && BARE_NAME.test(name)) out[name] = spec.slice(5);
@@ -1,4 +1,5 @@
1
- import { Effect, FileSystem, Path } from "effect";
1
+ import { Effect, FileSystem, Path, Result } from "effect";
2
+ import { PackageJsonFormat } from "@effected/package-json";
2
3
  import { Yaml } from "@effected/yaml";
3
4
 
4
5
  // src/internal/patterns.ts
@@ -48,15 +49,14 @@ const readPatterns = (root) => Effect.gen(function* () {
48
49
  kind: "read",
49
50
  cause
50
51
  })));
51
- const manifest = yield* Effect.try({
52
- try: () => JSON.parse(content),
53
- catch: (cause) => ({
54
- path: manifestPath,
55
- kind: "invalidJson",
56
- cause
57
- })
52
+ const manifest = PackageJsonFormat.parseObjectResult(content);
53
+ if (Result.isSuccess(manifest)) return manifestPatternsOf(manifest.success);
54
+ if (manifest.failure.reason === "not-an-object") return [];
55
+ return yield* Effect.fail({
56
+ path: manifestPath,
57
+ kind: "invalidJson",
58
+ cause: manifest.failure
58
59
  });
59
- return manifestPatternsOf(manifest);
60
60
  });
61
61
 
62
62
  export { manifestPatternsOf, pnpmPatternsOf, readPatterns, stringsOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/workspaces",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
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": [
@@ -51,16 +51,16 @@
51
51
  "./package.json": "./package.json"
52
52
  },
53
53
  "dependencies": {
54
- "@effected/commands": "^0.15.0",
55
- "@effected/git": "^0.24.0",
54
+ "@effected/commands": "^0.15.1",
55
+ "@effected/git": "^0.25.0",
56
56
  "@effected/glob": "^0.14.0",
57
- "@effected/jsonc": "^0.19.0",
58
- "@effected/lockfiles": "^0.19.1",
59
- "@effected/npm": "^0.25.0",
60
- "@effected/package-json": "^0.24.1",
61
- "@effected/semver": "^0.15.0",
57
+ "@effected/jsonc": "^0.20.0",
58
+ "@effected/lockfiles": "^0.19.2",
59
+ "@effected/npm": "^0.26.0",
60
+ "@effected/package-json": "^0.25.0",
61
+ "@effected/semver": "^0.16.0",
62
62
  "@effected/walker": "^0.19.0",
63
- "@effected/yaml": "^0.23.0",
63
+ "@effected/yaml": "^0.24.0",
64
64
  "@pnpm/catalogs.config": "^1100.0.5",
65
65
  "@pnpm/catalogs.protocol-parser": "^1100.0.0",
66
66
  "@pnpm/catalogs.resolver": "^1100.0.0",
package/testing.d.ts CHANGED
@@ -525,9 +525,10 @@ interface WorkspaceDiscoveryOptions {
525
525
  /**
526
526
  * The directory the workspace root is resolved from.
527
527
  *
528
- * @defaultValue `process.cwd()`, read lazily on first use — so a
529
- * `process.chdir` between providing the layer and the first call is
530
- * honoured.
528
+ * @defaultValue `"."`, resolved through the injected core `Path` on each
529
+ * use — so a `process.chdir` between providing the layer and the first
530
+ * call is honoured. `Path.resolve` reads `process.cwd()`, so the default
531
+ * needs a host that exposes `process`.
531
532
  */
532
533
  readonly cwd?: string;
533
534
  /**
@@ -647,9 +648,9 @@ declare const WorkspaceDiscovery_base: Context.ServiceClass<WorkspaceDiscovery,
647
648
  * the lifetime of the layer. A Vitest reporter that builds the layer per call
648
649
  * site and never queries it pays nothing.
649
650
  *
650
- * The memo is **success-only**: a failure or interrupt is not cached, so an
651
- * init interrupted by an unrelated timeout cannot brick the layer, and the next
652
- * call retries.
651
+ * The memo is **success-only**: a failure is not cached, so the next call
652
+ * re-runs the init. A cached failure would replay forever, and a caller's
653
+ * `Effect.retry` could never re-run it.
653
654
  *
654
655
  * @example
655
656
  * ```ts