Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

refactor: simplify source code && update webpack-defaults v1.1.0...1.5.0 #63

Merged
merged 3 commits into from
Jul 9, 2017

Conversation

mattlewis92
Copy link
Member

It looks like travis / appveyor aren't enabled on this repo yet so the tests won't run, @d3viant0ne would you mind enabling these when you have a sec please?

I think this should be enough for an RC release. Any feedback is welcome!

p.s. I removed all the sourcemap stuff from the codebase as it looks like the loader API in webpack 2+ changed so you can't get the source map from the previous loader and webpack will auto merge sourcemaps for you. Previously sourcemaps were always generated by default due to a bug in the source so I've left that on by default to preserve backwards compatibility (99% of the time users are going to want to produce sourcemaps, otherwise it will be impossible to debug their code)

@joshwiens joshwiens changed the title Update webpack defaults, add tests, simplify source code refactor: Update webpack defaults, add tests, simplify source code Jul 9, 2017
@hulkish
Copy link

hulkish commented Jul 9, 2017

@mattlewis92 Can you also include compilation warnings/errors in your snapshot tests? example: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/master/test/all-options.test.js#L70

@mattlewis92
Copy link
Member Author

@hulkish done!

src/index.js Outdated
srcMap = inlineSourceMap.sourcemap;
}
export default function (source) {
const userOptions = loaderUtils.getOptions(this) || {};
Copy link
Member

Choose a reason for hiding this comment

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

userOptions => options

test/helpers.js Outdated
import MemoryFileSystem from 'memory-fs';
import webpack from 'webpack';

const istanbulInstrumenterLoader = require.resolve('../src/cjs.js');
Copy link
Member

Choose a reason for hiding this comment

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

- const istanbulInstrumenterLoader
+ const loader

test/helpers.js Outdated
path: path.join(__dirname, 'fixtures', 'dist'),
},
module: {
rules: [{
Copy link
Member

Choose a reason for hiding this comment

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

[
  {
    test: /\.js$/
-   loader: istanbulInstrumenterLoader,
+   loader,
-   options: instrumenterOptions,
+   options,
    enforce: 'post'
  }
]

test/helpers.js Outdated
@@ -0,0 +1,40 @@
import path from 'path';
Copy link
Member

Choose a reason for hiding this comment

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

Rename to (webpack|compiler|run).js

test/helpers.js Outdated
});
}

export function stripLocalPaths(source) {
Copy link
Member

Choose a reason for hiding this comment

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

Move to test/helpers.js (Separate file to compiler)

test/helpers.js Outdated
}

export function stripLocalPaths(source) {
const regexpReplace = new RegExp(__dirname, 'g');
Copy link
Member

Choose a reason for hiding this comment

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

regexReplace => replacer || replacee || regex

test/helpers.js Outdated
}, extra);
}

export function runWebpack(config) {
Copy link
Member

Choose a reason for hiding this comment

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

Make this the default export without a name, see below why :)

@@ -0,0 +1,34 @@
import { runWebpack, webpackConfigFactory, stripLocalPaths } from './helpers';
Copy link
Member

@michael-ciniawsky michael-ciniawsky Jul 9, 2017

Choose a reason for hiding this comment

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

import webpack from './webpack'; // Constistent across the webpack-contrib (`webpack-defaults`)
import { stripLocalPaths } from './helpers'; // Custom helpers per repo

test/helpers.js Outdated

const istanbulInstrumenterLoader = require.resolve('../src/cjs.js');

export function webpackConfigFactory({ instrumenterOptions, extra, fixtureEntry = 'basic.js' } = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

Move into runWebpack

test/helpers.js Outdated
}, extra);
}

export function runWebpack(config) {
Copy link
Member

Choose a reason for hiding this comment

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

export default function (fixture, options, extend = {}) {
  const config = Object.assign({
    ...webpackConfigFactory
   }, extend)
   ...runWebpack
}

@michael-ciniawsky
Copy link
Member

Please also split chore, test, refactor tasks into micro PRs accordingly whenever possible, I ensure you it will get reviewed :)

@michael-ciniawsky michael-ciniawsky added this to the 3.0.1 milestone Jul 9, 2017
@michael-ciniawsky michael-ciniawsky self-assigned this Jul 9, 2017
@mattlewis92
Copy link
Member Author

@michael-ciniawsky it was kind of tricky to do that, since each subsequent commit depended on changes from the previous commit. It's probably best to just squash and merge these changes into one commit anyway 😄

@michael-ciniawsky michael-ciniawsky changed the title refactor: Update webpack defaults, add tests, simplify source code refactor: simplify source code && update webpack-defaults v1.1.0...1.5.0 Jul 9, 2017
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jul 9, 2017

Mind to open a PR in webpack-defaults with your initial test setup test/(compiler|run|webpack).js to start working on #68 (webpack-defaults) ? 🙃

package.json Outdated
@@ -48,7 +48,6 @@
"eslint-config-webpack": "^1.2.5",
"eslint-plugin-import": "^2.7.0",
"jest": "^20.0.4",
"jest-cli": "^20.0.4",
"lint-staged": "^3.6.1",
"memory-fs": "^0.4.1",
"nodemon": "^1.11.0",
Copy link
Member

@michael-ciniawsky michael-ciniawsky Jul 9, 2017

Choose a reason for hiding this comment

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

Not needed anymore since ~webpack-defaults v1.3.0+

@mattlewis92
Copy link
Member Author

Had a minor heart attack for one sec as I messed up the rebase then force pushed the changes and lost all my work... thankfully webstorm has a file restore feature 😅

@michael-ciniawsky I've addressed your review changes and squashed the commits into 2 - one for upgrading webpack-defaults and the other for making the produceSourceMap on by default to maintain BC with 2.x + added tests to verify the behaviour. LMK if you'd like me to change anything else 😄

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

👍

package.json Outdated
"jest": "^20.0.4",
"lint-staged": "^3.4.0",
"lint-staged": "^3.6.1",
"memory-fs": "^0.4.1",
"nodemon": "^1.11.0",
Copy link
Member

Choose a reason for hiding this comment

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

- nodemon

@michael-ciniawsky
Copy link
Member

Drop the nodemon dependency please and g2g :)

@mattlewis92
Copy link
Member Author

Done! 💃

@mattlewis92
Copy link
Member Author

Awesome thanks @michael-ciniawsky ! Would it be possible for either @d3viant0ne or @bebraw to cut a new beta with this change please? Thanks! 😄

btw there was actually a fix in with this PR, previously produceSourceMap was off and now it's on by default. It's probably worth adding this to the changelog for the release when its generated (although the previous release was broken so I doubt anyone would have had issues with it)

@joshwiens
Copy link
Member

joshwiens commented Jul 9, 2017

@mattlewis92 - Not sure why Travis & Appveyor weren't enabled but that test suite fails locally.

The lib works, so i'll push a new beta & we can deal with the snapshots later.

joshwiens pushed a commit that referenced this pull request Jul 10, 2017
 - `produceSourceMap` is now on by default & must be explicitly
disabled if so desired
@joshwiens
Copy link
Member

Done - 3.0.0-beta.1

@mattlewis92
Copy link
Member Author

Ah it's because the webpack build hashes are different, they're non-deterministic by default and not based off the file contents. I will just strip them from the snapshots the same way I do for the file paths, will send a PR later 😀

@michael-ciniawsky michael-ciniawsky removed this from the 3.0.2 milestone Oct 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants