Skip to content

Commit

Permalink
feat(angular-cli): Add a postinstall warning for Node 4 deprecation.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node < 6.9 will be deprecated soon, and this will show a warning to users. Moving forward, that warning will be moved to an error with the next release.
  • Loading branch information
hansl committed Jan 31, 2017
1 parent 3e03c97 commit 4f4a804
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
52 changes: 45 additions & 7 deletions packages/angular-cli/bin/ng
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
// Provide a title to the process in `ps`
process.title = 'angular-cli';

const resolve = require('resolve');
const packageJson = require('../package.json');
const CliConfig = require('../models/config').CliConfig;
const Version = require('../upgrade/version').Version;
const yellow = require('chalk').yellow;
const SemVer = require('semver').SemVer;

const fs = require('fs');
const packageJson = require('../package.json');
const path = require('path');
const resolve = require('resolve');
const stripIndents = require('common-tags').stripIndents;
const yellow = require('chalk').yellow;
const SemVer = require('semver').SemVer;


function _fromPackageJson(cwd) {
Expand Down Expand Up @@ -59,6 +62,37 @@ if (process.env['NG_CLI_PROFILING']) {
}


// Show the warnings due to package and version deprecation.
const version = new SemVer(process.version);
if (version.compare(new SemVer('6.9.0')) < 0
&& CliConfig.fromGlobal().get('warnings.nodeDeprecation')) {
process.stderr.write(yellow(stripIndents`
We detected that you are using Node v${version.version}. Unfortunately, this version will not
be officially supported when the Angular CLI is released. The official Node version that will
be supported is 6.9 and greater. This beta release (Beta.27) will be the last release to
support Node 4.
This is to ensure that we can provide our users with better support for the upcoming releases.
Many of our dependencies are moving to deprecating Node 4 already and that would mean that we
could not update them to the latest versions which might have bug fixes and new useful features.
To disable this warning use "ng set --global warnings.nodeDeprecation=false".
`));
}


if (require('../package.json')['name'] == 'angular-cli'
&& CliConfig.fromGlobal().get('warnings.packageDeprecation')) {
process.stderr.write(yellow(stripIndents`
As a forewarning, We are moving the CLI npm package to "@angular/cli" with the next release,
which will only support Node 6.9 and greater. This package will be officially deprecated
shortly after.
To disable this warning use "ng set --global warnings.packageDeprecation=false".
`));
}


resolve('angular-cli', { basedir: process.cwd() },
function (error, projectLocalCli) {
var cli;
Expand All @@ -85,10 +119,14 @@ resolve('angular-cli', { basedir: process.cwd() },
shouldWarn = true;
}

if (shouldWarn) {
if (shouldWarn && CliConfig.fromGlobal().get('warnings.versionMismatch')) {
// eslint-disable no-console
console.log(yellow(`Your global Angular CLI version (${globalVersion}) is greater than `
+ `your local version (${localVersion}). The local Angular CLI version is used.`));
console.log(yellow(stripIndents`
Your global Angular CLI version (${globalVersion}) is greater than your local
version (${localVersion}). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
`));
}

// No error implies a projectLocalCli, which will load whatever
Expand Down
21 changes: 21 additions & 0 deletions packages/angular-cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,27 @@
}
},
"additionalProperties": false
},
"warnings": {
"description": "Allow people to disable console warnings.",
"type": "object",
"properties": {
"nodeDeprecation": {
"description": "Show a warning when the node version is incompatible.",
"type": "boolean",
"default": true
},
"packageDeprecation": {
"description": "Show a warning when the user installed angular-cli.",
"type": "boolean",
"default": true
},
"versionMismatch": {
"description": "Show a warning when the global version is newer than the local one.",
"type": "boolean",
"default": true
}
}
}
},
"additionalProperties": false
Expand Down
3 changes: 3 additions & 0 deletions packages/angular-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"node": ">= 4.1.0",
"npm": ">= 3.0.0"
},
"scripts": {
"postinstall": "node ./scripts/install.js"
},
"author": "Angular Authors",
"license": "MIT",
"bugs": {
Expand Down

0 comments on commit 4f4a804

Please sign in to comment.