@@ -10,7 +10,7 @@ var __migrations = [
1010
1111function migrateProject ( tsConfig , tsconfigPath , projectDir ) {
1212 var displayableTsconfigPath = path . relative ( projectDir , tsconfigPath ) ;
13- __migrations . forEach ( function ( migration ) {
13+ __migrations . forEach ( function ( migration ) {
1414 migration ( tsConfig , displayableTsconfigPath , projectDir ) ;
1515 } ) ;
1616}
@@ -32,7 +32,7 @@ function migrateTsConfig(tsconfigPath, projectDir) {
3232 fs . writeFileSync ( tsconfigPath , JSON . stringify ( existingConfig , null , 4 ) ) ;
3333 }
3434
35- withTsConfig ( function ( existingConfig ) {
35+ withTsConfig ( function ( existingConfig ) {
3636 migrateProject ( existingConfig , displayableTsconfigPath , projectDir ) ;
3737 } ) ;
3838}
@@ -54,47 +54,17 @@ function addIterableToAngularProjects(existingConfig, displayableTsconfigPath, p
5454 var dependencies = packageJson . dependencies || [ ] ;
5555
5656 var hasAngular = Object . keys ( dependencies ) . includes ( "nativescript-angular" ) ;
57- var hasRelevantAngularVersion = / [ 4 - 9 ] \. \d + \. \d + / i. test ( dependencies [ "@angular/core" ] ) ;
58- if ( hasAngular && hasRelevantAngularVersion ) {
59- console . log ( "Adding 'es2015.iterable' lib to tsconfig.json..." ) ;
57+ if ( hasAngular ) {
58+ console . log ( "Adding 'es2015.iterable' lib to tsconfig.json..." ) ;
6059 addTsLib ( existingConfig , "es2015.iterable" ) ;
6160 }
6261}
6362
64- function hasModules30 ( projectDir ) {
65- function relevantModulesVersion ( version ) {
66- return / [ 3 - 9 ] \. \d + \. \d + / i. test ( version ) ;
67- }
68-
69- function hasRelevantModulesDependency ( ) {
70- var packageJsonPath = path . join ( projectDir , "package.json" ) ;
71- var packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath ) ) ;
72- var dependencies = packageJson . dependencies || [ ] ;
73-
74- return relevantModulesVersion ( dependencies [ "tns-core-modules" ] ) ;
75- }
76-
77- function hasRelevantModulesPackage ( ) {
78- var packageJsonPath = path . join ( projectDir , "node_modules" , "tns-core-modules" , "package.json" ) ;
79- if ( ! fs . existsSync ( packageJsonPath ) ) {
80- return false ;
81- }
82-
83- var packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath ) ) ;
84- return relevantModulesVersion ( packageJson . version ) ;
85- }
86-
87- return hasRelevantModulesDependency ( ) || hasRelevantModulesPackage ( ) ;
88- }
89- exports . hasModules30 = hasModules30 ;
90-
9163function addDomLibs ( existingConfig , displayableTsconfigPath , projectDir ) {
92- if ( hasModules30 ( projectDir ) ) {
93- console . log ( "Adding 'es6' lib to tsconfig.json..." ) ;
94- addTsLib ( existingConfig , "es6" ) ;
95- console . log ( "Adding 'dom' lib to tsconfig.json..." ) ;
96- addTsLib ( existingConfig , "dom" ) ;
97- }
64+ console . log ( "Adding 'es6' lib to tsconfig.json..." ) ;
65+ addTsLib ( existingConfig , "es6" ) ;
66+ console . log ( "Adding 'dom' lib to tsconfig.json..." ) ;
67+ addTsLib ( existingConfig , "dom" ) ;
9868}
9969
10070function addTsLib ( existingConfig , libName ) {
@@ -103,31 +73,29 @@ function addTsLib(existingConfig, libName) {
10373 if ( ! options . lib ) {
10474 options . lib = [ ] ;
10575 }
106- if ( ! options . lib . find ( function ( l ) {
107- return libName . toLowerCase ( ) === l . toLowerCase ( ) ;
108- } ) ) {
76+ if ( ! options . lib . find ( function ( l ) {
77+ return libName . toLowerCase ( ) === l . toLowerCase ( ) ;
78+ } ) ) {
10979 options . lib . push ( libName ) ;
11080 }
11181 }
11282}
11383
11484function addTnsCoreModulesPathMappings ( existingConfig , displayableTsconfigPath , projectDir ) {
115- if ( hasModules30 ( projectDir ) ) {
116- console . log ( "Adding tns-core-modules path mappings lib to tsconfig.json..." ) ;
117- existingConfig [ "compilerOptions" ] = existingConfig [ "compilerOptions" ] || { } ;
118- var compilerOptions = existingConfig [ "compilerOptions" ] ;
119- compilerOptions [ "baseUrl" ] = "." ;
120- compilerOptions [ "paths" ] = compilerOptions [ "paths" ] || { } ;
121-
122- const appPath = getAppPath ( projectDir ) ;
123- compilerOptions [ "paths" ] [ "~/*" ] = compilerOptions [ "paths" ] [ "~/*" ] || [
124- `${ appPath } /*`
125- ] ;
126- compilerOptions [ "paths" ] [ "*" ] = compilerOptions [ "paths" ] [ "*" ] || [
127- "./node_modules/tns-core-modules/*" ,
128- "./node_modules/*"
129- ] ;
130- }
85+ console . log ( "Adding tns-core-modules path mappings lib to tsconfig.json..." ) ;
86+ existingConfig [ "compilerOptions" ] = existingConfig [ "compilerOptions" ] || { } ;
87+ var compilerOptions = existingConfig [ "compilerOptions" ] ;
88+ compilerOptions [ "baseUrl" ] = "." ;
89+ compilerOptions [ "paths" ] = compilerOptions [ "paths" ] || { } ;
90+
91+ const appPath = getAppPath ( projectDir ) ;
92+ compilerOptions [ "paths" ] [ "~/*" ] = compilerOptions [ "paths" ] [ "~/*" ] || [
93+ `${ appPath } /*`
94+ ] ;
95+ compilerOptions [ "paths" ] [ "*" ] = compilerOptions [ "paths" ] [ "*" ] || [
96+ "./node_modules/tns-core-modules/*" ,
97+ "./node_modules/*"
98+ ] ;
13199}
132100
133101function getAppPath ( projectDir ) {
@@ -138,7 +106,7 @@ function getAppPath(projectDir) {
138106 const nsConfig = JSON . parse ( fs . readFileSync ( nsConfigPath ) ) ;
139107 const appPath = nsConfig && nsConfig . appPath ;
140108 return appPath || DEFAULT_PATH ;
141- } catch ( _ ) {
109+ } catch ( _ ) {
142110 return DEFAULT_PATH ;
143111 }
144112}
0 commit comments