-
Notifications
You must be signed in to change notification settings - Fork 63
refactor: simplify source code && update webpack-defaults v1.1.0...1.5.0
#63
Conversation
@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 |
@hulkish done! |
src/index.js
Outdated
srcMap = inlineSourceMap.sourcemap; | ||
} | ||
export default function (source) { | ||
const userOptions = loaderUtils.getOptions(this) || {}; |
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.
userOptions
=> options
test/helpers.js
Outdated
import MemoryFileSystem from 'memory-fs'; | ||
import webpack from 'webpack'; | ||
|
||
const istanbulInstrumenterLoader = require.resolve('../src/cjs.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.
- const istanbulInstrumenterLoader
+ const loader
test/helpers.js
Outdated
path: path.join(__dirname, 'fixtures', 'dist'), | ||
}, | ||
module: { | ||
rules: [{ |
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.
[
{
test: /\.js$/
- loader: istanbulInstrumenterLoader,
+ loader,
- options: instrumenterOptions,
+ options,
enforce: 'post'
}
]
test/helpers.js
Outdated
@@ -0,0 +1,40 @@ | |||
import path from 'path'; |
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.
Rename to (webpack|compiler|run).js
test/helpers.js
Outdated
}); | ||
} | ||
|
||
export function stripLocalPaths(source) { |
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.
Move to test/helpers.js
(Separate file to compiler)
test/helpers.js
Outdated
} | ||
|
||
export function stripLocalPaths(source) { | ||
const regexpReplace = new RegExp(__dirname, 'g'); |
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.
regexReplace
=> replacer || replacee || regex
test/helpers.js
Outdated
}, extra); | ||
} | ||
|
||
export function runWebpack(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.
Make this the default
export without a name, see below why :)
test/index.test.js
Outdated
@@ -0,0 +1,34 @@ | |||
import { runWebpack, webpackConfigFactory, stripLocalPaths } from './helpers'; |
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.
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' } = {}) { |
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.
Move into runWebpack
test/helpers.js
Outdated
}, extra); | ||
} | ||
|
||
export function runWebpack(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.
export default function (fixture, options, extend = {}) {
const config = Object.assign({
...webpackConfigFactory
}, extend)
...runWebpack
}
Please also split |
@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 😄 |
webpack-defaults v1.1.0...1.5.0
Mind to open a PR in |
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", |
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.
Not needed anymore since ~webpack-defaults v1.3.0+
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 |
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.
👍
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", |
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.
- nodemon
Drop the |
Done! 💃 |
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 |
@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. |
- `produceSourceMap` is now on by default & must be explicitly disabled if so desired
Done - |
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 😀 |
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)