-
-
Notifications
You must be signed in to change notification settings - Fork 254
refactor: apply webpack-defaults
#130
Conversation
Codecov Report
@@ Coverage Diff @@
## master #130 +/- ##
=======================================
Coverage ? 85%
=======================================
Files ? 2
Lines ? 40
Branches ? 18
=======================================
Hits ? 34
Misses ? 6
Partials ? 0
Continue to review full report at Codecov.
|
806aa38
to
8966cd3
Compare
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.
👍
src/index.js
Outdated
this.emitFile(outputPath, content); | ||
} | ||
|
||
return `module.exports = ${publicPath};`; |
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.
// webpack 2
if (loader.version === 2) return `export default ${publicPath}`
return `module.exports = ${publicPath}`
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.
?
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.
That's original code I moved over. Looks like it detects webpack version. This is actually something I can do in certain other place...
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 do the change you proposed in another PR. 👍
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.
Yep agreed, needs to be tested properly, it bited me yesterday in postcss-loader
+ style-loader || extract-text-plugin
where es2015 modules don't work atm
package.json
Outdated
"standard-version": "^4.0.0", | ||
"mocha": "~1.21.3" | ||
"webpack-defaults": "^0.1.1" | ||
}, | ||
"scripts": { |
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.
Please sort them 😛 e.g
"lint": "eslint --cache src test",
"test": "jest",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"travis:lint": "yarn run lint && yarn run nsp",
"travis:test": "npm run test",
"travis:coverage": "yarn run test:coverage"
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.
Any thoughts on this @sapegin? Is this something we can fix at mrm?
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.
scripts
aren't reordered automatically so should be easy enough, i'll PR it into defaults in a minute.
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.
👍
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 sure would be the best approach here. Sorting everything (including existing scripts) feels too destructive. Also would be nice to do it not just for scripts
. @bebraw Good feature for webpack-merge? ;-)
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 not sure. The language specification doesn't really say anything about key order if I remember right.
Let's skip this problem for now. Open an issue at webpack-defaults repo, though.
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.
Note that npm has a tendency to do its own sorting when it touches package.json somehow so I'm not sure if it's worthwhile to spend too much time on fixing 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.
I would personally like to get people accustomed to using import | export | export default
and so on.
The Babel config provides access to all the ES module stuff & it doesn't transpile into a book, may as well make use of it now and get people into the esNext groove :)
test/optional-file-emission.test.js
Outdated
@@ -1,29 +1,27 @@ | |||
var should = require("should"); | |||
var fileLoader = require("../"); | |||
const fileLoader = require('../'); |
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 fileLoader from '../src';
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'll port those. 👍
src/index.js
Outdated
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
const loaderUtils = require('loader-utils'); |
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 loaderUtils from 'loader-utils';
src/index.js
Outdated
*/ | ||
const loaderUtils = require('loader-utils'); | ||
|
||
module.exports = function fileLoader(content) { |
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 fileLoader(content) {
src/index.js
Outdated
|
||
return `module.exports = ${publicPath};`; | ||
}; | ||
module.exports.raw = true; |
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 const raw = true;
test/correct-filename.test.js
Outdated
var should = require("should"); | ||
var path = require("path"); | ||
var fileLoader = require("../"); | ||
const fileLoader = require('../'); |
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 fileLoader from '../src';
test/correct-filename.test.js
Outdated
var should = require("should"); | ||
var path = require("path"); | ||
var fileLoader = require("../"); | ||
const fileLoader = require('../'); |
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.
Also needs to be moved into the src
folder. Tests should reside with the code they are testing ( or that is what was discussed ).
The build
task ignores them though we need to put thought into how we want to handle libs with extensive fixtures
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.
Ah, yeah. I forgot to do that. Good call.
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.
Maybe we end up with both. Unit tests below src
and fixtures/integration tests below 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.
Looking at some of the libs, maybe a test
folder is going to be the cleaner way to do this. Jest is smart enough to handle the preprocessing regardless of where the tests reside.
src/index.js
Outdated
} | ||
|
||
return `module.exports = ${publicPath};`; | ||
}; |
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.
Shouldn't be a semi here
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 that was forced by the linting 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.
I promise that will fail if you run yarn run lint
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's actually the opposite then:
.../file-loader/src/index.js
58:2 error Missing semicolon semi
It's because of module.exports = function fileLoader(content) {...};
.
I pulled down the branch and made the suggested changes so I could check the transpiled output. Also probably best to hold off until the following PR's land and are published. webpack-contrib/webpack-defaults#15 |
@d3viant0ne Ok, feel free to force push your changes over the PR. 👍 |
e5d3d65
to
a2697af
Compare
@bebraw @sapegin - This is ready for a final look.
Reminder: As NodeJS 4 support hasn't been enforced for this loader yet, this will have to be semver
|
The only part that's a little puzzling to me is the handling of imports. Example:
It might make sense to force preprocessing imports too and expose through This isn't an issue if you use the loader within webpack, but it will be problematic if you use loader-runner and such. |
Open an issue in defaults so we can figure out the correct output for "all the things" |
Sure. 👍 |
webpack-contrib/webpack-defaults#23 for further discussion. |
.eslintrc
Outdated
@@ -0,0 +1,6 @@ | |||
{ | |||
"extends": "webpack", | |||
"globals": { |
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 we don’t need this anymore, since webpack preset includes jest
environment.
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, safe to drop. 👍
Yup. Basically
now. This leaves one decision - how to handle |
Ready for a review. I changed the module entry point as discussed at webpack-contrib/webpack-defaults#23. |
src/index.js
Outdated
|
||
return `export default = ${publicPath};`; | ||
} | ||
export const raw = true; |
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.
One thing of note, we are going to need a consistent way to handle the proxy + libs. While it seems like overkill on a single file library like file-loader, applying the same to something like css-loader would be a bit messy.
Proposing we as a standard, leave cjs.js
in ./src
and move any library files into ./src/lib
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.
Another way, go with _cjs.js
so at least it will stand out as glue code. No need for src/lib
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.
Still doesn't solve the issue with the more complicated libs imo. For the sake of simplicity, particularly with defaults upgrade / update still think libs in lib
would be cleaner. Not that I want to endlessly debate the topic.
Take a look at some of our more complicated loaders / plugins, just hammering everything into ./src
stands to get a little messy.
package.json
Outdated
@@ -4,20 +4,49 @@ | |||
"author": "Tobias Koppers @sokra", | |||
"description": "file loader module for webpack", | |||
"files": [ | |||
"index.js" | |||
"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.
This can be removed if webpack-defaults > v0.4.4
I would say merge, publish a 1.0 beta. |
@bebraw - A thought while I'm working on the exports-loader upgrade and it's tests, we had discussed testing everything through webpack which is something i'm doing in exports-loader. We should really make it a point to either create an integration suite or just test everything through webpack to include file-loader. |
@d3viant0ne Yeah, now that I think of it, testing directly through webpack is the sanest option. It adds some overhead but at least that avoids a category of bugs and integration tests are needed anyway so it's hard to avoid not running through webpack. |
Do we want to add webpack as a |
@d3viant0ne Since you are going to need it for development anyway, then a dev dep would make sense. Setting a peer dep as well would be good, though, as that would allow us to communicate version support to users (much harder to run incompatible versions). |
devDep limits our ability to test against multiple versions in travis |
Good point. What if we push the problem to an init script a developer runs when starting to develop? That would do |
Same issue applies to local development imo. Any automated install of Webpack will be limiting in the same manner. I think particular instance, i think clear documentation should be enough. For anyone familiar with the ecosystem, needing Webpack for loader / plugin development is obvious. For anyone that isn't, it's a simple lesson they will only have to learn once which can be at least partially mitigated in a |
Ok, cool. 👍 |
webpack-defaults
@d3viant0ne: Do you want to move with this later? I don't mind updating the PR. |
What kind of change does this PR introduce?
Refactoring.
Did you add tests for your changes?
The old tests should work.
Summary
This PR integrates webpack-defaults to the project.
Does this PR introduce a breaking change?
Yes. Will enforce NodeJS > 4.3 via engines.
Must release as semver
MAJOR
Closes #148