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

Commit

Permalink
perf(sh): load main module in-process when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jan 2, 2019
1 parent 760b12e commit 5e9e352
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/commands/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ async function shell (argv, opts) {
}

function launchShell (argv, opts) {
// TODO - remove argv._.length check when next clause can be made to
// work with `esm`.
if (argv._.length || (opts.nodeArg && opts.nodeArg.length)) {
if (opts.nodeArg && opts.nodeArg.length) {
cp.spawnSync(
process.argv[0],
['-r', require.resolve('esm'), '-r', require.resolve('../node/index.js'), ...(opts.nodeArg || []), ...argv._.slice(1)],
{ stdio: 'inherit' }
)
} else if (argv._.length > 1) {
// TODO - try to hook up to `esm`
require('../node/index.js')
const Module = require('module')
process.argv = [
process.argv[0],
path.resolve(argv._[1]),
...argv._.slice(2)
]
Module.runMain()
const Module = module.constructor
const fname = path.resolve(argv._[1])
const mod = new Module(fname, null)
process.mainModule = mod
mod.id = '.'
try {
mod.load(fname)
} catch (err) {
delete Module._cache[fname]
}
} else {
require('../node/index.js')
const { createRepl } = require('../node/repl.js')
Expand Down

0 comments on commit 5e9e352

Please sign in to comment.