fix(schematics): handle projects that have similar names
This commit is contained in:
parent
912fc81708
commit
fe7032d29f
@ -153,6 +153,34 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
|
|||||||
|
|
||||||
expect(deps).toEqual({ app1: ['app1'] });
|
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', () => {
|
describe('affectedApps', () => {
|
||||||
@ -236,7 +264,7 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
|
|||||||
['package.json']
|
['package.json']
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(affected).toEqual(['app1', 'app2']);
|
expect(affected).toEqual(['app2', 'app1']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle slashes', () => {
|
it('should handle slashes', () => {
|
||||||
@ -289,7 +317,7 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
|
|||||||
['app1.ts']
|
['app1.ts']
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(affected).toEqual(['app1', 'app2']);
|
expect(affected).toEqual(['app2', 'app1']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -51,7 +51,13 @@ export function dependencies(
|
|||||||
class Deps {
|
class Deps {
|
||||||
private deps: { [appName: string]: string[] };
|
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() {
|
calculateDeps() {
|
||||||
this.deps = this.projects.reduce((m, c) => ({ ...m, [c.name]: [] }), {});
|
this.deps = this.projects.reduce((m, c) => ({ ...m, [c.name]: [] }), {});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user