Skip to content

Commit

Permalink
fix(cmd-api-server): enable version selection in plugins
Browse files Browse the repository at this point in the history
cactus-cmd-api-server can now import plugins specifying
the npm package version as a plugin option

cmd-api-server: add missing dependency bluebird

closes hyperledger-cacti#839 and hyperledger-cacti#840

Signed-off-by: Elena Izaguirre <e.izaguirre.equiza@accenture.com>
  • Loading branch information
elenaizaguirre committed Sep 30, 2021
1 parent 6deed6d commit 6bced8d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cactus-cmd-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@hyperledger/cactus-core-api": "0.10.0",
"@thream/socketio-jwt": "2.1.1",
"axios": "0.21.4",
"bluebird": "3.7.2",
"body-parser": "1.19.0",
"compression": "1.7.4",
"convict": "6.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ export class ApiServer {

const instanceId = pluginImport.options.instanceId;
const pluginPackageDir = path.join(this.pluginsPath, instanceId);
const pluginVersion = // version of the npm package
pluginImport.options.version != undefined &&
pluginImport.options.version != ""
? "@".concat(pluginImport.options.version as string)
: "";
try {
await fs.mkdirp(pluginPackageDir);
this.log.debug(`${pkgName} plugin package dir: %o`, pluginPackageDir);
Expand All @@ -341,7 +346,7 @@ export class ApiServer {
lmify.setRootDir(pluginPackageDir);
this.log.debug(`Installing ${pkgName} for plugin import`, pluginImport);
const out = await lmify.install([
pkgName,
pkgName.concat(pluginVersion), // empty if no version was specified
"--production",
"--audit=false",
"--progress=false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ test("can instal plugins at runtime based on imports", async (t: Test) => {
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
version: "0.9.0",
logLevel,
},
},
Expand All @@ -66,6 +67,7 @@ test("can instal plugins at runtime based on imports", async (t: Test) => {
instanceId: uuidv4(),
keyPairPem: keyPairPem,
consortiumDatabase: db,
version: "0.9.0",
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test("can import plugins at runtime (CLI)", async (t: Test) => {
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
version: "0.9.0",
logLevel,
},
},
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6275,7 +6275,7 @@ blocking-proxy@^1.0.0:
dependencies:
minimist "^1.2.0"

bluebird@^3.5.0:
bluebird@3.7.2, bluebird@^3.5.0:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
Expand Down

0 comments on commit 6bced8d

Please sign in to comment.