Always strip git+ prefix and .git suffix from package repository URLs

Previously, a guard based on the presence of the _id field (which is
inserted by npm during installation) prevented a regex replacement of
the git+ prefix on URLs. Now we always do this. Since the .git suffix
also causes problems and we’re removing that in packages, I now remove
that as well.
This commit is contained in:
Nathan Sobo
2016-02-29 17:30:03 -07:00
parent 920d348014
commit 6292484c97
3 changed files with 17 additions and 3 deletions

View File

@@ -541,11 +541,12 @@ class PackageManager
unless typeof metadata.name is 'string' and metadata.name.length > 0
metadata.name = packageName
if metadata.repository?.type is 'git' and typeof metadata.repository.url is 'string'
metadata.repository.url = metadata.repository.url.replace(/(^git\+)|(\.git$)/g, '')
metadata
normalizePackageMetadata: (metadata) ->
unless metadata?._id
normalizePackageData ?= require 'normalize-package-data'
normalizePackageData(metadata)
if metadata.repository?.type is 'git' and typeof metadata.repository.url is 'string'
metadata.repository.url = metadata.repository.url.replace(/^git\+/, '')