diff --git a/lib/controllers/migrate-controller.ts b/lib/controllers/migrate-controller.ts index 899afff4c8..19f72ae70e 100644 --- a/lib/controllers/migrate-controller.ts +++ b/lib/controllers/migrate-controller.ts @@ -381,6 +381,16 @@ export class MigrateController this.spinner.text = "Project dependencies have been updated"; this.spinner.succeed(); + // update tsconfig + const tsConfigPath = path.resolve(projectDir, "tsconfig.json"); + if (this.$fs.exists(tsConfigPath)) { + this.spinner.start("Updating tsconfig.json"); + + await this.migrateTSConfig(tsConfigPath); + + this.spinner.succeed("Updated tsconfig.json"); + } + // add latest runtimes (if they were specified in the nativescript key) // this.spinner.start("Updating runtimes"); // @@ -780,8 +790,24 @@ export class MigrateController constants.NODE_MODULES_FOLDER_NAME, constants.WEBPACK_CONFIG_NAME, constants.PACKAGE_LOCK_JSON_FILE_NAME, - constants.TSCCONFIG_TNS_JSON_NAME, ]); + + const { + dependencies, + devDependencies, + } = await this.$pluginsService.getDependenciesFromPackageJson( + projectData.projectDir + ); + const hasSchematics = [...dependencies, ...devDependencies].find( + (p) => p.name === "@nativescript/schematics" + ); + + if (!hasSchematics) { + // clean tsconfig.tns.json if not in a shared project + await this.$projectCleanupService.clean([ + constants.TSCCONFIG_TNS_JSON_NAME, + ]); + } } private async handleAutoGeneratedFiles( @@ -1182,6 +1208,31 @@ export class MigrateController return dependencies; } + private async migrateTSConfig(tsConfigPath: string): Promise { + try { + const configContents = this.$fs.readJson(tsConfigPath); + + // update + configContents.compilerOptions = configContents.compilerOptions || {}; + configContents.compilerOptions.target = "es2017"; + configContents.compilerOptions.module = "esnext"; + configContents.compilerOptions.moduleResolution = "node"; + configContents.compilerOptions.experimentalDecorators = true; + configContents.compilerOptions.removeComments = false; + + configContents.compilerOptions.lib = [ + ...new Set([...(configContents.compilerOptions.lib || []), "es2017"]), + ]; + + this.$fs.writeJson(tsConfigPath, configContents); + + return true; + } catch (error) { + this.$logger.trace("Failed to migrate tsconfig.json. Error is: ", error); + return false; + } + } + private async migrateNativeScriptAngular(): Promise { const dependencies = [ { diff --git a/lib/services/project-backup-service.ts b/lib/services/project-backup-service.ts index 2f4331d655..b5ded0515a 100644 --- a/lib/services/project-backup-service.ts +++ b/lib/services/project-backup-service.ts @@ -37,7 +37,8 @@ export class ProjectBackupService implements IProjectBackupService { } create() { - const backedUpPaths = []; + const backupData = this.getBackupData(); + const backedUpPaths = backupData?.paths || []; this.$super.$logger.trace("creating backup: ", this.name); this.$super.$fs.createDirectory(this.backupDir);