Skip to content

Commit

Permalink
realtive path of cordova plugin should be relative to meteor project
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtkowiak authored and Slava committed May 22, 2015
1 parent d978ad4 commit 1f2f584
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
22 changes: 16 additions & 6 deletions tools/commands-cordova.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var main = require('./main.js');
var _ = require('underscore');
var util = require('util');
var path = require('path');
var chalk = require('chalk');
var files = require('./files.js');
var buildmessage = require('./buildmessage.js');
Expand Down Expand Up @@ -468,14 +469,14 @@ var targetsToPlatforms = cordova.targetsToPlatforms = function (targets) {

// --- Cordova plugins ---

var installPlugin = function (cordovaPath, name, version, conf) {
var installPlugin = function (cordovaPath, name, version, conf, projectDir) {
verboseLog('Installing a plugin', name, version);

var pluginInstallCommand;

if (utils.isUrlWithFileScheme(version)) {
// Strip file://
pluginInstallCommand = version.substr(7);
// Strip file:// and compute the relative path from plugin to corodova-build
pluginInstallCommand = getCordovaLocalPluginPath(version, cordovaPath, projectDir);
} else {
pluginInstallCommand = version ? name + '@' + version : name;
}
Expand Down Expand Up @@ -535,6 +536,15 @@ var uninstallPlugin = function (cordovaPath, name, isFromTarballUrl) {
}
};

// Strips the file:// from the path and if a relative path was used, it translates it to a relative path to the
// cordova-build directory instead of meteor project directory.
var getCordovaLocalPluginPath = function (pluginPath, cordovaPath, projectDir) {
pluginPath = pluginPath.substr("file://".length);
if (utils.isPathRelative(pluginPath))
return path.relative(cordovaPath, path.resolve(projectDir, pluginPath));
return pluginPath;
}

var getTarballPluginsLock = function (cordovaPath) {
verboseLog('Will check for cordova-tarball-plugins.json' +
' for tarball-url-based plugins previously installed.');
Expand Down Expand Up @@ -663,10 +673,10 @@ var ensureCordovaPlugins = function (projectContext, options) {
}
});

if (pluginsFromLocalPath.length > 0)
if (! _.isEmpty(pluginsFromLocalPath))
verboseLog('Reinstalling cordova plugins added from the local path');

if (shouldReinstallPlugins || pluginsFromLocalPath.length > 0) {
if (shouldReinstallPlugins || ! _.isEmpty(pluginsFromLocalPath)) {
// Loop through all of the current plugins and remove them one by one until
// we have deleted proper amount of plugins. It's necessary to loop because
// we might have dependencies between plugins.
Expand Down Expand Up @@ -720,7 +730,7 @@ var ensureCordovaPlugins = function (projectContext, options) {

buildmessage.reportProgress({ current: 0, end: pluginsCount });
_.each(pluginsToInstall, function (version, name) {
installPlugin(cordovaPath, name, version, pluginsConfiguration[name]);
installPlugin(cordovaPath, name, version, pluginsConfiguration[name], projectContext.projectDir);

buildmessage.reportProgress({
current: ++pluginsInstalled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ Package.onUse(function(api) {
Cordova.depends({
// In the test "meteor reinstalls only local cordova plugins on consecutive
// builds/runs" (test in file cordova-plugin.js) the "plugin"
// directory from this package is copied one level up from the meteor app.
// directory from this package is copied one level up from the meteor project.
// Cordova local plugins must have an absolute or relative path to
// meteor_app/.meteor/local/cordova-build, so in this case the plugin will
// be 4 levels up from cordova-build directory.
'com.cordova.empty': 'file://../../../../cordova-local-plugin'
// meteor project, so in this case the plugin will be one level up from it.
'com.cordova.empty': 'file://../cordova-local-plugin'
});
});
2 changes: 1 addition & 1 deletion tools/tests/cordova-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ selftest.define("meteor reinstalls only local cordova plugins on consecutive bui
);

// Add the local cordova plugin
run = s.run("add", "cordova:com.cordova.empty@file://../../../../cordova-local-plugin");
run = s.run("add", "cordova:com.cordova.empty@file://../cordova-local-plugin");
run.waitSecs(60);
run.match("added cordova plugin com.cordova.empty");
run.expectExit(0);
Expand Down
4 changes: 4 additions & 0 deletions tools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ exports.isUrlWithSha = function (x) {
return /^https?:\/\/.*[0-9a-f]{40}/.test(x);
};

exports.isPathRelative = function (x) {
return x.charAt(0) !== '/';
};

// If there is a version that isn't exact, throws an Error with a
// human-readable message that is suitable for showing to the user.
// dependencies may be falsey or empty.
Expand Down

0 comments on commit 1f2f584

Please sign in to comment.