File tree 1 file changed +17
-0
lines changed
packages/angular_devkit/core/src/workspace/json
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
import { applyEdits , modify } from 'jsonc-parser' ;
10
+ import { EOL } from 'node:os' ;
10
11
import { JsonObject , JsonValue } from '../../json' ;
11
12
import { ProjectDefinition , TargetDefinition , WorkspaceDefinition } from '../definitions' ;
12
13
import { WorkspaceHost } from '../host' ;
@@ -163,6 +164,7 @@ function updateJsonWorkspace(metadata: JsonWorkspaceMetadata): string {
163
164
formattingOptions : {
164
165
insertSpaces : true ,
165
166
tabSize : 2 ,
167
+ eol : getEOL ( content ) ,
166
168
} ,
167
169
} ) ;
168
170
@@ -171,3 +173,18 @@ function updateJsonWorkspace(metadata: JsonWorkspaceMetadata): string {
171
173
172
174
return content ;
173
175
}
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