mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 18:28:01 +00:00
Fix npm package resolution (#339)
Current approach fails with an 'ERR_PACKAGE_PATH_NOT_EXPORTED' error for
npm package that defines an exports field in the package.json
e.g:
> require.resolve('@redstone-finance/evm-connector/package.json')
will fail with
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json'
is not defined by "exports" in
/home/pg/github/evm-test-suite/eth-rpc/node_modules/@redstone-finance/evm-connector/package.json
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
This commit is contained in:
@@ -3,6 +3,7 @@ import { spawn } from 'child_process'
|
||||
import { resolc, version as resolcVersion } from './resolc'
|
||||
import path from 'path'
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import resolvePkg from 'resolve-pkg'
|
||||
|
||||
export type SolcInput = {
|
||||
[contractName: string]: {
|
||||
@@ -149,17 +150,15 @@ export function tryResolveImport(importPath: string) {
|
||||
const specifiedVersion = match[2] // "1.2.3" (optional)
|
||||
const relativePath = match[3] // "/path/to/file.sol"
|
||||
|
||||
let packageJsonPath
|
||||
try {
|
||||
packageJsonPath = require.resolve(path.join(basePackage, 'package.json'))
|
||||
} catch {
|
||||
throw new Error(`Could not resolve package ${basePackage}`)
|
||||
const packageRoot = resolvePkg(basePackage)
|
||||
if (!packageRoot) {
|
||||
throw new Error(`Package ${basePackage} not found.`)
|
||||
}
|
||||
|
||||
// Check if a version was specified and compare with the installed version
|
||||
if (specifiedVersion) {
|
||||
const installedVersion = JSON.parse(
|
||||
readFileSync(packageJsonPath, 'utf-8')
|
||||
readFileSync(path.join(packageRoot, 'package.json'), 'utf-8')
|
||||
).version
|
||||
|
||||
if (installedVersion !== specifiedVersion) {
|
||||
@@ -169,8 +168,6 @@ export function tryResolveImport(importPath: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const packageRoot = path.dirname(packageJsonPath)
|
||||
|
||||
// Construct full path to the requested file
|
||||
const resolvedPath = path.join(packageRoot, relativePath)
|
||||
if (existsSync(resolvedPath)) {
|
||||
|
||||
Reference in New Issue
Block a user