You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/03/03 08:37:37 UTC
[02/12] cordova-lib git commit: plugins are fetched from npm before
cordova registry
plugins are fetched from npm before cordova registry
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/049548a5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/049548a5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/049548a5
Branch: refs/heads/CB-8551
Commit: 049548a5994d4efcd85560c81526bcd0cd4c3ed5
Parents: 75687fb
Author: Steve Gill <st...@gmail.com>
Authored: Fri Jan 23 15:25:33 2015 -0800
Committer: Steve Gill <st...@gmail.com>
Committed: Fri Jan 23 17:20:15 2015 -0800
----------------------------------------------------------------------
cordova-lib/src/plugman/fetch.js | 1 -
cordova-lib/src/plugman/registry/registry.js | 121 ++++++++++++++++++----
2 files changed, 99 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/049548a5/cordova-lib/src/plugman/fetch.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js
index 1d4d0a4..136b849 100644
--- a/cordova-lib/src/plugman/fetch.js
+++ b/cordova-lib/src/plugman/fetch.js
@@ -128,7 +128,6 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
));
}
// If not found in local search path, fetch from the registry.
- events.emit('log', 'Fetching plugin "' + plugin_src + '" via plugin registry');
return registry.fetch([plugin_src], options.client)
.then(function(dir) {
return {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/049548a5/cordova-lib/src/plugman/registry/registry.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/registry/registry.js b/cordova-lib/src/plugman/registry/registry.js
index e3e0532..3643eb3 100644
--- a/cordova-lib/src/plugman/registry/registry.js
+++ b/cordova-lib/src/plugman/registry/registry.js
@@ -152,29 +152,15 @@ module.exports = {
*/
fetch: function(plugin, client) {
plugin = plugin.shift();
- return initSettings()
- .then(function (settings) {
- return Q.nfcall(npm.load)
- // configure npm here instead of passing parameters to npm.load due to CB-7670
- .then(function () {
- for (var prop in settings){
- npm.config.set(prop, settings[prop]);
- }
- });
- })
- .then(function() {
- return Q.ninvoke(npm.commands, 'cache', ['add', plugin]);
- })
- .then(function(info) {
- var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
- bumpCounter(info, cl);
- var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
- // Unpack the plugin that was added to the cache (CB-8154)
- var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
- return unpack.unpackTgz(package_tgz, pluginDir);
+ return fetchNPM(plugin, client)
+ .fail(function() {
+ events.emit('log', 'Fetching from npm failed');
+ //reset settings to fetch from cordova registry
+ module.exports.settings = null;
+ return fetchPlugReg(plugin,client);
});
},
-
+
/**
* @method info
* @param {String} name Plugin name
@@ -195,7 +181,6 @@ module.exports = {
// Plugin info should be accessed as info[version]. If a version
// specifier like >=x.y.z was used when calling npm view, info
// can contain several versions, but we take the first one here.
- console.log(info);
var version = Object.keys(info)[0];
return info[version];
});
@@ -230,6 +215,33 @@ function initSettings() {
return Q(settings);
}
+/**
+ * @method initSettingsNPM
+ * @return {Promise.<Object>} Promised settings.
+ */
+function initSettingsNPM() {
+ var settings = module.exports.settings;
+ // check if settings already set
+ if(settings !== null) return Q(settings);
+
+ // setting up settings
+ // obviously if settings dir does not exist settings is going to be empty
+ if(!fs.existsSync(plugmanConfigDir)) {
+ fs.mkdirSync(plugmanConfigDir);
+ fs.mkdirSync(plugmanCacheDir);
+ }
+
+ settings =
+ module.exports.settings =
+ rc('plugman', {
+ cache: plugmanCacheDir,
+ registry: 'http://registry.npmjs.org',
+ logstream: fs.createWriteStream(path.resolve(plugmanConfigDir, 'plugman.log')),
+ 'cache-min': oneDay
+ });
+ return Q(settings);
+}
+
// Send a message to the registry to update download counts.
function bumpCounter(info, client) {
@@ -308,3 +320,68 @@ function makeRequest (method, where, what, cb_) {
return req;
}
+
+/**
+ * @method fetchNPM
+ * @param {Array} with one element - the plugin id or "id@version"
+ * @return {Promise.<string>} Promised path to fetched package.
+ */
+function fetchNPM(plugin, client) {
+ events.emit('log', 'Fetching plugin "' + plugin + '" via npm');
+ return initSettingsNPM()
+ .then(function (settings) {
+ return Q.nfcall(npm.load)
+ // configure npm here instead of passing parameters to npm.load due to CB-7670
+ .then(function () {
+ for (var prop in settings){
+ npm.config.set(prop, settings[prop]);
+ }
+ });
+ })
+ .then(function() {
+ return Q.ninvoke(npm.commands, 'cache', ['add', plugin]);
+ })
+ .then(function(info) {
+ var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
+ bumpCounter(info, cl);
+ var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
+ // Unpack the plugin that was added to the cache (CB-8154)
+ var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
+ return unpack.unpackTgz(package_tgz, pluginDir);
+ });
+}
+
+
+/**
+ * @method fetchPlugReg
+ * @param {Array} with one element - the plugin id or "id@version"
+ * @return {Promise.<string>} Promised path to fetched package.
+ */
+function fetchPlugReg(plugin, client) {
+ events.emit('log', 'Fetching plugin "' + plugin + '" via plugin registry');
+ return initSettings()
+ .then(function (settings) {
+ return Q.nfcall(npm.load)
+ // configure npm here instead of passing parameters to npm.load due to CB-7670
+ .then(function () {
+ for (var prop in settings){
+ npm.config.set(prop, settings[prop]);
+ }
+ });
+ })
+ .then(function() {
+ return Q.ninvoke(npm.commands, 'cache', ['add', plugin]);
+ })
+ .then(function(info) {
+ var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
+ bumpCounter(info, cl);
+ var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
+ // Unpack the plugin that was added to the cache (CB-8154)
+ var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
+ return unpack.unpackTgz(package_tgz, pluginDir);
+ })
+ .fail(function() {
+ events.emit('log', 'Fetching from plugin registry failed');
+ });
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org