Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add options validation #224

Merged
merged 1 commit into from
May 22, 2017
Merged

feat: add options validation #224

merged 1 commit into from
May 22, 2017

Conversation

michael-ciniawsky
Copy link
Member

@michael-ciniawsky michael-ciniawsky commented May 1, 2017

#What kind of change does this PR introduce?

  • Style
  • Feature
  • Refactor

Did you add tests for your changes?

😛 Yep

If relevant, did you update the README?

👌 #222

Summary

Fixes #223

  • Add options validation
  • Initial repo restructure
  • Initial code style update
  • Update dependencies (css-loader, file-loader, jsdom)

Does this PR introduce a breaking change?

Nope

Copy link
Contributor

@bebraw bebraw left a comment

Choose a reason for hiding this comment

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

Can you split this into two PRs? Restructuring and schema. Now it's a little tricky to review. :)

@michael-ciniawsky
Copy link
Member Author

michael-ciniawsky commented May 1, 2017

@bebraw Yeah sry 😛 it come over me, could we make an exception this time please? 🙃 🙏

@michael-ciniawsky
Copy link
Member Author

It's just addStyles && addStylesUrl && urls (fixUrls) => lib, delete fixtures (dead code), add spaces and shorten names in addStyles && addStylesUrl + schema in index, url, useable

@michael-ciniawsky
Copy link
Member Author

michael-ciniawsky commented May 1, 2017

no logic related changes and the tests pass.. :)

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Seems very good, some note

lib/addStyles.js Outdated

// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
// tags it will allow on a page
if (typeof options.singleton === "undefined") options.singleton = isOldIE();
Copy link
Member

Choose a reason for hiding this comment

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

Why typeof ?

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, will update :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

lib/addStyles.js Outdated
if(domStyle) {
domStyle.refs++;

for(var j = 0; j < domStyle.parts.length; j++) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems it can do in one loop

Copy link
Member

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.

👍 I wll take a look into that

Copy link
Member Author

@michael-ciniawsky michael-ciniawsky May 2, 2017

Choose a reason for hiding this comment

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

for(var j = 0; j < domStyle.parts.length && item.parts.length; j++) {
  domStyle.parts[j](item.parts[j]);
  domStyle.parts.push(addStyle(item.parts[j], options));
}

@evilebottnawi &&or || ? 🙃 the tests pass with &&, but I'm not 💯 on this :D

package.json Outdated
"description": "style loader module for webpack",
"engines": {
"node": ">= 0.12.0"
Copy link
Member

Choose a reason for hiding this comment

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

Why? 😄 maybe 4 minimum?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep but this PR is minor and current style-loader is node =< 4 aswell, I bump it with the webpack-defaults upgrade 😛

"node": ">= 0.12.0"
},
"main": "index.js",
"files": [
Copy link
Member

Choose a reason for hiding this comment

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

We have not forgotten anything? Maybe be good add to default smoke test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I this a rhetoric question just to double check or did I miss something obvious ? 🙃

Copy link
Member Author

Choose a reason for hiding this comment

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

We have && done 😛

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Seems good, I hope we did not break anything 😛

@michael-ciniawsky
Copy link
Member Author

@evilebottnawi blocked by webpack/schema-utils#9 it's an enterily stupid issue, but any ideas welcome 😛

@michael-ciniawsky
Copy link
Member Author

michael-ciniawsky commented May 10, 2017

My apologizes for the PR size again 🙏 , wouldn't happen again 😛

module.exports = function () {};

module.exports.pitch = function (request) {
if (this.cacheable) this.cacheable();
Copy link
Contributor

Choose a reason for hiding this comment

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

this.cacheable shouldn't be needed in webpack 2 anymore if I understood right.

Copy link
Member Author

@michael-ciniawsky michael-ciniawsky May 10, 2017

Choose a reason for hiding this comment

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

I left it because it's semver minor & planned to remove with webpack-defaults upgrade in the upcoming major, but we can remove it if consensus is found about it

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that's fine.

module.exports.pitch = function (request) {
if (this.cacheable) this.cacheable();

var options = loaderUtils.getOptions(this) || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe getOptions should return {} by default? Worth checking.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean var options = loaderUtils.getOptions(this) returns {} anyways ? mom I will check that :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Check for sure. If it doesn't, figure out why it doesn't return an {}. That would seem like a sensible default or else we end up with the check everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

use: [ 'style-loader' ] // options === null

getOptions returns null 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, maybe escalate to loader-utils. It would make sense to change the default from consumer point of view. I wonder what's the reasoning for null. It's easier if you get an object always.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep {} would be better, I open an issue at loader-utils is this blocking the PR ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not blocking. The current implementation is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

},
"convertToAbsoluteUrls": {
"type": "boolean"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be a good idea to add a description field for each.

Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason it doesn't get displayed in the OptionsValidationError @schema-utils, but agreed this is mandatory to some point, but I need to fix it in schema-utils first 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure.

@michael-ciniawsky
Copy link
Member Author

michael-ciniawsky commented May 22, 2017

I took a note about #224 (comment) in case it should cause an unforeseen regression and needs to be reverted, works fine locally so far and test pass, but... 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants