Skip to content

Commit

Permalink
Update dependencies; update code to pass new lints
Browse files Browse the repository at this point in the history
Change eslint-config-airbnb to eslint-config-airbnb-base to reduce
dependencies. Add an override to import/no-extraneous-dependencies
to allow peerDependencies (new in v1.11.0).
  • Loading branch information
Diogo Franco (Kovensky) committed Jul 18, 2016
1 parent 609f094 commit 9b22cc2
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 74 deletions.
11 changes: 7 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"parser": "babel-eslint",
"extends": "airbnb/base",
"env": {
"node": true
}
"extends": "airbnb-base",
"env": {
"node": true
},
"rules": {
"import/no-extraneous-dependencies": ["error", {"peerDependencies": true}]
}
}
Empty file modified bin/mocha-webpack
100644 → 100755
Empty file.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-eslint": "^4.1.8",
"babel-eslint": "^6.1.2",
"babel-plugin-transform-class-properties": "^6.5.2",
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.5.2",
"chai": "^3.5.0",
"del": "^2.2.0",
"del-cli": "^0.2.0",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^5.0.1",
"eslint": "^3.1.0",
"eslint-config-airbnb-base": "^4.0.2",
"eslint-plugin-import": "^1.11.0",
"mocha": "^2.4.5",
"sinon": "^1.17.3",
"webpack": "^1.12.13"
},
"dependencies": {
"anymatch": "^1.3.0",
"fs-extra": "^0.26.5",
"fs-extra": "^0.30.0",
"glob-parent": "^2.0.0",
"invariant": "^2.2.0",
"is-glob": "^2.0.1",
Expand All @@ -62,6 +63,6 @@
"object-hash": "^1.1.2",
"webpack-info-plugin": "^0.1.0",
"webpack-sources": "^0.1.1",
"yargs": "^3.32.0"
"yargs": "^4.8.0"
}
}
4 changes: 2 additions & 2 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const defaultOptions = parseArgv([]);
const options = _.defaults({}, cliOptions, configOptions, defaultOptions);

options.require.forEach((mod) => {
require(resolve(mod));
require(resolve(mod)); // eslint-disable-line global-require
});

options.include = options.include.map(resolve);

if (options.webpackConfig) {
const webpackConfigPath = path.resolve(options.webpackConfig);
options.webpackConfig = require(webpackConfigPath);
options.webpackConfig = require(webpackConfigPath); // eslint-disable-line global-require
} else {
options.webpackConfig = {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/parseArgv.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import yargs from 'yargs';
import _ from 'lodash';
import { version } from '../../package.json';

const BASIC_GROUP = 'Basic options:';
const OUTPUT_GROUP = 'Output options:';
Expand Down Expand Up @@ -179,12 +180,11 @@ const parameters = paramList(options); // camel case parameters
const parametersWithMultipleArgs = paramList(_.pickBy(_.mapValues(options, (v) => !!v.requiresArg && v.multiple === true))); // eslint-disable-line max-len
const groupedAliases = _.values(_.mapValues(options, (value, key) => [_.camelCase(key), key, value.alias].filter(_.identity))); // eslint-disable-line max-len


export default function parseArgv(argv, ignoreDefaults = false) {
const parsedArgs = yargs(argv)
.help('help')
.alias('help', 'h', '?')
.version(() => require('../../package.json').version)
.version(() => version)
.demand(0, 1)
.options(options)
.strict()
Expand Down
6 changes: 5 additions & 1 deletion src/cli/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export function run(options, webpackConfig) {

webpackBuild(webpackConfig, (err) => {
if (err) {
return options.exit ? exit(1) : exitLater(1);
if (options.exit) {
exit(1);
} else {
exitLater(1);
}
}

mocha.files = [outputFilePath];
Expand Down
4 changes: 2 additions & 2 deletions src/mocha/checkReporter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default function checkReporter(reporter) {
try {
require(`mocha/lib/reporters/${reporter}`);
require(`mocha/lib/reporters/${reporter}`); // eslint-disable-line global-require
} catch (errModule) {
try {
require(reporter);
require(reporter); // eslint-disable-line global-require
} catch (errLocal) {
throw new Error(`reporter "${reporter}" does not exist`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mocha/configureMocha.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
import checkReporter from './checkReporter';
import Mocha from 'mocha';
import checkReporter from './checkReporter';

const defaults = {
reporterOptions: {},
Expand Down
58 changes: 29 additions & 29 deletions src/webpack/InjectChangedFilesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,34 @@ export default class InjectChangedFilesPlugin {
});
}

setChangedFiles(compilation, file) {
const original = compilation.assets[file];
const originalSource = original.source();
const originalMap = original.map();

const result = new ReplaceSource(original);
const regex = /__webpackManifest__\s*=\s*\[\s*\]/g;
const files = this.hotFiles.concat(this.failedFiles);
const changedFiles = `['${files.join("', '")}']`;
const replacement = `__webpackManifest__ = ${changedFiles}`;

let match;
while ((match = regex.exec(originalSource)) !== null) { // eslint-disable-line no-cond-assign
const start = match.index;
const end = match.index + match[0].length - 1;
result.replace(start, end, replacement);
}

const resultSource = result.source();
const resultMap = result.map();

compilation.assets[file] = new SourceMapSource( // eslint-disable-line no-param-reassign
resultSource,
file,
resultMap,
originalSource,
originalMap
);
}
setChangedFiles(compilation, file) {
const original = compilation.assets[file];
const originalSource = original.source();
const originalMap = original.map();

const result = new ReplaceSource(original);
const regex = /__webpackManifest__\s*=\s*\[\s*\]/g;
const files = this.hotFiles.concat(this.failedFiles);
const changedFiles = `['${files.join("', '")}']`;
const replacement = `__webpackManifest__ = ${changedFiles}`;

let match;
while ((match = regex.exec(originalSource)) !== null) { // eslint-disable-line no-cond-assign
const start = match.index;
const end = match.index + (match[0].length - 1);
result.replace(start, end, replacement);
}

const resultSource = result.source();
const resultMap = result.map();

compilation.assets[file] = new SourceMapSource( // eslint-disable-line no-param-reassign
resultSource,
file,
resultMap,
originalSource,
originalMap
);
}

}
5 changes: 3 additions & 2 deletions src/webpack/createCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import invariant from 'invariant';
import _ from 'lodash';
import webpack from 'webpack';

export default function createCompiler(webpackConfig, cb) {
invariant(arguments.length === 2, 'parameters are missing');
const missing = () => { invariant(false, 'parameters are missing'); };

export default function createCompiler(webpackConfig, cb = missing()) {
invariant(_.isPlainObject(webpackConfig), 'webpackConfig must be a plain object');
invariant(_.isFunction(cb), 'cb must be a function');

Expand Down
14 changes: 7 additions & 7 deletions test/bin/entry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('cli - entry', function () {
this.testFiles.forEach((file) => createTest(file, true));
});

it(`runs all tests in directory'`, function (done) {
it('runs all tests in directory\'', function (done) {
const matcher = anymatch(`${fixtureDir}/*.js`);
const files = this.testFiles.filter(matcher);

Expand All @@ -200,7 +200,7 @@ describe('cli - entry', function () {
});
});

it(`runs all tests matching file glob'`, function (done) {
it('runs all tests matching file glob\'', function (done) {
const matcher = anymatch(`${fixtureDir}/*-test-3.js`);
const files = this.testFiles.filter(matcher);
exec(`node ${binPath} --glob "*-test-3.js" \"${fixtureDir}\"`, (err, stdout) => {
Expand All @@ -214,7 +214,7 @@ describe('cli - entry', function () {
});


it(`runs all tests in directory & subdirectories'`, function (done) {
it('runs all tests in directory & subdirectories\'', function (done) {
const matcher = anymatch(`${fixtureDir}/**/*.js`);
const files = this.testFiles.filter(matcher);

Expand Down Expand Up @@ -242,7 +242,7 @@ describe('cli - entry', function () {
this.testFiles.forEach((file) => createTest(file, false));
});

it(`runs all tests in directory'`, function (done) {
it('runs all tests in directory\'', function (done) {
const matcher = anymatch(`${fixtureDir}/*.js`);
const files = this.testFiles.filter(matcher);

Expand All @@ -259,7 +259,7 @@ describe('cli - entry', function () {
});
});

it(`runs all tests in directory & subdirectories'`, function (done) {
it('runs all tests in directory & subdirectories\'', function (done) {
const matcher = anymatch(`${fixtureDir}/**/*.js`);
const files = this.testFiles.filter(matcher);

Expand Down Expand Up @@ -290,15 +290,15 @@ describe('cli - entry', function () {
this.testFiles.forEach((file) => createCorruptedTest(file));
});

it(`fails before running tests of directory`, function (done) {
it('fails before running tests of directory', function (done) {
exec(`node ${binPath} \"${fixtureDir}\"`, (err) => {
assert.isNotNull(err);
assert.isAbove(err.code, 0);
done();
});
});

it(`fails before running tests of directory directory & subdirectories'`, function (done) {
it('fails before running tests of directory directory & subdirectories\'', function (done) {
exec(`node ${binPath} --recursive \"${fixtureDir}\"`, (err) => {
assert.isNotNull(err);
assert.isAbove(err.code, 0);
Expand Down
3 changes: 2 additions & 1 deletion test/bin/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import { assert } from 'chai';
import path from 'path';
import { exec } from 'child_process';
import { version } from '../../package.json';

const binPath = path.relative(process.cwd(), path.join('bin', '_mocha'));

describe('cli - version', function () {
before(function () {
this.version = require('../../package.json').version;
this.version = version;
});

it('--version prints the correct version', function (done) {
Expand Down
Loading

0 comments on commit 9b22cc2

Please sign in to comment.