Skip to content

Commit d2c5812

Browse files
ioedeveloperAniket-Engg
authored andcommitted
Add support for custom solidity config file
1 parent 6637de6 commit d2c5812

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,15 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
436436
let externalCompType
437437
if (hhCompilation) externalCompType = 'hardhat'
438438
else if (truffleCompilation) externalCompType = 'truffle'
439-
compileTabLogic.runCompiler(externalCompType)
439+
compileTabLogic.runCompiler(externalCompType).catch((error) => {
440+
tooltip(error.message)
441+
compileIcon.current.classList.remove('remixui_bouncingIcon')
442+
compileIcon.current.classList.remove('remixui_spinningIcon')
443+
// @ts-ignore
444+
props.setCompileErrors({ [currentFile]: { error: error.message } })
445+
// @ts-ignore
446+
props.setBadgeStatus({ [currentFile]: { key: 1, title: error.message, type: 'error' } })
447+
})
440448
}
441449

442450
const compileAndRun = () => {
@@ -448,7 +456,15 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
448456
if (hhCompilation) externalCompType = 'hardhat'
449457
else if (truffleCompilation) externalCompType = 'truffle'
450458
api.runScriptAfterCompilation(currentFile)
451-
compileTabLogic.runCompiler(externalCompType)
459+
compileTabLogic.runCompiler(externalCompType).catch((error) => {
460+
tooltip(error.message)
461+
compileIcon.current.classList.remove('remixui_bouncingIcon')
462+
compileIcon.current.classList.remove('remixui_spinningIcon')
463+
// @ts-ignore
464+
props.setCompileErrors({ [currentFile]: { error: error.message } })
465+
// @ts-ignore
466+
props.setBadgeStatus({ [currentFile]: { key: 1, title: error.message, type: 'error' } })
467+
})
452468
}
453469

454470
const _updateVersionSelector = (version, customUrl = '', setQueryParameter = true) => {

libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,28 @@ export class CompileTabLogic {
117117
const config = JSON.parse(configContent)
118118

119119
if (config['solidity-compiler']) {
120-
this.compiler.set('configFileContent', config['solidity-compiler'])
120+
if (typeof config['solidity-compiler'] === 'string') {
121+
if (config['solidity-compiler'].endsWith('.json')) {
122+
const configFilePath = config['solidity-compiler']
123+
const fileExists = await this.api.fileExists(configFilePath)
124+
125+
if (fileExists) {
126+
try {
127+
const fileContent = await this.api.readFile(configFilePath)
128+
config['solidity-compiler'] = JSON.parse(fileContent)
129+
this.compiler.set('configFileContent', config['solidity-compiler'])
130+
} catch (e) {
131+
throw new Error('Configuration file specified in remix.config.json contains invalid configuration')
132+
}
133+
} else {
134+
throw new Error('Configuration file specified in remix.config.json does not exist')
135+
}
136+
} else {
137+
throw new Error('Configuration file specified in remix.config.json is not a valid JSON file')
138+
}
139+
} else {
140+
this.compiler.set('configFileContent', config['solidity-compiler'])
141+
}
121142
} else {
122143
this.compiler.set('configFileContent', JSON.parse(configFileContent))
123144
this.api.writeFile(remixConfigPath, JSON.stringify({ ...config, 'solidity-compiler': JSON.parse(configFileContent) }, null, 2))

libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
285285
updateCurrentVersion={updateCurrentVersion}
286286
configurationSettings={configurationSettings}
287287
solJsonBinData={state.solJsonBinData}
288+
setCompileErrors={setCompileErrors}
289+
setBadgeStatus={setBadgeStatus}
288290
/>
289291
{/* "compileErrors[currentFile]['contracts']" field will not be there in case of compilation errors */}
290292
{contractsFile && contractsFile[currentFile] && contractsFile[currentFile].contractsDetails

libs/remix-ui/solidity-compiler/src/lib/types/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export interface CompilerContainerProps {
2121
compiledFileName: string,
2222
updateCurrentVersion: any,
2323
configurationSettings: ConfigurationSettings,
24-
solJsonBinData: iSolJsonBinData
24+
solJsonBinData: iSolJsonBinData,
25+
setCompileErrors: (errors: Record<string, CompileErrors>) => void
26+
setBadgeStatus: (badgeStatus: Record<string, { key: string; title?: string; type?: string }>) => void
2527
}
2628

2729
export interface ContractSelectionProps {

0 commit comments

Comments
 (0)