-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for standardised import resolution (#72)
* Added resolver-engine functionality
- Loading branch information
1 parent
b0e9760
commit 8ce62d8
Showing
15 changed files
with
169 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {readFileContent} from '../utils'; | ||
import { ImportFile } from '@resolver-engine/imports'; | ||
|
||
export function findImports(libraryPath: string) { | ||
export function findImports(sources: ImportFile[]) { | ||
return (file: string) => { | ||
try { | ||
const libFile = path.join(libraryPath, file); | ||
if (fs.existsSync(file)) { | ||
return { contents: readFileContent(file) }; | ||
} else if (fs.existsSync(libFile)) { | ||
return { contents: readFileContent(libFile) }; | ||
} else { | ||
throw new Error(`File not found: ${file}`); | ||
} | ||
} catch (e) { | ||
return { error: e.message }; | ||
const result = sources.find((importFile) => importFile.url === file); | ||
if (result) { | ||
return {contents: result.source}; | ||
} | ||
return {error: `File not found: ${file}`}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import fs from 'fs-extra'; | ||
import {expect} from 'chai'; | ||
import {findImports} from '../../lib/compiler/findImports'; | ||
import {readFileContent} from '../../lib/utils'; | ||
import { ImportFile } from '@resolver-engine/imports'; | ||
|
||
describe('INTEGRATION: findImports', () => { | ||
before(async () => { | ||
await fs.mkdirp('/tmp/waffle/b'); | ||
await fs.writeFile('/tmp/waffle/b/b.sol', 'contents of b.sol'); | ||
}); | ||
|
||
after(async () => { | ||
await fs.remove('/tmp/waffle'); | ||
}); | ||
const DATA: ImportFile[] = [ | ||
{ | ||
url: '/tmp/waffle/b', | ||
source: 'content of b.sol', | ||
provider: 'unknown' | ||
}, | ||
{ | ||
url: 'test/projects/example/BasicToken.sol', | ||
source: readFileContent('test/projects/example/BasicToken.sol'), | ||
provider: 'unkown' | ||
} | ||
]; | ||
|
||
it('finds imports in source path', async () => { | ||
const contents = await readFileContent('test/projects/example/BasicToken.sol'); | ||
const result = findImports('/')('test/projects/example/BasicToken.sol'); | ||
expect(result).to.deep.equal({contents}); | ||
}); | ||
|
||
it('finds imports in library path', () => { | ||
const result = findImports('/tmp/waffle')('b/b.sol'); | ||
expect(result).to.deep.equal({contents: 'contents of b.sol'}); | ||
describe('INTEGRATION: findImports', () => { | ||
DATA.forEach((importFile) => { | ||
it(`correctly finds ${importFile.url}`, async () => { | ||
const result = findImports(DATA)(importFile.url); | ||
expect(result).to.be.deep.equal({contents: importFile.source}); | ||
}); | ||
}); | ||
|
||
it('findImports file not found', async () => { | ||
const result = findImports('/tmp/waffle')('random/nonexisting.sol'); | ||
const result = findImports(DATA)('random/nonexisting.sol'); | ||
expect(result).to.deep.equal({error: `File not found: random/nonexisting.sol`}); | ||
}); | ||
}); |
Oops, something went wrong.