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 {
171171 lineEnding: ' auto' ,
172172 // Control the line ending. See options at https://github.com/ryanve/eol
173173
174+ insertFinalNewline: true ,
175+ // Insert line ending at the end of output files
176+
174177 locales: [' en' , ' fr' ],
175178 // An array of the locales in your applications
176179
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ export interface UserConfig {
105105 default ?: ( SupportedLexer | CustomLexer | LexerConfig ) [ ] ;
106106 } ;
107107 lineEnding ?: "auto" | "crlf" | "\r\n" | "cr" | "\r" | "lf" | "\n" ;
108+ insertFinalNewline ?: boolean ;
108109 locales ?: string [ ] ;
109110 namespaceSeparator ?: string | false ;
110111 output ?: string ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ export default class i18nTransform extends Transform {
3030 keySeparator : '.' ,
3131 lexers : { } ,
3232 lineEnding : 'auto' ,
33+ insertFinalNewline : true ,
3334 locales : [ 'en' , 'fr' ] ,
3435 namespaceSeparator : ':' ,
3536 pluralSeparator : '_' ,
@@ -403,7 +404,9 @@ export default class i18nTransform extends Transform {
403404 ...this . options . yamlOptions ,
404405 } )
405406 } 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' : '' )
407410 // Convert non-printable Unicode characters to unicode escape sequence
408411 // https://unicode.org/reports/tr18/#General_Category_Property
409412 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', () => {
12941294 i18nextParser . end ( fakeFile )
12951295 } )
12961296
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+
12971321 it ( 'parses Trans from js file with lexer override to JsxLexer' , ( done ) => {
12981322 let result
12991323 const i18nextParser = new i18nTransform ( {
You can’t perform that action at this time.
0 commit comments