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

Commit

Permalink
fix(cache): fix --cache option to let it be provided in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 6, 2018
1 parent 4eda171 commit 5ebf116
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
30 changes: 5 additions & 25 deletions bin/tink.js
Original file line number Diff line number Diff line change
@@ -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')],
Expand All @@ -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) {
Expand All @@ -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'
}
4 changes: 0 additions & 4 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5ebf116

Please sign in to comment.