-
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
Changes from all commits
1ec8978
7a2e92a
df2bfa2
a71a99b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
vueOptionsNamespace: '__options__', | ||
defaultVueJestConfig: { | ||
transform: {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Updating it for this |
||
transformer, | ||
blocks, | ||
vueOptionsNamespace, | ||
filename, | ||
config | ||
) { | ||
return transformer.process({ blocks, vueOptionsNamespace, filename, config }) | ||
} | ||
|
||
function groupByType(acc, block) { | ||
acc[block.type] = acc[block.type] || [] | ||
acc[block.type].push(block) | ||
return acc | ||
} | ||
|
||
module.exports = function(allBlocks, filename, config) { | ||
const blocksByType = allBlocks.reduce(groupByType, {}) | ||
const code = [] | ||
for (const [type, blocks] of Object.entries(blocksByType)) { | ||
const transformer = getCustomTransformer( | ||
getVueJestConfig(config).transform, | ||
type | ||
) | ||
if (transformer) { | ||
const codeStr = applyTransformer( | ||
transformer, | ||
blocks, | ||
vueOptionsNamespace, | ||
filename, | ||
config | ||
) | ||
code.push(codeStr) | ||
} | ||
} | ||
|
||
return code.length ? code.join('\n') : '' | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -58,6 +58,7 @@ | |||
"stylus": "^0.54.5", | ||||
"typescript": "^3.2.2", | ||||
"vue": "^2.4.2", | ||||
"vue-i18n": "^8.15.5", | ||||
"vue-template-compiler": "^2.4.2" | ||||
}, | ||||
"peerDependencies": { | ||||
|
@@ -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 commentThe 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
|
||||
"js-yaml": "^3.13.1", | ||||
"json5": "^2.1.1", | ||||
"ts-jest": "^24.0.0" | ||||
}, | ||||
"repository": { | ||||
|
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?
Uh oh!
There was an error while loading. Please reload this page.
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