Skip to content

Commit

Permalink
fix(schematics): replaceAppNameWithPath use pattern matching now
Browse files Browse the repository at this point in the history
Make `replaceAppNameWithPath` uses pattern matching while replacing the strings, making sure it does
not mess with the wrong properties or values. Example: `ui` was messing with `build` &&
`@angular-devkit/build-angular`.

fix #856
  • Loading branch information
bcabanes authored and vsavkin committed Nov 7, 2018
1 parent cf158c9 commit f6af0b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/schematics/src/collection/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,16 @@ describe('app', () => {
expect(angularJson.projects['my-app-e2e']).toBeUndefined();
});
});

describe('replaceAppNameWithPath', () => {
it('should protect `angular.json` commands and properties', () => {
const tree = schematicRunner.runSchematic('app', { name: 'ui' }, appTree);

const angularJson = readJsonInTree(tree, 'angular.json');
expect(angularJson.projects['ui']).toBeDefined();
expect(
angularJson.projects['ui']['architect']['build']['builder']
).toEqual('@angular-devkit/build-angular:browser');
});
});
});
6 changes: 5 additions & 1 deletion packages/schematics/src/utils/cli-config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export function replaceAppNameWithPath(
root: string
): any {
if (typeof node === 'string') {
if (node.indexOf(appName) > -1 && node.indexOf(`${appName}:`) === -1) {
const matchPattern = new RegExp(
`([^a-z0-9]+(${appName}))|((${appName})[^a-z0-9:]+)`,
'gi'
);
if (!!node.match(matchPattern)) {
const r = node.replace(appName, root);
return r.startsWith('/apps') || r.startsWith('/libs')
? r.substring(1)
Expand Down

0 comments on commit f6af0b9

Please sign in to comment.