Skip to content

Commit 0463655

Browse files
committed
feat: add shortVmodel into macros plugin
1 parent b7f70e7 commit 0463655

File tree

18 files changed

+269
-165
lines changed

18 files changed

+269
-165
lines changed

.changeset/honest-cars-impress.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@vue-macros/short-vmodel': minor
3+
'@vue-macros/common': minor
4+
'unplugin-vue-macros': minor
5+
'@vue-macros/test-utils': patch
6+
---
7+
8+
feat: add shortVmodel into macros plugin

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"fast-glob": "^3.3.1",
5252
"monoman": "^0.4.2",
5353
"npm-run-all": "^4.1.5",
54-
"prettier": "^3.0.2",
54+
"prettier": "^3.0.3",
5555
"rimraf": "^5.0.1",
5656
"tsup": "^7.2.0",
5757
"tsx": "^3.12.7",

packages/astro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"devDependencies": {
5858
"@vitejs/plugin-vue": "^4.3.4",
59-
"astro": "^2.10.14"
59+
"astro": "^2.10.15"
6060
},
6161
"engines": {
6262
"node": ">=16.14.0"

packages/common/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
"magic-string-ast": "^0.3.0"
6262
},
6363
"devDependencies": {
64-
"@babel/parser": "^7.22.13"
64+
"@babel/parser": "^7.22.13",
65+
"@vitejs/plugin-vue": "^4.3.4",
66+
"rollup": "^3.28.1"
6567
},
6668
"engines": {
6769
"node": ">=16.14.0"

packages/common/src/unplugin.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
createFilter as createRollupFilter,
44
} from '@rollup/pluginutils'
55
import { generateTransform } from 'magic-string-ast'
6+
import { type ResolvedOptions } from '@vitejs/plugin-vue'
7+
import { type NormalizedInputOptions } from 'rollup'
68

79
/** @deprecated use `generateTransform` instead */
810
export const getTransformResult = generateTransform
@@ -18,3 +20,30 @@ export function createFilter(options: BaseOptions) {
1820
}
1921

2022
export { normalizePath } from '@rollup/pluginutils'
23+
24+
export interface VuePluginApi {
25+
options: ResolvedOptions
26+
version: string
27+
}
28+
29+
export function getVuePluginApi(
30+
rollupOpts: NormalizedInputOptions
31+
): VuePluginApi {
32+
const vuePlugin = rollupOpts.plugins.find(
33+
(p) => p.name === 'vite:vue' || p.name === 'unplugin-vue'
34+
)
35+
if (!vuePlugin) {
36+
throw new Error(
37+
'Cannot find Vue plugin (@vitejs/plugin-vue or unplugin-vue).\nPlease make sure to add it before using shortVmodel.'
38+
)
39+
}
40+
41+
const api = vuePlugin.api as VuePluginApi
42+
if (!api?.version) {
43+
throw new Error(
44+
'The Vue plugin is not supported (@vitejs/plugin-vue or unplugin-vue). Please make sure version > 4.3.4.'
45+
)
46+
}
47+
48+
return api
49+
}

packages/macros/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"@vue-macros/setup-component": "workspace:*",
101101
"@vue-macros/setup-sfc": "workspace:*",
102102
"@vue-macros/short-emits": "workspace:*",
103+
"@vue-macros/short-vmodel": "workspace:*",
103104
"unplugin": "^1.4.0",
104105
"unplugin-combine": "^0.7.0",
105106
"unplugin-vue-define-options": "workspace:*"

packages/macros/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ import VueSetupSFC, {
7272
import VueShortEmits, {
7373
type Options as OptionsShortEmits,
7474
} from '@vue-macros/short-emits'
75+
import VueShortVmodel, {
76+
type Options as OptionsShortVmodel,
77+
} from '@vue-macros/short-vmodel'
7578

7679
import { excludeDepOptimize } from './core'
7780
import { generatePluginName } from '#macros' assert { type: 'macro' }
@@ -98,6 +101,7 @@ export interface FeatureOptionsMap {
98101
setupComponent: OptionsSetupComponent
99102
setupSFC: OptionsSetupSFC
100103
shortEmits: OptionsShortEmits
104+
shortVmodel: OptionsShortVmodel
101105
}
102106
export type FeatureName = keyof FeatureOptionsMap
103107
export type FeatureOptions = FeatureOptionsMap[FeatureName]
@@ -154,6 +158,7 @@ export function resolveOptions({
154158
setupComponent,
155159
setupSFC,
156160
shortEmits,
161+
shortVmodel,
157162
}: Options): OptionsResolved {
158163
function resolveSubOptions<K extends FeatureName>(
159164
options: OptionalSubOptions<FeatureOptionsMap[K]>,
@@ -244,6 +249,7 @@ export function resolveOptions({
244249
{ version },
245250
version < 3.3
246251
),
252+
shortVmodel: resolveSubOptions<'shortVmodel'>(shortVmodel, { version }),
247253
}
248254
}
249255

@@ -321,6 +327,9 @@ export default createCombinePlugin<Options | undefined>(
321327
resolvePlugin(VueHoistStatic, framework, options.hoistStatic),
322328
resolvePlugin(VueDefineOptions, framework, options.defineOptions),
323329
resolvePlugin(VueJsxDirective, framework, options.jsxDirective),
330+
(framework === 'vite' || framework === 'webpack') &&
331+
// VueShortVmodel is not an unplugin, by now
332+
resolvePlugin(VueShortVmodel as any, framework, options.shortVmodel),
324333
options.plugins.vue,
325334
options.plugins.vueJsx,
326335
resolvePlugin(VueDefineRender, framework, options.defineRender),

packages/short-vmodel/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"@vue/compiler-core": "^3.3.4"
5050
},
5151
"devDependencies": {
52-
"@vue/compiler-sfc": "^3.3.4"
52+
"@vue/compiler-sfc": "^3.3.4",
53+
"rollup": "^3.28.1"
5354
},
5455
"engines": {
5556
"node": ">=16.14.0"

packages/short-vmodel/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './core'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './transformer'

0 commit comments

Comments
 (0)