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

Commit b278409

Browse files
authored
Merge pull request #5788 from trufflesuite/console-fix
don't load Truffle's console contract into the console environment
2 parents ac013dc + 7f833fd commit b278409

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/core/lib/console.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,23 @@ class Console extends EventEmitter {
262262
path.join(this.options.contracts_build_directory, file),
263263
"utf8"
264264
);
265-
jsonBlobs.push(JSON.parse(body));
265+
const json = JSON.parse(body);
266+
const metadata = JSON.parse(json.metadata);
267+
const sources = Object.keys(metadata.sources);
268+
// filter out Truffle's console.log. We don't want users to interact with in the REPL.
269+
// user contracts named console.log will be imported, and a warning will be issued.
270+
if (
271+
sources.length > 1 ||
272+
(sources.length === 1 &&
273+
!sources.some(source => {
274+
return (
275+
source === "truffle/console.sol" ||
276+
source === "truffle/Console.sol"
277+
);
278+
}))
279+
) {
280+
jsonBlobs.push(json);
281+
}
266282
} catch (error) {
267283
throw new Error(`Error parsing or reading ${file}: ${error.message}`);
268284
}

0 commit comments

Comments
 (0)