Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate tsconfig.json for ns7 projects #5378

Merged
merged 4 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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