Skip to content

Commit 419a775

Browse files
committed
build: use simplified stream construction in changelog script
Node.js now provides simplified stream construction capabilities which removes the need for the `through2` dependency. This change allows for the removal of the `through2` development dependency which was otherwise unused.
1 parent 34e66ff commit 419a775

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@
222222
"terser": "5.7.1",
223223
"terser-webpack-plugin": "5.1.4",
224224
"text-table": "0.2.0",
225-
"through2": "^4.0.0",
226225
"tree-kill": "1.2.2",
227226
"ts-api-guardian": "0.6.0",
228227
"ts-node": "^10.0.0",

scripts/changelog.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { execSync } from 'child_process';
1111
import * as fs from 'fs';
1212
import * as path from 'path';
1313
import * as semver from 'semver';
14+
import { Transform } from 'stream';
1415
import { packages } from '../lib/packages';
1516

1617
const conventionalCommitsParser = require('conventional-commits-parser');
1718
const ghGot = require('gh-got');
1819
const gitRawCommits = require('git-raw-commits');
19-
const through = require('through2');
2020
const changelogTemplate = require('./templates/changelog').default;
2121

2222
export interface ChangelogOptions {
@@ -77,23 +77,27 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) {
7777
}
7878

7979
return new Promise((resolve) => {
80-
(gitRawCommits({
81-
from: args.from,
82-
to: args.to || 'HEAD',
83-
format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n',
84-
}) as NodeJS.ReadStream)
80+
(
81+
gitRawCommits({
82+
from: args.from,
83+
to: args.to || 'HEAD',
84+
format: '%B%n-hash-%n%H%n-gitTags-%n%D%n-committerDate-%n%ci%n-authorName-%n%aN%n',
85+
}) as NodeJS.ReadStream
86+
)
8587
.on('error', (err) => {
8688
logger.fatal('An error happened: ' + err.message);
8789
process.exit(1);
8890
})
8991
.pipe(
90-
through((chunk: Buffer, enc: string, callback: Function) => {
91-
// Replace github URLs with `@XYZ#123`
92-
const commit = chunk
93-
.toString('utf-8')
94-
.replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2');
95-
96-
callback(undefined, Buffer.from(commit));
92+
new Transform({
93+
transform(chunk, encoding, callback) {
94+
// Replace github URLs with `@XYZ#123`
95+
const commit = chunk
96+
.toString('utf-8')
97+
.replace(/https?:\/\/github.com\/(.*?)\/issues\/(\d+)/g, '@$1#$2');
98+
99+
callback(undefined, Buffer.from(commit));
100+
},
97101
}),
98102
)
99103
.pipe(
@@ -106,22 +110,25 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) {
106110
}),
107111
)
108112
.pipe(
109-
through.obj((chunk: JsonObject, _: string, cb: Function) => {
110-
try {
111-
const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/);
112-
const tags = maybeTag && maybeTag[1].split(/,/g);
113-
chunk['tags'] = tags;
114-
115-
if (tags && tags.find((x) => x == args.to)) {
116-
toSha = chunk.hash as string;
117-
}
118-
if (!cherryPicked.has(chunk.hash as string)) {
119-
commits.push(chunk);
113+
new Transform({
114+
objectMode: true,
115+
transform(chunk: JsonObject, encoding, callback) {
116+
try {
117+
const maybeTag = chunk.gitTags && (chunk.gitTags as string).match(/tag: (.*)/);
118+
const tags = maybeTag && maybeTag[1].split(/,/g);
119+
chunk['tags'] = tags;
120+
121+
if (tags && tags.find((x) => x == args.to)) {
122+
toSha = chunk.hash as string;
123+
}
124+
if (!cherryPicked.has(chunk.hash as string)) {
125+
commits.push(chunk);
126+
}
127+
callback();
128+
} catch (err) {
129+
callback(err);
120130
}
121-
cb();
122-
} catch (err) {
123-
cb(err);
124-
}
131+
},
125132
}),
126133
)
127134
.on('finish', resolve);

0 commit comments

Comments
 (0)