add remappings for Foundry project

pull/2590/head
Aniket-Engg 3 years ago committed by Aniket
parent 8130cc5e7c
commit 9b02b3785b
  1. 12
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  2. 6
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  3. 7
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  4. 1
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -33,6 +33,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
configurationSettings, configurationSettings,
isHardhatProject, isHardhatProject,
isTruffleProject, isTruffleProject,
isFoundryProject,
workspaceName, workspaceName,
configFilePath, configFilePath,
setConfigFilePath, setConfigFilePath,
@ -245,7 +246,16 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
if (filePath === '') filePath = defaultPath if (filePath === '') filePath = defaultPath
if (!filePath.endsWith('.json')) filePath = filePath + '.json' if (!filePath.endsWith('.json')) filePath = filePath + '.json'
await api.writeFile(filePath, configFileContent) let compilerConfig = configFileContent
if (isFoundryProject && !compilerConfig.includes('remappings')) {
let config = JSON.parse(compilerConfig)
config.settings.remappings = [
'ds-test/=lib/forge-std/lib/ds-test/src/',
'forge-std/=lib/forge-std/src/'
]
compilerConfig = JSON.stringify(config, null, '\t')
}
await api.writeFile(filePath, compilerConfig)
api.setAppParameter('configFilePath', filePath) api.setAppParameter('configFilePath', filePath)
setConfigFilePath(filePath) setConfigFilePath(filePath)
compileTabLogic.setConfigFilePath(filePath) compileTabLogic.setConfigFilePath(filePath)

@ -131,6 +131,12 @@ export class CompileTabLogic {
} else return false } else return false
} }
async isFoundryProject () {
if (this.api.getFileManagerMode() === 'localhost') {
return await this.api.fileExists('foundry.toml')
} else return false
}
runCompiler (externalCompType) { runCompiler (externalCompType) {
try { try {
if (this.api.getFileManagerMode() === 'localhost') { if (this.api.getFileManagerMode() === 'localhost') {

@ -13,6 +13,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const [state, setState] = useState({ const [state, setState] = useState({
isHardhatProject: false, isHardhatProject: false,
isTruffleProject: false, isTruffleProject: false,
isFoundryProject: false,
workspaceName: '', workspaceName: '',
currentFile, currentFile,
configFilePath: 'compiler_config.json', configFilePath: 'compiler_config.json',
@ -67,9 +68,10 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
api.onSetWorkspace = async (isLocalhost: boolean, workspaceName: string) => { api.onSetWorkspace = async (isLocalhost: boolean, workspaceName: string) => {
const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject() const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
const isTruffle = await compileTabLogic.isTruffleProject() const isTruffle = isLocalhost && await compileTabLogic.isTruffleProject()
const isFoundry = isLocalhost && await compileTabLogic.isFoundryProject()
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile, isHardhatProject: isHardhat, workspaceName: workspaceName, isTruffleProject: isTruffle } return { ...prevState, currentFile, isHardhatProject: isHardhat, workspaceName: workspaceName, isTruffleProject: isTruffle, isFoundryProject: isFoundry }
}) })
} }
@ -171,6 +173,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
isHardhatProject={state.isHardhatProject} isHardhatProject={state.isHardhatProject}
workspaceName={state.workspaceName} workspaceName={state.workspaceName}
isTruffleProject={state.isTruffleProject} isTruffleProject={state.isTruffleProject}
isFoundryProject={state.isFoundryProject}
compileTabLogic={compileTabLogic} compileTabLogic={compileTabLogic}
tooltip={toast} tooltip={toast}
modal={modal} modal={modal}

@ -11,6 +11,7 @@ export interface CompilerContainerProps {
compileTabLogic: CompileTabLogic, compileTabLogic: CompileTabLogic,
isHardhatProject: boolean, isHardhatProject: boolean,
isTruffleProject: boolean, isTruffleProject: boolean,
isFoundryProject: boolean,
workspaceName: string, workspaceName: string,
tooltip: (message: string | JSX.Element) => void, tooltip: (message: string | JSX.Element) => void,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,

Loading…
Cancel
Save