Normalize repository short urls

This commit is contained in:
Jessica Lord
2015-04-30 11:22:52 -07:00
parent cf1e8c8706
commit 9dfd1ac5aa
2 changed files with 18 additions and 0 deletions

View File

@@ -38,6 +38,7 @@
"fuzzaldrin": "^2.1",
"git-utils": "^3.0.0",
"grim": "1.4.0",
"hosted-git-info": "^2.1.2",
"jasmine-json": "~0.0",
"jasmine-tagged": "^1.1.4",
"jquery": "^2.1.1",

View File

@@ -1,4 +1,5 @@
path = require 'path'
hostedGitInfo = require 'hosted-git-info'
_ = require 'underscore-plus'
async = require 'async'
@@ -24,6 +25,20 @@ class Package
@resourcePathWithTrailingSlash ?= "#{atom.packages.resourcePath}#{path.sep}"
packagePath?.startsWith(@resourcePathWithTrailingSlash)
@normalizeMetadata: (metadata) ->
if typeof metadata.repository is 'string'
metadata.repository =
type: 'git'
url: metadata.repository
repoUrl = metadata.repository?.url
if repoUrl
info = hostedGitInfo.fromUrl(repoUrl)
if info.getDefaultRepresentation() is 'shortcut'
metadata.repository.url = info.https().replace(/^git\+/, '')
else
metadata.repository.url = info.toString()
@loadMetadata: (packagePath, ignoreErrors=false) ->
packageName = path.basename(packagePath)
if @isBundledPackagePath(packagePath)
@@ -34,8 +49,10 @@ class Package
metadata = CSON.readFileSync(metadataPath)
catch error
throw error unless ignoreErrors
metadata ?= {}
metadata.name = packageName
@normalizeMetadata(metadata)
if includeDeprecatedAPIs and metadata.stylesheetMain?
deprecate("Use the `mainStyleSheet` key instead of `stylesheetMain` in the `package.json` of `#{packageName}`", {packageName})