diff --git a/packages/webpack/src/plugin.ts b/packages/webpack/src/plugin.ts index 1d80dc8780a5..2fb79cffad8c 100644 --- a/packages/webpack/src/plugin.ts +++ b/packages/webpack/src/plugin.ts @@ -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(); @@ -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) { diff --git a/packages/webpack/src/refactor.ts b/packages/webpack/src/refactor.ts index d7f64e4fba57..d38444d75c6f 100644 --- a/packages/webpack/src/refactor.ts +++ b/packages/webpack/src/refactor.ts @@ -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 }); diff --git a/tests/e2e/setup/100-npm-link.ts b/tests/e2e/setup/100-npm-link.ts index 396b974d94ec..a04a6980dfbd 100644 --- a/tests/e2e/setup/100-npm-link.ts +++ b/tests/e2e/setup/100-npm-link.ts @@ -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; } diff --git a/tests/e2e/setup/200-create-tmp-dir.ts b/tests/e2e/setup/200-create-tmp-dir.ts index 8cd88ec70a11..e63d150721de 100644 --- a/tests/e2e/setup/200-create-tmp-dir.ts +++ b/tests/e2e/setup/200-create-tmp-dir.ts @@ -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.`); diff --git a/tests/e2e/setup/500-create-project.ts b/tests/e2e/setup/500-create-project.ts index 2e39507af4f4..87e0555dcdb2 100644 --- a/tests/e2e/setup/500-create-project.ts +++ b/tests/e2e/setup/500-create-project.ts @@ -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. diff --git a/tests/e2e/tests/commands/new/new-routing.ts b/tests/e2e/tests/commands/new/new-routing.ts index cfd612f58691..1726abad6c21 100644 --- a/tests/e2e/tests/commands/new/new-routing.ts +++ b/tests/e2e/tests/commands/new/new-routing.ts @@ -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')); diff --git a/tests/e2e/tests/misc/lazy-module.ts b/tests/e2e/tests/misc/lazy-module.ts index 4fff6b80ae04..d3d33482d877 100644 --- a/tests/e2e/tests/misc/lazy-module.ts +++ b/tests/e2e/tests/misc/lazy-module.ts @@ -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')) diff --git a/tests/e2e/tests/packages/webpack/test.ts b/tests/e2e/tests/packages/webpack/test.ts index 2aef881606f5..be4a2b1e708e 100644 --- a/tests/e2e/tests/packages/webpack/test.ts +++ b/tests/e2e/tests/packages/webpack/test.ts @@ -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(); diff --git a/tests/e2e/tests/packages/webpack/weird.ts b/tests/e2e/tests/packages/webpack/weird.ts index 2987d935aae4..26f2eca981be 100644 --- a/tests/e2e/tests/packages/webpack/weird.ts +++ b/tests/e2e/tests/packages/webpack/weird.ts @@ -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(); diff --git a/tests/e2e/utils/project.ts b/tests/e2e/utils/project.ts index befb308e048b..45569278d1ad 100644 --- a/tests/e2e/utils/project.ts +++ b/tests/e2e/utils/project.ts @@ -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'; @@ -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')); +} diff --git a/tests/e2e_runner.js b/tests/e2e_runner.js index dc264f3eb4d3..9b8b79a5bc09 100644 --- a/tests/e2e_runner.js +++ b/tests/e2e_runner.js @@ -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: @@ -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); @@ -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.