diff --git a/package.json b/package.json index e4cc80f72970..c2c9f6b46453 100644 --- a/package.json +++ b/package.json @@ -222,7 +222,6 @@ "terser": "5.7.1", "terser-webpack-plugin": "5.1.4", "text-table": "0.2.0", - "through2": "^4.0.0", "tree-kill": "1.2.2", "ts-api-guardian": "0.6.0", "ts-node": "^10.0.0", diff --git a/scripts/changelog.ts b/scripts/changelog.ts index 72230ab9bf8f..17ac5a5260cf 100644 --- a/scripts/changelog.ts +++ b/scripts/changelog.ts @@ -11,12 +11,12 @@ import { execSync } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; import * as semver from 'semver'; +import { Transform } from 'stream'; import { packages } from '../lib/packages'; const conventionalCommitsParser = require('conventional-commits-parser'); const ghGot = require('gh-got'); const gitRawCommits = require('git-raw-commits'); -const through = require('through2'); const changelogTemplate = require('./templates/changelog').default; export interface ChangelogOptions { @@ -77,23 +77,27 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) { } return new Promise((resolve) => { - (gitRawCommits({ - from: args.from, - to: args.to || 'HEAD', - format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n', - }) as NodeJS.ReadStream) + ( + gitRawCommits({ + from: args.from, + to: args.to || 'HEAD', + format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n', + }) as NodeJS.ReadStream + ) .on('error', (err) => { logger.fatal('An error happened: ' + err.message); process.exit(1); }) .pipe( - through((chunk: Buffer, enc: string, callback: Function) => { - // Replace github URLs with `@XYZ#123` - const commit = chunk - .toString('utf-8') - .replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2'); - - callback(undefined, Buffer.from(commit)); + new Transform({ + transform(chunk, encoding, callback) { + // Replace github URLs with `@XYZ#123` + const commit = chunk + .toString('utf-8') + .replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2'); + + callback(undefined, Buffer.from(commit)); + }, }), ) .pipe( @@ -106,22 +110,25 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) { }), ) .pipe( - through.obj((chunk: JsonObject, _: string, cb: Function) => { - try { - const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/); - const tags = maybeTag && maybeTag[1].split(/,/g); - chunk['tags'] = tags; - - if (tags && tags.find((x) => x == args.to)) { - toSha = chunk.hash as string; - } - if (!cherryPicked.has(chunk.hash as string)) { - commits.push(chunk); + new Transform({ + objectMode: true, + transform(chunk: JsonObject, encoding, callback) { + try { + const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/); + const tags = maybeTag && maybeTag[1].split(/,/g); + chunk['tags'] = tags; + + if (tags && tags.find((x) => x == args.to)) { + toSha = chunk.hash as string; + } + if (!cherryPicked.has(chunk.hash as string)) { + commits.push(chunk); + } + callback(); + } catch (err) { + callback(err); } - cb(); - } catch (err) { - cb(err); - } + }, }), ) .on('finish', resolve);