Skip to content

Commit 4dcfe27

Browse files
authored
fix(@ngtools/webpack): performance improvement. (angular#3360)
1 parent 787dfa2 commit 4dcfe27

File tree

11 files changed

+73
-28
lines changed

11 files changed

+73
-28
lines changed

packages/webpack/src/plugin.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ export class AotPlugin implements Tapable {
160160
this._compiler = compiler;
161161

162162
compiler.plugin('context-module-factory', (cmf: any) => {
163-
cmf.resolvers.normal.apply(new PathsPlugin({
164-
tsConfigPath: this._tsConfigPath,
165-
compilerOptions: this._compilerOptions,
166-
compilerHost: this._compilerHost
167-
}));
168-
169163
cmf.plugin('before-resolve', (request: any, callback: (err?: any, request?: any) => void) => {
170164
if (!request) {
171165
return callback();
@@ -209,6 +203,11 @@ export class AotPlugin implements Tapable {
209203
cb();
210204
}
211205
});
206+
compiler.resolvers.normal.apply(new PathsPlugin({
207+
tsConfigPath: this._tsConfigPath,
208+
compilerOptions: this._compilerOptions,
209+
compilerHost: this._compilerHost
210+
}));
212211
}
213212

214213
private _make(compilation: any, cb: (err?: any, request?: any) => void) {

packages/webpack/src/refactor.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,14 @@ export class TypeScriptFileRefactor {
172172
}
173173

174174
transpile(compilerOptions: ts.CompilerOptions): TranspileOutput {
175-
compilerOptions = Object.assign({}, compilerOptions, {
176-
sourceMap: true,
177-
inlineSources: false,
178-
inlineSourceMap: false,
179-
sourceRoot: ''
180-
});
181-
182175
const source = this.sourceText;
183176
const result = ts.transpileModule(source, {
184-
compilerOptions,
177+
compilerOptions: Object.assign({}, compilerOptions, {
178+
sourceMap: true,
179+
inlineSources: false,
180+
inlineSourceMap: false,
181+
sourceRoot: ''
182+
}),
185183
fileName: this._fileName
186184
});
187185

tests/e2e/setup/100-npm-link.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {join} from 'path';
22
import {npm, exec} from '../utils/process';
33
import {updateJsonFile} from '../utils/project';
4+
import {getGlobalVariable} from '../utils/env';
45

56
const packages = require('../../../lib/packages');
67

78

8-
export default function (argv: any) {
9+
export default function () {
910
return Promise.resolve()
1011
.then(() => {
12+
const argv = getGlobalVariable('argv');
1113
if (argv.nolink) {
1214
return;
1315
}

tests/e2e/setup/200-create-tmp-dir.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import {setGlobalVariable} from '../utils/env';
1+
import {setGlobalVariable, getGlobalVariable} from '../utils/env';
22

33

44
const temp = require('temp');
55

6-
export default function(argv: any) {
6+
export default function() {
7+
const argv = getGlobalVariable('argv');
8+
79
// Get to a temporary directory.
810
let tempRoot = argv.reuse || temp.mkdirSync('angular-cli-e2e-');
911
console.log(` Using "${tempRoot}" as temporary directory for a new project.`);

tests/e2e/setup/500-create-project.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import {isMobileTest} from '../utils/utils';
44
import {expectFileToExist} from '../utils/fs';
55
import {updateTsConfig, updateJsonFile} from '../utils/project';
66
import {gitClean, gitCommit} from '../utils/git';
7+
import {getGlobalVariable} from '../utils/env';
78

89

910
let packages = require('../../../lib/packages');
1011

1112

12-
export default function(argv: any) {
13+
export default function() {
14+
const argv = getGlobalVariable('argv');
1315
let createProject = null;
1416

1517
// This is a dangerous flag, but is useful for testing packages only.

tests/e2e/tests/commands/new/new-routing.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import * as path from 'path';
21
import {ng} from '../../../utils/process';
3-
import {getGlobalVariable} from '../../../utils/env';
2+
import {createProject} from '../../../utils/project';
3+
44

55
export default function() {
66
return Promise.resolve()
7-
.then(() => process.chdir(getGlobalVariable('tmp-root')))
8-
.then(() => ng('new', 'routing-project', '--routing'))
9-
.then(() => process.chdir(path.join('routing-project')))
7+
.then(() => createProject('routing-project', '--routing'))
108

119
// Try to run the unit tests.
1210
.then(() => ng('test', '--single-run'));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ng} from '../../utils/process';
55
import {addImportToModule} from '../../utils/ast';
66

77

8-
export default function(argv: any) {
8+
export default function() {
99
let oldNumberOfFiles = 0;
1010
return Promise.resolve()
1111
.then(() => ng('build'))

tests/e2e/tests/packages/webpack/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {join} from 'path';
55
import {expectFileSizeToBeUnder} from '../../../utils/fs';
66

77

8-
export default function(argv: any, skipCleaning: () => void) {
8+
export default function(skipCleaning: () => void) {
99
if (process.platform.startsWith('win')) {
1010
// Disable the test on Windows.
1111
return Promise.resolve();

tests/e2e/tests/packages/webpack/weird.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {expectFileSizeToBeUnder, expectFileToExist} from '../../../utils/fs';
66
import {expectToFail} from '../../../utils/utils';
77

88

9-
export default function(argv: any, skipCleaning: () => void) {
9+
export default function(skipCleaning: () => void) {
1010
if (process.platform.startsWith('win')) {
1111
// Disable the test on Windows.
1212
return Promise.resolve();

tests/e2e/utils/project.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {readFile, writeFile} from './fs';
2-
import {silentExecAndWaitForOutputToMatch} from './process';
2+
import {silentExecAndWaitForOutputToMatch, silentNpm, ng} from './process';
3+
import {getGlobalVariable} from './env';
4+
5+
const packages = require('../../../lib/packages');
6+
37

48
const tsConfigPath = 'src/tsconfig.json';
59

@@ -24,3 +28,39 @@ export function ngServe(...args: string[]) {
2428
return silentExecAndWaitForOutputToMatch('ng',
2529
['serve', ...args], /webpack: bundle is now VALID/);
2630
}
31+
32+
33+
export function createProject(name: string, ...args: string[]) {
34+
return Promise.resolve()
35+
.then(() => process.chdir(getGlobalVariable('tmp-root')))
36+
.then(() => ng('new', name, '--skip-npm', ...args))
37+
.then(() => process.chdir(name))
38+
.then(() => updateJsonFile('package.json', json => {
39+
Object.keys(packages).forEach(pkgName => {
40+
json['dependencies'][pkgName] = packages[pkgName].dist;
41+
});
42+
}))
43+
.then(() => {
44+
const argv: any = getGlobalVariable('argv');
45+
if (argv.nightly) {
46+
return updateJsonFile('package.json', json => {
47+
// Install over the project with nightly builds.
48+
const angularPackages = [
49+
'core',
50+
'common',
51+
'compiler',
52+
'forms',
53+
'http',
54+
'router',
55+
'platform-browser',
56+
'platform-browser-dynamic'
57+
];
58+
angularPackages.forEach(pkgName => {
59+
json['dependencies'][`@angular/${pkgName}`] = `github:angular/${pkgName}-builds`;
60+
});
61+
});
62+
}
63+
})
64+
.then(() => console.log(`Project ${name} created... Installing npm.`))
65+
.then(() => silentNpm('install'));
66+
}

tests/e2e_runner.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const green = chalk.green;
1818
const red = chalk.red;
1919
const white = chalk.white;
2020

21+
const setGlobalVariable = require('./e2e/utils/env').setGlobalVariable;
22+
2123

2224
/**
2325
* Here's a short description of those flags:
@@ -73,6 +75,8 @@ if (testsToRun.length == allTests.length) {
7375
console.log(`Running ${testsToRun.length} tests (${allTests.length + allSetups.length} total)`);
7476
}
7577

78+
setGlobalVariable('argv', argv);
79+
7680
testsToRun.reduce((previous, relativeName) => {
7781
// Make sure this is a windows compatible path.
7882
let absoluteName = path.join(e2eRoot, relativeName);
@@ -96,7 +100,7 @@ testsToRun.reduce((previous, relativeName) => {
96100
return Promise.resolve()
97101
.then(() => printHeader(currentFileName))
98102
.then(() => previousDir = process.cwd())
99-
.then(() => fn(argv, () => clean = false))
103+
.then(() => fn(() => clean = false))
100104
.then(() => console.log(' ----'))
101105
.then(() => {
102106
// If we're not in a setup, change the directory back to where it was before the test.

0 commit comments

Comments
 (0)