From 77488cc86ca0805a6a29edbdc3da9d97d9a45da5 Mon Sep 17 00:00:00 2001 From: Rodrigo Couto Date: Tue, 13 Jul 2021 01:09:32 -0300 Subject: [PATCH] Enable .cjs config files on ESM projects On ESM based projects CommonJS code must end in `.cjs`. --- .../config/ConfigScreens/WorkspaceScreen.js | 27 ++++++++++--------- .../screens/contracts/ContractsScreen.js | 10 +++---- .../truffle-integration/projectsWatcher.js | 2 +- static/node/truffle-project-loader/index.js | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/integrations/ethereum/renderer/screens/config/ConfigScreens/WorkspaceScreen.js b/src/integrations/ethereum/renderer/screens/config/ConfigScreens/WorkspaceScreen.js index 649060916..73a73fbde 100644 --- a/src/integrations/ethereum/renderer/screens/config/ConfigScreens/WorkspaceScreen.js +++ b/src/integrations/ethereum/renderer/screens/config/ConfigScreens/WorkspaceScreen.js @@ -7,11 +7,11 @@ import SyntaxHighlighter from "react-syntax-highlighter"; class WorkspaceScreen extends Component { state = { selectedIdx: null }; - validateChange = e => { + validateChange = (e) => { this.props.validateChange(e, {}); }; - handleProjectClick = idx => () => { + handleProjectClick = (idx) => () => { this.setState({ selectedIdx: this.state.selectedIdx === idx ? null : idx, }); @@ -20,30 +20,30 @@ class WorkspaceScreen extends Component { handleAddProjectClick = async () => { const pathArray = await remote.dialog.showOpenDialog({ properties: ["openFile"], - filters: [{ name: "Truffle Config File", extensions: ["js"] }], + filters: [{ name: "Truffle Config File", extensions: ["js", "cjs"] }], }); if ( pathArray && pathArray.filePaths.length > 0 && - path.basename(pathArray.filePaths[0]).match(/^truffle(-config)?.js$/) + path.basename(pathArray.filePaths[0]).match(/^truffle(-config)?.[c]?js$/) ) { this.props.addWorkspaceProject(pathArray.filePaths[0]); this.setState({ selectedIdx: null }); } }; - removeProject = projectPath => { + removeProject = (projectPath) => { this.props.removeWorkspaceProject(projectPath); this.setState({ selectedIdx: null }); }; - verifyRemoveProject = projectPath => { + verifyRemoveProject = (projectPath) => { const modalDetails = new ModalDetails( ModalDetails.types.WARNING, [ { - click: modal => { + click: (modal) => { this.removeProject(projectPath); modal.close(); }, @@ -54,7 +54,7 @@ class WorkspaceScreen extends Component { }, ], "Remove Project?", - "This project has contracts deployed; are you sure you want to remove it? Contract data, transactions, and events will no longer be decoded.", + "This project has contracts deployed; are you sure you want to remove it? Contract data, transactions, and events will no longer be decoded." ); this.props.dispatch(ModalDetails.actions.setModalError(modalDetails)); @@ -67,7 +67,7 @@ class WorkspaceScreen extends Component { let projectHasDeployedContracts = false; - let project = this.props.workspaces.current.projects.filter(project => { + let project = this.props.workspaces.current.projects.filter((project) => { return path.dirname(projectPath) === project.configFile; }); @@ -83,7 +83,7 @@ class WorkspaceScreen extends Component { contract.address.length > 0) ); }, - false, + false ); } } @@ -140,7 +140,9 @@ class WorkspaceScreen extends Component { {showErrorDetails && (
- {validationErrors.stack.map(line => line.toString())} + {validationErrors.stack.map((line) => + line.toString() + )}
)} @@ -183,7 +185,8 @@ class WorkspaceScreen extends Component {

Link Truffle projects to this workspace by adding their - truffle-config.js or truffle.js file to this workspace. + truffle-config.js, truffle-config.cjs, truffle.js or truffle.cjs + file to this workspace.


diff --git a/src/integrations/ethereum/renderer/screens/contracts/ContractsScreen.js b/src/integrations/ethereum/renderer/screens/contracts/ContractsScreen.js index 8346236cc..157fcf872 100644 --- a/src/integrations/ethereum/renderer/screens/contracts/ContractsScreen.js +++ b/src/integrations/ethereum/renderer/screens/contracts/ContractsScreen.js @@ -31,8 +31,9 @@ class ContractsScreen extends Component { errorMessage = ( Your Truffle Project config is invalid. The - file should be named either "truffle.js" or - "truffle-config.js".{" "} + file should be named either "truffle.js", + "truffle.cjs", "truffle-config.js" or + "truffle-config.cjs".{" "} Choose a valid configuration file. @@ -105,7 +106,4 @@ class ContractsScreen extends Component { } } -export default connect( - ContractsScreen, - "workspaces", -); +export default connect(ContractsScreen, "workspaces"); diff --git a/static/node/truffle-integration/projectsWatcher.js b/static/node/truffle-integration/projectsWatcher.js index a3c681df8..b817475b5 100644 --- a/static/node/truffle-integration/projectsWatcher.js +++ b/static/node/truffle-integration/projectsWatcher.js @@ -158,7 +158,7 @@ class ProjectsWatcher extends EventEmitter { // TODO: might be an easier way now let truffleDirectory = projectPath; if ( - path.basename(truffleDirectory).match(/truffle(-config)?.js/) !== null + path.basename(truffleDirectory).match(/truffle(-config)?.[c]?js/) !== null ) { truffleDirectory = path.dirname(truffleDirectory); } diff --git a/static/node/truffle-project-loader/index.js b/static/node/truffle-project-loader/index.js index 915d4e313..1e11d2c8b 100644 --- a/static/node/truffle-project-loader/index.js +++ b/static/node/truffle-project-loader/index.js @@ -20,7 +20,7 @@ if (!fs.existsSync(projectFile)) { error: "project-does-not-exist", }); } else if ( - path.basename(projectFile).match(/^truffle(-config)?.js$/) === null + path.basename(projectFile).match(/^truffle(-config)?.[c]?js$/) === null ) { process.send({ name,