normalize all of package.json

use different module, catch throws, and still remove the ‘git’ prefix
from urls.
This commit is contained in:
Jessica Lord
2015-05-04 15:04:03 -07:00
parent ab817d9b27
commit 97ad2f30e0
2 changed files with 5 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
path = require 'path'
hostedGitInfo = require 'hosted-git-info'
normalizePackageData = require 'normalize-package-data'
_ = require 'underscore-plus'
async = require 'async'
@@ -27,15 +27,8 @@ class Package
@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\+/, '')
normalizePackageData(metadata)
metadata.repository.url = metadata.repository.url.replace(/^git\+/, '')
@loadMetadata: (packagePath, ignoreErrors=false) ->
packageName = path.basename(packagePath)
@@ -45,12 +38,12 @@ class Package
if metadataPath = CSON.resolve(path.join(packagePath, 'package'))
try
metadata = CSON.readFileSync(metadataPath)
@normalizeMetadata(metadata)
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})