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

Fix a bug when TruffleArtifactAdapter was incorrectly parsing the truffle config of the newest version #1654

Merged
merged 2 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": 1654
}
]
},
{
"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();
LogvinovLeon marked this conversation as resolved.
Show resolved Hide resolved
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