-
Notifications
You must be signed in to change notification settings - Fork 157
feat: add support for vue-i18n custom blocks by default #227
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 support for vue-i18n custom blocks by default #227
Conversation
da97129
to
3013e13
Compare
3013e13
to
832450e
Compare
832450e
to
c49525e
Compare
@JessicaSachs I'm glad you support i18n custom blocks by default in vue-jest. vue-jest seem that have already a mechanism that user can transform to code. https://github.com/vuejs/vue-jest/blob/master/lib/process-style.js#L67-L93 In the above, the custom transformer path gets from the jest config and require it, and the code is generated by custom transformer. As well as, I think we can do custom blocks. |
I agree! In discord I am asking for help to design an extensible interface
for custom blocks :-) come chat with me.
…On Tue, Mar 10, 2020 at 10:57 PM kazuya kawaguchi ***@***.***> wrote:
@JessicaSachs <https://github.com/JessicaSachs>
Thank you for your support !
I'm glad you support i18n custom blocks by default in vue-jest.
However, if we will consider the maintainability of vue-jest, I think that
it's should provide an interface that supports transform to code for custom
blocks.
vue-jest seem that have already a mechanism that user can transform to
code.
You can see the code in processStyle of lib/process-style.js.
https://github.com/vuejs/vue-jest/blob/master/lib/process-style.js#L67-L93
In the above, the custom transformer path gets from the jest config and
require it, and the code is generated by custom transformer.
As well as, I think we can do custom blocks.
The custom transformer need to provide with library author like vue-i18n,
but I don't think it's a problem because it's the responsibility of side
providing custom blocks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#227?email_source=notifications&email_token=AAVL4BFW7VUPH4AW5KVJLD3RG34YJA5CNFSM4LFJRW5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEON6GEI#issuecomment-597418769>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVL4BGEP5IO4L2QJ4CLSLLRG34YJANCNFSM4LFJRW5A>
.
|
1dc4982
to
7a2e92a
Compare
OK! @kazupon, @lmiller1990, @afontcu, and @dobromir-hristov would love feedback from any and all of you 🙇♀ |
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 the code looks fine, mostly questions rather than real feedback!
lib/transformers/i18n.js
Outdated
return JSON.stringify(JSON.parse(convert(content, langKnown))) | ||
} | ||
|
||
try { |
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.
do we need a warning here? "Your file is not valid JSON or YAML".
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.
Could do. I matched the existing code.
lib/transformers/i18n.js
Outdated
const codes = blocks.map(block => { | ||
if (block.type === 'i18n') { | ||
const value = parseLanguageAndContent(block, filename) | ||
.replace(/\u2028/g, '\\u2028') |
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.
What do these codes represent?
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.
They're line seperators, but really, I have no idea, I copied them from vue-i18n-jest
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.
ok, vue-i18n is battle tested, going to assume kazupon knows what he is doing
const { getVueJestConfig, getCustomTransformer } = require('./utils') | ||
const vueOptionsNamespace = require('./constants').vueOptionsNamespace | ||
|
||
function applyTransformer( |
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.
Should we try to match the jest process api a bit more closer? That would be `applyTransform(blocks, filename, config, transformer, vueOptionsNamespace) I guess. Although maybe more awkard to call then - just thinking out loud
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 wasn't sure about this either. I think if there was no external context, like if jest process didn't exist, maybe an object-based api would be best, because there's a lot of optional params.
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.
Object based works well for me too - what do you think? I really like to use an object when there are more than 1-2 params, since it is easier to read.
If it's not too much trouble that change could go with that? I don't mind too much, 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.
Updating it for this
@@ -21,7 +24,7 @@ module.exports = function generateCode( | |||
} | |||
|
|||
output += | |||
`var __options__ = typeof exports.default === 'function' ` + | |||
`var ${namespace} = typeof exports.default === 'function' ` + |
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 specific reason to move the constant to another file? It seems to be used elsewhere when it wasn't before - why is that?
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.
Because it was being hardcoded inside of vue-i18n-jest and Edd refactored this in v4, which broke vue-i18n-jest if we were to have released v4 of vue-jest... We should make any required constants passed in rather than requiring developers to dig into vue-jest source code to figure out what constants we're using when they're writing their processors
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.
Right, makes sense, sounds good
d53e699
to
df2bfa2
Compare
@JessicaSachs I'm realy gload to support vue-i18n as default at vue-jest. I hope that vue-jest will offer I/F only for custome blocks without natively supporting vue-i18n. :) |
No problem. I’m happy to remove the processor natively now that we’re
supporting custom blocks generally.
…On Thu, Mar 19, 2020 at 7:17 AM kazuya kawaguchi ***@***.***> wrote:
@JessicaSachs <https://github.com/JessicaSachs>
Thanks a lot!.
I'm realy gload to support vue-i18n as default at vue-jest.
But the supporting at least one custom block will seem unfair to the
creator of the library that provides the custom block.
I hope that vue-jest will offer I/F only for custome blocks without
natively supporting vue-i18n. :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#227 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVL4BB7NPGGSOGZVOPMLCTRIH5MHANCNFSM4LFJRW5A>
.
|
1684495
to
2f4901a
Compare
2f4901a
to
a71a99b
Compare
@JessicaSachs |
@@ -72,7 +73,8 @@ | |||
"chalk": "^2.1.0", | |||
"convert-source-map": "^1.6.0", | |||
"extract-from-css": "^0.4.4", | |||
"source-map": "^0.5.6", |
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.
@JessicaSachs this package is used here
vue-jest/lib/generate-source-map.js
Line 2 in 0b0d5e2
const sourceMap = require('source-map') |
This PR adds support for an extensible API to parse and process custom blocks.
See the rendered README for API changes and writing a processor