@skuba-lib/changesets-changelog 0.0.0 → 1.0.0-replace-global-vars-20260429053803

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ ### MIT License
2
+
3
+ Copyright (c) 2020 SEEK
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.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @skuba-lib/changesets-changelog
2
+
3
+ An opinionated changelog generator for [Changesets](https://github.com/changesets/changesets), used by skuba-managed projects.
4
+
5
+ This package provides a single changelog generator that:
6
+
7
+ - **Automatically uses GitHub metadata** (PR links, commit links, authors) when `GITHUB_TOKEN` is set, falling back gracefully to Git-based versioning when it isn't.
8
+ - **Bolds conventional commit scopes** (e.g. `feat(api): ...` becomes `**api:** ...`) for consistent formatting across changelogs.
9
+ - **Supports preamble injection** via a `skuba-changelog-inject` CLI, which prepends content from `.changeset/.PREAMBLE.md` into the generated `CHANGELOG.md` — useful for adding migration guides or release highlights to major versions.
10
+
11
+ ## Usage
12
+
13
+ ### 1. Configure Changesets
14
+
15
+ In your `.changeset/config.json`, set the changelog generator:
16
+
17
+ ```json
18
+ {
19
+ "changelog": ["@skuba-lib/changesets-changelog", { "repo": "org/repo" }]
20
+ }
21
+ ```
22
+
23
+ ### 2. Set up GitHub integration (recommended)
24
+
25
+ For GitHub-linked entries (PR links, commit SHAs, authors), provide a GitHub personal access token with the `public_repo` scope:
26
+
27
+ ```sh
28
+ export GITHUB_TOKEN=your_token_here
29
+ ```
30
+
31
+ Without `GITHUB_TOKEN`, the generator falls back to Git-based versioning and logs a warning.
32
+
33
+ ### 3. Inject a release preamble (optional)
34
+
35
+ To prepend custom content to a release — such as a migration guide — create `.changeset/.PREAMBLE.md` before running `changeset version`. Then run the inject script after:
36
+
37
+ ```sh
38
+ pnpm skuba-changelog-inject
39
+ ```
40
+
41
+ This inserts the preamble into `CHANGELOG.md` and removes `.PREAMBLE.md` automatically.
package/package.json CHANGED
@@ -1,11 +1,41 @@
1
1
  {
2
2
  "name": "@skuba-lib/changesets-changelog",
3
- "version": "0.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "",
10
- "license": "ISC"
11
- }
3
+ "version": "1.0.0-replace-global-vars-20260429053803",
4
+ "private": false,
5
+ "description": "Opinionated changelog generator for Changesets",
6
+ "homepage": "https://github.com/seek-oss/skuba/tree/main/packages/changesets-changelog#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/seek-oss/skuba/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/seek-oss/skuba.git",
13
+ "directory": "packages/changesets-changelog"
14
+ },
15
+ "license": "MIT",
16
+ "sideEffects": false,
17
+ "type": "module",
18
+ "exports": {
19
+ ".": "./src/index.mjs",
20
+ "./inject": "./src/inject.mjs",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "bin": {
24
+ "skuba-changelog-inject": "./src/inject.mjs"
25
+ },
26
+ "files": [
27
+ "src"
28
+ ],
29
+ "dependencies": {
30
+ "@changesets/get-github-info": "^0.8.0"
31
+ },
32
+ "engines": {
33
+ "node": ">=24"
34
+ },
35
+ "skuba": {
36
+ "entryPoint": "src/changelog.mjs",
37
+ "template": "oss-npm-package",
38
+ "type": "package",
39
+ "version": "14.1.2"
40
+ }
41
+ }
@@ -0,0 +1,133 @@
1
+ import { getInfo, getInfoFromPullRequest } from '@changesets/get-github-info';
2
+
3
+ /**
4
+ * Bold the scope of the changelog entry.
5
+ *
6
+ * This is used later in our site packaging.
7
+ *
8
+ * @param {string} firstLine
9
+ */
10
+ const boldScope = (firstLine) => firstLine.replace(/^([^:]+): /, '**$1:** ');
11
+
12
+ /**
13
+ * Adapted from `@changesets/cli`.
14
+ *
15
+ * {@link https://github.com/atlassian/changesets/blob/%40changesets/cli%402.17.0/packages/cli/src/changelog/index.ts}
16
+ *
17
+ * @type import('@changesets/types').ChangelogFunctions
18
+ */
19
+ const defaultChangelogFunctions = {
20
+ getDependencyReleaseLine: async (_changesets, _dependenciesUpdated) => '',
21
+ getReleaseLine: async (changeset) => {
22
+ const [firstLine, ...futureLines] = changeset.summary
23
+ .split('\n')
24
+ .map((l) => l.trimRight());
25
+
26
+ const formattedFirstLine = boldScope(firstLine);
27
+
28
+ const suffix = changeset.commit;
29
+
30
+ return `\n\n- ${formattedFirstLine}${
31
+ suffix ? ` (${suffix})` : ''
32
+ }\n${futureLines.map((l) => ` ${l}`).join('\n')}`;
33
+ },
34
+ };
35
+
36
+ /**
37
+ * Adapted from `@changesets/changelog-github`.
38
+ *
39
+ * {@link https://github.com/atlassian/changesets/blob/%40changesets/changelog-github%400.4.1/packages/changelog-github/src/index.ts}
40
+ *
41
+ * @type import('@changesets/types').ChangelogFunctions
42
+ */
43
+ const gitHubChangelogFunctions = {
44
+ getDependencyReleaseLine: async (
45
+ _changesets,
46
+ _dependenciesUpdated,
47
+ _options,
48
+ ) => '',
49
+ getReleaseLine: async (changeset, _type, options) => {
50
+ if (!options?.repo) {
51
+ throw new Error(
52
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]',
53
+ );
54
+ }
55
+
56
+ /** @type number | undefined */
57
+ let prFromSummary;
58
+ /** @type string | undefined */
59
+ let commitFromSummary;
60
+
61
+ const replacedChangelog = changeset.summary
62
+ .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
63
+ const num = Number(pr);
64
+ if (!isNaN(num)) {
65
+ prFromSummary = num;
66
+ }
67
+ return '';
68
+ })
69
+ .replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
70
+ commitFromSummary = commit;
71
+ return '';
72
+ })
73
+ .replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, () => '')
74
+ .trim();
75
+
76
+ const [firstLine, ...futureLines] = replacedChangelog
77
+ .split('\n')
78
+ .map((l) => l.trimRight());
79
+
80
+ const links = await (async () => {
81
+ if (prFromSummary !== undefined) {
82
+ let { links: prLinks } = await getInfoFromPullRequest({
83
+ repo: options.repo,
84
+ pull: prFromSummary,
85
+ });
86
+ if (commitFromSummary) {
87
+ prLinks = {
88
+ ...prLinks,
89
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
90
+ };
91
+ }
92
+ return prLinks;
93
+ }
94
+ const commitToFetchFrom = commitFromSummary || changeset.commit;
95
+ if (commitToFetchFrom) {
96
+ const { links: commitLinks } = await getInfo({
97
+ repo: options.repo,
98
+ commit: commitToFetchFrom,
99
+ });
100
+ return commitLinks;
101
+ }
102
+ return {
103
+ commit: null,
104
+ pull: null,
105
+ user: null,
106
+ };
107
+ })();
108
+
109
+ const formattedFirstLine = boldScope(firstLine);
110
+
111
+ const suffix = links.pull ?? links.commit;
112
+
113
+ return [
114
+ `\n- ${formattedFirstLine}${suffix ? ` (${suffix})` : ''}`,
115
+ ...futureLines.map((l) => ` ${l}`),
116
+ ].join('\n');
117
+ },
118
+ };
119
+
120
+ const changelogFunctions = (() => {
121
+ if (process.env.GITHUB_TOKEN) {
122
+ return gitHubChangelogFunctions;
123
+ }
124
+
125
+ // eslint-disable-next-line no-console
126
+ console.warn(
127
+ 'Defaulting to Git-based versioning.\nEnable GitHub-based versioning by setting the GITHUB_TOKEN environment variable.\nThis requires a GitHub personal access token with the `public_repo` scope: https://github.com/settings/tokens/new',
128
+ );
129
+
130
+ return defaultChangelogFunctions;
131
+ })();
132
+
133
+ export default changelogFunctions;
package/src/inject.mjs ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Hack to add a preamble from .changeset/.PREAMBLE.md to the CHANGELOG.md for a given release
4
+ /* eslint-disable no-sync */
5
+ import fs from 'fs';
6
+
7
+ const PREAMBLE_PATH = '.changeset/.PREAMBLE.md';
8
+ const CHANGELOG_PATH = 'CHANGELOG.md';
9
+
10
+ if (fs.existsSync(PREAMBLE_PATH) && fs.existsSync(CHANGELOG_PATH)) {
11
+ const preamble = fs.readFileSync(PREAMBLE_PATH, 'utf8');
12
+ const changeset = fs.readFileSync(CHANGELOG_PATH, 'utf8');
13
+
14
+ const lines = changeset.split('\n');
15
+ lines.splice(3, 0, preamble);
16
+ fs.writeFileSync(CHANGELOG_PATH, lines.join('\n'));
17
+ fs.rmSync(PREAMBLE_PATH);
18
+ }