@jakubmazanec/changesets-changelog 1.0.0-20220726001922

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.
@@ -0,0 +1,2 @@
1
+ export * from './getDependencyReleaseLine';
2
+ export * from './getReleaseLine';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ const _dotenv = require("dotenv");
3
+ _exportStar(require("./getDependencyReleaseLine"), exports);
4
+ _exportStar(require("./getReleaseLine"), exports);
5
+ function _exportStar(from, to) {
6
+ Object.keys(from).forEach(function(k) {
7
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
8
+ enumerable: true,
9
+ get: function() {
10
+ return from[k];
11
+ }
12
+ });
13
+ });
14
+ return from;
15
+ }
16
+ (0, _dotenv.config)();
17
+
18
+ //# sourceMappingURL=changesets-changelog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/changesets-changelog.ts"],"sourcesContent":["import {config} from 'dotenv';\n\nconfig();\n\nexport * from './getDependencyReleaseLine';\nexport * from './getReleaseLine';\n"],"names":["config"],"mappings":"AAAA;wBAAqB,QAAQ;oBAIf,4BAA4B;oBAC5B,kBAAkB;;;;;;;;;;;;AAHhCA,IAAAA,OAAM,OAAA,GAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { ModCompWithPackage, NewChangesetWithCommit } from '@changesets/types';
2
+ export declare function getDependencyReleaseLine(changesets: NewChangesetWithCommit[], updatedDependencies: ModCompWithPackage[], options?: Record<string, unknown>): Promise<string>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "getDependencyReleaseLine", {
3
+ enumerable: true,
4
+ get: ()=>getDependencyReleaseLine
5
+ });
6
+ const _getGithubInfo = require("@changesets/get-github-info");
7
+ async function getDependencyReleaseLine(changesets, updatedDependencies, options) {
8
+ if (!(options === null || options === void 0 ? void 0 : options.repo)) {
9
+ throw new Error('Please provide a repo in Changesets config, e.g.:\n"changelog": ["@jakubmazanec/changesets-changelog", { "repo": "org/repo" }]');
10
+ }
11
+ if (!updatedDependencies.length) {
12
+ return "";
13
+ }
14
+ const changesetLink = `- Updated dependencies [${(await Promise.all(changesets.map(async (changeset)=>{
15
+ if (changeset.commit) {
16
+ let { links } = await (0, _getGithubInfo.getInfo)({
17
+ repo: String(options.repo),
18
+ commit: changeset.commit
19
+ });
20
+ return links.commit;
21
+ }
22
+ return undefined;
23
+ }))).filter((_)=>_).join(", ")}]:`;
24
+ let updatedDepenenciesLines = updatedDependencies.map((dependency)=>` - ${dependency.name}@${dependency.newVersion}`);
25
+ return [
26
+ changesetLink,
27
+ ...updatedDepenenciesLines
28
+ ].join("\n");
29
+ }
30
+
31
+ //# sourceMappingURL=getDependencyReleaseLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/getDependencyReleaseLine.ts"],"sourcesContent":["import {getInfo} from '@changesets/get-github-info';\nimport type {ModCompWithPackage, NewChangesetWithCommit} from '@changesets/types';\n\nexport async function getDependencyReleaseLine(\n changesets: NewChangesetWithCommit[],\n updatedDependencies: ModCompWithPackage[],\n options?: Record<string, unknown>,\n) {\n if (!options?.repo) {\n throw new Error(\n 'Please provide a repo in Changesets config, e.g.:\\n\"changelog\": [\"@jakubmazanec/changesets-changelog\", { \"repo\": \"org/repo\" }]',\n );\n }\n\n if (!updatedDependencies.length) {\n return '';\n }\n\n const changesetLink = `- Updated dependencies [${(\n await Promise.all(\n changesets.map(async (changeset) => {\n if (changeset.commit) {\n let {links} = await getInfo({\n repo: String(options.repo),\n commit: changeset.commit,\n });\n\n return links.commit;\n }\n\n return undefined;\n }),\n )\n )\n .filter((_) => _)\n .join(', ')}]:`;\n\n let updatedDepenenciesLines = updatedDependencies.map(\n (dependency) => ` - ${dependency.name}@${dependency.newVersion}`,\n );\n\n return [changesetLink, ...updatedDepenenciesLines].join('\\n');\n}\n"],"names":["getDependencyReleaseLine","changesets","updatedDependencies","options","repo","Error","length","changesetLink","Promise","all","map","changeset","commit","links","getInfo","String","undefined","filter","_","join","updatedDepenenciesLines","dependency","name","newVersion"],"mappings":"AAAA;+BAGsBA,0BAAwB;;aAAxBA,wBAAwB;;+BAHxB,6BAA6B;AAG5C,eAAeA,wBAAwB,CAC5CC,UAAoC,EACpCC,mBAAyC,EACzCC,OAAiC,EACjC;IACA,IAAI,CAACA,CAAAA,OAAO,aAAPA,OAAO,WAAM,GAAbA,KAAAA,CAAa,GAAbA,OAAO,CAAEC,IAAI,CAAA,EAAE;QAClB,MAAM,IAAIC,KAAK,CACb,gIAAgI,CACjI,CAAC;KACH;IAED,IAAI,CAACH,mBAAmB,CAACI,MAAM,EAAE;QAC/B,OAAO,EAAE,CAAC;KACX;IAED,MAAMC,aAAa,GAAG,CAAC,wBAAwB,EAAE,CAC/C,MAAMC,OAAO,CAACC,GAAG,CACfR,UAAU,CAACS,GAAG,CAAC,OAAOC,SAAS,GAAK;QAClC,IAAIA,SAAS,CAACC,MAAM,EAAE;YACpB,IAAI,EAACC,KAAK,CAAA,EAAC,GAAG,MAAMC,IAAAA,cAAO,QAAA,EAAC;gBAC1BV,IAAI,EAAEW,MAAM,CAACZ,OAAO,CAACC,IAAI,CAAC;gBAC1BQ,MAAM,EAAED,SAAS,CAACC,MAAM;aACzB,CAAC,AAAC;YAEH,OAAOC,KAAK,CAACD,MAAM,CAAC;SACrB;QAED,OAAOI,SAAS,CAAC;KAClB,CAAC,CACH,CACF,CACEC,MAAM,CAAC,CAACC,CAAC,GAAKA,CAAC,CAAC,CAChBC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,AAAC;IAElB,IAAIC,uBAAuB,GAAGlB,mBAAmB,CAACQ,GAAG,CACnD,CAACW,UAAU,GAAK,CAAC,IAAI,EAAEA,UAAU,CAACC,IAAI,CAAC,CAAC,EAAED,UAAU,CAACE,UAAU,CAAC,CAAC,CAClE,AAAC;IAEF,OAAO;QAAChB,aAAa;WAAKa,uBAAuB;KAAC,CAACD,IAAI,CAAC,IAAI,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,2 @@
1
+ import type { VersionType, NewChangesetWithCommit } from '@changesets/types';
2
+ export declare function getReleaseLine(changeset: NewChangesetWithCommit, type: VersionType, options?: Record<string, unknown>): Promise<string>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "getReleaseLine", {
3
+ enumerable: true,
4
+ get: ()=>getReleaseLine
5
+ });
6
+ const _getGithubInfo = require("@changesets/get-github-info");
7
+ async function getReleaseLine(changeset, type, options) {
8
+ if (!(options === null || options === void 0 ? void 0 : options.repo)) {
9
+ throw new Error('Please provide a repo in Changesets config, e.g.:\n"changelog": ["@jakubmazanec/changesets-changelog", { "repo": "org/repo" }]');
10
+ }
11
+ let pullRequestFromSummary;
12
+ let commitFromSummary;
13
+ let usersFromSummary = [];
14
+ let replacedChangelog = changeset.summary.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/gim, (_, rawPullRequest)=>{
15
+ let pullRequest = Number(rawPullRequest);
16
+ if (!Number.isNaN(pullRequest)) {
17
+ pullRequestFromSummary = pullRequest;
18
+ }
19
+ return "";
20
+ }).replace(/^\s*commit:\s*(\S+)/gim, (_, commit)=>{
21
+ commitFromSummary = commit;
22
+ return "";
23
+ }).replace(/^\s*(?:author|user):\s*@?(\S+)/gim, (_, user)=>{
24
+ usersFromSummary.push(user);
25
+ return "";
26
+ }).trim();
27
+ let [firstLine, ...lines] = replacedChangelog.split("\n").map((line)=>line.trimEnd());
28
+ let commitLink;
29
+ let pullRequestLink;
30
+ let usersLink;
31
+ if (pullRequestFromSummary === undefined) {
32
+ let commitToFetchFrom = commitFromSummary ?? changeset.commit;
33
+ if (commitToFetchFrom) {
34
+ let { links } = await (0, _getGithubInfo.getInfo)({
35
+ repo: String(options.repo),
36
+ commit: commitToFetchFrom
37
+ });
38
+ commitLink = links.commit;
39
+ pullRequestLink = links.pull ?? undefined;
40
+ usersLink = links.user ?? undefined;
41
+ }
42
+ } else {
43
+ let { links: links1 } = await (0, _getGithubInfo.getInfoFromPullRequest)({
44
+ repo: String(options.repo),
45
+ pull: pullRequestFromSummary
46
+ });
47
+ if (commitFromSummary) {
48
+ links1 = {
49
+ ...links1,
50
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`
51
+ };
52
+ }
53
+ commitLink = links1.commit ?? undefined;
54
+ pullRequestLink = links1.pull;
55
+ usersLink = links1.user ?? undefined;
56
+ }
57
+ if (usersFromSummary.length) {
58
+ usersLink = usersFromSummary.map((userFromSummary)=>`[@${userFromSummary}](https://github.com/${userFromSummary})`).join(", ");
59
+ }
60
+ let prefix = [
61
+ pullRequestLink ? ` ${pullRequestLink}` : "",
62
+ commitLink ? ` ${commitLink}` : "",
63
+ usersLink ? ` (${usersLink})` : "",
64
+ ].join("");
65
+ return `\n\n-${prefix ? `${prefix} –` : ""} ${firstLine}\n${lines.map((line)=>` ${line}`).join("\n")}`;
66
+ }
67
+
68
+ //# sourceMappingURL=getReleaseLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/getReleaseLine.ts"],"sourcesContent":["import {getInfo, getInfoFromPullRequest} from '@changesets/get-github-info';\nimport type {VersionType, NewChangesetWithCommit} from '@changesets/types';\n\nexport async function getReleaseLine(\n changeset: NewChangesetWithCommit,\n type: VersionType,\n options?: Record<string, unknown>,\n) {\n if (!options?.repo) {\n throw new Error(\n 'Please provide a repo in Changesets config, e.g.:\\n\"changelog\": [\"@jakubmazanec/changesets-changelog\", { \"repo\": \"org/repo\" }]',\n );\n }\n\n let pullRequestFromSummary: number | undefined;\n let commitFromSummary: string | undefined;\n let usersFromSummary: string[] = [];\n let replacedChangelog = changeset.summary\n .replace(/^\\s*(?:pr|pull|pull\\s+request):\\s*#?(\\d+)/gim, (_, rawPullRequest) => {\n let pullRequest = Number(rawPullRequest);\n\n if (!Number.isNaN(pullRequest)) {\n pullRequestFromSummary = pullRequest;\n }\n\n return '';\n })\n .replace(/^\\s*commit:\\s*(\\S+)/gim, (_, commit: string) => {\n commitFromSummary = commit;\n\n return '';\n })\n .replace(/^\\s*(?:author|user):\\s*@?(\\S+)/gim, (_, user: string) => {\n usersFromSummary.push(user);\n\n return '';\n })\n .trim();\n let [firstLine, ...lines] = replacedChangelog.split('\\n').map((line) => line.trimEnd());\n let commitLink: string | undefined;\n let pullRequestLink: string | undefined;\n let usersLink: string | undefined;\n\n if (pullRequestFromSummary === undefined) {\n let commitToFetchFrom = commitFromSummary ?? changeset.commit;\n\n if (commitToFetchFrom) {\n let {links} = await getInfo({\n repo: String(options.repo),\n commit: commitToFetchFrom,\n });\n\n commitLink = links.commit;\n pullRequestLink = links.pull ?? undefined;\n usersLink = links.user ?? undefined;\n }\n } else {\n let {links} = await getInfoFromPullRequest({\n repo: String(options.repo),\n pull: pullRequestFromSummary,\n });\n\n if (commitFromSummary) {\n links = {\n ...links,\n commit: `[\\`${commitFromSummary}\\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,\n };\n }\n\n commitLink = links.commit ?? undefined;\n pullRequestLink = links.pull;\n usersLink = links.user ?? undefined;\n }\n\n if (usersFromSummary.length) {\n usersLink = usersFromSummary\n .map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)\n .join(', ');\n }\n\n let prefix = [\n pullRequestLink ? ` ${pullRequestLink}` : '',\n commitLink ? ` ${commitLink}` : '',\n usersLink ? ` (${usersLink})` : '',\n ].join('');\n\n return `\\n\\n-${prefix ? `${prefix} –` : ''} ${firstLine}\\n${lines\n .map((line) => ` ${line}`)\n .join('\\n')}`;\n}\n"],"names":["getReleaseLine","changeset","type","options","repo","Error","pullRequestFromSummary","commitFromSummary","usersFromSummary","replacedChangelog","summary","replace","_","rawPullRequest","pullRequest","Number","isNaN","commit","user","push","trim","firstLine","lines","split","map","line","trimEnd","commitLink","pullRequestLink","usersLink","undefined","commitToFetchFrom","links","getInfo","String","pull","getInfoFromPullRequest","length","userFromSummary","join","prefix"],"mappings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EAAE,EAAEA,eAAe,CAAC,qBAAqB,EAAEA,eAAe,CAAC,CAAC,CAAC,CAAC,CACxFC,IAAI,CAAC,IAAI,CAAC,CAAC;KACf;IAED,IAAIC,MAAM,GAAG;QACXZ,eAAe,GAAG,CAAC,CAAC,EAAEA,eAAe,CAAC,CAAC,GAAG,EAAE;QAC5CD,UAAU,GAAG,CAAC,CAAC,EAAEA,UAAU,CAAC,CAAC,GAAG,EAAE;QAClCE,SAAS,GAAG,CAAC,EAAE,EAAEA,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE;KACnC,CAACU,IAAI,CAAC,EAAE,CAAC,AAAC;IAEX,OAAO,CAAC,KAAK,EAAEC,MAAM,GAAG,CAAC,EAAEA,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAEnB,SAAS,CAAC,EAAE,EAAEC,KAAK,CAC9DE,GAAG,CAAC,CAACC,IAAI,GAAK,CAAC,EAAE,EAAEA,IAAI,CAAC,CAAC,CAAC,CAC1Bc,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@jakubmazanec/changesets-changelog",
3
+ "version": "1.0.0-20220726001922",
4
+ "description": "Changelog for projects using Changesets.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git@github.com:jakubmazanec/js-tools.git",
8
+ "directory": "packages/eslint-config"
9
+ },
10
+ "license": "MIT",
11
+ "author": "Jakub Mazanec <jakub@mazanec.dev>",
12
+ "sideEffects": false,
13
+ "type": "commonjs",
14
+ "exports": "./dist/changesets-changelog.js",
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "scripts": {
20
+ "build": "swc src -d dist && tsc",
21
+ "clean": "del-cli dist *.tsbuildinfo",
22
+ "format": "prettier . --write --ignore-unknown --ignore-path ../../.prettierignore",
23
+ "lint": "eslint .",
24
+ "test": "jest",
25
+ "typecheck": "tsc --project tsconfig.typecheck.json"
26
+ },
27
+ "dependencies": {
28
+ "@changesets/get-github-info": "0.5.1",
29
+ "dotenv": "^16.0.1"
30
+ },
31
+ "devDependencies": {
32
+ "@changesets/parse": "^0.3.13",
33
+ "@changesets/types": "^5.0.0",
34
+ "@types/node": "^16.11.43"
35
+ },
36
+ "peerDependencies": {
37
+ "eslint": "^8.19.0",
38
+ "prettier": "^2.7.1",
39
+ "typescript": "^4.7.4"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "prettier": {
43
+ "optional": true
44
+ }
45
+ },
46
+ "packageManager": "npm@8.11.0",
47
+ "engines": {
48
+ "node": ">=16.15.0"
49
+ }
50
+ }
@@ -0,0 +1,6 @@
1
+ import {config} from 'dotenv';
2
+
3
+ config();
4
+
5
+ export * from './getDependencyReleaseLine';
6
+ export * from './getReleaseLine';
@@ -0,0 +1,43 @@
1
+ import {getInfo} from '@changesets/get-github-info';
2
+ import type {ModCompWithPackage, NewChangesetWithCommit} from '@changesets/types';
3
+
4
+ export async function getDependencyReleaseLine(
5
+ changesets: NewChangesetWithCommit[],
6
+ updatedDependencies: ModCompWithPackage[],
7
+ options?: Record<string, unknown>,
8
+ ) {
9
+ if (!options?.repo) {
10
+ throw new Error(
11
+ 'Please provide a repo in Changesets config, e.g.:\n"changelog": ["@jakubmazanec/changesets-changelog", { "repo": "org/repo" }]',
12
+ );
13
+ }
14
+
15
+ if (!updatedDependencies.length) {
16
+ return '';
17
+ }
18
+
19
+ const changesetLink = `- Updated dependencies [${(
20
+ await Promise.all(
21
+ changesets.map(async (changeset) => {
22
+ if (changeset.commit) {
23
+ let {links} = await getInfo({
24
+ repo: String(options.repo),
25
+ commit: changeset.commit,
26
+ });
27
+
28
+ return links.commit;
29
+ }
30
+
31
+ return undefined;
32
+ }),
33
+ )
34
+ )
35
+ .filter((_) => _)
36
+ .join(', ')}]:`;
37
+
38
+ let updatedDepenenciesLines = updatedDependencies.map(
39
+ (dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
40
+ );
41
+
42
+ return [changesetLink, ...updatedDepenenciesLines].join('\n');
43
+ }
@@ -0,0 +1,90 @@
1
+ import {getInfo, getInfoFromPullRequest} from '@changesets/get-github-info';
2
+ import type {VersionType, NewChangesetWithCommit} from '@changesets/types';
3
+
4
+ export async function getReleaseLine(
5
+ changeset: NewChangesetWithCommit,
6
+ type: VersionType,
7
+ options?: Record<string, unknown>,
8
+ ) {
9
+ if (!options?.repo) {
10
+ throw new Error(
11
+ 'Please provide a repo in Changesets config, e.g.:\n"changelog": ["@jakubmazanec/changesets-changelog", { "repo": "org/repo" }]',
12
+ );
13
+ }
14
+
15
+ let pullRequestFromSummary: number | undefined;
16
+ let commitFromSummary: string | undefined;
17
+ let usersFromSummary: string[] = [];
18
+ let replacedChangelog = changeset.summary
19
+ .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/gim, (_, rawPullRequest) => {
20
+ let pullRequest = Number(rawPullRequest);
21
+
22
+ if (!Number.isNaN(pullRequest)) {
23
+ pullRequestFromSummary = pullRequest;
24
+ }
25
+
26
+ return '';
27
+ })
28
+ .replace(/^\s*commit:\s*(\S+)/gim, (_, commit: string) => {
29
+ commitFromSummary = commit;
30
+
31
+ return '';
32
+ })
33
+ .replace(/^\s*(?:author|user):\s*@?(\S+)/gim, (_, user: string) => {
34
+ usersFromSummary.push(user);
35
+
36
+ return '';
37
+ })
38
+ .trim();
39
+ let [firstLine, ...lines] = replacedChangelog.split('\n').map((line) => line.trimEnd());
40
+ let commitLink: string | undefined;
41
+ let pullRequestLink: string | undefined;
42
+ let usersLink: string | undefined;
43
+
44
+ if (pullRequestFromSummary === undefined) {
45
+ let commitToFetchFrom = commitFromSummary ?? changeset.commit;
46
+
47
+ if (commitToFetchFrom) {
48
+ let {links} = await getInfo({
49
+ repo: String(options.repo),
50
+ commit: commitToFetchFrom,
51
+ });
52
+
53
+ commitLink = links.commit;
54
+ pullRequestLink = links.pull ?? undefined;
55
+ usersLink = links.user ?? undefined;
56
+ }
57
+ } else {
58
+ let {links} = await getInfoFromPullRequest({
59
+ repo: String(options.repo),
60
+ pull: pullRequestFromSummary,
61
+ });
62
+
63
+ if (commitFromSummary) {
64
+ links = {
65
+ ...links,
66
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
67
+ };
68
+ }
69
+
70
+ commitLink = links.commit ?? undefined;
71
+ pullRequestLink = links.pull;
72
+ usersLink = links.user ?? undefined;
73
+ }
74
+
75
+ if (usersFromSummary.length) {
76
+ usersLink = usersFromSummary
77
+ .map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
78
+ .join(', ');
79
+ }
80
+
81
+ let prefix = [
82
+ pullRequestLink ? ` ${pullRequestLink}` : '',
83
+ commitLink ? ` ${commitLink}` : '',
84
+ usersLink ? ` (${usersLink})` : '',
85
+ ].join('');
86
+
87
+ return `\n\n-${prefix ? `${prefix} –` : ''} ${firstLine}\n${lines
88
+ .map((line) => ` ${line}`)
89
+ .join('\n')}`;
90
+ }