aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts')
-rw-r--r--packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts15
1 files changed, 11 insertions, 4 deletions
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,