Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Enable .cjs config files on ESM projects - FIX: #2881 #2882

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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();
},
Expand All @@ -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));
Expand All @@ -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;
});

Expand All @@ -83,7 +83,7 @@ class WorkspaceScreen extends Component {
contract.address.length > 0)
);
},
false,
false
);
}
}
Expand Down Expand Up @@ -140,7 +140,9 @@ class WorkspaceScreen extends Component {
{showErrorDetails && (
<div className="ValidationDetails">
<SyntaxHighlighter language="bash">
{validationErrors.stack.map(line => line.toString())}
{validationErrors.stack.map((line) =>
line.toString()
)}
</SyntaxHighlighter>
</div>
)}
Expand Down Expand Up @@ -183,7 +185,8 @@ class WorkspaceScreen extends Component {
<div className="RowItem">
<p>
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.
</p>
<br />
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class ContractsScreen extends Component {
errorMessage = (
<span>
<strong>Your Truffle Project config is invalid.</strong> The
file should be named either &quot;truffle.js&quot; or
&quot;truffle-config.js&quot;.{" "}
file should be named either &quot;truffle.js&quot;,
&quot;truffle.cjs&quot;, &quot;truffle-config.js&quot; or
&quot;truffle-config.cjs&quot;.{" "}
<Link className="settingsLink" to="/config">
Choose a valid configuration file.
</Link>
Expand Down Expand Up @@ -105,7 +106,4 @@ class ContractsScreen extends Component {
}
}

export default connect(
ContractsScreen,
"workspaces",
);
export default connect(ContractsScreen, "workspaces");
2 changes: 1 addition & 1 deletion static/node/truffle-integration/projectsWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion static/node/truffle-project-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down