diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-12-06 04:33:34 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-12-06 04:33:34 +0800 |
commit | f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac (patch) | |
tree | e1b93ec089efa842372b885d51046c845728dd75 /packages/sol-resolver/src | |
parent | 5c29b918df4ac8b0f7914e8da10fa1ae530ff4e8 (diff) | |
parent | 08eb0b91b6d0f0dc90ae920a18ca5dd080bf235c (diff) | |
download | dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.tar dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.tar.gz dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.tar.bz2 dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.tar.lz dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.tar.xz dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.tar.zst dexon-sol-tools-f9e73d2a6f6b7c3126c0c10286c2f79c4fd2a7ac.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/website/instant-configurator
Diffstat (limited to 'packages/sol-resolver/src')
-rw-r--r-- | packages/sol-resolver/src/resolvers/npm_resolver.ts | 15 |
1 files changed, 13 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..eeb2b5493 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,22 @@ export class NPMResolver extends Resolver { } public resolveIfExists(importPath: string): ContractSource | undefined { if (!importPath.startsWith('/')) { - const [packageName, ...other] = importPath.split('/'); + 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 lookupPath = path.join(currentPath, 'node_modules', packageName, pathWithinPackage); + 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 { |