normalize-package-data
Advanced tools
Comparing version 1.0.3 to 2.0.0
var semver = require("semver") | ||
var parseGitHubURL = require("github-url-from-git") | ||
var hostedGitInfo = require("hosted-git-info") | ||
var depTypes = ["dependencies","devDependencies","optionalDependencies"] | ||
@@ -8,3 +8,2 @@ var extractDescription = require("./extract_description") | ||
var coreModuleNames = require("./core_module_names") | ||
var githubUserRepo = require("github-url-from-username-repo") | ||
@@ -29,8 +28,6 @@ var fixer = module.exports = { | ||
if (r) { | ||
var ghurl = parseGitHubURL(r) | ||
if (ghurl) { | ||
r = ghurl.replace(/^https?:\/\//, 'git://') | ||
} else if (githubUserRepo(r)) { | ||
// repo has 'user/reponame' filled in as repo | ||
data.repository.url = githubUserRepo(r) | ||
var hosted = hostedGitInfo.fromUrl(r) | ||
if (hosted) { | ||
r = data.repository.url | ||
= hosted.getDefaultRepresentation() == "shortcut" ? hosted.https() : hosted.toString() | ||
} | ||
@@ -62,3 +59,3 @@ } | ||
delete data.scripts[k] | ||
} else if (typos.script[k]) { | ||
} else if (typos.script[k] && !data.scripts[typos.script[k]]) { | ||
this.warn("typo", k, typos.script[k], "scripts") | ||
@@ -149,7 +146,4 @@ } | ||
} | ||
// "/" is not allowed as packagename for publishing, but for git-urls | ||
// normalize shorthand-urls | ||
if (githubUserRepo(data[deps][d])) { | ||
data[deps][d] = 'git+' + githubUserRepo(data[deps][d]) | ||
} | ||
var hosted = hostedGitInfo.fromUrl(data[deps][d]) | ||
if (hosted) data[deps][d] = hosted.toString() | ||
}, this) | ||
@@ -241,8 +235,5 @@ }, this) | ||
if (!data.bugs && data.repository && data.repository.url) { | ||
var gh = parseGitHubURL(data.repository.url) | ||
if(gh) { | ||
if(gh.match(/^https:\/\/github.com\//)) | ||
data.bugs = {url: gh + "/issues"} | ||
else // gist url | ||
data.bugs = {url: gh} | ||
var hosted = hostedGitInfo.fromUrl(data.repository.url) | ||
if(hosted && hosted.bugs()) { | ||
data.bugs = {url: hosted.bugs()} | ||
} | ||
@@ -286,9 +277,6 @@ } | ||
if (!data.homepage && data.repository && data.repository.url) { | ||
var gh = parseGitHubURL(data.repository.url) | ||
if (gh) | ||
data.homepage = gh | ||
else | ||
return true | ||
} else if (!data.homepage) | ||
return true | ||
var hosted = hostedGitInfo.fromUrl(data.repository.url) | ||
if (hosted && hosted.docs()) data.homepage = hosted.docs() | ||
} | ||
if (!data.homepage) return | ||
@@ -295,0 +283,0 @@ if(typeof data.homepage !== "string") { |
{ | ||
"name": "normalize-package-data", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"author": "Meryn Stol <merynstol@gmail.com>", | ||
@@ -8,3 +8,3 @@ "description": "Normalizes data that can be found in package.json files.", | ||
"type": "git", | ||
"url": "git://github.com/meryn/normalize-package-data.git" | ||
"url": "git://github.com/npm/normalize-package-data.git" | ||
}, | ||
@@ -16,4 +16,3 @@ "main": "lib/normalize.js", | ||
"dependencies": { | ||
"github-url-from-git": "^1.3.0", | ||
"github-url-from-username-repo": "^1.0.0", | ||
"hosted-git-info": "^2.0.2", | ||
"semver": "2 || 3 || 4" | ||
@@ -20,0 +19,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# normalize-package-data [![Build Status](https://travis-ci.org/meryn/normalize-package-data.png?branch=master)](https://travis-ci.org/meryn/normalize-package-data) | ||
# normalize-package-data [![Build Status](https://travis-ci.org/npm/normalize-package-data.png?branch=master)](https://travis-ci.org/npm/normalize-package-data) | ||
@@ -71,5 +71,7 @@ normalize-package data exports a function that normalizes package metadata. This data is typically found in a package.json file, but in principle could come from any source - for example the npm registry. | ||
* The values in `optionalDependencies` get added to `dependencies`. The `optionalDependencies` array is left untouched. | ||
* As of v2: Dependencies that point at known hosted git providers (currently: github, bitbucket, gitlab) will have their URLs canonicalized, but protocols will be preserved. | ||
* As of v2: Dependencies that use shortcuts for hosted git providers (`org/proj`, `github:org/proj`, `bitbucket:org/proj`, `gitlab:org/proj`, `gist:docid`) will have the shortcut left in place. (In the case of github, the `org/proj` form will be expanded to `github:org/proj`.) THIS MARKS A BREAKING CHANGE FROM V1, where the shorcut was previously expanded to a URL. | ||
* If `description` field does not exist, but `readme` field does, then (more or less) the first paragraph of text that's found in the readme is taken as value for `description`. | ||
* If `repository` field is a string, it will become an object with `url` set to the original string value, and `type` set to `"git"`. | ||
* If `repository.url` is not a valid url, but in the style of "[owner-name]/[repo-name]", `repository.url` will be set to git://github.com/[owner-name]/[repo-name] | ||
* If `repository.url` is not a valid url, but in the style of "[owner-name]/[repo-name]", `repository.url` will be set to https://github.com/[owner-name]/[repo-name] | ||
* If `bugs` field is a string, the value of `bugs` field is changed into an object with `url` set to the original string value. | ||
@@ -76,0 +78,0 @@ * If `bugs` field does not exist, but `repository` field points to a repository hosted on GitHub, the value of the `bugs` field gets set to an url in the form of https://github.com/[owner-name]/[repo-name]/issues . If the repository field points to a GitHub Gist repo url, the associated http url is chosen. |
@@ -12,2 +12,3 @@ var tap = require("tap") | ||
var rpjPath = path.resolve(__dirname,"./fixtures/read-package-json.json") | ||
tap.test("normalize some package data", function(t) { | ||
@@ -147,3 +148,3 @@ var packageData = require(rpjPath) | ||
normalize(d) | ||
t.same(d.repository, { type: 'git', url: 'git@gist.github.com:123456.git' }) | ||
t.same(d.repository, { type: 'git', url: 'git+ssh://git@gist.github.com/123456.git' }) | ||
t.same(d.bugs, { url: 'https://gist.github.com/123456' }) | ||
@@ -156,3 +157,3 @@ t.end(); | ||
normalize(d) | ||
t.same(d.repository, { type: 'git', url: 'git@gist.github.com:123456.git' }) | ||
t.same(d.repository, { type: 'git', url: 'git+ssh://git@gist.github.com/123456.git' }) | ||
t.end() | ||
@@ -164,3 +165,3 @@ }); | ||
normalize(d) | ||
t.same(d.repository, { type: "git", url: "https://github.com/visionmedia/express" }) | ||
t.same(d.repository, { type: "git", url: "https://github.com/visionmedia/express.git" }) | ||
t.end() | ||
@@ -172,3 +173,3 @@ }); | ||
normalize(d) | ||
t.same(d.repository, { type: "git", url: "https://github.com/isaacs/node-graceful-fs" }) | ||
t.same(d.repository, { type: "git", url: "https://github.com/isaacs/node-graceful-fs.git" }) | ||
t.end() | ||
@@ -182,3 +183,3 @@ }); | ||
}) | ||
t.same(a.homepage, 'https://github.com/isaacs/node-graceful-fs') | ||
t.same(a.homepage, 'https://github.com/isaacs/node-graceful-fs#readme') | ||
t.end() | ||
@@ -201,10 +202,10 @@ }) | ||
}) | ||
t.same(a.homepage, 'https://github.com/sindresorhus/chalk') | ||
t.same(a.homepage, 'https://github.com/sindresorhus/chalk#readme') | ||
t.end() | ||
}) | ||
tap.test("treat isaacs/node-graceful-fs as github repo in dependencies", function(t) { | ||
tap.test("don't mangle github shortcuts in dependencies", function(t) { | ||
var d = {dependencies: {"node-graceful-fs": "isaacs/node-graceful-fs"}} | ||
normalize(d) | ||
t.same(d.dependencies, {"node-graceful-fs": "git+https://github.com/isaacs/node-graceful-fs" }) | ||
t.same(d.dependencies, {"node-graceful-fs": "github:isaacs/node-graceful-fs" }) | ||
t.end() | ||
@@ -211,0 +212,0 @@ }); |
@@ -105,2 +105,15 @@ var test = require('tap').test | ||
warnings.length = 0 | ||
expect = | ||
[ warningMessages.missingDescription, | ||
warningMessages.missingRepository, | ||
warningMessages.missingReadme ] | ||
normalize({name:"name" | ||
,version:"1.2.5" | ||
,scripts:{server:"start",tests:"test" | ||
,start:"start",test:"test"}}, warn) | ||
t.same(warnings, expect) | ||
warnings.length = 0 | ||
expect = [] | ||
@@ -107,0 +120,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61267
2
34
104
1490
1
+ Addedhosted-git-info@^2.0.2
+ Addedhosted-git-info@2.8.9(transitive)
- Removedgithub-url-from-git@^1.3.0
- Removedgithub-url-from-username-repo@^1.0.0
- Removedgithub-url-from-git@1.5.0(transitive)
- Removedgithub-url-from-username-repo@1.0.2(transitive)