@@ -3,11 +3,12 @@ import simpleGit, { SimpleGit } from 'simple-git';
33import ts from 'typescript' ;
44
55import { getConfig } from '../config' ;
6+ import { detectLineEnding } from '../helpers/line-ending-detector' ;
67import { log } from '../helpers/log' ;
78
8- import { collectNonImportNodes } from './collect-non-import-nodes' ;
99import { categorizeImportLiterals } from './categorize-imports' ;
1010import { collectImportNodes } from './collect-import-nodes' ;
11+ import { collectNonImportNodes } from './collect-non-import-nodes' ;
1112import { formatImportStatements } from './format-import-statements' ;
1213import { getImportStatementMap } from './get-import-statement-map' ;
1314import { sortImportCategories } from './sort-import-categories' ;
@@ -37,6 +38,7 @@ export async function optimizeImports(filePath: string): Promise<string> {
3738 }
3839
3940 let fileContent = readFileSync ( filePath ) . toString ( ) ;
41+ const lineEnding = detectLineEnding ( fileContent ) ;
4042 const { staged, autoAdd, dryRun } = getConfig ( ) ;
4143 if ( / \/ [ / * ] \s * i m p o r t - c o n d u c t o r - s k i p / . test ( fileContent ) ) {
4244 log ( 'gray' , filePath , 'skipped (via comment)' ) ;
@@ -58,7 +60,7 @@ export async function optimizeImports(filePath: string): Promise<string> {
5860
5961 const categorizedImports = categorizeImportLiterals ( importStatementMap ) ;
6062 const sortedAndCategorizedImports = sortImportCategories ( categorizedImports ) ;
61- let updatedContent = formatImportStatements ( sortedAndCategorizedImports ) ;
63+ let updatedContent = formatImportStatements ( sortedAndCategorizedImports , lineEnding ) ;
6264
6365 const lastImport = importNodes . pop ( ) ;
6466 const contentWithoutImportStatements = fileContent . slice ( lastImport . end ) ;
0 commit comments