Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schematics): consider ExportDeclaration w/ moduleSpecifier for dependency calculation in v7 #1304

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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