File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
packages/angular_devkit/core/src/workspace/json Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 77 */
88
99import { applyEdits , modify } from 'jsonc-parser' ;
10+ import { EOL } from 'node:os' ;
1011import { JsonObject , JsonValue } from '../../json' ;
1112import { ProjectDefinition , TargetDefinition , WorkspaceDefinition } from '../definitions' ;
1213import { WorkspaceHost } from '../host' ;
@@ -163,6 +164,7 @@ function updateJsonWorkspace(metadata: JsonWorkspaceMetadata): string {
163164 formattingOptions : {
164165 insertSpaces : true ,
165166 tabSize : 2 ,
167+ eol : getEOL ( content ) ,
166168 } ,
167169 } ) ;
168170
@@ -171,3 +173,18 @@ function updateJsonWorkspace(metadata: JsonWorkspaceMetadata): string {
171173
172174 return content ;
173175}
176+
177+ function getEOL ( content : string ) : string {
178+ const CRLF = '\r\n' ;
179+ const LF = '\n' ;
180+ const newlines = content . match ( / (?: \r ? \n ) / g) ;
181+
182+ if ( newlines ?. length ) {
183+ const crlf = newlines . filter ( ( l ) => l === CRLF ) . length ;
184+ const lf = newlines . length - crlf ;
185+
186+ return crlf > lf ? CRLF : LF ;
187+ }
188+
189+ return EOL ;
190+ }
You can’t perform that action at this time.
0 commit comments