fix(angular): allow creating an app named 'app' or lib named 'lib'

Currently when trying to create an app named 'app' or a lib named 'lib', the schematics inject the
'projectType' as 'apps/application' or lib as 'libs/library', breaking the Angular build.

fix #1844
This commit is contained in:
Dan Smith 2019-11-09 19:57:14 -05:00 committed by Victor Savkin
parent 607bcfdeb2
commit f095647013
3 changed files with 36 additions and 1 deletions

View File

@ -140,6 +140,12 @@ describe('app', () => {
expect(result.exists('apps/my-app/src/main.ts')).toEqual(true);
expect(result.exists('apps/my-app-e2e/protractor.conf.js')).toEqual(true);
});
it('should set projectType to application', async () => {
const tree = await runSchematic('app', { name: 'app' }, appTree);
const workspaceJson = readJsonInTree(tree, '/workspace.json');
expect(workspaceJson.projects['app'].projectType).toEqual('application');
});
});
describe('nested', () => {

View File

@ -0,0 +1,25 @@
import { replaceAppNameWithPath } from './cli-config-utils';
describe('replaceAppNameWithPath', () => {
describe('when node is `application`', () => {
describe('and appName is `app`', () => {
it('still returns the node', () => {
const node = 'application';
const appName = 'app';
const root = 'apps/app';
expect(replaceAppNameWithPath(node, appName, root)).toEqual(node);
});
});
});
describe('when node is `library`', () => {
describe('and appName is `lib`', () => {
it('still returns the node', () => {
const node = 'library';
const appName = 'lib';
const root = 'libs/lib';
expect(replaceAppNameWithPath(node, appName, root)).toEqual(node);
});
});
});
});

View File

@ -39,7 +39,11 @@ export function replaceAppNameWithPath(
`([^a-z0-9]*(${appName}))|((${appName})[^a-z0-9:]*)`,
'gi'
);
if (!!node.match(matchPattern)) {
if (
!!node.match(matchPattern) &&
node !== 'application' &&
node !== 'library'
) {
const r = node.replace(appName, root);
return r.startsWith('/apps') || r.startsWith('/libs')
? r.substring(1)