Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Fix a bug when TruffleArtifactAdapter was incorrectly parsing the tru…
Browse files Browse the repository at this point in the history
…ffle config of the newest version
  • Loading branch information
LogvinovLeon committed Feb 27, 2019
1 parent 3f0db92 commit a749624
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/sol-tracing-utils/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "6.0.6",
"changes": [
{
"note": "Fix a bug when `TruffleArtifactAdapter` wasn't parsing solc config in the newest version of trufle",
"pr": 42
}
]
},
{
"timestamp": 1551220833,
"version": "6.0.5",
Expand Down
1 change: 1 addition & 0 deletions packages/sol-tracing-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"ethereumjs-util": "^5.1.1",
"ethers": "~4.0.4",
"glob": "^7.1.2",
"solc": "^0.5.2",
"istanbul": "^0.4.5",
"lodash": "^4.17.11",
"loglevel": "^1.6.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Compiler, CompilerOptions } from '@0x/sol-compiler';
import * as fs from 'fs';
import * as glob from 'glob';
import * as _ from 'lodash';
import * as path from 'path';
import * as solc from 'solc';

import { ContractData } from '../types';

Expand All @@ -10,8 +12,15 @@ import { SolCompilerArtifactAdapter } from './sol_compiler_artifact_adapter';

const DEFAULT_TRUFFLE_ARTIFACTS_DIR = './build/contracts';

interface TruffleSolcConfig {
version?: string;
settings?: solc.CompilerSettings;
}
interface TruffleConfig {
solc?: any;
solc?: TruffleSolcConfig;
compilers?: {
solc?: TruffleSolcConfig;
};
contracts_build_directory?: string;
}

Expand All @@ -32,7 +41,7 @@ export class TruffleArtifactAdapter extends AbstractArtifactAdapter {
const artifactsDir = '.0x-artifacts';
const contractsDir = path.join(this._projectRoot, 'contracts');
const truffleConfig = this._getTruffleConfig();
const solcConfig = truffleConfig.solc || {};
const solcConfig = this._getTruffleSolcSettings();
const truffleArtifactsDirectory = truffleConfig.contracts_build_directory || DEFAULT_TRUFFLE_ARTIFACTS_DIR;
this._assertSolidityVersionIsCorrect(truffleArtifactsDirectory);
const compilerOptions: CompilerOptions = {
Expand Down Expand Up @@ -70,6 +79,16 @@ export class TruffleArtifactAdapter extends AbstractArtifactAdapter {
);
}
}
private _getTruffleSolcSettings(): Partial<solc.CompilerSettings> {
const truffleConfig = this._getTruffleConfig();
if (!_.isUndefined(truffleConfig.solc)) {
return (truffleConfig as any).solc.settings;
} else if (!_.isUndefined((truffleConfig as any).compilers.solc)) {
return (truffleConfig as any).compilers.solc.settings;
} else {
return {};
}
}
private _assertSolidityVersionIsCorrect(truffleArtifactsDirectory: string): void {
const artifactsGlob = `${truffleArtifactsDirectory}/**/*.json`;
const artifactFileNames = glob.sync(artifactsGlob, { absolute: true });
Expand Down

0 comments on commit a749624

Please sign in to comment.