-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
fix(addStyles): support exports of transpiled transforms (options.transform
)
#333
Conversation
Codecov Report
@@ Coverage Diff @@
## master #333 +/- ##
=======================================
Coverage 98.43% 98.43%
=======================================
Files 4 4
Lines 64 64
Branches 21 21
=======================================
Hits 63 63
Misses 1 1 Continue to review full report at Codecov.
|
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 add tests and we can merge this
Please accept CLA too |
lib/addStyles.js
Outdated
result = options.transform(obj.css); | ||
result = typeof options.transform === 'function' | ||
? options.transform(obj.css) | ||
: Object.values(options.transform)[0](obj.css); |
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 question, why 0
? Maybe better default
?
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 first thought of options.transform.default(obj.css);
But then I thought if there are other modules which uses another name other than default, then Object.values(options.transform)[0](obj.css);
, will support all of them.
Then decision is yours.
Error: |
Yeah, you are right. So then we can use |
@evilebottnawi I replaced Object.values with Object.keys to support old browsers. And as for accepting CLA, I already done that. I don't know why it is not reflecting here. |
@evilebottnawi can you now take a look? |
{Error}
when export default
is used (options.transform
)
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.
Where does it currently check and throw within the loader :) ? While it's an valid issue it's debatable if adding a check for this to the loader in particular is really needed here , the style-loader
is still kind of a node module (require
) and node
simply doesn't support ES Modules natively yet. What about adding an note to the README instead warning that one needs to transpile transforms written with ES Modules beforehand?
@michael-ciniawsky it's throw error: transform is not a function when export default or exports.default is used instead of module.exports. If want to check, I already created a repo. https://github.com/akki-jat/style-loader-bug--332 About the transpile, most of the user place their transform.js file outside the src folder and they default configuration which transpiles only src folder. And It would be irretating to user if we force this to them. What do you think? Tell me, we will discuss it. |
I see and I'm ok with using |
Around the transform option section something like e.g
|
@michael-ciniawsky you are right about the warning. Why throws error even after the transpile?export default is transpiled in exports.default and it returns the transform as object (not as a function) and actual transform function wrapped inside its default property. So, meaning this will solve problem that is occurring after transpiling. |
…tions.transform`)
What kind of change does this PR introduce?
bugfix
Did you add tests for your changes?
No
Solves #332
Does this PR introduce a breaking change?
No