mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-29 07:47:57 +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:
@@ -32,6 +32,7 @@
|
|||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"commander": "^13.1.0",
|
"commander": "^13.1.0",
|
||||||
"package-json": "^10.0.1",
|
"package-json": "^10.0.1",
|
||||||
|
"resolve-pkg": "^2.0.0",
|
||||||
"solc": ">=0.8.0 <=0.8.30"
|
"solc": ">=0.8.0 <=0.8.30"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { spawn } from 'child_process'
|
|||||||
import { resolc, version as resolcVersion } from './resolc'
|
import { resolc, version as resolcVersion } from './resolc'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { existsSync, readFileSync } from 'fs'
|
import { existsSync, readFileSync } from 'fs'
|
||||||
|
import resolvePkg from 'resolve-pkg'
|
||||||
|
|
||||||
export type SolcInput = {
|
export type SolcInput = {
|
||||||
[contractName: string]: {
|
[contractName: string]: {
|
||||||
@@ -149,17 +150,15 @@ export function tryResolveImport(importPath: string) {
|
|||||||
const specifiedVersion = match[2] // "1.2.3" (optional)
|
const specifiedVersion = match[2] // "1.2.3" (optional)
|
||||||
const relativePath = match[3] // "/path/to/file.sol"
|
const relativePath = match[3] // "/path/to/file.sol"
|
||||||
|
|
||||||
let packageJsonPath
|
const packageRoot = resolvePkg(basePackage)
|
||||||
try {
|
if (!packageRoot) {
|
||||||
packageJsonPath = require.resolve(path.join(basePackage, 'package.json'))
|
throw new Error(`Package ${basePackage} not found.`)
|
||||||
} catch {
|
|
||||||
throw new Error(`Could not resolve package ${basePackage}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a version was specified and compare with the installed version
|
// Check if a version was specified and compare with the installed version
|
||||||
if (specifiedVersion) {
|
if (specifiedVersion) {
|
||||||
const installedVersion = JSON.parse(
|
const installedVersion = JSON.parse(
|
||||||
readFileSync(packageJsonPath, 'utf-8')
|
readFileSync(path.join(packageRoot, 'package.json'), 'utf-8')
|
||||||
).version
|
).version
|
||||||
|
|
||||||
if (installedVersion !== specifiedVersion) {
|
if (installedVersion !== specifiedVersion) {
|
||||||
@@ -169,8 +168,6 @@ export function tryResolveImport(importPath: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageRoot = path.dirname(packageJsonPath)
|
|
||||||
|
|
||||||
// Construct full path to the requested file
|
// Construct full path to the requested file
|
||||||
const resolvedPath = path.join(packageRoot, relativePath)
|
const resolvedPath = path.join(packageRoot, relativePath)
|
||||||
if (existsSync(resolvedPath)) {
|
if (existsSync(resolvedPath)) {
|
||||||
|
|||||||
Generated
+26
@@ -44,12 +44,17 @@
|
|||||||
},
|
},
|
||||||
"js/resolc": {
|
"js/resolc": {
|
||||||
"name": "@parity/resolc",
|
"name": "@parity/resolc",
|
||||||
|
<<<<<<< Updated upstream
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
|
=======
|
||||||
|
"version": "0.1.0-dev.16",
|
||||||
|
>>>>>>> Stashed changes
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"commander": "^13.1.0",
|
"commander": "^13.1.0",
|
||||||
"package-json": "^10.0.1",
|
"package-json": "^10.0.1",
|
||||||
|
"resolve-pkg": "^2.0.0",
|
||||||
"solc": ">=0.8.0 <=0.8.30"
|
"solc": ">=0.8.0 <=0.8.30"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -5601,6 +5606,27 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/resolve-pkg": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve-pkg/-/resolve-pkg-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-+1lzwXehGCXSeryaISr6WujZzowloigEofRB+dj75y9RRa/obVcYgbHJd53tdYw8pvZj8GojXaaENws8Ktw/hQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"resolve-from": "^5.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/resolve-pkg/node_modules/resolve-from": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/resolve.exports": {
|
"node_modules/resolve.exports": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.3.tgz",
|
||||||
|
|||||||
Reference in New Issue
Block a user