aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-11-23 21:05:40 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-12-03 19:09:28 +0800
commit5b0746a8efdad0250897ef255ea9fab7bd14deb5 (patch)
tree3b9e6926c90374c7c21c051cb574adaca206a3f8 /packages/sol-resolver
parent0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4 (diff)
downloaddexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar.gz
dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar.zst
dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.zip
Add support for scoped packages resolving to NPMResoler
Diffstat (limited to 'packages/sol-resolver')
-rw-r--r--packages/sol-resolver/CHANGELOG.json9
-rw-r--r--packages/sol-resolver/src/resolvers/npm_resolver.ts13
2 files changed, 20 insertions, 2 deletions
diff --git a/packages/sol-resolver/CHANGELOG.json b/packages/sol-resolver/CHANGELOG.json
index fdfb4009b..4c9e612d7 100644
--- a/packages/sol-resolver/CHANGELOG.json
+++ b/packages/sol-resolver/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "1.1.0",
+ "changes": [
+ {
+ "note": "NPMResolver now supports scoped packages",
+ "pr": 1311
+ }
+ ]
+ },
+ {
"timestamp": 1542821676,
"version": "1.0.17",
"changes": [
diff --git a/packages/sol-resolver/src/resolvers/npm_resolver.ts b/packages/sol-resolver/src/resolvers/npm_resolver.ts
index a2df0dcad..505362c88 100644
--- a/packages/sol-resolver/src/resolvers/npm_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/npm_resolver.ts
@@ -1,4 +1,5 @@
import * as fs from 'fs';
+import * as _ from 'lodash';
import * as path from 'path';
import { ContractSource } from '../types';
@@ -13,12 +14,20 @@ export class NPMResolver extends Resolver {
}
public resolveIfExists(importPath: string): ContractSource | undefined {
if (!importPath.startsWith('/')) {
- const [packageName, ...other] = importPath.split('/');
+ let packageName;
+ let packageScope;
+ let other;
+ if (importPath.startsWith('@')) {
+ [packageScope, 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 lookupPath = path.join(currentPath, 'node_modules', packageName, pathWithinPackage);
+ const packagePath = _.isUndefined(packageScope) ? packageName : path.join(packageScope, 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 {