Skip to content

Commit 33c9c73

Browse files
authored
fix: lazy loading now works as expected with latest webpack (angular#2038)
1 parent 78b0126 commit 33c9c73

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

.appveyor.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ environment:
33
- nodejs_version: "5.0"
44
- nodejs_version: "6.0"
55

6+
matrix:
7+
fast_finish: true
8+
69
install:
710
- ps: Install-Product node $env:nodejs_version
811
- npm install

addon/ng2/models/find-lazy-modules.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,16 @@ export function findLoadChildren(tsFilePath: string): string[] {
5151

5252

5353
export function findLazyModules(projectRoot: any): string[] {
54-
const result: {[key: string]: boolean} = {};
54+
const result: {[key: string]: string} = {};
5555
glob.sync(path.join(projectRoot, '/**/*.ts'))
5656
.forEach(tsPath => {
5757
findLoadChildren(tsPath).forEach(moduleName => {
58-
const fileName = path.resolve(path.dirname(tsPath), moduleName) + '.ts';
58+
const fileName = path.resolve(projectRoot, moduleName) + '.ts';
5959
if (fs.existsSync(fileName)) {
6060
// Put the moduleName as relative to the main.ts.
61-
const fullPath = path.resolve(path.dirname(tsPath), moduleName);
62-
const name = `./${path.relative(projectRoot, fullPath)}.ts`;
63-
result[name] = true;
61+
result[moduleName] = fileName;
6462
}
6563
});
6664
});
67-
return Object.keys(result);
65+
return result;
6866
}

tests/acceptance/find-lazy-module.spec.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ describe('find-lazy-module', () => {
3939
afterEach(() => mockFs.restore());
4040

4141
it('works', () => {
42-
expect(findLazyModules('project-root')).to.eql([
43-
'./' + join('.', 'moduleA.ts'),
44-
'./' + join('.', 'moduleB.ts'),
45-
'./' + join('.', 'moduleC.ts'),
46-
'./' + join('.', 'app/+workspace/+settings/settings.module.ts')
47-
]);
42+
expect(findLazyModules('project-root')).to.eql({
43+
'moduleA': join(process.cwd(), 'project-root', 'moduleA.ts'),
44+
'moduleB': join(process.cwd(), 'project-root', 'moduleB.ts'),
45+
'moduleC': join(process.cwd(), 'project-root', 'moduleC.ts'),
46+
'app/+workspace/+settings/settings.module':
47+
join(process.cwd(), 'project-root', 'app/+workspace/+settings/settings.module.ts'),
48+
});
4849
});
4950
});

tests/e2e/tests/misc/lazy-module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export default function(argv: any) {
1717
return Promise.resolve()
1818
.then(() => ng('build'))
1919
.then(() => oldNumberOfFiles = readdirSync('dist').length)
20-
.then(() => ng('generate', 'module', 'lazy'))
20+
.then(() => ng('generate', 'module', 'lazy', '--routing'))
2121
.then(() => addImportToModule('src/app/app.module.ts', oneLine`
22-
RouterModule.forRoot([{ path: "/lazy", loadChildren: "./lazy/lazy.module#LazyModule" }])
22+
RouterModule.forRoot([{ path: "lazy", loadChildren: "app/lazy/lazy.module#LazyModule" }])
2323
`, '@angular/router'))
2424
.then(() => ng('build'))
2525
.then(() => currentNumberOfDistFiles = readdirSync('dist').length)

tests/e2e_runner.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ testsToRun.reduce((previous, relativeName) => {
104104
});
105105
}, Promise.resolve())
106106
.then(
107-
() => console.log(green('Done.')),
107+
() => {
108+
console.log(green('Done.'));
109+
process.exit(0);
110+
},
108111
(err) => {
109112
console.log('\n');
110113
console.error(red(`Test "${currentFileName}" failed...`));

0 commit comments

Comments
 (0)