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: support custom blocks for Vue 3 #364

Merged
merged 2 commits into from
Nov 28, 2021

Conversation

kazupon
Copy link
Member

@kazupon kazupon commented Jul 10, 2021

This is WIP pull request.

As the title, I’ll support be transforming custom blocks for Vue 3.
At this time, only jest 26.x is supported.

@kazupon kazupon marked this pull request as ready for review July 11, 2021 15:47
if (Array.isArray(customBlocksResult)) {
customBlocksResult.forEach(codes => {
codes.forEach(code => {
node.add(`;((${componentNamespace}) => { ${code} })(exports.default);`)
Copy link
Member Author

Choose a reason for hiding this comment

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

Custom blocks can now be handled for components like vue-loader and @vitejs/plugin-vue.

@@ -133,23 +134,28 @@ function processStyle(styles, filename, config) {

module.exports = function(src, filename, config) {
const { descriptor } = parse(src, { filename })
const componentNamespace =
getVueJestConfig(config)['componentNamespace'] || vueComponentNamespace
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 added the componentNamespace option to the vue-jest config.
This is because we want the transformer (parser) side of custom blocks to be able to handle them flexibly.

In the case of i18n custom blocks, we are using a common library for generic processing for various bundlers such as vue-i18n-loader, rollup-plugin-vue-i18n, and vite-plugin-vue-i18n. For example, it's handled the below:

https://github.com/intlify/cli/blob/4875ec52e0256bf2cf9723dde999b8efa8c043cd/src/generator/json.ts#L91-L103

In the code in the URL above, the component pass to the function, and uses the variable name Component.

In order to reuse this logic in vue-jest transformer, I need to change it a bit, but in any case, being able to specify the variable name allows for flexible processing on the transformer side.

@lmiller1990
Copy link
Member

I will review this and port to Jest 27 in the near future, thanks for waiting.

@kazupon
Copy link
Member Author

kazupon commented Nov 11, 2021

Hi! @lmiller1990
I'm working with @nogic1008 and my project member on vue-i18n-jest, which is now monorepo like vue-jest.
intlify/vue-i18n-jest#42

What do we do need additional work?

@lmiller1990
Copy link
Member

Sorry I took a while to look at this. Seems fine!

Let's release this right now.

@lmiller1990 lmiller1990 merged commit 6e76d59 into vuejs:master Nov 28, 2021
@kazupon kazupon deleted the feat/custom-blocks-for-vue3 branch November 29, 2021 04:15
@kazupon
Copy link
Member Author

kazupon commented Nov 29, 2021

Thank you very much! ✨ ❤️

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