Skip to content

Commit da8740b

Browse files
committed
fix: require.resolve
1 parent 0c5e9e3 commit da8740b

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"has-pkg": "^0.0.1",
6767
"magic-string": "^0.25.7",
6868
"minimatch": "^3.0.4",
69+
"resolve": "^1.20.0",
6970
"unplugin": "^0.2.7"
7071
},
7172
"peerDependencies": {
@@ -78,6 +79,7 @@
7879
"@types/jest": "^27.0.1",
7980
"@types/minimatch": "^3.0.5",
8081
"@types/node": "^16.7.10",
82+
"@types/resolve": "^1.20.1",
8183
"@typescript-eslint/eslint-plugin": "^4.30.0",
8284
"compare-versions": "^3.6.0",
8385
"eslint": "^7.32.0",

pnpm-lock.yaml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/helpers/libraryResolver.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import fs from 'fs'
22
import { dirname, join } from 'path'
33
import Debug from 'debug'
44
import { ComponentResolver, UILibraryOptions } from '../../types'
5-
import { camelCase, kebabCase } from '../utils'
5+
import { camelCase, kebabCase, resolveImportPath } from '../utils'
66

77
const debug = Debug('unplugin-vue-components:helper:library')
88

99
export function tryLoadVeturTags(name: string): string[] | undefined {
1010
try {
11-
const pkgPath = require.resolve(`${name}/package.json`)
11+
// eslint-disable-next-line no-eval
12+
const pkgPath = resolveImportPath(`${name}/package.json`)
1213
if (!pkgPath)
1314
return
1415
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))

src/core/resolvers/veui.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join, normalize } from 'path'
22
import { ComponentResolver, SideEffectsInfo } from '../../types'
3-
import { kebabCase, camelCase, pascalCase } from '../utils'
3+
import { kebabCase, camelCase, pascalCase, resolveImportPath } from '../utils'
44

55
interface VeuiPeerConfig {
66
/**
@@ -106,7 +106,7 @@ const peerPaths = new Map<string, boolean>()
106106
function assertPeerPath(peerPath: string) {
107107
if (!peerPaths.has(peerPath)) {
108108
try {
109-
require.resolve(peerPath)
109+
resolveImportPath(peerPath)
110110
peerPaths.set(peerPath, true)
111111
}
112112
catch (e) {

src/core/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { parse } from 'path'
22
import minimatch from 'minimatch'
33
import { ResolvedConfig } from 'vite'
44
import { slash, toArray } from '@antfu/utils'
5+
import { sync as resolve } from 'resolve'
56
import { ComponentInfo, ResolvedOptions, ImportInfo } from '../types'
67
import { Context } from './context'
78
import { DISABLE_COMMENT } from './constants'
@@ -155,3 +156,9 @@ export function shouldTransform(code: string) {
155156
return false
156157
return true
157158
}
159+
160+
export function resolveImportPath(importName: string): string | undefined {
161+
return resolve(importName, {
162+
preserveSymlinks: false,
163+
})
164+
}

0 commit comments

Comments
 (0)