Skip to content

Commit 3dc4db7

Browse files
committed
fix(@angular-devkit/core): retain existing EOL when updating workspace config
This commit updates the JSON utility to retain the existing EOF when updating the workspace config. (cherry picked from commit d77c005)
1 parent a5c339e commit 3dc4db7

File tree

1 file changed

+17
-0
lines changed
  • packages/angular_devkit/core/src/workspace/json

1 file changed

+17
-0
lines changed

packages/angular_devkit/core/src/workspace/json/writer.ts

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { applyEdits, modify } from 'jsonc-parser';
10+
import { EOL } from 'node:os';
1011
import { JsonObject, JsonValue } from '../../json';
1112
import { ProjectDefinition, TargetDefinition, WorkspaceDefinition } from '../definitions';
1213
import { 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+
}

0 commit comments

Comments
 (0)