In order to support a better middleware story (for reasons below), I think handling require
ing should be removed from the Neutrino API, and pushed into the CLI. Basically we switch the constructor to do nothing, and introduce something like .use()
for injecting presets. This makes module resolution better for Neutrino, while giving preset authors and extenders a more consistent custom configuration API (i.e. death to .custom
).
Prototyping and experimentation is happening at #86.
EDIT: This has evolved into something a little different than proposed below, see comments for current direction. Keeping this here for posterity.
Presets as code
The Neutrino constructor will no longer take an array of preset names/paths. Instead, a .use()
or similar would accept a preset as code, probably some kind of middleware function:
use(preset) {
preset(this);
}
package.json configuration
I'm thinking that merging of package.json data should also be moved into the CLI. We already have a mechanism for merging data, so the CLI just needs to call this on the configuration after .use
ing all the presets
const api = new Neutrino();
api.use(require('preset-alpha'));
api.use(require('preset-beta'));
api.config.merge(require('package.json').config.neutrino);
Along those lines, we should probably change the schema of config data in package.json so it can be aggregated into a single namespace. Looking at html
and neutrino
and custom
and presets
et al is...meh.
Maybe just a top-level "neutrino" is OK.
{
"neutrino": {
"presets": ["neutrino-preset-react"],
"config": { "publicPath": "./" },
"jest": { "bail": true },
"mocha": { "reporter": "nyan" }
}
}
Middleware configuration
The .custom
configuration object is a hack that needs to go. Making preset authors manually put configuration on this, with no way to automatically merge this back from package.json makes things annoying. This blocks #23, and you can see evidence of this mess in the Jest preset. it would be nice if preset authors could also use the middleware concept to inject preset-specific configuration with automatic merging from additional arbitrary keys from the package.json neutrino
object, e.g. jest
, mocha
. Maybe if .use()
takes a key as well.
use(name, preset) {
const custom = this.middlewareConfig[name];
preset(this, custom);
}
// ...
module.exports = (neutrino, options) => {
const mochaConfig = { ...defaults, ...options };
};
I know this is a lot of changes, so I'm saving this for v5 (obviously since these are breaking changes). I'd appreciate any thoughts on this, recommendations, or better practices.