@@ -11,12 +11,12 @@ import { execSync } from 'child_process';
11
11
import * as fs from 'fs' ;
12
12
import * as path from 'path' ;
13
13
import * as semver from 'semver' ;
14
+ import { Transform } from 'stream' ;
14
15
import { packages } from '../lib/packages' ;
15
16
16
17
const conventionalCommitsParser = require ( 'conventional-commits-parser' ) ;
17
18
const ghGot = require ( 'gh-got' ) ;
18
19
const gitRawCommits = require ( 'git-raw-commits' ) ;
19
- const through = require ( 'through2' ) ;
20
20
const changelogTemplate = require ( './templates/changelog' ) . default ;
21
21
22
22
export interface ChangelogOptions {
@@ -77,23 +77,27 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) {
77
77
}
78
78
79
79
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
+ )
85
87
. on ( 'error' , ( err ) => {
86
88
logger . fatal ( 'An error happened: ' + err . message ) ;
87
89
process . exit ( 1 ) ;
88
90
} )
89
91
. 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
+ } ,
97
101
} ) ,
98
102
)
99
103
. pipe (
@@ -106,22 +110,25 @@ export default async function (args: ChangelogOptions, logger: logging.Logger) {
106
110
} ) ,
107
111
)
108
112
. 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 ) ;
120
130
}
121
- cb ( ) ;
122
- } catch ( err ) {
123
- cb ( err ) ;
124
- }
131
+ } ,
125
132
} ) ,
126
133
)
127
134
. on ( 'finish' , resolve ) ;
0 commit comments