@effected/workspaces 0.38.1 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { WorkspaceManifestError } from "./WorkspacePackage.js";
2
+ import { MARKER_FILES, decidePackageManager } from "./internal/packageManagerDecision.js";
2
3
  import { Context, Effect, FileSystem, Layer, Option, Path, Predicate, Schema } from "effect";
3
- import { PackageJsonFormat, PackageManager } from "@effected/package-json";
4
+ import { PackageJsonFormat } from "@effected/package-json";
4
5
 
5
6
  // src/PackageManagerName.ts
6
7
  /**
@@ -76,49 +77,6 @@ var DetectedPackageManager = class extends Schema.Class("DetectedPackageManager"
76
77
  evidence: PackageManagerEvidence
77
78
  }) {};
78
79
  /**
79
- * The exact version a `name` + `version` pair denotes, or none when the version
80
- * is not an exact version.
81
- *
82
- * Reuses the corepack `name@version+integrity` grammar rather than a second
83
- * parser, so a `devEngines` version carrying a hash (`11.11.0+sha512.…`)
84
- * normalizes to the same `11.11.0` the
85
- * top-level field reports — and a *range* (`^11`, `11.x`) yields none, because a
86
- * range is not a version and corepack will not run one either.
87
- */
88
- const exactVersionOf = (name, version) => Schema.decodeUnknownOption(PackageManager.FromString)(`${name}@${version}`).pipe(Option.map((pm) => pm.version));
89
- /**
90
- * The `devEngines.packageManager` hint, or none.
91
- *
92
- * Every malformed shape corepack itself tolerates is tolerated here by *ignoring
93
- * the field*, never by failing detection: a non-object `devEngines`, a
94
- * non-object `packageManager`, an **array** of them (corepack does not support
95
- * arrays in this slot and falls back), a missing or non-string `name`, and a
96
- * `name` containing `@`. A version that is not an exact version is dropped on its
97
- * own, keeping the name — the name is still a valid disambiguator.
98
- */
99
- const devEnginesHint = (manifest) => {
100
- const devEngines = manifest.devEngines;
101
- if (!Predicate.isObject(devEngines)) return Option.none();
102
- const slot = devEngines.packageManager;
103
- if (!Predicate.isObject(slot)) return Option.none();
104
- const name = slot.name;
105
- if (typeof name !== "string" || name === "" || name.includes("@")) return Option.none();
106
- const version = slot.version;
107
- return Option.some({
108
- name,
109
- version: typeof version === "string" && version !== "" ? exactVersionOf(name, version) : Option.none()
110
- });
111
- };
112
- /** The corepack top-level `packageManager` hint, or none when absent or malformed. */
113
- const corepackHint = (manifest) => {
114
- const raw = manifest.packageManager;
115
- if (typeof raw !== "string") return Option.none();
116
- return Schema.decodeUnknownOption(PackageManager.FromString)(raw).pipe(Option.map((pm) => ({
117
- name: pm.name,
118
- version: Option.some(pm.version)
119
- })));
120
- };
121
- /**
122
80
  * Raised when a directory carries no lockfile and no workspace configuration,
123
81
  * so no package manager can be attributed to it.
124
82
  *
@@ -211,98 +169,15 @@ var PackageManagerDetector = class PackageManagerDetector extends Context.Servic
211
169
  })));
212
170
  return Option.some(parsed);
213
171
  });
214
- /**
215
- * The manager name the manifest declares, if any.
216
- *
217
- * `devEngines` first — it is authoritative for the name, and corepack errors
218
- * when the top-level field contradicts it.
219
- */
220
- const declaredName = (hints) => Option.map(Option.orElse(hints.devEngines, () => hints.corepack), (hint) => hint.name);
221
- /** Whether the manifest declares `name` as its manager. */
222
- const namesManager = (hints, name) => Option.contains(declaredName(hints), name);
223
- /**
224
- * The version to report for the manager that was detected — none unless a
225
- * field naming *that* manager carries one.
226
- *
227
- * The top-level `packageManager` wins when it names the manager, because it
228
- * is the field carrying the integrity hash; `devEngines` supplies the version
229
- * when it does not.
230
- */
231
- const versionFor = (hints, name) => {
232
- if (!namesManager(hints, name)) return Option.none();
233
- const fromCorepack = Option.flatMap(hints.corepack, (hint) => hint.name === name ? hint.version : Option.none());
234
- return Option.orElse(fromCorepack, () => Option.flatMap(hints.devEngines, (hint) => hint.name === name ? hint.version : Option.none()));
235
- };
236
172
  const detect = Effect.fn("PackageManagerDetector.detect")(function* (root) {
237
173
  const manifest = yield* manifestOf(root);
238
- const hints = {
239
- devEngines: Option.flatMap(manifest, devEnginesHint),
240
- corepack: Option.flatMap(manifest, corepackHint)
241
- };
242
- if (yield* has(root, "pnpm-workspace.yaml")) return DetectedPackageManager.make({
243
- name: "pnpm",
244
- version: versionFor(hints, "pnpm"),
245
- runtime: "node",
246
- evidence: "pnpm-workspace.yaml"
247
- });
248
- const bunLock = (yield* has(root, "bun.lock")) ? Option.some("bun.lock") : (yield* has(root, "bun.lockb")) ? Option.some("bun.lockb") : Option.none();
249
- if (Option.isSome(bunLock) && namesManager(hints, "bun")) return DetectedPackageManager.make({
250
- name: "bun",
251
- version: versionFor(hints, "bun"),
252
- runtime: "bun",
253
- evidence: bunLock.value
254
- });
255
- if ((yield* has(root, "yarn.lock")) && namesManager(hints, "yarn")) return DetectedPackageManager.make({
256
- name: "yarn",
257
- version: versionFor(hints, "yarn"),
258
- runtime: "node",
259
- evidence: "yarn.lock"
260
- });
261
- const workspaces = Option.map(manifest, (fields) => fields.workspaces);
262
- if (Option.isSome(workspaces) && workspaces.value !== void 0 && workspaces.value !== null) return DetectedPackageManager.make({
263
- name: "npm",
264
- version: versionFor(hints, "npm"),
265
- runtime: "node",
266
- evidence: "package.json#workspaces"
267
- });
268
- if (yield* has(root, "pnpm-lock.yaml")) return DetectedPackageManager.make({
269
- name: "pnpm",
270
- version: versionFor(hints, "pnpm"),
271
- runtime: "node",
272
- evidence: "pnpm-lock.yaml"
273
- });
274
- if (Option.isSome(bunLock) && namesManager(hints, "bun")) return DetectedPackageManager.make({
275
- name: "bun",
276
- version: versionFor(hints, "bun"),
277
- runtime: "bun",
278
- evidence: bunLock.value
279
- });
280
- if ((yield* has(root, "yarn.lock")) && namesManager(hints, "yarn")) return DetectedPackageManager.make({
281
- name: "yarn",
282
- version: versionFor(hints, "yarn"),
283
- runtime: "node",
284
- evidence: "yarn.lock"
285
- });
286
- if (yield* has(root, "package-lock.json")) return DetectedPackageManager.make({
287
- name: "npm",
288
- version: versionFor(hints, "npm"),
289
- runtime: "node",
290
- evidence: "package-lock.json"
291
- });
292
- const declared = declaredName(hints);
293
- if (Option.isSome(declared)) {
294
- const name = declared.value;
295
- if (name === "pnpm" || name === "npm" || name === "yarn" || name === "bun") return DetectedPackageManager.make({
296
- name,
297
- version: versionFor(hints, name),
298
- runtime: name === "bun" ? "bun" : "node",
299
- evidence: Option.isSome(hints.devEngines) ? "package.json#devEngines.packageManager" : "package.json#packageManager"
300
- });
301
- }
302
- return yield* Effect.fail(new PackageManagerDetectionError({
174
+ const present = new Set((yield* Effect.forEach(MARKER_FILES, (file) => has(root, file).pipe(Effect.map((hit) => hit ? file : null)), { concurrency: "unbounded" })).filter(Predicate.isNotNull));
175
+ const decision = decidePackageManager(manifest, (file) => present.has(file));
176
+ if (decision === void 0) return yield* Effect.fail(new PackageManagerDetectionError({
303
177
  root,
304
178
  checked: CHECKED
305
179
  }));
180
+ return DetectedPackageManager.make(decision);
306
181
  });
307
182
  return { detect: (root) => detect(root).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path)) };
308
183
  });
package/Workspaces.js CHANGED
@@ -8,7 +8,7 @@ import { WorkspaceCatalogs } from "./WorkspaceCatalogs.js";
8
8
  import { WorkspaceSnapshots } from "./WorkspaceSnapshots.js";
9
9
  import { Git } from "@effected/git";
10
10
  import { Effect, Layer, Option } from "effect";
11
- import { ExecContext, LocalExec, LocalExecError } from "@effected/commands";
11
+ import { LocalExec, LocalExecError } from "@effected/commands";
12
12
 
13
13
  // src/Workspaces.ts
14
14
  const compose = (options, hooks) => {
@@ -19,59 +19,12 @@ const compose = (options, hooks) => {
19
19
  const catalogs = WorkspaceCatalogs.layerWithHooks(hooks, options).pipe(Layer.provide(roots), Layer.provide(lockfiles));
20
20
  return Layer.mergeAll(roots, detector, discovery, lockfiles, catalogs);
21
21
  };
22
- const layer = (options) => compose(options, ConfigDependencyHooks.layerNoop);
23
- /**
24
- * The core composite widened with the git tier: `Git`, `ChangeDetector` and
25
- * `WorkspaceSnapshots`. It builds the core over `hooks` ITSELF, so the SAME
26
- * hooks layer reaches `WorkspaceCatalogs` (through `compose`) and
27
- * `WorkspaceSnapshots` by construction — `at(ref)` replays a ref's config
28
- * dependencies exactly as the live assembler replays the worktree's: one
29
- * reference, one memo, one policy for both sides of a diff.
30
- */
31
- const withGit = (hooks, options) => {
32
- const core = compose(options, hooks);
33
- const git = Git.layer;
34
- return Layer.mergeAll(core, git, ChangeDetector.layer.pipe(Layer.provide(git), Layer.provide(core)), WorkspaceSnapshots.layer(options).pipe(Layer.provide(git), Layer.provide(hooks), Layer.provide(core)));
35
- };
36
- const layerWithGit = (options) => withGit(ConfigDependencyHooks.layerNoop, options);
37
- const resolvers = Layer.mergeAll(WorkspaceCatalogs.catalogResolver, WorkspaceDiscovery.workspaceResolver);
38
- const layerWithConfigDependencies = (options) => compose(options, ConfigDependencyHooks.layerLive);
39
- const layerWithConfigDependenciesSubprocess = (options) => compose(options, ConfigDependencyHooks.layerSubprocess);
40
- const layerWithGitAndConfigDependencies = (options) => withGit(ConfigDependencyHooks.layerLive, options);
41
- const layerWithGitAndConfigDependenciesSubprocess = (options) => withGit(ConfigDependencyHooks.layerSubprocess, options);
42
- const resolverLayer = (options) => resolvers.pipe(Layer.provide(layerWithConfigDependencies(options)));
43
- const resolveManifest = Effect.fn("Workspaces.resolveManifest")(function* (manifest, options) {
44
- return yield* manifest.resolve().pipe(Effect.provide(resolverLayer(options)));
45
- });
46
- const localExecLayer = (options) => Layer.effect(LocalExec, Effect.gen(function* () {
47
- const roots = yield* WorkspaceRoot;
48
- const detector = yield* PackageManagerDetector;
49
- return { context: Effect.gen(function* () {
50
- const cwd = options?.cwd ?? ".";
51
- const stopAt = options?.stopAt;
52
- const root = yield* roots.find(cwd, stopAt === void 0 ? void 0 : { stopAt }).pipe(Effect.asSome, Effect.orElseSucceed(Option.none));
53
- if (Option.isNone(root)) return Option.none();
54
- const detected = yield* detector.detect(root.value).pipe(Effect.asSome, Effect.catchTag("PackageManagerDetectionError", () => Effect.succeed(Option.none())), Effect.mapError((cause) => new LocalExecError({
55
- directory: root.value,
56
- cause
57
- })));
58
- if (Option.isNone(detected)) return Option.none();
59
- const { prefix, dlxPrefix, scriptPrefix } = LocalExec.prefixes(detected.value.name);
60
- return Option.some(ExecContext.make({
61
- label: detected.value.name,
62
- prefix,
63
- dlxPrefix,
64
- scriptPrefix,
65
- directory: root.value
66
- }));
67
- }) };
68
- }));
69
22
  /**
70
23
  * The composite layers.
71
24
  *
72
25
  * @public
73
26
  */
74
- var Workspaces = class {
27
+ var Workspaces = class Workspaces {
75
28
  constructor() {}
76
29
  /**
77
30
  * Every service that needs only a filesystem: root, package-manager
@@ -103,7 +56,9 @@ var Workspaces = class {
103
56
  * const AppLayer = Layer.provide(WorkspacesLayer, PlatformLayer);
104
57
  * ```
105
58
  */
106
- static layer = layer;
59
+ static layer(options) {
60
+ return compose(options, ConfigDependencyHooks.layerNoop);
61
+ }
107
62
  /**
108
63
  * The git-free composite, but with catalog assembly that **replays config
109
64
  * dependency `pnpmfile.cjs` hooks** —
@@ -118,7 +73,9 @@ var Workspaces = class {
118
73
  *
119
74
  * **Bind the result to a `const`.**
120
75
  */
121
- static layerWithConfigDependencies = layerWithConfigDependencies;
76
+ static layerWithConfigDependencies(options) {
77
+ return compose(options, ConfigDependencyHooks.layerLive);
78
+ }
122
79
  /**
123
80
  * The git-free composite with config-dependency hook replay in a `node`
124
81
  * **child process** —
@@ -144,7 +101,9 @@ var Workspaces = class {
144
101
  *
145
102
  * **Bind the result to a `const`.**
146
103
  */
147
- static layerWithConfigDependenciesSubprocess = layerWithConfigDependenciesSubprocess;
104
+ static layerWithConfigDependenciesSubprocess(options) {
105
+ return compose(options, ConfigDependencyHooks.layerSubprocess);
106
+ }
148
107
  /**
149
108
  * The git-free composite plus {@link ChangeDetector} and
150
109
  * {@link WorkspaceSnapshots}, over `@effected/git`'s `Git` service.
@@ -158,7 +117,9 @@ var Workspaces = class {
158
117
  * provides `Git.layerTest({ … })` — git's own shipped double, whose
159
118
  * unstubbed members die named — and needs no repository on disk.
160
119
  */
161
- static layerWithGit = layerWithGit;
120
+ static layerWithGit(options) {
121
+ return Workspaces.layerWithGitAndHooks(ConfigDependencyHooks.layerNoop, options);
122
+ }
162
123
  /**
163
124
  * {@link Workspaces.layerWithGit} over
164
125
  * {@link Workspaces.layerWithConfigDependencies} — snapshots, change
@@ -192,7 +153,9 @@ var Workspaces = class {
192
153
  * const KitLayer = Workspaces.layerWithGitAndConfigDependencies();
193
154
  * ```
194
155
  */
195
- static layerWithGitAndConfigDependencies = layerWithGitAndConfigDependencies;
156
+ static layerWithGitAndConfigDependencies(options) {
157
+ return Workspaces.layerWithGitAndHooks(ConfigDependencyHooks.layerLive, options);
158
+ }
196
159
  /**
197
160
  * {@link Workspaces.layerWithGitAndConfigDependencies}, with the hook replay
198
161
  * in a `node` **child process** rather than in process.
@@ -219,7 +182,9 @@ var Workspaces = class {
219
182
  * const KitLayer = Workspaces.layerWithGitAndConfigDependenciesSubprocess();
220
183
  * ```
221
184
  */
222
- static layerWithGitAndConfigDependenciesSubprocess = layerWithGitAndConfigDependenciesSubprocess;
185
+ static layerWithGitAndConfigDependenciesSubprocess(options) {
186
+ return Workspaces.layerWithGitAndHooks(ConfigDependencyHooks.layerSubprocess, options);
187
+ }
223
188
  /**
224
189
  * The git composite over a **caller-supplied** hooks layer — the same graph
225
190
  * as {@link Workspaces.layerWithGit} and its two config-dependency
@@ -255,7 +220,11 @@ var Workspaces = class {
255
220
  * );
256
221
  * ```
257
222
  */
258
- static layerWithGitAndHooks = withGit;
223
+ static layerWithGitAndHooks(hooks, options) {
224
+ const core = compose(options, hooks);
225
+ const git = Git.layer;
226
+ return Layer.mergeAll(core, git, ChangeDetector.layer.pipe(Layer.provide(git), Layer.provide(core)), WorkspaceSnapshots.layer(options).pipe(Layer.provide(git), Layer.provide(hooks), Layer.provide(core)));
227
+ }
259
228
  /**
260
229
  * This package's implementation of `@effected/commands`' `LocalExec`
261
230
  * contract: how to run a project-local binary here.
@@ -323,7 +292,24 @@ var Workspaces = class {
323
292
  * );
324
293
  * ```
325
294
  */
326
- static localExecLayer = localExecLayer;
295
+ static localExecLayer(options) {
296
+ return Layer.effect(LocalExec, Effect.gen(function* () {
297
+ const roots = yield* WorkspaceRoot;
298
+ const detector = yield* PackageManagerDetector;
299
+ return { context: Effect.gen(function* () {
300
+ const cwd = options?.cwd ?? ".";
301
+ const stopAt = options?.stopAt;
302
+ const root = yield* roots.find(cwd, stopAt === void 0 ? void 0 : { stopAt }).pipe(Effect.asSome, Effect.orElseSucceed(Option.none));
303
+ if (Option.isNone(root)) return Option.none();
304
+ const detected = yield* detector.detect(root.value).pipe(Effect.asSome, Effect.catchTag("PackageManagerDetectionError", () => Effect.succeed(Option.none())), Effect.mapError((cause) => new LocalExecError({
305
+ directory: root.value,
306
+ cause
307
+ })));
308
+ if (Option.isNone(detected)) return Option.none();
309
+ return Option.some(LocalExec.contextFor(detected.value.name, { directory: root.value }));
310
+ }) };
311
+ }));
312
+ }
327
313
  /**
328
314
  * Resolve every `catalog:` and `workspace:` specifier in one `Manifest`
329
315
  * against the real workspace, in one call — the 90% path. Decode stays at
@@ -358,7 +344,9 @@ var Workspaces = class {
358
344
  * });
359
345
  * ```
360
346
  */
361
- static resolveManifest = resolveManifest;
347
+ static resolveManifest = Effect.fn("Workspaces.resolveManifest")(function* (manifest, options) {
348
+ return yield* manifest.resolve().pipe(Effect.provide(Workspaces.resolverLayer(options)));
349
+ });
362
350
  /**
363
351
  * The one-call resolver factory: {@link Workspaces.resolvers} pre-wired
364
352
  * over {@link Workspaces.layerWithConfigDependencies}, so the two
@@ -392,7 +380,9 @@ var Workspaces = class {
392
380
  * );
393
381
  * ```
394
382
  */
395
- static resolverLayer = resolverLayer;
383
+ static resolverLayer(options) {
384
+ return Workspaces.resolvers.pipe(Layer.provide(Workspaces.layerWithConfigDependencies(options)));
385
+ }
396
386
  /**
397
387
  * The two `@effected/npm` resolver contracts, implemented for real.
398
388
  *
@@ -411,7 +401,7 @@ var Workspaces = class {
411
401
  * const Resolvers = Workspaces.resolvers.pipe(Layer.provide(WorkspacesLayer));
412
402
  * ```
413
403
  */
414
- static resolvers = resolvers;
404
+ static resolvers = Layer.mergeAll(WorkspaceCatalogs.catalogResolver, WorkspaceDiscovery.workspaceResolver);
415
405
  };
416
406
 
417
407
  export { Workspaces };
package/WorkspacesSync.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { Traversal, badMaxDepthMessage, isPruned, isValidMaxDepth, joinRelative } from "./internal/traverse.js";
2
2
  import { isStringRecord } from "./internal/guards.js";
3
3
  import { manifestPatternsOf, pnpmPatternsOf } from "./internal/patterns.js";
4
- import { PublishConfig, WorkspacePackage } from "./WorkspacePackage.js";
5
- import { Effect, Exit, Result, Schema } from "effect";
4
+ import { PublishConfig, WorkspaceManifestError, WorkspacePackage } from "./WorkspacePackage.js";
5
+ import { decidePackageManager } from "./internal/packageManagerDecision.js";
6
+ import { DetectedPackageManager, PackageManagerDetectionError, PackageManagerEvidence } from "./PackageManagerName.js";
7
+ import { Effect, Exit, Option, Result, Schema } from "effect";
6
8
  import { GlobSet } from "@effected/glob";
7
9
  import { PackageJsonFormat } from "@effected/package-json";
8
10
  import { Yaml } from "@effected/yaml";
11
+ import { LocalExec, LocalExecError } from "@effected/commands";
9
12
 
10
13
  // src/WorkspacesSync.ts
11
14
  /**
@@ -342,5 +345,122 @@ const getWorkspacePackagesSync = (root, options) => {
342
345
  options.onSkip?.(rootPackage);
343
346
  return members;
344
347
  };
348
+ /**
349
+ * Which package manager owns `root`, synchronously — the same answer
350
+ * `PackageManagerDetector.detect` gives, as a `Result`.
351
+ *
352
+ * @remarks
353
+ * **Synchronous**, for a caller with no Effect runtime (a lint-staged
354
+ * handler, a Vitest config). Both surfaces run one decision — the same
355
+ * priority order, the same `devEngines`-over-`packageManager` precedence, the
356
+ * same refusal to guess — so the two cannot disagree about a root. Only the IO
357
+ * differs: the file operations are the caller's ({@link WorkspacesSyncOptions};
358
+ * `nodeSyncOps` from `@effected/workspaces/node-sync` is the Node binding),
359
+ * and only `exists` and `readFile` are used.
360
+ *
361
+ * Unlike the other sync entry points this one is not degraded-skip: there is
362
+ * no partial answer to degrade to, so the failure the Effect surface would
363
+ * raise comes back as the `Result`'s failure instead — a
364
+ * `PackageManagerDetectionError` when no evidence matches, a
365
+ * `WorkspaceManifestError` when the root `package.json` exists but cannot be
366
+ * read or parsed. A throwing `readFile` is caught into the latter; nothing
367
+ * throws out of this function.
368
+ *
369
+ * `root` is probed as given — no ascent. Pair it with
370
+ * {@link findWorkspaceRootSync} for the workspace root, or pass the directory
371
+ * whose manager you mean.
372
+ *
373
+ * @param root - The directory to probe.
374
+ * @param options - The consumer-supplied file and path operations.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * import { detectPackageManagerSync } from "@effected/workspaces";
379
+ * import { nodeSyncOps } from "@effected/workspaces/node-sync";
380
+ * import { Result } from "effect";
381
+ *
382
+ * const detected = detectPackageManagerSync(process.cwd(), nodeSyncOps);
383
+ * const name = Result.isSuccess(detected) ? detected.success.name : "npm";
384
+ * ```
385
+ *
386
+ * @public
387
+ */
388
+ const detectPackageManagerSync = (root, options) => {
389
+ const { fileSystem, path } = options;
390
+ const packageJsonPath = path.join(root, "package.json");
391
+ let manifest = Option.none();
392
+ if (fileSystem.exists(packageJsonPath)) {
393
+ let text;
394
+ try {
395
+ text = fileSystem.readFile(packageJsonPath);
396
+ } catch (cause) {
397
+ return Result.fail(new WorkspaceManifestError({
398
+ packageJsonPath,
399
+ kind: "read",
400
+ cause
401
+ }));
402
+ }
403
+ const parsed = PackageJsonFormat.parseObjectResult(text);
404
+ if (Result.isFailure(parsed)) return Result.fail(new WorkspaceManifestError({
405
+ packageJsonPath,
406
+ kind: "decode",
407
+ cause: parsed.failure
408
+ }));
409
+ manifest = Option.some(parsed.success);
410
+ }
411
+ const decision = decidePackageManager(manifest, (file) => fileSystem.exists(path.join(root, file)));
412
+ return decision === void 0 ? Result.fail(new PackageManagerDetectionError({
413
+ root,
414
+ checked: PackageManagerEvidence.literals
415
+ })) : Result.succeed(DetectedPackageManager.make(decision));
416
+ };
417
+ /**
418
+ * The project-local execution context for `cwd`, synchronously — what
419
+ * `Workspaces.localExecLayer` answers through `LocalExec.context`.
420
+ *
421
+ * @remarks
422
+ * The sync half of the `LocalExec` bridge: hand the context to
423
+ * `@effected/commands`' `makeToolDiscoverySync` and project-local tools
424
+ * resolve through the right launcher, in the workspace root. The rules are the
425
+ * Effect layer's, step for step:
426
+ *
427
+ * - the workspace root is found with {@link findWorkspaceRootSync} (honouring
428
+ * `stopAt`); no root is `Option.none()` — nothing project-local to run here;
429
+ * - a detection refusal (`PackageManagerDetectionError`) is also
430
+ * `Option.none()`: no identifiable launcher is not a failure;
431
+ * - a root manifest that cannot be read or parsed is a mechanism failure, the
432
+ * `Result`'s `LocalExecError` with the `WorkspaceManifestError` as its cause.
433
+ *
434
+ * The argv prefixes come from `LocalExec.prefixes` — the one home of that
435
+ * knowledge — so nothing here re-derives `pnpm exec` or `npx --no --`.
436
+ *
437
+ * @param cwd - Where to start the root ascent (typically `process.cwd()`).
438
+ * @param options - The consumer-supplied file and path operations, plus an
439
+ * optional `stopAt` ceiling.
440
+ *
441
+ * @example
442
+ * ```ts
443
+ * import { makeToolDiscoverySync, Tool } from "@effected/commands";
444
+ * import { nodeSpawnSync } from "@effected/commands/node-sync";
445
+ * import { localExecContextSync } from "@effected/workspaces";
446
+ * import { nodeSyncOps } from "@effected/workspaces/node-sync";
447
+ * import { Option, Result } from "effect";
448
+ *
449
+ * const context = Result.getOrElse(localExecContextSync(process.cwd(), nodeSyncOps), () => Option.none());
450
+ * const discovery = makeToolDiscoverySync({ spawn: nodeSpawnSync, context: Option.getOrUndefined(context) });
451
+ * ```
452
+ *
453
+ * @public
454
+ */
455
+ const localExecContextSync = (cwd, options) => {
456
+ const root = findWorkspaceRootSync(cwd, options);
457
+ if (root === null) return Result.succeed(Option.none());
458
+ const detected = detectPackageManagerSync(root, options);
459
+ if (Result.isFailure(detected)) return detected.failure._tag === "PackageManagerDetectionError" ? Result.succeed(Option.none()) : Result.fail(new LocalExecError({
460
+ directory: root,
461
+ cause: detected.failure
462
+ }));
463
+ return Result.succeed(Option.some(LocalExec.contextFor(detected.success.name, { directory: root })));
464
+ };
345
465
 
346
- export { findWorkspaceRootSync, getWorkspacePackagesSync };
466
+ export { detectPackageManagerSync, findWorkspaceRootSync, getWorkspacePackagesSync, localExecContextSync };
package/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { Lockfile, LockfileFramingError, LockfileIntegrity, LockfileParseError,
6
6
  import { Package } from "@effected/package-json";
7
7
  import { ChildProcessSpawner } from "effect/process";
8
8
  import { SemVer } from "@effected/semver";
9
- import { LocalExec } from "@effected/commands";
9
+ import { ExecContext, LocalExec, LocalExecError } from "@effected/commands";
10
10
  declare const PublishConfig_base: Schema.Class<PublishConfig, Schema.Struct<{
11
11
  /** Scoped-package visibility. Its presence overrides `private`. */
12
12
  readonly access: Schema.optionalKey<Schema.Literals<readonly ["public", "restricted"]>>;
@@ -4115,7 +4115,7 @@ export declare class Workspaces {
4115
4115
  * const AppLayer = Layer.provide(WorkspacesLayer, PlatformLayer);
4116
4116
  * ```
4117
4117
  */
4118
- static readonly layer: (options?: WorkspacesOptions) => Layer.Layer<WorkspacesServices, never, FileSystem.FileSystem | Path.Path>;
4118
+ static layer(options?: WorkspacesOptions): Layer.Layer<WorkspacesServices, never, FileSystem.FileSystem | Path.Path>;
4119
4119
  /**
4120
4120
  * The git-free composite, but with catalog assembly that **replays config
4121
4121
  * dependency `pnpmfile.cjs` hooks** —
@@ -4130,7 +4130,7 @@ export declare class Workspaces {
4130
4130
  *
4131
4131
  * **Bind the result to a `const`.**
4132
4132
  */
4133
- static readonly layerWithConfigDependencies: (options?: WorkspacesOptions) => Layer.Layer<WorkspacesServices, never, FileSystem.FileSystem | Path.Path>;
4133
+ static layerWithConfigDependencies(options?: WorkspacesOptions): Layer.Layer<WorkspacesServices, never, FileSystem.FileSystem | Path.Path>;
4134
4134
  /**
4135
4135
  * The git-free composite with config-dependency hook replay in a `node`
4136
4136
  * **child process** —
@@ -4156,7 +4156,7 @@ export declare class Workspaces {
4156
4156
  *
4157
4157
  * **Bind the result to a `const`.**
4158
4158
  */
4159
- static readonly layerWithConfigDependenciesSubprocess: (options?: WorkspacesOptions) => Layer.Layer<WorkspacesServices, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4159
+ static layerWithConfigDependenciesSubprocess(options?: WorkspacesOptions): Layer.Layer<WorkspacesServices, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4160
4160
  /**
4161
4161
  * The git-free composite plus {@link ChangeDetector} and
4162
4162
  * {@link WorkspaceSnapshots}, over `@effected/git`'s `Git` service.
@@ -4170,7 +4170,7 @@ export declare class Workspaces {
4170
4170
  * provides `Git.layerTest({ … })` — git's own shipped double, whose
4171
4171
  * unstubbed members die named — and needs no repository on disk.
4172
4172
  */
4173
- static readonly layerWithGit: (options?: WorkspacesGitOptions) => Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4173
+ static layerWithGit(options?: WorkspacesGitOptions): Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4174
4174
  /**
4175
4175
  * {@link Workspaces.layerWithGit} over
4176
4176
  * {@link Workspaces.layerWithConfigDependencies} — snapshots, change
@@ -4204,7 +4204,7 @@ export declare class Workspaces {
4204
4204
  * const KitLayer = Workspaces.layerWithGitAndConfigDependencies();
4205
4205
  * ```
4206
4206
  */
4207
- static readonly layerWithGitAndConfigDependencies: (options?: WorkspacesGitOptions) => Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4207
+ static layerWithGitAndConfigDependencies(options?: WorkspacesGitOptions): Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4208
4208
  /**
4209
4209
  * {@link Workspaces.layerWithGitAndConfigDependencies}, with the hook replay
4210
4210
  * in a `node` **child process** rather than in process.
@@ -4231,7 +4231,7 @@ export declare class Workspaces {
4231
4231
  * const KitLayer = Workspaces.layerWithGitAndConfigDependenciesSubprocess();
4232
4232
  * ```
4233
4233
  */
4234
- static readonly layerWithGitAndConfigDependenciesSubprocess: (options?: WorkspacesGitOptions) => Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4234
+ static layerWithGitAndConfigDependenciesSubprocess(options?: WorkspacesGitOptions): Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
4235
4235
  /**
4236
4236
  * The git composite over a **caller-supplied** hooks layer — the same graph
4237
4237
  * as {@link Workspaces.layerWithGit} and its two config-dependency
@@ -4267,7 +4267,7 @@ export declare class Workspaces {
4267
4267
  * );
4268
4268
  * ```
4269
4269
  */
4270
- static readonly layerWithGitAndHooks: <R = never>(hooks: Layer.Layer<ConfigDependencyHooks, never, R>, options?: WorkspacesGitOptions) => Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner | R>;
4270
+ static layerWithGitAndHooks<R = never>(hooks: Layer.Layer<ConfigDependencyHooks, never, R>, options?: WorkspacesGitOptions): Layer.Layer<WorkspacesServices | ChangeDetector | WorkspaceSnapshots | Git, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner | R>;
4271
4271
  /**
4272
4272
  * This package's implementation of `@effected/commands`' `LocalExec`
4273
4273
  * contract: how to run a project-local binary here.
@@ -4335,10 +4335,10 @@ export declare class Workspaces {
4335
4335
  * );
4336
4336
  * ```
4337
4337
  */
4338
- static readonly localExecLayer: (options?: {
4338
+ static localExecLayer(options?: {
4339
4339
  readonly cwd?: string;
4340
4340
  readonly stopAt?: string | undefined;
4341
- }) => Layer.Layer<LocalExec, never, PackageManagerDetector | WorkspaceRoot>;
4341
+ }): Layer.Layer<LocalExec, never, PackageManagerDetector | WorkspaceRoot>;
4342
4342
  /**
4343
4343
  * Resolve every `catalog:` and `workspace:` specifier in one `Manifest`
4344
4344
  * against the real workspace, in one call — the 90% path. Decode stays at
@@ -4407,7 +4407,7 @@ export declare class Workspaces {
4407
4407
  * );
4408
4408
  * ```
4409
4409
  */
4410
- static readonly resolverLayer: (options?: WorkspacesOptions) => Layer.Layer<CatalogResolver | WorkspaceResolver, never, FileSystem.FileSystem | Path.Path>;
4410
+ static resolverLayer(options?: WorkspacesOptions): Layer.Layer<CatalogResolver | WorkspaceResolver, never, FileSystem.FileSystem | Path.Path>;
4411
4411
  /**
4412
4412
  * The two `@effected/npm` resolver contracts, implemented for real.
4413
4413
  *
@@ -4778,5 +4778,85 @@ interface GetWorkspacePackagesSyncOptions extends WorkspacesSyncOptions {
4778
4778
  * @public
4779
4779
  */
4780
4780
  export declare const getWorkspacePackagesSync: (root: string, options: GetWorkspacePackagesSyncOptions) => ReadonlyArray<WorkspacePackage>;
4781
+ /**
4782
+ * Which package manager owns `root`, synchronously — the same answer
4783
+ * `PackageManagerDetector.detect` gives, as a `Result`.
4784
+ *
4785
+ * @remarks
4786
+ * **Synchronous**, for a caller with no Effect runtime (a lint-staged
4787
+ * handler, a Vitest config). Both surfaces run one decision — the same
4788
+ * priority order, the same `devEngines`-over-`packageManager` precedence, the
4789
+ * same refusal to guess — so the two cannot disagree about a root. Only the IO
4790
+ * differs: the file operations are the caller's ({@link WorkspacesSyncOptions};
4791
+ * `nodeSyncOps` from `@effected/workspaces/node-sync` is the Node binding),
4792
+ * and only `exists` and `readFile` are used.
4793
+ *
4794
+ * Unlike the other sync entry points this one is not degraded-skip: there is
4795
+ * no partial answer to degrade to, so the failure the Effect surface would
4796
+ * raise comes back as the `Result`'s failure instead — a
4797
+ * `PackageManagerDetectionError` when no evidence matches, a
4798
+ * `WorkspaceManifestError` when the root `package.json` exists but cannot be
4799
+ * read or parsed. A throwing `readFile` is caught into the latter; nothing
4800
+ * throws out of this function.
4801
+ *
4802
+ * `root` is probed as given — no ascent. Pair it with
4803
+ * {@link findWorkspaceRootSync} for the workspace root, or pass the directory
4804
+ * whose manager you mean.
4805
+ *
4806
+ * @param root - The directory to probe.
4807
+ * @param options - The consumer-supplied file and path operations.
4808
+ *
4809
+ * @example
4810
+ * ```ts
4811
+ * import { detectPackageManagerSync } from "@effected/workspaces";
4812
+ * import { nodeSyncOps } from "@effected/workspaces/node-sync";
4813
+ * import { Result } from "effect";
4814
+ *
4815
+ * const detected = detectPackageManagerSync(process.cwd(), nodeSyncOps);
4816
+ * const name = Result.isSuccess(detected) ? detected.success.name : "npm";
4817
+ * ```
4818
+ *
4819
+ * @public
4820
+ */
4821
+ export declare const detectPackageManagerSync: (root: string, options: WorkspacesSyncOptions) => Result.Result<DetectedPackageManager, PackageManagerDetectionFailure>;
4822
+ /**
4823
+ * The project-local execution context for `cwd`, synchronously — what
4824
+ * `Workspaces.localExecLayer` answers through `LocalExec.context`.
4825
+ *
4826
+ * @remarks
4827
+ * The sync half of the `LocalExec` bridge: hand the context to
4828
+ * `@effected/commands`' `makeToolDiscoverySync` and project-local tools
4829
+ * resolve through the right launcher, in the workspace root. The rules are the
4830
+ * Effect layer's, step for step:
4831
+ *
4832
+ * - the workspace root is found with {@link findWorkspaceRootSync} (honouring
4833
+ * `stopAt`); no root is `Option.none()` — nothing project-local to run here;
4834
+ * - a detection refusal (`PackageManagerDetectionError`) is also
4835
+ * `Option.none()`: no identifiable launcher is not a failure;
4836
+ * - a root manifest that cannot be read or parsed is a mechanism failure, the
4837
+ * `Result`'s `LocalExecError` with the `WorkspaceManifestError` as its cause.
4838
+ *
4839
+ * The argv prefixes come from `LocalExec.prefixes` — the one home of that
4840
+ * knowledge — so nothing here re-derives `pnpm exec` or `npx --no --`.
4841
+ *
4842
+ * @param cwd - Where to start the root ascent (typically `process.cwd()`).
4843
+ * @param options - The consumer-supplied file and path operations, plus an
4844
+ * optional `stopAt` ceiling.
4845
+ *
4846
+ * @example
4847
+ * ```ts
4848
+ * import { makeToolDiscoverySync, Tool } from "@effected/commands";
4849
+ * import { nodeSpawnSync } from "@effected/commands/node-sync";
4850
+ * import { localExecContextSync } from "@effected/workspaces";
4851
+ * import { nodeSyncOps } from "@effected/workspaces/node-sync";
4852
+ * import { Option, Result } from "effect";
4853
+ *
4854
+ * const context = Result.getOrElse(localExecContextSync(process.cwd(), nodeSyncOps), () => Option.none());
4855
+ * const discovery = makeToolDiscoverySync({ spawn: nodeSpawnSync, context: Option.getOrUndefined(context) });
4856
+ * ```
4857
+ *
4858
+ * @public
4859
+ */
4860
+ export declare const localExecContextSync: (cwd: string, options: FindWorkspaceRootSyncOptions) => Result.Result<Option.Option<ExecContext>, LocalExecError>;
4781
4861
  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 };
4782
4862
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -16,6 +16,6 @@ import { CatalogSet, WorkspaceCatalogs } from "./WorkspaceCatalogs.js";
16
16
  import { PackageStateSnapshot, WorkspaceStateSnapshot } from "./WorkspaceStateSnapshot.js";
17
17
  import { WorkspaceSnapshots } from "./WorkspaceSnapshots.js";
18
18
  import { Workspaces } from "./Workspaces.js";
19
- import { findWorkspaceRootSync, getWorkspacePackagesSync } from "./WorkspacesSync.js";
19
+ import { detectPackageManagerSync, findWorkspaceRootSync, getWorkspacePackagesSync, localExecContextSync } from "./WorkspacesSync.js";
20
20
 
21
- 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, WorkspacePackage, WorkspacePatternError, WorkspaceRoot, WorkspaceRootNotFoundError, WorkspaceSnapshots, WorkspaceStateSnapshot, Workspaces, classifyTag, findWorkspaceRootSync, getWorkspacePackagesSync };
21
+ 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, WorkspacePackage, WorkspacePatternError, WorkspaceRoot, WorkspaceRootNotFoundError, WorkspaceSnapshots, WorkspaceStateSnapshot, Workspaces, classifyTag, detectPackageManagerSync, findWorkspaceRootSync, getWorkspacePackagesSync, localExecContextSync };
@@ -3,10 +3,25 @@ import { Predicate } from "effect";
3
3
  // src/internal/causeMessage.ts
4
4
  /** How many nodes of a cause chain the walk reads before stopping, so a cyclic chain cannot spin. */
5
5
  const CAUSE_DEPTH = 8;
6
- /** The message a single node carries: a thrown string, or a non-empty string `message` property. */
6
+ /**
7
+ * The message a single node carries: a thrown string, or a non-empty string `message` property. A getter or
8
+ * proxy trap that throws is a node with no message.
9
+ */
7
10
  const messageAt = (node) => {
8
- const text = Predicate.isString(node) ? node : Predicate.hasProperty(node, "message") && Predicate.isString(node.message) ? node.message : void 0;
9
- return text === void 0 || text.trim() === "" ? void 0 : text;
11
+ try {
12
+ const text = Predicate.isString(node) ? node : Predicate.hasProperty(node, "message") && Predicate.isString(node.message) ? node.message : void 0;
13
+ return text === void 0 || text.trim() === "" ? void 0 : text;
14
+ } catch {
15
+ return;
16
+ }
17
+ };
18
+ /** The next link of the chain: a node's `cause`, or `undefined` when it has none or reading it throws. */
19
+ const causeAt = (node) => {
20
+ try {
21
+ return Predicate.hasProperty(node, "cause") ? node.cause : void 0;
22
+ } catch {
23
+ return;
24
+ }
10
25
  };
11
26
  /**
12
27
  * Every distinct non-empty message a preserved cause chain carries, nearest
@@ -21,6 +36,9 @@ const messageAt = (node) => {
21
36
  * actionable detail, yet a wrapper that composes its own context must not
22
37
  * lose it either; so nothing is dropped, and a deeper text the nearer one
23
38
  * already contains is not repeated. The walk is bounded, so a cycle terminates.
39
+ *
40
+ * It never throws: every property read is guarded, so a `message` getter that throws leaves that link
41
+ * without text, and a `cause` getter that throws ends the walk with what was found so far.
24
42
  */
25
43
  const causeMessage = (cause) => {
26
44
  let message;
@@ -31,7 +49,7 @@ const causeMessage = (cause) => {
31
49
  if (message === void 0 || text.includes(message)) message = text;
32
50
  else if (!message.includes(text)) message = `${message}: ${text}`;
33
51
  }
34
- node = Predicate.hasProperty(node, "cause") ? node.cause : void 0;
52
+ node = causeAt(node);
35
53
  }
36
54
  return message;
37
55
  };
@@ -0,0 +1,116 @@
1
+ import { Option, Predicate, Schema } from "effect";
2
+ import { PackageManager } from "@effected/package-json";
3
+
4
+ // src/internal/packageManagerDecision.ts
5
+ /** The marker FILES the decision may ask about, in the order it asks. */
6
+ const MARKER_FILES = [
7
+ "pnpm-workspace.yaml",
8
+ "bun.lock",
9
+ "bun.lockb",
10
+ "yarn.lock",
11
+ "pnpm-lock.yaml",
12
+ "package-lock.json"
13
+ ];
14
+ /**
15
+ * The exact version a `name` + `version` pair denotes, or none when the version
16
+ * is not an exact version.
17
+ *
18
+ * Reuses the corepack `name@version+integrity` grammar rather than a second
19
+ * parser, so a `devEngines` version carrying a hash (`11.11.0+sha512.…`)
20
+ * normalizes to the same `11.11.0` the
21
+ * top-level field reports — and a *range* (`^11`, `11.x`) yields none, because a
22
+ * range is not a version and corepack will not run one either.
23
+ */
24
+ const exactVersionOf = (name, version) => Schema.decodeUnknownOption(PackageManager.FromString)(`${name}@${version}`).pipe(Option.map((pm) => pm.version));
25
+ /**
26
+ * The `devEngines.packageManager` hint, or none.
27
+ *
28
+ * Every malformed shape corepack itself tolerates is tolerated here by *ignoring
29
+ * the field*, never by failing detection: a non-object `devEngines`, a
30
+ * non-object `packageManager`, an **array** of them (corepack does not support
31
+ * arrays in this slot and falls back), a missing or non-string `name`, and a
32
+ * `name` containing `@`. A version that is not an exact version is dropped on its
33
+ * own, keeping the name — the name is still a valid disambiguator.
34
+ */
35
+ const devEnginesHint = (manifest) => {
36
+ const devEngines = manifest.devEngines;
37
+ if (!Predicate.isObject(devEngines)) return Option.none();
38
+ const slot = devEngines.packageManager;
39
+ if (!Predicate.isObject(slot)) return Option.none();
40
+ const name = slot.name;
41
+ if (typeof name !== "string" || name === "" || name.includes("@")) return Option.none();
42
+ const version = slot.version;
43
+ return Option.some({
44
+ name,
45
+ version: typeof version === "string" && version !== "" ? exactVersionOf(name, version) : Option.none()
46
+ });
47
+ };
48
+ /** The corepack top-level `packageManager` hint, or none when absent or malformed. */
49
+ const corepackHint = (manifest) => {
50
+ const raw = manifest.packageManager;
51
+ if (typeof raw !== "string") return Option.none();
52
+ return Schema.decodeUnknownOption(PackageManager.FromString)(raw).pipe(Option.map((pm) => ({
53
+ name: pm.name,
54
+ version: Option.some(pm.version)
55
+ })));
56
+ };
57
+ /**
58
+ * The manager name the manifest declares, if any.
59
+ *
60
+ * `devEngines` first — it is authoritative for the name, and corepack errors
61
+ * when the top-level field contradicts it.
62
+ */
63
+ const declaredName = (hints) => Option.map(Option.orElse(hints.devEngines, () => hints.corepack), (hint) => hint.name);
64
+ /** Whether the manifest declares `name` as its manager. */
65
+ const namesManager = (hints, name) => Option.contains(declaredName(hints), name);
66
+ /**
67
+ * The version to report for the manager that was detected — none unless a
68
+ * field naming *that* manager carries one.
69
+ *
70
+ * The top-level `packageManager` wins when it names the manager, because it
71
+ * is the field carrying the integrity hash; `devEngines` supplies the version
72
+ * when it does not.
73
+ */
74
+ const versionFor = (hints, name) => {
75
+ if (!namesManager(hints, name)) return Option.none();
76
+ const fromCorepack = Option.flatMap(hints.corepack, (hint) => hint.name === name ? hint.version : Option.none());
77
+ return Option.orElse(fromCorepack, () => Option.flatMap(hints.devEngines, (hint) => hint.name === name ? hint.version : Option.none()));
78
+ };
79
+ /**
80
+ * Decides which manager owns a root, or `undefined` when no evidence matches.
81
+ *
82
+ * @remarks
83
+ * The priority order and its reasons are documented on
84
+ * `PackageManagerDetector`; this is its single implementation. `has` is asked
85
+ * about marker files only, so a caller may answer lazily (one `exists` per
86
+ * question) or from a precomputed set.
87
+ */
88
+ const decidePackageManager = (manifest, has) => {
89
+ const hints = {
90
+ devEngines: Option.flatMap(manifest, devEnginesHint),
91
+ corepack: Option.flatMap(manifest, corepackHint)
92
+ };
93
+ const make = (name, evidence) => ({
94
+ name,
95
+ version: versionFor(hints, name),
96
+ runtime: name === "bun" ? "bun" : "node",
97
+ evidence
98
+ });
99
+ if (has("pnpm-workspace.yaml")) return make("pnpm", "pnpm-workspace.yaml");
100
+ const bunLock = has("bun.lock") ? "bun.lock" : has("bun.lockb") ? "bun.lockb" : void 0;
101
+ if (bunLock !== void 0 && namesManager(hints, "bun")) return make("bun", bunLock);
102
+ if (has("yarn.lock") && namesManager(hints, "yarn")) return make("yarn", "yarn.lock");
103
+ const workspaces = Option.map(manifest, (fields) => fields.workspaces);
104
+ if (Option.isSome(workspaces) && workspaces.value !== void 0 && workspaces.value !== null) return make("npm", "package.json#workspaces");
105
+ if (has("pnpm-lock.yaml")) return make("pnpm", "pnpm-lock.yaml");
106
+ if (bunLock !== void 0 && namesManager(hints, "bun")) return make("bun", bunLock);
107
+ if (has("yarn.lock") && namesManager(hints, "yarn")) return make("yarn", "yarn.lock");
108
+ if (has("package-lock.json")) return make("npm", "package-lock.json");
109
+ const declared = declaredName(hints);
110
+ if (Option.isSome(declared)) {
111
+ const name = declared.value;
112
+ if (name === "pnpm" || name === "npm" || name === "yarn" || name === "bun") return make(name, Option.isSome(hints.devEngines) ? "package.json#devEngines.packageManager" : "package.json#packageManager");
113
+ }
114
+ };
115
+
116
+ export { MARKER_FILES, decidePackageManager };
package/node-sync.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import "@effected/npm";
1
+ import "@effected/commands";
2
2
  import "effect";
3
3
  import "@effected/glob";
4
4
  import "@effected/lockfiles";
5
5
  import "@effected/package-json";
6
+ import "@effected/npm";
6
7
  /**
7
8
  * The synchronous file operations the sync entry points need, supplied by the
8
9
  * consumer. Node's built-ins satisfy it directly:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/workspaces",
3
- "version": "0.38.1",
3
+ "version": "0.39.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": [
@@ -51,15 +51,15 @@
51
51
  "./package.json": "./package.json"
52
52
  },
53
53
  "dependencies": {
54
- "@effected/commands": "^0.15.1",
55
- "@effected/git": "^0.25.0",
56
- "@effected/glob": "^0.14.0",
57
- "@effected/jsonc": "^0.20.0",
58
- "@effected/lockfiles": "^0.19.4",
59
- "@effected/npm": "^0.26.2",
60
- "@effected/package-json": "^0.25.2",
54
+ "@effected/commands": "^0.17.0",
55
+ "@effected/git": "^0.26.0",
56
+ "@effected/glob": "^0.15.0",
57
+ "@effected/jsonc": "^0.20.1",
58
+ "@effected/lockfiles": "^0.19.5",
59
+ "@effected/npm": "^0.27.1",
60
+ "@effected/package-json": "^0.26.1",
61
61
  "@effected/semver": "^0.18.0",
62
- "@effected/walker": "^0.20.0",
62
+ "@effected/walker": "^0.21.0",
63
63
  "@effected/yaml": "^0.25.1",
64
64
  "@pnpm/catalogs.config": "^1100.0.5",
65
65
  "@pnpm/catalogs.protocol-parser": "^1100.0.0",
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.1"
8
+ "packageVersion": "7.59.4"
9
9
  }
10
10
  ]
11
11
  }