Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit c4aabeb

Browse files
authored
Development (#1)
Allow plugins to be loaded from an absolute or relative path
1 parent af890a6 commit c4aabeb

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 4.1.2 (2019-07-29)
2+
- [NEW] Plugins can now be loaded from outside of the 'plugins/' directory
3+
14
# 4.1.1 (2019-06-17)
25
- [FIXED] Remove unnecessary `npm-cli-login` dependency.
36

lib/client.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const async = require('async');
1717
const concat = require('concat-stream');
1818
const debug = require('debug')('cloudant:client');
1919
const EventRelay = require('./eventrelay.js');
20+
const path = require('path');
2021
const PassThroughDuplex = require('./passthroughduplex.js');
2122
const pkg = require('../package.json');
2223
const utils = require('./clientutils.js');
@@ -147,6 +148,21 @@ class CloudantClient {
147148
});
148149
}
149150

151+
_buildPluginPath(name) {
152+
// Only a plugin name was provided: use plugin directory
153+
if (path.basename(name) === name) {
154+
return '../plugins/' + name;
155+
}
156+
157+
// An absolute path was provided
158+
if (path.isAbsolute(name)) {
159+
return name;
160+
}
161+
162+
// A relative path was provided
163+
return path.join(process.cwd(), name);
164+
}
165+
150166
_initClient(client) {
151167
if (typeof client !== 'undefined') {
152168
debug('Using custom client.');

test/client.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const assert = require('assert');
1919
const Client = require('../lib/client.js');
2020
const nock = require('./nock.js');
21+
const path = require('path');
2122
const stream = require('stream');
2223
const testPlugin = require('./fixtures/testplugins.js');
2324
const uuidv4 = require('uuid/v4'); // random
@@ -86,6 +87,21 @@ describe('CloudantClient', function() {
8687
});
8788

8889
describe('plugin support', function() {
90+
it('get plugin path by name', function() {
91+
var cloudantClient = new Client();
92+
assert.equal(cloudantClient._buildPluginPath('dummy-plugin'), '../plugins/dummy-plugin');
93+
});
94+
95+
it('get plugin path by relative path', function() {
96+
var cloudantClient = new Client();
97+
assert.equal(cloudantClient._buildPluginPath('./dummy-plugin'), path.join(process.cwd(), 'dummy-plugin'));
98+
});
99+
100+
it('get plugin path by absolute path', function() {
101+
var cloudantClient = new Client();
102+
assert.equal(cloudantClient._buildPluginPath('/plugins/dummy-plugin'), '/plugins/dummy-plugin');
103+
});
104+
89105
it('adds cookie authentication plugin if no other plugins are specified', function() {
90106
var cloudantClient = new Client();
91107
assert.equal(cloudantClient._plugins.length, 1);

0 commit comments

Comments
 (0)