Skip to content

Commit

Permalink
feat(angular): support migrating angular cli workspaces with library …
Browse files Browse the repository at this point in the history
…projects (#9885)
  • Loading branch information
leosvelperez authored Apr 19, 2022
1 parent 367e95a commit cfaedc8
Show file tree
Hide file tree
Showing 22 changed files with 2,417 additions and 223 deletions.
5 changes: 0 additions & 5 deletions docs/generated/packages/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -1293,11 +1293,6 @@
"description": "Preserve the Angular CLI layout instead of moving the app into apps. NOTE: only used if running the generator in an Angular CLI workspace.",
"default": false
},
"name": {
"type": "string",
"description": "Project name. NOTE: only used if running the generator in an Angular CLI workspace.",
"$default": { "$source": "projectName" }
},
"unitTestRunner": {
"type": "string",
"enum": ["karma", "jest", "none"],
Expand Down
58 changes: 55 additions & 3 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
expect(() =>
runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')
).toThrow(
'An e2e project with Protractor was found but "e2e/protractor.conf.js" could not be found.'
'The "e2e" target is using a Protractor builder but the Protractor config file "e2e/protractor.conf.js" could not be found.'
);
// Restore e2e directory
runCommand('mv e2e-bak e2e');
Expand All @@ -309,7 +309,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
expect(() =>
runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')
).toThrow(
'An e2e project with Cypress was found but "cypress.json" could not be found.'
'The "e2e" target is using a Cypress builder but the Cypress config file "cypress.json" could not be found.'
);
// Restore cypress.json
runCommand('mv cypress.json.bak cypress.json');
Expand All @@ -319,7 +319,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
expect(() =>
runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')
).toThrow(
'An e2e project with Cypress was found but the "cypress" directory could not be found.'
'The "e2e" target is using a Cypress builder but the "cypress" directory could not be found.'
);
// Restore cypress.json
runCommand('mv cypress-bak cypress');
Expand Down Expand Up @@ -429,6 +429,58 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
);
});

it('should support a workspace with multiple libraries', () => {
// add some libraries
const lib1 = uniq('lib1');
const lib2 = uniq('lib2');
runCommand(`ng g @schematics/angular:library ${lib1}`);
runCommand(`ng g @schematics/angular:library ${lib2}`);

runNgAdd('@nrwl/angular', '--npm-scope projscope');

// check angular.json
expect(readJson('angular.json')).toStrictEqual({
version: 2,
projects: {
[project]: `apps/${project}`,
[lib1]: `libs/${lib1}`,
[lib2]: `libs/${lib2}`,
},
});

// check building lib1
let output = runCLI(`build ${lib1}`);
expect(output).toContain(`> nx run ${lib1}:build:production`);
expect(output).toContain(
`Successfully ran target build for project ${lib1}`
);
checkFilesExist(`dist/${lib1}/package.json`);

output = runCLI(`build ${lib1}`);
expect(output).toContain(
`> nx run ${lib1}:build:production [existing outputs match the cache, left as is]`
);
expect(output).toContain(
`Successfully ran target build for project ${lib1}`
);

// check building lib2
output = runCLI(`build ${lib2}`);
expect(output).toContain(`> nx run ${lib2}:build:production`);
expect(output).toContain(
`Successfully ran target build for project ${lib2}`
);
checkFilesExist(`dist/${lib2}/package.json`);

output = runCLI(`build ${lib2}`);
expect(output).toContain(
`> nx run ${lib2}:build:production [existing outputs match the cache, left as is]`
);
expect(output).toContain(
`Successfully ran target build for project ${lib2}`
);
});

it('should support --preserve-angular-cli-layout', () => {
// add another app and a library
runCommand(`ng g @schematics/angular:application app2`);
Expand Down
1 change: 1 addition & 0 deletions packages/angular/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@angular-eslint/",
"@schematics",
"@phenomnomnominal/tsquery",
"chalk",
"ignore",
"jasmine-marbles",
"rxjs-for-await",
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
"@nrwl/jest": "*",
"@nrwl/linter": "*",
"@nrwl/storybook": "*",
"@nrwl/workspace": "*",
"@schematics/angular": "~13.3.0",
"@phenomnomnominal/tsquery": "4.1.1",
"chalk": "4.1.0",
"ignore": "^5.0.4",
"jasmine-marbles": "~0.8.4",
"rxjs-for-await": "0.0.2",
Expand Down
14 changes: 2 additions & 12 deletions packages/angular/src/generators/library/library.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
addDependenciesToPackageJson,
formatFiles,
installPackagesTask,
moveFilesToNewDirectory,
Expand All @@ -10,10 +9,10 @@ import { jestProjectGenerator } from '@nrwl/jest';
import { Linter } from '@nrwl/linter';
import { convertToNxProjectGenerator } from '@nrwl/workspace/generators';
import init from '../../generators/init/init';
import { postcssVersion } from '../../utils/versions';
import addLintingGenerator from '../add-linting/add-linting';
import karmaProjectGenerator from '../karma-project/karma-project';
import setupTailwindGenerator from '../setup-tailwind/setup-tailwind';
import { addBuildableLibrariesPostCssDependencies } from '../utils/dependencies';
import { addModule } from './lib/add-module';
import {
enableStrictTypeChecking,
Expand Down Expand Up @@ -86,16 +85,7 @@ export async function libraryGenerator(host: Tree, schema: Partial<Schema>) {
}

if (options.buildable || options.publishable) {
addDependenciesToPackageJson(
host,
{},
{
postcss: postcssVersion,
'postcss-import': '^14.0.2',
'postcss-preset-env': '^6.7.0',
'postcss-url': '^10.1.1',
}
);
addBuildableLibrariesPostCssDependencies(host);
}

if (options.standaloneConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ Object {
"devDependencies": "*",
},
},
"npmScope": "my-app",
"npmScope": "my-org",
"targetDependencies": Object {
"build": Array [
Object {
Expand Down
Loading

1 comment on commit cfaedc8

@vercel
Copy link

@vercel vercel bot commented on cfaedc8 Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.