Skip to content

Commit 8491b07

Browse files
authored
feat: migrate tsconfig.json for ns7 projects (#5378)
* fix: backup create should look for existing backup data, and update it * feat: migrate tsconfig.json for ns7 projects * fix: only remove tsconfig.tns.json if not inside a shared project * fix: remove plugins from tsconfig - only required for plugins
1 parent dd09547 commit 8491b07

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

lib/controllers/migrate-controller.ts

+52-1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ export class MigrateController
381381
this.spinner.text = "Project dependencies have been updated";
382382
this.spinner.succeed();
383383

384+
// update tsconfig
385+
const tsConfigPath = path.resolve(projectDir, "tsconfig.json");
386+
if (this.$fs.exists(tsConfigPath)) {
387+
this.spinner.start("Updating tsconfig.json");
388+
389+
await this.migrateTSConfig(tsConfigPath);
390+
391+
this.spinner.succeed("Updated tsconfig.json");
392+
}
393+
384394
// add latest runtimes (if they were specified in the nativescript key)
385395
// this.spinner.start("Updating runtimes");
386396
//
@@ -780,8 +790,24 @@ export class MigrateController
780790
constants.NODE_MODULES_FOLDER_NAME,
781791
constants.WEBPACK_CONFIG_NAME,
782792
constants.PACKAGE_LOCK_JSON_FILE_NAME,
783-
constants.TSCCONFIG_TNS_JSON_NAME,
784793
]);
794+
795+
const {
796+
dependencies,
797+
devDependencies,
798+
} = await this.$pluginsService.getDependenciesFromPackageJson(
799+
projectData.projectDir
800+
);
801+
const hasSchematics = [...dependencies, ...devDependencies].find(
802+
(p) => p.name === "@nativescript/schematics"
803+
);
804+
805+
if (!hasSchematics) {
806+
// clean tsconfig.tns.json if not in a shared project
807+
await this.$projectCleanupService.clean([
808+
constants.TSCCONFIG_TNS_JSON_NAME,
809+
]);
810+
}
785811
}
786812

787813
private async handleAutoGeneratedFiles(
@@ -1182,6 +1208,31 @@ export class MigrateController
11821208
return dependencies;
11831209
}
11841210

1211+
private async migrateTSConfig(tsConfigPath: string): Promise<boolean> {
1212+
try {
1213+
const configContents = this.$fs.readJson(tsConfigPath);
1214+
1215+
// update
1216+
configContents.compilerOptions = configContents.compilerOptions || {};
1217+
configContents.compilerOptions.target = "es2017";
1218+
configContents.compilerOptions.module = "esnext";
1219+
configContents.compilerOptions.moduleResolution = "node";
1220+
configContents.compilerOptions.experimentalDecorators = true;
1221+
configContents.compilerOptions.removeComments = false;
1222+
1223+
configContents.compilerOptions.lib = [
1224+
...new Set([...(configContents.compilerOptions.lib || []), "es2017"]),
1225+
];
1226+
1227+
this.$fs.writeJson(tsConfigPath, configContents);
1228+
1229+
return true;
1230+
} catch (error) {
1231+
this.$logger.trace("Failed to migrate tsconfig.json. Error is: ", error);
1232+
return false;
1233+
}
1234+
}
1235+
11851236
private async migrateNativeScriptAngular(): Promise<IMigrationDependency[]> {
11861237
const dependencies = [
11871238
{

lib/services/project-backup-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export class ProjectBackupService implements IProjectBackupService {
3737
}
3838

3939
create() {
40-
const backedUpPaths = [];
40+
const backupData = this.getBackupData();
41+
const backedUpPaths = backupData?.paths || [];
4142
this.$super.$logger.trace("creating backup: ", this.name);
4243

4344
this.$super.$fs.createDirectory(this.backupDir);

0 commit comments

Comments
 (0)