@effected/changesets 0.1.0 → 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.
@@ -61,6 +61,47 @@ const toPlatformError = (method, path, cause) => PlatformError.systemError({
61
61
  cause
62
62
  });
63
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
+ };
64
105
  /**
65
106
  * Reading the pending changesets under a repository's `.changeset/`
66
107
  * directory.
@@ -75,54 +116,95 @@ var PendingChangesets = class {
75
116
  * `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, dotfiles and non-`.md` files are
76
117
  * skipped; a missing directory answers `[]`.
77
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
+ *
78
123
  * @param root - The repository root.
79
124
  */
80
125
  static read = Effect.fn("PendingChangesets.read")(function* (root) {
81
126
  const fs = yield* FileSystem.FileSystem;
82
127
  const path = yield* Path.Path;
83
128
  const dir = path.join(root, ".changeset");
84
- const list = (directory) => fs.readDirectory(directory).pipe(Effect.catch((error) => isNotFound(error) ? Effect.succeed([]) : Effect.fail(error)));
85
- const names = selectNames(yield* list(dir));
86
- const consumed = selectNames(yield* list(path.join(dir, PRE)));
87
- const files = [...names, ...consumed.map((name) => `${PRE}/${name}`)];
129
+ const files = yield* listFiles(dir);
88
130
  return yield* Effect.forEach(files, (file) => fs.readFileString(path.join(dir, file)).pipe(Effect.flatMap((text) => Effect.fromResult(toPending(file, text)))));
89
131
  });
90
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
+ /**
91
165
  * Synchronous {@link PendingChangesets.read} over `node:fs`, for callers
92
166
  * that run before any Effect runtime exists.
93
167
  *
94
168
  * @param root - The repository root.
95
169
  */
96
170
  static readSync(root) {
97
- let end = root.length;
98
- while (end > 0 && (root[end - 1] === "/" || root[end - 1] === "\\")) end--;
99
- const dir = `${root.slice(0, end)}/.changeset`;
100
- const list = (directory) => {
101
- try {
102
- return Result.succeed(selectNames(readdirSync(directory)));
103
- } catch (cause) {
104
- const error = toPlatformError("readDirectory", directory, cause);
105
- return isNotFound(error) ? Result.succeed([]) : Result.fail(error);
106
- }
107
- };
108
- const names = list(dir);
109
- if (Result.isFailure(names)) return Result.fail(names.failure);
110
- const consumed = list(`${dir}/${PRE}`);
111
- if (Result.isFailure(consumed)) return Result.fail(consumed.failure);
171
+ const dir = changesetDirSync(root);
172
+ const files = listFilesSync(dir);
173
+ if (Result.isFailure(files)) return Result.fail(files.failure);
112
174
  const pending = [];
113
- for (const file of [...names.success, ...consumed.success.map((name) => `${PRE}/${name}`)]) {
114
- let text;
115
- try {
116
- text = readFileSync(`${dir}/${file}`, "utf8");
117
- } catch (cause) {
118
- return Result.fail(toPlatformError("readFile", `${dir}/${file}`, cause));
119
- }
120
- const parsed = toPending(file, text);
175
+ for (const file of files.success) {
176
+ const parsed = readOneSync(dir, file);
121
177
  if (Result.isFailure(parsed)) return Result.fail(parsed.failure);
122
178
  pending.push(parsed.success);
123
179
  }
124
180
  return Result.succeed(pending);
125
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
+ }
126
208
  };
127
209
 
128
210
  export { PendingChangeset, PendingChangesets };
package/index.d.ts CHANGED
@@ -190,6 +190,30 @@ declare const PendingChangeset_base: Schema.Class<PendingChangeset, Schema.Struc
190
190
  * @public
191
191
  */
192
192
  export declare class PendingChangeset extends PendingChangeset_base {}
193
+ /**
194
+ * One changeset file {@link PendingChangesets.readSettled} could not read or
195
+ * parse.
196
+ *
197
+ * @public
198
+ */
199
+ interface PendingChangesetFailure {
200
+ /** The file name, relative to `.changeset/`, as a {@link PendingChangeset} names it. */
201
+ readonly file: string;
202
+ /** Why the file was skipped: it would not parse, or it would not read. */
203
+ readonly error: ChangesetParseError | PlatformError.PlatformError;
204
+ }
205
+ /**
206
+ * Every pending changeset that parsed, and every one that did not, from
207
+ * {@link PendingChangesets.readSettled}.
208
+ *
209
+ * @public
210
+ */
211
+ interface SettledChangesets {
212
+ /** The changesets that parsed, in the order {@link PendingChangesets.read} returns them. */
213
+ readonly changesets: ReadonlyArray<PendingChangeset>;
214
+ /** The files that did not, in the same order. */
215
+ readonly failures: ReadonlyArray<PendingChangesetFailure>;
216
+ }
193
217
  /**
194
218
  * Reading the pending changesets under a repository's `.changeset/`
195
219
  * directory.
@@ -204,9 +228,26 @@ export declare class PendingChangesets {
204
228
  * `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, dotfiles and non-`.md` files are
205
229
  * skipped; a missing directory answers `[]`.
206
230
  *
231
+ * The read is all or nothing: the first file that does not read or parse
232
+ * fails it. {@link PendingChangesets.readSettled} reads the same files and
233
+ * skips a bad one instead.
234
+ *
207
235
  * @param root - The repository root.
208
236
  */
209
237
  static readonly read: (root: string) => Effect.Effect<PendingChangeset[], ChangesetParseError | PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
238
+ /**
239
+ * Read the same files as {@link PendingChangesets.read}, in the same order,
240
+ * but skip a file that does not read or parse and report it in `failures`
241
+ * rather than failing the whole read. For a best-effort view of pending
242
+ * bumps; a versioning tool wants the strict {@link PendingChangesets.read}.
243
+ *
244
+ * Listing `.changeset/` or `.changeset/pre/` still fails the effect with a
245
+ * `PlatformError`, since then no file is known to be missing; a missing
246
+ * directory answers no changesets and no failures.
247
+ *
248
+ * @param root - The repository root.
249
+ */
250
+ static readonly readSettled: (root: string) => Effect.Effect<SettledChangesets, PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
210
251
  /**
211
252
  * Synchronous {@link PendingChangesets.read} over `node:fs`, for callers
212
253
  * that run before any Effect runtime exists.
@@ -214,6 +255,14 @@ export declare class PendingChangesets {
214
255
  * @param root - The repository root.
215
256
  */
216
257
  static readSync(root: string): Result.Result<ReadonlyArray<PendingChangeset>, ChangesetParseError | PlatformError.PlatformError>;
258
+ /**
259
+ * Synchronous {@link PendingChangesets.readSettled} over `node:fs`, for
260
+ * callers that run before any Effect runtime exists. Fails only when a
261
+ * directory cannot be listed.
262
+ *
263
+ * @param root - The repository root.
264
+ */
265
+ static readSettledSync(root: string): Result.Result<SettledChangesets, PlatformError.PlatformError>;
217
266
  }
218
267
  declare const PreState_base: Schema.Class<PreState, Schema.Struct<{
219
268
  /** `pre` while pre-releasing, `exit` once `changeset pre exit` has run. */
@@ -430,5 +479,5 @@ export declare class ReleasePlan extends ReleasePlan_base {
430
479
  */
431
480
  static readonly read: (root: string) => Effect.Effect<ReleasePlan, ChangesetConfigError | ChangesetParseError | InvalidVersionError | PlatformError.PlatformError | UnknownPackageError | WorkspaceDiscoveryError | import("@effected/workspaces").WorkspacePatternError | WorkspaceRootNotFoundError, FileSystem.FileSystem | Path.Path | WorkspaceDiscovery>;
432
481
  }
433
- export {};
482
+ export type { PendingChangesetFailure, SettledChangesets };
434
483
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/changesets",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "Changeset files, `.changeset/config.json` and the release plan as Effect schemas and pure functions.",
6
6
  "keywords": [
@@ -44,12 +44,12 @@
44
44
  "dependencies": {
45
45
  "@effected/glob": "^0.20.0",
46
46
  "@effected/semver": "^0.22.0",
47
- "@effected/workspaces": "^0.44.0",
47
+ "@effected/workspaces": "^0.44.1",
48
48
  "@effected/yaml": "^0.29.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@effected/markdown": "^0.28.0",
52
- "@effected/markdown-lint": "^0.1.0",
52
+ "@effected/markdown-lint": "^0.1.1",
53
53
  "effect": "~4.1.0"
54
54
  },
55
55
  "peerDependenciesMeta": {