Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Morph Neutrino API and CLI into middleware injectors for external CLI tools #852

Merged
merged 7 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { Neutrino } = require('./packages/neutrino');
const neutrino = require('./packages/neutrino');

module.exports = Neutrino({ root: __dirname })
.use('.neutrinorc.js')
.call('eslintrc');
module.exports = neutrino(require('./.neutrinorc')).eslintrc();
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"scripts": {
"changelog": "auto-changelog --remote upstream --commit-limit false",
"link:all": "lerna exec yarn link",
"lint": "node packages/neutrino/bin/neutrino lint",
"lint": "eslint packages .neutrinorc.js",
"precommit": "lint-staged",
"release": "lerna publish --force-publish=*",
"release:preview": "lerna publish --force-publish=* --skip-git --skip-npm",
Expand All @@ -29,7 +29,7 @@
"validate:eslintrc:airbnb-base": "eslint --no-eslintrc --print-config . -c ./packages/airbnb-base/eslintrc.js > /dev/null",
"validate:eslintrc:standardjs": "eslint --no-eslintrc --print-config . -c ./packages/standardjs/eslintrc.js > /dev/null",
"validate:eslintrc": "yarn validate:eslintrc:eslint && yarn validate:eslintrc:airbnb-base && yarn validate:eslintrc:airbnb && yarn validate:eslintrc:standardjs && yarn validate:eslintrc:root",
"version": "test -v SKIP_CHANGELOG || yarn changelog --package && git add CHANGELOG.md"
"version": "[[ -z \"$SKIP_CHANGELOG\" ]] || yarn changelog --package && git add CHANGELOG.md"
},
"devDependencies": {
"auto-changelog": "^1.4.6",
Expand All @@ -38,12 +38,19 @@
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"husky": "^0.14.3",
"jest": "^22.4.3",
"karma": "^2.0.2",
"karma-cli": "^1.0.1",
"lerna": "^2.11.0",
"lint-staged": "^7.0.5",
"mocha": "^5.2.0",
"nyc": "^11.7.1",
"prettier": "^1.12.1",
"stylelint": "^8.4.0",
"verdaccio": "3.0.0-beta.10",
"verdaccio-memory": "^1.0.1"
"verdaccio-memory": "^1.0.1",
"webpack": "^4.8.3",
"webpack-dev-server": "^3.1.4"
},
"lint-staged": {
"*.js": [
Expand Down
6 changes: 2 additions & 4 deletions packages/airbnb-base/eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { Neutrino } = require('../neutrino');
const neutrino = require('../neutrino');

module.exports = Neutrino({ cwd: __dirname })
.use(require('.')) // eslint-disable-line global-require
.call('eslintrc');
module.exports = neutrino(require('.')).eslintrc();
5 changes: 3 additions & 2 deletions packages/airbnb-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
},
"dependencies": {
"@neutrinojs/eslint": "^8.2.0",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.11.0"
},
"peerDependencies": {
"neutrino": "^8.0.0"
"eslint": "^4.0.0",
"neutrino": "^8.0.0",
"webpack": "^4.0.0"
}
}
33 changes: 23 additions & 10 deletions packages/airbnb-base/test/airbnb_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'ava';
import { Neutrino } from 'neutrino';
import Neutrino from '../../neutrino/Neutrino';
import neutrino from '../../neutrino';

const mw = () => require('..');
const options = { eslint: { rules: { semi: false } } };
Expand All @@ -9,37 +10,49 @@ test('loads preset', t => {
});

test('uses preset', t => {
t.notThrows(() => Neutrino().use(mw()));
t.notThrows(() => new Neutrino().use(mw()));
});

test('uses with options', t => {
t.notThrows(() => Neutrino().use(mw(), options));
t.notThrows(() => new Neutrino().use(mw(), options));
});

test('instantiates', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw());

t.notThrows(() => api.config.toConfig());
});

test('instantiates with options', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw(), options);

t.notThrows(() => api.config.toConfig());
});

test('exposes lint command', t => {
const api = Neutrino();
test('exposes eslintrc output handler', t => {
const api = new Neutrino();

api.use(mw());

t.is(typeof api.commands.lint, 'function');
const handler = api.outputHandlers.get('eslintrc');

t.is(typeof handler, 'function');
});

test('exposes eslintrc config from output', t => {
const config = neutrino(mw()).output('eslintrc');

t.is(typeof config, 'object');
});

test('exposes eslintrc method', t => {
t.is(typeof neutrino(mw()).eslintrc, 'function');
});

test('exposes eslintrc config', t => {
t.is(typeof Neutrino().use(mw()).call('eslintrc'), 'object');
test('exposes eslintrc config from method', t => {
t.is(typeof neutrino(mw()).eslintrc(), 'object');
});
6 changes: 2 additions & 4 deletions packages/airbnb/eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { Neutrino } = require('../neutrino');
const neutrino = require('../neutrino');

module.exports = Neutrino({ cwd: __dirname })
.use(require('.')) // eslint-disable-line global-require
.call('eslintrc');
module.exports = neutrino(require('.')).eslintrc();
5 changes: 3 additions & 2 deletions packages/airbnb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
},
"dependencies": {
"@neutrinojs/eslint": "^8.2.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0"
},
"peerDependencies": {
"neutrino": "^8.0.0"
"eslint": "^4.0.0",
"neutrino": "^8.0.0",
"webpack": "^4.0.0"
}
}
33 changes: 23 additions & 10 deletions packages/airbnb/test/airbnb_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'ava';
import { Neutrino } from 'neutrino';
import Neutrino from '../../neutrino/Neutrino';
import neutrino from '../../neutrino';

const mw = () => require('..');
const options = { eslint: { rules: { semi: false } } };
Expand All @@ -9,37 +10,49 @@ test('loads preset', t => {
});

test('uses preset', t => {
t.notThrows(() => Neutrino().use(mw()));
t.notThrows(() => new Neutrino().use(mw()));
});

test('uses with options', t => {
t.notThrows(() => Neutrino().use(mw(), options));
t.notThrows(() => new Neutrino().use(mw(), options));
});

test('instantiates', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw());

t.notThrows(() => api.config.toConfig());
});

test('instantiates with options', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw(), options);

t.notThrows(() => api.config.toConfig());
});

test('exposes lint command', t => {
const api = Neutrino();
test('exposes eslintrc output handler', t => {
const api = new Neutrino();

api.use(mw());

t.is(typeof api.commands.lint, 'function');
const handler = api.outputHandlers.get('eslintrc');

t.is(typeof handler, 'function');
});

test('exposes eslintrc config from output', t => {
const config = neutrino(mw()).output('eslintrc');

t.is(typeof config, 'object');
});

test('exposes eslintrc method', t => {
t.is(typeof neutrino(mw()).eslintrc, 'function');
});

test('exposes eslintrc config', t => {
t.is(typeof Neutrino().use(mw()).call('eslintrc'), 'object');
test('exposes eslintrc config from method', t => {
t.is(typeof neutrino(mw()).eslintrc(), 'object');
});
6 changes: 2 additions & 4 deletions packages/banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
"npm": ">=5.4.0",
"yarn": ">=1.2.1"
},
"dependencies": {
"webpack": "^4.7.0"
},
"peerDependencies": {
"neutrino": "^8.0.0"
"neutrino": "^8.0.0",
"webpack": "^4.0.0"
}
}
10 changes: 5 additions & 5 deletions packages/banner/test/middleware_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { Neutrino } from 'neutrino';
import Neutrino from '../../neutrino/Neutrino';

const mw = () => require('..');
const options = { raw: false, entryOnly: false };
Expand All @@ -9,23 +9,23 @@ test('loads middleware', t => {
});

test('uses middleware', t => {
t.notThrows(() => Neutrino().use(mw()));
t.notThrows(() => new Neutrino().use(mw()));
});

test('uses with options', t => {
t.notThrows(() => Neutrino().use(mw(), options));
t.notThrows(() => new Neutrino().use(mw(), options));
});

test('instantiates', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw());

t.notThrows(() => api.config.toConfig());
});

test('instantiates with options', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw(), options);

Expand Down
3 changes: 2 additions & 1 deletion packages/clean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"clean-webpack-plugin": "^0.1.19"
},
"peerDependencies": {
"neutrino": "^8.0.0"
"neutrino": "^8.0.0",
"webpack": "^4.0.0"
}
}
10 changes: 5 additions & 5 deletions packages/clean/test/middleware_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { Neutrino } from 'neutrino';
import Neutrino from '../../neutrino/Neutrino';

const mw = () => require('..');
const options = { paths: ['sample'], root: __dirname };
Expand All @@ -9,23 +9,23 @@ test('loads middleware', t => {
});

test('uses middleware', t => {
t.notThrows(() => Neutrino().use(mw()));
t.notThrows(() => new Neutrino().use(mw()));
});

test('uses with options', t => {
t.notThrows(() => Neutrino().use(mw(), options));
t.notThrows(() => new Neutrino().use(mw(), options));
});

test('instantiates', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw());

t.notThrows(() => api.config.toConfig());
});

test('instantiates with options', t => {
const api = Neutrino();
const api = new Neutrino();

api.use(mw(), options);

Expand Down
25 changes: 17 additions & 8 deletions packages/compile-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
const babelMerge = require('babel-merge');

module.exports = (neutrino, options = {}) => neutrino.config.module
.rule(options.ruleId || 'compile')
module.exports = (neutrino, options = {}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate PR? :-)

neutrino.config.module
.rule(options.ruleId || 'compile')
.test(options.test || neutrino.regexFromExtensions())
.when(options.include, rule => rule.include.merge(options.include))
.when(options.exclude, rule => rule.exclude.merge(options.exclude))
.use(options.useId || 'babel')
.loader(require.resolve('babel-loader'))
.options({
cacheDirectory: true,
babelrc: false,
...(options.babel || {})
});
.loader(require.resolve('babel-loader'))
.options({
cacheDirectory: true,
babelrc: false,
...(options.babel || {})
});

neutrino.register('babel', (neutrino, override) => override(
neutrino.config.module
.rule('compile')
.use('babel')
.get('options')
Copy link
Member

@edmorley edmorley May 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to filter out cacheDirectory etc here in the future, but happy to wait until we decide whether to move wholesale to babelrc only we figure out how jest or similar are going to use .babelrc.js.

));
};

module.exports.merge = babelMerge;
6 changes: 3 additions & 3 deletions packages/compile-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"dependencies": {
"@babel/core": "^7.0.0-beta.46",
"babel-loader": "^8.0.0-beta.2",
"babel-merge": "^1.1.1",
"webpack": "^4.7.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this to peerDependencies rather than removing it?
eg @neutrinojs/clean kept is as a peer dep even though index.js doesn't refer to it.

Perhaps it might just be easier to add the webpack peer dep to every single Neutrino package to save having to think about it? (And to make it 200% clear to people using Neutrino what version of webpack we support.) All presets have to be used with Neutrino, which already has a peer dep on webpack, so won't really affect whether people see warnings or not. (Though the jest preset doesn't technically require it I suppose..)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people have voiced their want to use Neutrino middleware to test or lint things without actually building, so I would want to only provide it where necessary, if possible.

I think the reason clean keeps it is because the webpack plugin also peerDeps on webpack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case babel-loader has a peer dep on webpack, so if we're going to explicitly mirror the deps peer deps, we should add it to compile-loader too.

"babel-merge": "^1.1.1"
},
"peerDependencies": {
"neutrino": "^8.0.0"
"neutrino": "^8.0.0",
"webpack": "^4.0.0"
}
}
Loading