From a3e093bbfef573b90c110522ebffe70a74ad73d0 Mon Sep 17 00:00:00 2001 From: Daan Kets Date: Wed, 7 Feb 2018 09:13:22 +0200 Subject: [PATCH] Support for scoped package names --- lib/Utility.js | 10 ++++++---- test/interface/utility.mocha.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Utility.js b/lib/Utility.js index 169d86fd..ee51e3f8 100644 --- a/lib/Utility.js +++ b/lib/Utility.js @@ -223,12 +223,14 @@ var Utility = module.exports = { //pm2 install username/module else if(canonic_module_name.indexOf('/') !== -1) { - canonic_module_name = canonic_module_name.split('/')[1]; + if (!canonic_module_name.startsWith("@")){ + canonic_module_name = canonic_module_name.split('/')[1]; + } } - //pm2 install module@2.1.0-beta - if(canonic_module_name.indexOf('@') !== -1) { - canonic_module_name = canonic_module_name.split('@')[0]; + //pm2 install @somescope/module@2.1.0-beta + if(canonic_module_name.lastIndexOf('@') !== 0) { + canonic_module_name = canonic_module_name.substr(0,canonic_module_name.lastIndexOf("@")); } //pm2 install module#some-branch diff --git a/test/interface/utility.mocha.js b/test/interface/utility.mocha.js index e5e76adc..1cb89389 100644 --- a/test/interface/utility.mocha.js +++ b/test/interface/utility.mocha.js @@ -18,7 +18,7 @@ describe('Utility', function() { assert(Utility.getCanonicModuleName('ma-zal/pm2-slack') === 'pm2-slack'); assert(Utility.getCanonicModuleName('ma-zal/pm2-slack#own-branch') === 'pm2-slack'); assert(Utility.getCanonicModuleName('pm2-slack') === 'pm2-slack'); - assert(Utility.getCanonicModuleName('@org/pm2-slack') === 'pm2-slack'); + assert(Utility.getCanonicModuleName('@org/pm2-slack') === '@org/pm2-slack'); assert(Utility.getCanonicModuleName('git+https://github.com/user/pm2-slack') === 'pm2-slack'); assert(Utility.getCanonicModuleName('git+https://github.com/user/pm2-slack.git') === 'pm2-slack'); assert(Utility.getCanonicModuleName('file:///home/user/pm2-slack') === 'pm2-slack');