From 72b2a1c66fa9fb85ea8515645b97332eee204550 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 18 Apr 2018 22:22:39 +0200 Subject: Implement new artifacts format --- packages/sol-resolver/src/index.ts | 1 + .../sol-resolver/src/resolvers/name_resolver.ts | 11 ++++----- .../src/resolvers/relative_fs_resolver.ts | 26 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 packages/sol-resolver/src/resolvers/relative_fs_resolver.ts (limited to 'packages/sol-resolver') diff --git a/packages/sol-resolver/src/index.ts b/packages/sol-resolver/src/index.ts index cd6ec42ec..a86053259 100644 --- a/packages/sol-resolver/src/index.ts +++ b/packages/sol-resolver/src/index.ts @@ -3,6 +3,7 @@ export { FallthroughResolver } from './resolvers/fallthrough_resolver'; export { URLResolver } from './resolvers/url_resolver'; export { NPMResolver } from './resolvers/npm_resolver'; export { FSResolver } from './resolvers/fs_resolver'; +export { RelativeFSResolver } from './resolvers/relative_fs_resolver'; export { NameResolver } from './resolvers/name_resolver'; export { EnumerableResolver } from './resolvers/enumerable_resolver'; export { Resolver } from './resolvers/resolver'; diff --git a/packages/sol-resolver/src/resolvers/name_resolver.ts b/packages/sol-resolver/src/resolvers/name_resolver.ts index 6849b7610..a0bedab98 100644 --- a/packages/sol-resolver/src/resolvers/name_resolver.ts +++ b/packages/sol-resolver/src/resolvers/name_resolver.ts @@ -18,7 +18,7 @@ export class NameResolver extends EnumerableResolver { const onFile = (filePath: string) => { const contractName = path.basename(filePath, SOLIDITY_FILE_EXTENSION); if (contractName === lookupContractName) { - const source = fs.readFileSync(filePath).toString(); + const source = fs.readFileSync(path.join(this._contractsDir, filePath)).toString(); contractSource = { source, path: filePath, @@ -35,7 +35,7 @@ export class NameResolver extends EnumerableResolver { const contractSources: ContractSource[] = []; const onFile = (filePath: string) => { const contractName = path.basename(filePath, SOLIDITY_FILE_EXTENSION); - const source = fs.readFileSync(filePath).toString(); + const source = fs.readFileSync(path.join(this._contractsDir, filePath)).toString(); const contractSource = { source, path: filePath, @@ -54,9 +54,10 @@ export class NameResolver extends EnumerableResolver { throw new Error(`No directory found at ${dirPath}`); } for (const fileName of dirContents) { - const entryPath = path.join(dirPath, fileName); - const isDirectory = fs.lstatSync(entryPath).isDirectory(); - const isComplete = isDirectory ? this._traverseContractsDir(entryPath, onFile) : onFile(entryPath); + const absoluteEntryPath = path.join(dirPath, fileName); + const isDirectory = fs.lstatSync(absoluteEntryPath).isDirectory(); + const entryPath = path.relative(this._contractsDir, absoluteEntryPath); + const isComplete = isDirectory ? this._traverseContractsDir(absoluteEntryPath, onFile) : onFile(entryPath); if (isComplete) { return isComplete; } diff --git a/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts b/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts new file mode 100644 index 000000000..2317ede83 --- /dev/null +++ b/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts @@ -0,0 +1,26 @@ +import * as fs from 'fs'; +import * as path from 'path'; + +import { ContractSource } from '../types'; + +import { Resolver } from './resolver'; + +export class RelativeFSResolver extends Resolver { + private _contractsDir: string; + constructor(contractsDir: string) { + super(); + this._contractsDir = contractsDir; + } + // tslint:disable-next-line:prefer-function-over-method + public resolveIfExists(importPath: string): ContractSource | undefined { + const filePath = path.join(this._contractsDir, importPath); + if (fs.existsSync(filePath)) { + const fileContent = fs.readFileSync(filePath).toString(); + return { + source: fileContent, + path: importPath, + }; + } + return undefined; + } +} -- cgit v1.2.3 From 8eabc49e9d17925d5cce92cf9e1b3d65ba875f2d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 7 May 2018 14:06:00 +0200 Subject: Introduce a var --- packages/sol-resolver/src/resolvers/name_resolver.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/sol-resolver') diff --git a/packages/sol-resolver/src/resolvers/name_resolver.ts b/packages/sol-resolver/src/resolvers/name_resolver.ts index a0bedab98..76bed802e 100644 --- a/packages/sol-resolver/src/resolvers/name_resolver.ts +++ b/packages/sol-resolver/src/resolvers/name_resolver.ts @@ -18,7 +18,8 @@ export class NameResolver extends EnumerableResolver { const onFile = (filePath: string) => { const contractName = path.basename(filePath, SOLIDITY_FILE_EXTENSION); if (contractName === lookupContractName) { - const source = fs.readFileSync(path.join(this._contractsDir, filePath)).toString(); + const absoluteContractPath = path.join(this._contractsDir, filePath); + const source = fs.readFileSync(absoluteContractPath).toString(); contractSource = { source, path: filePath, @@ -35,7 +36,8 @@ export class NameResolver extends EnumerableResolver { const contractSources: ContractSource[] = []; const onFile = (filePath: string) => { const contractName = path.basename(filePath, SOLIDITY_FILE_EXTENSION); - const source = fs.readFileSync(path.join(this._contractsDir, filePath)).toString(); + const absoluteContractPath = path.join(this._contractsDir, filePath); + const source = fs.readFileSync(absoluteContractPath).toString(); const contractSource = { source, path: filePath, -- cgit v1.2.3