Skip to content

Commit

Permalink
fix(NgModule): dont link to files excluded via tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed Jan 19, 2017
1 parent 93a40de commit 3063f10
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 7 deletions.
35 changes: 33 additions & 2 deletions dist/index-cli.js

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion src/app/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,32 @@ export class Application {

prepareModules() {
logger.info('Prepare modules');
this.configuration.mainData.modules = $dependenciesEngine.getModules();
this.configuration.mainData.modules = $dependenciesEngine.getModules().map(ngModule => {
['declarations', 'bootstrap', 'imports', 'exports'].forEach(metadataType => {
ngModule[metadataType] = ngModule[metadataType].filter(metaDataItem => {
switch (metaDataItem.type) {
case 'directive':
return $dependenciesEngine.getDirectives().some(directive => directive.name === metaDataItem.name);

case 'component':
return $dependenciesEngine.getComponents().some(component => component.name === metaDataItem.name);

case 'module':
return $dependenciesEngine.getModules().some(module => module.name === metaDataItem.name);

case 'pipe':
return $dependenciesEngine.getPipes().some(pipe => pipe.name === metaDataItem.name);

default:
return true;
}
});
});
ngModule.providers = ngModule.providers.filter(provider => {
return $dependenciesEngine.getInjectables().some(injectable => injectable.name === provider.name);
});
return ngModule;
});
this.configuration.addPage({
name: 'modules',
context: 'modules'
Expand Down
27 changes: 27 additions & 0 deletions test/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,5 +694,32 @@ describe('CLI', () => {

});

describe('when specific files are included in tsconfig', () => {

let stdoutString = null,
moduleFile = null;
before(function (done) {
tmp.create();
exec(tsNodePath + ' ./bin/index-cli.js -p ./test/src/sample-files/tsconfig.entry.json -d ' + tmp.name + '/', {env}, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
done('error');
return;
}
stdoutString = stdout;
moduleFile = read(`${tmp.name}/modules/AppModule.html`);
done();
});
});
after(() => tmp.clean(tmp.name));

it('should only create links to files included via tsconfig', () => {
expect(moduleFile).to.contain('components/FooComponent.html');
expect(moduleFile).to.contain('modules/FooModule.html');
expect(moduleFile).not.to.contain('components/BarComponent.html');
expect(moduleFile).not.to.contain('injectables/FooService.html');
expect(moduleFile).not.to.contain('modules/BarModule.html');
});
});

});
4 changes: 3 additions & 1 deletion test/src/sample-files/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { FooModule } from './foo.module';

@NgModule({
declarations: [
FooDirective, FooComponent
FooDirective,
FooComponent,
BarComponent
],
providers: [
FooService
Expand Down
4 changes: 3 additions & 1 deletion test/src/sample-files/tsconfig.entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"module": "commonjs"
},
"files": [
"app.module.ts"
"app.module.ts",
"foo.component.ts",
"foo.module.ts"
]
}

0 comments on commit 3063f10

Please sign in to comment.