@effected/changesets 0.0.0-stage → 0.2.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/BumpType.js ADDED
@@ -0,0 +1,27 @@
1
+ import { Schema } from "effect";
2
+
3
+ // src/BumpType.ts
4
+ /**
5
+ * A semver bump a changeset can request: `patch`, `minor` or `major`.
6
+ *
7
+ * @public
8
+ */
9
+ const BumpType = Schema.Literals([
10
+ "patch",
11
+ "minor",
12
+ "major"
13
+ ]);
14
+ /**
15
+ * What a changeset can say about a package: a {@link (BumpType:variable)}, or `none`, which names the package and
16
+ * moves no version.
17
+ *
18
+ * @public
19
+ */
20
+ const ReleaseType = Schema.Literals([
21
+ "patch",
22
+ "minor",
23
+ "major",
24
+ "none"
25
+ ]);
26
+
27
+ export { BumpType, ReleaseType };
@@ -0,0 +1,102 @@
1
+ import { ChangesetConfigError } from "./errors.js";
2
+ import { Effect, FileSystem, Path, Schema } from "effect";
3
+
4
+ // src/ChangesetConfig.ts
5
+ const Groups = Schema.Array(Schema.Array(Schema.String));
6
+ const expandPrivatePackages = (json) => {
7
+ const flag = json?.privatePackages;
8
+ return typeof flag === "boolean" ? {
9
+ ...json,
10
+ privatePackages: {
11
+ tag: flag,
12
+ version: flag
13
+ }
14
+ } : json;
15
+ };
16
+ /**
17
+ * The decoded `.changeset/config.json`, with the defaults changesets
18
+ * documents. Keys the schema does not model (`changelog`, `$schema`,
19
+ * `format`, ...) are kept on the instance rather than rejected.
20
+ *
21
+ * @public
22
+ */
23
+ var ChangesetConfig = class ChangesetConfig extends Schema.Class("ChangesetConfig")({
24
+ /** The branch releases are cut against. Defaults to `main`. */
25
+ baseBranch: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed("main"))),
26
+ /**
27
+ * Groups of packages that always release together at one version: when
28
+ * one bumps, every member does, by the group's highest bump, from the
29
+ * group's highest current version. Entries are globs over the
30
+ * workspace's names, with `!` negation applying in order.
31
+ */
32
+ fixed: Groups.pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
33
+ /**
34
+ * Groups of packages whose versions are kept in step: the members that
35
+ * release take the group's highest bump from its highest current version,
36
+ * and members with nothing to release stay out. Entries are globs, as in
37
+ * `fixed`.
38
+ */
39
+ linked: Groups.pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
40
+ /**
41
+ * Packages that never bump: globs over the workspace's package names, with
42
+ * `!` negation applying in order. A release plan can still list a matching
43
+ * package as `none` when it depends on something in the plan.
44
+ */
45
+ ignore: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
46
+ /**
47
+ * The smallest bump for which `changeset version` rewrites an internal
48
+ * dependency range. It is not the bump a dependent receives: a release plan
49
+ * always bumps a dependent `patch`.
50
+ */
51
+ updateInternalDependencies: Schema.Literals(["patch", "minor"]).pipe(Schema.withDecodingDefaultKey(Effect.succeed("patch"))),
52
+ /**
53
+ * Whether private packages are tagged and versioned. Both default to `false`,
54
+ * as `@changesets/config` has them, so a private package releases only when
55
+ * the file opts in. {@link ChangesetConfig.read} also takes the boolean form,
56
+ * which sets both.
57
+ */
58
+ privatePackages: Schema.Struct({
59
+ tag: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
60
+ version: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false)))
61
+ }).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
62
+ /** The publish access level. Defaults to `restricted`. */
63
+ access: Schema.Literals(["public", "restricted"]).pipe(Schema.withDecodingDefaultKey(Effect.succeed("restricted"))),
64
+ /** `false`, `true` or a commit-message generator spec; carried as-is. */
65
+ commit: Schema.Unknown.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
66
+ /**
67
+ * Every key of the file the schema does not model, such as `changelog` or
68
+ * `$schema`. A file key literally named `extra` is not carried: the field
69
+ * name is reserved.
70
+ */
71
+ extra: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
72
+ }) {
73
+ /**
74
+ * Read and decode `<root>/.changeset/config.json`.
75
+ *
76
+ * Fails with {@link ChangesetConfigError} when the file is missing
77
+ * (`reason: "missing"`), is not JSON, or has a malformed value. Whether the
78
+ * repository is in pre-release mode is `.changeset/pre.json`, which
79
+ * {@link PreState.read} reads.
80
+ *
81
+ * @param root - The repository root.
82
+ */
83
+ static read = Effect.fn("ChangesetConfig.read")(function* (root) {
84
+ const fs = yield* FileSystem.FileSystem;
85
+ const path = yield* Path.Path;
86
+ const dir = path.join(root, ".changeset");
87
+ const text = yield* fs.readFileString(path.join(dir, "config.json")).pipe(Effect.catch((error) => error.reason._tag === "NotFound" ? Effect.fail(new ChangesetConfigError({ reason: "missing" })) : Effect.fail(error)));
88
+ const json = yield* Effect.try({
89
+ try: () => JSON.parse(text),
90
+ catch: (cause) => new ChangesetConfigError({ reason: `not valid JSON: ${cause.message}` })
91
+ });
92
+ const decoded = yield* Schema.decodeUnknownEffect(ChangesetConfig)(expandPrivatePackages(json)).pipe(Effect.mapError((error) => new ChangesetConfigError({ reason: error.message })));
93
+ const known = new Set(Object.keys(ChangesetConfig.fields));
94
+ const extra = Object.fromEntries(Object.entries(json).filter(([key]) => !known.has(key)));
95
+ return ChangesetConfig.make({
96
+ ...decoded,
97
+ extra
98
+ });
99
+ });
100
+ };
101
+
102
+ export { ChangesetConfig };
@@ -0,0 +1,68 @@
1
+ import { ReleaseType } from "./BumpType.js";
2
+ import { ChangesetParseError } from "./errors.js";
3
+ import { Effect, Result, Schema } from "effect";
4
+ import { Yaml } from "@effected/yaml";
5
+
6
+ // src/ChangesetFile.ts
7
+ /**
8
+ * One parsed changeset: the packages it releases and its summary text.
9
+ *
10
+ * @public
11
+ */
12
+ var ParsedChangeset = class extends Schema.Class("ParsedChangeset")({
13
+ /** Package name to requested release type, in file order. */
14
+ releases: Schema.ReadonlyMap(Schema.String, ReleaseType),
15
+ /** The markdown after the front matter. */
16
+ summary: Schema.String
17
+ }) {};
18
+ const Releases = Schema.Record(Schema.String, ReleaseType);
19
+ const decodeReleases = Schema.decodeUnknownResult(Releases);
20
+ const fail = (reason, line) => Result.fail(new ChangesetParseError({
21
+ reason,
22
+ ...line === void 0 ? {} : { line }
23
+ }));
24
+ const parseText = (text) => {
25
+ const lines = text.split("\n");
26
+ const isFence = (line) => line !== void 0 && line.replace(/\r$/, "") === "---";
27
+ if (!isFence(lines[0])) return fail("missing front matter: the file must start with a --- line", 1);
28
+ const close = lines.findIndex((line, index) => index > 0 && isFence(line));
29
+ if (close === -1) return fail("unterminated front matter: no closing --- line", 1);
30
+ const block = lines.slice(1, close).join("\n");
31
+ const summary = lines.slice(close + 1).join("\n").replace(/^\r?\n/, "");
32
+ const value = block.trim() === "" ? Result.succeed({}) : Yaml.parseResult(block);
33
+ return Result.match(value, {
34
+ onFailure: (error) => fail(`front matter is not valid YAML: ${error.message}`, (error.diagnostics[0]?.line ?? 0) + 2),
35
+ onSuccess: (parsed) => Result.match(decodeReleases(parsed ?? {}), {
36
+ onFailure: (error) => fail(`front matter must map package names to patch, minor, major or none: ${error.message}`, 2),
37
+ onSuccess: (releases) => Result.succeed(ParsedChangeset.make({
38
+ releases: new Map(Object.entries(releases)),
39
+ summary
40
+ }))
41
+ })
42
+ });
43
+ };
44
+ /**
45
+ * Parsing a changeset markdown file: YAML front matter mapping package names
46
+ * to release types, then the summary.
47
+ *
48
+ * @public
49
+ */
50
+ var ChangesetFile = class ChangesetFile {
51
+ /**
52
+ * Parse a changeset synchronously.
53
+ *
54
+ * @param text - The file contents.
55
+ * @returns A `Result` of the parsed changeset or a {@link ChangesetParseError}.
56
+ */
57
+ static parseSync(text) {
58
+ return parseText(text);
59
+ }
60
+ /**
61
+ * Parse a changeset; the `Effect` form of {@link ChangesetFile.parseSync}.
62
+ *
63
+ * @param text - The file contents.
64
+ */
65
+ static parse = Effect.fn("ChangesetFile.parse")((text) => Effect.fromResult(ChangesetFile.parseSync(text)));
66
+ };
67
+
68
+ export { ChangesetFile, ParsedChangeset };
@@ -0,0 +1,108 @@
1
+ import { ContentStructure } from "./internal/lint/content-structure.js";
2
+ import { DependencyTableFormat } from "./internal/lint/dependency-table-format.js";
3
+ import { HeadingHierarchy } from "./internal/lint/heading-hierarchy.js";
4
+ import { RequiredSections } from "./internal/lint/required-sections.js";
5
+ import { UncategorizedContent } from "./internal/lint/uncategorized-content.js";
6
+ import { MarkdownLint } from "@effected/markdown-lint";
7
+
8
+ // src/ChangesetLint.ts
9
+ /**
10
+ * The changeset style rules CSH001 to CSH005, each defined once as a
11
+ * `LintRule` over `@effected/markdown` trees, so one definition runs in
12
+ * `MarkdownLint` and, through `MarkdownlintAdapter`, in markdownlint and
13
+ * markdownlint-cli2.
14
+ *
15
+ * @remarks
16
+ * The rules check a changeset's body, whatever its front matter says:
17
+ *
18
+ * - `CSH001` `changeset-heading-hierarchy`: no `h1`, and no heading that
19
+ * skips a level.
20
+ * - `CSH002` `changeset-required-sections`: every `h2` names one of the
21
+ * thirteen categories (`Breaking Changes`, `Features`, `Bug Fixes`,
22
+ * `Performance`, `Documentation`, `Refactoring`, `Tests`, `Build System`,
23
+ * `CI`, `Dependencies`, `Maintenance`, `Reverts`, `Other`), ignoring case.
24
+ * - `CSH003` `changeset-content-structure`: no empty section, no code fence
25
+ * without a language, no empty list item.
26
+ * - `CSH004` `changeset-uncategorized-content`: no content before the first
27
+ * `h2`.
28
+ * - `CSH005` `changeset-dependency-table-format`: a `Dependencies` section
29
+ * holds a `Dependency | Type | Action | From | To` table whose cells are
30
+ * valid.
31
+ *
32
+ * Messages, lines and columns are savvy-web/systems' own, which wrote the
33
+ * rules. systems implements each rule twice, and where its two engines
34
+ * disagree these follow its markdownlint engine, the one markdownlint-cli2
35
+ * and a pre-commit hook run. That engine reads micromark tokens, so:
36
+ *
37
+ * - Only top-level blocks are sections: a heading, list or code block
38
+ * inside a list item or a block quote is not checked by CSH001, CSH002 or
39
+ * CSH003.
40
+ * - A heading or table cell is compared as written, with backslash escapes
41
+ * resolved and inline formatting kept: a heading of `Features` in a code
42
+ * span and `## *Bug Fixes*` are unknown sections, and a `From` cell of
43
+ * `1.0.0` in a code span is not a version. That verdict looks stricter than an author
44
+ * expects, but it is what markdownlint enforces.
45
+ * - CSH003 checks fenced code only, since an indented block has no fence to
46
+ * name a language on, and calls a list item empty unless it holds a
47
+ * paragraph: an item of only an HTML comment, a nested list or a heading is
48
+ * empty, and an item of only an image is not.
49
+ * - A table row shorter than the header has too few columns. The parsed tree
50
+ * pads it with empty cells, which are not counted.
51
+ * - A setext heading directly under a link reference definition is
52
+ * reported on the definition's line, where micromark starts its token.
53
+ * - A heading over several lines is named on one line, as markdownlint
54
+ * writes every detail.
55
+ *
56
+ * One difference remains, and it is the parser's, not a rule's: after an
57
+ * indented code block, markdownlint's micromark reads a bare `- ` line as a
58
+ * paragraph, where CommonMark reads an empty list item, so CSH003 reports an
59
+ * empty item there and markdownlint does not.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { MarkdownlintAdapter } from "@effected/markdown-lint";
64
+ * import { ChangesetLint } from "@effected/changesets/lint";
65
+ *
66
+ * // .markdownlint-cli2.mjs
67
+ * export default { customRules: MarkdownlintAdapter.rules(ChangesetLint.rules) };
68
+ * ```
69
+ *
70
+ * @public
71
+ */
72
+ var ChangesetLint = class ChangesetLint {
73
+ /** CSH001: headings start at `h2` and never skip a level. */
74
+ static headingHierarchy = HeadingHierarchy;
75
+ /** CSH002: every `h2` names a changeset category. */
76
+ static requiredSections = RequiredSections;
77
+ /** CSH003: sections have content, fences a language, list items text. */
78
+ static contentStructure = ContentStructure;
79
+ /** CSH004: nothing comes before the first category heading. */
80
+ static uncategorizedContent = UncategorizedContent;
81
+ /** CSH005: a `Dependencies` section holds a valid dependency table. */
82
+ static dependencyTableFormat = DependencyTableFormat;
83
+ /**
84
+ * The five rules in the order savvy-web/systems' linter runs them, CSH005
85
+ * before CSH004, which is the order `MarkdownLint` reports their findings
86
+ * in.
87
+ */
88
+ static rules = [
89
+ HeadingHierarchy,
90
+ RequiredSections,
91
+ ContentStructure,
92
+ DependencyTableFormat,
93
+ UncategorizedContent
94
+ ];
95
+ /**
96
+ * Lint one changeset file's text with all five rules: `MarkdownLint.lint`
97
+ * over {@link ChangesetLint.rules}. Line numbers count the whole file, front
98
+ * matter included.
99
+ *
100
+ * @param source - The changeset file's text.
101
+ * @param options - Parse options, passed to `MarkdownLint.lint`.
102
+ */
103
+ static lint(source, options) {
104
+ return MarkdownLint.lint(source, ChangesetLint.rules, options);
105
+ }
106
+ };
107
+
108
+ export { ChangesetLint };
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 C. Spencer Beggs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,210 @@
1
+ import { ReleaseType } from "./BumpType.js";
2
+ import { ChangesetFile } from "./ChangesetFile.js";
3
+ import { ChangesetParseError } from "./errors.js";
4
+ import { Effect, FileSystem, Path, PlatformError, Result, Schema } from "effect";
5
+ import { readFileSync, readdirSync } from "node:fs";
6
+
7
+ // src/PendingChangesets.ts
8
+ /**
9
+ * One pending changeset read from `.changeset/`.
10
+ *
11
+ * @public
12
+ */
13
+ var PendingChangeset = class extends Schema.Class("PendingChangeset")({
14
+ /**
15
+ * The file name, relative to `.changeset/`: `pre/<name>.md` for a
16
+ * changeset an earlier pre-release consumed.
17
+ */
18
+ file: Schema.String,
19
+ /** Package name to requested release type, in file order. */
20
+ releases: Schema.ReadonlyMap(Schema.String, ReleaseType),
21
+ /** The markdown after the front matter. */
22
+ summary: Schema.String
23
+ }) {};
24
+ /** The directory, under `.changeset/`, holding the changesets a pre-release consumed. */
25
+ const PRE = "pre";
26
+ const CONTEXT_FILES = /* @__PURE__ */ new Set([
27
+ "AGENTS.md",
28
+ "CLAUDE.md",
29
+ "GEMINI.md"
30
+ ]);
31
+ const isChangesetName = (name) => name.endsWith(".md") && !name.startsWith(".") && !/^README\.md$/i.test(name) && !CONTEXT_FILES.has(name);
32
+ const selectNames = (names) => names.filter(isChangesetName).sort();
33
+ const withFile = (file, error) => new ChangesetParseError({
34
+ reason: error.reason,
35
+ file,
36
+ ...error.line === void 0 ? {} : { line: error.line }
37
+ });
38
+ const toPending = (file, text) => Result.match(ChangesetFile.parseSync(text), {
39
+ onFailure: (error) => Result.fail(withFile(file, error)),
40
+ onSuccess: (parsed) => Result.succeed(PendingChangeset.make({
41
+ file,
42
+ releases: parsed.releases,
43
+ summary: parsed.summary
44
+ }))
45
+ });
46
+ const nodeErrorTag = (code) => {
47
+ switch (code) {
48
+ case "ENOENT": return "NotFound";
49
+ case "EACCES":
50
+ case "EPERM": return "PermissionDenied";
51
+ case "EISDIR":
52
+ case "ENOTDIR": return "BadResource";
53
+ default: return "Unknown";
54
+ }
55
+ };
56
+ const toPlatformError = (method, path, cause) => PlatformError.systemError({
57
+ _tag: nodeErrorTag(cause?.code),
58
+ module: "PendingChangesets",
59
+ method,
60
+ pathOrDescriptor: path,
61
+ cause
62
+ });
63
+ const isNotFound = (error) => error.reason._tag === "NotFound";
64
+ /** The changeset files under `.changeset/`, then those under `.changeset/pre/` as `pre/<name>.md`. */
65
+ const listFiles = Effect.fnUntraced(function* (dir) {
66
+ const fs = yield* FileSystem.FileSystem;
67
+ const path = yield* Path.Path;
68
+ const list = (directory) => fs.readDirectory(directory).pipe(Effect.catch((error) => isNotFound(error) ? Effect.succeed([]) : Effect.fail(error)));
69
+ const names = selectNames(yield* list(dir));
70
+ const consumed = selectNames(yield* list(path.join(dir, PRE)));
71
+ return [...names, ...consumed.map((name) => `${PRE}/${name}`)];
72
+ });
73
+ /** {@link listFiles} over `node:fs`; `dir` is the `.changeset` directory with no trailing separator. */
74
+ const listFilesSync = (dir) => {
75
+ const list = (directory) => {
76
+ try {
77
+ return Result.succeed(selectNames(readdirSync(directory)));
78
+ } catch (cause) {
79
+ const error = toPlatformError("readDirectory", directory, cause);
80
+ return isNotFound(error) ? Result.succeed([]) : Result.fail(error);
81
+ }
82
+ };
83
+ const names = list(dir);
84
+ if (Result.isFailure(names)) return Result.fail(names.failure);
85
+ const consumed = list(`${dir}/${PRE}`);
86
+ if (Result.isFailure(consumed)) return Result.fail(consumed.failure);
87
+ return Result.succeed([...names.success, ...consumed.success.map((name) => `${PRE}/${name}`)]);
88
+ };
89
+ /** `<root>/.changeset`, trimming any run of trailing separators off `root`. */
90
+ const changesetDirSync = (root) => {
91
+ let end = root.length;
92
+ while (end > 0 && (root[end - 1] === "/" || root[end - 1] === "\\")) end--;
93
+ return `${root.slice(0, end)}/.changeset`;
94
+ };
95
+ /** Read and parse one changeset file over `node:fs`. */
96
+ const readOneSync = (dir, file) => {
97
+ let text;
98
+ try {
99
+ text = readFileSync(`${dir}/${file}`, "utf8");
100
+ } catch (cause) {
101
+ return Result.fail(toPlatformError("readFile", `${dir}/${file}`, cause));
102
+ }
103
+ return toPending(file, text);
104
+ };
105
+ /**
106
+ * Reading the pending changesets under a repository's `.changeset/`
107
+ * directory.
108
+ *
109
+ * @public
110
+ */
111
+ var PendingChangesets = class {
112
+ /**
113
+ * Read every pending changeset under `<root>/.changeset/`, ordered by file
114
+ * name, then those under `<root>/.changeset/pre/`, which a pre-release
115
+ * keeps after consuming them, as `pre/<name>.md`. A readme in any case,
116
+ * `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, dotfiles and non-`.md` files are
117
+ * skipped; a missing directory answers `[]`.
118
+ *
119
+ * The read is all or nothing: the first file that does not read or parse
120
+ * fails it. {@link PendingChangesets.readSettled} reads the same files and
121
+ * skips a bad one instead.
122
+ *
123
+ * @param root - The repository root.
124
+ */
125
+ static read = Effect.fn("PendingChangesets.read")(function* (root) {
126
+ const fs = yield* FileSystem.FileSystem;
127
+ const path = yield* Path.Path;
128
+ const dir = path.join(root, ".changeset");
129
+ const files = yield* listFiles(dir);
130
+ return yield* Effect.forEach(files, (file) => fs.readFileString(path.join(dir, file)).pipe(Effect.flatMap((text) => Effect.fromResult(toPending(file, text)))));
131
+ });
132
+ /**
133
+ * Read the same files as {@link PendingChangesets.read}, in the same order,
134
+ * but skip a file that does not read or parse and report it in `failures`
135
+ * rather than failing the whole read. For a best-effort view of pending
136
+ * bumps; a versioning tool wants the strict {@link PendingChangesets.read}.
137
+ *
138
+ * Listing `.changeset/` or `.changeset/pre/` still fails the effect with a
139
+ * `PlatformError`, since then no file is known to be missing; a missing
140
+ * directory answers no changesets and no failures.
141
+ *
142
+ * @param root - The repository root.
143
+ */
144
+ static readSettled = Effect.fn("PendingChangesets.readSettled")(function* (root) {
145
+ const fs = yield* FileSystem.FileSystem;
146
+ const path = yield* Path.Path;
147
+ const dir = path.join(root, ".changeset");
148
+ const files = yield* listFiles(dir);
149
+ const changesets = [];
150
+ const failures = [];
151
+ for (const file of files) {
152
+ const result = yield* fs.readFileString(path.join(dir, file)).pipe(Effect.flatMap((text) => Effect.fromResult(toPending(file, text))), Effect.result);
153
+ if (Result.isSuccess(result)) changesets.push(result.success);
154
+ else failures.push({
155
+ file,
156
+ error: result.failure
157
+ });
158
+ }
159
+ return {
160
+ changesets,
161
+ failures
162
+ };
163
+ });
164
+ /**
165
+ * Synchronous {@link PendingChangesets.read} over `node:fs`, for callers
166
+ * that run before any Effect runtime exists.
167
+ *
168
+ * @param root - The repository root.
169
+ */
170
+ static readSync(root) {
171
+ const dir = changesetDirSync(root);
172
+ const files = listFilesSync(dir);
173
+ if (Result.isFailure(files)) return Result.fail(files.failure);
174
+ const pending = [];
175
+ for (const file of files.success) {
176
+ const parsed = readOneSync(dir, file);
177
+ if (Result.isFailure(parsed)) return Result.fail(parsed.failure);
178
+ pending.push(parsed.success);
179
+ }
180
+ return Result.succeed(pending);
181
+ }
182
+ /**
183
+ * Synchronous {@link PendingChangesets.readSettled} over `node:fs`, for
184
+ * callers that run before any Effect runtime exists. Fails only when a
185
+ * directory cannot be listed.
186
+ *
187
+ * @param root - The repository root.
188
+ */
189
+ static readSettledSync(root) {
190
+ const dir = changesetDirSync(root);
191
+ const files = listFilesSync(dir);
192
+ if (Result.isFailure(files)) return Result.fail(files.failure);
193
+ const changesets = [];
194
+ const failures = [];
195
+ for (const file of files.success) {
196
+ const parsed = readOneSync(dir, file);
197
+ if (Result.isSuccess(parsed)) changesets.push(parsed.success);
198
+ else failures.push({
199
+ file,
200
+ error: parsed.failure
201
+ });
202
+ }
203
+ return Result.succeed({
204
+ changesets,
205
+ failures
206
+ });
207
+ }
208
+ };
209
+
210
+ export { PendingChangeset, PendingChangesets };
package/PreState.js ADDED
@@ -0,0 +1,54 @@
1
+ import { ChangesetConfigError } from "./errors.js";
2
+ import { Effect, FileSystem, Option, Path, Schema } from "effect";
3
+
4
+ // src/PreState.ts
5
+ /**
6
+ * The decoded `.changeset/pre.json`: the repository is in pre-release mode
7
+ * (`changeset pre enter <tag>`), or leaving it (`changeset pre exit`).
8
+ *
9
+ * @remarks
10
+ * In `pre` mode a release plan appends `-<tag>.<n>` to every bumped version
11
+ * and leaves out the changesets under `.changeset/pre/`, which an earlier
12
+ * pre-release already consumed. In `exit` mode those changesets count again,
13
+ * no suffix is appended, and every package still on a numbered prerelease
14
+ * bumps at least `patch`. The file's other keys are not kept.
15
+ *
16
+ * @public
17
+ */
18
+ var PreState = class PreState extends Schema.Class("PreState")({
19
+ /** `pre` while pre-releasing, `exit` once `changeset pre exit` has run. */
20
+ mode: Schema.Literals(["pre", "exit"]),
21
+ /** The prerelease tag, such as `next` or `beta`. */
22
+ tag: Schema.String,
23
+ /**
24
+ * The changesets an earlier pre-release consumed, by id (the file name
25
+ * without `.md`), as the older `pre.json` layout lists them. The current
26
+ * layout moves those files into `.changeset/pre/` instead.
27
+ */
28
+ changesets: Schema.optionalKey(Schema.Array(Schema.String))
29
+ }) {
30
+ /**
31
+ * Read `<root>/.changeset/pre.json`: `Option.none()` when the repository
32
+ * is not in pre-release mode.
33
+ *
34
+ * Fails with {@link ChangesetConfigError} when the file is not JSON or does
35
+ * not match the shape. Unlike `@changesets/pre`, it never rewrites an
36
+ * older-layout file or moves a changeset.
37
+ *
38
+ * @param root - The repository root.
39
+ */
40
+ static read = Effect.fn("PreState.read")(function* (root) {
41
+ const fs = yield* FileSystem.FileSystem;
42
+ const path = yield* Path.Path;
43
+ const text = yield* fs.readFileString(path.join(root, ".changeset", "pre.json")).pipe(Effect.map(Option.some), Effect.catch((error) => error.reason._tag === "NotFound" ? Effect.succeed(Option.none()) : Effect.fail(error)));
44
+ if (Option.isNone(text)) return Option.none();
45
+ const json = yield* Effect.try({
46
+ try: () => JSON.parse(text.value),
47
+ catch: (cause) => new ChangesetConfigError({ reason: `pre.json is not valid JSON: ${cause.message}` })
48
+ });
49
+ const decoded = yield* Schema.decodeUnknownEffect(PreState)(json).pipe(Effect.mapError((error) => new ChangesetConfigError({ reason: `pre.json: ${error.message}` })));
50
+ return Option.some(decoded);
51
+ });
52
+ };
53
+
54
+ export { PreState };