File tree Expand file tree Collapse file tree 2 files changed +43
-7
lines changed Expand file tree Collapse file tree 2 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -14,11 +14,28 @@ class RouteStream extends Readable {
14
14
this . modified = data . modified ;
15
15
}
16
16
17
+ // Assume we only accept Buffer, plain object, or string
18
+ _toBuffer ( data ) {
19
+ if ( data instanceof Buffer ) {
20
+ return data ;
21
+ }
22
+ if ( typeof data === 'object' ) {
23
+ data = JSON . stringify ( data ) ;
24
+ }
25
+ if ( typeof data === 'string' ) {
26
+ return Buffer . from ( data ) ; // Assume string is UTF-8 encoded string
27
+ }
28
+ return null ;
29
+ }
30
+
17
31
_read ( ) {
18
32
const data = this . _data ;
19
33
20
34
if ( typeof data !== 'function' ) {
21
- this . push ( data ) ;
35
+ const bufferData = this . _toBuffer ( data ) ;
36
+ if ( bufferData ) {
37
+ this . push ( bufferData ) ;
38
+ }
22
39
this . push ( null ) ;
23
40
return ;
24
41
}
@@ -40,13 +57,11 @@ class RouteStream extends Readable {
40
57
data . on ( 'error' , err => {
41
58
this . emit ( 'error' , err ) ;
42
59
} ) ;
43
- } else if ( data instanceof Buffer || typeof data === 'string' ) {
44
- this . push ( data ) ;
45
- this . push ( null ) ;
46
- } else if ( typeof data === 'object' ) {
47
- this . push ( JSON . stringify ( data ) ) ;
48
- this . push ( null ) ;
49
60
} else {
61
+ const bufferData = this . _toBuffer ( data ) ;
62
+ if ( bufferData ) {
63
+ this . push ( bufferData ) ;
64
+ }
50
65
this . push ( null ) ;
51
66
}
52
67
} ) . catch ( err => {
Original file line number Diff line number Diff line change @@ -261,6 +261,27 @@ describe('generate', () => {
261
261
} ) ;
262
262
} ) ;
263
263
264
+ it ( 'should generate all files when bail option is set to true and no errors' , async ( ) => {
265
+ // Test cases for hexojs/hexo#4499
266
+ hexo . extend . generator . register ( 'resource' , ( ) =>
267
+ [
268
+ {
269
+ path : 'resource-1' ,
270
+ data : 'string'
271
+ } ,
272
+ {
273
+ path : 'resource-2' ,
274
+ data : { }
275
+ } ,
276
+ {
277
+ path : 'resource-3' ,
278
+ data : ( ) => Promise . resolve ( Buffer . from ( 'string' ) )
279
+ }
280
+ ]
281
+ ) ;
282
+ return generate ( { bail : true } ) ;
283
+ } ) ;
284
+
264
285
it ( 'should generate all files even when concurrency is set' , async ( ) => {
265
286
await generate ( { concurrency : 1 } ) ;
266
287
return generate ( { concurrency : 2 } ) ;
You can’t perform that action at this time.
0 commit comments