diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-21 22:28:39 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-21 22:28:39 +0800 |
commit | ce65ac0c1c34913027ff4ea9e512d01a5e20abdf (patch) | |
tree | 03ce75a4176abbf31e08116946578f23f64352a3 | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-0x-contracts-ce65ac0c1c34913027ff4ea9e512d01a5e20abdf.tar.gz dexon-0x-contracts-ce65ac0c1c34913027ff4ea9e512d01a5e20abdf.tar.zst dexon-0x-contracts-ce65ac0c1c34913027ff4ea9e512d01a5e20abdf.zip |
SolCompilerArtifactsAdapter now uses SolResolver under the hood which allows to resolve NPM dependencies properly
-rw-r--r-- | packages/sol-tracing-utils/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/sol-tracing-utils/package.json | 1 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts | 15 |
3 files changed, 21 insertions, 4 deletions
diff --git a/packages/sol-tracing-utils/CHANGELOG.json b/packages/sol-tracing-utils/CHANGELOG.json index ef96dc69b..3df9ffc16 100644 --- a/packages/sol-tracing-utils/CHANGELOG.json +++ b/packages/sol-tracing-utils/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "6.0.0", + "changes": [ + { + "note": "`SolCompilerArtifactsAdapter` now uses `SolResolver` under the hood which allows to resolve `NPM` dependencies properly", + "pr": "TODO" + } + ] + }, + { "version": "5.0.0", "changes": [ { diff --git a/packages/sol-tracing-utils/package.json b/packages/sol-tracing-utils/package.json index cabb752d2..4b0fff222 100644 --- a/packages/sol-tracing-utils/package.json +++ b/packages/sol-tracing-utils/package.json @@ -44,6 +44,7 @@ "dependencies": { "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", + "@0x/sol-resolver": "^1.2.3", "@0x/subproviders": "^2.1.11", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", diff --git a/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts b/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts index d52587f2c..4798f20a6 100644 --- a/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts +++ b/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts @@ -1,3 +1,4 @@ +import { FallthroughResolver, FSResolver, NPMResolver, RelativeFSResolver, URLResolver } from '@0x/sol-resolver'; import { logUtils } from '@0x/utils'; import { CompilerOptions, ContractArtifact } from 'ethereum-types'; import * as fs from 'fs'; @@ -14,6 +15,7 @@ const CONFIG_FILE = 'compiler.json'; export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter { private readonly _artifactsPath: string; private readonly _sourcesPath: string; + private readonly _resolver: FallthroughResolver; /** * Instantiates a SolCompilerArtifactAdapter * @param artifactsPath Path to your artifacts directory @@ -32,6 +34,12 @@ export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter { throw new Error(`contractsDir not found in ${CONFIG_FILE}`); } this._sourcesPath = (sourcesPath || config.contractsDir) as string; + this._resolver = new FallthroughResolver(); + this._resolver.appendResolver(new URLResolver()); + const packagePath = path.resolve(''); + this._resolver.appendResolver(new NPMResolver(packagePath)); + this._resolver.appendResolver(new RelativeFSResolver(this._sourcesPath)); + this._resolver.appendResolver(new FSResolver()); } public async collectContractsDataAsync(): Promise<ContractData[]> { const artifactsGlob = `${this._artifactsPath}/**/*.json`; @@ -46,10 +54,9 @@ export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter { const sources: Sources = {}; const sourceCodes: SourceCodes = {}; _.map(artifact.sources, (value: { id: number }, relativeFilePath: string) => { - const filePath = path.resolve(this._sourcesPath, relativeFilePath); - const fileContent = fs.readFileSync(filePath).toString(); - sources[value.id] = filePath; - sourceCodes[value.id] = fileContent; + const source = this._resolver.resolve(relativeFilePath); + sources[value.id] = source.absolutePath; + sourceCodes[value.id] = source.source; }); const contractData = { sourceCodes, |