From 4200cd0ee78631d4a6c1744435abe59f1c7b7915 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 7 Sep 2020 13:57:08 +0200 Subject: [PATCH 1/4] fix: backup create should look for existing backup data, and update it --- lib/services/project-backup-service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); From a0f66f82e0eecb0456272787e2cb3d8cffd8f789 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 7 Sep 2020 13:57:24 +0200 Subject: [PATCH 2/4] feat: migrate tsconfig.json for ns7 projects --- lib/controllers/migrate-controller.ts | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/controllers/migrate-controller.ts b/lib/controllers/migrate-controller.ts index 899afff4c8..6462bda331 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"); // @@ -1182,6 +1192,41 @@ 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"]), + ]; + configContents.compilerOptions.plugins = [ + ...new Set([ + ...(configContents.compilerOptions.plugins || []), + { + transform: + "@nativescript/webpack/transformers/ns-transform-native-classes", + type: "raw", + }, + ]), + ]; + + 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 = [ { From bbd2ab605db68181402f47144b19f27b9a2c1428 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 7 Sep 2020 19:42:33 +0200 Subject: [PATCH 3/4] fix: only remove tsconfig.tns.json if not inside a shared project --- lib/controllers/migrate-controller.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/controllers/migrate-controller.ts b/lib/controllers/migrate-controller.ts index 6462bda331..8bbb57867a 100644 --- a/lib/controllers/migrate-controller.ts +++ b/lib/controllers/migrate-controller.ts @@ -790,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( From d5de823f9b09acb4e9233b143f06679ce3ac2682 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 7 Sep 2020 19:42:55 +0200 Subject: [PATCH 4/4] fix: remove plugins from tsconfig - only required for plugins --- lib/controllers/migrate-controller.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/controllers/migrate-controller.ts b/lib/controllers/migrate-controller.ts index 8bbb57867a..19f72ae70e 100644 --- a/lib/controllers/migrate-controller.ts +++ b/lib/controllers/migrate-controller.ts @@ -1223,16 +1223,6 @@ export class MigrateController configContents.compilerOptions.lib = [ ...new Set([...(configContents.compilerOptions.lib || []), "es2017"]), ]; - configContents.compilerOptions.plugins = [ - ...new Set([ - ...(configContents.compilerOptions.plugins || []), - { - transform: - "@nativescript/webpack/transformers/ns-transform-native-classes", - type: "raw", - }, - ]), - ]; this.$fs.writeJson(tsConfigPath, configContents);