Skip to content

Commit

Permalink
fix: lazy loading now works as expected with latest webpack (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl authored Sep 10, 2016
1 parent 78b0126 commit 33c9c73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ environment:
- nodejs_version: "5.0"
- nodejs_version: "6.0"

matrix:
fast_finish: true

install:
- ps: Install-Product node $env:nodejs_version
- npm install
Expand Down
10 changes: 4 additions & 6 deletions addon/ng2/models/find-lazy-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ export function findLoadChildren(tsFilePath: string): string[] {


export function findLazyModules(projectRoot: any): string[] {
const result: {[key: string]: boolean} = {};
const result: {[key: string]: string} = {};
glob.sync(path.join(projectRoot, '/**/*.ts'))
.forEach(tsPath => {
findLoadChildren(tsPath).forEach(moduleName => {
const fileName = path.resolve(path.dirname(tsPath), moduleName) + '.ts';
const fileName = path.resolve(projectRoot, moduleName) + '.ts';
if (fs.existsSync(fileName)) {
// Put the moduleName as relative to the main.ts.
const fullPath = path.resolve(path.dirname(tsPath), moduleName);
const name = `./${path.relative(projectRoot, fullPath)}.ts`;
result[name] = true;
result[moduleName] = fileName;
}
});
});
return Object.keys(result);
return result;
}
13 changes: 7 additions & 6 deletions tests/acceptance/find-lazy-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ describe('find-lazy-module', () => {
afterEach(() => mockFs.restore());

it('works', () => {
expect(findLazyModules('project-root')).to.eql([
'./' + join('.', 'moduleA.ts'),
'./' + join('.', 'moduleB.ts'),
'./' + join('.', 'moduleC.ts'),
'./' + join('.', 'app/+workspace/+settings/settings.module.ts')
]);
expect(findLazyModules('project-root')).to.eql({
'moduleA': join(process.cwd(), 'project-root', 'moduleA.ts'),
'moduleB': join(process.cwd(), 'project-root', 'moduleB.ts'),
'moduleC': join(process.cwd(), 'project-root', 'moduleC.ts'),
'app/+workspace/+settings/settings.module':
join(process.cwd(), 'project-root', 'app/+workspace/+settings/settings.module.ts'),
});
});
});
4 changes: 2 additions & 2 deletions tests/e2e/tests/misc/lazy-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default function(argv: any) {
return Promise.resolve()
.then(() => ng('build'))
.then(() => oldNumberOfFiles = readdirSync('dist').length)
.then(() => ng('generate', 'module', 'lazy'))
.then(() => ng('generate', 'module', 'lazy', '--routing'))
.then(() => addImportToModule('src/app/app.module.ts', oneLine`
RouterModule.forRoot([{ path: "/lazy", loadChildren: "./lazy/lazy.module#LazyModule" }])
RouterModule.forRoot([{ path: "lazy", loadChildren: "app/lazy/lazy.module#LazyModule" }])
`, '@angular/router'))
.then(() => ng('build'))
.then(() => currentNumberOfDistFiles = readdirSync('dist').length)
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ testsToRun.reduce((previous, relativeName) => {
});
}, Promise.resolve())
.then(
() => console.log(green('Done.')),
() => {
console.log(green('Done.'));
process.exit(0);
},
(err) => {
console.log('\n');
console.error(red(`Test "${currentFileName}" failed...`));
Expand Down

0 comments on commit 33c9c73

Please sign in to comment.