mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-11-25 20:10:01 +00:00
@parity/resolc fix sol file resolutions (#343)
second take on #339 turns out that the resolve-pkg npm package was also failing to properly resolve package with an exports field define in the package.json. This fixes it and add a test case with such a package
This commit is contained in:
1 parent
e94432eaa0
commit
63f0266fff
4 files changed
+1424
-42
No files matched your search
+21
-1
@@ -129,6 +129,26 @@ export async function compile(
|
||||
return resolc(input)
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve the package root
|
||||
* use resolve-pkg to find the package root, and fallback to using require.resolve if the package defines an exports field
|
||||
* see https://github.com/sindresorhus/resolve-pkg/issues/9
|
||||
**/
|
||||
function resolvePkgRoot(basePackage: string) {
|
||||
const packageRoot = resolvePkg(basePackage)
|
||||
if (packageRoot) {
|
||||
return packageRoot
|
||||
}
|
||||
|
||||
try {
|
||||
const packageExport = require.resolve(basePackage)
|
||||
const endIndex = packageExport.indexOf(basePackage) + basePackage.length
|
||||
return packageExport.substring(0, endIndex)
|
||||
} catch {}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an import path to a file path.
|
||||
* @param importPath - The import path to resolve.
|
||||
@@ -150,7 +170,7 @@ export function tryResolveImport(importPath: string) {
|
||||
const specifiedVersion = match[2] // "1.2.3" (optional)
|
||||
const relativePath = match[3] // "/path/to/file.sol"
|
||||
|
||||
const packageRoot = resolvePkg(basePackage)
|
||||
const packageRoot = resolvePkgRoot(basePackage)
|
||||
if (!packageRoot) {
|
||||
throw new Error(`Package ${basePackage} not found.`)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user