Skip to content

Commit a25670e

Browse files
authoredNov 19, 2024··
feat: support pnp mode (#15)
1 parent c10d34f commit a25670e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

Diff for: ‎src/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { dirname, join, win32 } from 'node:path'
2+
import { createRequire } from 'node:module'
23
import fs from 'node:fs'
34
import fsp from 'node:fs/promises'
45
import process from 'node:process'
@@ -28,6 +29,17 @@ function _resolve(path: string, options: PackageResolvingOptions = {}) {
2829
if (options.platform === 'auto' || !options.platform)
2930
options.platform = process.platform === 'win32' ? 'win32' : 'posix'
3031

32+
if (process.versions.pnp) {
33+
const paths = options.paths || []
34+
if (paths.length === 0)
35+
paths.push(process.cwd())
36+
const targetRequire = createRequire(import.meta.url)
37+
try {
38+
return targetRequire.resolve(path, { paths })
39+
}
40+
catch {}
41+
}
42+
3143
const modulePath = resolvePathSync(path, {
3244
url: options.paths,
3345
})

0 commit comments

Comments
 (0)
Please sign in to comment.