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

don't load Truffle's console contract into the console environment #5788

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/core/lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,23 @@ class Console extends EventEmitter {
path.join(this.options.contracts_build_directory, file),
"utf8"
);
jsonBlobs.push(JSON.parse(body));
const json = JSON.parse(body);
const metadata = JSON.parse(json.metadata);
const sources = Object.keys(metadata.sources);
// filter out Truffle's console.log. We don't want users to interact with in the REPL.
// user contracts named console.log will be imported, and a warning will be issued.
if (
sources.length > 1 ||
(sources.length === 1 &&
!sources.some(source => {
return (
source === "truffle/console.sol" ||
source === "truffle/Console.sol"
);
}))
) {
jsonBlobs.push(json);
}
} catch (error) {
throw new Error(`Error parsing or reading ${file}: ${error.message}`);
}
Expand Down