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

Baseline for Neutrino v5 #86

Merged
merged 23 commits into from
Mar 8, 2017
Merged

Baseline for Neutrino v5 #86

merged 23 commits into from
Mar 8, 2017

Conversation

eliperelman
Copy link
Member

@eliperelman eliperelman commented Mar 1, 2017

Summary

BREAKING CHANGES

  • webpack-chain upgraded to v3, which has a lot more shorthand methods, but also breaks how configs are extended for plugins and rule-loaders. Now the extension handler is either passed the args or options directly, removing a level of nesting:
config.plugin('env').use(EnvironmentPlugin, ['NODE_ENV']);
config.plugin('env').tap(args => [...args, 'SECRET_KEY']);

// ...

config.rule('compile')
  .use('babel')
    .loader('babel-loader')
    .options({ presets: ['es2015'] });

config.rule('compile')
  .use('babel')
    .tap(options => merge(options, { plugins: ['object-rest-spread'] }));

webpack-chain also has moved rule includes and excludes to ChainedMaps:

config.rule('compile')
  .include
    .add(...).add(...).end()
  .exclude
    .add(...).add(...).end()
  • package.json presets configuration now under top-level neutrino object.
{
  "neutrino": {
    "presets": []
  }
}
  • package.json custom options now under top-level neutrino object. No more neutrino.custom.
{
  "neutrino": {
    "options": {
      "jest": { "bail": true },
      "mocha": { "reporter": "nyan" }
    }
  }
}
neutrino.options.jest.bail // true
neutrino.options.mocha.reporter // "nyan"
  • package.json webpack-chain overrides now under top-level neutrino object.
{
  "neutrino": {
    "config": {
      "devServer": { "port": 3000 }
    }
  }
}
  • Web preset rule for CSS has been renamed from css to style, i.e. config.module.rule('style').
  • Jest upgraded to v19, which changes option from testPathDirs to roots. Jest options through package.json are now done via neutrino.options.jest solely.
  • No more lint base, now neutrino-middleware-eslint.
  • When using eslint middleware, RC method moved from neutrino.custom.eslintrc() to neutrino.eslintrc().
  • API no longer accepts presets in constructor. Constructor now takes an options object to store at .options.
  • API no longer does preset module resolution. This has been moved to the CLI. API users must now pass a preset as a function to api.use() or call it with the API and options, i.e. preset(neutrino, options).
  • getWebpackOptions() no longer caches calls.
  • Using a node target no longer skips the watcher for a builder, it now uses the Webpack watcher, i.e. neutrino start && node build is obsolete. neutrino build && node build would work to start a Node instance for production-built bundles.

Features

  • Added options for setting or overriding a number of paths Neutrino uses, from package.json, middleware, or the API. These paths can be provided absolutely or relative to neutrino.options.root, or for entry, relative to neutrino.options.source:
neutrino.options.root, // defaults to process.cwd()
neutrino.options.source, // defaults to process.cwd()/src
neutrino.options.output, // defaults to process.cwd()/build
neutrino.options.tests, // defaults to process.cwd()/test
neutrino.options.entry, // defaults to process.cwd()/src/index.js
neutrino.options.node_modules // defaults to process.cwd()/node_modules
  • Added --inspect flag to output a string representation of the Webpack configuration object. Can be used to diff configuration changes:
neutrino build --inspect --presets alpha > alpha.config
neutrino build --inspect --presets alpha beta > beta.config

git diff alpha.config beta.config
  • HMR for Node.js!
  • Dynamic imports for Web AND Node.js!
const { default: Home } = await import('./home');
  • Testing via AVA, just add tests to packages/*/test
  • Running tests in Travis

Bugs

  • various

@eliperelman eliperelman added this to the v5 milestone Mar 1, 2017
@eliperelman eliperelman closed this Mar 3, 2017
@eliperelman eliperelman reopened this Mar 3, 2017
@eliperelman eliperelman closed this Mar 3, 2017
@eliperelman eliperelman reopened this Mar 3, 2017
@eliperelman
Copy link
Member Author

eliperelman commented Mar 4, 2017

Updated description with current list of breaking changes. Will update with features and bugs soonish.

@eliperelman eliperelman requested a review from helfi92 March 4, 2017 00:28
@eliperelman eliperelman self-assigned this Mar 4, 2017
@eliperelman
Copy link
Member Author

@helfi92 feel free to start reviewing this whenever. I will add docs in a different PR.

cc: @tj @TheLarkInn @ev1stensberg for any comments or opinions they may have. :)

@@ -0,0 +1,5 @@
const { EnvironmentPlugin } = require('webpack');

module.exports = ({ config }, envs = []) => config
Copy link

@tj tj Mar 4, 2017

Choose a reason for hiding this comment

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

Is the second argument automatically scoped to the middleware from the "options" in package.json? Or the whole object? Or neither hahah

EDIT: nvm I see, presets are slightly different than middleware accessing neutrino.options instead of passing that object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Although it would be cool to map a name to preset/middleware options automatically, but that would probably require passing a name along with the preset/middleware. Which is possible.

Copy link

Choose a reason for hiding this comment

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

Might be cool to unify middleware/presets in some way like that, not a big deal though

@tj
Copy link

tj commented Mar 4, 2017

awesome LGTM at a quick glance! Thanks a ton for working on this, amazing how much work it removes

"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues",
"dependencies": {
"progress-bar-webpack-plugin": "^1.9.3",
"webpack": "^2.2.1"

Choose a reason for hiding this comment

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

Does this middleware need webpack as a dep??

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, that's a mistake lol.

"description": "Neutrino preset for testing Neutrino projects with Karma",
"main": "src/index.js",
"main": "index.js",
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you took index.js outside src?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to flatten the directory structure for packages that don't need the extra complexity.


try {
pkg = require(join(cwd, 'package.json'));
} catch (ex) {}
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 throw an exception message?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we try to load data from package.json if it exists, but it's not going to affect anything if we can't find it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, makes sense.

@evenstensberg
Copy link

@eliperelman Want to exhange emails instead? I need some insight on the entire thing from multiple sources, so I can elaborate better :)

@eliperelman
Copy link
Member Author

@ev1stensberg sure, eli@mozilla.com.

@eliperelman
Copy link
Member Author

eliperelman commented Mar 7, 2017

If there are no major objections, I plan on merging this later today.

@eliperelman
Copy link
Member Author

I made some changes to webpack-chain, now v3, which makes interacting with some APIs different, but more extensible.

The Neutrino API now also defines defaults for options which mostly eliminate the need for presets to do their own path lookups:

neutrino.options : {
  root, // defaults to process.cwd()
  source, // defaults to process.cwd()/src
  output, // defaults to process.cwd()/build
  tests, // defaults to process.cwd()/test
  entry, // defaults to process.cwd()/src/index.js
  node_modules // defaults to process.cwd()/node_modules
};

All the presets now use these at neutrino.options! 🎉

This also means that you can easily override how a single option affects a number of configuration changes:

{
  "neutrino": {
    "options": {
      "source": "lib",
      "entry": "entry.js"
    }
  }
}
const api = new Neutrino({ source: 'lib', entry: 'entry.js' });
module.exports = neutrino => {
  neutrino.options.source = 'lib';
  neutrino.options.entry = 'entry.js';
}

For example, the Web preset needs the source directory (not to mention other directories) for:

  • Babel compilation directory
  • Dev server content base
  • Copying plugin

w00t!

@eliperelman
Copy link
Member Author

eliperelman commented Mar 8, 2017

Just to contrast, let's say you wanted to change the web/react presets to use lib instead of src for your source directory (v4):

module.exports = ({ config }) => {
  const oldSrc = path.join(__dirname, 'src');
  const newSrc = path.join(__dirname, 'lib');
  const oldEntry = path.join(oldSrc, 'index.js');
  const newEntry = path.join(newSrc, 'index.js');
  
  config
    .entry('index')
    .delete(oldEntry)
    .add(newEntry);

  config.module
    .rule('compile')
      ._include.delete(oldSrc);

  config.module.rule('compile').add(newSrc)
  config.devServer.contentBase(newSrc);

  if (process.env.NODE_ENV !== 'development') {
    config
      .plugin('copy')
      .inject((Plugin, args) => {
        args[0].context = newSrc;
        return new Plugin(...args);
      });
  }
};

eww.

Now v5:

{
  "neutrino": {
    "options": {
      "source": "lib"
    }
  }
}

Or from override file:

neutrino.options.source = 'lib';

Ahh.

const merge = require('deepmerge');

module.exports = ({ config }, options) => {
const { paths, root } = merge({ paths: [], root: process.cwd() }, options);
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to switch this to neutrino.options.root.

@eliperelman
Copy link
Member Author

eliperelman commented Mar 8, 2017

SOON

image

.travis.yml Outdated
yarn: true
directories:
- node_modules
- packages/neutrino-middleware-chunk/node_modules
Copy link
Member

Choose a reason for hiding this comment

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

Should this list also include these entries?

  • packages/neutrino-middleware-banner/node_modules
  • packages/neutrino/node_modules

Copy link
Member Author

Choose a reason for hiding this comment

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

Doh, yes.

.travis.yml Outdated
- packages/neutrino-preset-react/node_modules
- packages/neutrino-preset-web/node_modules
before_script:
- yarn
Copy link
Member

@edmorley edmorley Mar 8, 2017

Choose a reason for hiding this comment

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

Travis by default runs yarn install as part of the install step (if not overridden), so this additional yarn invocation is a duplicate, eg:
https://travis-ci.org/mozilla-neutrino/neutrino-dev/jobs/209062877#L274

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! This is an artifact left over from when I switched from install to before_script in 573c821. I'll update. 👍

@eliperelman
Copy link
Member Author

I will add README.md's to the middleware packages after this and #98 have been merged.

@eliperelman eliperelman merged commit f88b557 into neutrinojs:master Mar 8, 2017
@eliperelman
Copy link
Member Author

🎉

@eliperelman
Copy link
Member Author

:shipit:

@edmorley
Copy link
Member

edmorley commented Mar 9, 2017

Aside from #58, is there much else to do before v5 is published? I'm just trying to work out whether we should switch to v5 now for the Treeherder Neutrino PR, or wait until later.

@eliperelman
Copy link
Member Author

eliperelman commented Mar 9, 2017

@edmorley right now nothing more is planning regarding functionality, and late last night I published beta packages of everything to npm, e.g. neutrino@beta, neutrino-preset-web@beta, which all point to the v5 changes. If you want, feel free to try it and let me know if there are any issues.

eliperelman pushed a commit that referenced this pull request Sep 25, 2017
* Docs: Sync the READMEs in docs/ and packages/

Since the content had drifted out of sync.

* Docs: Use consistent case for Hot Module Replacement

* Docs: Sync the react and web preset feature lists

* Docs: Correct the loader name for the 'html' rule

Since the loader name was changed from `file` to `html` in #219.

* Docs: Correct the rule name for neutrino-middleware-style-loader

Since it was changed from `css` to `style` in #86.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants