@effected/workspaces 0.37.0 → 0.38.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/LayerPolicy.js +5 -1
- package/LockfileReader.js +1 -2
- package/PackedInstall.js +32 -8
- package/WorkspaceCatalogs.js +1 -2
- package/WorkspaceDiscovery.js +2 -4
- package/WorkspaceSnapshots.js +6 -7
- package/index.d.ts +5 -5
- package/internal/causeMessage.js +39 -0
- package/internal/configDependencyResolution.js +5 -3
- package/internal/configDependencyShared.js +3 -2
- package/package.json +6 -6
- package/testing.d.ts +7 -2
package/LayerPolicy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { causeMessage } from "./internal/causeMessage.js";
|
|
1
2
|
import { ALL_DEPENDENCY_FIELDS } from "./internal/dependencyFields.js";
|
|
2
3
|
import { Effect, FileSystem, Result, Schema } from "effect";
|
|
3
4
|
import { GlobSet } from "@effected/glob";
|
|
@@ -33,7 +34,10 @@ var LayerPolicyError = class extends Schema.TaggedError()("LayerPolicyError", {
|
|
|
33
34
|
switch (this.reason) {
|
|
34
35
|
case "read": return `Could not read the layer policy${at}`;
|
|
35
36
|
case "json": return `The layer policy${at} is not valid JSON`;
|
|
36
|
-
default:
|
|
37
|
+
default: {
|
|
38
|
+
const detail = causeMessage(this.cause);
|
|
39
|
+
return `The layer policy${at} does not match the LayerPolicy shape${detail === void 0 ? "" : `: ${detail}`}`;
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
};
|
package/LockfileReader.js
CHANGED
|
@@ -91,8 +91,7 @@ var LockfileReader = class LockfileReader extends Context.Service()("@effected/w
|
|
|
91
91
|
return typeof name === "string" && name.length > 0 ? Option.some(name) : Option.none();
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
-
const [
|
|
95
|
-
const memo = Effect.onExit(resolveOnce, (exit) => Exit.isSuccess(exit) ? Effect.void : invalidate);
|
|
94
|
+
const [memo, invalidate] = yield* Effect.cachedInvalidateWithTTL(init, (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
96
95
|
return {
|
|
97
96
|
read: Effect.fn("LockfileReader.read")(function* () {
|
|
98
97
|
return yield* memo;
|
package/PackedInstall.js
CHANGED
|
@@ -32,13 +32,18 @@ var PackedInstallError = class extends Schema.TaggedError()("PackedInstallError"
|
|
|
32
32
|
"Discovery",
|
|
33
33
|
"Io"
|
|
34
34
|
]),
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Names the package or manager involved. For `PackFailed` and
|
|
37
|
+
* `InstallFailed` on a non-zero exit it continues with the last few lines
|
|
38
|
+
* of the command's output, so a log that prints only the message is still
|
|
39
|
+
* actionable; `output` carries the longer tail.
|
|
40
|
+
*/
|
|
36
41
|
message: Schema.String,
|
|
37
42
|
/** The package manager involved. */
|
|
38
43
|
manager: Schema.optionalKey(PackageManagerName),
|
|
39
44
|
/** The workspace package involved. */
|
|
40
45
|
package: Schema.optionalKey(Schema.String),
|
|
41
|
-
/** The tail of the failing command's output. */
|
|
46
|
+
/** The tail of the failing command's output, both streams, stdout first. */
|
|
42
47
|
output: Schema.optionalKey(Schema.String),
|
|
43
48
|
/** The originating failure. */
|
|
44
49
|
cause: Schema.optionalKey(Schema.Defect())
|
|
@@ -343,6 +348,21 @@ const DEFAULT_PACK_FROM = { directory: "dist/prod/npm/pkg" };
|
|
|
343
348
|
const WORKSPACE_PROTOCOL_NOT_INSTALLED = "ERR_PNPM_CANNOT_RESOLVE_WORKSPACE_PROTOCOL";
|
|
344
349
|
const TAIL = 2e3;
|
|
345
350
|
const tail = (text) => text.length <= TAIL ? text : text.slice(-2e3);
|
|
351
|
+
const MESSAGE_TAIL_CHARS = 600;
|
|
352
|
+
/**
|
|
353
|
+
* `message` followed by the end of `output`. The manager's own install and
|
|
354
|
+
* pack logs are what `output` holds: npm, pnpm, yarn and bun print registry
|
|
355
|
+
* URLs and resolution failures, never the auth values they read from the
|
|
356
|
+
* user's rc files or from `NODE_AUTH_TOKEN` (npm redacts tokens in its own
|
|
357
|
+
* log lines), and the install env is already scrubbed of the parent
|
|
358
|
+
* manager's `npm_config_*` context. The message therefore widens what is
|
|
359
|
+
* printed, not what is captured: everything it shows was already in `output`.
|
|
360
|
+
*/
|
|
361
|
+
const withOutputTail = (message, output) => {
|
|
362
|
+
const lines = output.split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.length > 0).slice(-8).join("\n");
|
|
363
|
+
if (lines.length === 0) return message;
|
|
364
|
+
return `${message}; output tail:\n${lines.length <= MESSAGE_TAIL_CHARS ? lines : `…${lines.slice(-600)}`}`;
|
|
365
|
+
};
|
|
346
366
|
const DEFAULT_INSTALL_TIMEOUT = "4 minutes";
|
|
347
367
|
const PROBE_TIMEOUT = "30 seconds";
|
|
348
368
|
const DEFAULT_PACK_TIMEOUT = "2 minutes";
|
|
@@ -767,9 +787,10 @@ var PackedInstall = class PackedInstall {
|
|
|
767
787
|
})));
|
|
768
788
|
if (!output.succeeded) {
|
|
769
789
|
const notInstalled = packer === "pnpm" && `${output.stdout}${output.stderr}`.includes(WORKSPACE_PROTOCOL_NOT_INSTALLED);
|
|
770
|
-
|
|
790
|
+
const captured = tail(`${output.stdout}\n${output.stderr}`);
|
|
791
|
+
return yield* failure("PackFailed", withOutputTail(notInstalled ? `pnpm pack could not rewrite the workspace: specifiers of ${name} because the workspace is not installed; run pnpm install in the workspace first` : `${packer} pack exited ${output.exitCode} for ${name}`, captured), {
|
|
771
792
|
package: name,
|
|
772
|
-
output:
|
|
793
|
+
output: captured
|
|
773
794
|
});
|
|
774
795
|
}
|
|
775
796
|
const found = (yield* fs.readDirectory(destination).pipe(Effect.mapError(io(`could not list ${destination}`)))).filter((file) => file.endsWith(".tgz"));
|
|
@@ -846,10 +867,13 @@ var PackedInstall = class PackedInstall {
|
|
|
846
867
|
manager,
|
|
847
868
|
cause
|
|
848
869
|
})));
|
|
849
|
-
if (!output.succeeded)
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
870
|
+
if (!output.succeeded) {
|
|
871
|
+
const captured = tail(`${output.stdout}\n${output.stderr}`);
|
|
872
|
+
return yield* failure("InstallFailed", withOutputTail(`${manager} install exited ${output.exitCode}`, captured), {
|
|
873
|
+
manager,
|
|
874
|
+
output: captured
|
|
875
|
+
});
|
|
876
|
+
}
|
|
853
877
|
const consumer = InstalledConsumer.make({
|
|
854
878
|
manager,
|
|
855
879
|
managerVersion: version,
|
package/WorkspaceCatalogs.js
CHANGED
|
@@ -403,8 +403,7 @@ var WorkspaceCatalogs = class WorkspaceCatalogs extends Context.Service()("@effe
|
|
|
403
403
|
hookReplays
|
|
404
404
|
};
|
|
405
405
|
});
|
|
406
|
-
const [
|
|
407
|
-
const memo = Effect.onExit(resolveOnce, (exit) => Exit.isSuccess(exit) ? Effect.void : invalidate);
|
|
406
|
+
const [memo, invalidate] = yield* Effect.cachedInvalidateWithTTL(assemble, (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
408
407
|
return {
|
|
409
408
|
set: Effect.fn("WorkspaceCatalogs.set")(function* () {
|
|
410
409
|
return (yield* memo).catalogs;
|
package/WorkspaceDiscovery.js
CHANGED
|
@@ -250,8 +250,7 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
|
|
|
250
250
|
const root = yield* findLayerRoot(roots, options);
|
|
251
251
|
return yield* discoverAt(root);
|
|
252
252
|
});
|
|
253
|
-
const [
|
|
254
|
-
const memo = Effect.onExit(resolveOnce, (exit) => Exit.isSuccess(exit) ? Effect.void : invalidate);
|
|
253
|
+
const [memo, invalidate] = yield* Effect.cachedInvalidateWithTTL(discover, (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
255
254
|
/**
|
|
256
255
|
* Per-resolved-root memos for the `…In` methods, each success-only on the
|
|
257
256
|
* same discipline as the layer-bound one above.
|
|
@@ -273,8 +272,7 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
|
|
|
273
272
|
const root = yield* roots.find(directory);
|
|
274
273
|
const existing = rootMemos.get(root);
|
|
275
274
|
if (existing !== void 0) return yield* existing.memo;
|
|
276
|
-
const [
|
|
277
|
-
const built = Effect.onExit(resolveOnce, (exit) => Exit.isSuccess(exit) ? Effect.void : invalidateOne);
|
|
275
|
+
const [built, invalidateOne] = yield* Effect.cachedInvalidateWithTTL(discoverAt(root), (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
278
276
|
const raced = rootMemos.get(root);
|
|
279
277
|
if (raced !== void 0) return yield* raced.memo;
|
|
280
278
|
rootMemos.set(root, {
|
package/WorkspaceSnapshots.js
CHANGED
|
@@ -80,11 +80,11 @@ const unstubbed = (method) => Effect.die(/* @__PURE__ */ new Error(`WorkspaceSna
|
|
|
80
80
|
* Reads workspace state at a git ref with no checkout, and the live worktree.
|
|
81
81
|
*
|
|
82
82
|
* @remarks
|
|
83
|
-
* `at(ref)` is cached per `(resolved root, ref)` via
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
83
|
+
* `at(ref)` is cached per `(resolved root, ref)` via `Effect.cachedWithTTL`
|
|
84
|
+
* with an exit-keyed time-to-live: infinite for a success, zero for a failure
|
|
85
|
+
* — never bare `Effect.cached`, which would memoize a failure. A failed
|
|
86
|
+
* `at(ref)` init is therefore retried on the next call, not memoized, and
|
|
87
|
+
* concurrent callers share one in-flight init.
|
|
88
88
|
*
|
|
89
89
|
* @example
|
|
90
90
|
* ```ts
|
|
@@ -206,8 +206,7 @@ var WorkspaceSnapshots = class WorkspaceSnapshots extends Context.Service()("@ef
|
|
|
206
206
|
const key = `${root}\0${ref}`;
|
|
207
207
|
let memo = atCaches.get(key);
|
|
208
208
|
if (memo === void 0) {
|
|
209
|
-
const
|
|
210
|
-
const built = Effect.onExit(resolveOnce, (exit) => Exit.isSuccess(exit) ? Effect.void : invalidate);
|
|
209
|
+
const built = yield* Effect.cachedWithTTL(computeAt(root, ref), (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
211
210
|
const existing = atCaches.get(key);
|
|
212
211
|
if (existing !== void 0) memo = existing;
|
|
213
212
|
else {
|
package/index.d.ts
CHANGED
|
@@ -3910,11 +3910,11 @@ declare const WorkspaceSnapshots_base: Context.ServiceClass<WorkspaceSnapshots,
|
|
|
3910
3910
|
* Reads workspace state at a git ref with no checkout, and the live worktree.
|
|
3911
3911
|
*
|
|
3912
3912
|
* @remarks
|
|
3913
|
-
* `at(ref)` is cached per `(resolved root, ref)` via
|
|
3914
|
-
*
|
|
3915
|
-
*
|
|
3916
|
-
*
|
|
3917
|
-
*
|
|
3913
|
+
* `at(ref)` is cached per `(resolved root, ref)` via `Effect.cachedWithTTL`
|
|
3914
|
+
* with an exit-keyed time-to-live: infinite for a success, zero for a failure
|
|
3915
|
+
* — never bare `Effect.cached`, which would memoize a failure. A failed
|
|
3916
|
+
* `at(ref)` init is therefore retried on the next call, not memoized, and
|
|
3917
|
+
* concurrent callers share one in-flight init.
|
|
3918
3918
|
*
|
|
3919
3919
|
* @example
|
|
3920
3920
|
* ```ts
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Predicate } from "effect";
|
|
2
|
+
|
|
3
|
+
// src/internal/causeMessage.ts
|
|
4
|
+
/** How many nodes of a cause chain the walk reads before stopping, so a cyclic chain cannot spin. */
|
|
5
|
+
const CAUSE_DEPTH = 8;
|
|
6
|
+
/** The message a single node carries: a thrown string, or a non-empty string `message` property. */
|
|
7
|
+
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;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Every distinct non-empty message a preserved cause chain carries, nearest
|
|
13
|
+
* first and joined with `: `, or `undefined` when nothing along it has one.
|
|
14
|
+
*
|
|
15
|
+
* A `Schema.Defect()` field holds whatever was thrown, so the read is guarded
|
|
16
|
+
* rather than assumed: `Predicate.hasProperty` + `Predicate.isString` accepts
|
|
17
|
+
* an `Error`, a cross-realm `Error` that fails `instanceof`, a plain
|
|
18
|
+
* `{ message }` object and a thrown string alike. An empty or whitespace-only
|
|
19
|
+
* message counts as none. The walk follows `cause` links because a wrapper's
|
|
20
|
+
* text is often the generic summary and the driver's text underneath is the
|
|
21
|
+
* actionable detail, yet a wrapper that composes its own context must not
|
|
22
|
+
* lose it either; so nothing is dropped, and a deeper text the nearer one
|
|
23
|
+
* already contains is not repeated. The walk is bounded, so a cycle terminates.
|
|
24
|
+
*/
|
|
25
|
+
const causeMessage = (cause) => {
|
|
26
|
+
let message;
|
|
27
|
+
let node = cause;
|
|
28
|
+
for (let depth = 0; depth < CAUSE_DEPTH && node !== void 0 && node !== null; depth++) {
|
|
29
|
+
const text = messageAt(node);
|
|
30
|
+
if (text !== void 0) {
|
|
31
|
+
if (message === void 0 || text.includes(message)) message = text;
|
|
32
|
+
else if (!message.includes(text)) message = `${message}: ${text}`;
|
|
33
|
+
}
|
|
34
|
+
node = Predicate.hasProperty(node, "cause") ? node.cause : void 0;
|
|
35
|
+
}
|
|
36
|
+
return message;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { causeMessage };
|
|
@@ -302,10 +302,12 @@ const resolveDirectory = (root, entry, stores, locks, options) => Effect.gen(fun
|
|
|
302
302
|
});
|
|
303
303
|
/**
|
|
304
304
|
* A lazy memo of `effect`, scoped to one {@link resolvePnpmfiles} call: the
|
|
305
|
-
* house success-only memo (never `Effect.cached`, which would pin
|
|
306
|
-
*
|
|
305
|
+
* house success-only memo (never `Effect.cached`, which would pin a failure),
|
|
306
|
+
* an exit-keyed TTL that keeps a success for good and expires a failure at
|
|
307
|
+
* once, so a failed run is retried by the next user while concurrent users
|
|
308
|
+
* share the one in flight. Core never caches an interrupt.
|
|
307
309
|
*/
|
|
308
|
-
const memoizeSuccess = (effect) => Effect.
|
|
310
|
+
const memoizeSuccess = (effect) => Effect.cachedWithTTL(effect, (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
309
311
|
/**
|
|
310
312
|
* Resolve every declared config dependency at its declared version, in
|
|
311
313
|
* declaration order. A dependency that ships no pnpmfile is still returned
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { causeMessage } from "./causeMessage.js";
|
|
1
2
|
import { Effect, Option, Predicate, Result } from "effect";
|
|
2
3
|
import { CatalogAssemblyError } from "@effected/npm";
|
|
3
4
|
import { PackageJsonFormat } from "@effected/package-json";
|
|
@@ -12,8 +13,8 @@ const hooksError = (path, cause, reason) => new CatalogAssemblyError({
|
|
|
12
13
|
cause,
|
|
13
14
|
...reason === void 0 ? {} : { reason }
|
|
14
15
|
});
|
|
15
|
-
/** The message of a cause, for splicing into ours. */
|
|
16
|
-
const messageOf = (cause) => cause
|
|
16
|
+
/** The message of a cause, for splicing into ours; a cause with no message renders as its string form. */
|
|
17
|
+
const messageOf = (cause) => causeMessage(cause) ?? String(cause);
|
|
17
18
|
/** Where the declared spec came from, for messages: `the working tree` or `ref <ref>`. */
|
|
18
19
|
const sideLabel = (side) => side.ref === void 0 ? "the working tree" : `ref ${side.ref}`;
|
|
19
20
|
/** Whether a `node:fs` rejection means "nothing there" (as opposed to a real IO failure). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/workspaces",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.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": [
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"@effected/git": "^0.25.0",
|
|
56
56
|
"@effected/glob": "^0.14.0",
|
|
57
57
|
"@effected/jsonc": "^0.20.0",
|
|
58
|
-
"@effected/lockfiles": "^0.19.
|
|
59
|
-
"@effected/npm": "^0.26.
|
|
60
|
-
"@effected/package-json": "^0.25.
|
|
61
|
-
"@effected/semver": "^0.
|
|
58
|
+
"@effected/lockfiles": "^0.19.3",
|
|
59
|
+
"@effected/npm": "^0.26.1",
|
|
60
|
+
"@effected/package-json": "^0.25.1",
|
|
61
|
+
"@effected/semver": "^0.17.0",
|
|
62
62
|
"@effected/walker": "^0.19.0",
|
|
63
|
-
"@effected/yaml": "^0.
|
|
63
|
+
"@effected/yaml": "^0.25.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
|
@@ -1370,13 +1370,18 @@ interface PackedInstallOptions extends PackedInstallClosureOptions {
|
|
|
1370
1370
|
declare const PackedInstallError_base: Schema.Class<PackedInstallError, Schema.TaggedStruct<"PackedInstallError", {
|
|
1371
1371
|
/** What failed. */
|
|
1372
1372
|
readonly reason: Schema.Literals<readonly ["UnsupportedPlatform", "NoManagerAvailable", "ManagerUnavailable", "UnknownPackage", "PackSourceMissing", "PackFailed", "UnresolvedProtocol", "InvalidOverride", "BinConflict", "InstallFailed", "MissingBin", "BinFailed", "UnownedBin", "Discovery", "Io"]>;
|
|
1373
|
-
/**
|
|
1373
|
+
/**
|
|
1374
|
+
* Names the package or manager involved. For `PackFailed` and
|
|
1375
|
+
* `InstallFailed` on a non-zero exit it continues with the last few lines
|
|
1376
|
+
* of the command's output, so a log that prints only the message is still
|
|
1377
|
+
* actionable; `output` carries the longer tail.
|
|
1378
|
+
*/
|
|
1374
1379
|
readonly message: Schema.String;
|
|
1375
1380
|
/** The package manager involved. */
|
|
1376
1381
|
readonly manager: Schema.optionalKey<Schema.Literals<readonly ["npm", "pnpm", "yarn", "bun"]>>;
|
|
1377
1382
|
/** The workspace package involved. */
|
|
1378
1383
|
readonly package: Schema.optionalKey<Schema.String>;
|
|
1379
|
-
/** The tail of the failing command's output. */
|
|
1384
|
+
/** The tail of the failing command's output, both streams, stdout first. */
|
|
1380
1385
|
readonly output: Schema.optionalKey<Schema.String>;
|
|
1381
1386
|
/** The originating failure. */
|
|
1382
1387
|
readonly cause: Schema.optionalKey<Schema.Defect>;
|