Skip to content

Commit

Permalink
fix(schematics): handle projects that have similar names
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jan 5, 2018
1 parent 912fc81 commit fe7032d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
32 changes: 30 additions & 2 deletions packages/schematics/src/command-line/affected-apps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ describe('Calculates Dependencies Between Apps and Libs', () => {

expect(deps).toEqual({ app1: ['app1'] });
});

it('should handle projects with the names starting with the same string', () => {
const deps = dependencies(
'nrwl',
[
{
name: 'aa',
files: ['aa.ts'],
isApp: true
},
{
name: 'aa/bb',
files: ['bb.ts'],
isApp: true
}
],
file => {
switch (file) {
case 'aa.ts':
return `import '@nrwl/aa/bb'`;
case 'bb.ts':
return '';
}
}
);

expect(deps).toEqual({ aa: ['aa', 'aa/bb'], 'aa/bb': ['aa/bb'] });
});
});

describe('affectedApps', () => {
Expand Down Expand Up @@ -236,7 +264,7 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
['package.json']
);

expect(affected).toEqual(['app1', 'app2']);
expect(affected).toEqual(['app2', 'app1']);
});

it('should handle slashes', () => {
Expand Down Expand Up @@ -289,7 +317,7 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
['app1.ts']
);

expect(affected).toEqual(['app1', 'app2']);
expect(affected).toEqual(['app2', 'app1']);
});
});
});
8 changes: 7 additions & 1 deletion packages/schematics/src/command-line/affected-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ export function dependencies(
class Deps {
private deps: { [appName: string]: string[] };

constructor(private npmScope: string, private projects: Project[], private fileRead: (s: string) => string) {}
constructor(private npmScope: string, private projects: Project[], private fileRead: (s: string) => string) {
this.projects.sort((a, b) => {
if (!a.name) return -1;
if (!b.name) return -1;
return a.name.length > b.name.length ? -1 : 1;
});
}

calculateDeps() {
this.deps = this.projects.reduce((m, c) => ({ ...m, [c.name]: [] }), {});
Expand Down

0 comments on commit fe7032d

Please sign in to comment.