Skip to content

Commit

Permalink
Scaffold: Switch to eslint-config-gulp rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Feb 24, 2019
1 parent 7853fd3 commit c0fc65f
Show file tree
Hide file tree
Showing 34 changed files with 291 additions and 310 deletions.
24 changes: 6 additions & 18 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-empty": ["error", { "allowEmptyCatch": true }],
"comma-dangle": ["error", "only-multiline"]
}
"extends": "gulp",
"rules": {
"max-len": [0, 90],
"max-statements": [1, 50],
"no-empty": ["error", { "allowEmptyCatch": true }]
}
}
79 changes: 40 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
const fs = require('fs');
const util = require('util');
const path = require('path');
const EE = require('events').EventEmitter;

const extend = require('extend');
const resolve = require('resolve');
const flaggedRespawn = require('flagged-respawn');
const isPlainObject = require('is-plain-object');
const mapValues = require('object.map');
const fined = require('fined');

const findCwd = require('./lib/find_cwd');
const findConfig = require('./lib/find_config');
const fileSearch = require('./lib/file_search');
const parseOptions = require('./lib/parse_options');
const silentRequire = require('./lib/silent_require');
const buildConfigName = require('./lib/build_config_name');
const registerLoader = require('./lib/register_loader');
const getNodeFlags = require('./lib/get_node_flags');


function Liftoff (opts) {
var fs = require('fs');
var util = require('util');
var path = require('path');
var EE = require('events').EventEmitter;

var extend = require('extend');
var resolve = require('resolve');
var flaggedRespawn = require('flagged-respawn');
var isPlainObject = require('is-plain-object');
var mapValues = require('object.map');
var fined = require('fined');

var findCwd = require('./lib/find_cwd');
var findConfig = require('./lib/find_config');
var fileSearch = require('./lib/file_search');
var parseOptions = require('./lib/parse_options');
var silentRequire = require('./lib/silent_require');
var buildConfigName = require('./lib/build_config_name');
var registerLoader = require('./lib/register_loader');
var getNodeFlags = require('./lib/get_node_flags');


function Liftoff(opts) {
EE.call(this);
extend(this, parseOptions(opts));
}
util.inherits(Liftoff, EE);

Liftoff.prototype.requireLocal = function (module, basedir) {
Liftoff.prototype.requireLocal = function(module, basedir) {
try {
var result = require(resolve.sync(module, {basedir: basedir}));
var result = require(resolve.sync(module, { basedir: basedir }));
this.emit('require', module, result);
return result;
} catch (e) {
this.emit('requireFail', module, e);
}
};

Liftoff.prototype.buildEnvironment = function (opts) {
Liftoff.prototype.buildEnvironment = function(opts) {
opts = opts || {};

// get modules we want to preload
Expand Down Expand Up @@ -64,14 +64,14 @@ Liftoff.prototype.buildEnvironment = function (opts) {
// calculate the regex to use for finding the config file
var configNameSearch = buildConfigName({
configName: this.configName,
extensions: Object.keys(this.extensions)
extensions: Object.keys(this.extensions),
});

// calculate configPath
var configPath = findConfig({
configNameSearch: configNameSearch,
searchPaths: searchPaths,
configPath: opts.configPath
configPath: opts.configPath,
});

// if we have a config path, save the directory it resides in.
Expand All @@ -90,11 +90,12 @@ Liftoff.prototype.buildEnvironment = function (opts) {

// TODO: break this out into lib/
// locate local module and package next to config or explicitly provided cwd
/* eslint one-var: 0 */
var modulePath, modulePackage;
try {
var delim = path.delimiter,
paths = (process.env.NODE_PATH ? process.env.NODE_PATH.split(delim) : []);
modulePath = resolve.sync(this.moduleName, {basedir: configBase || cwd, paths: paths});
var delim = path.delimiter;
var paths = (process.env.NODE_PATH ? process.env.NODE_PATH.split(delim) : []);
modulePath = resolve.sync(this.moduleName, { basedir: configBase || cwd, paths: paths });
modulePackage = silentRequire(fileSearch('package.json', [modulePath]));
} catch (e) {}

Expand All @@ -118,9 +119,9 @@ Liftoff.prototype.buildEnvironment = function (opts) {
// load any modules which were requested to be required
if (preload.length) {
// unique results first
preload.filter(function (value, index, self) {
preload.filter(function(value, index, self) {
return self.indexOf(value) === index;
}).forEach(function (dep) {
}).forEach(function(dep) {
this.requireLocal(dep, findCwd(opts));
}, this);
}
Expand Down Expand Up @@ -152,27 +153,27 @@ Liftoff.prototype.buildEnvironment = function (opts) {
configBase: configBase,
modulePath: modulePath,
modulePackage: modulePackage || {},
configFiles: configFiles
configFiles: configFiles,
};
};

Liftoff.prototype.handleFlags = function (cb) {
Liftoff.prototype.handleFlags = function(cb) {
if (typeof this.v8flags === 'function') {
this.v8flags(function (err, flags) {
this.v8flags(function(err, flags) {
if (err) {
cb(err);
} else {
cb(null, flags);
}
});
} else {
process.nextTick(function () {
process.nextTick(function() {
cb(null, this.v8flags);
}.bind(this));
}
};

Liftoff.prototype.launch = function (opts, fn) {
Liftoff.prototype.launch = function(opts, fn) {
if (typeof fn !== 'function') {
throw new Error('You must provide a callback function.');
}
Expand All @@ -183,7 +184,7 @@ Liftoff.prototype.launch = function (opts, fn) {
return this.completions(completion);
}

this.handleFlags(function (err, flags) {
this.handleFlags(function(err, flags) {
if (err) {
throw err;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/build_config_name.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (opts) {
module.exports = function(opts) {
opts = opts || {};
var configName = opts.configName;
var extensions = opts.extensions;
Expand All @@ -11,7 +11,7 @@ module.exports = function (opts) {
if (!Array.isArray(extensions)) {
throw new Error('Please provide an array of valid extensions.');
}
return extensions.map(function (ext) {
return extensions.map(function(ext) {
return configName + ext;
});
};
6 changes: 3 additions & 3 deletions lib/file_search.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const findup = require('findup-sync');
var findup = require('findup-sync');

module.exports = function (search, paths) {
module.exports = function(search, paths) {
var path;
var len = paths.length;
for (var i = 0; i < len; i++) {
if (path) {
break;
} else {
path = findup(search, {cwd: paths[i], nocase: true});
path = findup(search, { cwd: paths[i], nocase: true });
}
}
return path;
Expand Down
8 changes: 4 additions & 4 deletions lib/find_config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs');
const path = require('path');
const fileSearch = require('./file_search');
var fs = require('fs');
var path = require('path');
var fileSearch = require('./file_search');

module.exports = function (opts) {
module.exports = function(opts) {
opts = opts || {};
var configNameSearch = opts.configNameSearch;
var configPath = opts.configPath;
Expand Down
4 changes: 2 additions & 2 deletions lib/find_cwd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
var path = require('path');

module.exports = function (opts) {
module.exports = function(opts) {
if (!opts) {
opts = {};
}
Expand Down
8 changes: 4 additions & 4 deletions lib/parse_options.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const extend = require('extend');
var extend = require('extend');

module.exports = function (opts) {
module.exports = function(opts) {
var defaults = {
extensions: {
'.js': null,
'.json': null
'.json': null,
},
searchPaths: []
searchPaths: [],
};
if (!opts) {
opts = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/register_loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rechoir = require('rechoir');
var rechoir = require('rechoir');

module.exports = function(eventEmitter, extensions, configPath, cwd) {
extensions = extensions || {};
Expand Down
2 changes: 1 addition & 1 deletion lib/silent_require.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (path) {
module.exports = function(path) {
try {
return require(path);
} catch (e) {}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"chai": "^3.5.0",
"coffeescript": "^1.10.0",
"eslint": "^2.13.1",
"eslint-config-gulp": "^3.0.1",
"mocha": "^3.5.3",
"nyc": "^13.3.0",
"sinon": "~1.17.4"
Expand Down
3 changes: 3 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "gulp/test"
}
2 changes: 1 addition & 1 deletion test/fixtures/configfiles/require-md.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {

const path = require('path');
var path = require('path');

require.extensions['.md'] = function(module, filepath) {
module.loaded = true;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/configfiles/require-txt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {

const path = require('path');
var path = require('path');

require.extensions['.txt'] = function(module, filepath) {
module.loaded = true;
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/developing_yourself/app1/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Liftoff = require('../../../..');
var Liftoff = require('../../../..');

const app1 = new Liftoff({
var app1 = new Liftoff({
name: 'app1'
});

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/developing_yourself/app2/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Liftoff = require('../../../..');
var Liftoff = require('../../../..');

const app2 = new Liftoff({
var app2 = new Liftoff({
name: 'app2'
});

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/developing_yourself/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Liftoff = require('../../..');
var Liftoff = require('../../..');

const app0 = new Liftoff({
var app0 = new Liftoff({
name: 'app0'
});

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/nodeflags_only.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Liftoff = require('../..');
var Liftoff = require('../..');

const Test = new Liftoff({
var Test = new Liftoff({
name: 'test',
});

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/register_loader/require-cfg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {

const path = require('path');
var path = require('path');

require.extensions['.cfg'] = function(module, filepath) {
module.loaded = true;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/register_loader/require-conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {

const path = require('path');
var path = require('path');

require.extensions['.conf'] = function(module, filepath) {
module.loaded = true;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/register_loader/require-rc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {

const path = require('path');
var path = require('path');

require.extensions['.rc'] = function(module, filepath) {
module.loaded = true;
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/v8flags.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Liftoff = require('../..');
var Liftoff = require('../..');

const Test = new Liftoff({
var Test = new Liftoff({
name: 'test',
v8flags: ['--lazy']
});
Test.on('respawn', function (flags, proc) {
Test.on('respawn', function(flags, proc) {
console.log('saw respawn');
});

Test.launch({}, function (env) {
Test.launch({}, function(env) {
console.error(process.execArgv.join(''));
});
4 changes: 2 additions & 2 deletions test/fixtures/v8flags_config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Liftoff = require('../..');
var Liftoff = require('../..');

const Test = new Liftoff({
var Test = new Liftoff({
name: 'test',
v8flags: ['--harmony'],
});
Expand Down
Loading

0 comments on commit c0fc65f

Please sign in to comment.