diff --git a/.changeset/breezy-snakes-warn.md b/.changeset/breezy-snakes-warn.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/breezy-snakes-warn.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/.changeset/config.json b/.changeset/config.json index f8b7c1cf9ee..c494a6d4edb 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,11 +1,6 @@ { "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", - "changelog": [ - "@changesets/changelog-github", - { - "repo": "FuelLabs/fuels-ts" - } - ], + "changelog": "../scripts/changelog.js", "commit": false, "fixed": [["@fuel-ts/*", "fuels"]], "linked": [], diff --git a/package.json b/package.json index f4eb7720a03..4f39b9d1aa1 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ }, "homepage": "https://github.com/FuelLabs/fuels-ts#readme", "devDependencies": { - "@changesets/changelog-github": "^0.4.7", "@changesets/cli": "^2.25.0", + "@changesets/get-github-info": "^0.5.2", "@ethersproject/bytes": "^5.7.0", "@jest/types": "^29.5.0", "@types/jest": "^29.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 149a7847abf..3e85a521ead 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,12 +4,12 @@ importers: .: devDependencies: - '@changesets/changelog-github': - specifier: ^0.4.7 - version: 0.4.7 '@changesets/cli': specifier: ^2.25.0 version: 2.25.2 + '@changesets/get-github-info': + specifier: ^0.5.2 + version: 0.5.2 '@ethersproject/bytes': specifier: ^5.7.0 version: 5.7.0 @@ -1816,16 +1816,6 @@ packages: '@changesets/types': 5.2.0 dev: true - /@changesets/changelog-github@0.4.7: - resolution: {integrity: sha512-UUG5sKwShs5ha1GFnayUpZNcDGWoY7F5XxhOEHS62sDPOtoHQZsG3j1nC5RxZ3M1URHA321cwVZHeXgu99Y3ew==} - dependencies: - '@changesets/get-github-info': 0.5.1 - '@changesets/types': 5.2.0 - dotenv: 8.6.0 - transitivePeerDependencies: - - encoding - dev: true - /@changesets/cli@2.25.2: resolution: {integrity: sha512-ACScBJXI3kRyMd2R8n8SzfttDHi4tmKSwVwXBazJOylQItSRSF4cGmej2E4FVf/eNfGy6THkL9GzAahU9ErZrA==} hasBin: true @@ -1893,8 +1883,8 @@ packages: semver: 5.7.1 dev: true - /@changesets/get-github-info@0.5.1: - resolution: {integrity: sha512-w2yl3AuG+hFuEEmT6j1zDlg7GQLM/J2UxTmk0uJBMdRqHni4zXGe/vUlPfLom5KfX3cRfHc0hzGvloDPjWFNZw==} + /@changesets/get-github-info@0.5.2: + resolution: {integrity: sha512-JppheLu7S114aEs157fOZDjFqUDpm7eHdq5E8SSR0gUBTEK0cNSHsrSR5a66xs0z3RWuo46QvA3vawp8BxDHvg==} dependencies: dataloader: 1.4.0 node-fetch: 2.6.7 @@ -5493,6 +5483,17 @@ packages: ms: 2.0.0 dev: true + /debug@3.2.7: + resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.3 + dev: true + /debug@3.2.7(supports-color@5.5.0): resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} peerDependencies: @@ -5631,11 +5632,6 @@ packages: engines: {node: '>=12'} dev: true - /dotenv@8.6.0: - resolution: {integrity: sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==} - engines: {node: '>=10'} - dev: true - /dotenv@9.0.2: resolution: {integrity: sha512-I9OvvrHp4pIARv4+x9iuewrWycX6CcZtoAu1XrzPxc5UygMJXJZYmBsynku8IkrJwgypE5DGNjDPmPRhDCptUg==} engines: {node: '>=10'} @@ -6075,7 +6071,7 @@ packages: /eslint-import-resolver-node@0.3.6: resolution: {integrity: sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==} dependencies: - debug: 3.2.7(supports-color@5.5.0) + debug: 3.2.7 resolve: 1.22.1 transitivePeerDependencies: - supports-color @@ -6103,7 +6099,7 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 5.44.0(eslint@8.28.0)(typescript@4.9.3) - debug: 3.2.7(supports-color@5.5.0) + debug: 3.2.7 eslint: 8.28.0 eslint-import-resolver-node: 0.3.6 transitivePeerDependencies: diff --git a/scripts/changelog.js b/scripts/changelog.js new file mode 100644 index 00000000000..864c0fa97e5 --- /dev/null +++ b/scripts/changelog.js @@ -0,0 +1,107 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +/** + * This script was copied from https://github.com/formidablelabs/urql + */ +const { getInfo } = require('@changesets/get-github-info'); +const { config } = require('dotenv'); + +config(); + +const REPO = 'FuelLabs/fuels-ts'; +const SEE_LINE = /^See:\s*(.*)/i; +const TRAILING_CHAR = /[.;:]$/g; +const listFormatter = new Intl.ListFormat('en-US'); + +const getSummaryLines = (cs) => { + const lines = cs.summary + .trim() + .split(/[\r\n]+/) + .map((l) => l.trim()) + .filter(Boolean); + const size = lines.length; + if (size > 0) { + lines[size - 1] = lines[size - 1].replace(TRAILING_CHAR, ''); + } + + return lines; +}; + +/** Creates a "(See X)" string from a template */ +const templateSeeRef = (links) => { + const humanReadableLinks = links.filter(Boolean).map((link) => { + if (typeof link === 'string') return link; + return link.pull || link.commit; + }); + + const size = humanReadableLinks.length; + if (size === 0) return ''; + + const str = listFormatter.format(humanReadableLinks); + return `(See ${str})`; +}; + +const changelogFunctions = { + // eslint-disable-next-line @typescript-eslint/require-await + getDependencyReleaseLine: async () => '', + getReleaseLine: async (changeset, _type) => { + let pull; + let commit; + let user; + + const lines = getSummaryLines(changeset); + const prLineIndex = lines.findIndex((line) => SEE_LINE.test(line)); + if (prLineIndex > -1) { + const match = lines[prLineIndex].match(SEE_LINE); + pull = (match && match[1].trim()) || undefined; + lines.splice(prLineIndex, 1); + } + + const [firstLine, ...futureLines] = lines; + + if (changeset.commit && !pull) { + const { links } = await getInfo({ + repo: REPO, + commit: changeset.commit, + }); + + pull = links.pull || undefined; + commit = links.commit || undefined; + user = links.user || undefined; + } + + let annotation = ''; + if (/^\s*fix/i.test(firstLine)) { + annotation = '🐞 '; + } + if (/^\s*feat/i.test(firstLine)) { + annotation = '✨ '; + } + if (/^\s*style/i.test(firstLine)) { + annotation = '💅🏻 '; + } + if (/^\s*doc/i.test(firstLine)) { + annotation = '📃 '; + } + + let str = `- ${annotation}${firstLine}`; + if (futureLines.length > 0) { + str += `\n${futureLines.map((l) => ` ${l}`).join('\n')}`; + } + + if (user) { + str += `, by ${user}`; + } + + if (pull || commit) { + const seeRef = templateSeeRef([pull || commit]); + if (seeRef) str += ` ${seeRef}`; + } + + return str; + }, +}; + +module.exports = { + ...changelogFunctions, + default: changelogFunctions, +};