@effected/workspaces 0.46.0 → 0.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LayerPolicy.js +1 -1
- package/WorkspaceDiscovery.js +18 -8
- package/WorkspaceLayering.js +1 -1
- package/WorkspacePackage.js +1 -1
- package/WorkspaceSnapshots.js +14 -7
- package/WorkspacesSync.js +39 -20
- package/index.d.ts +18 -5
- package/internal/enumerate.js +10 -9
- package/internal/membership.js +95 -0
- package/internal/patterns.js +20 -12
- package/package.json +5 -5
- package/testing.d.ts +6 -0
package/LayerPolicy.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { causeMessage } from "./internal/causeMessage.js";
|
|
2
2
|
import { ALL_DEPENDENCY_FIELDS } from "./internal/dependencyFields.js";
|
|
3
3
|
import { Effect, FileSystem, Result, Schema } from "effect";
|
|
4
|
-
import { GlobSet } from "@effected/glob";
|
|
5
4
|
import { DependencyField } from "@effected/npm";
|
|
5
|
+
import { GlobSet } from "@effected/glob";
|
|
6
6
|
|
|
7
7
|
// src/LayerPolicy.ts
|
|
8
8
|
const REQUIRED_EDGE = /^\S+ -> \S+$/u;
|
package/WorkspaceDiscovery.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { enumerate } from "./internal/enumerate.js";
|
|
2
2
|
import { isStringRecord } from "./internal/guards.js";
|
|
3
3
|
import { findLayerRoot } from "./internal/layerRoot.js";
|
|
4
|
-
import {
|
|
4
|
+
import { membershipOf, rulesFor } from "./internal/membership.js";
|
|
5
|
+
import { MARKER_FILES } from "./internal/packageManagerDecision.js";
|
|
6
|
+
import { readPatternSource } from "./internal/patterns.js";
|
|
5
7
|
import { WorkspacePackage } from "./WorkspacePackage.js";
|
|
6
8
|
import { WorkspaceRoot } from "./WorkspaceRoot.js";
|
|
7
9
|
import { Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Schema } from "effect";
|
|
8
|
-
import { GlobSet } from "@effected/glob";
|
|
9
10
|
import { DependencyResolutionError, WorkspaceResolver } from "@effected/npm";
|
|
10
11
|
import { PackageJsonFormat } from "@effected/package-json";
|
|
11
12
|
|
|
@@ -70,7 +71,13 @@ var WorkspacePatternError = class extends Schema.TaggedError()("WorkspacePattern
|
|
|
70
71
|
"unreadableDirectory"
|
|
71
72
|
]),
|
|
72
73
|
/** A short, structured detail — the missing directory, or the bound exceeded. */
|
|
73
|
-
detail: Schema.String
|
|
74
|
+
detail: Schema.String,
|
|
75
|
+
/**
|
|
76
|
+
* For `uncompilable`: the typed error that stopped the patterns being read —
|
|
77
|
+
* glob's `GlobPatternError`, or `@effected/npm`'s `NpmWorkspacePatternsError`
|
|
78
|
+
* when an npm root's `workspaces` field passes one of npm's pattern ceilings.
|
|
79
|
+
*/
|
|
80
|
+
cause: Schema.optionalKey(Schema.Defect())
|
|
74
81
|
}) {
|
|
75
82
|
/** Renders the pattern and failure kind into a one-line message. */
|
|
76
83
|
get message() {
|
|
@@ -216,19 +223,22 @@ var WorkspaceDiscovery = class WorkspaceDiscovery extends Context.Service()("@ef
|
|
|
216
223
|
* branch that adds or removes a package stays invisible. This re-reads.
|
|
217
224
|
*/
|
|
218
225
|
const discoverAt = (root) => Effect.gen(function* () {
|
|
219
|
-
const
|
|
226
|
+
const source = yield* readPatternSource(root).pipe(Effect.mapError((failure) => new WorkspaceDiscoveryError({
|
|
220
227
|
root,
|
|
221
228
|
path: failure.path,
|
|
222
229
|
kind: failure.kind,
|
|
223
230
|
cause: failure.cause
|
|
224
231
|
})));
|
|
225
|
-
const
|
|
232
|
+
const { patterns } = source;
|
|
233
|
+
const present = Option.isNone(source.manifest) ? /* @__PURE__ */ new Set() : new Set(yield* Effect.filter(MARKER_FILES, (file) => fs.exists(path.join(root, file)).pipe(Effect.orElseSucceed(() => false))));
|
|
234
|
+
const membership = yield* Effect.fromResult(membershipOf(patterns, rulesFor(source.manifest, (file) => present.has(file)))).pipe(Effect.mapError((failure) => new WorkspacePatternError({
|
|
226
235
|
root,
|
|
227
|
-
pattern:
|
|
236
|
+
pattern: failure.pattern,
|
|
228
237
|
kind: "uncompilable",
|
|
229
|
-
detail:
|
|
238
|
+
detail: failure.detail,
|
|
239
|
+
cause: failure.cause
|
|
230
240
|
})));
|
|
231
|
-
const directories = yield* enumerate(root,
|
|
241
|
+
const directories = yield* enumerate(root, membership, { maxDepth: options?.maxDepth ?? 32 }).pipe(Effect.mapError((failure) => new WorkspacePatternError({
|
|
232
242
|
root,
|
|
233
243
|
pattern: failure.pattern,
|
|
234
244
|
kind: patternKindOf(failure.kind),
|
package/WorkspaceLayering.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ALL_DEPENDENCY_FIELDS } from "./internal/dependencyFields.js";
|
|
2
2
|
import { WorkspaceDiscovery } from "./WorkspaceDiscovery.js";
|
|
3
3
|
import { Effect, Graph, Option, Schema } from "effect";
|
|
4
|
-
import { GlobSet } from "@effected/glob";
|
|
5
4
|
import { DependencyField } from "@effected/npm";
|
|
5
|
+
import { GlobSet } from "@effected/glob";
|
|
6
6
|
|
|
7
7
|
// src/WorkspaceLayering.ts
|
|
8
8
|
/**
|
package/WorkspacePackage.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, FileSystem, Option, Schema } from "effect";
|
|
2
|
-
import { GlobPattern } from "@effected/glob";
|
|
3
2
|
import { Package, PackageJsonFormat } from "@effected/package-json";
|
|
3
|
+
import { GlobPattern } from "@effected/glob";
|
|
4
4
|
import { WorkspaceManifest } from "@effected/lockfiles";
|
|
5
5
|
|
|
6
6
|
// src/WorkspacePackage.ts
|
package/WorkspaceSnapshots.js
CHANGED
|
@@ -2,6 +2,7 @@ import { ConfigDependencyHooks } from "./ConfigDependencyHooks.js";
|
|
|
2
2
|
import { isStringRecord } from "./internal/guards.js";
|
|
3
3
|
import { importerVersionsOf } from "./internal/importerVersions.js";
|
|
4
4
|
import { findLayerRoot } from "./internal/layerRoot.js";
|
|
5
|
+
import { membershipOf, rulesFor } from "./internal/membership.js";
|
|
5
6
|
import { manifestPatternsOf, pnpmPatternsOf } from "./internal/patterns.js";
|
|
6
7
|
import { CatalogSet, WorkspaceCatalogs, injectFromDocument } from "./WorkspaceCatalogs.js";
|
|
7
8
|
import { WorkspaceDiscovery } from "./WorkspaceDiscovery.js";
|
|
@@ -9,7 +10,6 @@ import { WorkspaceRoot } from "./WorkspaceRoot.js";
|
|
|
9
10
|
import { PackageStateSnapshot, WorkspaceStateSnapshot } from "./WorkspaceStateSnapshot.js";
|
|
10
11
|
import { Git } from "@effected/git";
|
|
11
12
|
import { Context, Duration, Effect, Exit, Layer, Option, Predicate, Result } from "effect";
|
|
12
|
-
import { GlobSet } from "@effected/glob";
|
|
13
13
|
import { CatalogAssemblyError } from "@effected/npm";
|
|
14
14
|
import { PackageJsonFormat } from "@effected/package-json";
|
|
15
15
|
import { Yaml } from "@effected/yaml";
|
|
@@ -140,6 +140,7 @@ var WorkspaceSnapshots = class WorkspaceSnapshots extends Context.Service()("@ef
|
|
|
140
140
|
onSome: parseJsonObject
|
|
141
141
|
});
|
|
142
142
|
let patterns;
|
|
143
|
+
let patternManifest = Option.none();
|
|
143
144
|
let inline;
|
|
144
145
|
let injected;
|
|
145
146
|
let recorded;
|
|
@@ -152,6 +153,7 @@ var WorkspaceSnapshots = class WorkspaceSnapshots extends Context.Service()("@ef
|
|
|
152
153
|
})));
|
|
153
154
|
const pnpmPatterns = pnpmPatternsOf(document);
|
|
154
155
|
patterns = pnpmPatterns.length > 0 ? pnpmPatterns : manifestPatternsOf(rootManifest);
|
|
156
|
+
if (pnpmPatterns.length === 0) patternManifest = Option.some(rootManifest);
|
|
155
157
|
inline = yield* CatalogSet.fromWorkspaceYaml(pnpmWorkspaceText.value);
|
|
156
158
|
const lockfile = yield* lockfileText(root, ref, "pnpm");
|
|
157
159
|
const replayed = yield* injectFromDocument(hooks, root, document, inline, {
|
|
@@ -163,17 +165,22 @@ var WorkspaceSnapshots = class WorkspaceSnapshots extends Context.Service()("@ef
|
|
|
163
165
|
recorded = yield* lockfileRecord(lockfile, "pnpm");
|
|
164
166
|
} else {
|
|
165
167
|
patterns = manifestPatternsOf(rootManifest);
|
|
168
|
+
patternManifest = Option.some(rootManifest);
|
|
166
169
|
inline = bunInlineCatalogs(rootManifest);
|
|
167
170
|
injected = CatalogSet.empty();
|
|
168
171
|
recorded = yield* lockfileRecord(yield* lockfileText(root, ref, "bun"), "bun");
|
|
169
172
|
}
|
|
170
173
|
const catalogs = CatalogSet.merge(recorded.catalogs, inline, injected);
|
|
171
|
-
const globs = yield* GlobSet.compile(patterns).pipe(Effect.mapError((error) => new CatalogAssemblyError({
|
|
172
|
-
source: "manifest",
|
|
173
|
-
path: error.pattern,
|
|
174
|
-
cause: error
|
|
175
|
-
})));
|
|
176
174
|
const entries = yield* git.lsTree(root, ref);
|
|
175
|
+
const rootFiles = /* @__PURE__ */ new Set();
|
|
176
|
+
for (const entry of entries) if (entry.type === "blob" && !entry.path.includes("/")) rootFiles.add(entry.path);
|
|
177
|
+
const membership = membershipOf(patterns, rulesFor(patternManifest, (file) => rootFiles.has(file)));
|
|
178
|
+
if (Result.isFailure(membership)) return yield* new CatalogAssemblyError({
|
|
179
|
+
source: "manifest",
|
|
180
|
+
path: membership.failure.pattern,
|
|
181
|
+
cause: membership.failure.cause
|
|
182
|
+
});
|
|
183
|
+
const isMember = membership.success.matches;
|
|
177
184
|
const memberDirs = [];
|
|
178
185
|
let hasRootManifest = false;
|
|
179
186
|
for (const entry of entries) {
|
|
@@ -184,7 +191,7 @@ var WorkspaceSnapshots = class WorkspaceSnapshots extends Context.Service()("@ef
|
|
|
184
191
|
}
|
|
185
192
|
if (!entry.path.endsWith("/package.json")) continue;
|
|
186
193
|
const dir = entry.path.slice(0, entry.path.length - 13);
|
|
187
|
-
if (
|
|
194
|
+
if (isMember(dir)) memberDirs.push(dir);
|
|
188
195
|
}
|
|
189
196
|
memberDirs.sort();
|
|
190
197
|
const members = yield* Effect.forEach(memberDirs, (dir) => git.show(root, ref, `./${dir}/package.json`).pipe(Effect.map((content) => snapshotOf(content, dir))), { concurrency: 10 });
|
package/WorkspacesSync.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isStringRecord } from "./internal/guards.js";
|
|
2
|
+
import { membershipOf, rulesFor } from "./internal/membership.js";
|
|
2
3
|
import { decidePackageManager } from "./internal/packageManagerDecision.js";
|
|
3
4
|
import { manifestPatternsOf, pnpmPatternsOf } from "./internal/patterns.js";
|
|
4
5
|
import { Traversal, badMaxDepthMessage, isPruned, isValidMaxDepth, joinRelative } from "./internal/traverse.js";
|
|
@@ -7,7 +8,6 @@ import { WorkspaceDiscoveryError, WorkspacePatternError } from "./WorkspaceDisco
|
|
|
7
8
|
import { WorkspaceRootMatch, probedMarkers } from "./WorkspaceMarker.js";
|
|
8
9
|
import { PublishConfig, WorkspaceManifestError, WorkspacePackage } from "./WorkspacePackage.js";
|
|
9
10
|
import { Effect, Exit, Option, Result, Schema } from "effect";
|
|
10
|
-
import { GlobSet } from "@effected/glob";
|
|
11
11
|
import { PackageJsonFormat } from "@effected/package-json";
|
|
12
12
|
import { Yaml } from "@effected/yaml";
|
|
13
13
|
import { LocalExec, LocalExecError } from "@effected/commands";
|
|
@@ -239,10 +239,16 @@ const readPatternsSync = (options, root) => {
|
|
|
239
239
|
cause: parsed.failure
|
|
240
240
|
});
|
|
241
241
|
const patterns = pnpmPatternsOf(parsed.success);
|
|
242
|
-
if (patterns.length > 0) return
|
|
242
|
+
if (patterns.length > 0) return {
|
|
243
|
+
patterns,
|
|
244
|
+
manifest: Option.none()
|
|
245
|
+
};
|
|
243
246
|
}
|
|
244
247
|
const manifestPath = path.join(root, "package.json");
|
|
245
|
-
if (!fileSystem.exists(manifestPath)) return
|
|
248
|
+
if (!fileSystem.exists(manifestPath)) return {
|
|
249
|
+
patterns: [],
|
|
250
|
+
manifest: Option.none()
|
|
251
|
+
};
|
|
246
252
|
let content;
|
|
247
253
|
try {
|
|
248
254
|
content = fileSystem.readFile(manifestPath);
|
|
@@ -255,8 +261,14 @@ const readPatternsSync = (options, root) => {
|
|
|
255
261
|
});
|
|
256
262
|
}
|
|
257
263
|
const manifest = PackageJsonFormat.parseObjectResult(content);
|
|
258
|
-
if (Result.isSuccess(manifest)) return
|
|
259
|
-
|
|
264
|
+
if (Result.isSuccess(manifest)) return {
|
|
265
|
+
patterns: manifestPatternsOf(manifest.success),
|
|
266
|
+
manifest: Option.some(manifest.success)
|
|
267
|
+
};
|
|
268
|
+
if (manifest.failure.reason === "not-an-object") return {
|
|
269
|
+
patterns: [],
|
|
270
|
+
manifest: Option.none()
|
|
271
|
+
};
|
|
260
272
|
throw new WorkspaceDiscoveryError({
|
|
261
273
|
root,
|
|
262
274
|
path: manifestPath,
|
|
@@ -331,7 +343,12 @@ const readPackageSync = (options, root, directory, relativePath) => {
|
|
|
331
343
|
* drive the **same traversal state machine** (`internal/traverse.ts`), so the
|
|
332
344
|
* dequeue order, the depth rule, the visit budget and the prune list cannot
|
|
333
345
|
* drift apart. A `packages/**` finds exactly the same packages here as there,
|
|
334
|
-
* including at the depth boundary.
|
|
346
|
+
* including at the depth boundary. Which directories the patterns declare is
|
|
347
|
+
* one decision too: on an npm root (as `detectPackageManagerSync` would
|
|
348
|
+
* report it) `package.json#workspaces` is read the way npm reads it, through
|
|
349
|
+
* `@effected/npm`'s `NpmWorkspacePatterns` — ordered negation, a trailing
|
|
350
|
+
* `/`, an even `!` run, a backslash as a separator — and on a pnpm, yarn or
|
|
351
|
+
* bun root as one `GlobSet`.
|
|
335
352
|
*
|
|
336
353
|
* The one deliberate difference is what happens at a bound: the Effect surface
|
|
337
354
|
* fails typed (`depthExceeded` / `budgetExceeded`), while this one truncates.
|
|
@@ -342,8 +359,9 @@ const readPackageSync = (options, root, directory, relativePath) => {
|
|
|
342
359
|
*
|
|
343
360
|
* **A pattern set that does not compile throws.** The patterns compile as one
|
|
344
361
|
* `GlobSet`, and when that fails — one malformed member, or members that each
|
|
345
|
-
* compile alone but together exhaust the set's shared compile budget
|
|
346
|
-
*
|
|
362
|
+
* compile alone but together exhaust the set's shared compile budget, or an
|
|
363
|
+
* npm root's `workspaces` field past one of `NpmWorkspacePatterns`' ceilings —
|
|
364
|
+
* there is no partial answer to degrade to: every pattern is lost at once. Returning
|
|
347
365
|
* the root alone would read as "no workspace packages", a decision taken on a
|
|
348
366
|
* corrupt config, so the facade throws the `WorkspacePatternError` (kind
|
|
349
367
|
* `"uncompilable"`, `pattern` the member the compile stopped at) that
|
|
@@ -375,8 +393,9 @@ const readPackageSync = (options, root, directory, relativePath) => {
|
|
|
375
393
|
* `pnpm-workspace.yaml` exists but cannot be read or parsed, and (kind
|
|
376
394
|
* `"read"` or `"invalidJson"`) when the root `package.json` is the pattern
|
|
377
395
|
* source and exists but cannot be read or parsed;
|
|
378
|
-
* `WorkspacePatternError` (kind `"uncompilable"`
|
|
379
|
-
* `packages:` patterns do not compile as one `GlobSet
|
|
396
|
+
* `WorkspacePatternError` (kind `"uncompilable"`, `cause` the typed error)
|
|
397
|
+
* when the workspace's `packages:` patterns do not compile as one `GlobSet`
|
|
398
|
+
* or, on an npm root, pass an `NpmWorkspacePatterns` ceiling; `RangeError` for a
|
|
380
399
|
* `maxDepth` that is not a positive integer.
|
|
381
400
|
*
|
|
382
401
|
* @example
|
|
@@ -404,20 +423,20 @@ const getWorkspacePackagesSync = (root, options) => {
|
|
|
404
423
|
const { fileSystem, path } = options;
|
|
405
424
|
const maxDepth = options.maxDepth ?? 32;
|
|
406
425
|
if (!isValidMaxDepth(maxDepth)) throw new RangeError(`getWorkspacePackagesSync: ${badMaxDepthMessage(maxDepth)}`);
|
|
407
|
-
const patterns = readPatternsSync(options, root);
|
|
408
|
-
const
|
|
409
|
-
if (Result.isFailure(
|
|
426
|
+
const { patterns, manifest } = readPatternsSync(options, root);
|
|
427
|
+
const read = membershipOf(patterns, rulesFor(manifest, (file) => fileSystem.exists(path.join(root, file))));
|
|
428
|
+
if (Result.isFailure(read)) throw new WorkspacePatternError({
|
|
410
429
|
root,
|
|
411
|
-
pattern:
|
|
430
|
+
pattern: read.failure.pattern,
|
|
412
431
|
kind: "uncompilable",
|
|
413
|
-
detail:
|
|
432
|
+
detail: read.failure.detail,
|
|
433
|
+
cause: read.failure.cause
|
|
414
434
|
});
|
|
415
|
-
const globs =
|
|
416
|
-
const
|
|
417
|
-
const isExcluded = excludes.length === 0 ? (_) => false : (relative) => excludes.some((exclude) => exclude.matches(relative));
|
|
435
|
+
const globs = read.success.candidates;
|
|
436
|
+
const isMember = read.success.matches;
|
|
418
437
|
const included = /* @__PURE__ */ new Map();
|
|
419
438
|
for (const literal of globs.literals) {
|
|
420
|
-
if (
|
|
439
|
+
if (!isMember(literal)) continue;
|
|
421
440
|
const absolute = path.join(root, literal);
|
|
422
441
|
if (isPackage(options, absolute)) included.set(literal, absolute);
|
|
423
442
|
}
|
|
@@ -440,7 +459,7 @@ const getWorkspacePackagesSync = (root, options) => {
|
|
|
440
459
|
stopped = true;
|
|
441
460
|
break;
|
|
442
461
|
}
|
|
443
|
-
if (wildcard.matches(relative) &&
|
|
462
|
+
if (wildcard.matches(relative) && isMember(relative) && isPackage(options, absolute)) included.set(relative, absolute);
|
|
444
463
|
if (!wildcard.crossesSegments) continue;
|
|
445
464
|
traversal.push(current, relative, absolute);
|
|
446
465
|
}
|
package/index.d.ts
CHANGED
|
@@ -581,6 +581,12 @@ declare const WorkspacePatternError_base: Schema.Class<WorkspacePatternError, Sc
|
|
|
581
581
|
readonly kind: Schema.Literals<readonly ["missingBaseDir", "uncompilable", "depthExceeded", "budgetExceeded", "unreadableDirectory"]>;
|
|
582
582
|
/** A short, structured detail — the missing directory, or the bound exceeded. */
|
|
583
583
|
readonly detail: Schema.String;
|
|
584
|
+
/**
|
|
585
|
+
* For `uncompilable`: the typed error that stopped the patterns being read —
|
|
586
|
+
* glob's `GlobPatternError`, or `@effected/npm`'s `NpmWorkspacePatternsError`
|
|
587
|
+
* when an npm root's `workspaces` field passes one of npm's pattern ceilings.
|
|
588
|
+
*/
|
|
589
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
584
590
|
}>, import("effect/Cause").YieldableError>;
|
|
585
591
|
/**
|
|
586
592
|
* Raised when a `packages:` pattern cannot be enumerated: its base directory is
|
|
@@ -5305,7 +5311,12 @@ interface GetWorkspacePackagesSyncOptions extends WorkspacesSyncOptions {
|
|
|
5305
5311
|
* drive the **same traversal state machine** (`internal/traverse.ts`), so the
|
|
5306
5312
|
* dequeue order, the depth rule, the visit budget and the prune list cannot
|
|
5307
5313
|
* drift apart. A `packages/**` finds exactly the same packages here as there,
|
|
5308
|
-
* including at the depth boundary.
|
|
5314
|
+
* including at the depth boundary. Which directories the patterns declare is
|
|
5315
|
+
* one decision too: on an npm root (as `detectPackageManagerSync` would
|
|
5316
|
+
* report it) `package.json#workspaces` is read the way npm reads it, through
|
|
5317
|
+
* `@effected/npm`'s `NpmWorkspacePatterns` — ordered negation, a trailing
|
|
5318
|
+
* `/`, an even `!` run, a backslash as a separator — and on a pnpm, yarn or
|
|
5319
|
+
* bun root as one `GlobSet`.
|
|
5309
5320
|
*
|
|
5310
5321
|
* The one deliberate difference is what happens at a bound: the Effect surface
|
|
5311
5322
|
* fails typed (`depthExceeded` / `budgetExceeded`), while this one truncates.
|
|
@@ -5316,8 +5327,9 @@ interface GetWorkspacePackagesSyncOptions extends WorkspacesSyncOptions {
|
|
|
5316
5327
|
*
|
|
5317
5328
|
* **A pattern set that does not compile throws.** The patterns compile as one
|
|
5318
5329
|
* `GlobSet`, and when that fails — one malformed member, or members that each
|
|
5319
|
-
* compile alone but together exhaust the set's shared compile budget
|
|
5320
|
-
*
|
|
5330
|
+
* compile alone but together exhaust the set's shared compile budget, or an
|
|
5331
|
+
* npm root's `workspaces` field past one of `NpmWorkspacePatterns`' ceilings —
|
|
5332
|
+
* there is no partial answer to degrade to: every pattern is lost at once. Returning
|
|
5321
5333
|
* the root alone would read as "no workspace packages", a decision taken on a
|
|
5322
5334
|
* corrupt config, so the facade throws the `WorkspacePatternError` (kind
|
|
5323
5335
|
* `"uncompilable"`, `pattern` the member the compile stopped at) that
|
|
@@ -5349,8 +5361,9 @@ interface GetWorkspacePackagesSyncOptions extends WorkspacesSyncOptions {
|
|
|
5349
5361
|
* `pnpm-workspace.yaml` exists but cannot be read or parsed, and (kind
|
|
5350
5362
|
* `"read"` or `"invalidJson"`) when the root `package.json` is the pattern
|
|
5351
5363
|
* source and exists but cannot be read or parsed;
|
|
5352
|
-
* `WorkspacePatternError` (kind `"uncompilable"`
|
|
5353
|
-
* `packages:` patterns do not compile as one `GlobSet
|
|
5364
|
+
* `WorkspacePatternError` (kind `"uncompilable"`, `cause` the typed error)
|
|
5365
|
+
* when the workspace's `packages:` patterns do not compile as one `GlobSet`
|
|
5366
|
+
* or, on an npm root, pass an `NpmWorkspacePatterns` ceiling; `RangeError` for a
|
|
5354
5367
|
* `maxDepth` that is not a positive integer.
|
|
5355
5368
|
*
|
|
5356
5369
|
* @example
|
package/internal/enumerate.js
CHANGED
|
@@ -5,21 +5,22 @@ import { Effect, FileSystem, Path } from "effect";
|
|
|
5
5
|
/** Strip a trailing slash from `GlobPattern.enumerationPrefix` to get a relative directory. */
|
|
6
6
|
const baseOf = (pattern) => pattern.enumerationPrefix.replace(/\/$/, "");
|
|
7
7
|
/**
|
|
8
|
-
* Enumerate the workspace directories a
|
|
8
|
+
* Enumerate the workspace directories a membership selects.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The walk is bounded by `membership.candidates` — its literals are looked up,
|
|
11
|
+
* its wildcards drive the descent — and every returned directory holds a
|
|
12
|
+
* `package.json`, is a candidate, and is a member by `membership.matches`.
|
|
13
|
+
* Results are sorted by relative path.
|
|
13
14
|
*/
|
|
14
|
-
const enumerate = (root,
|
|
15
|
+
const enumerate = (root, membership, options) => Effect.gen(function* () {
|
|
15
16
|
const fs = yield* FileSystem.FileSystem;
|
|
16
17
|
const path = yield* Path.Path;
|
|
17
18
|
const maxDepth = options?.maxDepth ?? 32;
|
|
18
19
|
if (!isValidMaxDepth(maxDepth)) return yield* Effect.die(/* @__PURE__ */ new Error(`enumerate: ${badMaxDepthMessage(maxDepth)}`));
|
|
19
20
|
const isPackage = (absolute) => fs.exists(path.join(absolute, "package.json")).pipe(Effect.orElseSucceed(() => false));
|
|
20
21
|
const isDirectory = (absolute) => fs.stat(absolute).pipe(Effect.map((info) => info.type === "Directory"), Effect.orElseSucceed(() => false));
|
|
21
|
-
const
|
|
22
|
-
const
|
|
22
|
+
const globs = membership.candidates;
|
|
23
|
+
const isMember = membership.matches;
|
|
23
24
|
const included = /* @__PURE__ */ new Map();
|
|
24
25
|
/** A shared-traversal stop, materialized as this module's failure record. */
|
|
25
26
|
const failureOf = (stop, pattern) => ({
|
|
@@ -28,7 +29,7 @@ const enumerate = (root, globs, options) => Effect.gen(function* () {
|
|
|
28
29
|
detail: stop.detail
|
|
29
30
|
});
|
|
30
31
|
const literalHits = yield* Effect.forEach(globs.literals, (literal) => Effect.gen(function* () {
|
|
31
|
-
if (
|
|
32
|
+
if (!isMember(literal)) return void 0;
|
|
32
33
|
const absolute = path.join(root, literal);
|
|
33
34
|
return (yield* isPackage(absolute)) ? [literal, absolute] : void 0;
|
|
34
35
|
}), { concurrency: 10 });
|
|
@@ -60,7 +61,7 @@ const enumerate = (root, globs, options) => Effect.gen(function* () {
|
|
|
60
61
|
const absolute = path.join(frame.absolute, entry);
|
|
61
62
|
if (!(yield* isDirectory(absolute))) continue;
|
|
62
63
|
if (wildcard.crossesSegments && !traversal.admits(frame)) return yield* Effect.fail(failureOf(traversal.depthStop(), wildcard.source));
|
|
63
|
-
if (wildcard.matches(relative) &&
|
|
64
|
+
if (wildcard.matches(relative) && isMember(relative) && (yield* isPackage(absolute))) included.set(relative, absolute);
|
|
64
65
|
if (!wildcard.crossesSegments) continue;
|
|
65
66
|
traversal.push(frame, relative, absolute);
|
|
66
67
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { decidePackageManager } from "./packageManagerDecision.js";
|
|
2
|
+
import { Option, Result } from "effect";
|
|
3
|
+
import { NpmWorkspacePatterns } from "@effected/npm";
|
|
4
|
+
import { GlobSet } from "@effected/glob";
|
|
5
|
+
|
|
6
|
+
// src/internal/membership.ts
|
|
7
|
+
/** The rules for a root that is not npm's. */
|
|
8
|
+
const GLOB_RULES = { _tag: "glob" };
|
|
9
|
+
/**
|
|
10
|
+
* The rules a root's patterns are read under.
|
|
11
|
+
*
|
|
12
|
+
* `manifest` is the root `package.json` when it is the pattern source — none
|
|
13
|
+
* when `pnpm-workspace.yaml` supplied the patterns. The manager is decided the
|
|
14
|
+
* way `PackageManagerDetector` decides it, over the same `has` the caller
|
|
15
|
+
* answers with its own IO, so "npm root" here and there are one answer.
|
|
16
|
+
*/
|
|
17
|
+
const rulesFor = (manifest, has) => {
|
|
18
|
+
if (Option.isNone(manifest)) return GLOB_RULES;
|
|
19
|
+
return decidePackageManager(manifest, has)?.name === "npm" ? {
|
|
20
|
+
_tag: "npm",
|
|
21
|
+
field: manifest.value.workspaces
|
|
22
|
+
} : GLOB_RULES;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A positive npm pattern as npm reads it, as a `GlobSet` include, or
|
|
26
|
+
* `undefined` for a negation or an empty pattern: an even `!` run dropped, one
|
|
27
|
+
* leading `./` or `/` run stripped, backslashes turned to `/`, and a trailing
|
|
28
|
+
* `/.` run and `/` dropped (npm matches directories, so `packages/*\/` is
|
|
29
|
+
* `packages/*`).
|
|
30
|
+
*/
|
|
31
|
+
const npmCandidateOf = (entry) => {
|
|
32
|
+
const bangs = /^!+/.exec(entry)?.[0].length ?? 0;
|
|
33
|
+
if (bangs % 2 === 1) return void 0;
|
|
34
|
+
let pattern = entry.slice(bangs).replace(/^\.?\/+/, "").replace(/\\/g, "/");
|
|
35
|
+
let end = pattern.length;
|
|
36
|
+
for (;;) if (end >= 1 && pattern.charCodeAt(end - 1) === 47) end -= 1;
|
|
37
|
+
else if (end >= 2 && pattern.charCodeAt(end - 1) === 46 && pattern.charCodeAt(end - 2) === 47) end -= 2;
|
|
38
|
+
else break;
|
|
39
|
+
pattern = pattern.slice(0, end);
|
|
40
|
+
return pattern === "" ? void 0 : pattern;
|
|
41
|
+
};
|
|
42
|
+
/** The `GlobSet` compile failure, materialized. */
|
|
43
|
+
const globFailure = (error) => ({
|
|
44
|
+
pattern: error.pattern,
|
|
45
|
+
detail: error.message,
|
|
46
|
+
cause: error
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* The membership `patterns` declare under `rules`, or the failure that stops
|
|
50
|
+
* them being read. There is no fallback reading: an npm field past one of
|
|
51
|
+
* `NpmWorkspacePatterns`' ceilings fails rather than being read as a `GlobSet`,
|
|
52
|
+
* which would silently decide members by other rules.
|
|
53
|
+
*/
|
|
54
|
+
const membershipOf = (patterns, rules) => {
|
|
55
|
+
if (rules._tag === "glob") {
|
|
56
|
+
const compiled = GlobSet.compileResult(patterns);
|
|
57
|
+
if (Result.isFailure(compiled)) return Result.fail(globFailure(compiled.failure));
|
|
58
|
+
const globs = compiled.success;
|
|
59
|
+
return Result.succeed({
|
|
60
|
+
candidates: globs,
|
|
61
|
+
matches: (relative) => globs.matches(relative)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const matcher = NpmWorkspacePatterns.matcherResult(rules.field);
|
|
65
|
+
if (Result.isFailure(matcher)) {
|
|
66
|
+
const error = matcher.failure;
|
|
67
|
+
const at = error.index === void 0 ? void 0 : declaredAt(rules.field, error.index);
|
|
68
|
+
return Result.fail({
|
|
69
|
+
pattern: at ?? "package.json#workspaces",
|
|
70
|
+
detail: error.message,
|
|
71
|
+
cause: error
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const candidates = [];
|
|
75
|
+
for (const entry of patterns) {
|
|
76
|
+
const candidate = npmCandidateOf(entry);
|
|
77
|
+
if (candidate !== void 0) candidates.push(candidate);
|
|
78
|
+
}
|
|
79
|
+
const compiled = GlobSet.compileResult(candidates);
|
|
80
|
+
if (Result.isFailure(compiled)) return Result.fail(globFailure(compiled.failure));
|
|
81
|
+
return Result.succeed({
|
|
82
|
+
candidates: compiled.success,
|
|
83
|
+
matches: matcher.success
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/** The string entry at `index` of a `workspaces` field, in either shape. */
|
|
87
|
+
const declaredAt = (field, index) => {
|
|
88
|
+
const packages = typeof field === "object" && field !== null && !Array.isArray(field) && Object.hasOwn(field, "packages") ? field.packages : void 0;
|
|
89
|
+
const declared = Array.isArray(packages) ? packages : field;
|
|
90
|
+
if (!Array.isArray(declared)) return void 0;
|
|
91
|
+
const entry = declared[index];
|
|
92
|
+
return typeof entry === "string" ? entry : void 0;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { GLOB_RULES, membershipOf, rulesFor };
|
package/internal/patterns.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, FileSystem, Path, Result } from "effect";
|
|
1
|
+
import { Effect, FileSystem, Option, Path, Result } from "effect";
|
|
2
2
|
import { PackageJsonFormat } from "@effected/package-json";
|
|
3
3
|
import { Yaml } from "@effected/yaml";
|
|
4
4
|
|
|
@@ -19,12 +19,8 @@ const manifestPatternsOf = (manifest) => {
|
|
|
19
19
|
if (workspaces !== null && typeof workspaces === "object" && "packages" in workspaces) return stringsOf(workspaces.packages) ?? [];
|
|
20
20
|
return [];
|
|
21
21
|
};
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
* then the root package.json `workspaces` field. An absent config is a
|
|
25
|
-
* standalone package, not an error — it yields an empty list.
|
|
26
|
-
*/
|
|
27
|
-
const readPatterns = (root) => Effect.gen(function* () {
|
|
22
|
+
/** {@link readPatterns}, with the root manifest when it is the pattern source. */
|
|
23
|
+
const readPatternSource = (root) => Effect.gen(function* () {
|
|
28
24
|
const fs = yield* FileSystem.FileSystem;
|
|
29
25
|
const path = yield* Path.Path;
|
|
30
26
|
const pnpmWorkspacePath = path.join(root, "pnpm-workspace.yaml");
|
|
@@ -40,18 +36,30 @@ const readPatterns = (root) => Effect.gen(function* () {
|
|
|
40
36
|
cause
|
|
41
37
|
})));
|
|
42
38
|
const patterns = pnpmPatternsOf(document);
|
|
43
|
-
if (patterns.length > 0) return
|
|
39
|
+
if (patterns.length > 0) return {
|
|
40
|
+
patterns,
|
|
41
|
+
manifest: Option.none()
|
|
42
|
+
};
|
|
44
43
|
}
|
|
45
44
|
const manifestPath = path.join(root, "package.json");
|
|
46
|
-
if (!(yield* fs.exists(manifestPath).pipe(Effect.orElseSucceed(() => false)))) return
|
|
45
|
+
if (!(yield* fs.exists(manifestPath).pipe(Effect.orElseSucceed(() => false)))) return {
|
|
46
|
+
patterns: [],
|
|
47
|
+
manifest: Option.none()
|
|
48
|
+
};
|
|
47
49
|
const content = yield* fs.readFileString(manifestPath).pipe(Effect.mapError((cause) => ({
|
|
48
50
|
path: manifestPath,
|
|
49
51
|
kind: "read",
|
|
50
52
|
cause
|
|
51
53
|
})));
|
|
52
54
|
const manifest = PackageJsonFormat.parseObjectResult(content);
|
|
53
|
-
if (Result.isSuccess(manifest)) return
|
|
54
|
-
|
|
55
|
+
if (Result.isSuccess(manifest)) return {
|
|
56
|
+
patterns: manifestPatternsOf(manifest.success),
|
|
57
|
+
manifest: Option.some(manifest.success)
|
|
58
|
+
};
|
|
59
|
+
if (manifest.failure.reason === "not-an-object") return {
|
|
60
|
+
patterns: [],
|
|
61
|
+
manifest: Option.none()
|
|
62
|
+
};
|
|
55
63
|
return yield* Effect.fail({
|
|
56
64
|
path: manifestPath,
|
|
57
65
|
kind: "invalidJson",
|
|
@@ -59,4 +67,4 @@ const readPatterns = (root) => Effect.gen(function* () {
|
|
|
59
67
|
});
|
|
60
68
|
});
|
|
61
69
|
|
|
62
|
-
export { manifestPatternsOf, pnpmPatternsOf,
|
|
70
|
+
export { manifestPatternsOf, pnpmPatternsOf, readPatternSource, stringsOf };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/workspaces",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Monorepo workspace tooling as Effect services — root discovery, package enumeration, the dependency graph, package-manager detection, pnpm catalog resolution, lockfile IO and git-based change detection.",
|
|
6
6
|
"keywords": [
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@effected/commands": "^0.21.0",
|
|
55
55
|
"@effected/git": "^0.32.0",
|
|
56
|
-
"@effected/glob": "^0.
|
|
56
|
+
"@effected/glob": "^0.22.0",
|
|
57
57
|
"@effected/jsonc": "^0.25.0",
|
|
58
|
-
"@effected/lockfiles": "^0.
|
|
59
|
-
"@effected/npm": "^0.34.
|
|
58
|
+
"@effected/lockfiles": "^0.25.0",
|
|
59
|
+
"@effected/npm": "^0.34.1",
|
|
60
60
|
"@effected/package-json": "^0.32.1",
|
|
61
61
|
"@effected/semver": "^0.24.0",
|
|
62
|
-
"@effected/walker": "^0.
|
|
62
|
+
"@effected/walker": "^0.29.0",
|
|
63
63
|
"@effected/yaml": "^0.30.0",
|
|
64
64
|
"@pnpm/catalogs.config": "^1100.0.5",
|
|
65
65
|
"@pnpm/catalogs.protocol-parser": "^1100.0.0",
|
package/testing.d.ts
CHANGED
|
@@ -561,6 +561,12 @@ declare const WorkspacePatternError_base: Schema.Class<WorkspacePatternError, Sc
|
|
|
561
561
|
readonly kind: Schema.Literals<readonly ["missingBaseDir", "uncompilable", "depthExceeded", "budgetExceeded", "unreadableDirectory"]>;
|
|
562
562
|
/** A short, structured detail — the missing directory, or the bound exceeded. */
|
|
563
563
|
readonly detail: Schema.String;
|
|
564
|
+
/**
|
|
565
|
+
* For `uncompilable`: the typed error that stopped the patterns being read —
|
|
566
|
+
* glob's `GlobPatternError`, or `@effected/npm`'s `NpmWorkspacePatternsError`
|
|
567
|
+
* when an npm root's `workspaces` field passes one of npm's pattern ceilings.
|
|
568
|
+
*/
|
|
569
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
564
570
|
}>, import("effect/Cause").YieldableError>;
|
|
565
571
|
/**
|
|
566
572
|
* Raised when a `packages:` pattern cannot be enumerated: its base directory is
|