Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 88F0C1941C for ; Wed, 13 Apr 2016 07:25:43 +0000 (UTC) Received: (qmail 52680 invoked by uid 500); 13 Apr 2016 07:25:43 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 52644 invoked by uid 500); 13 Apr 2016 07:25:42 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 52633 invoked by uid 99); 13 Apr 2016 07:25:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Apr 2016 07:25:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4EEA0DFCE0; Wed, 13 Apr 2016 07:25:42 +0000 (UTC) From: vladimir-kotikov To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request: CB-10986: Adding support for scoped npm ... Content-Type: text/plain Message-Id: <20160413072542.4EEA0DFCE0@git1-us-west.apache.org> Date: Wed, 13 Apr 2016 07:25:42 +0000 (UTC) Github user vladimir-kotikov commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/425#discussion_r59503554 --- Diff: cordova-lib/src/cordova/plugin_spec_parser.js --- @@ -0,0 +1,61 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +// npm packages follow the pattern of (@scope/)?package(@spec)? where scope and tag are optional +var NPM_SPEC_REGEX = /^(@[^\/]+\/)?([^@\/]+)(?:@(.+))?$/; + +module.exports.parse = parse; + +/** + * Represents a parsed specification for a plugin + * @class + * @param {String} raw The raw specification (i.e. provided by the user) + * @param {String} scope The scope of the package if this is an npm package + * @param {String} id The id of the package if this is an npm package + * @param {String} version The version specified for the package if this is an npm package + */ +function PluginSpec(raw, scope, id, version) { + /** @member {String|null} The npm scope of the plugin spec or null if it does not have one */ + this.scope = scope || null; + + /** @member {String|null} The id of the plugin or the raw plugin spec if it is not an npm package */ + this.id = id || raw; + + /** @member {String|null} The specified version of the plugin or null if no version was specified */ + this.version = version || null; + + /** @member {String|null} The npm package of the plugin (with scope) or null if this is not a spec for an npm package */ + this.package = (scope ? scope + id : id) || null; +} + +/** + * Tries to parse the given string as an npm-style package specification of + * the form (@scope/)?package(@version)? and return the various parts. + * + * @param {String} raw The string to be parsed + * @param {PluginSpec} The parsed plugin spec + */ +function parse(raw) { + var split = NPM_SPEC_REGEX.exec(raw); + if (split) { + return new PluginSpec(raw, split[1], split[2], split[3]); + } else { --- End diff -- Not an issue, but `else` is not necessary here --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org