@effected/changesets 0.5.0 → 0.6.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/Ledger.js +200 -0
- package/PendingChangesets.js +68 -0
- package/RegistryVersions.js +50 -0
- package/ReleaseCause.js +30 -0
- package/ReleaseEdits.js +3 -0
- package/ReleaseManager.js +49 -0
- package/ReleasePlan.js +257 -20
- package/VersioningCheck.js +102 -0
- package/errors.js +188 -2
- package/index.d.ts +678 -10
- package/index.js +7 -2
- package/internal/pnpmPlan.js +610 -0
- package/internal/twins.js +21 -0
- package/package.json +5 -3
package/ReleasePlan.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { computeBreakingFloors } from "./BreakingFloors.js";
|
|
2
2
|
import { ChangesetConfig } from "./ChangesetConfig.js";
|
|
3
3
|
import { ChangesetConfigError, SnapshotPreModeError, SnapshotTemplateError, UnknownPackageError } from "./errors.js";
|
|
4
|
+
import { planPnpm, projectDir } from "./internal/pnpmPlan.js";
|
|
5
|
+
import { twinReleases } from "./internal/twins.js";
|
|
4
6
|
import { DEPENDENCY_KINDS, WORKSPACE, cleanVersion, increment, matchNames, parseRange, satisfies } from "./internal/versions.js";
|
|
7
|
+
import { Ledger } from "./Ledger.js";
|
|
5
8
|
import { PendingChangeset, PendingChangesets } from "./PendingChangesets.js";
|
|
6
9
|
import { PreState } from "./PreState.js";
|
|
10
|
+
import { RegistryVersions } from "./RegistryVersions.js";
|
|
11
|
+
import { ReleaseCause, sortCauses } from "./ReleaseCause.js";
|
|
7
12
|
import { computeEdits } from "./ReleaseEdits.js";
|
|
13
|
+
import { ReleaseManager } from "./ReleaseManager.js";
|
|
8
14
|
import { InvalidVersionError, Range, SemVer } from "@effected/semver";
|
|
9
15
|
import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
|
|
10
16
|
import { posix } from "node:path";
|
|
17
|
+
import { PnpmSettings } from "@effected/pnpm";
|
|
11
18
|
import { WorkspaceDiscovery, WorkspaceDiscoveryError, WorkspacePackage } from "@effected/workspaces";
|
|
12
19
|
|
|
13
20
|
// src/ReleasePlan.ts
|
|
@@ -190,6 +197,14 @@ const readLonePackage = Effect.fnUntraced(function* (directory, notFound) {
|
|
|
190
197
|
var PlannedRelease = class extends Schema.Class("PlannedRelease")({
|
|
191
198
|
/** The package name. */
|
|
192
199
|
name: Schema.String,
|
|
200
|
+
/**
|
|
201
|
+
* The project's workspace-relative directory as pnpm spells it (no
|
|
202
|
+
* leading `./`, no trailing `/`, `""` for the workspace root). Present
|
|
203
|
+
* only in a `manager: "pnpm"` plan, which is keyed by directory, so two
|
|
204
|
+
* same-named projects can each have a release; a Changesets plan is keyed
|
|
205
|
+
* by name and leaves it out.
|
|
206
|
+
*/
|
|
207
|
+
dir: Schema.optionalKey(Schema.String),
|
|
193
208
|
/** The bump, or `none` for a listed package whose version does not move. */
|
|
194
209
|
type: Schema.Literals([
|
|
195
210
|
"patch",
|
|
@@ -202,7 +217,11 @@ var PlannedRelease = class extends Schema.Class("PlannedRelease")({
|
|
|
202
217
|
* member of a fixed or linked group, the group's highest.
|
|
203
218
|
*/
|
|
204
219
|
oldVersion: Schema.String,
|
|
205
|
-
/**
|
|
220
|
+
/**
|
|
221
|
+
* The version after the release; equal to `oldVersion` when `type` is
|
|
222
|
+
* `none`, and in a pnpm plan for a first release, which publishes its
|
|
223
|
+
* manifest version as it is.
|
|
224
|
+
*/
|
|
206
225
|
newVersion: Schema.String,
|
|
207
226
|
/**
|
|
208
227
|
* The ids of the changesets in the plan that name the package, as the
|
|
@@ -239,12 +258,30 @@ var PlannedRelease = class extends Schema.Class("PlannedRelease")({
|
|
|
239
258
|
* ripple brings back, has an empty list.
|
|
240
259
|
* - A snapshot plan builds its releases exactly as a plain one does.
|
|
241
260
|
*
|
|
261
|
+
* In a pnpm plan the list is the intents the release consumes, the ids pnpm
|
|
262
|
+
* records in its ledger: those still pending, and, when it graduates off a
|
|
263
|
+
* lane, those its prereleases consumed.
|
|
264
|
+
*
|
|
242
265
|
* To tell a group or exit bump from a ripple, read `fixed` and `linked`
|
|
243
266
|
* and the plan's `preState`. To tell whether the package's own changeset
|
|
244
267
|
* set its type, compare `type` with the highest bump its listed changesets
|
|
245
268
|
* give it.
|
|
246
269
|
*/
|
|
247
|
-
changesets: Schema.Array(Schema.String)
|
|
270
|
+
changesets: Schema.Array(Schema.String),
|
|
271
|
+
/**
|
|
272
|
+
* Why the package is in the plan, each cause once, in pnpm's order
|
|
273
|
+
* (`dependencies`, `epic`, `fixed`, `intent`).
|
|
274
|
+
*
|
|
275
|
+
* @remarks
|
|
276
|
+
* A pnpm plan reports the causes pnpm reports. A Changesets plan fills
|
|
277
|
+
* them from the paths its oracle has: `intent` for a release a changeset
|
|
278
|
+
* made (and for a prerelease completed on `exit`), `dependencies` for one
|
|
279
|
+
* a ripple made, which replaces the entry and its causes as the ripple
|
|
280
|
+
* replaces the release, and `fixed` for a member a fixed group added or
|
|
281
|
+
* moved. A `linked` group adds no cause. Decoding a value without the
|
|
282
|
+
* field gives `[]`.
|
|
283
|
+
*/
|
|
284
|
+
causes: Schema.Array(ReleaseCause).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])), Schema.withConstructorDefault(Effect.succeed([])))
|
|
248
285
|
}) {};
|
|
249
286
|
/**
|
|
250
287
|
* What a set of pending changesets releases: the packages they name and the
|
|
@@ -427,18 +464,66 @@ var ReleasePlan = class extends Schema.Class("ReleasePlan")({
|
|
|
427
464
|
* suffix is never empty, so the oracle's quiet fallback to plain versions
|
|
428
465
|
* on an empty suffix cannot happen here.
|
|
429
466
|
*
|
|
467
|
+
* With `manager: "pnpm"` the plan is pnpm's own, `assemble_release_plan`
|
|
468
|
+
* from pnpm 12.20.0's `crates/versioning`, held to pnpm's recorded answers
|
|
469
|
+
* (`__test__/fixtures/pnpm-native/`). `config` and `pre` are not read, since
|
|
470
|
+
* pnpm reads neither file, and a changeset under `.changeset/pre/` is not an
|
|
471
|
+
* intent. What it reads instead:
|
|
472
|
+
*
|
|
473
|
+
* - `versioning`: `pnpm-workspace.yaml`'s block. Lanes build `X.Y.Z-<lane>.N`,
|
|
474
|
+
* the counter continuing while the stable target holds and resetting when
|
|
475
|
+
* a bigger bump moves it (`2.1.0-alpha.1` plus a major is `3.0.0-alpha.0`);
|
|
476
|
+
* a package off its lane graduates to the stable version its lane built,
|
|
477
|
+
* but only when the intents that built it are still pending files the
|
|
478
|
+
* ledger records under prerelease versions alone. `fixed` groups share
|
|
479
|
+
* their highest version, bumped. Epic members keep their majors in the
|
|
480
|
+
* lead's band, `M*100` to `M*100+99`, and re-base to the next band's floor
|
|
481
|
+
* when the lead releases a new stable major. `ignore` takes a project out
|
|
482
|
+
* of planning. `maxBump` caps the final plan's real version distance.
|
|
483
|
+
* - `ledger`: which intents each project already consumed, matched by `dir`,
|
|
484
|
+
* or by name for a bare-list entry.
|
|
485
|
+
* - `published`: the registry seam, the project directories whose MANIFEST
|
|
486
|
+
* version the registry already has (pnpm probes exactly that version, so
|
|
487
|
+
* a newer published `latest` does not count). Absent, the first-release
|
|
488
|
+
* rule is off and nothing debuts. Given, a public release whose directory
|
|
489
|
+
* the set lacks is a first release: it keeps its manifest version (on a
|
|
490
|
+
* lane, `<stable>-<lane>.0`) while still reporting its intent's bump and
|
|
491
|
+
* consuming its intents, and the plan is made again, as `pnpm version -r`
|
|
492
|
+
* makes it. A private project is never probed, so never debuts.
|
|
493
|
+
* - `enforceWorkspaceProtocol`: refuse an internal production dependency
|
|
494
|
+
* that is not a `workspace:` range, as `pnpm version -r` does. Off is
|
|
495
|
+
* `pnpm change status`'s reading.
|
|
496
|
+
*
|
|
497
|
+
* The plan is keyed by project directory: each release has its `dir`, so two
|
|
498
|
+
* same-named projects each release. A changeset may name a project by its
|
|
499
|
+
* `./`-prefixed workspace-relative directory (`"./packages/b": patch`),
|
|
500
|
+
* normalised as pnpm normalises one (backslashes to `/`, every leading `./`
|
|
501
|
+
* and the trailing `/` removed, `./` alone being the root). A key that names
|
|
502
|
+
* nothing fails {@link UnknownPackageError}, and a bare name that more than
|
|
503
|
+
* one project publishes {@link AmbiguousPackageError}, both even for an
|
|
504
|
+
* intent already consumed. A dependent ripples `patch` only through a
|
|
505
|
+
* `workspace:` range the dependency's new version leaves, so a 1.x minor
|
|
506
|
+
* stays inside `workspace:^` and a plain range never ripples;
|
|
507
|
+
* devDependencies never do. Every other refusal is {@link VersioningError},
|
|
508
|
+
* whose `code` is pnpm's.
|
|
509
|
+
*
|
|
510
|
+
* The default, `"changesets"`, is the Changesets CLI's reading: a `./` key is
|
|
511
|
+
* an unknown package, as it is there.
|
|
512
|
+
*
|
|
513
|
+
* A snapshot under `manager: "pnpm"` is the engine's: every release becomes
|
|
514
|
+
* `0.0.0-<suffix>`, with the suffix built from the snapshot alone as above
|
|
515
|
+
* (`useCalculatedVersion` is not read), and bands and `maxBump` go
|
|
516
|
+
* unchecked.
|
|
517
|
+
*
|
|
430
518
|
* @param input - The packages to plan, the pending changesets, the config
|
|
431
519
|
* and, in pre-release mode, the {@link PreState}, and for a snapshot
|
|
432
|
-
* release the {@link ReleaseSnapshot}
|
|
433
|
-
*
|
|
520
|
+
* release the {@link ReleaseSnapshot}; for a pnpm plan, its `versioning`,
|
|
521
|
+
* `ledger`, `published` and `enforceWorkspaceProtocol`.
|
|
522
|
+
* {@link ReleasePlan.read} decides whether the workspace root is one of the
|
|
523
|
+
* packages.
|
|
434
524
|
*/
|
|
435
525
|
static assemble(input) {
|
|
436
|
-
|
|
437
|
-
return Result.succeed(assembleOrHalt(input));
|
|
438
|
-
} catch (error) {
|
|
439
|
-
if (error instanceof Halt) return Result.fail(error.failure);
|
|
440
|
-
throw error;
|
|
441
|
-
}
|
|
526
|
+
return assembleResult(input);
|
|
442
527
|
}
|
|
443
528
|
/**
|
|
444
529
|
* What `changeset version` writes for `plan`, as data: each manifest's new
|
|
@@ -509,6 +594,14 @@ var ReleasePlan = class extends Schema.Class("ReleasePlan")({
|
|
|
509
594
|
* writing caret ranges. A plan without a snapshot deletes that
|
|
510
595
|
* `pre.json`; a caller reproducing the CLI keeps it.
|
|
511
596
|
*
|
|
597
|
+
* These are Changesets semantics, keyed by package name. pnpm applies its own
|
|
598
|
+
* plans, writing `workspace:` ranges it never rewrites and the dependency
|
|
599
|
+
* updates its plan carries, which a {@link PlannedRelease} does not; so a
|
|
600
|
+
* `manager: "pnpm"` plan is read here as Changesets would apply it. A pnpm
|
|
601
|
+
* plan holding two releases with one name (same-named projects) fails
|
|
602
|
+
* {@link AmbiguousPackageError} listing their directories, since an edit
|
|
603
|
+
* keyed by name would land both on one manifest.
|
|
604
|
+
*
|
|
512
605
|
* Fails with {@link MissingPackageError} when the plan releases a package
|
|
513
606
|
* `packages` lacks, and with `InvalidVersionError` when a bounded range
|
|
514
607
|
* must be bumped past a new version that is not a version, which a plan
|
|
@@ -563,6 +656,9 @@ var ReleasePlan = class extends Schema.Class("ReleasePlan")({
|
|
|
563
656
|
* dependent `patch` however far the dependency moves, so a dependency's
|
|
564
657
|
* breaking release ripples as a patch of everything that peers on it.
|
|
565
658
|
*
|
|
659
|
+
* Keyed by package name, as {@link ReleasePlan.edits} is: a pnpm plan
|
|
660
|
+
* holding two releases with one name fails {@link AmbiguousPackageError}.
|
|
661
|
+
*
|
|
566
662
|
* Fails as {@link ReleasePlan.edits} fails, which a plan
|
|
567
663
|
* {@link ReleasePlan.assemble} made from the same packages never does.
|
|
568
664
|
*
|
|
@@ -576,6 +672,20 @@ var ReleasePlan = class extends Schema.Class("ReleasePlan")({
|
|
|
576
672
|
return computeBreakingFloors(plan, input.packages, input.config);
|
|
577
673
|
}
|
|
578
674
|
/**
|
|
675
|
+
* The plan's releases keyed by package name, for a consumer that reads a
|
|
676
|
+
* plan by name. A Changesets plan always has one release per name. A
|
|
677
|
+
* `manager: "pnpm"` plan is keyed by directory and may release two
|
|
678
|
+
* same-named projects; then this fails {@link AmbiguousPackageError} naming
|
|
679
|
+
* the first such name and every directory releasing it, rather than letting
|
|
680
|
+
* one release silently stand for both.
|
|
681
|
+
*
|
|
682
|
+
* @param plan - The plan to key.
|
|
683
|
+
*/
|
|
684
|
+
static releasesByName(plan) {
|
|
685
|
+
const twins = twinReleases(plan.releases);
|
|
686
|
+
return twins === void 0 ? Result.succeed(new Map(plan.releases.map((release) => [release.name, release]))) : Result.fail(twins);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
579
689
|
* Discover the workspace's packages, read its config, pending changesets and
|
|
580
690
|
* `.changeset/pre.json`, and {@link ReleasePlan.assemble | assemble} the
|
|
581
691
|
* plan. {@link ReleasePlan.readWithContext} reads the same plan and also
|
|
@@ -600,6 +710,30 @@ var ReleasePlan = class extends Schema.Class("ReleasePlan")({
|
|
|
600
710
|
* calls `WorkspaceDiscovery`'s `refreshIn(root)` first, or the new plan
|
|
601
711
|
* reads the versions the release replaced.
|
|
602
712
|
*
|
|
713
|
+
* In a repository `ReleaseManager.detect` calls pnpm's, the plan is pnpm's
|
|
714
|
+
* (see {@link ReleasePlan.assemble}): every discovered project is planned,
|
|
715
|
+
* the root included; the `versioning` block is read through `PnpmSettings`
|
|
716
|
+
* and the ledger through {@link Ledger.read}; a `config.json` that is missing,
|
|
717
|
+
* is not JSON or has a malformed value is the defaults, because pnpm plans
|
|
718
|
+
* without the file (it feeds only {@link ReleasePlan.edits} and the
|
|
719
|
+
* changelog); `pre.json` is not read. With a {@link RegistryVersions} provided,
|
|
720
|
+
* the registry is asked whether each public release's manifest version is
|
|
721
|
+
* published, and the ones it lacks are planned as first releases
|
|
722
|
+
* ({@link ReleasePlan.assemble}'s `published`); a registry failure is
|
|
723
|
+
* `RegistryReadError`, never read as unpublished. A snapshot never asks. It
|
|
724
|
+
* also fails with `PnpmSettingsError` and {@link LedgerError}.
|
|
725
|
+
*
|
|
726
|
+
* The registry service is read with `Effect.serviceOption`, so it never
|
|
727
|
+
* appears in `R` and nothing fails to compile when it is missing. Never
|
|
728
|
+
* provide only the `WorkspaceDiscovery` and platform layers to a pnpm-native
|
|
729
|
+
* repository and expect first releases: without
|
|
730
|
+
* `RegistryVersions.layerFrom(config)` nothing is asked, no release debuts,
|
|
731
|
+
* and a project that was never published plans a bump from its manifest
|
|
732
|
+
* version (`1.0.0` to `1.1.0`) where `pnpm version -r` would publish
|
|
733
|
+
* `1.0.0` itself; the plan reports success either way. Provide
|
|
734
|
+
* `RegistryVersions.layerFrom(config)` (it requires `NpmRegistry`) whenever
|
|
735
|
+
* the plan feeds a publish.
|
|
736
|
+
*
|
|
603
737
|
* @param directory - The workspace root, or a directory inside it.
|
|
604
738
|
* @param options - `snapshot` plans a snapshot release, as
|
|
605
739
|
* {@link ReleasePlan.assemble} describes.
|
|
@@ -656,14 +790,55 @@ var ReleaseContext = class extends Schema.Class("ReleaseContext")({
|
|
|
656
790
|
const readContext = Effect.fnUntraced(function* (directory, options) {
|
|
657
791
|
const discovered = yield* (yield* WorkspaceDiscovery).listPackagesIn(directory).pipe(Effect.catchTag("WorkspaceRootNotFoundError", (error) => readLonePackage(directory, error)));
|
|
658
792
|
const root = discovered[0]?.workspaceRoot ?? directory;
|
|
659
|
-
const
|
|
793
|
+
const manager = yield* ReleaseManager.detect(root);
|
|
660
794
|
const changesets = yield* PendingChangesets.read(root);
|
|
795
|
+
if (manager === "pnpm") {
|
|
796
|
+
const config = yield* ChangesetConfig.read(root).pipe(Effect.catchTag("ChangesetConfigError", () => Effect.succeed(DEFAULT_CONFIG)));
|
|
797
|
+
const settings = yield* PnpmSettings.load({
|
|
798
|
+
cwd: root,
|
|
799
|
+
env: {},
|
|
800
|
+
platform: "linux"
|
|
801
|
+
});
|
|
802
|
+
const versioning = yield* Effect.fromResult(settings.versioning());
|
|
803
|
+
const ledger = yield* Ledger.read(root);
|
|
804
|
+
const input = {
|
|
805
|
+
packages: discovered,
|
|
806
|
+
changesets,
|
|
807
|
+
config,
|
|
808
|
+
manager,
|
|
809
|
+
...Option.isSome(versioning) ? { versioning: versioning.value } : {},
|
|
810
|
+
...Option.isSome(ledger) ? { ledger: ledger.value } : {},
|
|
811
|
+
...options?.snapshot === void 0 ? {} : { snapshot: options.snapshot }
|
|
812
|
+
};
|
|
813
|
+
let plan = yield* Effect.fromResult(ReleasePlan.assemble(input));
|
|
814
|
+
const registry = yield* Effect.serviceOption(RegistryVersions);
|
|
815
|
+
if (Option.isSome(registry) && options?.snapshot === void 0) {
|
|
816
|
+
const byDir = new Map(discovered.map((pkg) => [projectDir(pkg.relativePath), pkg]));
|
|
817
|
+
const probed = yield* Effect.forEach(plan.releases.filter((release) => byDir.get(pnpmDir(release))?.private !== true), (release) => {
|
|
818
|
+
const publishedName = byDir.get(pnpmDir(release))?.publishConfig?.name;
|
|
819
|
+
return registry.value.published(publishedName === void 0 || publishedName === "" ? release.name : publishedName, release.oldVersion).pipe(Effect.map((found) => [pnpmDir(release), found]));
|
|
820
|
+
}, { concurrency: 8 });
|
|
821
|
+
const unpublished = new Set(probed.filter(([, found]) => !found).map(([dir]) => dir));
|
|
822
|
+
if (unpublished.size > 0) plan = yield* Effect.fromResult(assembleResult({
|
|
823
|
+
...input,
|
|
824
|
+
unpublished
|
|
825
|
+
}));
|
|
826
|
+
}
|
|
827
|
+
return ReleaseContext.make({
|
|
828
|
+
root,
|
|
829
|
+
plan,
|
|
830
|
+
packages: discovered,
|
|
831
|
+
config
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
const config = yield* ChangesetConfig.read(root);
|
|
661
835
|
const pre = yield* PreState.read(root);
|
|
662
836
|
const members = discovered.filter((pkg) => !pkg.isRootWorkspace);
|
|
663
837
|
const plan = yield* Effect.fromResult(ReleasePlan.assemble({
|
|
664
838
|
packages: members.length > 0 ? members : discovered,
|
|
665
839
|
changesets,
|
|
666
840
|
config,
|
|
841
|
+
manager,
|
|
667
842
|
...Option.isSome(pre) ? { pre: pre.value } : {},
|
|
668
843
|
...options?.snapshot === void 0 ? {} : { snapshot: options.snapshot }
|
|
669
844
|
}));
|
|
@@ -674,6 +849,56 @@ const readContext = Effect.fnUntraced(function* (directory, options) {
|
|
|
674
849
|
config
|
|
675
850
|
});
|
|
676
851
|
});
|
|
852
|
+
/** A pnpm-mode release's directory: `PlannedRelease.dir` is always set there, so its absence is a planner defect. */
|
|
853
|
+
const pnpmDir = (release) => {
|
|
854
|
+
if (release.dir === void 0) throw new Error(`pnpm plan: release ${release.name} has no dir`);
|
|
855
|
+
return release.dir;
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* {@link ReleasePlan.assemble}'s body, with the one input it does not publish:
|
|
859
|
+
* `unpublished`, the directories to plan as first releases outright, for
|
|
860
|
+
* `read`, which has already asked the registry. `published` stays the only
|
|
861
|
+
* public way to say which directories debut.
|
|
862
|
+
*/
|
|
863
|
+
const assembleResult = (input) => {
|
|
864
|
+
try {
|
|
865
|
+
return Result.succeed(assembleOrHalt(input));
|
|
866
|
+
} catch (error) {
|
|
867
|
+
if (error instanceof Halt) return Result.fail(error.failure);
|
|
868
|
+
throw error;
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
/** The config a pnpm repository without `.changeset/config.json` is read with: every default. */
|
|
872
|
+
const DEFAULT_CONFIG = Schema.decodeUnknownSync(ChangesetConfig)({});
|
|
873
|
+
/**
|
|
874
|
+
* pnpm-native planning: {@link planPnpm} over the packages, intents, the
|
|
875
|
+
* `versioning` block and the ledger, its releases made {@link PlannedRelease}s.
|
|
876
|
+
* `config` and `pre` are not read, as pnpm reads neither file.
|
|
877
|
+
*/
|
|
878
|
+
const assemblePnpm = (input) => {
|
|
879
|
+
const { snapshot } = input;
|
|
880
|
+
const suffix = snapshot === void 0 ? void 0 : snapshotSuffix(snapshot.prereleaseTemplate, snapshot.tag === "" ? void 0 : snapshot.tag, snapshot.commit === "" ? void 0 : snapshot.commit, snapshot.timestamp);
|
|
881
|
+
const planned = planPnpm({
|
|
882
|
+
packages: input.packages,
|
|
883
|
+
changesets: input.changesets,
|
|
884
|
+
versioning: input.versioning,
|
|
885
|
+
ledger: input.ledger,
|
|
886
|
+
published: input.published,
|
|
887
|
+
unpublished: input.unpublished,
|
|
888
|
+
enforceWorkspaceProtocol: input.enforceWorkspaceProtocol,
|
|
889
|
+
snapshotSuffix: suffix
|
|
890
|
+
});
|
|
891
|
+
if (Result.isFailure(planned)) throw new Halt(planned.failure);
|
|
892
|
+
return ReleasePlan.make({
|
|
893
|
+
releases: planned.success.releases.map((release) => PlannedRelease.make({
|
|
894
|
+
...release,
|
|
895
|
+
changesets: [...release.changesets],
|
|
896
|
+
causes: [...release.causes]
|
|
897
|
+
})),
|
|
898
|
+
changesets: [...planned.success.consumed],
|
|
899
|
+
snapshot: snapshot !== void 0
|
|
900
|
+
});
|
|
901
|
+
};
|
|
677
902
|
/** The highest of `types`, none of which is `none`. */
|
|
678
903
|
const highestType = (types) => types.reduce((high, type) => RANK[type] > RANK[high] ? type : high, "none");
|
|
679
904
|
/**
|
|
@@ -683,6 +908,7 @@ const highestType = (types) => types.reduce((high, type) => RANK[type] > RANK[hi
|
|
|
683
908
|
*/
|
|
684
909
|
const assembleOrHalt = (input) => {
|
|
685
910
|
const { packages, changesets, config, pre, snapshot } = input;
|
|
911
|
+
if (input.manager === "pnpm") return assemblePnpm(input);
|
|
686
912
|
if (snapshot !== void 0 && pre?.mode === "pre") throw new Halt(new SnapshotPreModeError({ preTag: pre.tag }));
|
|
687
913
|
const byName = new Map(packages.map((pkg) => [pkg.name, pkg]));
|
|
688
914
|
const ignored = new Set(matchNames(packages, config.ignore));
|
|
@@ -691,10 +917,11 @@ const assembleOrHalt = (input) => {
|
|
|
691
917
|
const linked = config.linked.map((group) => matchNames(packages, group));
|
|
692
918
|
const invalid = groupError(fixed, linked);
|
|
693
919
|
if (invalid !== void 0) throw new Halt(invalid);
|
|
694
|
-
for (const changeset of changesets) for (const
|
|
695
|
-
packageName:
|
|
920
|
+
for (const changeset of changesets) for (const key of changeset.releases.keys()) if (!byName.has(key)) throw new Halt(new UnknownPackageError({
|
|
921
|
+
packageName: key,
|
|
696
922
|
changeset: changeset.file
|
|
697
923
|
}));
|
|
924
|
+
const releasesOf = (changeset) => [...changeset.releases];
|
|
698
925
|
const consumedIds = new Set(pre?.changesets ?? []);
|
|
699
926
|
const listedConsumed = (file) => !file.startsWith("pre/") && consumedIds.has(file.replace(/\.md$/, ""));
|
|
700
927
|
const relevant = pre === void 0 ? changesets : pre.mode === "pre" ? changesets.filter((c) => !c.file.startsWith("pre/") && !listedConsumed(c.file)) : changesets.map((c) => listedConsumed(c.file) ? PendingChangeset.make({
|
|
@@ -719,7 +946,7 @@ const assembleOrHalt = (input) => {
|
|
|
719
946
|
return pre !== void 0 && pre.mode === "pre" ? `${next}-${pre.tag}.${preNumbers.get(release.name) ?? 0}` : next;
|
|
720
947
|
};
|
|
721
948
|
const releases = /* @__PURE__ */ new Map();
|
|
722
|
-
for (const changeset of relevant) for (const [name, type] of changeset
|
|
949
|
+
for (const changeset of relevant) for (const [name, type] of releasesOf(changeset)) {
|
|
723
950
|
const pkg = byName.get(name);
|
|
724
951
|
if (isSkipped(pkg)) continue;
|
|
725
952
|
const release = releases.get(name);
|
|
@@ -728,7 +955,8 @@ const assembleOrHalt = (input) => {
|
|
|
728
955
|
name,
|
|
729
956
|
type,
|
|
730
957
|
oldVersion: pkg.version,
|
|
731
|
-
changesets: [changeset.id]
|
|
958
|
+
changesets: [changeset.id],
|
|
959
|
+
causes: /* @__PURE__ */ new Set(["intent"])
|
|
732
960
|
});
|
|
733
961
|
continue;
|
|
734
962
|
}
|
|
@@ -766,7 +994,8 @@ const assembleOrHalt = (input) => {
|
|
|
766
994
|
name: dependent.name,
|
|
767
995
|
type,
|
|
768
996
|
oldVersion: dependent.version,
|
|
769
|
-
changesets: []
|
|
997
|
+
changesets: [],
|
|
998
|
+
causes: /* @__PURE__ */ new Set(["dependencies"])
|
|
770
999
|
};
|
|
771
1000
|
releases.set(dependent.name, release);
|
|
772
1001
|
search.push(release);
|
|
@@ -808,17 +1037,20 @@ const assembleOrHalt = (input) => {
|
|
|
808
1037
|
name,
|
|
809
1038
|
type,
|
|
810
1039
|
oldVersion,
|
|
811
|
-
changesets: []
|
|
1040
|
+
changesets: [],
|
|
1041
|
+
causes: /* @__PURE__ */ new Set(["fixed"])
|
|
812
1042
|
});
|
|
813
1043
|
continue;
|
|
814
1044
|
}
|
|
815
1045
|
if (release.type !== type) {
|
|
816
1046
|
updated = true;
|
|
817
1047
|
release.type = type;
|
|
1048
|
+
release.causes.add("fixed");
|
|
818
1049
|
}
|
|
819
1050
|
if (release.oldVersion !== oldVersion) {
|
|
820
1051
|
updated = true;
|
|
821
1052
|
release.oldVersion = oldVersion;
|
|
1053
|
+
release.causes.add("fixed");
|
|
822
1054
|
}
|
|
823
1055
|
}
|
|
824
1056
|
}
|
|
@@ -856,9 +1088,13 @@ const assembleOrHalt = (input) => {
|
|
|
856
1088
|
name: pkg.name,
|
|
857
1089
|
type: "patch",
|
|
858
1090
|
oldVersion: pkg.version,
|
|
859
|
-
changesets: []
|
|
1091
|
+
changesets: [],
|
|
1092
|
+
causes: /* @__PURE__ */ new Set(["intent"])
|
|
860
1093
|
});
|
|
861
|
-
else if (release.type === "none")
|
|
1094
|
+
else if (release.type === "none") {
|
|
1095
|
+
release.type = "patch";
|
|
1096
|
+
release.causes.add("intent");
|
|
1097
|
+
}
|
|
862
1098
|
}
|
|
863
1099
|
const suffix = snapshot === void 0 ? void 0 : snapshotSuffix(snapshot.prereleaseTemplate ?? config.snapshot.prereleaseTemplate, snapshot.tag === "" ? void 0 : snapshot.tag, snapshot.commit === "" ? void 0 : snapshot.commit, snapshot.timestamp);
|
|
864
1100
|
const useCalculated = snapshot?.useCalculatedVersion ?? config.snapshot.useCalculatedVersion;
|
|
@@ -875,7 +1111,8 @@ const assembleOrHalt = (input) => {
|
|
|
875
1111
|
type: release.type,
|
|
876
1112
|
oldVersion: release.oldVersion,
|
|
877
1113
|
newVersion: next,
|
|
878
|
-
changesets: [...release.changesets]
|
|
1114
|
+
changesets: [...release.changesets],
|
|
1115
|
+
causes: sortCauses(release.causes)
|
|
879
1116
|
}));
|
|
880
1117
|
}
|
|
881
1118
|
planned.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { checkPnpm } from "./internal/pnpmPlan.js";
|
|
2
|
+
import { Result, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/VersioningCheck.ts
|
|
5
|
+
/**
|
|
6
|
+
* An epic member whose committed major is outside the band of its lead.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
var EpicOutOfBand = class extends Schema.TaggedClass()("EpicOutOfBand", {
|
|
11
|
+
/** The epic's lead, as configured. */
|
|
12
|
+
epic: Schema.String,
|
|
13
|
+
/** The member at fault, by name. */
|
|
14
|
+
package: Schema.String,
|
|
15
|
+
/** The member's committed version. */
|
|
16
|
+
version: Schema.String,
|
|
17
|
+
/** The member's committed major, the one outside the band. */
|
|
18
|
+
major: Schema.Number,
|
|
19
|
+
/** The lead's major the band derives from: members live in `bandMajor*100` to `bandMajor*100+99`. */
|
|
20
|
+
bandMajor: Schema.Number
|
|
21
|
+
}) {
|
|
22
|
+
/** One line, as `pnpm change check` words it. */
|
|
23
|
+
get message() {
|
|
24
|
+
const low = this.bandMajor * 100;
|
|
25
|
+
return `${this.package} is at ${this.version}, whose major ${this.major} is outside the band ${low}-${low + 99} of the epic led by "${this.epic}" (major ${this.bandMajor}).`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A fixed group whose members do not share one version.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
var FixedOutOfStep = class extends Schema.TaggedClass()("FixedOutOfStep", {
|
|
34
|
+
/** The group, as written in `versioning.fixed`. */
|
|
35
|
+
group: Schema.Array(Schema.String),
|
|
36
|
+
/** Each participating member and its committed version, in the group's order. */
|
|
37
|
+
versions: Schema.Array(Schema.Struct({
|
|
38
|
+
package: Schema.String,
|
|
39
|
+
version: Schema.String
|
|
40
|
+
}))
|
|
41
|
+
}) {
|
|
42
|
+
/** One line, as `pnpm change check` words it. */
|
|
43
|
+
get message() {
|
|
44
|
+
return `The fixed group [${this.group.join(", ")}] is not in lockstep: ${this.versions.map((member) => `${member.package}@${member.version}`).join(", ")}.`;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The check behind `pnpm change check`: are the committed versions where the
|
|
49
|
+
* `versioning` block says they must be?
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* A port of `check_versioning_invariants`
|
|
53
|
+
* (`.repos/pnpm/pnpm/crates/versioning/src/plan.rs:217`). It looks at no
|
|
54
|
+
* intent and plans nothing: with no plan, an epic's band comes from its lead's
|
|
55
|
+
* current major (a lead on `N.0.0-<lane>.x` is still in the band of `N-1`),
|
|
56
|
+
* and every member is held to it; every fixed group must share one version.
|
|
57
|
+
* The band rule is the one the planner enforces on new versions, read from the
|
|
58
|
+
* same function, so the two cannot disagree.
|
|
59
|
+
*
|
|
60
|
+
* Every violation is returned, not the first: epic members in directory order
|
|
61
|
+
* per epic, then fixed groups in declaration order. A `versioning` block pnpm
|
|
62
|
+
* refuses (an ambiguous name, an unknown lead, overlapping epics) fails with
|
|
63
|
+
* {@link VersioningError} before any version is looked at, as pnpm's does.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { VersioningCheck } from "@effected/changesets";
|
|
68
|
+
* import { Result } from "effect";
|
|
69
|
+
*
|
|
70
|
+
* const found = VersioningCheck.check([], undefined);
|
|
71
|
+
* console.log(Result.isSuccess(found) && found.success.length);
|
|
72
|
+
* // => 0
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
var VersioningCheck = class {
|
|
78
|
+
constructor() {}
|
|
79
|
+
/**
|
|
80
|
+
* Check `packages`' committed versions against `versioning`.
|
|
81
|
+
*
|
|
82
|
+
* @param packages - Every package of the workspace, the root included.
|
|
83
|
+
* @param versioning - The `versioning` block, or none.
|
|
84
|
+
*/
|
|
85
|
+
static check(packages, versioning) {
|
|
86
|
+
return Result.map(checkPnpm({
|
|
87
|
+
packages,
|
|
88
|
+
versioning
|
|
89
|
+
}), (found) => found.map((violation) => violation._tag === "EpicOutOfBand" ? EpicOutOfBand.make({
|
|
90
|
+
epic: violation.epic,
|
|
91
|
+
package: violation.package,
|
|
92
|
+
version: violation.version,
|
|
93
|
+
bandMajor: violation.bandMajor,
|
|
94
|
+
major: violation.major
|
|
95
|
+
}) : FixedOutOfStep.make({
|
|
96
|
+
group: [...violation.group],
|
|
97
|
+
versions: violation.versions.map((member) => ({ ...member }))
|
|
98
|
+
})));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { EpicOutOfBand, FixedOutOfStep, VersioningCheck };
|