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(@ngtools/webpack): performance improvement. #3360

Merged
merged 2 commits into from
Dec 3, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,6 @@ export class AotPlugin implements Tapable {
this._compiler = compiler;

compiler.plugin('context-module-factory', (cmf: any) => {
cmf.resolvers.normal.apply(new PathsPlugin({
tsConfigPath: this._tsConfigPath,
compilerOptions: this._compilerOptions,
compilerHost: this._compilerHost
}));

cmf.plugin('before-resolve', (request: any, callback: (err?: any, request?: any) => void) => {
if (!request) {
return callback();
Expand Down Expand Up @@ -209,6 +203,11 @@ export class AotPlugin implements Tapable {
cb();
}
});
compiler.resolvers.normal.apply(new PathsPlugin({
tsConfigPath: this._tsConfigPath,
compilerOptions: this._compilerOptions,
compilerHost: this._compilerHost
}));
}

private _make(compilation: any, cb: (err?: any, request?: any) => void) {
Expand Down
14 changes: 6 additions & 8 deletions packages/webpack/src/refactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,14 @@ export class TypeScriptFileRefactor {
}

transpile(compilerOptions: ts.CompilerOptions): TranspileOutput {
compilerOptions = Object.assign({}, compilerOptions, {
sourceMap: true,
inlineSources: false,
inlineSourceMap: false,
sourceRoot: ''
});

const source = this.sourceText;
const result = ts.transpileModule(source, {
compilerOptions,
compilerOptions: Object.assign({}, compilerOptions, {
sourceMap: true,
inlineSources: false,
inlineSourceMap: false,
sourceRoot: ''
}),
fileName: this._fileName
});

Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/setup/100-npm-link.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {join} from 'path';
import {npm, exec} from '../utils/process';
import {updateJsonFile} from '../utils/project';
import {getGlobalVariable} from '../utils/env';

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


export default function (argv: any) {
export default function () {
return Promise.resolve()
.then(() => {
const argv = getGlobalVariable('argv');
if (argv.nolink) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/setup/200-create-tmp-dir.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {setGlobalVariable} from '../utils/env';
import {setGlobalVariable, getGlobalVariable} from '../utils/env';


const temp = require('temp');

export default function(argv: any) {
export default function() {
const argv = getGlobalVariable('argv');

// Get to a temporary directory.
let tempRoot = argv.reuse || temp.mkdirSync('angular-cli-e2e-');
console.log(` Using "${tempRoot}" as temporary directory for a new project.`);
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/setup/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {isMobileTest} from '../utils/utils';
import {expectFileToExist} from '../utils/fs';
import {updateTsConfig, updateJsonFile} from '../utils/project';
import {gitClean, gitCommit} from '../utils/git';
import {getGlobalVariable} from '../utils/env';


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


export default function(argv: any) {
export default function() {
const argv = getGlobalVariable('argv');
let createProject = null;

// This is a dangerous flag, but is useful for testing packages only.
Expand Down
8 changes: 3 additions & 5 deletions tests/e2e/tests/commands/new/new-routing.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as path from 'path';
import {ng} from '../../../utils/process';
import {getGlobalVariable} from '../../../utils/env';
import {createProject} from '../../../utils/project';


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

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/misc/lazy-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ng} from '../../utils/process';
import {addImportToModule} from '../../utils/ast';


export default function(argv: any) {
export default function() {
let oldNumberOfFiles = 0;
return Promise.resolve()
.then(() => ng('build'))
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/packages/webpack/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {join} from 'path';
import {expectFileSizeToBeUnder} from '../../../utils/fs';


export default function(argv: any, skipCleaning: () => void) {
export default function(skipCleaning: () => void) {
if (process.platform.startsWith('win')) {
// Disable the test on Windows.
return Promise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/packages/webpack/weird.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {expectFileSizeToBeUnder, expectFileToExist} from '../../../utils/fs';
import {expectToFail} from '../../../utils/utils';


export default function(argv: any, skipCleaning: () => void) {
export default function(skipCleaning: () => void) {
if (process.platform.startsWith('win')) {
// Disable the test on Windows.
return Promise.resolve();
Expand Down
42 changes: 41 additions & 1 deletion tests/e2e/utils/project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {readFile, writeFile} from './fs';
import {silentExecAndWaitForOutputToMatch} from './process';
import {silentExecAndWaitForOutputToMatch, silentNpm, ng} from './process';
import {getGlobalVariable} from './env';

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


const tsConfigPath = 'src/tsconfig.json';

Expand All @@ -24,3 +28,39 @@ export function ngServe(...args: string[]) {
return silentExecAndWaitForOutputToMatch('ng',
['serve', ...args], /webpack: bundle is now VALID/);
}


export function createProject(name: string, ...args: string[]) {
return Promise.resolve()
.then(() => process.chdir(getGlobalVariable('tmp-root')))
.then(() => ng('new', name, '--skip-npm', ...args))
.then(() => process.chdir(name))
.then(() => updateJsonFile('package.json', json => {
Object.keys(packages).forEach(pkgName => {
json['dependencies'][pkgName] = packages[pkgName].dist;
});
}))
.then(() => {
const argv: any = getGlobalVariable('argv');
if (argv.nightly) {
return updateJsonFile('package.json', json => {
// Install over the project with nightly builds.
const angularPackages = [
'core',
'common',
'compiler',
'forms',
'http',
'router',
'platform-browser',
'platform-browser-dynamic'
];
angularPackages.forEach(pkgName => {
json['dependencies'][`@angular/${pkgName}`] = `github:angular/${pkgName}-builds`;
});
});
}
})
.then(() => console.log(`Project ${name} created... Installing npm.`))
.then(() => silentNpm('install'));
}
6 changes: 5 additions & 1 deletion tests/e2e_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const green = chalk.green;
const red = chalk.red;
const white = chalk.white;

const setGlobalVariable = require('./e2e/utils/env').setGlobalVariable;


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

setGlobalVariable('argv', argv);

testsToRun.reduce((previous, relativeName) => {
// Make sure this is a windows compatible path.
let absoluteName = path.join(e2eRoot, relativeName);
Expand All @@ -96,7 +100,7 @@ testsToRun.reduce((previous, relativeName) => {
return Promise.resolve()
.then(() => printHeader(currentFileName))
.then(() => previousDir = process.cwd())
.then(() => fn(argv, () => clean = false))
.then(() => fn(() => clean = false))
.then(() => console.log(' ----'))
.then(() => {
// If we're not in a setup, change the directory back to where it was before the test.
Expand Down