File tree 1 file changed +11
-3
lines changed
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";
5
5
import * as crypto from "crypto" ;
6
6
import * as shelljs from "shelljs" ;
7
7
import { parseJson } from "./helpers" ;
8
+ import { PACKAGE_JSON_FILE_NAME } from "../constants" ;
9
+ import { EOL } from "os" ;
8
10
import stringifyPackage = require( "stringify-package" ) ;
9
11
import detectNewline = require( "detect-newline" ) ;
10
12
@@ -207,10 +209,16 @@ export class FileSystem implements IFileSystem {
207
209
space = this . getIndentationCharacter ( filename ) ;
208
210
}
209
211
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
+ }
213
219
stringifiedData = stringifyPackage ( data , space , newline ) ;
220
+ } else {
221
+ stringifiedData = JSON . stringify ( data , null , space ) ;
214
222
}
215
223
216
224
return this . writeFile ( filename , stringifiedData , encoding ) ;
You can’t perform that action at this time.
0 commit comments