File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import * as injector from "./yok";
55import * as crypto from "crypto" ;
66import * as shelljs from "shelljs" ;
77import { parseJson } from "./helpers" ;
8+ import { PACKAGE_JSON_FILE_NAME } from "../constants" ;
9+ import { EOL } from "os" ;
810import stringifyPackage = require( "stringify-package" ) ;
911import detectNewline = require( "detect-newline" ) ;
1012
@@ -207,10 +209,16 @@ export class FileSystem implements IFileSystem {
207209 space = this . getIndentationCharacter ( filename ) ;
208210 }
209211
210- let stringifiedData = JSON . stringify ( data , null , space ) ;
211- if ( path . basename ( filename ) === "package.json" ) {
212- const newline = detectNewline ( stringifiedData ) ;
212+ let stringifiedData ;
213+ if ( path . basename ( filename ) === PACKAGE_JSON_FILE_NAME ) {
214+ let newline = EOL ;
215+ if ( fs . existsSync ( filename ) ) {
216+ const existingFile = this . readText ( filename ) ;
217+ newline = detectNewline ( existingFile ) ;
218+ }
213219 stringifiedData = stringifyPackage ( data , space , newline ) ;
220+ } else {
221+ stringifiedData = JSON . stringify ( data , null , space ) ;
214222 }
215223
216224 return this . writeFile ( filename , stringifiedData , encoding ) ;
You can’t perform that action at this time.
0 commit comments