From f828da9d37d324ead09caa8ab210af0673a732c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Tue, 7 Jun 2022 13:26:36 +0100 Subject: [PATCH] fix(angular): handle paths correctly on window when migrating angular cli workspaces to nx (#10611) --- .../ng-add/utilities/app.migrator.ts | 33 ++++++++++++------- .../ng-add/utilities/lib.migrator.ts | 12 +++---- .../ng-add/utilities/project.migrator.ts | 3 +- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/angular/src/generators/ng-add/utilities/app.migrator.ts b/packages/angular/src/generators/ng-add/utilities/app.migrator.ts index b6e5680f12945..f82910a4085e6 100644 --- a/packages/angular/src/generators/ng-add/utilities/app.migrator.ts +++ b/packages/angular/src/generators/ng-add/utilities/app.migrator.ts @@ -343,10 +343,13 @@ export class AppMigrator extends ProjectMigrator { this.logger.warn( `The "${this.targetNames.build}" target does not have the "tsConfig" option configured. Skipping updating the tsConfig file.` ); - } else if (!this.tree.exists(buildDevTsConfig)) { - this.logger.warn( - `The tsConfig file "${buildDevTsConfig}" specified in the "${this.targetNames.build}" target could not be found. Skipping updating the tsConfig file.` - ); + } else { + const newBuildDevTsConfig = this.convertPath(buildDevTsConfig); + if (!this.tree.exists(newBuildDevTsConfig)) { + this.logger.warn( + `The tsConfig file "${buildDevTsConfig}" specified in the "${this.targetNames.build}" target could not be found. Skipping updating the tsConfig file.` + ); + } } this.convertBuildOptions(buildTarget.options ?? {}); @@ -467,10 +470,13 @@ export class AppMigrator extends ProjectMigrator { this.logger.warn( `The "${this.targetNames.server}" target does not have the "tsConfig" option configured. Skipping updating the tsConfig file.` ); - } else if (!this.tree.exists(serverDevTsConfig)) { - this.logger.warn( - `The tsConfig file "${serverDevTsConfig}" specified in the "${this.targetNames.server}" target could not be found. Skipping updating the tsConfig file.` - ); + } else { + const newServerDevTsConfig = this.convertPath(serverDevTsConfig); + if (!this.tree.exists(newServerDevTsConfig)) { + this.logger.warn( + `The tsConfig file "${serverDevTsConfig}" specified in the "${this.targetNames.server}" target could not be found. Skipping updating the tsConfig file.` + ); + } } this.convertServerOptions(serverTarget.options ?? {}); @@ -534,10 +540,13 @@ export class AppMigrator extends ProjectMigrator { this.logger.warn( `The "${this.targetNames.test}" target does not have the "tsConfig" option configured. Skipping updating the tsConfig file.` ); - } else if (!this.tree.exists(testOptions.tsConfig)) { - this.logger.warn( - `The tsConfig file "${testOptions.tsConfig}" specified in the "${this.targetNames.test}" target could not be found. Skipping updating the tsConfig file.` - ); + } else { + const newTestTsConfig = this.convertPath(testOptions.tsConfig); + if (!this.tree.exists(newTestTsConfig)) { + this.logger.warn( + `The tsConfig file "${testOptions.tsConfig}" specified in the "${this.targetNames.test}" target could not be found. Skipping updating the tsConfig file.` + ); + } } testOptions.main = testOptions.main && this.convertAsset(testOptions.main); diff --git a/packages/angular/src/generators/ng-add/utilities/lib.migrator.ts b/packages/angular/src/generators/ng-add/utilities/lib.migrator.ts index 931a11021d233..59786c3080732 100644 --- a/packages/angular/src/generators/ng-add/utilities/lib.migrator.ts +++ b/packages/angular/src/generators/ng-add/utilities/lib.migrator.ts @@ -50,8 +50,8 @@ export class LibMigrator extends ProjectMigrator { } async migrate(): Promise { - this.moveProjectFiles(); await this.updateProjectConfiguration(); + this.moveProjectFiles(); this.updateNgPackageJson(); this.updateTsConfigs(); this.updateEsLintConfig(); @@ -259,7 +259,7 @@ export class LibMigrator extends ProjectMigrator { return; } - const existEsLintConfigPath = this.tree.exists(this.newEsLintConfigPath); + const existEsLintConfigPath = this.tree.exists(this.oldEsLintConfigPath); if (!existEsLintConfigPath) { this.logger.warn( `The ESLint config file "${this.oldEsLintConfigPath}" could not be found. Skipping updating the file.` @@ -267,11 +267,7 @@ export class LibMigrator extends ProjectMigrator { } lintOptions.eslintConfig = - lintOptions.eslintConfig && - joinPathFragments( - this.project.newRoot, - basename(lintOptions.eslintConfig) - ); + lintOptions.eslintConfig && this.newEsLintConfigPath; lintOptions.lintFilePatterns = lintOptions.lintFilePatterns && lintOptions.lintFilePatterns.map((pattern) => { @@ -304,7 +300,7 @@ export class LibMigrator extends ProjectMigrator { return; } - const eslintConfig = readJson(this.tree, this.newEsLintConfigPath); + const eslintConfig = readJson(this.tree, this.oldEsLintConfigPath); if (hasRulesRequiringTypeChecking(eslintConfig)) { lintOptions.hasTypeAwareRules = true; } diff --git a/packages/angular/src/generators/ng-add/utilities/project.migrator.ts b/packages/angular/src/generators/ng-add/utilities/project.migrator.ts index 051612489e313..930bcfc67551a 100644 --- a/packages/angular/src/generators/ng-add/utilities/project.migrator.ts +++ b/packages/angular/src/generators/ng-add/utilities/project.migrator.ts @@ -1,5 +1,6 @@ import { joinPathFragments, + normalizePath, offsetFromRoot, ProjectConfiguration, readWorkspaceConfiguration, @@ -289,7 +290,7 @@ export abstract class ProjectMigrator { protected moveDir(from: string, to: string): void { visitNotIgnoredFiles(this.tree, from, (file) => { - this.moveFile(file, file.replace(from, to), true); + this.moveFile(file, normalizePath(file).replace(from, to), true); }); }