diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-11-23 21:05:40 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-12-03 19:09:28 +0800 |
commit | 5b0746a8efdad0250897ef255ea9fab7bd14deb5 (patch) | |
tree | 3b9e6926c90374c7c21c051cb574adaca206a3f8 /packages/sol-resolver/src/resolvers/npm_resolver.ts | |
parent | 0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4 (diff) | |
download | dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar.gz dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar.bz2 dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar.lz dexon-sol-tools-5b0746a8efdad0250897ef255ea9fab7bd14deb5.tar.xz 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/src/resolvers/npm_resolver.ts')
-rw-r--r-- | packages/sol-resolver/src/resolvers/npm_resolver.ts | 13 |
1 files changed, 11 insertions, 2 deletions
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 { |