Skip to content

Commit 989a151

Browse files
committed
feat!: intruducing macros
1 parent 24081e3 commit 989a151

29 files changed

+937
-617
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
"chalk": "^5.3.0",
4040
"conventional-changelog-cli": "^5.0.0",
4141
"eslint": "^9.6.0",
42-
"esno": "^4.7.0",
4342
"fast-glob": "^3.3.2",
4443
"nodemon": "^3.1.4",
4544
"rimraf": "^5.0.7",
46-
"tsup": "^8.1.0",
45+
"tsup": "^8.4.0",
4746
"typescript": "^5.7.0",
4847
"unplugin": "^1.11.0",
49-
"unplugin-raw": "^0.3.1",
48+
"unplugin-raw": "^0.4.4",
49+
"vite": "^6.0.0",
5050
"vitest": "^1.6.0"
5151
},
5252
"pnpm": {

packages/macros/package.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,47 @@
3333
"import": "./dist/index.js"
3434
},
3535
"./astro": {
36+
"dev": "./src/astro.ts",
3637
"require": "./dist/astro.cjs",
3738
"import": "./dist/astro.js"
3839
},
3940
"./rspack": {
41+
"dev": "./src/rspack.ts",
4042
"require": "./dist/rspack.cjs",
4143
"import": "./dist/rspack.js"
4244
},
4345
"./vite": {
46+
"dev": "./src/vite.ts",
4447
"require": "./dist/vite.cjs",
4548
"import": "./dist/vite.js"
4649
},
4750
"./webpack": {
51+
"dev": "./src/webpack.ts",
4852
"require": "./dist/webpack.cjs",
4953
"import": "./dist/webpack.js"
5054
},
5155
"./rollup": {
56+
"dev": "./src/rollup.ts",
5257
"require": "./dist/rollup.cjs",
5358
"import": "./dist/rollup.js"
5459
},
5560
"./esbuild": {
61+
"dev": "./src/esbuild.ts",
5662
"require": "./dist/esbuild.cjs",
5763
"import": "./dist/esbuild.js"
5864
},
5965
"./nuxt": {
66+
"dev": "./src/nuxt.ts",
6067
"require": "./dist/nuxt.cjs",
6168
"import": "./dist/nuxt.js"
6269
},
6370
"./api": {
71+
"dev": "./src/api.ts",
6472
"require": "./dist/api.cjs",
6573
"import": "./dist/api.js"
6674
},
6775
"./raw": {
76+
"dev": "./src/raw.ts",
6877
"require": "./dist/raw.cjs",
6978
"import": "./dist/raw.js"
7079
},
@@ -134,6 +143,14 @@
134143
"build": "tsup",
135144
"dev": "DEV=true tsup"
136145
},
146+
"peerDependencies": {
147+
"@nuxt/kit": "^3",
148+
"@nuxt/schema": "^3",
149+
"esbuild": "*",
150+
"rollup": "^3",
151+
"vite": ">=3",
152+
"webpack": "^4 || ^5"
153+
},
137154
"peerDependenciesMeta": {
138155
"@nuxt/kit": {
139156
"optional": true
@@ -156,16 +173,18 @@
156173
},
157174
"dependencies": {
158175
"@vue-macros/common": "3.0.0-beta.4",
176+
"@vue/compiler-dom": "catalog:",
159177
"@vue/compiler-sfc": "catalog:",
178+
"@vue/language-core": "^2.2.8",
160179
"hash-sum": "^2.0.0",
161180
"ts-macro": "catalog:"
162181
},
163182
"devDependencies": {
164183
"@babel/types": "7.26.9",
165-
"@nuxt/kit": "^3.12.3",
166-
"@nuxt/schema": "^3.12.3",
167184
"@types/hash-sum": "^1.0.2",
168185
"@vue-macros/test-utils": "3.0.0-beta.4",
169-
"vue": "catalog:"
186+
"vue": "catalog:",
187+
"@nuxt/kit": "^3.12.3",
188+
"@nuxt/schema": "^3.12.3"
170189
}
171190
}

packages/macros/src/astro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unplugin from '.'
2-
import type { Options } from './types'
2+
import type { Options } from './options'
33

44
export default (options: Options) => ({
55
name: 'unplugin-vue-jsx-vapor',

packages/macros/src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { transformDefineExpose } from './define-expose'
1212
import { transformDefineModel } from './define-model'
1313
import { transformDefineSlots } from './define-slots'
1414
import { transformDefineStyle } from './define-style'
15-
import type { OptionsResolved } from '../types'
15+
import type { OptionsResolved } from '../options'
1616
import type {
1717
ArrowFunctionExpression,
1818
CallExpression,

packages/macros/src/core/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { compileStyleAsync } from '@vue/compiler-sfc'
2-
import type { OptionsResolved } from '../types'
2+
import type { OptionsResolved } from '../options'
33

44
export async function transformStyle(
55
code: string,

packages/macros/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { type UnpluginInstance, createUnplugin } from 'unplugin'
22
import plugin from './raw'
3-
import type { Options } from './types'
3+
import type { Options } from './options'
44

5-
export * from './types'
5+
export * from './options'
66

77
const unplugin: UnpluginInstance<Options | undefined> = createUnplugin(plugin)
88
export default unplugin

packages/macros/src/nuxt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'
22
import vite from './vite'
33
import webpack from './webpack'
4-
import type { Options } from './types'
4+
import type { Options } from './options'
55
import '@nuxt/schema'
66

77
export interface ModuleOptions extends Options {}

packages/macros/src/options.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { detectVueVersion, REGEX_NODE_MODULES, REGEX_SETUP_SFC, REGEX_SRC_FILE, type BaseOptions, type MarkRequired } from '@vue-macros/common'
2+
3+
export type Options = BaseOptions & {
4+
lib?: 'vue' | 'vue/vapor' | (string & {})
5+
defineComponent?: { alias: string[] }
6+
defineModel?: { alias: string[] }
7+
defineExpose?: { alias: string[] }
8+
defineSlots?: { alias: string[] }
9+
defineStyle?: { alias: string[] }
10+
}
11+
export type OptionsResolved = MarkRequired<
12+
Options,
13+
| 'include'
14+
| 'version'
15+
| 'lib'
16+
| 'defineComponent'
17+
| 'defineModel'
18+
| 'defineExpose'
19+
| 'defineSlots'
20+
| 'defineStyle'
21+
>
22+
23+
export function resolveOptions(options: Options): OptionsResolved {
24+
const version = options.version || detectVueVersion()
25+
const lib = options.lib || 'vue/vapor'
26+
return {
27+
include: [REGEX_SRC_FILE],
28+
exclude: [REGEX_SETUP_SFC, REGEX_NODE_MODULES],
29+
...options,
30+
version,
31+
lib,
32+
defineComponent: {
33+
alias: options?.defineComponent?.alias ?? [
34+
'defineComponent',
35+
'defineVaporComponent',
36+
],
37+
},
38+
defineModel: { alias: options?.defineModel?.alias ?? ['defineModel'] },
39+
defineSlots: { alias: options?.defineSlots?.alias ?? ['defineSlots'] },
40+
defineExpose: { alias: options?.defineExpose?.alias ?? ['defineExpose'] },
41+
defineStyle: { alias: options?.defineStyle?.alias ?? ['defineStyle'] },
42+
}
43+
}

packages/macros/src/raw.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import {
2-
FilterFileType,
3-
REGEX_NODE_MODULES,
4-
REGEX_SETUP_SFC,
5-
REGEX_SRC_FILE,
62
createFilter,
7-
detectVueVersion,
83
normalizePath,
94
} from '@vue-macros/common'
105
import {
@@ -16,31 +11,9 @@ import {
1611
} from './core/helper'
1712
import { transformStyle } from './core/style'
1813
import { transformJsxMacros } from './core'
19-
import type { Options, OptionsResolved } from './types'
14+
import { resolveOptions, type Options } from './options'
2015
import type { UnpluginOptions } from 'unplugin'
2116

22-
export function resolveOptions(options: Options): OptionsResolved {
23-
const version = options.version || detectVueVersion()
24-
const lib = options.lib || 'vue/vapor'
25-
return {
26-
include: [REGEX_SRC_FILE],
27-
exclude: [REGEX_SETUP_SFC, REGEX_NODE_MODULES],
28-
...options,
29-
version,
30-
lib,
31-
defineComponent: {
32-
alias: options?.defineComponent?.alias ?? [
33-
'defineComponent',
34-
'defineVaporComponent',
35-
],
36-
},
37-
defineModel: { alias: options?.defineModel?.alias ?? ['defineModel'] },
38-
defineSlots: { alias: options?.defineSlots?.alias ?? ['defineSlots'] },
39-
defineExpose: { alias: options?.defineExpose?.alias ?? ['defineExpose'] },
40-
defineStyle: { alias: options?.defineStyle?.alias ?? ['defineStyle'] },
41-
}
42-
}
43-
4417
const name = '@vue-jsx-vapor/macros'
4518

4619
const plugin = (userOptions: Options = {}): UnpluginOptions => {

packages/macros/src/types.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)