Merge pull request #13 from devtobo/CB-13503-squashed
CB-13503 fix trimID bug when using file:path/to/plugin
diff --git a/index.js b/index.js
index 9f4694c..8bb6326 100644
--- a/index.js
+++ b/index.js
@@ -145,7 +145,7 @@
* get the moduleID of the installed module.
*
* @param {String} target target that was passed into cordova-fetch.
- * can be moduleID, moduleID@version or gitURL
+ * can be moduleID, moduleID@version, gitURL or relative path (file:relative/path)
*
* @return {String} ID moduleID without version.
*/
@@ -166,6 +166,11 @@
}
// If local path exists, try to get plugin id from package.json or set target to final directory
+ if (target.startsWith('file:')) {
+ // If target starts with file: prefix, strip it
+ target = target.substring(5);
+ }
+
if (fs.existsSync(target)) {
var pluginId;
var pkgJsonPath = path.join(target, 'package.json');
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index ab08eab..7d3c6b7 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -208,6 +208,7 @@
beforeEach(function () {
tmpDir = helpers.tmpDir('plug_trimID');
+ shell.cp('-R', 'spec/support', path.join(tmpDir, 'support'));
process.chdir(tmpDir);
});
@@ -284,6 +285,26 @@
.fin(done);
}, 30000);
+ it('should fetch same plugin twice in a row if using a relative path', function (done) {
+ fetch('file:support/dummy-local-plugin', tmpDir, opts)
+ .then(function (result) {
+ expect(result).toBeDefined();
+ expect(fs.existsSync(result)).toBe(true);
+ expect(result).toMatch('test-plugin');
+ return fetch('file:support/dummy-local-plugin', tmpDir, opts);
+ })
+ .then(function (result) {
+ expect(result).toBeDefined();
+ expect(fs.existsSync(result)).toBe(true);
+ expect(result).toMatch('test-plugin');
+ })
+ .fail(function (err) {
+ console.error(err);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
+ }, 30000);
+
it('should fetch from git+http successfully', function (done) {
fetch('git+http://gitbox.apache.org/repos/asf/cordova-plugin-dialogs.git', tmpDir, opts)
.then(function () {
diff --git a/spec/support/dummy-local-plugin/package.json b/spec/support/dummy-local-plugin/package.json
new file mode 100644
index 0000000..77cb898
--- /dev/null
+++ b/spec/support/dummy-local-plugin/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "test-plugin",
+ "version": "1.0.0",
+ "description": "This plugin allows you to stream audio and video in a fullscreen, native player on iOS and Android.",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ }
+}
diff --git a/spec/support/dummy-local-plugin/plugin.xml b/spec/support/dummy-local-plugin/plugin.xml
new file mode 100755
index 0000000..b15d7b7
--- /dev/null
+++ b/spec/support/dummy-local-plugin/plugin.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin
+ xmlns="http://apache.org/cordova/ns/plugins/1.0"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ id="test-plugin"
+ version="1.0.0">
+
+ <name>test plugin</name>
+
+ <engines>
+ <engine name="cordova" version=">=3.0.0" />
+ </engines>
+
+</plugin>