diff --git a/packages/tsconfig-references/src/index.ts b/packages/tsconfig-references/src/index.ts index 5bcd95a..d7ab57c 100644 --- a/packages/tsconfig-references/src/index.ts +++ b/packages/tsconfig-references/src/index.ts @@ -13,6 +13,7 @@ interface TsReference { interface TsConfig { indent: string; + newLineEOF: string; references?: TsReference[]; [key: string]: unknown; } @@ -29,15 +30,19 @@ async function readTsConfig( return { ...JSON.parse(content), indent: detectIndent(content).indent, + newLineEOF: getNewLineAtEOF(content), }; } async function writeTsConfig( workspace: Workspace, - { indent, ...tsConfig }: TsConfig, + { indent, newLineEOF, ...tsConfig }: TsConfig, ): Promise { const path = getTsConfigPath(workspace); - await xfs.writeFilePromise(path, JSON.stringify(tsConfig, null, indent)); + await xfs.writeFilePromise( + path, + JSON.stringify(tsConfig, null, indent) + newLineEOF, + ); } async function isTsWorkspace(workspace: Workspace): Promise { @@ -120,3 +125,17 @@ const plugin: Plugin = { }; export default plugin; + +function getNewLineAtEOF(input: string) { + const length = input.length; + + if (input[length - 1] === '\n') { + if (input[length - 2] === '\r') { + return '\r\n'; + } + + return '\n'; + } + + return ''; +}