Skip to content

Commit a556f79

Browse files
committedJan 17, 2025
feat(cli): add support for Vue Vine
1 parent 440426a commit a556f79

File tree

6 files changed

+268
-9
lines changed

6 files changed

+268
-9
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function MyComponent() {
2+
return vine`<div>{{ console.log('Hello, world!') }}</div>`;
3+
}
4+
5+
// This is also valid
6+
const AnotherComponent = () => vine`<div>Hello World</div>`

‎fixtures/meta-frameworks-support/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"devDependencies": {
66
"@astrojs/ts-plugin": "latest",
77
"@mdx-js/language-service": "latest",
8-
"@vue/language-core": "latest"
8+
"@vue/language-core": "latest",
9+
"@vue-vine/language-service": "latest"
910
}
1011
}

‎packages/cli/index.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const lightYellow = (s: string) => '\x1b[93m' + s + _reset;
2121
// https://talyian.github.io/ansicolors/
2222
const tsColor = (s: string) => '\x1b[34m' + s + _reset;
2323
const vueColor = (s: string) => '\x1b[32m' + s + _reset;
24+
const vueVineColor = (s: string) => '\x1b[38;5;48m' + s + _reset;
2425
const mdxColor = (s: string) => '\x1b[33m' + s + _reset;
2526
const astroColor = (s: string) => '\x1b[38;5;209m' + s + _reset;
2627

@@ -64,6 +65,9 @@ class Project {
6465
if (this.languages.includes('vue')) {
6566
labels.push(vueColor('Vue'));
6667
}
68+
if (this.languages.includes('vue-vine')) {
69+
labels.push(vueVineColor('Vue Vine'));
70+
}
6771
if (this.languages.includes('mdx')) {
6872
labels.push(mdxColor('MDX'));
6973
}
@@ -124,6 +128,8 @@ class Project {
124128
'--projects',
125129
'--vue-project',
126130
'--vue-projects',
131+
'--vue-vine-project',
132+
'--vue-vine-projects',
127133
'--mdx-project',
128134
'--mdx-projects',
129135
'--astro-project',
@@ -136,6 +142,9 @@ class Project {
136142
options: [{
137143
label: 'Vue',
138144
value: 'vue',
145+
}, {
146+
label: 'Vue Vine',
147+
value: 'vue-vine',
139148
}, {
140149
label: 'MDX',
141150
value: 'mdx',
@@ -196,12 +205,10 @@ class Project {
196205
}
197206
}
198207

199-
clack.log.info(`Running: ${purple(command)}`);
208+
clack.log.info(`${darkGray('Command:')} ${purple(command)}`);
200209

201210
for (let tsconfig of selectedTsconfigs) {
202-
if (!tsconfig.startsWith('.')) {
203-
tsconfig = `./${tsconfig}`;
204-
}
211+
tsconfig = resolvePath(tsconfig);
205212
tsconfigAndLanguages.set(tsconfig, languages);
206213
}
207214
} else {
@@ -214,6 +221,10 @@ class Project {
214221
projectFlags: ['--vue-project', '--vue-projects'],
215222
language: 'vue',
216223
},
224+
{
225+
projectFlags: ['--vue-vine-project', '--vue-vine-projects'],
226+
language: 'vue-vine',
227+
},
217228
{
218229
projectFlags: ['--mdx-project', '--mdx-projects'],
219230
projectsFlag: '--mdx-projects',

‎packages/cli/lib/languagePlugins.ts

+52-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,57 @@ export async function load(tsconfig: string, languages: string[]) {
3838
plugins.push(vueLanguagePlugin);
3939
}
4040

41+
if (languages.includes('vue-vine')) {
42+
let vue: typeof import('@vue/language-core');
43+
let vueVine: typeof import('@vue-vine/language-service');
44+
let pkgPath: string | undefined;
45+
46+
if (pkgPath = findPackageJson('@vue-vine/language-service')) {
47+
const pkgDir = path.dirname(pkgPath);
48+
vueVine = require('@vue-vine/language-service');
49+
vue = require(require.resolve('@vue/language-core', { paths: [pkgDir] }));
50+
} else if (pkgPath = findPackageJson('vue-vine-tsc')) {
51+
const pkgDir = path.dirname(pkgPath);
52+
vue = require(require.resolve('@vue/language-core', { paths: [pkgDir] }));
53+
vueVine = require(require.resolve('@vue/language-core', { paths: [pkgDir] }));
54+
} else {
55+
const pkg = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'package.json');
56+
if (pkg) {
57+
throw new Error('Please install @vue-vine/language-service or vue-vine-tsc to ' + path.relative(process.cwd(), pkg));
58+
} else {
59+
throw new Error('Please install @vue-vine/language-service or vue-vine-tsc for ' + path.relative(process.cwd(), tsconfig));
60+
}
61+
}
62+
63+
const commonLine = vue.createParsedCommandLine(ts, ts.sys, tsconfig, true);
64+
const globalTypesFilePath = vueVine.setupGlobalTypes(path.dirname(tsconfig), commonLine.vueOptions as any, ts.sys);
65+
if (globalTypesFilePath) {
66+
commonLine.vueOptions.__setupedGlobalTypes = {
67+
absolutePath: globalTypesFilePath,
68+
};
69+
}
70+
71+
plugins.push(
72+
vue.createVueLanguagePlugin<string>(
73+
ts,
74+
commonLine.options,
75+
commonLine.vueOptions,
76+
id => id
77+
)
78+
);
79+
80+
plugins.push(
81+
vueVine.createVueVineLanguagePlugin(
82+
ts,
83+
{
84+
compilerOptions: commonLine.options,
85+
vueCompilerOptions: commonLine.vueOptions as any,
86+
target: 'tsc',
87+
}
88+
)
89+
);
90+
}
91+
4192
if (languages.includes('mdx')) {
4293
let mdx: any;
4394

@@ -78,8 +129,6 @@ export async function load(tsconfig: string, languages: string[]) {
78129
return plugins;
79130

80131
function findPackageJson(pkgName: string) {
81-
try {
82-
return require.resolve(`${pkgName}/package.json`, { paths: [path.dirname(tsconfig)] });
83-
} catch { }
132+
return ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, `node_modules/${pkgName}/package.json`);
84133
}
85134
}

‎packages/cli/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"typescript": "*"
2828
},
2929
"devDependencies": {
30-
"@vue/language-core": "latest"
30+
"@vue/language-core": "latest",
31+
"@vue-vine/language-service": "latest"
3132
}
3233
}

0 commit comments

Comments
 (0)
Failed to load comments.