diff --git a/README.md b/README.md index 71f4d7a7..bde183fd 100644 --- a/README.md +++ b/README.md @@ -157,11 +157,6 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp Manually set the CWD. The search for the gulpfile, as well as the relativity of all preloads (with the `--preload` flag) will be from here. - - --verify [path (optional)] - - Will verify plugins referenced in project's package.json against the plugins blacklist. - --tasks -T diff --git a/docs/CLI.md b/docs/CLI.md index fd40368f..0b2bd592 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -43,9 +43,6 @@ gulp has very few flags to know about. All other flags are for tasks to use if n **--cwd** [path] Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. -**--verify** [path (optional)] - Will verify plugins referenced in project's package.json against the plugins blacklist. - **--tasks**, **-T** Print the task dependency tree for the loaded gulpfile. diff --git a/index.js b/index.js index 9e5f43b6..935f8928 100644 --- a/index.js +++ b/index.js @@ -14,18 +14,12 @@ var tildify = require('./lib/shared/tildify'); var makeTitle = require('./lib/shared/make-title'); var parser = require('./lib/shared/options/parser'); var completion = require('./lib/shared/completion'); -var verifyDeps = require('./lib/shared/verify-dependencies'); var cliVersion = require('./package.json').version; -var getBlacklist = require('./lib/shared/blacklist'); var toConsole = require('./lib/shared/log/to-console'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); -// Logging functions -var logVerify = require('./lib/shared/log/verify'); -var logBlacklistError = require('./lib/shared/log/blacklist-error'); - // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -150,25 +144,6 @@ function onExecute(env) { exit(0); } - if (env.config.flags.verify) { - var pkgPath = env.config.flags.verify !== true ? env.config.flags.verify : 'package.json'; - /* istanbul ignore else */ - if (path.resolve(pkgPath) !== path.normalize(pkgPath)) { - pkgPath = path.join(env.cwd, pkgPath); - } - log.info('Verifying plugins in ' + pkgPath); - return getBlacklist(function(err, blacklist) { - /* istanbul ignore if */ - if (err) { - return logBlacklistError(err); - } - - var blacklisted = verifyDeps(require(pkgPath), blacklist); - - logVerify(blacklisted); - }); - } - if (!env.modulePath) { /* istanbul ignore next */ var missingNodeModules = diff --git a/lib/shared/blacklist/get-remote-json.js b/lib/shared/blacklist/get-remote-json.js deleted file mode 100644 index f5a21b68..00000000 --- a/lib/shared/blacklist/get-remote-json.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -var https = require('https'); - -function getRemoteJson(url, cb) { - var chunks = []; - - https.get(url, onRequest).on('error', onError);; - - function onRequest(res) { - if (res.statusCode !== 200) { - res.resume(); // Consume response data to free up memory - return cb(new Error('Request failed. Status Code: ' + res.statusCode)); - } - - res.on('error', onError); - res.on('data', onDrain); - res.on('end', onEnd); - } - - /* istanbul ignore next */ - function onError(e) { - cb(e, null); - } - - function onDrain(d) { - chunks.push(d); - } - - function onEnd() { - try { - cb(null, JSON.parse(Buffer.concat(chunks).toString('utf8'))); - } catch (err) { - cb(new Error('Invalid Blacklist JSON.')); - } - } -} - -module.exports = getRemoteJson; diff --git a/lib/shared/blacklist/index.js b/lib/shared/blacklist/index.js deleted file mode 100644 index edf66fa1..00000000 --- a/lib/shared/blacklist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -var getRemoteJson = require('./get-remote-json'); - -var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; - -function getBlacklist(cb) { - getRemoteJson(url, cb); -} - -module.exports = getBlacklist; diff --git a/lib/shared/log/blacklist-error.js b/lib/shared/log/blacklist-error.js deleted file mode 100644 index f3361b72..00000000 --- a/lib/shared/log/blacklist-error.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -var log = require('gulplog'); -var chalk = require('chalk'); - -var exit = require('../exit'); - -/* istanbul ignore next */ -function logBlacklistError(err) { - log.error(chalk.red('Error: failed to retrieve plugins black-list')); - log.error(err.message); // Avoid duplicating for each version - exit(1); -} - -module.exports = logBlacklistError; diff --git a/lib/shared/log/verify.js b/lib/shared/log/verify.js deleted file mode 100644 index f635bd39..00000000 --- a/lib/shared/log/verify.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var log = require('gulplog'); - -var chalk = require('chalk'); -var exit = require('../exit'); - -function logVerify(blacklisted) { - var pluginNames = Object.keys(blacklisted); - - if (!pluginNames.length) { - log.info( - chalk.green('There are no blacklisted plugins in this project') - ); - exit(0); - } - - log.warn(chalk.red('Blacklisted plugins found in this project:')); - - pluginNames.map(function(pluginName) { - var reason = blacklisted[pluginName]; - log.warn(chalk.bgRed(pluginName) + ': ' + reason); - }); - - exit(1); -} - -module.exports = logVerify; diff --git a/lib/shared/options/parser.js b/lib/shared/options/parser.js index 94801742..67594a05 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/parser.js @@ -42,11 +42,6 @@ var options = { 'Manually set the CWD. The search for the gulpfile, ' + 'as well as the relativity of all requires will be from here.'), }, - verify: { - desc: chalk.gray( - 'Will verify plugins referenced in project\'s package.json against ' + - 'the plugins blacklist.'), - }, tasks: { alias: 'T', type: 'boolean', diff --git a/lib/shared/verify-dependencies.js b/lib/shared/verify-dependencies.js deleted file mode 100644 index 2dbe9b7a..00000000 --- a/lib/shared/verify-dependencies.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -/** - * Given a collection of plugin names verifies this collection against - * the blacklist. Returns an object with: - * [plugin name]=>[blacklisting reason] - * or an empty object if none of the dependencies to check are blacklisted. - * - * @param pkg - package.json contents - * @param blacklist - contents of the blacklist in JSON format - */ -function verifyDependencies(pkg, blacklist) { - var pluginNames = [ - 'dependencies', - 'devDependencies', - 'peerDependencies', - ].reduce(function(res, prop) { - return res.concat(Object.keys(pkg[prop] || {})); - }, []); - - var blacklisted = pluginNames.filter(isContainedInBlacklist) - .reduce(function(blacklisted, pluginName) { - blacklisted[pluginName] = blacklist[pluginName]; - return blacklisted; - }, {}); - - return blacklisted; - - function isContainedInBlacklist(pluginName) { - return Boolean(blacklist[pluginName]); - } -} - -module.exports = verifyDependencies; diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt index fed71d76..bdf95bbe 100644 --- a/test/expected/flags-help.txt +++ b/test/expected/flags-help.txt @@ -13,8 +13,6 @@ Options: --cwd Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. [string] - --verify Will verify plugins referenced in project's - package.json against the plugins blacklist. -T, --tasks Print the task dependency tree for the loaded gulpfile. [boolean] --tasks-simple Print a plaintext list of tasks for the loaded diff --git a/test/flags-verify.js b/test/flags-verify.js deleted file mode 100644 index b3b6f53c..00000000 --- a/test/flags-verify.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var exec = require('child_process').exec; -var path = require('path'); - -var eraseTime = require('./tool/erase-time'); -var gulp = require('./tool/gulp-cmd'); - -var baseDir = path.join(__dirname, '..'); - -describe('flag: --verify', function() { - - it('dependencies with invalid dependency', function(done) { - var opts = { cwd: baseDir }; - exec(gulp( - '--verify invalid-package.json', - '--cwd ./test/fixtures/verify/' - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/invalid-package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' - ); - done(); - } - }); - - it('dependencies with valid dependency', function(done) { - var opts = { cwd: baseDir }; - exec(gulp( - '--verify valid-package.json', - '--cwd ./test/fixtures/verify/' - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/valid-package.json') + '\n' + - 'There are no blacklisted plugins in this project\n' + - '' - ); - done(err); - } - }); - - it('default args with invalid dependency', function(done) { - var opts = { cwd: baseDir }; - exec(gulp( - '--verify', - '--cwd', path.resolve('./test/fixtures/verify/') - ), opts, cb); - - function cb(err, stdout, stderr) { - expect(err).not.toBeNull(); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' - ); - done(); - } - }); - -}); diff --git a/test/lib/get-remote-json.js b/test/lib/get-remote-json.js deleted file mode 100644 index f610f84a..00000000 --- a/test/lib/get-remote-json.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var getRemoteJson = require('../../lib/shared/blacklist/get-remote-json'); - -describe('lib: blacklist/get-remote-json', function() { - - it('should get normal json', function(done) { - var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; - getRemoteJson(url, function(err, json) { - expect(err).toBeNull(); - expect(json['gulp-blink']).toEqual('deprecated. use `blink` instead.'); - done(); - }); - }); - - it('should get error when 404', function(done) { - var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/xxx.json'; - getRemoteJson(url, function(err, json) { - expect(err.message).toEqual('Request failed. Status Code: 404'); - expect(json).toBeFalsy(); - done(); - }); - }); - - it('should get error when not json', function(done) { - var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/README.md'; - getRemoteJson(url, function(err, json) { - expect(err.message).toEqual('Invalid Blacklist JSON.'); - expect(json).toBeFalsy(); - done(); - }); - }); -});