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

Commit 40b1333

Browse files
committed
fix(log): get logging config to propagate correctly
Also made current tink config globally accessible (will remove in --production mode)
1 parent 0af7eb0 commit 40b1333

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

bin/tink.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ function runCommandWithYargs (argv, log, npmConfig) {
4545
require('../lib/node/index.js')
4646
const yargv = npmConfig(config.argv).concat({ log })
4747
log.level = yargv.loglevel || 'notice'
48+
process.tink.config = yargv
4849
}

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const CONFIG_NAMES = ['tinkrc', '.tinkrc', 'npmrc', '.npmrc']
66
const ENV_PREFIX = /^(?:npm|tink)_config_/i
77
module.exports = getConfigs
88
function getConfigs (argv) {
9-
return config.read({
9+
return config.read(argv, {
1010
configNames: CONFIG_NAMES,
1111
envPrefix: ENV_PREFIX
1212
})

lib/lock-worker.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
'use strict'
22

3-
let config
43
let ensurePkg
54
let prepare
65

6+
const figgyPudding = require('figgy-pudding')
7+
8+
const MainOpts = figgyPudding({
9+
log: { default: () => require('libnpm').log },
10+
loglevel: { default: 'notice' }
11+
}, {
12+
other () { return true }
13+
})
14+
715
if (require.main === module && process.argv[2] === 'ensure-pkg') {
816
main(...process.argv.slice(3))
917
}
1018

1119
module.exports = main
12-
async function main (cache, integrity, pkg) {
13-
pkg = JSON.parse(pkg)
14-
if (!config) { config = require('./config.js') }
15-
const opts = config().concat({
20+
async function main (cache, integrity, pkg, opts) {
21+
opts = MainOpts(JSON.parse(opts)).concat({
1622
cache,
1723
integrity,
18-
log: require('npmlog'),
19-
// loglevel: 'silly',
2024
'restore-missing': true,
2125
force: true
22-
}, {
23-
other () { return true }
2426
})
27+
pkg = JSON.parse(pkg)
2528
opts.log.heading = 'tink'
26-
opts.log.notice('fs', 'unpacking', `${pkg.name}@${pkg.version}`)
29+
opts.log.level = opts.loglevel
30+
opts.log.notice('fs', 'fetching', `${pkg.name}@${pkg.version}`)
2731
try {
2832
if (!prepare) { prepare = require('./commands/prepare.js') }
29-
opts.log.level = 'silent'
30-
const res = await prepare.handler(opts.concat({
31-
loglevel: 'silent'
32-
}), [pkg.name])
33+
const res = await prepare.handler(opts, [pkg.name])
3334
if (res && !res.pkgCount) { throw new Error('no packages installed') }
3435
} catch (err) {
3536
if (!ensurePkg) { ensurePkg = require('./ensure-package.js') }
36-
opts.log.level = opts.loglevel
3737
await ensurePkg(cache, pkg.name, pkg, opts)
3838
}
3939
}

lib/pkglock.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,11 @@ function getPkg (cache, scope, pkgName) {
304304
}
305305

306306
let ensurePkg
307-
let config
308307
let ensureDep
309308
async function fetchPackage (cache, pkg, hash) {
310309
if (!ensurePkg) { ensurePkg = require('./ensure-package.js') }
311-
if (!config) { config = require('./config.js') }
312310
if (!ensureDep) { ensureDep = require('./lock-worker.js') }
313-
await ensureDep(cache, hash, pkg)
311+
await ensureDep(cache, hash, pkg, process.tink.config)
314312
}
315313

316314
function fetchPackageSync (cache, pkg, integrity) {
@@ -319,6 +317,7 @@ function fetchPackageSync (cache, pkg, integrity) {
319317
'ensure-pkg',
320318
cache,
321319
integrity,
322-
JSON.stringify(pkg)
320+
JSON.stringify(pkg),
321+
JSON.stringify(process.tink.config.concat({ log: undefined }) || {})
323322
], { stdio: 'inherit' })
324323
}

0 commit comments

Comments
 (0)