@@ -3,12 +3,12 @@ import { IRule, Replacement } from 'tslint';
33import { tsquery } from '@phenomnomnominal/tsquery' ;
44import { Tree , SchematicContext , isContentAction } from '@angular-devkit/schematics' ;
55import { LoggerApi } from '@angular-devkit/core/src/logger' ;
6- import { PreferMappedImportsRule } from '@nativescript/tslint-rules' ;
7- import { parseCompilerOptions } from '@nativescript/tslint-rules/dist/preferMappedImportsRule' ;
86
9- import { parseTsConfigFile } from '../ts-utils' ;
7+ import { getCompilerOptions } from '../ts-utils' ;
108import { getFileContents } from '../utils' ;
119import { getTsConfigFromProject } from '../angular-project-parser' ;
10+ import { getMappedImportsRule } from '../mapped-imports-rule-utils' ;
11+
1212import { Schema as ConvertRelativeImportsSchema } from './schema' ;
1313
1414// TODO: add link to the docs
@@ -25,7 +25,7 @@ export default function(options: ConvertRelativeImportsSchema) {
2525 return tree ;
2626 }
2727
28- const tsConfigPath = getTsConfigPath ( tree , options . project , logger ) || 'tsconfig.json' ;
28+ const tsConfigPath = getTsConfigFromProject ( tree , options . project ) || 'tsconfig.json' ;
2929 const compilerOptions = getCompilerOptions ( tree , tsConfigPath ) ;
3030
3131 if ( ! compilerOptions ) {
@@ -61,7 +61,7 @@ function fixImports(
6161 filePaths : Set < string > ,
6262 compilerOptions : ts . CompilerOptions ,
6363) : Tree {
64- const rule = generateTslintRule ( compilerOptions ) ;
64+ const rule = getMappedImportsRule ( compilerOptions ) ;
6565 if ( ! rule ) {
6666 logger . debug ( 'Convert Relative Imports: Failed to extract remap options from the TS compiler options.' ) ;
6767 logger . error ( conversionFailureMessage ) ;
@@ -91,49 +91,3 @@ function applyTslintRuleFixes(rule: IRule, filePath: string, fileContent: string
9191
9292 return fixedContent ;
9393}
94-
95- function generateTslintRule ( compilerOptions : ts . CompilerOptions ) : PreferMappedImportsRule | undefined {
96- const remapOptions = parseCompilerOptions ( compilerOptions ) ;
97- if ( ! remapOptions ) {
98- return ;
99- }
100-
101- const tslintRuleArguments = {
102- prefix : remapOptions . prefix ,
103- 'prefix-mapped-to' : remapOptions . prefixMappedTo ,
104- 'base-url' : remapOptions . baseUrl ,
105- } ;
106-
107- const rule = new PreferMappedImportsRule ( {
108- ruleArguments : [ tslintRuleArguments ] ,
109- ruleName : 'prefer-mapped-imports' ,
110- ruleSeverity : 'error' ,
111- disabledIntervals : [ ] ,
112- } ) ;
113-
114- return rule ;
115- }
116-
117- function getTsConfigPath ( tree : Tree , projectName : string , logger : LoggerApi ) : string | undefined {
118- let tsConfig : string | undefined ;
119- try {
120- tsConfig = getTsConfigFromProject ( tree , projectName ) ;
121- } catch ( e ) {
122- logger . error ( e ) ;
123- }
124-
125- return tsConfig ;
126- }
127-
128- function getCompilerOptions ( tree : Tree , tsConfigPath : string )
129- : ts . CompilerOptions | undefined {
130-
131- const tsConfigObject = parseTsConfigFile ( tree , tsConfigPath ) ;
132- if ( ! tsConfigObject ) {
133- return ;
134- }
135-
136- const compilerOptions = tsConfigObject . options ;
137-
138- return compilerOptions ;
139- }
0 commit comments