ethdeploy
ethdeploy copied to clipboard
add config to solcLoader to allow resolution of missing imports
@SilentCicero, love the ethdeploy project!
I ran into an issue porting an existing project over to ethdeploy from truffle. I had some import paths in my .sol files referencing zeppelin-solidity/contracts/... where zeppelin-solidity is a project dependency and exists in node_modules. Truffle was somehow handling the resolution to node_modules automatically.
I added some additional config options to solcLoader to support the same path resolution for ethdeploy:
findImports can be used to define a callback function that will be executed when solc compiler encounters a missing import path
for example:
{
test: /\.(sol)$/,
loader: 'ethdeploy-solc-loader',
optimize: 1,
filterFilenames: true,
filterWarnings: true,
findImports: (path) => {
const contents = fs.readFileSync(`node_modules/${path}`).toString()
if (contents) {
return { contents }
} else {
return { error: 'File not found' }
}
}
}
importResolves can be used to define an array of fallback paths for missing imports
for example:
{
test: /\.(sol)$/,
loader: 'ethdeploy-solc-loader',
optimize: 1,
filterFilenames: true,
filterWarnings: true,
importResolves: ['node_modules']
}
Thanks! And nice, I will review tomorrow
Sent from my iPhone
On Nov 27, 2017, at 5:41 AM, Mike Calvanese [email protected] wrote:
@SilentCicero, love the ethdeploy project!
I ran into an issue porting an existing project over to ethdeploy from truffle. I had some import paths in my .sol files referencing zeppelin-solidity/contracts/... where zeppelin-solidity is a project dependency and exists in node_modules. Truffle was somehow handling the resolution to node_modules automatically.
I added some additional config options to solcLoader to support the same path resolution for ethdeploy:
findImports can be used to define a callback function that will be executed when solc compiler encounters a missing import path
for example:
{ test: /.(sol)$/, loader: 'ethdeploy-solc-loader', optimize: 1, filterFilenames: true, filterWarnings: true, findImports: (path) => { const contents = fs.readFileSync(
node_modules/${path}).toString() if (contents) { return { contents } } else { return { error: 'File not found' } } } } importResolves can be used to define an array of fallback paths for missing importsfor example:
{ test: /.(sol)$/, loader: 'ethdeploy-solc-loader', optimize: 1, filterFilenames: true, filterWarnings: true, importResolves: ['node_modules'] } You can view, comment on, or merge this pull request online at:
https://github.com/SilentCicero/ethdeploy/pull/9
Commit Summary
add config to solcLoader to allow resolution of missing imports File Changes
M src/loaders/solc/index.js (22) Patch Links:
https://github.com/SilentCicero/ethdeploy/pull/9.patch https://github.com/SilentCicero/ethdeploy/pull/9.diff — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@mikec so I think I would make this another loader or can this be browserified somehow? My only worry is keeping the solc loader as something that can be eventually used in browser also.
Any thoughts on this?
I'm thinking this could be solc-complex, a slightly separate more advanced loader.