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 vue sfc #174
Conversation
Hey @blake-newman thank you for your contribution. We will take a look 👍 |
I'm thinking may be best to abstract this in a better way to avoid conditions. Can have a separate processor. Going to push changes up shortly |
c249762
to
82b2aa9
Compare
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.
Thank you for your contribution 🚀
I left some comments. It would be great if we could address them.
package.json
Outdated
"jest": "26.6.3", | ||
"prettier": "2.3.1", | ||
"ts-jest": "26.5.3", | ||
"typescript": "4.2.3" | ||
"typescript": "4.2.3", | ||
"vue": "^3.2.40" |
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.
Is vue
really needed?
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.
No; i've removed 👍
src/preprocessor.ts
Outdated
export function preprocessor(code: string, options: PrettierOptions) { | ||
if (options.filepath?.endsWith('.vue')) return code | ||
return process(code, options) | ||
} | ||
|
||
export function vuePreprocessor(code: string, options: PrettierOptions) { | ||
const { descriptor } = parse(code); | ||
const content = (descriptor.script ?? descriptor.scriptSetup)?.content ?? code | ||
|
||
return code.replace( | ||
content, | ||
`\n${process(content, options)}\n`, | ||
); | ||
|
||
} | ||
|
||
function process(code: string, options: PrettierOptions) { { |
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 would suggest to make a preprocessor folder and separate them in different files. I would say process
also can go in a separate file. Maybe preprocessor
can also be renamed to something like defaultPreprocessor
? What do you think?
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.
Yeah i've done the changes as requested. I'm happy with whatever you feel is best. Your repository after all :)
82b2aa9
to
d8e2162
Compare
FYI: I will open and re-opening the branch to fix the Github CI issue. |
e1a219c
to
5293ec4
Compare
@ayusharma i fixed the issue with the snapshot and also updated the README to reflect support for vue. |
Thank you so much, I will check it today. |
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.
The PR looks good to me. 🎉 Very nice work and thank you so much for the contribution @blake-newman ❤️
I would suggest releasing this change with a new major version v4.0.0. What do you think @blake-newman and @byara ?
Personally; i'd suggest even a patch/minor is fine as non-breaking and no changes in the configuration are needed from a user's perspective. |
Okay. I will release it with v3.4.0. |
Released in v3.4.0 🎉 Thank you again @blake-newman 😃 |
@blake-newman @ayusharma Hello! First of all, thanks for adding the support to Vue files. I wanted to run something by you regarding this PR: With Vue support, a dependency on
Do you see a way of supporting Vue, but keeping the dependency in a non-required way (e.g. |
It may be possible to make it a peer dependency, may need to do inline require in preproccesor layer so lazy load the Vue compiler. I'll take a look soon 👍 |
Ported from trivago/prettier-plugin-sort-imports#174 Co-authored-by: Blake Newman <code@blakenewman.dev>
resolves #49