Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't require version or name if package has "private": true #87

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions PJV.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

var PJV = exports.PJV;

PJV.getSpecMap = function (specName) {
PJV.getSpecMap = function (specName, isPrivate) {

if (specName == "npm") {
// https://docs.npmjs.com/cli/v9/configuring-npm/package-json
return {
"name": {"type": "string", required: true, format: PJV.packageFormat},
"version": {"type": "string", required: true, format: PJV.versionFormat},
"name": {"type": "string", required: !isPrivate, format: PJV.packageFormat},
"version": {"type": "string", required: !isPrivate, format: PJV.versionFormat},
"description": {"type": "string", warning: true},
"keywords": {"type": "array", warning: true},
"homepage": {"type": "string", recommended: true, format: PJV.urlFormat},
Expand Down Expand Up @@ -140,7 +140,7 @@
return out;
}

var map = PJV.getSpecMap(specName);
var map = PJV.getSpecMap(specName, parsed.private);
if (specName === false) {
out.critical = {"Invalid specification": specName};
return out;
Expand Down
8 changes: 8 additions & 0 deletions test/qunit-pjv.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ QUnit.test("Required fields", function() {
QUnit.equal(result.valid, false, JSON.stringify(result));
QUnit.equal(result.warnings, undefined, JSON.stringify(result));
});
["name", "version"].forEach(function(field) {
json = getPackageJson();
json['private'] = true;
delete json[field];
result = PJV.validate(JSON.stringify(json), "npm", {warnings: false, recommendations: false});
QUnit.equal(result.valid, true, JSON.stringify(result));
QUnit.equal(result.warnings, undefined, JSON.stringify(result));
});
});


Expand Down