Skip to content

Commit

Permalink
fix(schematics): consider ExportDeclaration with a moduleSpecifier on…
Browse files Browse the repository at this point in the history
…ly for dependency calculation

Closes #1303
  • Loading branch information
dherges committed Apr 30, 2019
1 parent b288abd commit 4265b98
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
73 changes: 73 additions & 0 deletions packages/schematics/src/command-line/deps-calculator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,79 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
});
});

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 }
]
});
});

it('should calculate dependencies in .tsx files', () => {
const deps = dependencies(
'nrwl',
Expand Down
5 changes: 4 additions & 1 deletion packages/schematics/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 4265b98

Please sign in to comment.