From 9b26d138c72de44662b4028ef63e291560456a05 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Wed, 22 Mar 2017 22:36:04 +0000 Subject: [PATCH] feat(@angular/cli): always use ng4 in ng new Fix #5566 --- .travis.yml | 16 ++- .../ng/files/__path__/tsconfig.app.json | 13 +- .../ng/files/__path__/tsconfig.spec.json | 12 +- .../blueprints/ng/files/e2e/tsconfig.e2e.json | 11 +- .../cli/blueprints/ng/files/package.json | 20 +-- packages/@angular/cli/blueprints/ng/index.ts | 1 - packages/@angular/cli/commands/init.ts | 1 - packages/@angular/cli/commands/new.ts | 6 - packages/@angular/cli/tasks/init.ts | 1 - tests/e2e/setup/500-create-project.ts | 5 +- tests/e2e/utils/project.ts | 114 +++++++++++++++++- 11 files changed, 136 insertions(+), 64 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c3077b9a8e5..52956506836f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,9 @@ env: matrix: fast_finish: true allow_failures: + - env: NODE_SCRIPT="tests/run_e2e.js --nightly" + - env: NODE_SCRIPT="tests/run_e2e.js --ng2" - node_js: "7" - - env: NODE_SCRIPT="tests/run_e2e.js --nightly --ng4" include: - node_js: "6" os: linux @@ -25,23 +26,20 @@ matrix: - node_js: "6" os: linux env: NODE_SCRIPT="tests/run_e2e.js --glob=tests/build/**" - - node_js: "6" - os: linux - env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**" - node_js: "6" os: linux env: NODE_SCRIPT="tests/run_e2e.js --ignore=**/tests/build/**" - node_js: "6" os: linux - env: NODE_SCRIPT="tests/run_e2e.js --ng4 --glob=tests/build/**" - - node_js: "6" - os: linux - env: NODE_SCRIPT="tests/run_e2e.js --ng4 --ignore=**/tests/build/**" + env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**" # Optional builds. - node_js: "6" os: linux - env: NODE_SCRIPT="tests/run_e2e.js --nightly --ng4" + env: NODE_SCRIPT="tests/run_e2e.js --ng2" + - node_js: "6" + os: linux + env: NODE_SCRIPT="tests/run_e2e.js --nightly" - node_js: "7" os: linux env: NODE_SCRIPT=tests/run_e2e.js diff --git a/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.app.json b/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.app.json index f40bd2db7ea3..eb874ea011a8 100644 --- a/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.app.json +++ b/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.app.json @@ -1,17 +1,6 @@ -{<% if (ng4) { %> +{ "extends": "<%= relativeRootPath %>/tsconfig.json", - "compilerOptions": {<% } else { %> "compilerOptions": { - "sourceMap": true, - "declaration": false, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "target": "es5", - "lib": [ - "es2016", - "dom" - ],<% } %> "outDir": "<%= relativeRootPath %>/out-tsc/app", "module": "es2015", "baseUrl": "", diff --git a/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.spec.json b/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.spec.json index 0bba9ea2069c..d072d14b1bd5 100644 --- a/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.spec.json +++ b/packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.spec.json @@ -1,16 +1,6 @@ -{<% if (ng4) { %> +{ "extends": "<%= relativeRootPath %>/tsconfig.json", - "compilerOptions": {<% } else { %> "compilerOptions": { - "sourceMap": true, - "declaration": false, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": [ - "es2016", - "dom" - ],<% } %> "outDir": "<%= relativeRootPath %>/out-tsc/spec", "module": "commonjs", "target": "es5", diff --git a/packages/@angular/cli/blueprints/ng/files/e2e/tsconfig.e2e.json b/packages/@angular/cli/blueprints/ng/files/e2e/tsconfig.e2e.json index 674dd643c913..ac7a37325798 100644 --- a/packages/@angular/cli/blueprints/ng/files/e2e/tsconfig.e2e.json +++ b/packages/@angular/cli/blueprints/ng/files/e2e/tsconfig.e2e.json @@ -1,15 +1,6 @@ -{<% if (ng4) { %> +{ "extends": "../tsconfig.json", - "compilerOptions": {<% } else { %> "compilerOptions": { - "sourceMap": true, - "declaration": false, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": [ - "es2016" - ],<% } %> "outDir": "../out-tsc/e2e", "module": "commonjs", "target": "es5", diff --git a/packages/@angular/cli/blueprints/ng/files/package.json b/packages/@angular/cli/blueprints/ng/files/package.json index d74bc410a5d8..810087dccb0f 100644 --- a/packages/@angular/cli/blueprints/ng/files/package.json +++ b/packages/@angular/cli/blueprints/ng/files/package.json @@ -12,21 +12,21 @@ }, "private": true, "dependencies": { - "@angular/common": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/compiler": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/core": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/forms": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/http": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/platform-browser": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/platform-browser-dynamic": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", - "@angular/router": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^3.4.0' %>", + "@angular/common": "^4.0.0", + "@angular/compiler": "^4.0.0", + "@angular/core": "^4.0.0", + "@angular/forms": "^4.0.0", + "@angular/http": "^4.0.0", + "@angular/platform-browser": "^4.0.0", + "@angular/platform-browser-dynamic": "^4.0.0", + "@angular/router": "^4.0.0", "core-js": "^2.4.1", "rxjs": "^5.1.0", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "<%= version %>", - "@angular/compiler-cli": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>", + "@angular/compiler-cli": "^4.0.0", "@types/jasmine": "2.5.38", "@types/node": "~6.0.60", "codelyzer": "~2.0.0", @@ -41,6 +41,6 @@ "protractor": "~5.1.0", "ts-node": "~2.0.0", "tslint": "~4.5.0", - "typescript": "<%= ng4 ? '~2.1.0' : '~2.0.0' %>" + "typescript": "~2.2.0" } } diff --git a/packages/@angular/cli/blueprints/ng/index.ts b/packages/@angular/cli/blueprints/ng/index.ts index 4de8a42cf01d..53516a38fe38 100644 --- a/packages/@angular/cli/blueprints/ng/index.ts +++ b/packages/@angular/cli/blueprints/ng/index.ts @@ -54,7 +54,6 @@ export default Blueprint.extend({ routing: options.routing, inlineStyle: options.inlineStyle, inlineTemplate: options.inlineTemplate, - ng4: options.ng4, tests: this.tests }; }, diff --git a/packages/@angular/cli/commands/init.ts b/packages/@angular/cli/commands/init.ts index e8cb2979d996..d696e1926f08 100644 --- a/packages/@angular/cli/commands/init.ts +++ b/packages/@angular/cli/commands/init.ts @@ -9,7 +9,6 @@ const InitCommand: any = Command.extend({ { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, { name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] }, - { name: 'ng4', type: Boolean, default: false }, { name: 'skip-install', type: Boolean, default: false, aliases: ['si'] }, { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }, { name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] }, diff --git a/packages/@angular/cli/commands/new.ts b/packages/@angular/cli/commands/new.ts index 0fd2945821e8..fbd28b971c51 100644 --- a/packages/@angular/cli/commands/new.ts +++ b/packages/@angular/cli/commands/new.ts @@ -40,12 +40,6 @@ const NewCommand = Command.extend({ aliases: ['lc'], description: 'Automatically link the `@angular/cli` package.' }, - { - name: 'ng4', - type: Boolean, - default: false, - description: 'Create a project with Angular 4 in the template.' - }, { name: 'skip-install', type: Boolean, diff --git a/packages/@angular/cli/tasks/init.ts b/packages/@angular/cli/tasks/init.ts index 8f4edd4a753f..2d0596796d04 100644 --- a/packages/@angular/cli/tasks/init.ts +++ b/packages/@angular/cli/tasks/init.ts @@ -75,7 +75,6 @@ export default Task.extend({ inlineStyle: commandOptions.inlineStyle, inlineTemplate: commandOptions.inlineTemplate, ignoredUpdateFiles: ['favicon.ico'], - ng4: commandOptions.ng4, skipGit: commandOptions.skipGit, skipTests: commandOptions.skipTests }; diff --git a/tests/e2e/setup/500-create-project.ts b/tests/e2e/setup/500-create-project.ts index e2343cfdbb15..1e25b3ac2db0 100644 --- a/tests/e2e/setup/500-create-project.ts +++ b/tests/e2e/setup/500-create-project.ts @@ -1,7 +1,7 @@ import {join} from 'path'; import {git, ng, silentNpm} from '../utils/process'; import {expectFileToExist} from '../utils/fs'; -import {updateTsConfig, updateJsonFile} from '../utils/project'; +import {updateTsConfig, updateJsonFile, useNg2} from '../utils/project'; import {gitClean, gitCommit} from '../utils/git'; import {getGlobalVariable} from '../utils/env'; @@ -24,7 +24,7 @@ export default function() { } else { // Otherwise create a project from scratch. createProject = Promise.resolve() - .then(() => ng('new', 'test-project', '--skip-install', ...(argv['ng4'] ? ['--ng4'] : []))) + .then(() => ng('new', 'test-project', '--skip-install')) .then(() => expectFileToExist(join(process.cwd(), 'test-project'))) .then(() => process.chdir('./test-project')); } @@ -36,6 +36,7 @@ export default function() { json['dependencies'][pkgName] = packages[pkgName].dist; }); })) + .then(() => argv['ng2'] ? useNg2() : Promise.resolve()) .then(() => { if (argv['nightly'] || argv['ng-sha']) { const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : ''; diff --git a/tests/e2e/utils/project.ts b/tests/e2e/utils/project.ts index 2c338b50c6cf..edc645d88148 100644 --- a/tests/e2e/utils/project.ts +++ b/tests/e2e/utils/project.ts @@ -36,13 +36,14 @@ export function createProject(name: string, ...args: string[]) { return Promise.resolve() .then(() => process.chdir(getGlobalVariable('tmp-root'))) - .then(() => ng('new', name, '--skip-install', ...(argv['ng4'] ? ['--ng4'] : []), ...args)) + .then(() => ng('new', name, '--skip-install', ...args)) .then(() => process.chdir(name)) .then(() => updateJsonFile('package.json', json => { Object.keys(packages).forEach(pkgName => { json['dependencies'][pkgName] = packages[pkgName].dist; }); })) + .then(() => argv['ng2'] ? useNg2() : Promise.resolve()) .then(() => { if (argv.nightly || argv['ng-sha']) { const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : ''; @@ -75,3 +76,114 @@ export function createProject(name: string, ...args: string[]) { .then(() => console.log(`Project ${name} created... Installing npm.`)) .then(() => silentNpm('install')); } + +// Convert a Angular 4 project to Angular 2. +export function useNg2() { + const ng2Deps: any = { + 'dependencies': { + '@angular/common': '^2.4.0', + '@angular/compiler': '^2.4.0', + '@angular/core': '^2.4.0', + '@angular/forms': '^2.4.0', + '@angular/http': '^2.4.0', + '@angular/platform-browser': '^2.4.0', + '@angular/platform-browser-dynamic': '^2.4.0', + '@angular/router': '^3.4.0', + 'zone.js': '^0.7.4' + }, + 'devDependencies': { + '@angular/compiler-cli': '^2.4.0', + 'typescript': '~2.0.0' + } + }; + + const tsconfigAppJson: any = { + 'compilerOptions': { + 'sourceMap': true, + 'declaration': false, + 'moduleResolution': 'node', + 'emitDecoratorMetadata': true, + 'experimentalDecorators': true, + 'target': 'es5', + 'lib': [ + 'es2016', + 'dom' + ], + 'outDir': '../out-tsc/app', + 'module': 'es2015', + 'baseUrl': '', + 'types': [] + }, + 'exclude': [ + 'test.ts', + '**/*.spec.ts' + ] + }; + + const tsconfigSpecJson: any = { + 'compilerOptions': { + 'sourceMap': true, + 'declaration': false, + 'moduleResolution': 'node', + 'emitDecoratorMetadata': true, + 'experimentalDecorators': true, + 'lib': [ + 'es2016', + 'dom' + ], + 'outDir': '../out-tsc/spec', + 'module': 'commonjs', + 'target': 'es5', + 'baseUrl': '', + 'types': [ + 'jasmine', + 'node' + ] + }, + 'files': [ + 'test.ts' + ], + 'include': [ + '**/*.spec.ts', + '**/*.d.ts' + ] + }; + + const tsconfigE2eJson: any = { + 'compilerOptions': { + 'sourceMap': true, + 'declaration': false, + 'moduleResolution': 'node', + 'emitDecoratorMetadata': true, + 'experimentalDecorators': true, + 'lib': [ + 'es2016' + ], + 'outDir': '../out-tsc/e2e', + 'module': 'commonjs', + 'target': 'es5', + 'types': [ + 'jasmine', + 'node' + ] + } + }; + + + return Promise.resolve() + .then(() => updateJsonFile('package.json', json => { + Object.keys(ng2Deps['dependencies']).forEach(pkgName => { + json['dependencies'][pkgName] = ng2Deps['dependencies'][pkgName]; + }); + Object.keys(ng2Deps['devDependencies']).forEach(pkgName => { + json['devDependencies'][pkgName] = ng2Deps['devDependencies'][pkgName]; + }); + console.log(JSON.stringify(json)) + })) + .then(() => updateJsonFile('src/tsconfig.app.json', json => + Object.assign(json, tsconfigAppJson))) + .then(() => updateJsonFile('src/tsconfig.spec.json', json => + Object.assign(json, tsconfigSpecJson))) + .then(() => updateJsonFile('e2e/tsconfig.e2e.json', json => + Object.assign(json, tsconfigE2eJson))); +}