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
Support Vue #40
Merged
Merged
Support Vue #40
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PrettierOptions } from '../types'; | ||
import { preprocessor } from './preprocessor'; | ||
|
||
export function defaultPreprocessor(code: string, options: PrettierOptions) { | ||
if (options.filepath?.endsWith('.vue')) return code; | ||
return preprocessor(code, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { parse } from '@vue/compiler-sfc'; | ||
|
||
import { PrettierOptions } from '../types'; | ||
import { preprocessor } from './preprocessor'; | ||
|
||
export function vuePreprocessor(code: string, options: PrettierOptions) { | ||
const { descriptor } = parse(code); | ||
const content = | ||
(descriptor.script ?? descriptor.scriptSetup)?.content ?? code; | ||
|
||
return code.replace(content, `\n${preprocessor(content, options)}\n`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`setup.vue - vue-verify: setup.vue 1`] = ` | ||
<script setup> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue' | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
</script> | ||
|
||
<template> | ||
<div></div> | ||
</template> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<script setup> | ||
// I am top level comment in this file. | ||
import thirdParty from "third-party"; | ||
import { defineComponent } from "vue"; | ||
import z from "z"; | ||
|
||
import abc from "@core/abc"; | ||
import otherthing from "@core/otherthing"; | ||
|
||
import something from "@server/something"; | ||
|
||
import component from "@ui/hello"; | ||
import xyz from "@ui/xyz"; | ||
|
||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
</script> | ||
|
||
<template> | ||
<div></div> | ||
</template> | ||
|
||
`; | ||
|
||
exports[`sfc.vue - vue-verify: sfc.vue 1`] = ` | ||
<script> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue'; | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
export default defineComponent({ | ||
}) | ||
</script> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<script> | ||
// I am top level comment in this file. | ||
import thirdParty from "third-party"; | ||
import { defineComponent } from "vue"; | ||
import z from "z"; | ||
|
||
import abc from "@core/abc"; | ||
import otherthing from "@core/otherthing"; | ||
|
||
import something from "@server/something"; | ||
|
||
import component from "@ui/hello"; | ||
import xyz from "@ui/xyz"; | ||
|
||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
export default defineComponent({}); | ||
</script> | ||
|
||
`; | ||
|
||
exports[`ts.vue - vue-verify: ts.vue 1`] = ` | ||
<script lang="ts"> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue'; | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
export default defineComponent({ | ||
}) | ||
</script> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<script lang="ts"> | ||
// I am top level comment in this file. | ||
import thirdParty from "third-party"; | ||
import { defineComponent } from "vue"; | ||
import z from "z"; | ||
|
||
import abc from "@core/abc"; | ||
import otherthing from "@core/otherthing"; | ||
|
||
import something from "@server/something"; | ||
|
||
import component from "@ui/hello"; | ||
import xyz from "@ui/xyz"; | ||
|
||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
export default defineComponent({}); | ||
</script> | ||
|
||
`; | ||
|
||
exports[`tsx.vue - vue-verify: tsx.vue 1`] = ` | ||
<script lang="tsx"> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue'; | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
export default defineComponent({ | ||
render() { | ||
return <div /> | ||
} | ||
}) | ||
</script> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<script lang="tsx"> | ||
// I am top level comment in this file. | ||
import thirdParty from "third-party"; | ||
import { defineComponent } from "vue"; | ||
import z from "z"; | ||
|
||
import abc from "@core/abc"; | ||
import otherthing from "@core/otherthing"; | ||
|
||
import something from "@server/something"; | ||
|
||
import component from "@ui/hello"; | ||
import xyz from "@ui/xyz"; | ||
|
||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
export default defineComponent({ | ||
render() { | ||
return <div />; | ||
}, | ||
}); | ||
</script> | ||
|
||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
run_spec(__dirname, ["vue"], { | ||
importOrder: ['^@core/(.*)$', '^@server/(.*)', '^@ui/(.*)$', '^[./]'], | ||
importOrderSeparation: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script setup> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue' | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
</script> | ||
|
||
<template> | ||
<div></div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue'; | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
export default defineComponent({ | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
// I am top level comment in this file. | ||
import z from 'z'; | ||
import threeLevelRelativePath from "../../../threeLevelRelativePath"; | ||
import sameLevelRelativePath from "./sameLevelRelativePath"; | ||
import thirdParty from "third-party"; | ||
import oneLevelRelativePath from "../oneLevelRelativePath"; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
import twoLevelRelativePath from "../../twoLevelRelativePath"; | ||
import component from "@ui/hello"; | ||
import fourLevelRelativePath from "../../../../fourLevelRelativePath"; | ||
import something from "@server/something"; | ||
import xyz from "@ui/xyz"; | ||
import { defineComponent } from 'vue'; | ||
function add(a,b) { | ||
return a + b; | ||
} | ||
export default defineComponent({ | ||
}) | ||
</script> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this have instead been an
optionalDependency
? I admit I'm unfamiliar with the size/complexity of@vue/compiler-sfc
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.
optionalDependency
anddevDependency
?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 don't think it can be optional, unless we have a good way to conditionally
import()
it, and I'm not sure how we'd know up-front when registering the plugin whether it will be needed or not.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.
Conditional import will require some shenanigans with require statements, but I think it's possible.
The way I'd do it, is by adding a wrapper function around the compiler call, that does that detection, and throws a clean error if the package is missing, but that codepath is executed. We would need some
// @ts-ignore
lines, I 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.
I think it would need to be in
peerDependencies
and we would setpeerDependenciesMeta
to treat it as optional. The main thing I'm not sure about is: Can we expect every Vue project to have this dependency?@blake-newman, since you wrote the original PR and know the Vue landscape much better than I do, maybe you can talk about why you chose to use a regular dependency for
@vue/compiler-sfc
rather than a peerDependency?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.
@IanVS i used it as a
devDependency
for simplicity of use; however it is correct that not all will need it.This is the stack it introduces: which is fairly heavy just to extract the script section. I may be able to remove this dependency tbh. As it's not a tricky job to do so.
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.
trivago/prettier-plugin-sort-imports#183
I decided to keep with the compiler; as no point re-inventing the wheel. Most Vue projects will have this dependency by default anyway.
The scope of the API used is very minimal so there is no need to try to lock it into a specific version; it's quite unlikely the API will break this use case. If it ever does it'll be likely trivial changes to fix but won't break this package and fix can be added consumer side to lock a particular version until resolved upstream.
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.
Great, thanks for the explanations! I'll make it a peer dependency on this fork as well, then.
Also note, if you're using the trivago version, it's potentially unsafe to use side-effect-only imports, since it will re-arrange them, which is the reason this fork exists. Just giving you a heads-up in case you weren't aware.