aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-resolver')
-rw-r--r--packages/sol-resolver/CHANGELOG.json18
-rw-r--r--packages/sol-resolver/CHANGELOG.md8
-rw-r--r--packages/sol-resolver/README.md67
-rw-r--r--packages/sol-resolver/package.json13
-rw-r--r--packages/sol-resolver/src/index.ts1
-rw-r--r--packages/sol-resolver/src/resolvers/name_resolver.ts13
-rw-r--r--packages/sol-resolver/src/resolvers/relative_fs_resolver.ts26
7 files changed, 136 insertions, 10 deletions
diff --git a/packages/sol-resolver/CHANGELOG.json b/packages/sol-resolver/CHANGELOG.json
index b17ba62e9..0126fa170 100644
--- a/packages/sol-resolver/CHANGELOG.json
+++ b/packages/sol-resolver/CHANGELOG.json
@@ -1,5 +1,23 @@
[
{
+ "timestamp": 1525477860,
+ "version": "0.0.4",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1525428773,
+ "version": "0.0.3",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"timestamp": 1524044013,
"version": "0.0.2",
"changes": [
diff --git a/packages/sol-resolver/CHANGELOG.md b/packages/sol-resolver/CHANGELOG.md
index 0fe7647aa..4780544fa 100644
--- a/packages/sol-resolver/CHANGELOG.md
+++ b/packages/sol-resolver/CHANGELOG.md
@@ -5,6 +5,14 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v0.0.4 - _May 5, 2018_
+
+ * Dependencies updated
+
+## v0.0.3 - _May 4, 2018_
+
+ * Dependencies updated
+
## v0.0.2 - _April 18, 2018_
* Dependencies updated
diff --git a/packages/sol-resolver/README.md b/packages/sol-resolver/README.md
new file mode 100644
index 000000000..8487947f0
--- /dev/null
+++ b/packages/sol-resolver/README.md
@@ -0,0 +1,67 @@
+## @0xproject/sol-resolver
+
+A Solidity import resolver used by [sol-compiler](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-compiler).
+
+## Installation
+
+```bash
+yarn add @0xproject/sol-resolver
+```
+
+**Import**
+
+```javascript
+import { Resolver } from '@0xproject/sol-resolver';
+```
+
+or
+
+```javascript
+var Resolver = require('@0xproject/sol-resolver').Resolver;
+```
+
+## Contributing
+
+We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
+
+Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
+
+### Install dependencies
+
+If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
+
+```bash
+yarn config set workspaces-experimental true
+```
+
+Then install dependencies
+
+```bash
+yarn install
+```
+
+### Build
+
+To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
+
+```bash
+PKG=@0xproject/sol-resolver yarn build
+```
+
+Or continuously rebuild on change:
+
+```bash
+PKG=@0xproject/sol-resolver yarn watch
+```
+
+### Clean
+
+```bash
+yarn clean
+```
+
+### Lint
+
+```bash
+yarn lint
+```
diff --git a/packages/sol-resolver/package.json b/packages/sol-resolver/package.json
index 4fdfd9421..ad42dfa6c 100644
--- a/packages/sol-resolver/package.json
+++ b/packages/sol-resolver/package.json
@@ -1,11 +1,14 @@
{
"name": "@0xproject/sol-resolver",
- "version": "0.0.2",
+ "version": "0.0.4",
+ "engines": {
+ "node" : ">=6.12"
+ },
"description": "Import resolver for smart contracts dependencies",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
- "build:watch": "tsc -w",
+ "watch": "tsc -w",
"build": "yarn clean && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib scripts",
"lint": "tslint --project .",
@@ -21,15 +24,15 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/resolver/README.md",
"devDependencies": {
- "@0xproject/monorepo-scripts": "^0.1.18",
- "@0xproject/tslint-config": "^0.4.16",
+ "@0xproject/monorepo-scripts": "^0.1.19",
+ "@0xproject/tslint-config": "^0.4.17",
"copyfiles": "^1.2.0",
"shx": "^0.2.2",
"tslint": "5.8.0",
"typescript": "2.7.1"
},
"dependencies": {
- "@0xproject/types": "^0.6.1",
+ "@0xproject/types": "^0.6.3",
"@0xproject/typescript-typings": "^0.0.3",
"lodash": "^4.17.4"
},
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..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(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(filePath).toString();
+ const absoluteContractPath = path.join(this._contractsDir, filePath);
+ const source = fs.readFileSync(absoluteContractPath).toString();
const contractSource = {
source,
path: filePath,
@@ -54,9 +56,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;
+ }
+}