aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-resolver/src')
-rw-r--r--packages/sol-resolver/src/globals.d.ts7
-rw-r--r--packages/sol-resolver/src/index.ts10
-rw-r--r--packages/sol-resolver/src/resolvers/enumerable_resolver.ts7
-rw-r--r--packages/sol-resolver/src/resolvers/fallthrough_resolver.ts21
-rw-r--r--packages/sol-resolver/src/resolvers/fs_resolver.ts18
-rw-r--r--packages/sol-resolver/src/resolvers/name_resolver.ts66
-rw-r--r--packages/sol-resolver/src/resolvers/npm_resolver.ts42
-rw-r--r--packages/sol-resolver/src/resolvers/relative_fs_resolver.ts23
-rw-r--r--packages/sol-resolver/src/resolvers/resolver.ts14
-rw-r--r--packages/sol-resolver/src/resolvers/spy_resolver.ts25
-rw-r--r--packages/sol-resolver/src/resolvers/url_resolver.ts18
-rw-r--r--packages/sol-resolver/src/types.ts9
12 files changed, 0 insertions, 260 deletions
diff --git a/packages/sol-resolver/src/globals.d.ts b/packages/sol-resolver/src/globals.d.ts
deleted file mode 100644
index e799b3529..000000000
--- a/packages/sol-resolver/src/globals.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-// tslint:disable:completed-docs
-declare module '*.json' {
- const json: any;
- /* tslint:disable */
- export default json;
- /* tslint:enable */
-}
diff --git a/packages/sol-resolver/src/index.ts b/packages/sol-resolver/src/index.ts
deleted file mode 100644
index f55aca070..000000000
--- a/packages/sol-resolver/src/index.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-export { ContractSource, ContractSources } from './types';
-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 { SpyResolver } from './resolvers/spy_resolver';
-export { EnumerableResolver } from './resolvers/enumerable_resolver';
-export { Resolver } from './resolvers/resolver';
diff --git a/packages/sol-resolver/src/resolvers/enumerable_resolver.ts b/packages/sol-resolver/src/resolvers/enumerable_resolver.ts
deleted file mode 100644
index 0efa43e7c..000000000
--- a/packages/sol-resolver/src/resolvers/enumerable_resolver.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-export abstract class EnumerableResolver extends Resolver {
- public abstract getAll(): ContractSource[];
-}
diff --git a/packages/sol-resolver/src/resolvers/fallthrough_resolver.ts b/packages/sol-resolver/src/resolvers/fallthrough_resolver.ts
deleted file mode 100644
index 338f334f4..000000000
--- a/packages/sol-resolver/src/resolvers/fallthrough_resolver.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import * as _ from 'lodash';
-
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-export class FallthroughResolver extends Resolver {
- private readonly _resolvers: Resolver[] = [];
- public appendResolver(resolver: Resolver): void {
- this._resolvers.push(resolver);
- }
- public resolveIfExists(importPath: string): ContractSource | undefined {
- for (const resolver of this._resolvers) {
- const contractSourceIfExists = resolver.resolveIfExists(importPath);
- if (!_.isUndefined(contractSourceIfExists)) {
- return contractSourceIfExists;
- }
- }
- return undefined;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/fs_resolver.ts b/packages/sol-resolver/src/resolvers/fs_resolver.ts
deleted file mode 100644
index 248fa405e..000000000
--- a/packages/sol-resolver/src/resolvers/fs_resolver.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import * as fs from 'fs';
-import * as path from 'path';
-
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-export class FSResolver extends Resolver {
- // tslint:disable-next-line:prefer-function-over-method
- public resolveIfExists(importPath: string): ContractSource | undefined {
- if (fs.existsSync(importPath) && fs.lstatSync(importPath).isFile()) {
- const fileContent = fs.readFileSync(importPath).toString();
- const absolutePath = path.resolve(importPath);
- return { source: fileContent, path: importPath, absolutePath } as any;
- }
- return undefined;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/name_resolver.ts b/packages/sol-resolver/src/resolvers/name_resolver.ts
deleted file mode 100644
index aee326fb7..000000000
--- a/packages/sol-resolver/src/resolvers/name_resolver.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import * as fs from 'fs';
-import * as path from 'path';
-
-import { ContractSource } from '../types';
-
-import { EnumerableResolver } from './enumerable_resolver';
-
-const SOLIDITY_FILE_EXTENSION = '.sol';
-
-export class NameResolver extends EnumerableResolver {
- private readonly _contractsDir: string;
- constructor(contractsDir: string) {
- super();
- this._contractsDir = contractsDir;
- }
- public resolveIfExists(lookupContractName: string): ContractSource | undefined {
- let contractSource: ContractSource | undefined;
- const onFile = (filePath: string) => {
- const contractName = path.basename(filePath, SOLIDITY_FILE_EXTENSION);
- if (contractName === lookupContractName) {
- const absoluteContractPath = path.join(this._contractsDir, filePath);
- const source = fs.readFileSync(absoluteContractPath).toString();
- contractSource = { source, path: filePath, absolutePath: absoluteContractPath };
- return true;
- }
- return undefined;
- };
- this._traverseContractsDir(this._contractsDir, onFile);
- return contractSource;
- }
- public getAll(): ContractSource[] {
- const contractSources: ContractSource[] = [];
- const onFile = (filePath: string) => {
- const absoluteContractPath = path.join(this._contractsDir, filePath);
- const source = fs.readFileSync(absoluteContractPath).toString();
- const contractSource = { source, path: filePath, absolutePath: absoluteContractPath };
- contractSources.push(contractSource);
- };
- this._traverseContractsDir(this._contractsDir, onFile);
- return contractSources;
- }
- // tslint:disable-next-line:prefer-function-over-method
- private _traverseContractsDir(dirPath: string, onFile: (filePath: string) => true | void): boolean {
- let dirContents: string[] = [];
- try {
- dirContents = fs.readdirSync(dirPath);
- } catch (err) {
- throw new Error(`No directory found at ${dirPath}`);
- }
- for (const fileName of dirContents) {
- const absoluteEntryPath = path.join(dirPath, fileName);
- const isDirectory = fs.lstatSync(absoluteEntryPath).isDirectory();
- const entryPath = path.relative(this._contractsDir, absoluteEntryPath);
- let isComplete;
- if (isDirectory) {
- isComplete = this._traverseContractsDir(absoluteEntryPath, onFile);
- } else if (fileName.endsWith(SOLIDITY_FILE_EXTENSION)) {
- isComplete = onFile(entryPath);
- }
- if (isComplete) {
- return isComplete;
- }
- }
- return false;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/npm_resolver.ts b/packages/sol-resolver/src/resolvers/npm_resolver.ts
deleted file mode 100644
index 3c1d09557..000000000
--- a/packages/sol-resolver/src/resolvers/npm_resolver.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import * as fs from 'fs';
-import * as _ from 'lodash';
-import * as path from 'path';
-
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-export class NPMResolver extends Resolver {
- private readonly _packagePath: string;
- constructor(packagePath: string) {
- super();
- this._packagePath = packagePath;
- }
- public resolveIfExists(importPath: string): ContractSource | undefined {
- if (!importPath.startsWith('/')) {
- let packageName;
- let packageScopeIfExists;
- let other;
- if (_.startsWith(importPath, '@')) {
- [packageScopeIfExists, packageName, ...other] = importPath.split('/');
- } else {
- [packageName, ...other] = importPath.split('/');
- }
- const pathWithinPackage = path.join(...other);
- let currentPath = this._packagePath;
- const ROOT_PATH = '/';
- while (currentPath !== ROOT_PATH) {
- const packagePath = _.isUndefined(packageScopeIfExists)
- ? packageName
- : path.join(packageScopeIfExists, packageName);
- const lookupPath = path.join(currentPath, 'node_modules', packagePath, pathWithinPackage);
- if (fs.existsSync(lookupPath) && fs.lstatSync(lookupPath).isFile()) {
- const fileContent = fs.readFileSync(lookupPath).toString();
- return { source: fileContent, path: importPath, absolutePath: lookupPath };
- }
- currentPath = path.dirname(currentPath);
- }
- }
- return undefined;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts b/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts
deleted file mode 100644
index cfff145f9..000000000
--- a/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import * as fs from 'fs';
-import * as path from 'path';
-
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-export class RelativeFSResolver extends Resolver {
- private readonly _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.resolve(path.join(this._contractsDir, importPath));
- if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
- const fileContent = fs.readFileSync(filePath).toString();
- return { source: fileContent, path: importPath, absolutePath: filePath };
- }
- return undefined;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/resolver.ts b/packages/sol-resolver/src/resolvers/resolver.ts
deleted file mode 100644
index 7edc9a85d..000000000
--- a/packages/sol-resolver/src/resolvers/resolver.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import * as _ from 'lodash';
-
-import { ContractSource } from '../types';
-
-export abstract class Resolver {
- public abstract resolveIfExists(importPath: string): ContractSource | undefined;
- public resolve(importPath: string): ContractSource {
- const contractSourceIfExists = this.resolveIfExists(importPath);
- if (_.isUndefined(contractSourceIfExists)) {
- throw new Error(`Failed to resolve ${importPath}`);
- }
- return contractSourceIfExists;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/spy_resolver.ts b/packages/sol-resolver/src/resolvers/spy_resolver.ts
deleted file mode 100644
index 5582d771a..000000000
--- a/packages/sol-resolver/src/resolvers/spy_resolver.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import * as _ from 'lodash';
-
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-/**
- * This resolver is a passthrough proxy to any resolver that records all the resolved contracts sources.
- * You can access them later using the `resolvedContractSources` public field.
- */
-export class SpyResolver extends Resolver {
- public resolvedContractSources: ContractSource[] = [];
- private readonly _resolver: Resolver;
- constructor(resolver: Resolver) {
- super();
- this._resolver = resolver;
- }
- public resolveIfExists(importPath: string): ContractSource | undefined {
- const contractSourceIfExists = this._resolver.resolveIfExists(importPath);
- if (!_.isUndefined(contractSourceIfExists)) {
- this.resolvedContractSources.push(contractSourceIfExists);
- }
- return contractSourceIfExists;
- }
-}
diff --git a/packages/sol-resolver/src/resolvers/url_resolver.ts b/packages/sol-resolver/src/resolvers/url_resolver.ts
deleted file mode 100644
index ef300e6db..000000000
--- a/packages/sol-resolver/src/resolvers/url_resolver.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import * as fs from 'fs';
-
-import { ContractSource } from '../types';
-
-import { Resolver } from './resolver';
-
-export class URLResolver extends Resolver {
- // tslint:disable-next-line:prefer-function-over-method
- public resolveIfExists(importPath: string): ContractSource | undefined {
- const FILE_URL_PREXIF = 'file://';
- if (importPath.startsWith(FILE_URL_PREXIF)) {
- const filePath = importPath.substr(FILE_URL_PREXIF.length);
- const fileContent = fs.readFileSync(filePath).toString();
- return { source: fileContent, path: importPath, absolutePath: filePath };
- }
- return undefined;
- }
-}
diff --git a/packages/sol-resolver/src/types.ts b/packages/sol-resolver/src/types.ts
deleted file mode 100644
index b4ba164c8..000000000
--- a/packages/sol-resolver/src/types.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export interface ContractSource {
- source: string;
- path: string;
- absolutePath: string;
-}
-
-export interface ContractSources {
- [key: string]: ContractSource;
-}