From 74af42c176025fe2490d4637ac562da9fcc5e185 Mon Sep 17 00:00:00 2001 From: Martin Page Date: Wed, 28 Mar 2018 12:16:09 +0100 Subject: [PATCH] Only replace last `@` after (if any) last `/` with `#` (#2395) --- lib/commands/info.js | 45 ++++++++++++++++++++++------------------- lib/commands/install.js | 16 +++++++++------ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/commands/info.js b/lib/commands/info.js index 28cac378b..ae9b9ab6f 100644 --- a/lib/commands/info.js +++ b/lib/commands/info.js @@ -10,7 +10,10 @@ function info(logger, endpoint, property, config) { } // handle @ as version divider - endpoint = endpoint.replace('@', '#'); + var splitParts = endpoint.split('/'); + splitParts[splitParts.length - 1] = splitParts[splitParts.length - 1].replace('@', '#'); + endpoint = splitParts.join('/'); + var repository; var decEndpoint; @@ -24,33 +27,33 @@ function info(logger, endpoint, property, config) { getPkgMeta(repository, decEndpoint, property), decEndpoint.target === '*' && !property ? repository.versions(decEndpoint.source) : null ]) - .spread(function (pkgMeta, versions) { - if (versions) { - return { - name: decEndpoint.source, - versions: versions, - latest: pkgMeta - }; - } + .spread(function (pkgMeta, versions) { + if (versions) { + return { + name: decEndpoint.source, + versions: versions, + latest: pkgMeta + }; + } - return pkgMeta; - }); + return pkgMeta; + }); } function getPkgMeta(repository, decEndpoint, property) { return repository.fetch(decEndpoint) - .spread(function (canonicalDir, pkgMeta) { - pkgMeta = mout.object.filter(pkgMeta, function (value, key) { - return key.charAt(0) !== '_'; - }); + .spread(function (canonicalDir, pkgMeta) { + pkgMeta = mout.object.filter(pkgMeta, function (value, key) { + return key.charAt(0) !== '_'; + }); - // Retrieve specific property - if (property) { - pkgMeta = mout.object.get(pkgMeta, property); - } + // Retrieve specific property + if (property) { + pkgMeta = mout.object.get(pkgMeta, property); + } - return pkgMeta; - }); + return pkgMeta; + }); } // ------------------- diff --git a/lib/commands/install.js b/lib/commands/install.js index 6e6b6fc55..c2b87dedf 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -16,8 +16,12 @@ function install(logger, endpoints, options, config) { // Convert endpoints to decomposed endpoints endpoints = endpoints || []; decEndpoints = endpoints.map(function (endpoint) { + // handle @ as version divider - endpoint = endpoint.replace('@', '#'); + var splitParts = endpoint.split('/'); + splitParts[splitParts.length - 1] = splitParts[splitParts.length - 1].replace('@', '#'); + endpoint = splitParts.join('/'); + return endpointParser.decompose(endpoint); }); @@ -30,11 +34,11 @@ install.readOptions = function (argv) { var cli = require('../util/cli'); var options = cli.readOptions({ - 'force-latest': { type: Boolean, shorthand: 'F'}, - 'production': { type: Boolean, shorthand: 'p' }, - 'save': { type: Boolean, shorthand: 'S' }, - 'save-dev': { type: Boolean, shorthand: 'D' }, - 'save-exact': { type: Boolean, shorthand: 'E' } + 'force-latest': {type: Boolean, shorthand: 'F'}, + 'production': {type: Boolean, shorthand: 'p'}, + 'save': {type: Boolean, shorthand: 'S'}, + 'save-dev': {type: Boolean, shorthand: 'D'}, + 'save-exact': {type: Boolean, shorthand: 'E'} }, argv); var packages = options.argv.remain.slice(1);