diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-12-04 20:53:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-04 20:53:15 +0800 |
commit | 79f5e36edbd8a4483aac46032092dece95bb0b4c (patch) | |
tree | b9c86a0badb2f1e82efa6354eede587368449a87 /packages/sol-resolver | |
parent | a1e985a1cac46ecbc54c7ef5b846fb5faf2bede2 (diff) | |
parent | a87276341356e31e0712f42ada00ed5d55707a6b (diff) | |
download | dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.tar dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.tar.gz dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.tar.bz2 dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.tar.lz dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.tar.xz dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.tar.zst dexon-0x-contracts-79f5e36edbd8a4483aac46032092dece95bb0b4c.zip |
Merge pull request #1311 from 0xProject/feature/contracts-monorepo-2
Contracts monorepo II
Diffstat (limited to 'packages/sol-resolver')
-rw-r--r-- | packages/sol-resolver/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/sol-resolver/src/resolvers/npm_resolver.ts | 15 |
2 files changed, 22 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..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 { |