Skip to content

Commit

Permalink
feat: Vite 4 support (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Dec 11, 2022
1 parent feb52d6 commit 934d5f8
Show file tree
Hide file tree
Showing 34 changed files with 1,551 additions and 1,209 deletions.
19 changes: 19 additions & 0 deletions .changeset/long-schools-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@vue-macros/better-define': minor
'@vue-macros/define-model': minor
'unplugin-vue-define-options': minor
'@vue-macros/define-props': minor
'@vue-macros/define-render': minor
'@vue-macros/define-slots': minor
'@vue-macros/hoist-static': minor
'unplugin-vue-macros': minor
'@vue-macros/named-template': minor
'@vue-macros/setup-component': minor
'@vue-macros/setup-sfc': minor
'@vue-macros/short-emits': minor
'@vue-macros/nuxt': patch
'@vue-macros/volar': patch
---

Support Vite 4
Drop Rollup 2
14 changes: 1 addition & 13 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@

{
matchUpdateTypes: ['major'],
matchPackageNames: [
'vue',

// wait Vite 4
'rollup',
'@rollup/pluginutils',
'@rollup/plugin-node-resolve',
],
enabled: false,
},
{
matchUpdateTypes: ['minor'],
matchPackageNames: ['unplugin-combine'],
matchPackageNames: ['vue'],
enabled: false,
},
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ English | [简体中文](./README-zh-CN.md)
- ✨ Explore and extend more macros and syntax sugar to Vue.
- 💚 Supports both Vue 2.7 and Vue 3 out-of-the-box.
- 🦾 Full TypeScript / Volar support.
- ⚡️ Supports Vite, Nuxt, Webpack, Vue CLI, Rollup, esbuild and more, powered by [unplugin](https://github.com/unjs/unplugin).
- ⚡️ Supports Vite, Nuxt, Webpack, Vue CLI, Rollup 3, esbuild and more, powered by [unplugin](https://github.com/unjs/unplugin).

## Installation

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/bundler-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default defineConfig({

:::

::: code-group-item Rollup (first-class support)
::: code-group-item Rollup 3 (first-class support)

```ts
// rollup.config.js
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ features:
details: Full TypeScript and Volar support.
- icon: ⚡️
title: Multiple bundlers are supported
details: Supports Vite, Nuxt, Webpack, Vue CLI, Rollup, esbuild and more, powered by unplugin.
details: Supports Vite, Nuxt, Webpack, Vue CLI, Rollup 3, esbuild and more, powered by unplugin.
---
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"serve": "vitepress serve"
},
"devDependencies": {
"@vitejs/plugin-vue-jsx": "^2.1.1",
"@vitejs/plugin-vue-jsx": "^3.0.0",
"markdown-it-container": "^3.0.0",
"unocss": "^0.47.5",
"unplugin-vue-define-options": "*",
"vite-plugin-pwa": "^0.13.3",
"vitepress": "1.0.0-alpha.29",
"vitepress": "1.0.0-alpha.31",
"vue": "^3.2.45"
}
}
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,27 @@
"@babel/types": "^7.20.5",
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.2",
"@pnpm/find-workspace-packages": "^5.0.13",
"@pnpm/find-workspace-packages": "^5.0.14",
"@pnpm/logger": "^5.0.0",
"@sxzz/eslint-config": "^2.4.4",
"@types/node": "18.11.10",
"@vitest/coverage-c8": "^0.25.3",
"@vitest/ui": "^0.25.3",
"@types/node": "18.11.13",
"@vitest/coverage-c8": "^0.25.7",
"@vitest/ui": "^0.25.7",
"@vue-macros/test-utils": "workspace:*",
"eslint": "^8.29.0",
"eslint-define-config": "^1.12.0",
"expect-type": "^0.15.0",
"fast-glob": "^3.2.12",
"hookable": "^5.4.2",
"npm-run-all": "^4.1.5",
"tsup": "^6.5.0",
"tsx": "^3.12.1",
"turbo": "^1.6.3",
"typescript": "^4.9.3",
"vite": "^3.2.4",
"vitest": "^0.25.3",
"vue": "^3.2.45"
"typescript": "^4.9.4",
"vite": "^4.0.0",
"vitest": "^0.25.7",
"vue": "^3.2.45",
"webpack": "^5.75.0"
},
"engines": {
"node": ">=14.19.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/better-define/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
"dev": "DEV=1 tsup"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/api": "workspace:~",
"@vue-macros/common": "workspace:~",
"unplugin": "^1.0.0"
},
"devDependencies": {
"rollup": "^2.79.1"
"rollup": "^3.7.3"
},
"engines": {
"node": ">=14.19.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/define-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
}
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "workspace:~",
"ast-walker-scope": "^0.3.0",
"ast-walker-scope": "^0.3.1",
"unplugin": "^1.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/define-options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If you support this feature, feel free to hit like 👍 or comment on [RFC Discu
- ✨ With this macro, you can use Options API in Vue `<script setup>`.
- 💚 Supports both Vue 2.7 and Vue 3 out-of-the-box.
- 🦾 Full TypeScript support.
- ⚡️ Supports Vite, Nuxt, Webpack, Vue CLI, Rollup, esbuild and more, powered by <a href="https://github.com/unjs/unplugin">unplugin</a>.
- ⚡️ Supports Vite, Nuxt, Webpack, Vue CLI, Rollup 3, esbuild and more, powered by <a href="https://github.com/unjs/unplugin">unplugin</a>.

### See Also

Expand Down
6 changes: 3 additions & 3 deletions packages/define-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
"dev": "DEV=1 tsup"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "workspace:~",
"ast-walker-scope": "^0.3.0",
"ast-walker-scope": "^0.3.1",
"unplugin": "^1.0.0"
},
"devDependencies": {
"rollup": "^2.79.1",
"rollup": "^3.7.3",
"vue": "^3.2.45"
},
"engines": {
Expand Down
12 changes: 6 additions & 6 deletions packages/define-options/tests/__snapshots__/rollup.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ export { empty as default };
"
`;
exports[`Rollup > fixtures > tests/fixtures/error1.vue 1`] = `[Error: unplugin-vue-define-options SyntaxError: \`defineOptions()\` in <script setup> cannot reference locally declared variables (name) because it will be hoisted outside of the setup() function.]`;
exports[`Rollup > fixtures > tests/fixtures/error1.vue 1`] = `[RollupError: unplugin-vue-define-options SyntaxError: \`defineOptions()\` in <script setup> cannot reference locally declared variables (name) because it will be hoisted outside of the setup() function.]`;
exports[`Rollup > fixtures > tests/fixtures/error2.vue 1`] = `[Error: unplugin-vue-define-options SyntaxError: \`defineOptions()\` in <script setup> cannot reference locally declared variables (foo) because it will be hoisted outside of the setup() function.]`;
exports[`Rollup > fixtures > tests/fixtures/error2.vue 1`] = `[RollupError: unplugin-vue-define-options SyntaxError: \`defineOptions()\` in <script setup> cannot reference locally declared variables (foo) because it will be hoisted outside of the setup() function.]`;
exports[`Rollup > fixtures > tests/fixtures/error3.vue 1`] = `[Error: unplugin-vue-define-options SyntaxError: defineOptions cannot be used with default export within <script>.]`;
exports[`Rollup > fixtures > tests/fixtures/error3.vue 1`] = `[RollupError: unplugin-vue-define-options SyntaxError: defineOptions cannot be used with default export within <script>.]`;
exports[`Rollup > fixtures > tests/fixtures/error4.vue 1`] = `[Error: unplugin-vue-define-options SyntaxError: defineOptions() please use defineProps or defineEmits instead.]`;
exports[`Rollup > fixtures > tests/fixtures/error4.vue 1`] = `[RollupError: unplugin-vue-define-options SyntaxError: defineOptions() please use defineProps or defineEmits instead.]`;
exports[`Rollup > fixtures > tests/fixtures/error5.vue 1`] = `[Error: unplugin-vue-define-options SyntaxError: defineOptions() please use defineProps or defineEmits instead.]`;
exports[`Rollup > fixtures > tests/fixtures/error5.vue 1`] = `[RollupError: unplugin-vue-define-options SyntaxError: defineOptions() please use defineProps or defineEmits instead.]`;
exports[`Rollup > fixtures > tests/fixtures/error6.vue 1`] = `[Error: unplugin-vue-define-options SyntaxError: duplicate defineOptions() call]`;
exports[`Rollup > fixtures > tests/fixtures/error6.vue 1`] = `[RollupError: unplugin-vue-define-options SyntaxError: duplicate defineOptions() call]`;
exports[`Rollup > fixtures > tests/fixtures/function.vue 1`] = `
"var _function = \`<script lang=\\"ts\\">
Expand Down
2 changes: 1 addition & 1 deletion packages/define-props/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"vue": "^3.2.25"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "workspace:~",
"unplugin": "^1.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/define-render/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"vue": "^2.7.0 || ^3.0.0"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "workspace:~",
"unplugin": "^1.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _export_sfc = (sfc, props) => {
return target;
};
var id = /*#__PURE__*/_export_sfc(_sfc_main, [__FILE__]);
var id = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { id as default };
"
Expand All @@ -67,7 +67,7 @@ var _export_sfc = (sfc, props) => {
return target;
};
var tsx = /*#__PURE__*/_export_sfc(_sfc_main, [__FILE__]);
var tsx = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { tsx as default };
"
Expand All @@ -91,7 +91,7 @@ var _export_sfc = (sfc, props) => {
return target;
};
var withoutFn = /*#__PURE__*/_export_sfc(_sfc_main, [__FILE__]);
var withoutFn = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { withoutFn as default };
"
Expand Down
2 changes: 1 addition & 1 deletion packages/define-slots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"vue": "^2.7.0 || ^3.0.0"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "workspace:~",
"unplugin": "^1.0.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/hoist-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@
"dev": "DEV=1 tsup"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "workspace:~",
"unplugin": "^1.0.0"
},
"devDependencies": {},
"engines": {
"node": ">=14.19.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/macros/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"vue": "^2.7.0 || ^3.2.25"
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/better-define": "workspace:*",
"@vue-macros/define-model": "workspace:*",
"@vue-macros/define-props": "workspace:*",
Expand All @@ -85,11 +85,11 @@
"@vue-macros/setup-sfc": "workspace:*",
"@vue-macros/short-emits": "workspace:*",
"local-pkg": "^0.4.2",
"unplugin-combine": "^0.2.8",
"unplugin-combine": "^0.5.1",
"unplugin-vue-define-options": "workspace:*"
},
"devDependencies": {
"esbuild": "^0.15.18",
"esbuild": "^0.16.4",
"unplugin": "^1.0.0",
"vue": "^3.2.45"
},
Expand Down
78 changes: 43 additions & 35 deletions packages/macros/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import VueShortEmits from '@vue-macros/short-emits'

import { getVueVersion } from './utils'
import type { UnpluginInstance } from 'unplugin'
import type {
OptionsPlugin,
Unplugin,
UnpluginCombineInstance,
} from 'unplugin-combine'
import type { OptionsPlugin, Plugin, PluginType } from 'unplugin-combine'
import type { Options as OptionsBetterDefine } from '@vue-macros/better-define'
import type { Options as OptionsDefineModel } from '@vue-macros/define-model'
import type { Options as OptionsDefineOptions } from 'unplugin-vue-define-options'
Expand Down Expand Up @@ -127,48 +123,60 @@ function resolveOptions({
}

function resolvePlugin(
options: FeatureOptions | false,
unplugin: UnpluginCombineInstance<any>,
index: number
): Unplugin<any> | undefined
unplugin: UnpluginInstance<any, true>,
framework: PluginType,
options: FeatureOptions | false
): Plugin[] | undefined

function resolvePlugin(
options: FeatureOptions | false,
unplugin: UnpluginInstance<any, false>
): Unplugin<any> | undefined
unplugin: UnpluginInstance<any, false>,
framework: PluginType,
options: FeatureOptions | false
): Plugin | undefined

function resolvePlugin(
options: FeatureOptions | false,
unplugin: UnpluginInstance<any, false> | UnpluginCombineInstance<any>,
idx?: number
): Unplugin<any> | undefined {
unplugin: UnpluginInstance<any, boolean>,
framework: PluginType,
options: FeatureOptions | false
): Plugin | Plugin[] | undefined {
if (!options) return
if ('plugins' in unplugin) {
return ((unplugin.plugins as any)(options) as Unplugin<any>)[idx!]
}
return [unplugin, options]
return unplugin[framework!](options)
}

const name = 'unplugin-vue-macros'

export default createCombinePlugin((userOptions: Options = {}) => {
export default createCombinePlugin((userOptions: Options = {}, meta) => {
const options = resolveOptions(userOptions)

const framework = meta.framework!
const setupComponentPlugins = resolvePlugin(
VueSetupComponent,
framework,
options.setupComponent
)
const namedTemplatePlugins = resolvePlugin(
VueNamedTemplate,
framework,
options.namedTemplate
)

const plugins: OptionsPlugin[] = [
resolvePlugin(options.setupSFC, VueSetupSFC),
resolvePlugin(options.setupComponent, VueSetupComponent, 0),
resolvePlugin(options.setupBlock, VueSetupBlock),
resolvePlugin(options.hoistStatic, VueHoistStatic),
resolvePlugin(options.namedTemplate, VueNamedTemplate, 0),
resolvePlugin(options.defineProps, VueDefineProps),
resolvePlugin(options.shortEmits, VueShortEmits),
resolvePlugin(options.defineModel, VueDefineModel),
resolvePlugin(options.defineSlots, VueDefineSlots),
resolvePlugin(options.betterDefine, VueBetterDefine),
resolvePlugin(options.defineOptions, VueDefineOptions),
resolvePlugin(VueSetupSFC, framework, options.setupSFC),
setupComponentPlugins?.[0],
resolvePlugin(VueSetupBlock, framework, options.setupBlock),
resolvePlugin(VueHoistStatic, framework, options.hoistStatic),
namedTemplatePlugins?.[0],
resolvePlugin(VueDefineProps, framework, options.defineProps),
resolvePlugin(VueShortEmits, framework, options.shortEmits),
resolvePlugin(VueDefineModel, framework, options.defineModel),
resolvePlugin(VueDefineSlots, framework, options.defineSlots),
resolvePlugin(VueBetterDefine, framework, options.betterDefine),
resolvePlugin(VueDefineOptions, framework, options.defineOptions),
options.plugins.vue,
options.plugins.vueJsx,
resolvePlugin(options.defineRender, VueDefineRender),
resolvePlugin(options.setupComponent, VueSetupComponent, 1),
resolvePlugin(options.namedTemplate, VueNamedTemplate, 1),
resolvePlugin(VueDefineRender, framework, options.defineRender),
setupComponentPlugins?.[1],
namedTemplatePlugins?.[1],
].filter(Boolean)

return {
Expand Down

0 comments on commit 934d5f8

Please sign in to comment.