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

Commit

Permalink
fix(production): fix up the config stuff after adding --prod
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 26, 2018
1 parent a260db1 commit 8a6e295
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 22 deletions.
8 changes: 1 addition & 7 deletions bin/tink.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,5 @@ function runCommandWithYargs (argv, log, npmConfig) {
config = config.command(mod)
}
require('../lib/node/index.js')
const yargv = npmConfig(config.argv).concat({ log })
log.level = yargv.loglevel || 'notice'
if (!yargv.production) {
process.tink.config = yargv
} else {
process.tink.config = { production: true }
}
config = config.argv
}
6 changes: 2 additions & 4 deletions lib/commands/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ async function prepare (argv, packages) {
const config = require('../config.js')
const figgyPudding = require('figgy-pudding')
const fs = require('graceful-fs')
const log = require('npmlog')
const path = require('path')

const opts = figgyPudding(Prepare.options)(config(argv))

log.level = opts.loglevel
if (argv.force || !await checkPkgLock()) {
const installer = require('../installer.js')
try {
await installer({
log (level, ...args) {
return log[level](...args)
return opts.log[level](...args)
},
only: packages,
cache: opts.cache
})
} catch (e) {
log.error('installer', e)
opts.log.error('installer', e)
}
}

Expand Down
14 changes: 12 additions & 2 deletions lib/commands/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ async function shell (argv) {

const opts = figgyPudding(Shell.options)(config(argv))

process.tink = {
cache: path.resolve(opts.cache)
if (argv.production) {
process.tink = {
cache: path.resolve(opts.cache),
config: figgyPudding({
production: { default: true }
})()
}
} else {
process.tink = {
cache: path.resolve(opts.cache),
config: opts
}
}
if (opts.nodeArg && opts.nodeArg.length) {
cp.spawnSync(
Expand Down
13 changes: 11 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ const CONFIG_NAMES = ['tinkrc', '.tinkrc', 'npmrc', '.npmrc']
const ENV_PREFIX = /^(?:npm|tink)_config_/i
module.exports = getConfigs
function getConfigs (argv) {
return config.read(argv, {
let conf = config.read(argv, {
configNames: CONFIG_NAMES,
envPrefix: ENV_PREFIX
})
}).concat({ log: require('npmlog') })
if (!conf.log) {
conf = conf.concat({
log: require('npmlog')
})
}
if (conf.loglevel) {
conf.log.level = conf.loglevel
}
return conf
}
6 changes: 3 additions & 3 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class Installer {
this.pkgCount = 0

// Misc
this.log = this.opts.log ||
((level, type, ...msgs) => process.emit(level, type, ...msgs))

this.log = (level, ...msgs) => {
this.opts.log[level](...msgs)
}
this.onlyDeps = opts.only && new Set(opts.only)
this.pkg = null
this.tree = null
Expand Down
7 changes: 5 additions & 2 deletions lib/lock-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ async function main (cache, integrity, pkg, opts) {
'restore-missing': true,
force: true
})
if (!opts.log) {
opts = opts.concat({ log: require('npmlog') })
opts.log.heading = 'tink'
opts.log.level = opts.loglevel
}
pkg = JSON.parse(pkg)
opts.log.heading = 'tink'
opts.log.level = opts.loglevel
opts.log.notice('fs', 'fetching', `${pkg.name}@${pkg.version}`)
try {
if (!prepare) { prepare = require('./commands/prepare.js') }
Expand Down
4 changes: 2 additions & 2 deletions lib/pkglock.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function getPkg (cache, scope, pkgName) {

function notCachedError (cache, pkg, hash) {
throw Object.assign(
new Error(`A file belonging to ${pkg.name}@${pkg.version} is missing and can't be restored because you are in production mode. Re-run tink in development mode and try again. (integrity: ${hash})`), { code: 'ENOTCACHED' }
new Error(`A file belonging to ${pkg.name}@${pkg.version} is missing and can't be restored because you are in production mode. Run \`tink prepare\` and try again. (integrity: ${hash})`), { code: 'ENOTCACHED' }
)
}

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

0 comments on commit 8a6e295

Please sign in to comment.