Skip to content

Commit ad07b3f

Browse files
committed
fix!: ignore node_modules by default
1 parent 06125aa commit ad07b3f

File tree

4 files changed

+19
-38
lines changed

4 files changed

+19
-38
lines changed

src/core/options.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import process from 'node:process'
2-
import { getPackageInfo } from 'local-pkg'
2+
import { getPackageInfoSync } from 'local-pkg'
33
import type { VueJSXPluginOptions } from '@vue/babel-plugin-jsx'
44
import type { FilterPattern } from 'unplugin-utils'
55

@@ -31,27 +31,24 @@ export type OptionsResolved = Omit<Required<Options>, 'version' | 'exclude'> & {
3131
exclude?: Options['exclude']
3232
}
3333

34-
export async function resolveOption(
35-
options: Options,
36-
): Promise<OptionsResolved> {
34+
export function resolveOptions(options: Options): OptionsResolved {
3735
const root = options.root || process.cwd()
3836
let version: 2 | 3
3937
if (options.version === 'auto') {
40-
version = await getVueVersion(root)
38+
version = getVueVersion(root)
4139
} else version = options.version || 3
4240

4341
return {
4442
...options,
4543
include: options.include || [/\.[jt]sx?$/],
46-
exclude: options.exclude || undefined,
44+
exclude: options.exclude || [/node_modules/],
4745
version,
4846
root,
4947
sourceMap: options.sourceMap ?? true,
5048
}
5149
}
5250

53-
async function getVueVersion(root: string) {
54-
const pkg = await getPackageInfo('vue', { paths: [root] })
55-
if (!pkg) return 3
56-
return pkg.version?.startsWith('2') ? 2 : 3
51+
function getVueVersion(root: string) {
52+
const pkg = getPackageInfoSync('vue', { paths: [root] })
53+
return pkg?.version?.startsWith('2') ? 2 : 3
5754
}

src/index.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1-
import {
2-
createUnplugin,
3-
type UnpluginInstance,
4-
type UnpluginOptions,
5-
} from 'unplugin'
1+
import { createUnplugin, type UnpluginInstance } from 'unplugin'
62
import { createFilter } from 'unplugin-utils'
7-
import {
8-
resolveOption,
9-
type Options,
10-
type OptionsResolved,
11-
} from './core/options'
3+
import { resolveOptions, type Options } from './core/options'
124

135
const VueJsx: UnpluginInstance<Options | undefined, false> = createUnplugin(
146
(userOptions = {}) => {
15-
let options: OptionsResolved
16-
let filter: (id: unknown) => boolean
7+
const options = resolveOptions(userOptions)
8+
const filter = createFilter(options.include, options.exclude)
179

18-
const name = 'unplugin-vue-jsx'
19-
const factory: UnpluginOptions = {
20-
name,
21-
22-
async buildStart() {
23-
options = await resolveOption(userOptions)
24-
filter = createFilter(options.include, options.exclude)
25-
},
10+
return {
11+
name: 'unplugin-vue-jsx',
2612

2713
transformInclude(id) {
2814
return filter(id)
@@ -33,11 +19,11 @@ const VueJsx: UnpluginInstance<Options | undefined, false> = createUnplugin(
3319
if (options.version === 2) {
3420
// Vue 2
3521
const { transformVue2 } = await import('./core/vue2')
36-
result = await transformVue2(code, id, options)
22+
result = transformVue2(code, id, options)
3723
} else {
3824
// Vue 3
3925
const { transformVue3 } = await import('./core/vue3')
40-
result = await transformVue3(code, id, options)
26+
result = transformVue3(code, id, options)
4127
}
4228

4329
if (!result?.code) return
@@ -55,8 +41,6 @@ const VueJsx: UnpluginInstance<Options | undefined, false> = createUnplugin(
5541
},
5642
},
5743
}
58-
59-
return factory
6044
},
6145
)
6246
export default VueJsx

tests/vue2.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { describe, expect, test } from 'vitest'
2-
import { resolveOption, type Options } from '../src/core/options'
2+
import { resolveOptions, type Options } from '../src/core/options'
33
import { transformVue2 } from '../src/core/vue2'
44

55
const transform = async (code: string, userOptions: Options = {}) => {
6-
const options = await resolveOption({
6+
const options = await resolveOptions({
77
version: 2,
88
...userOptions,
99
})

tests/vue3.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { describe, expect, test } from 'vitest'
2-
import { resolveOption, type Options } from '../src/core/options'
2+
import { resolveOptions, type Options } from '../src/core/options'
33
import { transformVue3 } from '../src/core/vue3'
44

55
const transform = async (
66
code: string,
77
isTS = false,
88
userOptions: Options = {},
99
) => {
10-
const options = await resolveOption({
10+
const options = await resolveOptions({
1111
version: 3,
1212
...userOptions,
1313
})

0 commit comments

Comments
 (0)