aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-01-23 23:54:27 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-01-23 23:54:27 +0800
commite8d68dc07faa1c8daa59b2a3f1980328b2b49017 (patch)
treedbbcae9fbaeddb329556b78bba6ac2f9f1bbcc74 /packages/sol-resolver
parentef928aff31f09b368307548bd5a512b4212a0c95 (diff)
downloaddexon-0x-contracts-e8d68dc07faa1c8daa59b2a3f1980328b2b49017.tar.gz
dexon-0x-contracts-e8d68dc07faa1c8daa59b2a3f1980328b2b49017.tar.zst
dexon-0x-contracts-e8d68dc07faa1c8daa59b2a3f1980328b2b49017.zip
Implement docker as another backend for sol-compiler
Diffstat (limited to 'packages/sol-resolver')
-rw-r--r--packages/sol-resolver/src/resolvers/fs_resolver.ts4
-rw-r--r--packages/sol-resolver/src/resolvers/npm_resolver.ts13
2 files changed, 11 insertions, 6 deletions
diff --git a/packages/sol-resolver/src/resolvers/fs_resolver.ts b/packages/sol-resolver/src/resolvers/fs_resolver.ts
index 86128023d..248fa405e 100644
--- a/packages/sol-resolver/src/resolvers/fs_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/fs_resolver.ts
@@ -1,4 +1,5 @@
import * as fs from 'fs';
+import * as path from 'path';
import { ContractSource } from '../types';
@@ -9,7 +10,8 @@ export class FSResolver extends Resolver {
public resolveIfExists(importPath: string): ContractSource | undefined {
if (fs.existsSync(importPath) && fs.lstatSync(importPath).isFile()) {
const fileContent = fs.readFileSync(importPath).toString();
- return { source: fileContent, path: importPath, absolutePath: importPath };
+ const absolutePath = path.resolve(importPath);
+ return { source: fileContent, path: importPath, absolutePath } as any;
}
return undefined;
}
diff --git a/packages/sol-resolver/src/resolvers/npm_resolver.ts b/packages/sol-resolver/src/resolvers/npm_resolver.ts
index 3c1d09557..1c9e56957 100644
--- a/packages/sol-resolver/src/resolvers/npm_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/npm_resolver.ts
@@ -8,9 +8,11 @@ import { Resolver } from './resolver';
export class NPMResolver extends Resolver {
private readonly _packagePath: string;
- constructor(packagePath: string) {
+ private readonly _workspacePath: string;
+ constructor(packagePath: string, workspacePath: string) {
super();
this._packagePath = packagePath;
+ this._workspacePath = workspacePath;
}
public resolveIfExists(importPath: string): ContractSource | undefined {
if (!importPath.startsWith('/')) {
@@ -23,9 +25,11 @@ export class NPMResolver extends Resolver {
[packageName, ...other] = importPath.split('/');
}
const pathWithinPackage = path.join(...other);
- let currentPath = this._packagePath;
- const ROOT_PATH = '/';
- while (currentPath !== ROOT_PATH) {
+ for (
+ let currentPath = this._packagePath;
+ currentPath.includes(this._workspacePath);
+ currentPath = path.dirname(currentPath)
+ ) {
const packagePath = _.isUndefined(packageScopeIfExists)
? packageName
: path.join(packageScopeIfExists, packageName);
@@ -34,7 +38,6 @@ export class NPMResolver extends Resolver {
const fileContent = fs.readFileSync(lookupPath).toString();
return { source: fileContent, path: importPath, absolutePath: lookupPath };
}
- currentPath = path.dirname(currentPath);
}
}
return undefined;