Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit 5e9e352

Browse files
committed
perf(sh): load main module in-process when possible
1 parent 760b12e commit 5e9e352

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/commands/shell.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ async function shell (argv, opts) {
3030
}
3131

3232
function launchShell (argv, opts) {
33-
// TODO - remove argv._.length check when next clause can be made to
34-
// work with `esm`.
35-
if (argv._.length || (opts.nodeArg && opts.nodeArg.length)) {
33+
if (opts.nodeArg && opts.nodeArg.length) {
3634
cp.spawnSync(
3735
process.argv[0],
3836
['-r', require.resolve('esm'), '-r', require.resolve('../node/index.js'), ...(opts.nodeArg || []), ...argv._.slice(1)],
3937
{ stdio: 'inherit' }
4038
)
4139
} else if (argv._.length > 1) {
42-
// TODO - try to hook up to `esm`
4340
require('../node/index.js')
44-
const Module = require('module')
45-
process.argv = [
46-
process.argv[0],
47-
path.resolve(argv._[1]),
48-
...argv._.slice(2)
49-
]
50-
Module.runMain()
41+
const Module = module.constructor
42+
const fname = path.resolve(argv._[1])
43+
const mod = new Module(fname, null)
44+
process.mainModule = mod
45+
mod.id = '.'
46+
try {
47+
mod.load(fname)
48+
} catch (err) {
49+
delete Module._cache[fname]
50+
}
5151
} else {
5252
require('../node/index.js')
5353
const { createRepl } = require('../node/repl.js')

0 commit comments

Comments
 (0)