Skip to content

Commit

Permalink
Drop node < 4 support, don't transpile code
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
shvaikalesh authored and mgol committed Aug 25, 2016
1 parent e939d9b commit 1bd86ea
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 192 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/**
dist/**
test/*/**/*.js
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@

"env": {
"node": true
},

"rules": {
"prefer-reflect": 0,
"prefer-rest-params": 0,
"prefer-spread": 0
}
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/node_modules/
/dist/
*.log
/test/*/*-copy
/test/*-fixtures/generated/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
sudo: false
node_js:
- '0.12'
- '4'
- '6'
env:
Expand Down
89 changes: 3 additions & 86 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,22 @@
'use strict';

// Disable options that don't work in Node.js 0.12.
// Gruntfile.js & tasks/*.js are the only non-transpiled files.
/* eslint-disable no-var, object-shorthand, prefer-arrow-callback, prefer-const,
prefer-spread, prefer-reflect, prefer-rest-params, prefer-template */

var assert = require('assert');

var newNode;
try {
assert.strictEqual(eval('(r => [...r])([2])[0]'), 2); // eslint-disable-line no-eval
newNode = true;
} catch (e) {
newNode = false;
}

var tooOldNodeForTheTask = /^v0\./.test(process.version);

// Support: Node.js <4
// Skip running tasks that dropped support for Node.js 0.10 & 0.12
// in those Node versions.
var runIfNewNode = function (task) {
return tooOldNodeForTheTask ? 'print_old_node_message:' + task : task;
};

module.exports = function (grunt) {
require('time-grunt')(grunt);

grunt.initConfig({
clean: {
all: {
src: [
'dist',
'*.log',
'test/*/*-copy',
'test/*-fixtures/generated',
],
},
},

copy: {
all: {
files: [
{
expand: true,
dot: true,
src: [
'test/**/*',
'!test/**/*.js',
],
dest: 'dist',
},
],
},
},

babel: {
options: {
sourceMap: true,
retainLines: true,
},
all: {
files: [
{
expand: true,
src: [
'bin/**/*.js',
'lib/**/*.js',
'test/**/*.js',
],
dest: 'dist',
},
],
},
},

eslint: {
all: {
src: [
'*.js',
'bin',
'lib',
'test',
Expand All @@ -91,41 +29,20 @@ module.exports = function (grunt) {
options: {
reporter: 'spec',
},
src: [newNode ? 'test/spec.js' : 'dist/test/spec.js'],
src: 'test/spec.js',
},
},
});

// Load grunt tasks from NPM packages
// Support: Node.js <4
// Don't load the eslint task in old Node.js, it won't parse.
require('load-grunt-tasks')(grunt, {
pattern: tooOldNodeForTheTask ? ['grunt-*', '!grunt-eslint'] : ['grunt-*'],
});

// Supports: Node.js <4
grunt.registerTask('print_old_node_message', function () {
var task = [].slice.call(arguments).join(':');
grunt.log.writeln('Old Node.js detected, running the task "' + task + '" skipped...');
});

grunt.registerTask('lint', [
runIfNewNode('eslint'),
]);

// In modern Node.js we just use the non-transpiled source as it makes it easier to debug;
// in older version we transpile (but keep the lines).
grunt.registerTask('build', [
'copy',
'babel',
]);
require('load-grunt-tasks')(grunt);

grunt.registerTask('lint', ['eslint']);
grunt.registerTask('test', ['mochaTest']);

grunt.registerTask('default', [
'clean',
'lint',
'build',
'test',
]);
};
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ init:
# Test against these versions of Node.js.
environment:
matrix:
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "6"

# Install scripts. (runs after repo cloning)
Expand Down Expand Up @@ -37,7 +37,7 @@ build: off
matrix:
# fast_finish: true
allow_failures:
- nodejs_version: "6"
- nodejs_version: "4"

# Set up cache, clear it on package.json changes.
# NOTE: Cache disabled for now.
Expand Down
21 changes: 0 additions & 21 deletions bin.js

This file was deleted.

6 changes: 3 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
'use strict';

const minimist = require('minimist');
const _ = require('lodash');
const camelCase = require('lodash.camelcase');
const checkDependencies = require('../lib/check-dependencies');

const argv = minimist(process.argv.slice(2));

// camelCase the options
for (const key in argv) {
for (const key of Object.keys(argv)) {
const value = argv[key];
delete argv[key];
argv[_.camelCase(key)] = value;
argv[camelCase(key)] = value;
}

// Options of type array should always have array values
Expand Down
19 changes: 0 additions & 19 deletions index.js

This file was deleted.

50 changes: 19 additions & 31 deletions lib/check-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
'use strict';

/* eslint-disable no-undef */

const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const findup = require('findup-sync');
const _ = require('lodash');
const semver = require('semver');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;

/* eslint-enable no-undef */

const checkDependenciesHelper = (syncOrAsync, config, callback) => {
// We treat the signature:
// checkDependencies(callback)
Expand All @@ -31,12 +26,12 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {
if (callback == null) {
// In the async mode we return the promise anyway; assign callback
// to noop to keep code consistency.
callback = _.noop;
callback = () => {/* noop */};
} else {
// If callback was simply not provided, we assume the user wanted
// to handle the returned promise. If it was passed but not a function
// we assume user error and throw.
throw new Error('The provided callback wasn\'t a function! Got:', callback);
throw new TypeError(`The provided callback wasn't a function! Got: ${ callback }`);
}
}
}
Expand All @@ -51,7 +46,7 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {
let installNeeded = false;
let pruneNeeded = false;

const options = _.defaults({}, config, {
const options = Object.assign({
packageManager: 'npm',
onlySpecified: false,
install: false,
Expand All @@ -62,7 +57,7 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {
checkCustomPackageNames: false,
log: console.log.bind(console),
error: console.error.bind(console),
});
}, config);

const packageJsonName = options.packageManager === 'npm' ? 'package.json' : 'bower.json';
const packageJsonRegex = options.packageManager === 'npm' ? /package\.json$/ : /bower\.json$/;
Expand All @@ -86,7 +81,7 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {
output.status = success ? 0 : 1;
if (syncOrAsync === 'async') {
callback(output);
return new Promise(resolve => resolve(output));
return Promise.resolve(output);
}
return output;
};
Expand Down Expand Up @@ -127,17 +122,20 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {
const getDepsMappingsFromScopeList = scopeList =>
// Get names of all packages specified in package.json/bower.json at keys from scopeList
// together with specified version numbers.
scopeList.reduce((result, scope) => _.merge(result, packageJson[scope] || {}), {});
scopeList.reduce((result, scope) => Object.assign(result, packageJson[scope]), {});

// Make sure each package from `scopeList` is present and matches the specified version range.
// Packages from `optionalScopeList` may not be present but if they are, they are required
// to match the specified version range.
const checkPackage = ({name, versionString, isOptional}) => {
const checkPackage = pkg => {
const name = pkg.name;
let versionString = pkg.versionString;

const depDir = `${ depsDir }/${ name }`;
const depJson = `${ depDir }/${ depsJsonName }`;

if (!fs.existsSync(depDir) || !fs.existsSync(depJson)) {
if (isOptional) {
if (pkg.isOptional) {
log(`${ name }: ${ chalk.red('not installed!') }`);
} else {
error(`${ name }: ${ chalk.red('not installed!') }`);
Expand Down Expand Up @@ -194,14 +192,14 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {

const depsMappings = getDepsMappingsFromScopeList(options.scopeList);
const optionalDepsMappings = getDepsMappingsFromScopeList(options.optionalScopeList);
const fullDepsMappings = _.assign({}, depsMappings, optionalDepsMappings);
const fullDepsMappings = Object.assign({}, depsMappings, optionalDepsMappings);

_.forEach(depsMappings, (versionString, name) => {
checkPackage({name, versionString, isOptional: false});
Object.keys(depsMappings).forEach(name => {
checkPackage({name, versionString: depsMappings[name], isOptional: false});
});

_.forEach(optionalDepsMappings, (versionString, name) => {
checkPackage({name, versionString, isOptional: true});
Object.keys(optionalDepsMappings).forEach(name => {
checkPackage({name, versionString: optionalDepsMappings[name], isOptional: true});
});

installNeeded = !success;
Expand Down Expand Up @@ -271,7 +269,7 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {

if (win32) {
spawnReturn = method(pkgManagerPath ? 'node' : 'cmd',
(pkgManagerPath ? [pkgManagerPath] : ['/c', options.packageManager]).concat([mode]),
(pkgManagerPath ? [pkgManagerPath] : ['/c', options.packageManager]).concat(mode),
{
cwd: options.packageDir,
stdio: 'inherit',
Expand Down Expand Up @@ -347,15 +345,5 @@ const checkDependenciesHelper = (syncOrAsync, config, callback) => {
});
};

module.exports = (...args) => checkDependenciesHelper('async', ...args);

module.exports.sync = (...args) => {
if (!spawnSync) {
throw new Error([
'Your version of Node.js doesn\'t support child_process.spawnSync.',
'Update Node.js or use require(\'checkDependencies\') instead of',
'require(\'checkDependencies\').sync.',
].join(' '));
}
return checkDependenciesHelper('sync', ...args);
};
module.exports = (cfg, cb) => checkDependenciesHelper('async', cfg, cb);
module.exports.sync = (cfg, cb) => checkDependenciesHelper('sync', cfg, cb);
Loading

0 comments on commit 1bd86ea

Please sign in to comment.