File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,9 @@ export default {
171
171
lineEnding: ' auto' ,
172
172
// Control the line ending. See options at https://github.com/ryanve/eol
173
173
174
+ insertFinalNewline: true ,
175
+ // Insert line ending at the end of output files
176
+
174
177
locales: [' en' , ' fr' ],
175
178
// An array of the locales in your applications
176
179
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ export interface UserConfig {
105
105
default ?: ( SupportedLexer | CustomLexer | LexerConfig ) [ ] ;
106
106
} ;
107
107
lineEnding ?: "auto" | "crlf" | "\r\n" | "cr" | "\r" | "lf" | "\n" ;
108
+ insertFinalNewline ?: boolean ;
108
109
locales ?: string [ ] ;
109
110
namespaceSeparator ?: string | false ;
110
111
output ?: string ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ export default class i18nTransform extends Transform {
30
30
keySeparator : '.' ,
31
31
lexers : { } ,
32
32
lineEnding : 'auto' ,
33
+ insertFinalNewline : true ,
33
34
locales : [ 'en' , 'fr' ] ,
34
35
namespaceSeparator : ':' ,
35
36
pluralSeparator : '_' ,
@@ -403,7 +404,9 @@ export default class i18nTransform extends Transform {
403
404
...this . options . yamlOptions ,
404
405
} )
405
406
} else {
406
- text = JSON . stringify ( contents , null , this . options . indentation ) + '\n'
407
+ text =
408
+ JSON . stringify ( contents , null , this . options . indentation ) +
409
+ ( this . options . insertFinalNewline ? '\n' : '' )
407
410
// Convert non-printable Unicode characters to unicode escape sequence
408
411
// https://unicode.org/reports/tr18/#General_Category_Property
409
412
text = text . replace ( / [ \p{ Z} \p{ Cc} \p{ Cf} ] / gu, ( chr ) => {
Original file line number Diff line number Diff line change @@ -1294,6 +1294,30 @@ describe('parser', () => {
1294
1294
i18nextParser . end ( fakeFile )
1295
1295
} )
1296
1296
1297
+ it ( 'supports insertFinalNewline' , ( done ) => {
1298
+ let result
1299
+ const i18nextParser = new i18nTransform ( {
1300
+ lineEnding : '\r\n' ,
1301
+ insertFinalNewline : false ,
1302
+ } )
1303
+ const fakeFile = new Vinyl ( {
1304
+ contents : Buffer . from ( "t('first')" ) ,
1305
+ path : 'file.js' ,
1306
+ } )
1307
+
1308
+ i18nextParser . on ( 'data' , ( file ) => {
1309
+ if ( file . relative . endsWith ( enLibraryPath ) ) {
1310
+ result = file . contents . toString ( )
1311
+ }
1312
+ } )
1313
+ i18nextParser . once ( 'end' , ( ) => {
1314
+ assert . equal ( result , '{\r\n "first": ""\r\n}' )
1315
+ done ( )
1316
+ } )
1317
+
1318
+ i18nextParser . end ( fakeFile )
1319
+ } )
1320
+
1297
1321
it ( 'parses Trans from js file with lexer override to JsxLexer' , ( done ) => {
1298
1322
let result
1299
1323
const i18nextParser = new i18nTransform ( {
You can’t perform that action at this time.
0 commit comments