@@ -11,12 +11,12 @@ import { execSync } from 'child_process';
1111import * as fs from 'fs' ;
1212import * as path from 'path' ;
1313import * as semver from 'semver' ;
14+ import { Transform } from 'stream' ;
1415import { packages } from '../lib/packages' ;
1516
1617const conventionalCommitsParser = require ( 'conventional-commits-parser' ) ;
1718const ghGot = require ( 'gh-got' ) ;
1819const gitRawCommits = require ( 'git-raw-commits' ) ;
19- const through = require ( 'through2' ) ;
2020const changelogTemplate = require ( './templates/changelog' ) . default ;
2121
2222export 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 ( / h t t p s ? : \/ \/ g i t h u b .c o m \/ ( .* ?) \/ i s s u e s \/ ( \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 ( / h t t p s ? : \/ \/ g i t h u b .c o m \/ ( .* ?) \/ i s s u e s \/ ( \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 ( / t a g : ( .* ) / ) ;
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 ( / t a g : ( .* ) / ) ;
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