diff --git a/packages/schematics/src/command-line/affected-apps.spec.ts b/packages/schematics/src/command-line/affected-apps.spec.ts index 8333f26604..a7aace6980 100644 --- a/packages/schematics/src/command-line/affected-apps.spec.ts +++ b/packages/schematics/src/command-line/affected-apps.spec.ts @@ -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', () => { @@ -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', () => { @@ -289,7 +317,7 @@ describe('Calculates Dependencies Between Apps and Libs', () => { ['app1.ts'] ); - expect(affected).toEqual(['app1', 'app2']); + expect(affected).toEqual(['app2', 'app1']); }); }); }); diff --git a/packages/schematics/src/command-line/affected-apps.ts b/packages/schematics/src/command-line/affected-apps.ts index 60eccbe4a8..02711443e6 100644 --- a/packages/schematics/src/command-line/affected-apps.ts +++ b/packages/schematics/src/command-line/affected-apps.ts @@ -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]: [] }), {});