Skip to content

Commit

Permalink
fix(angular): allow creating an app named 'app' or lib named 'lib'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
getabetterpic authored and vsavkin committed Nov 11, 2019
1 parent 607bcfd commit f095647
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
25 changes: 25 additions & 0 deletions packages/workspace/src/utils/cli-config-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
6 changes: 5 additions & 1 deletion packages/workspace/src/utils/cli-config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f095647

Please sign in to comment.