This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3k
Multiple registry support (re: #1401) #3093
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d8dee15
First attempt at a fallback to multiple registries
cianclarke 84a9930
Support more than one registry - iterate over IDX until we run out of…
cianclarke c0798a7
Move registry retry logic out into a registry manager component
cianclarke bded5ef
Support whitespace seperated registry config from the command line, s…
cianclarke 0ed0ea0
Allow users to specify multiple registries whitespace separated with …
cianclarke 225ef87
Merge post-rebase
cianclarke File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,12 @@ config.completion = function (opts, cb) { | |
// npm config list | ||
function config (args, cb) { | ||
var action = args.shift() | ||
|
||
// Config for registry can be whitespace separated, support that here by treating them as one 'value' | ||
if (action=='set' && args[0] === 'registry' && args.length >2){ | ||
args = [args[0], args.slice(1, args.length).join(' ')] | ||
} | ||
|
||
switch (action) { | ||
case "set": return set(args[0], args[1], cb) | ||
case "get": return get(args[0], cb) | ||
|
@@ -129,11 +135,17 @@ function set (key, val, cb) { | |
} | ||
|
||
function get (key, cb) { | ||
debugger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this, please. |
||
if (!key) return list(cb) | ||
if (key.charAt(0) === "_") { | ||
return cb(new Error("---sekretz---")) | ||
} | ||
console.log(npm.config.get(key)) | ||
var val = npm.config.get(key) | ||
// TODO: Add support to npmconf for whitespace separated URls.. | ||
if (val && val.indexOf('%20')!==-1){ | ||
val = val.replace('%20', ' ') | ||
} | ||
console.log(val) | ||
cb() | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
// Registry manager - makes npm.registry's functions allow a retry | ||
|
||
module.exports = RegManager | ||
|
||
|
||
function RegManager(registries) { | ||
if (!registries || registries.length<1){ | ||
throw new Error("No registries have been supplied to the registry manager") | ||
} | ||
|
||
var idx = 0, | ||
primaryRegistry = registries[0], | ||
i; | ||
|
||
for (var key in primaryRegistry){ | ||
// No .hasOwnProperty check - we want the prototype chain! | ||
this[key] = primaryRegistry[key]; | ||
} | ||
this.get = function(){ | ||
// First attempt at overriding get function - long term this | ||
// may not be enough. Maybe, the whole NPM install|search|whatever | ||
// command needs to be retried from scratch if it's falling back to | ||
// another registry.. | ||
var args = arguments, | ||
i, _cb | ||
// Pluck out the callback from the arguments & intercept it | ||
for (i=0; i<arguments.length; i++){ | ||
if (typeof arguments[i] == 'function'){ | ||
_cb = arguments[i] | ||
arguments[i] = function(err, data){ | ||
// If the error is 'just' a 404, and there are registries still left to try, let's try them | ||
if (err && err.code && err.code === "E404" && ++idx<registries.length){ | ||
return registries[idx].get.apply(registries[idx], args); | ||
}else{ | ||
// Either we've succeeded, we're out of registries, or it's an error we can't deal with | ||
return _cb(err, data) | ||
} | ||
} | ||
} | ||
} | ||
registries[idx].get.apply(this, arguments) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just require that the user quote the value?
npm config set registry "http://foo.com http://bar.com"
etc?