-
Notifications
You must be signed in to change notification settings - Fork 213
Morph Neutrino API and CLI into middleware injectors for external CLI tools #852
Conversation
Ah, one thing I forgot to mention is that you can override configuration still using neutrinorc with the webpack-chain instance. This means you can now override using whichever method you prefer: // Use neutrinorc for deterministic configurability with
// the chainable API
module.exports = {
use: [
'@neutrinojs/react',
neutrino => {
neutrino.config.devtool('source-map');
}
]
}; // Override from the configuration file of your CLI tool.
// This requires that you switch away from using the internal
// Neutrino CLI loader to making the tool use its own config file
// again, e.g.
// from:
// neutrino webpack --mode production
// to:
// webpack --mode production
// webpack.config.js
const neutrino = require('neutrino');
module.exports = neutrino().webpack(config => ({
...config,
devtool: 'source-map'
}); |
Hope to review this week, but I'm a big fan of moving in this direction! |
Absolutely love this. |
Many thanks for working on this - as you know I'm keen to try and make it easier to use native tools with Neutrino / reduce the cost of maintenance on our side / possibly reduce the overhead of Neutrino in startup time :-) I tested this by comparing
On master I get:
Trying with this PR I got:
I presume this is due to needing I instead created a const neutrino = require('neutrino');
module.exports = neutrino().webpack(); And then tried using webpack directly:
It looks like the configuration differs slightly:
...however the build time reduced by 1.5s, which is promising (though might just be the different build options?). Some other things I spotted:
|
Could this part be avoided by instead defining the I know passing a Also, what are your thoughts on starting to use |
Ah the former is because The latter is because the Jest preset's Babel settings are being applied even for |
Yes, that is certainly possible. If we are fine with a little loss in ergonomics here, we can move forward with it.
This should be totally possible now, just need to add a
Good catch, yay bugs!
🤔 Hmm yeah, let me think about this one. |
With my current changeset, the only way to affect configuration is via const neutrino = require('neutrino');
module.exports = neutrino().webpack(); I think we should discuss if this needs to be a requirement, or if we should provide the scripts to pass to these external bins. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this locally with a webpack-cli build using --mode production
, which worked great. It initially only tooks 15s on a warm rebuild which I tracked down to my .neutrinorc.js
having a NODE_ENV === 'production'
conditional for setting devtool source-map
.
I think we still need to set process.env.NODE_ENV according to mode and/or whether command={jest,...} etc. I also can't decide whether our conditionals throughout should be from mode, command or NODE_ENV.
I think we might still need some inspect functionality (eg looking for argv.inspect
), but perhaps our options will be clearer once that feature is upstreamed to webpack-chain.
I ran out of time to test further (need to head out for a show) - but will take another look tomorrow at dev server/eslint/....
Oh and sorry for so many "separate PR" comments -- I wouldn't bother so much but it's already +2400, -5700 hehe.
package.json
Outdated
"prettier": "^1.12.1" | ||
"prettier": "^1.12.1", | ||
"stylelint": "^8.4.0", | ||
"webpack": "^4.7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
latest webpack is 4.8.2
(not that it matters much given tilde..)
packages/banner/index.js
Outdated
@@ -4,7 +4,7 @@ module.exports = (neutrino, options = {}) => { | |||
neutrino.config | |||
.plugin(options.pluginId || 'banner') | |||
.use(BannerPlugin, [{ | |||
banner: 'require(\'source-map-support\').install();', | |||
banner: `require('source-map-support').install();`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split this change to a separate PR?
packages/clean/index.js
Outdated
delete options.pluginId; | ||
|
||
Reflect.deleteProperty(options, 'paths'); | ||
Reflect.deleteProperty(options, 'pluginId'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate PR? :-)
@@ -1,7 +1,8 @@ | |||
const babelMerge = require('babel-merge'); | |||
|
|||
module.exports = (neutrino, options = {}) => neutrino.config.module | |||
.rule(options.ruleId || 'compile') | |||
module.exports = (neutrino, options = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate PR? :-)
packages/env/index.js
Outdated
module.exports = ({ config }, envs = []) => config | ||
.plugin('env') | ||
.use(EnvironmentPlugin, envs); | ||
module.exports = ({ config }, envs = []) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate PR? :-)
packages/style-minify/index.js
Outdated
@@ -10,4 +10,4 @@ module.exports = ({ config }, opts = {}) => { | |||
config | |||
.plugin(options.pluginId) | |||
.use(OptimizeCssPlugin, [options.plugin]); | |||
} | |||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate PR? :-)
@@ -252,13 +248,4 @@ module.exports = (neutrino, opts = {}) => { | |||
|
|||
config.output.filename('[name].[chunkhash].js'); | |||
}); | |||
|
|||
neutrino.on('prerun', () => { | |||
if (neutrino.config.entryPoints.has('vendor')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if we could add this check somewhere else - since it's a likely footgun for people upgrading that results in larger/slower builds (vs the other cases where it's just about cleaning up removed preferences).
.eslintignore
Outdated
@@ -1,4 +1,6 @@ | |||
packages/**/node_modules/ | |||
# Remove ignore of neutrinorc since ESLint ignores dotfiles by default | |||
!.neutrinorc.js | |||
# TODO: Fix lint errors in our tests and remove this line | |||
packages/**/test/ | |||
# The templates have any lint errors fixed during project creation, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
packages/airbnb-base/package.json
Outdated
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.11.0" | ||
}, | ||
"peerDependencies": { | ||
"eslint": "^4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @neutrinojs/eslint
package will already have a peerDependency
on eslint, which will be inherited. Though might be clearer for users inspecting only the top-level package.json to be explicit? I can't decide. (The same also applies to eg the webpack
peerDep in @neutrinojs/font-loader
since file-loader has it's own peerDep etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I added this since I figured it would be easier to ensure users would be notified from their top-level peer dependencies, but I am fine with removing some of them if they are bloating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think given we're now needing users to add a bunch of peerDeps perhaps we need to have it as clear as possible to them :-)
destination && | ||
destination.eslint && | ||
destination.eslint.rules | ||
) || {}; | ||
const rules = deepmerge(sourceRules, destinationRules, { | ||
arrayMerge(source, destination) { | ||
return destination; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't select the line, since it's further down below - but there's a leftover neutrino.options.command !== 'start'
.
I wonder if command
could be renamed to something else so third-party middleware / end-users' .neutrinorc.js
conditionals fail hard rather than silently not matching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think target
was suggested at one point, e.g. neutrino.options.target
, but I'm not convinced it wouldn't be confused with config.target
.
Oh and the debug functionality (for me, main use I have had for it is preset-env's debug output). |
I wonder if we should also make |
@eliperelman testing my With the new setup, would I have something like this in my
What would the api be then for a preset to return a list of webpack configurations? |
packages/jest/src/index.js
Outdated
neutrino.config.when( | ||
neutrino.config.module.rules.has('compile') && | ||
neutrino.options.command === 'jest', | ||
() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the false case isn't used, and we're not using a passed (config)
, this might be cleaner as:
if (
neutrino.config.module.rules.has("compile") &&
neutrino.options.command === "jest"
) {
// ...
}
packages/mocha/package.json
Outdated
@@ -2,7 +2,7 @@ | |||
"name": "@neutrinojs/mocha", | |||
"version": "8.2.0", | |||
"description": "Neutrino preset for testing Neutrino projects with Mocha", | |||
"main": "src/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the jest preset case, could the file be left under src/
for now, so that git knows it's existing content and displays the actual diff? (Happy for the file to be moved either in a PR before this lands, or sometime after)
packages/neutrino/karma.js
Outdated
.command('karma') | ||
.init(); | ||
|
||
if (neutrino.config.module.rules.has('compile')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like these really belong in the preset rather than in the Neutrino package. Could we instead maybe do something like either:
- make these files be mostly a shell that
require()
s the relevant parts from the preset - have the presets dynamically register new commands, so we don't need to hardcode each test runner in the neutrino package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I hadn't thought of it this way before, and it would take re-working the adapter pattern, but let me see what I can do.
@ringods I think the idea would be that you could export multiple Neutrino calls: EDITED // webpack.config.js
const neutrino = require('neutrino');
module.exports = [
neutrino().output('webpack'),
neutrino(middleware).output('webpack')
]; |
To add to the commit message: Fixes #708. We should also check whether it fixes any of: |
Updated description to reflect removal of adapter pattern, and now using: neutrino().output(name, override);
neutrino().output('webpack');
neutrino().output('webpack', config => {
return config;
}); |
|
||
const err = t.throws(() => api.use(require('..'), { minify: { image: true } })); | ||
t.true(err.message.includes('The minify.image option has been removed')); | ||
}); | ||
|
||
test('throws when vendor entrypoint defined', async t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you re-add this test? (though it will need adjusting)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this test to inside neutrino
since this wasn't web
's concern.
packages/web/index.js
Outdated
@@ -92,7 +93,6 @@ module.exports = (neutrino, opts = {}) => { | |||
], | |||
presets: [ | |||
[require.resolve('@babel/preset-env'), { | |||
debug: neutrino.options.debug, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you re-add this?
@@ -31,7 +31,6 @@ | |||
"@neutrinojs/loader-merge": "^8.2.0", | |||
"@neutrinojs/web": "^8.2.0", | |||
"deepmerge": "^1.5.2", | |||
"eslint": "^4.19.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess now if people don't add eslint to their package.json
they will get peer dependency warnings from eslint-plugin-react
(and similar for the vue/preact presets etc). However maybe that's ok and their choice to save the dependency?
The only option I can think of (other than leaving this dependency in here), is to stop the react preset from including the eslint react plugin, and then airbnb guide users can just use the airbnb preset (which does include the plugin), and for standardjs perhaps we'd have to add a second "standardjs-react" preset? (Maybe not worth it...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah, hadn't thought of this one. I think the easiest thing at the moment would be to leave it until we think of something better, if possible.
@@ -0,0 +1,51 @@ | |||
import test from 'ava'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome for the extra tests!
|
||
t.notDeepEqual(api.config.toConfig(), {}); | ||
}); | ||
|
||
test('throws when trying to call() a non-registered command', t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should turn this into a test checking for the Unable to find an output handler named
behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to the new package_test
.
packages/neutrino/package.json
Outdated
@@ -2,16 +2,11 @@ | |||
"name": "neutrino", | |||
"version": "8.2.0", | |||
"description": "Create and build JS applications with managed configurations", | |||
"main": "src/index.js", | |||
"bin": { | |||
"neutrino": "./bin/neutrino.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should leave a bin script that outputs something like "The neutrino command has been removed. See migration guide"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me.
packages/karma/package.json
Outdated
"karma-coverage": "^1.1.2", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-webpack": "^3.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some of these are still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved them to peer deps, although I'm not entirely happy about that.
}); | ||
|
||
test('exposes eslintrc config', t => { | ||
t.is(typeof Neutrino().use(mw()).call('eslintrc'), 'object'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we convert this and the other "expose XYZ" to checking that ...output('...')
works?
package.json
Outdated
@@ -34,17 +33,21 @@ | |||
}, | |||
"devDependencies": { | |||
"auto-changelog": "^1.4.6", | |||
"ava": "^0.25.0", | |||
"ava": "1.0.0-beta.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sneaking in more changes again hehe.. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase artifact. I'll fix. 😄
@@ -22,5 +23,6 @@ const name = basename(directory); | |||
env.run('create-project', { | |||
directory, | |||
name, | |||
registry: cli.registry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change so that the global yarn registry setting doesn't need to be adjusted? (And so can be removed from the script.) If so, this would be good since means running these tests don't affect global state locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, yes. You can either pass --registry
during create-project
, or you can specify the registry in the test generator (see the project()
function in test/cli_test
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like this is unrelated to the other changes here, and so belongs in a separate PR?
I'll open one for some of these cleanup things now.
OK, I think have the latest round of review comments addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posting this so you don't have to wait for me to finish up the rest of the testing etc first.
It occurred to me for could always replace the .output('name')
API with .webpack()
et al, by making use of ES6 Proxy traps to catch unknown commands and handle them gracefully? (Which I presume is the reason why the switch to .output()
?). Either way works for me though, so happy to go with your choice :-)
@@ -25,8 +25,7 @@ | |||
"dependencies": { | |||
"@babel/core": "^7.0.0-beta.46", | |||
"babel-loader": "^8.0.0-beta.2", | |||
"babel-merge": "^1.1.1", | |||
"webpack": "^4.7.0" |
There was a problem hiding this comment.
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..)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -22,5 +23,6 @@ const name = basename(directory); | |||
env.run('create-project', { | |||
directory, | |||
name, | |||
registry: cli.registry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like this is unrelated to the other changes here, and so belongs in a separate PR?
I'll open one for some of these cleanup things now.
… tools Remove all CLIs, remove create project, expose command name from each config method Fix test references to API Simplify adapter pattern for overriding tool options More webpack peerDeps changes Remove irrelevant changes from patch Reset jest source files location, upgrade to latest webpack Fail lint if mode is production Add support for options.debug and options.inspect Throw if vendor entrypoint exists Re-work create-project to support external CLIs and test with verdaccio Fix bugs in beta verdaccio setup Remove localhost yarn.lock entries :/ Trying single-instance tests again in CI Removing unused environment variable detection in tests Add back karma and mocha middleware for eslint settings Experiment with using ramdisk for yarn cache Use updated yarn cache directory Update yarn.lock after rebase Remove adapter pattern, move output handlers to middleware, parse --mode from argv Fix output command for create-project mocha Removing rebase artifacts Use babel register from mocha output options Remove reference to old yarn cache script Add tests for exposing commands, add peer deps for karma Revert back to previous ava Use a proxy to expose output handlers as named methods on neutrino package Revert changes to eslintignore and create-project that were out of scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last few things and hopefully this should be good to go! :-)
@@ -25,8 +25,7 @@ | |||
"dependencies": { | |||
"@babel/core": "^7.0.0-beta.46", | |||
"babel-loader": "^8.0.0-beta.2", | |||
"babel-merge": "^1.1.1", | |||
"webpack": "^4.7.0" |
There was a problem hiding this comment.
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.
packages/eslint/package.json
Outdated
}, | ||
"peerDependencies": { | ||
"eslint": "^4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint-loader
has a peer dep on webpack
, so webpack needs adding here, if we're following that pattern. Similarly, should we then add it to @neutrinojs/airbnb
and @neutrinojs/airbnb-base
to, since they depend on @neutrinojs/eslint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess so.
}, | ||
"peerDependencies": { | ||
"jest": "^22.0.0", |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this one feels kinda wrong since the addition of the linting is optional based on existing lint rule. Thoughts on leaving this one out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah sorry we do the same for the react preset etc, so ignore this
packages/jest/package.json
Outdated
@@ -22,18 +22,16 @@ | |||
"yarn": ">=1.2.1" | |||
}, | |||
"dependencies": { | |||
"@babel/core": "^7.0.0-beta.46", | |||
"@babel/core": "^7.0.0-beta.47", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version and the one in the mocha preset is now out of sync with the others in the repo. Could you revert the changes to the @babel/*
deps? (At some point in the future I'm sure we'll hand bump again, but this is in-range and it was only done recently in #848.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, this was from moving the .jest()
command from neutrino
package to jest
.
packages/neutrino/bin/neutrino.js
Outdated
@@ -1,130 +1,9 @@ | |||
#!/usr/bin/env node | |||
#! /usr/bin/env node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray whitespace here (shebangs normally don't have additional whitespace before the interpreter; not all POSIX implementations support it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
"neutrino": "^8.0.0" | ||
"karma": "^2.0.0", | ||
"karma-cli": "^1.0.0", | ||
"mocha": "^5.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm presuming mocha
can't be moved to dependencies
due to something like the karma frameworks
pref not accepting absolute depdency paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was mostly to enable usage of karma and mocha presets in the same repo.
"@neutrinojs/loader-merge": "^8.2.0", | ||
"change-case": "^3.0.2", | ||
"mocha": "^5.1.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this preset, should mocha now be listed in peerDependencies, rather than removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh, yes.
scripts.start = `${packages.NEUTRINO} start`; | ||
scripts.start = this.data.project === '@neutrinojs/node' | ||
? 'webpack --watch --mode development' | ||
: 'webpack-serve --mode development'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running yarn start
on a create-project with options React+Jest+AirBnb, I get:
$ yarn start
yarn run v1.6.0
(node:6040) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
$ webpack-serve --mode development
× 「config」: An error ocurred while trying to find a config file
Did you forget to specify a --require?
C:\Users\Ed\src\test-project\node_modules\@webpack-contrib\config-loader\lib\load.js:84
throw new LoadConfigError(e, configPath);
^
LoadConfigError: Cannot find module 'webpack-dev-server/client'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.require.resolve (C:\Users\Ed\src\test-project\node_modules\webpack-serve\node_modules\v8-compile-cache\v8-compile-cache.js:162:23)
at config.entry.batch.entry (C:\Users\Ed\src\test-project\node_modules\@neutrinojs\web\index.js:235:43)
I guess we have no coverage of this at the moment?
Perhaps in test_cli.js
we can do either (or both) of:
- test webpack build using
--mode development
- see if we can spawn the dev server via
yarn start
, then if it starts successfully, kill it after a few seconds
Until then perhaps we need to hand-test (using create-project and --registry
) all of the top-level preset's yarn start
commands?
Also, I think the reason the unit tests didn't catch this is because the repo root package.json
contains webpack-dev-server
(when I think it perhaps shouldn't?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooooooh, this is a problem. I don't think we can use webpack-serve out-of-the-box because of our hardcoded entries in web for dev server:
https://github.com/mozilla-neutrino/neutrino-dev/blob/master/packages/web/index.js#L235
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should switch back to webpack-dev-server for now (also reduces the amount changed in one PR) and we can figure it out later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You read my mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps in test_cli.js we can do either (or both) of:
- test webpack build using --mode development
- see if we can spawn the dev server via yarn start, then if it starts successfully, kill it after a few seconds
I've filed #886 for this.
|
||
// devServer :: (Object config -> Object api) -> Future () Function | ||
const devServer = (config, { options }) => Future | ||
.of(merge({ devServer: { host: 'localhost', port: 5000, noInfo: !options.debug } }, config)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the noInfo: !options.debug
need to move to packages/dev-server/index.js
now? Or are we leaving it to the user to pass the options to webpack-serve?
The latter seems to make sense, I was just wondering if with the current settings things are going to get verbose. I think after this PR we'll probably want to revisit our customisation of stats
entirely, so perhaps this can wait until then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's follow up with stats changes.
.option('debug', { | ||
description: 'Run in debug mode', | ||
boolean: true, | ||
default: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR neutrino.options.debug
now defaults to undefined
rather than false
, which means clean-webpack-plugin
now gives verbose output (its default) when it didn't before. I think we need to make it default to false
again.
On that note, process.env.NODE_ENV
is also undefined
when it wasn't before. I think we need to set that explicitly again too, per:
#852 (review)
The Netlify build on Could you update |
This adjusts the console output to be less verbose, for parity with how it was prior to the switch to native CLIs in #852. In some cases the output has been made to be even more concise than in Neutrino 8, since it's now possible for users to adjust the output via CLI flags, therefore less important to satisfy all use-cases out of the box. For that reason the `debug` handling has also been removed. The output when using webpack-dev-server now includes the duration, which makes it much easier to compare incremental build times. The `performance.hints(false)` of `@neutrinojs/node` has been removed since it's redundant as of webpack 4.2.0: webpack/webpack@c65fb74 Fixes #897.
) - Improve documentation based in feedback in #1129. - Add checks for the legacy Neutrino `options.host` and `options.port`, since they were removed in #852. Refs: #1129 (comment) #1129 (comment) #814 (comment)
Edited to reflect current state of PR.
Fixes #708.
Fixes #736.
Fixes #870.
Fixes #842.
Closes #773.
Closes #839.
Closes #849.
Outstanding issues to file:
Determine need for config-loading bins instead of forcing config file boilerplate (still unsure if we should do this because of IDE integration)This patch is a work-in-progress, and is quite the overhaul of Neutrino into something different. Right now there is no change to the documentation, which I will change if we decide to move forward with this.
This patch morphs Neutrino into a "preset engine" for transforming managed webpack configuration into a format that can be consumed by other CLI tools. No longer would we wrap external CLI tools like webpack, eslint, jest, karma, mocha, stylelint, etc. Instead, Neutrino could augment these tools by exposing methods for returning usable configuration.
This approach gives the user control of their CLI tool back, and they can programmatically invoke Neutrino to load their configuration, and override however they like:
The same works for ESLint and friends too (except for mocha, since it has no config file we can be required from):
.neutrinorc.js
, which shouldn't change at all.This does do away with a bunch of CLI functionality likeThis is now back in the form of the CLI with--inspect
or--use
, but those become less useful if we are just an interface to external CLI tools. We can discuss potentially bringing those back.neutrino --inspect
.All environment variables are gone. We rely only on webpack'sWe internally only use webpack'smode
value.mode
value, but still setprocess.env.NODE_ENV
if not set based on the mode, or defaulted toproduction
.There is no longer a create-project tool, since we cannot force users to choose between competing tools like webpack-cli or webpack-command, and webpack-dev-server or webpack-serve.The create-project tool is back, and we opt forwebpack-cli
andwebpack-dev-server
as opinions for now.I'm sure there are other major things I am neglecting to mention. Let's discuss! I see so many benefits to this, including reduced maintenance burden and the ability to allow people to use Neutrino without dumping their existing tools.
cc: @mozilla-neutrino/core-contributors