Skip to content

Commit 3d9ac66

Browse files
authored
refactor: extraction the resolvePath function (#48)
1 parent a2e9473 commit 3d9ac66

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/core/components.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { addComponent, createResolver } from '@nuxt/kit'
1+
import { addComponent } from '@nuxt/kit'
22
import { libraryName } from '../config'
3-
import { hyphenate, toArray } from '../utils'
3+
import { hyphenate, resolvePath, toArray } from '../utils'
44
import type { ModuleOptions } from '../types'
55

66
export function resolveComponents (config: ModuleOptions) {
77
const { components, excludeExports } = config
8-
const { resolvePath } = createResolver(import.meta.url)
98

109
components.forEach(async (item) => {
1110
const [name, alias, from] = toArray(item)

src/core/transformPlugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createUnplugin } from 'unplugin'
22
import MagicString from 'magic-string'
33
import type { NuxtOptions } from '@nuxt/schema'
4-
import { createResolver } from '@nuxt/kit'
54
import { allImportsWithStyle, libraryName } from '../config'
6-
import { camelize, genSideEffectsImport, toRegExp } from '../utils'
5+
import { camelize, genSideEffectsImport, resolvePath, toRegExp } from '../utils'
76
import type { TransformOptions } from '../types'
87

98
interface PluginOptions extends TransformOptions {
@@ -34,7 +33,6 @@ export const transformPlugin = createUnplugin((options: PluginOptions) => {
3433
}
3534
},
3635
async transform (code, id) {
37-
const { resolvePath } = createResolver(import.meta.url)
3836
const styles = new Set<string>()
3937
const s = new MagicString(code)
4038

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { createResolver } from '@nuxt/kit'
12
import type { NuxtConfigLayer } from '@nuxt/schema'
23
import { libraryName } from './config'
34

5+
export function resolvePath (path: string): Promise<string> {
6+
const { resolvePath } = createResolver(import.meta.url)
7+
return resolvePath(path)
8+
}
9+
410
export function getLayersDir (layers: NuxtConfigLayer[]) {
511
const list = []
612

0 commit comments

Comments
 (0)