Skip to content

add config to solcLoader to allow resolution of missing imports#9

Open
mikec wants to merge 1 commit intoSilentCicero:masterfrom
levelkdev:find-imports
Open

add config to solcLoader to allow resolution of missing imports#9
mikec wants to merge 1 commit intoSilentCicero:masterfrom
levelkdev:find-imports

Conversation

@mikec
Copy link
Copy Markdown

@mikec mikec commented Nov 27, 2017

@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']
}

adds `findImports` and `importResolves` options to solcLoader config

`findImports` can be used to define a callback function that will be executed when solc compiler encounters a missing import path

`importResolves` can be used to define an array of fallback paths for missing imports
@SilentCicero
Copy link
Copy Markdown
Owner

SilentCicero commented Nov 27, 2017 via email

@SilentCicero
Copy link
Copy Markdown
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants