@effected/workspaces 0.36.1 → 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 +7 -10
- package/PackageManagerName.js +7 -17
- package/PackedInstall.js +39 -13
- package/WorkspaceCatalogs.js +14 -25
- package/WorkspaceDiscovery.js +11 -22
- package/WorkspacePackage.js +6 -9
- package/WorkspaceRoot.js +5 -7
- package/WorkspaceSnapshots.js +11 -21
- package/Workspaces.js +12 -3
- package/WorkspacesSync.js +12 -17
- package/index.d.ts +45 -25
- package/internal/causeMessage.js +39 -0
- package/internal/configDependencyResolution.js +40 -15
- package/internal/configDependencyShared.js +11 -9
- package/internal/guards.js +12 -0
- package/internal/layerRoot.js +13 -7
- package/internal/packedInstallPlan.js +12 -23
- package/internal/patterns.js +9 -9
- package/package.json +9 -9
- package/testing.d.ts +14 -8
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
|
@@ -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,16 +86,12 @@ 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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})
|
|
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
|
-
const [
|
|
97
|
-
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);
|
|
98
95
|
return {
|
|
99
96
|
read: Effect.fn("LockfileReader.read")(function* () {
|
|
100
97
|
return yield* memo;
|
package/PackageManagerName.js
CHANGED
|
@@ -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 (!
|
|
101
|
+
if (!Predicate.isObject(devEngines)) return Option.none();
|
|
104
102
|
const slot = devEngines.packageManager;
|
|
105
|
-
if (!
|
|
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.
|
|
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
|
|
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";
|
|
@@ -31,13 +32,18 @@ var PackedInstallError = class extends Schema.TaggedError()("PackedInstallError"
|
|
|
31
32
|
"Discovery",
|
|
32
33
|
"Io"
|
|
33
34
|
]),
|
|
34
|
-
/**
|
|
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
|
+
*/
|
|
35
41
|
message: Schema.String,
|
|
36
42
|
/** The package manager involved. */
|
|
37
43
|
manager: Schema.optionalKey(PackageManagerName),
|
|
38
44
|
/** The workspace package involved. */
|
|
39
45
|
package: Schema.optionalKey(Schema.String),
|
|
40
|
-
/** The tail of the failing command's output. */
|
|
46
|
+
/** The tail of the failing command's output, both streams, stdout first. */
|
|
41
47
|
output: Schema.optionalKey(Schema.String),
|
|
42
48
|
/** The originating failure. */
|
|
43
49
|
cause: Schema.optionalKey(Schema.Defect())
|
|
@@ -129,11 +135,12 @@ var InstalledConsumer = class extends Schema.Class("InstalledConsumer")({
|
|
|
129
135
|
const manifest = path.join(dir, "package.json");
|
|
130
136
|
if (!(yield* fs.exists(manifest).pipe(Effect.mapError(io(`could not inspect ${manifest}`))))) continue;
|
|
131
137
|
const text = yield* fs.readFileString(manifest).pipe(Effect.mapError(io(`could not read ${manifest}`)));
|
|
132
|
-
const parsed =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
const parsed = PackageJsonFormat.parseObjectResult(text);
|
|
139
|
+
if (Result.isFailure(parsed)) {
|
|
140
|
+
if (parsed.failure.reason === "invalid-json") return yield* io(`${manifest} is not JSON`)(parsed.failure);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const named = parsed.success.name;
|
|
137
144
|
if (typeof named === "string") return {
|
|
138
145
|
package: named,
|
|
139
146
|
target
|
|
@@ -341,6 +348,21 @@ const DEFAULT_PACK_FROM = { directory: "dist/prod/npm/pkg" };
|
|
|
341
348
|
const WORKSPACE_PROTOCOL_NOT_INSTALLED = "ERR_PNPM_CANNOT_RESOLVE_WORKSPACE_PROTOCOL";
|
|
342
349
|
const TAIL = 2e3;
|
|
343
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
|
+
};
|
|
344
366
|
const DEFAULT_INSTALL_TIMEOUT = "4 minutes";
|
|
345
367
|
const PROBE_TIMEOUT = "30 seconds";
|
|
346
368
|
const DEFAULT_PACK_TIMEOUT = "2 minutes";
|
|
@@ -765,9 +787,10 @@ var PackedInstall = class PackedInstall {
|
|
|
765
787
|
})));
|
|
766
788
|
if (!output.succeeded) {
|
|
767
789
|
const notInstalled = packer === "pnpm" && `${output.stdout}${output.stderr}`.includes(WORKSPACE_PROTOCOL_NOT_INSTALLED);
|
|
768
|
-
|
|
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), {
|
|
769
792
|
package: name,
|
|
770
|
-
output:
|
|
793
|
+
output: captured
|
|
771
794
|
});
|
|
772
795
|
}
|
|
773
796
|
const found = (yield* fs.readDirectory(destination).pipe(Effect.mapError(io(`could not list ${destination}`)))).filter((file) => file.endsWith(".tgz"));
|
|
@@ -844,10 +867,13 @@ var PackedInstall = class PackedInstall {
|
|
|
844
867
|
manager,
|
|
845
868
|
cause
|
|
846
869
|
})));
|
|
847
|
-
if (!output.succeeded)
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
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
|
+
}
|
|
851
877
|
const consumer = InstalledConsumer.make({
|
|
852
878
|
manager,
|
|
853
879
|
managerVersion: version,
|
package/WorkspaceCatalogs.js
CHANGED
|
@@ -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.
|
|
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
|
|
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"
|
|
@@ -413,8 +403,7 @@ var WorkspaceCatalogs = class WorkspaceCatalogs extends Context.Service()("@effe
|
|
|
413
403
|
hookReplays
|
|
414
404
|
};
|
|
415
405
|
});
|
|
416
|
-
const [
|
|
417
|
-
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);
|
|
418
407
|
return {
|
|
419
408
|
set: Effect.fn("WorkspaceCatalogs.set")(function* () {
|
|
420
409
|
return (yield* memo).catalogs;
|
package/WorkspaceDiscovery.js
CHANGED
|
@@ -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
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
|
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
|
|
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,
|
|
@@ -258,8 +250,7 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
|
|
|
258
250
|
const root = yield* findLayerRoot(roots, options);
|
|
259
251
|
return yield* discoverAt(root);
|
|
260
252
|
});
|
|
261
|
-
const [
|
|
262
|
-
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);
|
|
263
254
|
/**
|
|
264
255
|
* Per-resolved-root memos for the `…In` methods, each success-only on the
|
|
265
256
|
* same discipline as the layer-bound one above.
|
|
@@ -281,8 +272,7 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
|
|
|
281
272
|
const root = yield* roots.find(directory);
|
|
282
273
|
const existing = rootMemos.get(root);
|
|
283
274
|
if (existing !== void 0) return yield* existing.memo;
|
|
284
|
-
const [
|
|
285
|
-
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);
|
|
286
276
|
const raced = rootMemos.get(root);
|
|
287
277
|
if (raced !== void 0) return yield* raced.memo;
|
|
288
278
|
rootMemos.set(root, {
|
|
@@ -555,6 +545,5 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
|
|
|
555
545
|
} };
|
|
556
546
|
}));
|
|
557
547
|
};
|
|
558
|
-
const isStringRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
559
548
|
|
|
560
549
|
export { PackageNotFoundError, WorkspaceDiscovery, WorkspaceDiscoveryError, WorkspaceInfo, WorkspacePatternError };
|
package/WorkspacePackage.js
CHANGED
|
@@ -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.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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 =
|
|
60
|
-
|
|
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) };
|
package/WorkspaceSnapshots.js
CHANGED
|
@@ -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
|
|
@@ -89,11 +80,11 @@ const unstubbed = (method) => Effect.die(/* @__PURE__ */ new Error(`WorkspaceSna
|
|
|
89
80
|
* Reads workspace state at a git ref with no checkout, and the live worktree.
|
|
90
81
|
*
|
|
91
82
|
* @remarks
|
|
92
|
-
* `at(ref)` is cached per `(resolved root, ref)` via
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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.
|
|
97
88
|
*
|
|
98
89
|
* @example
|
|
99
90
|
* ```ts
|
|
@@ -215,8 +206,7 @@ var WorkspaceSnapshots = class WorkspaceSnapshots extends Context.Service()("@ef
|
|
|
215
206
|
const key = `${root}\0${ref}`;
|
|
216
207
|
let memo = atCaches.get(key);
|
|
217
208
|
if (memo === void 0) {
|
|
218
|
-
const
|
|
219
|
-
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);
|
|
220
210
|
const existing = atCaches.get(key);
|
|
221
211
|
if (existing !== void 0) memo = existing;
|
|
222
212
|
else {
|
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 ??
|
|
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 `
|
|
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 `
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
49
|
+
let text;
|
|
55
50
|
try {
|
|
56
|
-
|
|
51
|
+
text = fileSystem.readFile(file);
|
|
57
52
|
} catch {
|
|
58
53
|
return;
|
|
59
54
|
}
|
|
60
|
-
return
|
|
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) =>
|
|
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 `
|
|
537
|
-
* `process.chdir` between providing the layer and the first
|
|
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
|
|
659
|
-
*
|
|
660
|
-
*
|
|
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 `
|
|
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 `
|
|
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 `
|
|
3834
|
-
*
|
|
3835
|
-
*
|
|
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
|
/**
|
|
@@ -3906,11 +3910,11 @@ declare const WorkspaceSnapshots_base: Context.ServiceClass<WorkspaceSnapshots,
|
|
|
3906
3910
|
* Reads workspace state at a git ref with no checkout, and the live worktree.
|
|
3907
3911
|
*
|
|
3908
3912
|
* @remarks
|
|
3909
|
-
* `at(ref)` is cached per `(resolved root, ref)` via
|
|
3910
|
-
*
|
|
3911
|
-
*
|
|
3912
|
-
*
|
|
3913
|
-
*
|
|
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.
|
|
3914
3918
|
*
|
|
3915
3919
|
* @example
|
|
3916
3920
|
* ```ts
|
|
@@ -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 `
|
|
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 `
|
|
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 `
|
|
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
|
-
*
|
|
4581
|
-
*
|
|
4582
|
-
*
|
|
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
|
|
4595
|
-
*
|
|
4596
|
-
* `
|
|
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
|
}
|
|
@@ -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 };
|
|
@@ -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
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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
|
|
109
|
-
|
|
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 (
|
|
113
|
-
if (
|
|
114
|
-
if (platform === "win32" &&
|
|
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)));
|
|
@@ -279,10 +302,12 @@ const resolveDirectory = (root, entry, stores, locks, options) => Effect.gen(fun
|
|
|
279
302
|
});
|
|
280
303
|
/**
|
|
281
304
|
* A lazy memo of `effect`, scoped to one {@link resolvePnpmfiles} call: the
|
|
282
|
-
* house success-only memo (never `Effect.cached`, which would pin
|
|
283
|
-
*
|
|
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.
|
|
284
309
|
*/
|
|
285
|
-
const memoizeSuccess = (effect) => Effect.
|
|
310
|
+
const memoizeSuccess = (effect) => Effect.cachedWithTTL(effect, (exit) => Exit.isSuccess(exit) ? Duration.infinity : Duration.zero);
|
|
286
311
|
/**
|
|
287
312
|
* Resolve every declared config dependency at its declared version, in
|
|
288
313
|
* declaration order. A dependency that ships no pnpmfile is still returned
|
|
@@ -330,4 +355,4 @@ const lookupPnpmfiles = (entries, configDependencies) => Effect.flatMap(declared
|
|
|
330
355
|
});
|
|
331
356
|
}));
|
|
332
357
|
|
|
333
|
-
export { lookupPnpmfiles, resolvePnpmfiles };
|
|
358
|
+
export { environmentStoreRoots, lookupPnpmfiles, resolvePnpmfiles };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { causeMessage } from "./causeMessage.js";
|
|
2
|
+
import { Effect, Option, Predicate, Result } from "effect";
|
|
2
3
|
import { CatalogAssemblyError } from "@effected/npm";
|
|
4
|
+
import { PackageJsonFormat } from "@effected/package-json";
|
|
3
5
|
import { readFile } from "node:fs/promises";
|
|
4
6
|
import { join } from "node:path";
|
|
5
7
|
|
|
@@ -11,8 +13,8 @@ const hooksError = (path, cause, reason) => new CatalogAssemblyError({
|
|
|
11
13
|
cause,
|
|
12
14
|
...reason === void 0 ? {} : { reason }
|
|
13
15
|
});
|
|
14
|
-
/** The message of a cause, for splicing into ours. */
|
|
15
|
-
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);
|
|
16
18
|
/** Where the declared spec came from, for messages: `the working tree` or `ref <ref>`. */
|
|
17
19
|
const sideLabel = (side) => side.ref === void 0 ? "the working tree" : `ref ${side.ref}`;
|
|
18
20
|
/** Whether a `node:fs` rejection means "nothing there" (as opposed to a real IO failure). */
|
|
@@ -38,13 +40,13 @@ const carries = (manifest, declared) => manifest._tag === "version" && manifest.
|
|
|
38
40
|
*/
|
|
39
41
|
const manifestVersion = (name, dir) => ioOrNone(name, () => readFile(join(dir, "package.json"), "utf8")).pipe(Effect.flatMap((text) => {
|
|
40
42
|
if (Option.isNone(text)) return Effect.succeed(ABSENT);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const parsed = PackageJsonFormat.parseObjectResult(text.value);
|
|
44
|
+
if (Result.isFailure(parsed)) return parsed.failure.reason === "invalid-json" ? Effect.fail(hooksError(name, parsed.failure)) : Effect.succeed(UNVERSIONED);
|
|
45
|
+
const version = parsed.success.version;
|
|
46
|
+
return Effect.succeed(typeof version === "string" && version !== "" ? {
|
|
45
47
|
_tag: "version",
|
|
46
|
-
version
|
|
47
|
-
} : UNVERSIONED)
|
|
48
|
+
version
|
|
49
|
+
} : UNVERSIONED);
|
|
48
50
|
}));
|
|
49
51
|
|
|
50
52
|
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 };
|
package/internal/layerRoot.js
CHANGED
|
@@ -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.
|
|
6
|
-
*
|
|
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) =>
|
|
14
|
+
const findLayerRoot = (roots, options) => {
|
|
9
15
|
const stopAt = options?.stopAt;
|
|
10
|
-
return roots.find(options?.cwd ??
|
|
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
|
|
170
|
-
const readPackedManifest = (manifestJson) =>
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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)
|
|
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)
|
|
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);
|
package/internal/patterns.js
CHANGED
|
@@ -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 =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.
|
|
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": [
|
|
@@ -51,16 +51,16 @@
|
|
|
51
51
|
"./package.json": "./package.json"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@effected/commands": "^0.15.
|
|
55
|
-
"@effected/git": "^0.
|
|
54
|
+
"@effected/commands": "^0.15.1",
|
|
55
|
+
"@effected/git": "^0.25.0",
|
|
56
56
|
"@effected/glob": "^0.14.0",
|
|
57
|
-
"@effected/jsonc": "^0.
|
|
58
|
-
"@effected/lockfiles": "^0.19.
|
|
59
|
-
"@effected/npm": "^0.
|
|
60
|
-
"@effected/package-json": "^0.
|
|
61
|
-
"@effected/semver": "^0.
|
|
57
|
+
"@effected/jsonc": "^0.20.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
|
@@ -525,9 +525,10 @@ interface WorkspaceDiscoveryOptions {
|
|
|
525
525
|
/**
|
|
526
526
|
* The directory the workspace root is resolved from.
|
|
527
527
|
*
|
|
528
|
-
* @defaultValue `
|
|
529
|
-
* `process.chdir` between providing the layer and the first
|
|
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
|
|
651
|
-
*
|
|
652
|
-
*
|
|
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
|
|
@@ -1369,13 +1370,18 @@ interface PackedInstallOptions extends PackedInstallClosureOptions {
|
|
|
1369
1370
|
declare const PackedInstallError_base: Schema.Class<PackedInstallError, Schema.TaggedStruct<"PackedInstallError", {
|
|
1370
1371
|
/** What failed. */
|
|
1371
1372
|
readonly reason: Schema.Literals<readonly ["UnsupportedPlatform", "NoManagerAvailable", "ManagerUnavailable", "UnknownPackage", "PackSourceMissing", "PackFailed", "UnresolvedProtocol", "InvalidOverride", "BinConflict", "InstallFailed", "MissingBin", "BinFailed", "UnownedBin", "Discovery", "Io"]>;
|
|
1372
|
-
/**
|
|
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
|
+
*/
|
|
1373
1379
|
readonly message: Schema.String;
|
|
1374
1380
|
/** The package manager involved. */
|
|
1375
1381
|
readonly manager: Schema.optionalKey<Schema.Literals<readonly ["npm", "pnpm", "yarn", "bun"]>>;
|
|
1376
1382
|
/** The workspace package involved. */
|
|
1377
1383
|
readonly package: Schema.optionalKey<Schema.String>;
|
|
1378
|
-
/** The tail of the failing command's output. */
|
|
1384
|
+
/** The tail of the failing command's output, both streams, stdout first. */
|
|
1379
1385
|
readonly output: Schema.optionalKey<Schema.String>;
|
|
1380
1386
|
/** The originating failure. */
|
|
1381
1387
|
readonly cause: Schema.optionalKey<Schema.Defect>;
|