Skip to content

Commit

Permalink
fix(workspace): consider ExportDeclaration w/ moduleSpecifier for dep…
Browse files Browse the repository at this point in the history
…endency calculation
  • Loading branch information
dherges authored and vsavkin committed May 2, 2019
1 parent 5318f00 commit 183ac6b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
73 changes: 73 additions & 0 deletions packages/workspace/src/command-line/deps-calculator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,5 +1133,78 @@ describe('Calculates Dependencies Between Apps and Libs', () => {

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

it(`should handle an ExportDeclaration w/ moduleSpecifier and w/o moduleSpecifier`, () => {
const deps = dependencies(
'nrwl',
[
{
name: 'lib1Name',
root: 'libs/lib1',
files: ['lib1.ts'],
fileMTimes: {
'lib1.ts': 1
},
tags: [],
implicitDependencies: [],
architect: {},
type: ProjectType.lib
},
{
name: 'lib2Name',
root: 'libs/lib2',
files: ['lib2.ts'],
fileMTimes: {
'lib2.ts': 1
},
tags: [],
implicitDependencies: [],
architect: {},
type: ProjectType.lib
},
{
name: 'lib3Name',
root: 'libs/lib3',
files: ['lib3.ts'],
fileMTimes: {
'lib3.ts': 1
},
tags: [],
implicitDependencies: [],
architect: {},
type: ProjectType.lib
}
],
null,
file => {
switch (file) {
case 'lib1.ts':
return `
const FOO = 23;
export { FOO };
`;
case 'lib2.ts':
return `
export const BAR = 24;
`;
case 'lib3.ts':
return `
import { FOO } from '@nrwl/lib1';
export { FOO };
export { BAR } from '@nrwl/lib2';
`;
}
}
);

expect(deps).toEqual({
lib1Name: [],
lib2Name: [],
lib3Name: [
{ projectName: 'lib1Name', type: DependencyType.es6Import },
{ projectName: 'lib2Name', type: DependencyType.es6Import }
]
});
});
});
});
5 changes: 4 additions & 1 deletion packages/workspace/src/command-line/deps-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ export class DepsCalculator {
}

private processNode(filePath: string, node: ts.Node): void {
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
if (
ts.isImportDeclaration(node) ||
(ts.isExportDeclaration(node) && node.moduleSpecifier)
) {
const imp = this.getStringLiteralValue(node.moduleSpecifier);
this.addDepIfNeeded(imp, filePath, DependencyType.es6Import);
return; // stop traversing downwards
Expand Down

0 comments on commit 183ac6b

Please sign in to comment.