Browse Source

Fixing linting to run for all packages

v6-dev
Eli Perelman 8 years ago
parent
commit
6968fcbdde
  1. 2
      package.json
  2. 10
      packages/neutrino-preset-jest/src/index.js
  3. 4
      packages/neutrino-preset-mocha/src/index.js
  4. 4
      packages/neutrino-preset-mocha/src/mocha.js
  5. 52
      packages/neutrino/src/neutrino.js

2
package.json

@ -8,7 +8,7 @@
"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues", "bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues",
"repository": "mozilla-neutrino/neutrino-dev", "repository": "mozilla-neutrino/neutrino-dev",
"scripts": { "scripts": {
"lint": "eslint packages/**/*.js", "lint": "eslint packages/*/*.js packages/*/src/**/*.js",
"bootstrap": "oao bootstrap", "bootstrap": "oao bootstrap",
"changelog": "changelog mozilla-neutrino/neutrino-dev all --markdown > CHANGELOG.md", "changelog": "changelog mozilla-neutrino/neutrino-dev all --markdown > CHANGELOG.md",
"deps:add": "oao add", "deps:add": "oao add",

10
packages/neutrino-preset-jest/src/index.js

@ -12,7 +12,7 @@ function normalizeJestOptions(jestOptions, config, args) {
Object Object
.keys(aliases) .keys(aliases)
.map(key => options.moduleNameMapper[key] = join('<rootDir>', aliases[key])); .map(key => Object.assign(options.moduleNameMapper, { [key]: join('<rootDir>', aliases[key]) }));
options.moduleFileExtensions = [...new Set([ options.moduleFileExtensions = [...new Set([
...options.moduleFileExtensions, ...options.moduleFileExtensions,
@ -33,12 +33,12 @@ function normalizeJestOptions(jestOptions, config, args) {
return options; return options;
} }
module.exports = neutrino => { module.exports = (neutrino) => {
neutrino.on('test', args => { neutrino.on('test', (args) => {
const jestOptions = merge({ const jestOptions = merge({
bail: true, bail: true,
transform: { transform: {
"\\.(js|jsx)$": require.resolve('./transformer') '\\.(js|jsx)$': require.resolve('./transformer')
}, },
roots: [neutrino.options.tests], roots: [neutrino.options.tests],
testRegex: '(_test|_spec|\\.test|\\.spec)\\.jsx?$', testRegex: '(_test|_spec|\\.test|\\.spec)\\.jsx?$',
@ -75,7 +75,7 @@ module.exports = neutrino => {
const dir = options.rootDir || neutrino.options.root; const dir = options.rootDir || neutrino.options.root;
writeFileSync(configFile, `${JSON.stringify(options, null, 2)}\n`); writeFileSync(configFile, `${JSON.stringify(options, null, 2)}\n`);
runCLI(cliOptions, dir, result => result.numFailedTests || result.numFailedTestSuites ? reject() : resolve()); runCLI(cliOptions, dir, result => (result.numFailedTests || result.numFailedTestSuites ? reject() : resolve()));
}); });
}); });
}; };

4
packages/neutrino-preset-mocha/src/index.js

@ -2,7 +2,7 @@ const mocha = require('./mocha');
const merge = require('deepmerge'); const merge = require('deepmerge');
const loaderMerge = require('neutrino-middleware-loader-merge'); const loaderMerge = require('neutrino-middleware-loader-merge');
module.exports = neutrino => { module.exports = (neutrino) => {
neutrino.on('test', ({ files }) => { neutrino.on('test', ({ files }) => {
neutrino.use(loaderMerge('compile', 'babel'), { neutrino.use(loaderMerge('compile', 'babel'), {
env: { env: {
@ -16,6 +16,6 @@ module.exports = neutrino => {
merge({ reporter: 'spec', ui: 'tdd', bail: true }, neutrino.options.mocha || {}), merge({ reporter: 'spec', ui: 'tdd', bail: true }, neutrino.options.mocha || {}),
neutrino.config.module.rule('compile').use('babel').get('options'), neutrino.config.module.rule('compile').use('babel').get('options'),
files files
) );
}); });
}; };

4
packages/neutrino-preset-mocha/src/mocha.js

@ -3,13 +3,13 @@ const toParam = require('change-case').paramCase;
let proc; let proc;
module.exports = (mochaOpts = {}, babelOpts = {}, files = []) => new Promise(resolve => { module.exports = (mochaOpts = {}, babelOpts = {}, files = []) => new Promise((resolve) => {
if (proc) { if (proc) {
proc.kill(); proc.kill();
} }
if (files.length) { if (files.length) {
mochaOpts.recursive = true; Object.assign(mochaOpts, { recursive: true });
} }
process.env.NEUTRINO_BABEL_CONFIG = JSON.stringify(babelOpts); process.env.NEUTRINO_BABEL_CONFIG = JSON.stringify(babelOpts);

52
packages/neutrino/src/neutrino.js

@ -6,7 +6,7 @@ const Config = require('webpack-chain');
const ora = require('ora'); const ora = require('ora');
const merge = require('deepmerge'); const merge = require('deepmerge');
const normalizePath = (path, root) => isAbsolute(path) ? path : join(root, path); const normalizePath = (path, root) => (isAbsolute(path) ? path : join(root, path));
class Neutrino extends EventEmitter { class Neutrino extends EventEmitter {
constructor(options = {}) { constructor(options = {}) {
@ -16,7 +16,7 @@ class Neutrino extends EventEmitter {
const source = normalizePath(options.source || 'src', root); const source = normalizePath(options.source || 'src', root);
const output = normalizePath(options.output || 'build', root); const output = normalizePath(options.output || 'build', root);
const tests = normalizePath(options.tests || 'test', root); const tests = normalizePath(options.tests || 'test', root);
const node_modules = normalizePath(options.node_modules || 'node_modules', root); const node_modules = normalizePath(options.node_modules || 'node_modules', root); // eslint-disable-line camelcase
const entry = normalizePath(options.entry || 'index.js', source); const entry = normalizePath(options.entry || 'index.js', source);
this.config = new Config(); this.config = new Config();
@ -27,6 +27,7 @@ class Neutrino extends EventEmitter {
preset(this, options); preset(this, options);
} }
/* eslint-disable no-console */
handleErrors(err, stats) { handleErrors(err, stats) {
if (err) { if (err) {
console.error(err.stack || err); console.error(err.stack || err);
@ -47,6 +48,7 @@ class Neutrino extends EventEmitter {
return false; return false;
} }
/* eslint-enable no-console */
getWebpackOptions() { getWebpackOptions() {
return this.config.toConfig(); return this.config.toConfig();
@ -85,7 +87,7 @@ class Neutrino extends EventEmitter {
} }
devServer() { devServer() {
return new Promise(resolve => { return new Promise((resolve) => {
const starting = ora('Starting development server').start(); const starting = ora('Starting development server').start();
const config = this.getWebpackOptions(); const config = this.getWebpackOptions();
const protocol = config.devServer.https ? 'https' : 'http'; const protocol = config.devServer.https ? 'https' : 'http';
@ -111,7 +113,7 @@ class Neutrino extends EventEmitter {
} }
watcher() { watcher() {
return new Promise(resolve => { return new Promise((resolve) => {
const building = ora('Waiting for initial build to finish').start(); const building = ora('Waiting for initial build to finish').start();
const config = this.getWebpackOptions(); const config = this.getWebpackOptions();
const compiler = webpack(config); const compiler = webpack(config);
@ -125,26 +127,28 @@ class Neutrino extends EventEmitter {
} }
builder() { builder() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const config = this.getWebpackOptions(); const config = this.getWebpackOptions();
const compiler = webpack(config); const compiler = webpack(config);
compiler.run((err, stats) => { // eslint-disable-next-line consistent-return
const failed = this.handleErrors(err, stats); compiler.run((err, stats) => {
const failed = this.handleErrors(err, stats);
if (failed) {
return reject(); if (failed) {
} return reject();
}
console.log(stats.toString({
colors: true, // eslint-disable-next-line no-console
chunks: false, console.log(stats.toString({
children: false colors: true,
})); chunks: false,
children: false
resolve(); }));
});
}); resolve();
});
});
} }
} }

Loading…
Cancel
Save