Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/scoped package support #3453

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("@")){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests on 0.12 failed cause startsWidth is not supported :(
I think we should write test just like this :
if (canonic_module_name[0] !== "@"){

canonic_module_name = canonic_module_name.split('/')[1];
}
}

//pm2 install [email protected]
if(canonic_module_name.indexOf('@') !== -1) {
canonic_module_name = canonic_module_name.split('@')[0];
//pm2 install @somescope/[email protected]
if(canonic_module_name.lastIndexOf('@') !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to have > 0 instead of !==0.
Otherwise if you have a simple module name (without @, / etc) condition will be evaluated as true because lastIndexOf('@') will return -1.
This is why tests are failing.

canonic_module_name = canonic_module_name.substr(0,canonic_module_name.lastIndexOf("@"));
}

//pm2 install module#some-branch
Expand Down
2 changes: 1 addition & 1 deletion test/interface/utility.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just add a test with multiple @.
Like @org/[email protected]
Just to ensure we test all cases.

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');
Expand Down