diff --git a/bin/tink.js b/bin/tink.js index 7ca347b..022fa77 100755 --- a/bin/tink.js +++ b/bin/tink.js @@ -1,7 +1,5 @@ #!/usr/bin/env node -require('../lib/node/index.js') - const CMDS = new Map([ ['sh', require('../lib/commands/shell.js')], ['shell', require('../lib/commands/shell.js')], @@ -19,17 +17,7 @@ function main (argv) { const log = require('npmlog') log.heading = 'tink' const npmConfig = require('../lib/config.js') - if (needsYargs(argv)) { - return runCommandWithYargs(argv, log, npmConfig) - } else { - return noYargsShortcut(argv, log, npmConfig) - } -} - -function needsYargs (argv) { - return argv.length > 3 && ( - argv[3] !== '--' && argv[3].match(/^--?[a-z0-9]+/i) - ) + return runCommandWithYargs(argv, log, npmConfig) } function runCommandWithYargs (argv, log, npmConfig) { @@ -44,18 +32,10 @@ function runCommandWithYargs (argv, log, npmConfig) { for (const mod of CMDS.values()) { config = config.command(mod) } + require('../lib/node/index.js') const yargv = npmConfig(config.argv).concat({ log }) - log.level = yargv.loglevel || 'notice' -} - -function noYargsShortcut (argv, log, npmConfig) { - // This is an optimization because Yargs can be expensive to load. - const opts = npmConfig({ log, _: argv.slice(2) }) - log.level = opts.loglevel - const cmd = CMDS.get(argv[2]) - if (!cmd) { - return runCommandWithYargs(argv, log, npmConfig) - } else { - return cmd.handler(opts) + process.tink = { + cache: yargv.cache } + log.level = yargv.loglevel || 'notice' } diff --git a/lib/node/index.js b/lib/node/index.js index 912dc52..b957d10 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -2,10 +2,6 @@ module.exports.overrideNode = overrideNode function overrideNode () { - process.tink = { - cache: require('../config.js')().cache - } - Object.freeze(process.tink) require('./fs.js').overrideNode() require('./child_process.js').overrideNode() require('./module.js').overrideNode()