@@ -30,6 +30,7 @@ import {
3030} from './lib/option-normalization' ;
3131import { getConfigFromPkgJson , getName } from './lib/package-info' ;
3232import { shouldCssModules , cssModulesConfig } from './lib/css-modules' ;
33+ import { EOL } from 'os' ;
3334
3435// Extensions to use when resolving modules
3536const EXTENSIONS = [ '.ts' , '.tsx' , '.js' , '.jsx' , '.es6' , '.es' , '.mjs' ] ;
@@ -403,9 +404,13 @@ function createConfig(options, entry, format, writeMeta) {
403404 const externalTest =
404405 external . length === 0 ? id => false : id => externalPredicate . test ( id ) ;
405406
407+ let endsWithNewLine = false ;
408+
406409 function loadNameCache ( ) {
407410 try {
408- nameCache = JSON . parse ( fs . readFileSync ( getNameCachePath ( ) , 'utf8' ) ) ;
411+ const data = fs . readFileSync ( getNameCachePath ( ) , 'utf8' ) ;
412+ endsWithNewLine = data . endsWith ( EOL ) ;
413+ nameCache = JSON . parse ( data ) ;
409414 // mangle.json can contain a "minify" field, same format as the pkg.mangle:
410415 if ( nameCache . minify ) {
411416 minifyOptions = Object . assign (
@@ -618,7 +623,11 @@ function createConfig(options, entry, format, writeMeta) {
618623 if ( writeMeta && nameCache ) {
619624 fs . writeFile (
620625 getNameCachePath ( ) ,
621- JSON . stringify ( nameCache , null , 2 ) ,
626+ JSON . stringify (
627+ endsWithNewLine ? `${ nameCache } ${ EOL } ` : nameCache ,
628+ null ,
629+ 2 ,
630+ ) ,
622631 ( ) => { } ,
623632 ) ;
624633 }
0 commit comments