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

Commit

Permalink
fix(log): get logging config to propagate correctly
Browse files Browse the repository at this point in the history
Also made current tink config globally accessible (will remove in --production mode)
  • Loading branch information
zkat committed Nov 21, 2018
1 parent 0af7eb0 commit 40b1333
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions bin/tink.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ function runCommandWithYargs (argv, log, npmConfig) {
require('../lib/node/index.js')
const yargv = npmConfig(config.argv).concat({ log })
log.level = yargv.loglevel || 'notice'
process.tink.config = yargv
}
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CONFIG_NAMES = ['tinkrc', '.tinkrc', 'npmrc', '.npmrc']
const ENV_PREFIX = /^(?:npm|tink)_config_/i
module.exports = getConfigs
function getConfigs (argv) {
return config.read({
return config.read(argv, {
configNames: CONFIG_NAMES,
envPrefix: ENV_PREFIX
})
Expand Down
30 changes: 15 additions & 15 deletions lib/lock-worker.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
'use strict'

let config
let ensurePkg
let prepare

const figgyPudding = require('figgy-pudding')

const MainOpts = figgyPudding({
log: { default: () => require('libnpm').log },
loglevel: { default: 'notice' }
}, {
other () { return true }
})

if (require.main === module && process.argv[2] === 'ensure-pkg') {
main(...process.argv.slice(3))
}

module.exports = main
async function main (cache, integrity, pkg) {
pkg = JSON.parse(pkg)
if (!config) { config = require('./config.js') }
const opts = config().concat({
async function main (cache, integrity, pkg, opts) {
opts = MainOpts(JSON.parse(opts)).concat({
cache,
integrity,
log: require('npmlog'),
// loglevel: 'silly',
'restore-missing': true,
force: true
}, {
other () { return true }
})
pkg = JSON.parse(pkg)
opts.log.heading = 'tink'
opts.log.notice('fs', 'unpacking', `${pkg.name}@${pkg.version}`)
opts.log.level = opts.loglevel
opts.log.notice('fs', 'fetching', `${pkg.name}@${pkg.version}`)
try {
if (!prepare) { prepare = require('./commands/prepare.js') }
opts.log.level = 'silent'
const res = await prepare.handler(opts.concat({
loglevel: 'silent'
}), [pkg.name])
const res = await prepare.handler(opts, [pkg.name])
if (res && !res.pkgCount) { throw new Error('no packages installed') }
} catch (err) {
if (!ensurePkg) { ensurePkg = require('./ensure-package.js') }
opts.log.level = opts.loglevel
await ensurePkg(cache, pkg.name, pkg, opts)
}
}
7 changes: 3 additions & 4 deletions lib/pkglock.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,11 @@ function getPkg (cache, scope, pkgName) {
}

let ensurePkg
let config
let ensureDep
async function fetchPackage (cache, pkg, hash) {
if (!ensurePkg) { ensurePkg = require('./ensure-package.js') }
if (!config) { config = require('./config.js') }
if (!ensureDep) { ensureDep = require('./lock-worker.js') }
await ensureDep(cache, hash, pkg)
await ensureDep(cache, hash, pkg, process.tink.config)
}

function fetchPackageSync (cache, pkg, integrity) {
Expand All @@ -319,6 +317,7 @@ function fetchPackageSync (cache, pkg, integrity) {
'ensure-pkg',
cache,
integrity,
JSON.stringify(pkg)
JSON.stringify(pkg),
JSON.stringify(process.tink.config.concat({ log: undefined }) || {})
], { stdio: 'inherit' })
}

0 comments on commit 40b1333

Please sign in to comment.