Skip to content

Commit

Permalink
fix(angular): handle paths correctly on window when migrating angular…
Browse files Browse the repository at this point in the history
… cli workspaces to nx (#10611)
  • Loading branch information
leosvelperez committed Jun 7, 2022
1 parent 838170e commit f828da9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
33 changes: 21 additions & 12 deletions packages/angular/src/generators/ng-add/utilities/app.migrator.ts
Expand Up @@ -343,10 +343,13 @@ export class AppMigrator extends ProjectMigrator<SupportedTargets> {
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 ?? {});
Expand Down Expand Up @@ -467,10 +470,13 @@ export class AppMigrator extends ProjectMigrator<SupportedTargets> {
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 ?? {});
Expand Down Expand Up @@ -534,10 +540,13 @@ export class AppMigrator extends ProjectMigrator<SupportedTargets> {
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);
Expand Down
12 changes: 4 additions & 8 deletions packages/angular/src/generators/ng-add/utilities/lib.migrator.ts
Expand Up @@ -50,8 +50,8 @@ export class LibMigrator extends ProjectMigrator<SupportedTargets> {
}

async migrate(): Promise<void> {
this.moveProjectFiles();
await this.updateProjectConfiguration();
this.moveProjectFiles();
this.updateNgPackageJson();
this.updateTsConfigs();
this.updateEsLintConfig();
Expand Down Expand Up @@ -259,19 +259,15 @@ export class LibMigrator extends ProjectMigrator<SupportedTargets> {
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.`
);
}

lintOptions.eslintConfig =
lintOptions.eslintConfig &&
joinPathFragments(
this.project.newRoot,
basename(lintOptions.eslintConfig)
);
lintOptions.eslintConfig && this.newEsLintConfigPath;
lintOptions.lintFilePatterns =
lintOptions.lintFilePatterns &&
lintOptions.lintFilePatterns.map((pattern) => {
Expand Down Expand Up @@ -304,7 +300,7 @@ export class LibMigrator extends ProjectMigrator<SupportedTargets> {
return;
}

const eslintConfig = readJson(this.tree, this.newEsLintConfigPath);
const eslintConfig = readJson(this.tree, this.oldEsLintConfigPath);
if (hasRulesRequiringTypeChecking(eslintConfig)) {
lintOptions.hasTypeAwareRules = true;
}
Expand Down
@@ -1,5 +1,6 @@
import {
joinPathFragments,
normalizePath,
offsetFromRoot,
ProjectConfiguration,
readWorkspaceConfiguration,
Expand Down Expand Up @@ -289,7 +290,7 @@ export abstract class ProjectMigrator<TargetType extends string = any> {

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);
});
}

Expand Down

0 comments on commit f828da9

Please sign in to comment.