Skip to content

Commit

Permalink
babel-node: support require flag in repl mode (#12297)
Browse files Browse the repository at this point in the history
  • Loading branch information
markyfyi committed Nov 4, 2020
1 parent 487f82e commit 4141793
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/babel-node/src/_babel-node.js
Expand Up @@ -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];
Expand All @@ -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 > ",
Expand Down

0 comments on commit 4141793

Please sign in to comment.