rolldown-pnpm-config 3.0.7 → 3.1.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/cli/commands/export.js +1 -1
- package/cli/commands/sync.js +527 -0
- package/cli/effective.js +12 -2
- package/cli/exit-codes.js +9 -2
- package/cli/local-merge.js +66 -1
- package/cli/preview-views.js +1 -1
- package/cli/root.js +3 -1
- package/cli/sync/commit-message.js +19 -0
- package/cli/sync/config.js +83 -0
- package/cli/sync/floors.js +146 -0
- package/cli/sync/local-gate.js +63 -0
- package/cli/sync/membership.js +118 -0
- package/cli/sync/release-plan.js +49 -0
- package/cli/sync/ripples.js +59 -0
- package/cli/sync/running-list.js +153 -0
- package/cli/version.js +1 -1
- package/index.d.ts +76 -9
- package/package.json +1 -1
- package/plugin/freeze.js +2 -1
- package/runtime/strategies/arrays.js +15 -10
- package/skills/rolldown-pnpm-config/SKILL.md +47 -0
- package/skills/rolldown-pnpm-config/assets/catalog-sync.yml +287 -0
- package/skills/rolldown-pnpm-config/assets/pre-push.sh +32 -0
- package/skills/rolldown-pnpm-config/references/catalogs.md +95 -0
- package/skills/rolldown-pnpm-config/references/options.md +314 -0
- package/skills/rolldown-pnpm-config/references/sync.md +138 -0
- package/skills/rolldown-pnpm-config/references/wiring.md +194 -0
package/cli/preview-views.js
CHANGED
|
@@ -17,7 +17,7 @@ import { overlayWorkspace } from "./workspace-overlay.js";
|
|
|
17
17
|
*/
|
|
18
18
|
function buildPreviewViews(input) {
|
|
19
19
|
const meta = {
|
|
20
|
-
localKeys: new Set(
|
|
20
|
+
localKeys: new Set(Object.keys(input.local ?? {}).filter((k) => WORKSPACE_FIELDS.has(k))),
|
|
21
21
|
managedKeys: WORKSPACE_FIELDS
|
|
22
22
|
};
|
|
23
23
|
const effective = effectiveManaged(input.managed, input.local, input.parsed, input.manifest, input.rootName);
|
package/cli/root.js
CHANGED
|
@@ -2,6 +2,7 @@ import { CliAudience } from "@effected/cli-kit";
|
|
|
2
2
|
import { Command } from "effect/cli";
|
|
3
3
|
import { exportCommand } from "./commands/export.js";
|
|
4
4
|
import { previewCommand } from "./commands/preview.js";
|
|
5
|
+
import { syncCommand } from "./commands/sync.js";
|
|
5
6
|
import { upgradeCommand } from "./commands/upgrade.js";
|
|
6
7
|
|
|
7
8
|
// src/cli/root.ts
|
|
@@ -15,7 +16,8 @@ import { upgradeCommand } from "./commands/upgrade.js";
|
|
|
15
16
|
const rootCommand = Command.make("rolldown-pnpm-config").pipe(Command.withSharedFlags(CliAudience.flags()), Command.withSubcommands([
|
|
16
17
|
upgradeCommand,
|
|
17
18
|
exportCommand,
|
|
18
|
-
previewCommand
|
|
19
|
+
previewCommand,
|
|
20
|
+
syncCommand
|
|
19
21
|
]));
|
|
20
22
|
|
|
21
23
|
export { rootCommand };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { byCatalog } from "./running-list.js";
|
|
2
|
+
|
|
3
|
+
// src/cli/sync/commit-message.ts
|
|
4
|
+
/**
|
|
5
|
+
* The commit message for a set of moves: a conventional-commit headline, a
|
|
6
|
+
* blank line, then one bullet per package.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* With no moves the message is the headline alone.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function renderCommitMessage(scope, moves) {
|
|
14
|
+
const headline = `chore(${scope}): sync catalog to the next release versions`;
|
|
15
|
+
if (moves.length === 0) return `${headline}\n`;
|
|
16
|
+
return `${headline}\n\n${byCatalog(moves).flatMap(([, group]) => group.map((move) => `- \`${move.pkg}\` ${move.from} -> ${move.to}`)).join("\n")}\n`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { renderCommitMessage };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { CliDoc } from "@effected/cli-kit";
|
|
2
|
+
import { Data, Effect, Schema } from "effect";
|
|
3
|
+
import { failureDoc } from "../render/report.js";
|
|
4
|
+
|
|
5
|
+
// src/cli/sync/config.ts
|
|
6
|
+
/**
|
|
7
|
+
* Typed failure raised when the `sync` block is absent or malformed. A usage
|
|
8
|
+
* error: the CLI maps it to exit 64.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
var SyncConfigError = class extends Data.TaggedError("SyncConfigError") {
|
|
13
|
+
/** The failure report `CliRuntime.main` prints: the message, without the class name. */
|
|
14
|
+
[CliDoc]() {
|
|
15
|
+
return failureDoc(this.message);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const Names = Schema.Array(Schema.String);
|
|
19
|
+
const SyncSchema = Schema.Struct({
|
|
20
|
+
catalog: Schema.String,
|
|
21
|
+
members: Schema.Struct({
|
|
22
|
+
scope: Schema.NonEmptyString,
|
|
23
|
+
packages: Schema.optionalKey(Names),
|
|
24
|
+
exclude: Schema.optionalKey(Names)
|
|
25
|
+
}),
|
|
26
|
+
changeset: Schema.optionalKey(Schema.Struct({
|
|
27
|
+
path: Schema.optionalKey(Schema.String),
|
|
28
|
+
bump: Schema.optionalKey(Schema.Literals(["patch", "minor"]))
|
|
29
|
+
})),
|
|
30
|
+
commit: Schema.optionalKey(Schema.Struct({
|
|
31
|
+
scope: Schema.optionalKey(Schema.String),
|
|
32
|
+
messagePath: Schema.optionalKey(Schema.String)
|
|
33
|
+
})),
|
|
34
|
+
floors: Schema.optionalKey(Schema.Boolean),
|
|
35
|
+
local: Schema.optionalKey(Schema.Struct({
|
|
36
|
+
pnpmfile: Schema.optionalKey(Schema.String),
|
|
37
|
+
catalogs: Schema.optionalKey(Names)
|
|
38
|
+
}))
|
|
39
|
+
});
|
|
40
|
+
const decodeSync = Schema.decodeUnknownEffect(SyncSchema);
|
|
41
|
+
/**
|
|
42
|
+
* Decode the statically evaluated `sync` block of a plugin config and apply
|
|
43
|
+
* its defaults. Unknown keys are rejected so a typo cannot pass for an absent
|
|
44
|
+
* setting.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function resolveSyncConfig(config) {
|
|
49
|
+
if (config.sync === void 0) return Effect.fail(new SyncConfigError({ message: "no `sync` block: add `sync: { catalog, members: { scope } }` to the PnpmConfigPlugin config" }));
|
|
50
|
+
return decodeSync(config.sync, {
|
|
51
|
+
onExcessProperty: "error",
|
|
52
|
+
errors: "all"
|
|
53
|
+
}).pipe(Effect.mapError((error) => new SyncConfigError({ message: `invalid \`sync\` block: ${error.message}` })), Effect.map((sync) => ({
|
|
54
|
+
catalog: sync.catalog,
|
|
55
|
+
scope: sync.members.scope,
|
|
56
|
+
packages: sync.members.packages,
|
|
57
|
+
exclude: sync.members.exclude ?? [],
|
|
58
|
+
changesetPath: sync.changeset?.path ?? ".changeset/catalog-sync.md",
|
|
59
|
+
bump: sync.changeset?.bump ?? "patch",
|
|
60
|
+
commitScope: sync.commit?.scope ?? sync.catalog,
|
|
61
|
+
messagePath: sync.commit?.messagePath ?? ".changeset/catalog-sync.commit.txt",
|
|
62
|
+
floors: sync.floors ?? false,
|
|
63
|
+
pnpmfile: sync.local?.pnpmfile ?? "dist/prod/npm/pkg/pnpmfile.mjs",
|
|
64
|
+
localCatalogs: sync.local?.catalogs
|
|
65
|
+
})));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Decode the `sync` block from what `evaluatePluginConfig` read out of
|
|
69
|
+
* `configFile`, naming the real problem when there is no config to read: a
|
|
70
|
+
* file that does not parse, or one with no `PnpmConfigPlugin(...)` call, is not
|
|
71
|
+
* a config with a missing `sync` block. Each is a usage error (exit 64).
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
function resolveEvaluatedSync(evaluated, configFile) {
|
|
76
|
+
if (evaluated.config === null) {
|
|
77
|
+
const message = evaluated.errors.length > 0 ? `cannot parse ${configFile}:\n${evaluated.errors.map((e) => ` ${e}`).join("\n")}` : `no PnpmConfigPlugin(...) call found in ${configFile}: sync reads its \`sync\` block from that call's config`;
|
|
78
|
+
return Effect.fail(new SyncConfigError({ message }));
|
|
79
|
+
}
|
|
80
|
+
return resolveSyncConfig(evaluated.config);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { SyncConfigError, resolveEvaluatedSync, resolveSyncConfig };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ChangesetConfig, PendingChangeset, PendingChangesets, PreState, ReleasePlan } from "@effected/changesets";
|
|
2
|
+
import { WorkspaceDiscovery } from "@effected/workspaces";
|
|
3
|
+
import { Effect, FileSystem, Option, Path } from "effect";
|
|
4
|
+
import { ReleasePlanError, discoveryLayer } from "./release-plan.js";
|
|
5
|
+
|
|
6
|
+
// src/cli/sync/floors.ts
|
|
7
|
+
/**
|
|
8
|
+
* Every file the floor pass owns starts with this, under `.changeset/`.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
const FLOOR_PREFIX = "breaking-floor-";
|
|
13
|
+
const floorFile = (name) => `${FLOOR_PREFIX}${name.replace(/^@/, "").replace(/\//g, "-")}.md`;
|
|
14
|
+
const isFloorFile = (file) => file.startsWith("breaking-floor-") && file.endsWith(".md");
|
|
15
|
+
/** The changeset raising one package, with a line per dependency whose floor it crosses. */
|
|
16
|
+
const renderFloorChangeset = (raised) => {
|
|
17
|
+
const lines = raised.causes.map((cause) => `- Requires \`${cause.dependency}\` ${cause.newVersion} (\`${cause.kind}\`: \`${cause.range}\`), a breaking release from ${cause.oldVersion}. A consumer still on ${cause.oldVersion} cannot install this version beside it, so this release leaves its own version line too.`);
|
|
18
|
+
const upgrade = raised.causes.map((cause) => `\`${cause.dependency}\` to ${cause.newVersion}`).join(", ");
|
|
19
|
+
return `---\n"${raised.name}": ${raised.required}\n---\n\n## Breaking Changes\n\n${lines.join("\n")}\n\nTo upgrade, move ${upgrade} in the same install as this release.\n`;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Raise every release whose published floor crosses a dependency's breaking
|
|
23
|
+
* line, then plan again until none does.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* `@changesets/assemble-release-plan` bumps a dependent `patch` however far its
|
|
27
|
+
* dependency moves. Under `workspace:^` a dependent released beside a breaking
|
|
28
|
+
* 0.x minor publishes a floor on the new minor, so a consumer holding the old
|
|
29
|
+
* line of both resolves the patch and gets a dependency it cannot satisfy.
|
|
30
|
+
* `ReleasePlan.breakingFloors` finds those releases. A raised package can cross
|
|
31
|
+
* its own dependents' floors, so each pass feeds the raises back in as synthetic
|
|
32
|
+
* changesets; the package count bounds the passes.
|
|
33
|
+
*
|
|
34
|
+
* Our own files are read out of the base before any plan is made: an obsolete
|
|
35
|
+
* one naming a removed package would fail the plan instead of being deleted, and
|
|
36
|
+
* a raise must never be its own evidence.
|
|
37
|
+
*/
|
|
38
|
+
const planFloors = Effect.fn("Sync.planFloors")(function* (rootDir) {
|
|
39
|
+
const discovered = yield* (yield* WorkspaceDiscovery).listPackagesIn(rootDir);
|
|
40
|
+
const config = yield* ChangesetConfig.read(rootDir);
|
|
41
|
+
const pending = yield* PendingChangesets.read(rootDir);
|
|
42
|
+
const pre = yield* PreState.read(rootDir);
|
|
43
|
+
const base = pending.filter((changeset) => !isFloorFile(changeset.file));
|
|
44
|
+
const members = discovered.filter((pkg) => !pkg.isRootWorkspace);
|
|
45
|
+
const packages = members.length > 0 ? members : discovered;
|
|
46
|
+
const raised = /* @__PURE__ */ new Map();
|
|
47
|
+
for (let pass = 0; pass <= packages.length; pass++) {
|
|
48
|
+
const synthetic = [...raised.values()].map((r) => PendingChangeset.make({
|
|
49
|
+
file: floorFile(r.name),
|
|
50
|
+
releases: /* @__PURE__ */ new Map([[r.name, r.required]]),
|
|
51
|
+
summary: ""
|
|
52
|
+
}));
|
|
53
|
+
const plan = yield* Effect.fromResult(ReleasePlan.assemble({
|
|
54
|
+
packages,
|
|
55
|
+
changesets: [...base, ...synthetic],
|
|
56
|
+
config,
|
|
57
|
+
...Option.isSome(pre) ? { pre: pre.value } : {}
|
|
58
|
+
}));
|
|
59
|
+
const floors = yield* Effect.fromResult(ReleasePlan.breakingFloors(plan, {
|
|
60
|
+
packages: discovered,
|
|
61
|
+
config
|
|
62
|
+
}));
|
|
63
|
+
if (floors.length === 0) return [...raised.values()].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
64
|
+
for (const floor of floors) raised.set(floor.name, {
|
|
65
|
+
name: floor.name,
|
|
66
|
+
required: floor.required,
|
|
67
|
+
causes: floor.causes
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return yield* Effect.die(/* @__PURE__ */ new Error("breaking floors did not settle; a raise should never undo another"));
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Plan the breaking-floor changesets for the workspace at `rootDir`: the raised
|
|
74
|
+
* releases, and the edits that make `.changeset/` hold exactly those and none
|
|
75
|
+
* other of ours. Writes nothing.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The files are derived. Every run recomputes them from the other changesets,
|
|
79
|
+
* rewrites those still needed and deletes the rest, so a floor that stops
|
|
80
|
+
* crossing takes its file with it. A plan that cannot be read fails
|
|
81
|
+
* {@link ReleasePlanError} rather than reporting "nothing crosses".
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
const planFloorEdits = Effect.fn("Sync.planFloorEdits")(function* (rootDir) {
|
|
86
|
+
const fs = yield* FileSystem.FileSystem;
|
|
87
|
+
const path = yield* Path.Path;
|
|
88
|
+
const raised = yield* planFloors(rootDir).pipe(Effect.provide(discoveryLayer(rootDir)), Effect.mapError((error) => new ReleasePlanError({ message: `Release plan could not be read: ${error.message}` })));
|
|
89
|
+
const dir = path.join(rootDir, ".changeset");
|
|
90
|
+
const edits = [];
|
|
91
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
92
|
+
for (const r of raised) {
|
|
93
|
+
const file = floorFile(r.name);
|
|
94
|
+
wanted.add(file);
|
|
95
|
+
const content = renderFloorChangeset(r);
|
|
96
|
+
const target = path.join(dir, file);
|
|
97
|
+
const current = yield* fs.readFileString(target).pipe(Effect.option);
|
|
98
|
+
if (Option.isNone(current) || current.value !== content) edits.push({
|
|
99
|
+
path: `.changeset/${file}`,
|
|
100
|
+
content
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const present = (yield* fs.readDirectory(dir).pipe(Effect.catchTag("PlatformError", (error) => error.reason._tag === "NotFound" ? Effect.succeed([]) : Effect.fail(error)), Effect.mapError((error) => new ReleasePlanError({ message: `Release plan could not be read: ${error.message}` })))).filter(isFloorFile).sort();
|
|
104
|
+
for (const file of present) if (!wanted.has(file)) edits.push({
|
|
105
|
+
path: `.changeset/${file}`,
|
|
106
|
+
content: null
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
raised,
|
|
110
|
+
edits
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Apply `edits` under `rootDir`. Parent directories are created; deleting a
|
|
115
|
+
* file that is already gone is not an error.
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
const applyFloorEdits = Effect.fn("Sync.applyFloorEdits")(function* (rootDir, edits) {
|
|
120
|
+
const fs = yield* FileSystem.FileSystem;
|
|
121
|
+
const path = yield* Path.Path;
|
|
122
|
+
for (const { path: relative, content } of edits) {
|
|
123
|
+
const target = path.join(rootDir, relative);
|
|
124
|
+
if (content === null) yield* fs.remove(target, { force: true });
|
|
125
|
+
else {
|
|
126
|
+
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
|
|
127
|
+
yield* fs.writeFileString(target, content);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* One line per edit, for a person reading a log or a red check.
|
|
133
|
+
*
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
function describeFloorEdits(raised, edits) {
|
|
137
|
+
const byPath = new Map(raised.map((r) => [`.changeset/${floorFile(r.name)}`, r]));
|
|
138
|
+
return edits.map(({ path, content }) => {
|
|
139
|
+
const r = byPath.get(path);
|
|
140
|
+
if (content === null || r === void 0) return ` ${path} (no longer needed)\n`;
|
|
141
|
+
const deps = r.causes.map((c) => `${c.dependency} ${c.oldVersion} -> ${c.newVersion}`).join(", ");
|
|
142
|
+
return ` ${r.name} -> ${r.required} (crosses ${deps})\n`;
|
|
143
|
+
}).join("");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { FLOOR_PREFIX, applyFloorEdits, describeFloorEdits, planFloorEdits };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { Fmt } from "@effected/cli-kit";
|
|
4
|
+
import { Data, Effect, Predicate } from "effect";
|
|
5
|
+
|
|
6
|
+
// src/cli/sync/local-gate.ts
|
|
7
|
+
/**
|
|
8
|
+
* Typed failure of the offline local gate (the built pnpmfile is missing or
|
|
9
|
+
* cannot be evaluated).
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
var LocalGateError = class extends Data.TaggedError("LocalGateError") {};
|
|
14
|
+
/**
|
|
15
|
+
* Import the built pnpmfile and ask its `updateConfig` hook what an empty
|
|
16
|
+
* consumer config receives. Offline; writes nothing.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function readServedCatalogs(pnpmfilePath) {
|
|
21
|
+
if (!existsSync(pnpmfilePath)) return Effect.fail(new LocalGateError({ message: `no built pnpmfile at ${pnpmfilePath}; build the plugin first` }));
|
|
22
|
+
return Effect.tryPromise({
|
|
23
|
+
try: async () => {
|
|
24
|
+
return (await (await import(pathToFileURL(pnpmfilePath).href)).hooks.updateConfig({})).catalogs ?? {};
|
|
25
|
+
},
|
|
26
|
+
catch: (cause) => new LocalGateError({ message: `cannot evaluate ${pnpmfilePath}: ${Fmt.errorText(cause)}` })
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The catalogs the export writes into this repo's own workspace file: an
|
|
31
|
+
* explicit `local.catalogs` wins, otherwise every served catalog except the
|
|
32
|
+
* sync catalog and its `:peers` sibling.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
function exportedCatalogNames(served, sync) {
|
|
37
|
+
if (sync.localCatalogs !== void 0) return sync.localCatalogs;
|
|
38
|
+
return Object.keys(served).filter((name) => name !== sync.catalog && name !== `${sync.catalog}:peers`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Per exported catalog, the packages whose served range differs from the
|
|
42
|
+
* parsed `pnpm-workspace.yaml` mapping (its `catalogs` key holds the named
|
|
43
|
+
* catalogs). Rows are human-readable; empty means in sync.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
function exportDrift(served, names, workspace) {
|
|
48
|
+
const catalogs = Predicate.isObject(workspace.catalogs) ? workspace.catalogs : {};
|
|
49
|
+
const rows = [];
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
const want = served[name] ?? {};
|
|
52
|
+
const raw = catalogs[name];
|
|
53
|
+
if (!Predicate.isObject(raw)) {
|
|
54
|
+
rows.push(` ${name}: absent from pnpm-workspace.yaml`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const have = raw;
|
|
58
|
+
for (const pkg of [.../* @__PURE__ */ new Set([...Object.keys(want), ...Object.keys(have)])].sort()) if (want[pkg] !== have[pkg]) rows.push(` ${name}.${pkg} served ${want[pkg] ?? "(absent)"}, pnpm-workspace.yaml ${have[pkg] ?? "(absent)"}`);
|
|
59
|
+
}
|
|
60
|
+
return rows;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { LocalGateError, exportDrift, exportedCatalogNames, readServedCatalogs };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CliDoc } from "@effected/cli-kit";
|
|
4
|
+
import { GlobPattern } from "@effected/glob";
|
|
5
|
+
import { Walker } from "@effected/walker";
|
|
6
|
+
import { getWorkspacePackagesSync } from "@effected/workspaces";
|
|
7
|
+
import { nodeSyncOps } from "@effected/workspaces/node-sync";
|
|
8
|
+
import { Data, Effect, FileSystem, Option, Path, Result, Schema } from "effect";
|
|
9
|
+
import { readCatalogSource } from "../commands/upgrade.js";
|
|
10
|
+
import { failureDoc } from "../render/report.js";
|
|
11
|
+
|
|
12
|
+
// src/cli/sync/membership.ts
|
|
13
|
+
/**
|
|
14
|
+
* Typed failure raised when the workspace cannot be discovered, or discovery
|
|
15
|
+
* leaves nothing to check against. A finding, not a usage error: exit 1.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
var SyncWorkspaceError = class extends Data.TaggedError("SyncWorkspaceError") {
|
|
20
|
+
/** The failure report `CliRuntime.main` prints: the message, without the class name. */
|
|
21
|
+
[CliDoc]() {
|
|
22
|
+
return failureDoc(this.message);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const PackageName = Schema.fromJsonString(Schema.Struct({ name: Schema.String }));
|
|
26
|
+
const decodePackageName = Schema.decodeUnknownEffect(PackageName);
|
|
27
|
+
/**
|
|
28
|
+
* The nearest `package.json` at or above the config file: the plugin
|
|
29
|
+
* package's manifest.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
const pluginManifest = Effect.fn("Sync.pluginManifest")(function* (configFile) {
|
|
34
|
+
const path = yield* Path.Path;
|
|
35
|
+
const dirs = yield* Walker.ascend(path.dirname(path.resolve(configFile)));
|
|
36
|
+
const found = yield* Walker.findUpward(dirs, (dir) => [path.join(dir, "package.json")]);
|
|
37
|
+
if (Option.isNone(found)) return yield* new SyncWorkspaceError({ message: `no package.json found at or above ${configFile}` });
|
|
38
|
+
return found.value;
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* The name of the plugin package: the `name` of the nearest `package.json` at
|
|
42
|
+
* or above the config file. Membership always excludes it.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
const pluginPackageName = Effect.fn("Sync.pluginPackageName")(function* (configFile) {
|
|
47
|
+
const fs = yield* FileSystem.FileSystem;
|
|
48
|
+
const manifest = yield* pluginManifest(configFile);
|
|
49
|
+
return yield* fs.readFileString(manifest).pipe(Effect.flatMap(decodePackageName), Effect.map((m) => m.name), Effect.mapError(() => new SyncWorkspaceError({ message: `cannot read a package name from ${manifest}` })));
|
|
50
|
+
});
|
|
51
|
+
function compile(source) {
|
|
52
|
+
return Result.mapError(GlobPattern.compileResult(source), (error) => new SyncWorkspaceError({ message: `invalid glob "${source}": ${error.message}` }));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Publishable workspace packages in `sync.scope`, sorted: `publishConfig.access`
|
|
56
|
+
* is `"public"`, the name is not excluded and is not the plugin itself. A scope
|
|
57
|
+
* that matches no workspace package name at all, whatever its access, fails.
|
|
58
|
+
* `sync.packages`, when set, limits discovery to members whose workspace-relative
|
|
59
|
+
* path matches one of its globs. Unlike the upgrade resolver, an unreadable
|
|
60
|
+
* workspace fails rather than reading as empty: an empty list would pass the
|
|
61
|
+
* gate for the wrong reason.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
function publishableMembers(rootDir, sync, pluginName) {
|
|
66
|
+
return Effect.gen(function* () {
|
|
67
|
+
if (!existsSync(join(rootDir, "pnpm-workspace.yaml"))) return yield* new SyncWorkspaceError({ message: `no pnpm-workspace.yaml found in ${rootDir}` });
|
|
68
|
+
const scope = yield* Effect.fromResult(compile(sync.scope));
|
|
69
|
+
const excludes = yield* Effect.fromResult(Result.all(sync.exclude.map(compile)));
|
|
70
|
+
const paths = yield* Effect.fromResult(Result.all((sync.packages ?? []).map(compile)));
|
|
71
|
+
const packages = yield* Effect.try({
|
|
72
|
+
try: () => getWorkspacePackagesSync(rootDir, nodeSyncOps),
|
|
73
|
+
catch: (error) => new SyncWorkspaceError({ message: `cannot discover workspace packages in ${rootDir}: ${error instanceof Error ? error.message : String(error)}` })
|
|
74
|
+
});
|
|
75
|
+
if (!packages.some((pkg) => scope.matches(pkg.name))) return yield* new SyncWorkspaceError({ message: `members.scope "${sync.scope}" matches no workspace package in ${rootDir}: check it for a typo` });
|
|
76
|
+
return packages.filter((pkg) => pkg.publishConfig?.access === "public" && pkg.name !== pluginName && scope.matches(pkg.name) && !excludes.some((glob) => glob.matches(pkg.name)) && (sync.packages === void 0 || paths.some((glob) => glob.matches(pkg.relativePath)))).map((pkg) => pkg.name).sort();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Compare the workspace's publishable members with the packages the sync
|
|
81
|
+
* catalog names in the config at `configFile`.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
const checkMembership = Effect.fn("Sync.checkMembership")(function* (configFile, rootDir, sync) {
|
|
86
|
+
const publishable = yield* publishableMembers(rootDir, sync, yield* pluginPackageName(configFile));
|
|
87
|
+
const { entries } = yield* readCatalogSource(configFile, sync.catalog);
|
|
88
|
+
const catalogued = entries.map((entry) => entry.pkg);
|
|
89
|
+
const scope = yield* Effect.fromResult(compile(sync.scope));
|
|
90
|
+
const inScope = catalogued.filter((name) => scope.matches(name));
|
|
91
|
+
if (publishable.length === 0 && inScope.length > 0) return yield* new SyncWorkspaceError({ message: `no publishable package matches ${sync.scope}, yet the \`${sync.catalog}\` catalog names ${inScope.length}: a member that is \`private\` without \`publishConfig.access: "public"\` is not publishable` });
|
|
92
|
+
const named = new Set(catalogued);
|
|
93
|
+
return {
|
|
94
|
+
missing: publishable.filter((name) => !named.has(name)),
|
|
95
|
+
publishable,
|
|
96
|
+
catalogued
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* What to do about a membership gap: the last line of {@link membershipMessage}.
|
|
101
|
+
*
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
const MEMBERSHIP_REMEDY = "Add an entry for each at the PnpmConfigPlugin(...) call site with `source: \"workspace\"`.";
|
|
105
|
+
/**
|
|
106
|
+
* The failure text for publishable packages the catalog does not name.
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
function membershipMessage(missing, configFile) {
|
|
111
|
+
return [
|
|
112
|
+
`Publishable packages missing from the catalog in ${configFile}:`,
|
|
113
|
+
...missing.map((name) => ` - ${name}`),
|
|
114
|
+
MEMBERSHIP_REMEDY
|
|
115
|
+
].join("\n");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { MEMBERSHIP_REMEDY, SyncWorkspaceError, checkMembership, membershipMessage, pluginManifest, pluginPackageName, publishableMembers };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ReleasePlan } from "@effected/changesets";
|
|
2
|
+
import { CliDoc } from "@effected/cli-kit";
|
|
3
|
+
import { WorkspaceDiscovery, WorkspaceRoot } from "@effected/workspaces";
|
|
4
|
+
import { Data, Effect, Layer } from "effect";
|
|
5
|
+
import { failureDoc } from "../render/report.js";
|
|
6
|
+
|
|
7
|
+
// src/cli/sync/release-plan.ts
|
|
8
|
+
/**
|
|
9
|
+
* Typed failure raised when the release plan cannot be read. A finding, not an
|
|
10
|
+
* empty plan: an empty plan would pass the ripple gate with nothing checked.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
var ReleasePlanError = class extends Data.TaggedError("ReleasePlanError") {
|
|
15
|
+
/** The failure report `CliRuntime.main` prints: the message, without the class name. */
|
|
16
|
+
[CliDoc]() {
|
|
17
|
+
return failureDoc(this.message);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Workspace discovery rooted at `rootDir`, for the release-plan reads. Needs
|
|
22
|
+
* `FileSystem` and `Path` from the caller; it exposes only `WorkspaceDiscovery`.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
const discoveryLayer = (rootDir) => WorkspaceDiscovery.layer({ cwd: rootDir }).pipe(Layer.provide(WorkspaceRoot.layer));
|
|
27
|
+
/**
|
|
28
|
+
* Every package changesets would release from `rootDir`, and the version it
|
|
29
|
+
* would get, ripples included.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* `@effected/changesets` computes the true plan (and holds it to
|
|
33
|
+
* `@changesets/get-release-plan` in its own tests), so this asks it rather than
|
|
34
|
+
* reimplementing changesets' dependency resolution. A package bumped only as a
|
|
35
|
+
* dependency ripple has no changeset naming it, so the catalog goes stale on
|
|
36
|
+
* exactly the branch where it matters. `type: "none"` entries are listed by
|
|
37
|
+
* changesets but not released; taking their version would pin the catalog to a
|
|
38
|
+
* version nothing publishes.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
const readReleasePlan = Effect.fn("Sync.readReleasePlan")(function* (rootDir) {
|
|
43
|
+
const plan = yield* ReleasePlan.read(rootDir).pipe(Effect.provide(discoveryLayer(rootDir)), Effect.mapError((error) => new ReleasePlanError({ message: `Release plan could not be read: ${error.message}` })));
|
|
44
|
+
const versions = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const release of plan.releases) if (release.type !== "none") versions.set(release.name, release.newVersion);
|
|
46
|
+
return versions;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export { ReleasePlanError, discoveryLayer, readReleasePlan };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { derivePeerRange } from "../peer-range.js";
|
|
3
|
+
|
|
4
|
+
// src/cli/sync/ripples.ts
|
|
5
|
+
/**
|
|
6
|
+
* Catalog entries whose range does not name the version the plan would release.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* The peer follows the entry's strategy through `derivePeerRange`, so `lock`
|
|
10
|
+
* pins it and `lock-minor` floors it. An entry with no peer literal keeps none.
|
|
11
|
+
* A peer literal with no declared strategy floors as `lock-minor`, matching the
|
|
12
|
+
* scripts this ports.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const rippleMismatches = Effect.fn("Sync.rippleMismatches")(function* (entries, plan) {
|
|
17
|
+
const ripples = [];
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
const planned = plan.get(entry.pkg);
|
|
20
|
+
if (planned === void 0) continue;
|
|
21
|
+
const to = `${entry.operator}${planned}`;
|
|
22
|
+
if (entry.currentRange === to) continue;
|
|
23
|
+
const derived = entry.peer === void 0 ? void 0 : yield* Effect.orDie(derivePeerRange(to, entry.strategy ?? "lock-minor"));
|
|
24
|
+
const warning = derived?.warning?.message;
|
|
25
|
+
ripples.push({
|
|
26
|
+
catalog: entry.catalog,
|
|
27
|
+
pkg: entry.pkg,
|
|
28
|
+
from: entry.currentRange,
|
|
29
|
+
to,
|
|
30
|
+
peer: derived?.range,
|
|
31
|
+
...warning !== void 0 ? { warning } : {}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return ripples;
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Span edits that bring each rippled entry's `range` and `peer` literals to the
|
|
38
|
+
* planned values, quoted. Nothing else in the source is touched.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
function rippleEdits(entries, ripples) {
|
|
43
|
+
const edits = [];
|
|
44
|
+
for (const ripple of ripples) {
|
|
45
|
+
const entry = entries.find((e) => e.catalog === ripple.catalog && e.pkg === ripple.pkg);
|
|
46
|
+
if (entry === void 0) continue;
|
|
47
|
+
edits.push({
|
|
48
|
+
span: entry.rangeSpan,
|
|
49
|
+
text: JSON.stringify(ripple.to)
|
|
50
|
+
});
|
|
51
|
+
if (entry.peer !== void 0 && ripple.peer !== void 0) edits.push({
|
|
52
|
+
span: entry.peer.span,
|
|
53
|
+
text: JSON.stringify(ripple.peer)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return edits;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { rippleEdits, rippleMismatches };
|