@effected/changesets 0.1.0 → 0.3.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/Changelog.js +414 -0
- package/ChangesetConfig.js +71 -13
- package/ChangesetFile.js +2 -2
- package/ChangesetLint.js +142 -77
- package/PendingChangesets.js +120 -29
- package/README.md +27 -13
- package/ReleaseEdits.js +226 -0
- package/ReleasePlan.js +345 -96
- package/errors.js +56 -1
- package/index.d.ts +922 -59
- package/index.js +5 -3
- package/internal/causeMessage.js +57 -0
- package/internal/frontMatter.js +83 -0
- package/internal/versions.js +103 -0
- package/lint.d.ts +71 -65
- package/package.json +4 -4
- package/internal/lint/content-structure.js +0 -37
- package/internal/lint/dependency-table-format.js +0 -117
- package/internal/lint/docs.js +0 -72
- package/internal/lint/heading-hierarchy.js +0 -32
- package/internal/lint/required-sections.js +0 -23
- package/internal/lint/uncategorized-content.js +0 -22
package/Changelog.js
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { ChangesetConfigError, MissingPackageError } from "./errors.js";
|
|
2
|
+
import { causeMessage } from "./internal/causeMessage.js";
|
|
3
|
+
import { WORKSPACE, parseRange, shouldUpdate } from "./internal/versions.js";
|
|
4
|
+
import { Effect, Option, Schema } from "effect";
|
|
5
|
+
|
|
6
|
+
// src/Changelog.ts
|
|
7
|
+
/**
|
|
8
|
+
* A bump as a changelog module receives it: `@changesets/types`'
|
|
9
|
+
* `VersionType`.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
const VersionType = Schema.Literals([
|
|
14
|
+
"major",
|
|
15
|
+
"minor",
|
|
16
|
+
"patch",
|
|
17
|
+
"none"
|
|
18
|
+
]).annotate({
|
|
19
|
+
identifier: "VersionType",
|
|
20
|
+
description: "A bump as a changelog module receives it"
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* A changeset as a changelog module receives it: `@changesets/types`'
|
|
24
|
+
* `NewChangeset`. `id` is the file name without `.md` (`pre/<name>` for one
|
|
25
|
+
* under `.changeset/pre/`), and `summary` is the text after the front matter,
|
|
26
|
+
* trimmed.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
const NewChangeset = Schema.Struct({
|
|
31
|
+
summary: Schema.mutableKey(Schema.String),
|
|
32
|
+
releases: Schema.mutableKey(Schema.mutable(Schema.Array(Schema.Struct({
|
|
33
|
+
name: Schema.mutableKey(Schema.String),
|
|
34
|
+
type: Schema.mutableKey(VersionType)
|
|
35
|
+
})))),
|
|
36
|
+
id: Schema.mutableKey(Schema.String)
|
|
37
|
+
}).annotate({
|
|
38
|
+
identifier: "NewChangeset",
|
|
39
|
+
description: "A changeset as a changelog module receives it"
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* {@link (NewChangeset:variable)} with the commit that added the file, when the caller
|
|
43
|
+
* supplied one: `@changesets/types`' `NewChangesetWithCommit`.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
const NewChangesetWithCommit = Schema.Struct({
|
|
48
|
+
...NewChangeset.fields,
|
|
49
|
+
commit: Schema.mutableKey(Schema.optionalKey(Schema.String))
|
|
50
|
+
}).annotate({
|
|
51
|
+
identifier: "NewChangesetWithCommit",
|
|
52
|
+
description: "A changeset as a changelog module receives it, with the commit that added it"
|
|
53
|
+
});
|
|
54
|
+
const releaseFields = {
|
|
55
|
+
name: Schema.mutableKey(Schema.String),
|
|
56
|
+
changesets: Schema.mutableKey(Schema.mutable(Schema.Array(Schema.String)))
|
|
57
|
+
};
|
|
58
|
+
const bumpedFields = {
|
|
59
|
+
...releaseFields,
|
|
60
|
+
oldVersion: Schema.mutableKey(Schema.String),
|
|
61
|
+
newVersion: Schema.mutableKey(Schema.String)
|
|
62
|
+
};
|
|
63
|
+
const noneFields = {
|
|
64
|
+
...releaseFields,
|
|
65
|
+
type: Schema.mutableKey(Schema.Literal("none")),
|
|
66
|
+
oldVersion: Schema.mutableKey(Schema.UndefinedOr(Schema.String)),
|
|
67
|
+
newVersion: Schema.mutableKey(Schema.UndefinedOr(Schema.String))
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* A planned release as a changelog module receives one:
|
|
71
|
+
* `@changesets/types`' `ComprehensiveRelease`. `changesets` holds ids, as
|
|
72
|
+
* {@link (NewChangeset:variable)} does. Only a `none` entry may lack its versions.
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
const ComprehensiveRelease = Schema.Union([
|
|
77
|
+
Schema.Struct({
|
|
78
|
+
...bumpedFields,
|
|
79
|
+
type: Schema.mutableKey(Schema.Literal("major"))
|
|
80
|
+
}),
|
|
81
|
+
Schema.Struct({
|
|
82
|
+
...bumpedFields,
|
|
83
|
+
type: Schema.mutableKey(Schema.Literal("minor"))
|
|
84
|
+
}),
|
|
85
|
+
Schema.Struct({
|
|
86
|
+
...bumpedFields,
|
|
87
|
+
type: Schema.mutableKey(Schema.Literal("patch"))
|
|
88
|
+
}),
|
|
89
|
+
Schema.Struct(noneFields)
|
|
90
|
+
]).annotate({
|
|
91
|
+
identifier: "ComprehensiveRelease",
|
|
92
|
+
description: "A planned release as a changelog module receives one"
|
|
93
|
+
});
|
|
94
|
+
const dependencyMap = Schema.mutableKey(Schema.optionalKey(Schema.Record(Schema.String, Schema.String)));
|
|
95
|
+
/**
|
|
96
|
+
* A manifest as a changelog module receives one: `@changesets/types`'
|
|
97
|
+
* `PackageJSON`. It is open: a key it does not name decodes and is kept,
|
|
98
|
+
* because a manifest carries far more than these, and a module may read any
|
|
99
|
+
* of them. `publishConfig` is open the same way for its `<scope>:registry`
|
|
100
|
+
* keys.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
const PackageJSON = Schema.StructWithRest(Schema.Struct({
|
|
105
|
+
name: Schema.mutableKey(Schema.String),
|
|
106
|
+
version: Schema.mutableKey(Schema.String),
|
|
107
|
+
dependencies: dependencyMap,
|
|
108
|
+
peerDependencies: dependencyMap,
|
|
109
|
+
devDependencies: dependencyMap,
|
|
110
|
+
optionalDependencies: dependencyMap,
|
|
111
|
+
resolutions: dependencyMap,
|
|
112
|
+
private: Schema.mutableKey(Schema.optionalKey(Schema.Boolean)),
|
|
113
|
+
publishConfig: Schema.mutableKey(Schema.optionalKey(Schema.StructWithRest(Schema.Struct({
|
|
114
|
+
access: Schema.mutableKey(Schema.optionalKey(Schema.Literals(["public", "restricted"]))),
|
|
115
|
+
directory: Schema.mutableKey(Schema.optionalKey(Schema.String)),
|
|
116
|
+
registry: Schema.mutableKey(Schema.optionalKey(Schema.String))
|
|
117
|
+
}), [Schema.Record(Schema.TemplateLiteral([Schema.String, ":registry"]), Schema.String)])))
|
|
118
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]).annotate({
|
|
119
|
+
identifier: "PackageJSON",
|
|
120
|
+
description: "A manifest as a changelog module receives one"
|
|
121
|
+
});
|
|
122
|
+
const withPackage = {
|
|
123
|
+
packageJson: Schema.mutableKey(PackageJSON),
|
|
124
|
+
dir: Schema.mutableKey(Schema.String),
|
|
125
|
+
relativeDir: Schema.mutableKey(Schema.optionalKey(Schema.String))
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* A release with its package, as `getDependencyReleaseLine` receives the
|
|
129
|
+
* dependencies a package's release updated: `@changesets/types`'
|
|
130
|
+
* `ModCompWithPackage`. `dir` is the package's absolute directory.
|
|
131
|
+
*
|
|
132
|
+
* `relativeDir`, the directory relative to the workspace root, is optional
|
|
133
|
+
* here and absent from `@changesets/types`' type, but `apply-release-plan`
|
|
134
|
+
* passes it and so does {@link Changelog.entry}, so it is modelled and a
|
|
135
|
+
* decode keeps it. An optional extra key leaves the two types mutually
|
|
136
|
+
* assignable. Other unknown keys are dropped: this schema cannot be open the
|
|
137
|
+
* way {@link (PackageJSON:variable)} is, because `@changesets/types` declares these
|
|
138
|
+
* members as interfaces, which are not assignable to an index signature.
|
|
139
|
+
*
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
const ModCompWithPackage = Schema.Union([
|
|
143
|
+
Schema.Struct({
|
|
144
|
+
...bumpedFields,
|
|
145
|
+
type: Schema.mutableKey(Schema.Literal("major")),
|
|
146
|
+
...withPackage
|
|
147
|
+
}),
|
|
148
|
+
Schema.Struct({
|
|
149
|
+
...bumpedFields,
|
|
150
|
+
type: Schema.mutableKey(Schema.Literal("minor")),
|
|
151
|
+
...withPackage
|
|
152
|
+
}),
|
|
153
|
+
Schema.Struct({
|
|
154
|
+
...bumpedFields,
|
|
155
|
+
type: Schema.mutableKey(Schema.Literal("patch")),
|
|
156
|
+
...withPackage
|
|
157
|
+
}),
|
|
158
|
+
Schema.Struct({
|
|
159
|
+
...noneFields,
|
|
160
|
+
...withPackage
|
|
161
|
+
})
|
|
162
|
+
]).annotate({
|
|
163
|
+
identifier: "ModCompWithPackage",
|
|
164
|
+
description: "A release with its package, as a changelog module receives one"
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* A changelog module's function threw or rejected while rendering a
|
|
168
|
+
* package's block.
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
var ChangelogError = class extends Schema.TaggedError()("ChangelogError", {
|
|
173
|
+
/** The package whose block was being rendered. */
|
|
174
|
+
packageName: Schema.String,
|
|
175
|
+
/** What the module threw. */
|
|
176
|
+
cause: Schema.Defect()
|
|
177
|
+
}) {
|
|
178
|
+
get message() {
|
|
179
|
+
const detail = causeMessage(this.cause);
|
|
180
|
+
return `The changelog functions failed for ${this.packageName}${detail === void 0 ? "" : `: ${detail}`}`;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const toNewChangeset = (changeset, commit) => ({
|
|
184
|
+
id: changeset.id,
|
|
185
|
+
summary: changeset.summary.trim(),
|
|
186
|
+
releases: [...changeset.releases].map(([name, type]) => ({
|
|
187
|
+
name,
|
|
188
|
+
type
|
|
189
|
+
})),
|
|
190
|
+
...commit === void 0 ? {} : { commit }
|
|
191
|
+
});
|
|
192
|
+
const nonEmpty = (map) => Object.keys(map).length > 0 ? { ...map } : void 0;
|
|
193
|
+
/**
|
|
194
|
+
* The manifest a module is handed: discovery's `manifestRecord`, the whole
|
|
195
|
+
* `package.json` as read, copied so a module that writes to it cannot reach
|
|
196
|
+
* the `WorkspacePackage`. A package built without a record (by hand, not by
|
|
197
|
+
* discovery) has nothing more than its typed fields, so it gets those.
|
|
198
|
+
*/
|
|
199
|
+
const toPackageJson = (pkg) => {
|
|
200
|
+
if (Object.keys(pkg.manifestRecord).length > 0) return structuredClone(pkg.manifestRecord);
|
|
201
|
+
const fields = {
|
|
202
|
+
name: pkg.name,
|
|
203
|
+
version: pkg.version ?? ""
|
|
204
|
+
};
|
|
205
|
+
for (const kind of [
|
|
206
|
+
"dependencies",
|
|
207
|
+
"devDependencies",
|
|
208
|
+
"peerDependencies",
|
|
209
|
+
"optionalDependencies"
|
|
210
|
+
]) {
|
|
211
|
+
const map = nonEmpty(pkg[kind]);
|
|
212
|
+
if (map !== void 0) fields[kind] = map;
|
|
213
|
+
}
|
|
214
|
+
if (pkg.private) fields.private = true;
|
|
215
|
+
if (pkg.publishConfig !== void 0) fields.publishConfig = { ...pkg.publishConfig };
|
|
216
|
+
return fields;
|
|
217
|
+
};
|
|
218
|
+
const toComprehensive = (release) => ({
|
|
219
|
+
name: release.name,
|
|
220
|
+
type: release.type,
|
|
221
|
+
changesets: [...release.changesets],
|
|
222
|
+
oldVersion: release.oldVersion,
|
|
223
|
+
newVersion: release.newVersion
|
|
224
|
+
});
|
|
225
|
+
const capitalize = (text) => `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
226
|
+
/** `apply-release-plan`'s `generateMarkdownForVersionType`. */
|
|
227
|
+
const section = (type, lines) => {
|
|
228
|
+
const kept = lines.filter((line) => Boolean(line));
|
|
229
|
+
if (kept.length === 0) return void 0;
|
|
230
|
+
let content = `### ${capitalize(type)} Changes`;
|
|
231
|
+
let newLines = 2;
|
|
232
|
+
for (const line of kept) {
|
|
233
|
+
newLines += line.match(/^\n*/)?.[0].length ?? 0;
|
|
234
|
+
content += "\n".repeat(Math.min(Math.max(newLines, 1), 2)) + line.trim();
|
|
235
|
+
newLines = line.match(/\n*$/)?.[0].length ?? 0;
|
|
236
|
+
}
|
|
237
|
+
return content;
|
|
238
|
+
};
|
|
239
|
+
const changelogOptionsOf = (options) => {
|
|
240
|
+
if (options.changelogOptions !== void 0) return Effect.succeed(options.changelogOptions);
|
|
241
|
+
const changelog = options.config.changelog;
|
|
242
|
+
if (typeof changelog !== "object") return Effect.succeed(null);
|
|
243
|
+
const value = changelog[1];
|
|
244
|
+
if (value === null) return Effect.succeed(null);
|
|
245
|
+
if (typeof value === "object") return Effect.succeed(value);
|
|
246
|
+
return Effect.fail(new ChangesetConfigError({ reason: "changelog options must be an object or null" }));
|
|
247
|
+
};
|
|
248
|
+
const unsafeOption = (config, key) => {
|
|
249
|
+
const options = config.extra.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH;
|
|
250
|
+
return typeof options === "object" && options !== null ? options[key] : void 0;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* CHANGELOG assembly for a {@link ReleasePlan}, matching
|
|
254
|
+
* `@changesets/apply-release-plan`.
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* This package never loads a changelog module. The caller resolves and
|
|
258
|
+
* imports the module `config.changelog` names (or any other) and passes its
|
|
259
|
+
* {@link ChangelogFunctions}; formatting the result (`changeset version`
|
|
260
|
+
* runs prettier or another formatter over it) and writing the file are the
|
|
261
|
+
* caller's too.
|
|
262
|
+
*
|
|
263
|
+
* Neither function reads `config.changelog` to decide whether to run:
|
|
264
|
+
* {@link Changelog.entry} renders whatever functions it is given. A caller
|
|
265
|
+
* whose config says `changelog: false` writes no changelog, as
|
|
266
|
+
* `changeset version` writes none, and so does not call it.
|
|
267
|
+
*
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
var Changelog = class {
|
|
271
|
+
/**
|
|
272
|
+
* Render `release`'s changelog block, the text `changeset version` inserts
|
|
273
|
+
* into its `CHANGELOG.md`: `Option.none()` for a `none` entry, which gets
|
|
274
|
+
* no block.
|
|
275
|
+
*
|
|
276
|
+
* As `apply-release-plan`'s `getChangelogEntry` does:
|
|
277
|
+
*
|
|
278
|
+
* - Each changeset in the plan naming the package with a real bump gets
|
|
279
|
+
* `getReleaseLine`, under that bump's heading, in the plan's changeset
|
|
280
|
+
* order.
|
|
281
|
+
* - `getDependencyReleaseLine` is called once, always, and its line goes
|
|
282
|
+
* last under `Patch Changes`. It gets the plan's releases (`none`
|
|
283
|
+
* entries included) that the package's `dependencies` (else
|
|
284
|
+
* `peerDependencies`) range would be updated for, by the rule
|
|
285
|
+
* {@link ReleasePlan.edits} applies, with a `workspace:` path counting
|
|
286
|
+
* when it points at the dependency, and the changesets behind them.
|
|
287
|
+
* - The block is `## <newVersion>` then `### Major Changes`,
|
|
288
|
+
* `### Minor Changes` and `### Patch Changes`, each only when it has a
|
|
289
|
+
* non-empty line, blank-line separated; a line's own leading and
|
|
290
|
+
* trailing newlines widen the gap to it, up to one blank line. With no
|
|
291
|
+
* lines at all the block is `## <newVersion>` and
|
|
292
|
+
* `No changes in this release.`
|
|
293
|
+
* - Every function is called before any is awaited, as the oracle calls
|
|
294
|
+
* them.
|
|
295
|
+
*
|
|
296
|
+
* A module's `packageJson` is the dependency's whole manifest as
|
|
297
|
+
* discovery read it (`WorkspacePackage.manifestRecord`), before this
|
|
298
|
+
* release's version, as the oracle passes it.
|
|
299
|
+
*
|
|
300
|
+
* Difference, ruled: a changeset with no commit in `options.commits` has
|
|
301
|
+
* no `commit` key, where the oracle sets it to `undefined`.
|
|
302
|
+
*
|
|
303
|
+
* Fails with {@link ChangelogError} when a function throws or rejects,
|
|
304
|
+
* with {@link MissingPackageError} when a release names a package
|
|
305
|
+
* `options.packages` lacks, and with {@link ChangesetConfigError} when
|
|
306
|
+
* the options element of `config.changelog` is neither an object nor
|
|
307
|
+
* `null` and no `changelogOptions` override is given.
|
|
308
|
+
*
|
|
309
|
+
* @param plan - The plan the release belongs to.
|
|
310
|
+
* @param release - The release whose block to render.
|
|
311
|
+
* @param functions - The changelog module.
|
|
312
|
+
* @param options - The workspace's packages, the config, the commits and
|
|
313
|
+
* the module's options.
|
|
314
|
+
*/
|
|
315
|
+
static entry = Effect.fn("Changelog.entry")(function* (plan, release, functions, options) {
|
|
316
|
+
if (release.type === "none") return Option.none();
|
|
317
|
+
const changelogOpts = yield* changelogOptionsOf(options);
|
|
318
|
+
const byName = new Map(options.packages.map((pkg) => [pkg.name, pkg]));
|
|
319
|
+
const packageOf = (name) => {
|
|
320
|
+
const pkg = byName.get(name);
|
|
321
|
+
return pkg === void 0 ? Effect.fail(new MissingPackageError({ packageName: name })) : Effect.succeed(pkg);
|
|
322
|
+
};
|
|
323
|
+
const pkg = yield* packageOf(release.name);
|
|
324
|
+
const changesets = plan.changesets.map((changeset) => toNewChangeset(changeset, options.commits?.get(changeset.file)));
|
|
325
|
+
const rule = {
|
|
326
|
+
minimum: options.config.updateInternalDependencies,
|
|
327
|
+
onlyPeersOutOfRange: unsafeOption(options.config, "onlyUpdatePeerDependentsWhenOutOfRange") === true
|
|
328
|
+
};
|
|
329
|
+
const updated = [];
|
|
330
|
+
for (const dependency of plan.releases) {
|
|
331
|
+
const fromDependencies = Object.hasOwn(pkg.dependencies, dependency.name) ? pkg.dependencies[dependency.name] : void 0;
|
|
332
|
+
const fromPeers = Object.hasOwn(pkg.peerDependencies, dependency.name) ? pkg.peerDependencies[dependency.name] : void 0;
|
|
333
|
+
const range = fromDependencies || fromPeers;
|
|
334
|
+
if (range === void 0 || range === "") continue;
|
|
335
|
+
if (!WORKSPACE.test(range) && parseRange(range) === void 0) continue;
|
|
336
|
+
const dependencyPackage = yield* packageOf(dependency.name);
|
|
337
|
+
if (!shouldUpdate(dependency, range, fromDependencies ? "dependencies" : "peerDependencies", rule, dependencyPackage.relativePath)) continue;
|
|
338
|
+
updated.push({
|
|
339
|
+
...toComprehensive(dependency),
|
|
340
|
+
packageJson: toPackageJson(dependencyPackage),
|
|
341
|
+
dir: dependencyPackage.path,
|
|
342
|
+
relativeDir: dependencyPackage.relativePath
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
const behind = new Set(updated.flatMap((dependency) => dependency.changesets));
|
|
346
|
+
const pending = {
|
|
347
|
+
major: [],
|
|
348
|
+
minor: [],
|
|
349
|
+
patch: []
|
|
350
|
+
};
|
|
351
|
+
yield* Effect.try({
|
|
352
|
+
try: () => {
|
|
353
|
+
for (const changeset of changesets) {
|
|
354
|
+
const type = changeset.releases.find((r) => r.name === release.name)?.type;
|
|
355
|
+
if (type === void 0 || type === "none") continue;
|
|
356
|
+
pending[type].push(Promise.resolve(functions.getReleaseLine(changeset, type, changelogOpts)));
|
|
357
|
+
}
|
|
358
|
+
pending.patch.push(Promise.resolve(functions.getDependencyReleaseLine(changesets.filter((changeset) => behind.has(changeset.id)), updated, changelogOpts)));
|
|
359
|
+
},
|
|
360
|
+
catch: (cause) => new ChangelogError({
|
|
361
|
+
packageName: release.name,
|
|
362
|
+
cause
|
|
363
|
+
})
|
|
364
|
+
});
|
|
365
|
+
const lines = yield* Effect.tryPromise({
|
|
366
|
+
try: async () => ({
|
|
367
|
+
major: await Promise.all(pending.major),
|
|
368
|
+
minor: await Promise.all(pending.minor),
|
|
369
|
+
patch: await Promise.all(pending.patch)
|
|
370
|
+
}),
|
|
371
|
+
catch: (cause) => new ChangelogError({
|
|
372
|
+
packageName: release.name,
|
|
373
|
+
cause
|
|
374
|
+
})
|
|
375
|
+
});
|
|
376
|
+
const rendered = [
|
|
377
|
+
`## ${release.newVersion}`,
|
|
378
|
+
section("major", lines.major),
|
|
379
|
+
section("minor", lines.minor),
|
|
380
|
+
section("patch", lines.patch)
|
|
381
|
+
].filter((line) => line !== void 0);
|
|
382
|
+
if (rendered.length === 1) rendered.push("No changes in this release.");
|
|
383
|
+
return Option.some(rendered.join("\n\n"));
|
|
384
|
+
});
|
|
385
|
+
/**
|
|
386
|
+
* Insert a block from {@link Changelog.entry} into a `CHANGELOG.md`'s
|
|
387
|
+
* text, as `apply-release-plan`'s `updateChangelog` does, and return the
|
|
388
|
+
* new text.
|
|
389
|
+
*
|
|
390
|
+
* - An empty `existing` (pass `""` for a file that does not exist) becomes
|
|
391
|
+
* `# <packageName>`, a blank line, and the block.
|
|
392
|
+
* - Otherwise the block goes before the first version heading (a `#` to
|
|
393
|
+
* `######` heading starting with `<n>.<n>`), followed by a blank line.
|
|
394
|
+
* - A file with no version heading gets the block after its first line,
|
|
395
|
+
* which is where `# <packageName>` sits in a file changesets started;
|
|
396
|
+
* a one-line file gets it appended.
|
|
397
|
+
*
|
|
398
|
+
* The block is trimmed and ends with one newline.
|
|
399
|
+
*
|
|
400
|
+
* @param existing - The changelog's current text, or `""`.
|
|
401
|
+
* @param block - The block to insert.
|
|
402
|
+
* @param packageName - The package name, for a new file's heading.
|
|
403
|
+
*/
|
|
404
|
+
static insert(existing, block, packageName) {
|
|
405
|
+
const template = `\n\n${block.trim()}\n`;
|
|
406
|
+
if (existing === "") return `# ${packageName}${template}`;
|
|
407
|
+
const firstVersion = existing.search(/^#{1,6}\s+\d+\.\d+/m);
|
|
408
|
+
if (firstVersion >= 0) return `${existing.slice(0, firstVersion)}${template.trimStart()}\n${existing.slice(firstVersion)}`;
|
|
409
|
+
const newline = existing.indexOf("\n");
|
|
410
|
+
return newline === -1 ? existing + template : `${existing.slice(0, newline)}${template}${existing.slice(newline + 1)}`;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
export { Changelog, ChangelogError, ComprehensiveRelease, ModCompWithPackage, NewChangeset, NewChangesetWithCommit, PackageJSON, VersionType };
|
package/ChangesetConfig.js
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
1
|
import { ChangesetConfigError } from "./errors.js";
|
|
2
|
-
import { Effect, FileSystem, Path, Schema } from "effect";
|
|
2
|
+
import { Effect, FileSystem, Path, Schema, SchemaGetter } from "effect";
|
|
3
3
|
|
|
4
4
|
// src/ChangesetConfig.ts
|
|
5
5
|
const Groups = Schema.Array(Schema.Array(Schema.String));
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const ChangelogPair = Schema.Tuple([Schema.String, Schema.Unknown]);
|
|
7
|
+
/**
|
|
8
|
+
* `@changesets/config` validates the tuple with valibot's `tuple`, which
|
|
9
|
+
* ignores elements past the second, so a longer array decodes to its first
|
|
10
|
+
* two rather than failing.
|
|
11
|
+
*/
|
|
12
|
+
const Changelog = Schema.Union([
|
|
13
|
+
Schema.Literal(false),
|
|
14
|
+
Schema.String,
|
|
15
|
+
Schema.TupleWithRest(ChangelogPair, [Schema.Unknown]).pipe(Schema.decodeTo(ChangelogPair, {
|
|
16
|
+
decode: SchemaGetter.transform((tuple) => [tuple[0], tuple[1]]),
|
|
17
|
+
encode: SchemaGetter.transform((pair) => pair)
|
|
18
|
+
}))
|
|
19
|
+
]);
|
|
20
|
+
const snapshotDefaults = { useCalculatedVersion: false };
|
|
21
|
+
const Snapshot = Schema.Struct({
|
|
22
|
+
useCalculatedVersion: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
|
|
23
|
+
prereleaseTemplate: Schema.optionalKey(Schema.String.check(Schema.isMinLength(1)))
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* The two shapes `@changesets/config` accepts that the class schema alone
|
|
27
|
+
* would not: the boolean `privatePackages`, which sets both flags, and an
|
|
28
|
+
* array `snapshot`, which valibot's `object` admits and reads as no keys set.
|
|
29
|
+
*/
|
|
30
|
+
const normalizeWritten = (json) => {
|
|
31
|
+
if (json === null || typeof json !== "object") return json;
|
|
32
|
+
const written = json;
|
|
33
|
+
const flag = written.privatePackages;
|
|
34
|
+
return {
|
|
35
|
+
...written,
|
|
36
|
+
...typeof flag === "boolean" ? { privatePackages: {
|
|
11
37
|
tag: flag,
|
|
12
38
|
version: flag
|
|
13
|
-
}
|
|
14
|
-
|
|
39
|
+
} } : {},
|
|
40
|
+
...Array.isArray(written.snapshot) ? { snapshot: {} } : {}
|
|
41
|
+
};
|
|
15
42
|
};
|
|
16
43
|
/**
|
|
17
44
|
* The decoded `.changeset/config.json`, with the defaults changesets
|
|
18
|
-
* documents. Keys the schema does not model (
|
|
19
|
-
* `
|
|
45
|
+
* documents. Keys the schema does not model (`$schema`, `format`,
|
|
46
|
+
* `changedFilePatterns`, ...) are kept on `extra` rather than rejected.
|
|
20
47
|
*
|
|
21
48
|
* @public
|
|
22
49
|
*/
|
|
@@ -64,8 +91,39 @@ var ChangesetConfig = class ChangesetConfig extends Schema.Class("ChangesetConfi
|
|
|
64
91
|
/** `false`, `true` or a commit-message generator spec; carried as-is. */
|
|
65
92
|
commit: Schema.Unknown.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
|
|
66
93
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
94
|
+
* The changelog generator, as the file writes it: `false` for none, a
|
|
95
|
+
* module id, or a `[moduleId, options]` pair. Defaults to
|
|
96
|
+
* `"@changesets/cli/changelog"`, the written default `@changesets/config`
|
|
97
|
+
* fills in.
|
|
98
|
+
*
|
|
99
|
+
* It is kept as written, not normalised: `@changesets/config` turns a bare
|
|
100
|
+
* id into `[id, null]`, and a caller wanting that form maps the string
|
|
101
|
+
* itself. Resolving and loading the module is the caller's job; this
|
|
102
|
+
* package only names it.
|
|
103
|
+
*
|
|
104
|
+
* Decoding accepts every shape `@changesets/config` accepts. A tuple longer
|
|
105
|
+
* than two keeps its first two elements, as the oracle does. The options
|
|
106
|
+
* element is carried as `unknown`, so a non-object there decodes here
|
|
107
|
+
* though the oracle rejects it: validating the options is the generator's
|
|
108
|
+
* concern.
|
|
109
|
+
*/
|
|
110
|
+
changelog: Changelog.pipe(Schema.withDecodingDefaultKey(Effect.succeed("@changesets/cli/changelog")), Schema.withConstructorDefault(Effect.succeed("@changesets/cli/changelog"))),
|
|
111
|
+
/**
|
|
112
|
+
* Options for `changeset version --snapshot`.
|
|
113
|
+
*
|
|
114
|
+
* - `useCalculatedVersion` bases a snapshot version on the version the plan
|
|
115
|
+
* calculates rather than `0.0.0`. Defaults to `false`.
|
|
116
|
+
* - `prereleaseTemplate` replaces the default `<tag>-<datetime>` suffix.
|
|
117
|
+
* It may use `{tag}`, `{commit}`, `{commit-short}`, `{timestamp}` and `{datetime}`. Absent
|
|
118
|
+
* when the file sets none, which is also `@changesets/config`'s default;
|
|
119
|
+
* an empty string is rejected, as the oracle rejects it.
|
|
120
|
+
*
|
|
121
|
+
* Defaults to `{ useCalculatedVersion: false }`.
|
|
122
|
+
*/
|
|
123
|
+
snapshot: Snapshot.pipe(Schema.withDecodingDefaultKey(Effect.succeed(snapshotDefaults)), Schema.withConstructorDefault(Effect.succeed(snapshotDefaults))),
|
|
124
|
+
/**
|
|
125
|
+
* Every key of the file the schema does not model, such as `$schema` or
|
|
126
|
+
* `format`. A file key literally named `extra` is not carried: the field
|
|
69
127
|
* name is reserved.
|
|
70
128
|
*/
|
|
71
129
|
extra: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
|
|
@@ -89,7 +147,7 @@ var ChangesetConfig = class ChangesetConfig extends Schema.Class("ChangesetConfi
|
|
|
89
147
|
try: () => JSON.parse(text),
|
|
90
148
|
catch: (cause) => new ChangesetConfigError({ reason: `not valid JSON: ${cause.message}` })
|
|
91
149
|
});
|
|
92
|
-
const decoded = yield* Schema.decodeUnknownEffect(ChangesetConfig)(
|
|
150
|
+
const decoded = yield* Schema.decodeUnknownEffect(ChangesetConfig)(normalizeWritten(json)).pipe(Effect.mapError((error) => new ChangesetConfigError({ reason: error.message })));
|
|
93
151
|
const known = new Set(Object.keys(ChangesetConfig.fields));
|
|
94
152
|
const extra = Object.fromEntries(Object.entries(json).filter(([key]) => !known.has(key)));
|
|
95
153
|
return ChangesetConfig.make({
|
package/ChangesetFile.js
CHANGED
|
@@ -12,7 +12,7 @@ import { Yaml } from "@effected/yaml";
|
|
|
12
12
|
var ParsedChangeset = class extends Schema.Class("ParsedChangeset")({
|
|
13
13
|
/** Package name to requested release type, in file order. */
|
|
14
14
|
releases: Schema.ReadonlyMap(Schema.String, ReleaseType),
|
|
15
|
-
/** The markdown after the front matter. */
|
|
15
|
+
/** The markdown after the front matter, trimmed as `@changesets/parse` trims it. */
|
|
16
16
|
summary: Schema.String
|
|
17
17
|
}) {};
|
|
18
18
|
const Releases = Schema.Record(Schema.String, ReleaseType);
|
|
@@ -28,7 +28,7 @@ const parseText = (text) => {
|
|
|
28
28
|
const close = lines.findIndex((line, index) => index > 0 && isFence(line));
|
|
29
29
|
if (close === -1) return fail("unterminated front matter: no closing --- line", 1);
|
|
30
30
|
const block = lines.slice(1, close).join("\n");
|
|
31
|
-
const summary = lines.slice(close + 1).join("\n").
|
|
31
|
+
const summary = lines.slice(close + 1).join("\n").trim();
|
|
32
32
|
const value = block.trim() === "" ? Result.succeed({}) : Yaml.parseResult(block);
|
|
33
33
|
return Result.match(value, {
|
|
34
34
|
onFailure: (error) => fail(`front matter is not valid YAML: ${error.message}`, (error.diagnostics[0]?.line ?? 0) + 2),
|