babel-node: support require flag in repl mode (#12297)

This commit is contained in:
Mark 2020-11-03 16:39:33 -08:00 committed by GitHub
parent 487f82e446
commit 4141793a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -187,12 +187,7 @@ if (program.eval || program.print) {
});
args = args.slice(i);
// We have to handle require ourselves, as we want to require it in the context of babel-register
if (program.require) {
require(resolve.sync(program.require, {
basedir: process.cwd(),
}));
}
requireArgs();
// make the filename absolute
const filename = args[0];
@ -206,10 +201,20 @@ if (program.eval || program.print) {
Module.runMain();
} else {
requireArgs();
replStart();
}
}
// We have to handle require ourselves, as we want to require it in the context of babel-register
function requireArgs() {
if (program.require) {
require(resolve.sync(program.require, {
basedir: process.cwd(),
}));
}
}
function replStart() {
repl.start({
prompt: "babel > ",