diff options
Diffstat (limited to 'packages/sol-resolver/src/resolvers')
-rw-r--r-- | packages/sol-resolver/src/resolvers/npm_resolver.ts | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/packages/sol-resolver/src/resolvers/npm_resolver.ts b/packages/sol-resolver/src/resolvers/npm_resolver.ts index d9377989f..3c1d09557 100644 --- a/packages/sol-resolver/src/resolvers/npm_resolver.ts +++ b/packages/sol-resolver/src/resolvers/npm_resolver.ts @@ -8,11 +8,9 @@ import { Resolver } from './resolver'; export class NPMResolver extends Resolver { private readonly _packagePath: string; - private readonly _workspacePath: string; - constructor(packagePath: string, workspacePath: string = '/') { + constructor(packagePath: string) { super(); this._packagePath = packagePath; - this._workspacePath = workspacePath; } public resolveIfExists(importPath: string): ContractSource | undefined { if (!importPath.startsWith('/')) { @@ -25,11 +23,9 @@ export class NPMResolver extends Resolver { [packageName, ...other] = importPath.split('/'); } const pathWithinPackage = path.join(...other); - for ( - let currentPath = this._packagePath; - currentPath.includes(this._workspacePath); - currentPath = path.dirname(currentPath) - ) { + let currentPath = this._packagePath; + const ROOT_PATH = '/'; + while (currentPath !== ROOT_PATH) { const packagePath = _.isUndefined(packageScopeIfExists) ? packageName : path.join(packageScopeIfExists, packageName); @@ -38,6 +34,7 @@ export class NPMResolver extends Resolver { const fileContent = fs.readFileSync(lookupPath).toString(); return { source: fileContent, path: importPath, absolutePath: lookupPath }; } + currentPath = path.dirname(currentPath); } } return undefined; |