Skip to content

Commit

Permalink
fix(cli-utils): Upgrade support for @vue/language-core@^2.0.1 (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten authored May 14, 2024
1 parent c56ebf7 commit a405503
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 97 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-squids-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gql.tada/cli-utils": patch
---

Support `@vue/language-core@^2.0.1`'s updated public API
6 changes: 3 additions & 3 deletions packages/cli-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
"@0no-co/graphqlsp": "^1.12.1",
"@gql.tada/internal": "workspace:*",
"@vue/compiler-dom": "^3.4.23",
"@vue/language-core": "^2.0.0",
"@vue/language-core": "^2.0.17",
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
"svelte2tsx": "^0.7.6"
},
"peerDependencies": {
"typescript": "^5.0.0",
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0"
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
"typescript": "^5.0.0"
},
"publishConfig": {
"access": "public",
Expand Down
23 changes: 19 additions & 4 deletions packages/cli-utils/src/ts/transformers/vue.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import ts from 'typescript';
import type { VirtualCode } from '@vue/language-core';
import { forEachEmbeddedCode, getDefaultVueLanguagePlugins } from '@vue/language-core';
import * as vueCompilerDOM from '@vue/compiler-dom';
import * as vue from '@vue/language-core';

function* forEachEmbeddedCode(virtualCode: VirtualCode) {
yield virtualCode;
if (virtualCode.embeddedCodes) {
for (const embeddedCode of virtualCode.embeddedCodes) {
yield* forEachEmbeddedCode(embeddedCode);
}
}
}

let VueVirtualCode: typeof vue.VueVirtualCode | undefined;
if ('VueVirtualCode' in vue) {
VueVirtualCode = vue.VueVirtualCode;
} else if ('VueGeneratedCode' in vue) {
VueVirtualCode = (vue as any).VueGeneratedCode;
}

let getBasePlugins: typeof vue.getBasePlugins | undefined;
if ('getBasePlugins' in vue) {
getBasePlugins = vue.getBasePlugins;
} else if ('getDefaultVueLanguagePlugins' in vue) {
getBasePlugins = (vue as any).getDefaultVueLanguagePlugins;
}

const vueCompilerOptions = vue.resolveVueCompilerOptions({});

let plugins: ReturnType<typeof getDefaultVueLanguagePlugins> | undefined;
let plugins: ReturnType<typeof vue.getBasePlugins> | undefined;

export const transform = (sourceFile: ts.SourceFile): VirtualCode | undefined => {
if (!VueVirtualCode) {
if (!VueVirtualCode || !getBasePlugins) {
return undefined;
} else if (!plugins) {
plugins = getDefaultVueLanguagePlugins({
plugins = getBasePlugins({
modules: {
typescript: ts,
'@vue/compiler-dom': vueCompilerDOM,
Expand Down
Loading

0 comments on commit a405503

Please sign in to comment.