Skip to content

Commit

Permalink
feat: migrate tsconfig.json for ns7 projects (#5378)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rigor789 authored Sep 7, 2020
1 parent dd09547 commit 8491b07
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
53 changes: 52 additions & 1 deletion lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
//
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1182,6 +1208,31 @@ export class MigrateController
return dependencies;
}

private async migrateTSConfig(tsConfigPath: string): Promise<boolean> {
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<IMigrationDependency[]> {
const dependencies = [
{
Expand Down
3 changes: 2 additions & 1 deletion lib/services/project-backup-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8491b07

Please sign in to comment.