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

fix(angular): ensure apps/libs layout is created when migrating from angular cli to nx monorepo layout #13577

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions e2e/angular-core/src/ng-add.test.ts
Expand Up @@ -284,19 +284,17 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
// Restore e2e directory
runCommand('mv e2e-bak e2e');

// TODO: this functionality is currently broken, this validation doesn't exist
// // Remove src
// runCommand('mv src src-bak');
// expect(() => runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')).toThrow(
// 'Path: src does not exist'
// );

// // Put src back
// runCommand('mv src-bak src');
// Remove src
runCommand('mv src src-bak');
expect(() =>
runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')
).toThrow('The project source root "src" could not be found.');

// Put src back
runCommand('mv src-bak src');
});

//TODO: reenable
xit('should handle a workspace with cypress v9', () => {
it('should handle a workspace with cypress v9', () => {
addCypress9();

// Remove cypress.json
Expand Down Expand Up @@ -383,8 +381,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
});
});

//TODO: reenable
xit('should handle a workspace with cypress v10', () => {
it('should handle a workspace with cypress v10', () => {
addCypress10();

// Remove cypress.config.ts
Expand Down
Empty file.
Expand Up @@ -269,6 +269,101 @@ describe('workspace', () => {
expect(prettierIgnore).toBe('# existing ignore rules');
});

it('should generate .gitkeep file in apps directory when there are no applications', async () => {
tree.write('projects/lib1/README.md', '');
tree.write('projects/lib1/src/public-api.ts', '');
writeJson(tree, 'angular.json', {
$schema: './node_modules/@angular/cli/lib/config/schema.json',
version: 1,
defaultProject: 'lib1',
newProjectRoot: 'projects',
projects: {
lib1: {
root: 'projects/lib1',
sourceRoot: 'projects/lib1/src',
projectType: 'library',
architect: {
build: {
builder: '@angular-devkit/build-angular:ng-packagr',
options: { tsConfig: 'projects/lib1/tsconfig.lib.json' },
},
test: {
builder: '@angular-devkit/build-angular:karma',
options: { tsConfig: 'projects/lib1/tsconfig.spec.json' },
},
},
},
},
});

await migrateFromAngularCli(tree, {});

expect(tree.exists('apps/.gitkeep')).toBe(true);
});

it('should not generate .gitkeep file in apps directory when there is at least one application', async () => {
await migrateFromAngularCli(tree, {});

expect(tree.exists('apps/.gitkeep')).toBe(false);
});

it('should generate .gitkeep file in libs directory when there are no libraries', async () => {
await migrateFromAngularCli(tree, {});

expect(tree.exists('libs/.gitkeep')).toBe(true);
});

it('should not generate .gitkeep file in libs directory when there is at least one library', async () => {
tree.write('projects/lib1/README.md', '');
tree.write('projects/lib1/src/public-api.ts', '');
writeJson(tree, 'angular.json', {
$schema: './node_modules/@angular/cli/lib/config/schema.json',
version: 1,
defaultProject: 'app1',
newProjectRoot: 'projects',
projects: {
app1: {
root: '',
sourceRoot: 'src',
projectType: 'application',
architect: {
build: {
builder: '@angular-devkit/build-angular:browser',
options: { tsConfig: 'tsconfig.app.json' },
},
test: {
builder: '@angular-devkit/build-angular:karma',
options: { tsConfig: 'tsconfig.spec.json' },
},
e2e: {
builder: '@angular-devkit/build-angular:protractor',
options: { protractorConfig: 'e2e/protractor.conf.js' },
},
},
},
lib1: {
root: 'projects/lib1',
sourceRoot: 'projects/lib1/src',
projectType: 'library',
architect: {
build: {
builder: '@angular-devkit/build-angular:ng-packagr',
options: { tsConfig: 'projects/lib1/tsconfig.lib.json' },
},
test: {
builder: '@angular-devkit/build-angular:karma',
options: { tsConfig: 'projects/lib1/tsconfig.spec.json' },
},
},
},
},
});

await migrateFromAngularCli(tree, {});

expect(tree.exists('libs/.gitkeep')).toBe(false);
});

it('should create a root eslint config', async () => {
await migrateFromAngularCli(tree, {});

Expand Down
Expand Up @@ -3,9 +3,7 @@ import {
addDependenciesToPackageJson,
installPackagesTask,
readJson,
readWorkspaceConfiguration,
updateJson,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { convertToNxProjectGenerator } from '@nrwl/workspace/generators';
import { prettierVersion } from '@nrwl/workspace/src/utils/versions';
Expand All @@ -20,6 +18,7 @@ import {
createWorkspaceFiles,
decorateAngularCli,
deleteAngularJson,
deleteGitKeepFilesIfNotNeeded,
formatFilesTask,
getAllProjects,
getWorkspaceRootFileTypesInfo,
Expand Down Expand Up @@ -119,6 +118,8 @@ export async function migrateFromAngularCli(
updateRootEsLintConfig(tree, eslintConfig, options.unitTestRunner);
cleanupEsLintPackages(tree);
}

deleteGitKeepFilesIfNotNeeded(tree);
}

deleteAngularJson(tree);
Expand Down
Expand Up @@ -400,3 +400,12 @@ export function deleteAngularJson(tree: Tree): void {
}
tree.delete('angular.json');
}

export function deleteGitKeepFilesIfNotNeeded(tree: Tree): void {
if (tree.children('apps').length > 1 && tree.exists('apps/.gitkeep')) {
tree.delete('apps/.gitkeep');
}
if (tree.children('libs').length > 1 && tree.exists('libs/.gitkeep')) {
tree.delete('libs/.gitkeep');
}
}