@livekit/changesets-changelog-github 0.0.1

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/dist/index.js ADDED
@@ -0,0 +1,114 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ default: () => src_default
23
+ });
24
+ module.exports = __toCommonJS(src_exports);
25
+ var import_dotenv = require("dotenv");
26
+ var import_get_github_info = require("@changesets/get-github-info");
27
+ (0, import_dotenv.config)();
28
+ var changelogFunctions = {
29
+ getDependencyReleaseLine: async (changesets, dependenciesUpdated, options) => {
30
+ if (!options.repo) {
31
+ throw new Error(
32
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
33
+ );
34
+ }
35
+ if (dependenciesUpdated.length === 0)
36
+ return "";
37
+ const changesetLink = `- Updated dependencies [${(await Promise.all(
38
+ changesets.map(async (cs) => {
39
+ if (cs.commit) {
40
+ let { links } = await (0, import_get_github_info.getInfo)({
41
+ repo: options.repo,
42
+ commit: cs.commit
43
+ });
44
+ return links.commit;
45
+ }
46
+ })
47
+ )).filter((_) => _).join(", ")}]:`;
48
+ const updatedDepenenciesList = dependenciesUpdated.map(
49
+ (dependency) => ` - ${dependency.name}@${dependency.newVersion}`
50
+ );
51
+ return [changesetLink, ...updatedDepenenciesList].join("\n");
52
+ },
53
+ getReleaseLine: async (changeset, type, options) => {
54
+ if (!options || !options.repo) {
55
+ throw new Error(
56
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
57
+ );
58
+ }
59
+ let prFromSummary;
60
+ let commitFromSummary;
61
+ let usersFromSummary = [];
62
+ const replacedChangelog = changeset.summary.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
63
+ let num = Number(pr);
64
+ if (!isNaN(num))
65
+ prFromSummary = num;
66
+ return "";
67
+ }).replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
68
+ commitFromSummary = commit;
69
+ return "";
70
+ }).replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
71
+ usersFromSummary.push(user);
72
+ return "";
73
+ }).trim();
74
+ const [firstLine, ...futureLines] = replacedChangelog.split("\n").map((l) => l.trimRight());
75
+ const links = await (async () => {
76
+ if (prFromSummary !== void 0) {
77
+ let { links: links2 } = await (0, import_get_github_info.getInfoFromPullRequest)({
78
+ repo: options.repo,
79
+ pull: prFromSummary
80
+ });
81
+ if (commitFromSummary) {
82
+ links2 = {
83
+ ...links2,
84
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`
85
+ };
86
+ }
87
+ return links2;
88
+ }
89
+ const commitToFetchFrom = commitFromSummary || changeset.commit;
90
+ if (commitToFetchFrom) {
91
+ let { links: links2 } = await (0, import_get_github_info.getInfo)({
92
+ repo: options.repo,
93
+ commit: commitToFetchFrom
94
+ });
95
+ return links2;
96
+ }
97
+ return {
98
+ commit: null,
99
+ pull: null,
100
+ user: null
101
+ };
102
+ })();
103
+ const users = usersFromSummary.length ? usersFromSummary.map((userFromSummary) => `@${userFromSummary}`).join(", ") : links.user;
104
+ const prefix = links.pull ? `${links.pull} -` : links.commit ? `${links.commit} -` : "";
105
+ const suffix = users === null ? "" : `(${users})`;
106
+ return `
107
+
108
+ - ${prefix} ${firstLine} ${suffix}
109
+ ${futureLines.map((l) => ` ${l}`).join("\n")}`;
110
+ }
111
+ };
112
+ var src_default = changelogFunctions;
113
+ // Annotate the CommonJS export names for ESM import in node:
114
+ 0 && (module.exports = {});
package/dist/index.mjs ADDED
@@ -0,0 +1,92 @@
1
+ // src/index.ts
2
+ import { config } from "dotenv";
3
+ import { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info";
4
+ config();
5
+ var changelogFunctions = {
6
+ getDependencyReleaseLine: async (changesets, dependenciesUpdated, options) => {
7
+ if (!options.repo) {
8
+ throw new Error(
9
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
10
+ );
11
+ }
12
+ if (dependenciesUpdated.length === 0)
13
+ return "";
14
+ const changesetLink = `- Updated dependencies [${(await Promise.all(
15
+ changesets.map(async (cs) => {
16
+ if (cs.commit) {
17
+ let { links } = await getInfo({
18
+ repo: options.repo,
19
+ commit: cs.commit
20
+ });
21
+ return links.commit;
22
+ }
23
+ })
24
+ )).filter((_) => _).join(", ")}]:`;
25
+ const updatedDepenenciesList = dependenciesUpdated.map(
26
+ (dependency) => ` - ${dependency.name}@${dependency.newVersion}`
27
+ );
28
+ return [changesetLink, ...updatedDepenenciesList].join("\n");
29
+ },
30
+ getReleaseLine: async (changeset, type, options) => {
31
+ if (!options || !options.repo) {
32
+ throw new Error(
33
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
34
+ );
35
+ }
36
+ let prFromSummary;
37
+ let commitFromSummary;
38
+ let usersFromSummary = [];
39
+ const replacedChangelog = changeset.summary.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
40
+ let num = Number(pr);
41
+ if (!isNaN(num))
42
+ prFromSummary = num;
43
+ return "";
44
+ }).replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
45
+ commitFromSummary = commit;
46
+ return "";
47
+ }).replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
48
+ usersFromSummary.push(user);
49
+ return "";
50
+ }).trim();
51
+ const [firstLine, ...futureLines] = replacedChangelog.split("\n").map((l) => l.trimRight());
52
+ const links = await (async () => {
53
+ if (prFromSummary !== void 0) {
54
+ let { links: links2 } = await getInfoFromPullRequest({
55
+ repo: options.repo,
56
+ pull: prFromSummary
57
+ });
58
+ if (commitFromSummary) {
59
+ links2 = {
60
+ ...links2,
61
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`
62
+ };
63
+ }
64
+ return links2;
65
+ }
66
+ const commitToFetchFrom = commitFromSummary || changeset.commit;
67
+ if (commitToFetchFrom) {
68
+ let { links: links2 } = await getInfo({
69
+ repo: options.repo,
70
+ commit: commitToFetchFrom
71
+ });
72
+ return links2;
73
+ }
74
+ return {
75
+ commit: null,
76
+ pull: null,
77
+ user: null
78
+ };
79
+ })();
80
+ const users = usersFromSummary.length ? usersFromSummary.map((userFromSummary) => `@${userFromSummary}`).join(", ") : links.user;
81
+ const prefix = links.pull ? `${links.pull} -` : links.commit ? `${links.commit} -` : "";
82
+ const suffix = users === null ? "" : `(${users})`;
83
+ return `
84
+
85
+ - ${prefix} ${firstLine} ${suffix}
86
+ ${futureLines.map((l) => ` ${l}`).join("\n")}`;
87
+ }
88
+ };
89
+ var src_default = changelogFunctions;
90
+ export {
91
+ src_default as default
92
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ clearMocks: true,
3
+ modulePathIgnorePatterns: ["<rootDir>/dist/"],
4
+ preset: "ts-jest",
5
+ testEnvironment: "node",
6
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@livekit/changesets-changelog-github",
3
+ "version": "0.0.1",
4
+ "description": "A compact changelog entry generator based on the official changesets changelog generator",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "license": "Apache 2.0",
8
+ "repository": "https://github.com/livekit/changesets-changelog-github",
9
+ "scripts": {
10
+ "build": "tsup-node",
11
+ "test": "jest"
12
+ },
13
+ "dependencies": {
14
+ "@changesets/get-github-info": "^0.5.1",
15
+ "@changesets/types": "^5.2.0",
16
+ "dotenv": "^8.1.0"
17
+ },
18
+ "devDependencies": {
19
+ "@changesets/parse": "*",
20
+ "@types/jest": "29.1.1",
21
+ "jest": "^29.2.2",
22
+ "jest-junit": "^6.4.0",
23
+ "ts-jest": "29.0.3",
24
+ "tsup": "^6.3.0",
25
+ "typescript": "^4.8.4"
26
+ }
27
+ }
@@ -0,0 +1,134 @@
1
+ import changelogFunctions from "./index";
2
+ import parse from "@changesets/parse";
3
+
4
+ const getReleaseLine = changelogFunctions.getReleaseLine;
5
+
6
+ jest.mock(
7
+ "@changesets/get-github-info",
8
+ (): typeof import("@changesets/get-github-info") => {
9
+ // this is duplicated because jest.mock reordering things
10
+ const data = {
11
+ commit: "a085003",
12
+ user: "Andarist",
13
+ pull: 1613,
14
+ repo: "emotion-js/emotion",
15
+ };
16
+ const links = {
17
+ user: `@${data.user}`,
18
+ pull: `[#${data.pull}](https://github.com/${data.repo}/pull/${data.pull})`,
19
+ commit: `[\`${data.commit}\`](https://github.com/${data.repo}/commit/${data.commit})`,
20
+ };
21
+ return {
22
+ async getInfo({ commit, repo }) {
23
+ expect(commit).toBe(data.commit);
24
+ expect(repo).toBe(data.repo);
25
+ return {
26
+ pull: data.pull,
27
+ user: data.user,
28
+ links,
29
+ };
30
+ },
31
+ async getInfoFromPullRequest({ pull, repo }) {
32
+ expect(pull).toBe(data.pull);
33
+ expect(repo).toBe(data.repo);
34
+ return {
35
+ commit: data.commit,
36
+ user: data.user,
37
+ links,
38
+ };
39
+ },
40
+ };
41
+ }
42
+ );
43
+
44
+ const getChangeset = (content: string, commit: string | undefined) => {
45
+ return [
46
+ {
47
+ ...parse(
48
+ `---
49
+ pkg: "minor"
50
+ ---
51
+ something
52
+ ${content}
53
+ `
54
+ ),
55
+ id: "some-id",
56
+ commit,
57
+ },
58
+ "minor",
59
+ { repo: data.repo },
60
+ ] as const;
61
+ };
62
+
63
+ const data = {
64
+ commit: "a085003",
65
+ user: "Andarist",
66
+ pull: 1613,
67
+ repo: "emotion-js/emotion",
68
+ };
69
+
70
+ describe.each([data.commit, "wrongcommit", undefined])(
71
+ "with commit from changeset of %s",
72
+ (commitFromChangeset) => {
73
+ describe.each(["pr", "pull request", "pull"])(
74
+ "override pr with %s keyword",
75
+ (keyword) => {
76
+ test.each(["with #", "without #"] as const)("%s", async (kind) => {
77
+ expect(
78
+ await getReleaseLine(
79
+ ...getChangeset(
80
+ `${keyword}: ${kind === "with #" ? "#" : ""}${data.pull}`,
81
+ commitFromChangeset
82
+ )
83
+ )
84
+ ).toEqual(
85
+ `\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) - something (@Andarist)\n`
86
+ );
87
+ });
88
+ }
89
+ );
90
+ test("override commit with commit keyword", async () => {
91
+ expect(
92
+ await getReleaseLine(
93
+ ...getChangeset(`commit: ${data.commit}`, commitFromChangeset)
94
+ )
95
+ ).toEqual(
96
+ `\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) - something (@Andarist)\n`
97
+ );
98
+ });
99
+ }
100
+ );
101
+
102
+ describe.each(["author", "user"])(
103
+ "override author with %s keyword",
104
+ (keyword) => {
105
+ test.each(["with @", "without @"] as const)("%s", async (kind) => {
106
+ expect(
107
+ await getReleaseLine(
108
+ ...getChangeset(
109
+ `${keyword}: ${kind === "with @" ? "@" : ""}other`,
110
+ data.commit
111
+ )
112
+ )
113
+ ).toEqual(
114
+ `\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) - something (@other)\n`
115
+ );
116
+ });
117
+ }
118
+ );
119
+
120
+ it("with multiple authors", async () => {
121
+ expect(
122
+ await getReleaseLine(
123
+ ...getChangeset(
124
+ ["author: @Andarist", "author: @mitchellhamilton"].join("\n"),
125
+ data.commit
126
+ )
127
+ )
128
+ ).toMatchInlineSnapshot(`
129
+ "
130
+
131
+ - [#1613](https://github.com/emotion-js/emotion/pull/1613) - something (@Andarist, @mitchellhamilton)
132
+ "
133
+ `);
134
+ });
package/src/index.ts ADDED
@@ -0,0 +1,122 @@
1
+ import { ChangelogFunctions } from "@changesets/types";
2
+ // @ts-ignore
3
+ import { config } from "dotenv";
4
+ import { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info";
5
+
6
+ config();
7
+
8
+ const changelogFunctions: ChangelogFunctions = {
9
+ getDependencyReleaseLine: async (
10
+ changesets,
11
+ dependenciesUpdated,
12
+ options
13
+ ) => {
14
+ if (!options.repo) {
15
+ throw new Error(
16
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
17
+ );
18
+ }
19
+ if (dependenciesUpdated.length === 0) return "";
20
+
21
+ const changesetLink = `- Updated dependencies [${(
22
+ await Promise.all(
23
+ changesets.map(async (cs) => {
24
+ if (cs.commit) {
25
+ let { links } = await getInfo({
26
+ repo: options.repo,
27
+ commit: cs.commit,
28
+ });
29
+ return links.commit;
30
+ }
31
+ })
32
+ )
33
+ )
34
+ .filter((_) => _)
35
+ .join(", ")}]:`;
36
+
37
+ const updatedDepenenciesList = dependenciesUpdated.map(
38
+ (dependency) => ` - ${dependency.name}@${dependency.newVersion}`
39
+ );
40
+
41
+ return [changesetLink, ...updatedDepenenciesList].join("\n");
42
+ },
43
+ getReleaseLine: async (changeset, type, options) => {
44
+ if (!options || !options.repo) {
45
+ throw new Error(
46
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
47
+ );
48
+ }
49
+
50
+ let prFromSummary: number | undefined;
51
+ let commitFromSummary: string | undefined;
52
+ let usersFromSummary: string[] = [];
53
+
54
+ const replacedChangelog = changeset.summary
55
+ .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
56
+ let num = Number(pr);
57
+ if (!isNaN(num)) prFromSummary = num;
58
+ return "";
59
+ })
60
+ .replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
61
+ commitFromSummary = commit;
62
+ return "";
63
+ })
64
+ .replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
65
+ usersFromSummary.push(user);
66
+ return "";
67
+ })
68
+ .trim();
69
+
70
+ const [firstLine, ...futureLines] = replacedChangelog
71
+ .split("\n")
72
+ .map((l) => l.trimRight());
73
+
74
+ const links = await (async () => {
75
+ if (prFromSummary !== undefined) {
76
+ let { links } = await getInfoFromPullRequest({
77
+ repo: options.repo,
78
+ pull: prFromSummary,
79
+ });
80
+ if (commitFromSummary) {
81
+ links = {
82
+ ...links,
83
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
84
+ };
85
+ }
86
+ return links;
87
+ }
88
+ const commitToFetchFrom = commitFromSummary || changeset.commit;
89
+ if (commitToFetchFrom) {
90
+ let { links } = await getInfo({
91
+ repo: options.repo,
92
+ commit: commitToFetchFrom,
93
+ });
94
+ return links;
95
+ }
96
+ return {
97
+ commit: null,
98
+ pull: null,
99
+ user: null,
100
+ };
101
+ })();
102
+
103
+ const users = usersFromSummary.length
104
+ ? usersFromSummary
105
+ .map((userFromSummary) => `@${userFromSummary}`)
106
+ .join(", ")
107
+ : links.user;
108
+
109
+ const prefix = links.pull
110
+ ? `${links.pull} -`
111
+ : links.commit
112
+ ? `${links.commit} -`
113
+ : "";
114
+ const suffix = users === null ? "" : `(${users})`;
115
+
116
+ return `\n\n- ${prefix} ${firstLine} ${suffix}\n${futureLines
117
+ .map((l) => ` ${l}`)
118
+ .join("\n")}`;
119
+ },
120
+ };
121
+
122
+ export default changelogFunctions;
package/tsup.config.js ADDED
@@ -0,0 +1,10 @@
1
+ /** @type {import("tsup").Options} */
2
+ export const tsup = {
3
+ entryPoints: ["src/index.ts"],
4
+ format: ["esm", "cjs"],
5
+ sourcemap: false,
6
+ splitting: false,
7
+ clean: true,
8
+ shims: true,
9
+ target: "node14.13.1",
10
+ };