diff --git a/packages/schematics/src/command-line/deps-calculator.spec.ts b/packages/schematics/src/command-line/deps-calculator.spec.ts index 1487f9ac008f7..2823ba93f0fc2 100644 --- a/packages/schematics/src/command-line/deps-calculator.spec.ts +++ b/packages/schematics/src/command-line/deps-calculator.spec.ts @@ -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', diff --git a/packages/schematics/src/command-line/deps-calculator.ts b/packages/schematics/src/command-line/deps-calculator.ts index f9c122b3493a9..c05afcb83c94a 100644 --- a/packages/schematics/src/command-line/deps-calculator.ts +++ b/packages/schematics/src/command-line/deps-calculator.ts @@ -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