@@ -153,19 +153,48 @@ var Utility = module.exports = {
153
153
154
154
async . waterfall ( flows , callback ) ;
155
155
} ,
156
+
156
157
/**
157
- * Returns the module name from a .tgz package name (or the original name if it is not a valid pkg).
158
- * @param {string } package_name The package name (e.g. "foo.tgz", "foo-1.0.0.tgz", "folder/foo.tgz")
159
- * @return {string } the name
158
+ * Function parse the module name and returns it as canonic:
159
+ * - Makes the name based on installation filename.
160
+ * - Removes the Github author, module version and git branch from original name.
161
+ *
162
+ * @param {string } module_name
163
+ * @returns {string } Canonic module name (without trimed parts).
164
+ * @example Always returns 'pm2-slack' for inputs 'ma-zal/pm2-slack', 'ma-zal/pm2-slack#own-branch',
165
+ * 'pm2-slack-1.0.0.tgz' or '[email protected] '.
160
166
*/
161
- packageNameToModuleName : function ( package_name ) {
162
- if ( package_name . match ( / ^ ( .+ \/ ) ? ( [ ^ \/ ] + ) \. t g z ( $ | \? ) / ) ) {
163
- package_name = package_name . match ( / ^ ( .+ \/ ) ? ( [ ^ \/ ] + ) \. t g z ( $ | \? ) / ) [ 2 ] ;
164
- if ( package_name . match ( / ^ ( .+ ) - [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ( - [ a - z A - Z 0 - 9 _ ] + \. [ 0 - 9 ] + ) ? $ / ) ) {
165
- package_name = package_name . match ( / ^ ( .+ ) - [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ( - [ a - z A - Z 0 - 9 _ ] + \. [ 0 - 9 ] + ) ? $ / ) [ 1 ] ;
167
+ getCanonicModuleName : function ( module_name ) {
168
+ var canonic_module_name = module_name ;
169
+
170
+ // Returns the module name from a .tgz package name (or the original name if it is not a valid pkg).
171
+ // Input: The package name (e.g. "foo.tgz", "foo-1.0.0.tgz", "folder/foo.tgz")
172
+ // Output: The module name
173
+ if ( canonic_module_name . match ( / \. t g z ( $ | \? ) / ) ) {
174
+ if ( canonic_module_name . match ( / ^ ( .+ \/ ) ? ( [ ^ \/ ] + ) \. t g z ( $ | \? ) / ) ) {
175
+ canonic_module_name = canonic_module_name . match ( / ^ ( .+ \/ ) ? ( [ ^ \/ ] + ) \. t g z ( $ | \? ) / ) [ 2 ] ;
176
+ if ( canonic_module_name . match ( / ^ ( .+ ) - [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ( - [ a - z A - Z 0 - 9 _ ] + \. [ 0 - 9 ] + ) ? $ / ) ) {
177
+ canonic_module_name = canonic_module_name . match ( / ^ ( .+ ) - [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ( - [ a - z A - Z 0 - 9 _ ] + \. [ 0 - 9 ] + ) ? $ / ) [ 1 ] ;
178
+ }
166
179
}
167
180
}
168
- return package_name ;
181
+
182
+ //pm2 install username/module
183
+ else if ( canonic_module_name . indexOf ( '/' ) !== - 1 ) {
184
+ canonic_module_name = canonic_module_name . split ( '/' ) [ 1 ] ;
185
+ }
186
+
187
+
188
+ if ( canonic_module_name . indexOf ( '@' ) !== - 1 ) {
189
+ canonic_module_name = canonic_module_name . split ( '@' ) [ 0 ] ;
190
+ }
191
+
192
+ //pm2 install module#some-branch
193
+ if ( canonic_module_name . indexOf ( '#' ) !== - 1 ) {
194
+ canonic_module_name = canonic_module_name . split ( '#' ) [ 0 ] ;
195
+ }
196
+
197
+ return canonic_module_name ;
169
198
}
170
199
171
200
} ;
0 commit comments