Skip to content

Commit

Permalink
config: differentiate scope from project scope in config
Browse files Browse the repository at this point in the history
Fixes: npm/npm#14412
PR-URL: npm/npm#14477
Credit: @zkat
Reviewed-By: @iarna
  • Loading branch information
zkat committed Nov 3, 2016
1 parent 1f22822 commit 39358f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/cache/caching-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ function adaptConfig (config) {
defaultTag: config.get('tag'),
couchToken: config.get('_token'),
maxSockets: config.get('maxsockets'),
scope: config.get('scope')
scope: npm.projectScope
}
}
13 changes: 7 additions & 6 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,9 @@
var lp = Object.getOwnPropertyDescriptor(config, 'localPrefix')
Object.defineProperty(npm, 'localPrefix', lp)

if (config.get('scope') === '') {
config.set('scope', getProjectScope(npm.prefix))
}
if (config.get('scope') !== '' && config.get('scope')[0] !== '@') {
config.set('scope', '@' + config.get('scope'))
}
config.set('scope', scopeifyScope(config.get('scope')))
npm.projectScope = config.get('scope') ||
scopeifyScope(getProjectScope(npm.prefix))

// at this point the configs are all set.
// go ahead and spin up the registry client.
Expand Down Expand Up @@ -411,6 +408,10 @@
require('../bin/npm-cli.js')
}

function scopeifyScope (scope) {
return (!scope || scope[0] === '@') ? scope : ('@' + scope)
}

function getProjectScope (prefix) {
try {
var pkg = JSON.parse(fs.readFileSync(path.join(prefix, 'package.json')))
Expand Down

0 comments on commit 39358f7

Please sign in to comment.