@@ -40,6 +40,7 @@ import { IInjector } from "../common/definitions/yok";
40
40
import { injector } from "../common/yok" ;
41
41
import { IJsonFileSettingsService } from "../common/definitions/json-file-settings-service" ;
42
42
import { SupportedConfigValues } from "../tools/config-manipulation/config-transformer" ;
43
+ import * as temp from "temp" ;
43
44
44
45
// const wait: (ms: number) => Promise<void> = (ms: number = 1000) =>
45
46
// new Promise((resolve) => setTimeout(resolve, ms));
@@ -432,12 +433,29 @@ export class MigrateController
432
433
433
434
this . spinner . succeed ( "Project dependencies have been updated" ) ;
434
435
436
+ const isAngular = this . hasDependency (
437
+ {
438
+ packageName : "@nativescript/angular" ,
439
+ } ,
440
+ projectData
441
+ ) ;
442
+
443
+ // ensure polyfills.ts exists in angular projects
444
+ let polyfillsPath ;
445
+ if ( isAngular ) {
446
+ polyfillsPath = await this . checkOrCreatePolyfillsTS ( projectData ) ;
447
+ }
448
+
435
449
// update tsconfig
436
450
const tsConfigPath = path . resolve ( projectDir , "tsconfig.json" ) ;
437
451
if ( this . $fs . exists ( tsConfigPath ) ) {
438
452
this . spinner . info ( `Updating ${ "tsconfig.json" . yellow } ` ) ;
439
453
440
- await this . migrateTSConfig ( tsConfigPath ) ;
454
+ await this . migrateTSConfig ( {
455
+ tsConfigPath,
456
+ isAngular,
457
+ polyfillsPath,
458
+ } ) ;
441
459
442
460
this . spinner . succeed ( `Updated ${ "tsconfig.json" . yellow } ` ) ;
443
461
}
@@ -1189,7 +1207,15 @@ export class MigrateController
1189
1207
return dependencies ;
1190
1208
}
1191
1209
1192
- private async migrateTSConfig ( tsConfigPath : string ) : Promise < boolean > {
1210
+ private async migrateTSConfig ( {
1211
+ tsConfigPath,
1212
+ isAngular,
1213
+ polyfillsPath,
1214
+ } : {
1215
+ tsConfigPath : string ;
1216
+ isAngular : boolean ;
1217
+ polyfillsPath ?: string ;
1218
+ } ) : Promise < boolean > {
1193
1219
try {
1194
1220
const configContents = this . $fs . readJson ( tsConfigPath ) ;
1195
1221
@@ -1205,6 +1231,18 @@ export class MigrateController
1205
1231
...new Set ( [ ...( configContents . compilerOptions . lib || [ ] ) , "es2017" ] ) ,
1206
1232
] ;
1207
1233
1234
+ if ( isAngular ) {
1235
+ // make sure polyfills.ts is in files
1236
+ if ( configContents . files ) {
1237
+ configContents . files = [
1238
+ ...new Set ( [
1239
+ ...( configContents . files || [ ] ) ,
1240
+ polyfillsPath ?? "./src/polyfills.ts" ,
1241
+ ] ) ,
1242
+ ] ;
1243
+ }
1244
+ }
1245
+
1208
1246
this . $fs . writeJson ( tsConfigPath , configContents ) ;
1209
1247
1210
1248
return true ;
@@ -1214,6 +1252,48 @@ export class MigrateController
1214
1252
}
1215
1253
}
1216
1254
1255
+ private async checkOrCreatePolyfillsTS (
1256
+ projectData : IProjectData
1257
+ ) : Promise < string > {
1258
+ const { projectDir, appDirectoryPath } = projectData ;
1259
+
1260
+ const possiblePaths = [
1261
+ `${ appDirectoryPath } /polyfills.ts` ,
1262
+ `./src/polyfills.ts` ,
1263
+ `./app/polyfills.ts` ,
1264
+ ] . map ( ( possiblePath ) => path . resolve ( projectDir , possiblePath ) ) ;
1265
+
1266
+ let polyfillsPath = possiblePaths . find ( ( possiblePath ) => {
1267
+ return this . $fs . exists ( possiblePath ) ;
1268
+ } ) ;
1269
+
1270
+ if ( polyfillsPath ) {
1271
+ return "./" + path . relative ( projectDir , polyfillsPath ) ;
1272
+ }
1273
+
1274
+ const tempDir = temp . mkdirSync ( {
1275
+ prefix : "migrate-angular-polyfills" ,
1276
+ } ) ;
1277
+
1278
+ // get from default angular template
1279
+ await this . $pacoteService . extractPackage (
1280
+ constants . RESERVED_TEMPLATE_NAMES [ "angular" ] ,
1281
+ tempDir
1282
+ ) ;
1283
+
1284
+ this . $fs . copyFile (
1285
+ path . resolve ( tempDir , "src/polyfills.ts" ) ,
1286
+ possiblePaths [ 0 ]
1287
+ ) ;
1288
+
1289
+ // clean up temp project
1290
+ this . $fs . deleteDirectory ( tempDir ) ;
1291
+
1292
+ this . spinner . succeed ( `Created fresh ${ "polyfills.ts" . cyan } ` ) ;
1293
+
1294
+ return "./" + path . relative ( projectDir , possiblePaths [ 0 ] ) ;
1295
+ }
1296
+
1217
1297
private async migrateNativeScriptAngular ( ) : Promise < IMigrationDependency [ ] > {
1218
1298
const minVersion = "10.0.0" ;
1219
1299
const desiredVersion = "^12.2.5" ;
@@ -1281,6 +1361,12 @@ export class MigrateController
1281
1361
} ,
1282
1362
1283
1363
// devDependencies
1364
+ {
1365
+ packageName : "@angular/cli" ,
1366
+ minVersion,
1367
+ desiredVersion,
1368
+ isDev : true ,
1369
+ } ,
1284
1370
{
1285
1371
packageName : "@angular/compiler-cli" ,
1286
1372
minVersion,
0 commit comments