Skip to content

Commit d36dcde

Browse files
authored
Multiple fixes (#25)
* src: handle malformed JSON better Report an error if the JSON in package-support.json is malformed instead of silently failing Signed-off-by: Michael Dawson <[email protected]> * src: validate as per spec for backing Allow backing to be an array a the top level as per the spec: https://github.com/nodejs/package-maintenance/blob/main/docs/PACKAGE-SUPPORT.md#support-backing
1 parent 4073b01 commit d36dcde

File tree

14 files changed

+85
-8
lines changed

14 files changed

+85
-8
lines changed

lib/cli/commands/validate.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,21 @@ module.exports = function (opts) {
4646
argv['base-path'],
4747
argv.fetch);
4848
if (supportData.resolved) {
49-
const supportDataJSON = JSON.parse(supportData.contents);
5049
try {
51-
const result = support.validate(supportDataJSON, true);
52-
if (result) {
53-
console.log('Your support information is valid!');
54-
return;
50+
const supportDataJSON = JSON.parse(supportData.contents);
51+
try {
52+
const result = support.validate(supportDataJSON, true);
53+
if (result) {
54+
console.log('Your support information is valid!');
55+
return;
56+
}
57+
} catch (e) {
58+
console.log('Error in support JSON');
59+
console.log(e.prettyValidationErrors);
5560
}
5661
} catch (e) {
57-
console.log('Error in support JSON');
58-
console.log(e.prettyValidationErrors);
62+
console.log('Your support information is not properly formed');
63+
console.log(e.message);
5964
}
6065
} else {
6166
console.log('support info not resolved: ' + supportData.url);

schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@
3333
"items": { "$ref": "#SupportResponse" }
3434
}]
3535
},
36-
"backing": { "$ref": "#SupportBacking" }
36+
"backing": {
37+
"oneOf": [{
38+
"$ref": "#SupportBacking"
39+
}, {
40+
"type": "array",
41+
"minItems": 1,
42+
"items": { "$ref": "#SupportBacking" }
43+
}]
44+
}
3745
},
3846
"additionalProperties": false
3947
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
validate
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Your support information is not properly formed
2+
Unexpected end of JSON input

test/cli/validate-invalid-json/package-support.json

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@pkgjs/validate-multiple-backing",
3+
"version": "0.0.1",
4+
"support": true
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
validate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Your support information is valid!
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"versions": [
3+
{
4+
"version": "*",
5+
"target": {
6+
"node": "lts"
7+
},
8+
"response": {
9+
"type": "time-permitting",
10+
"paid": false,
11+
"contact": {
12+
"name": "node-addon-api team",
13+
"url": "https://github.com/nodejs/node-addon-api/issues"
14+
}
15+
},
16+
"backing": [
17+
{ "project": "https://github.com/nodejs" },
18+
{ "foundation": "https://openjsf.org/" }
19+
]
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@pkgjs/validate-multiple-backing",
3+
"version": "0.0.1",
4+
"support": true
5+
}

0 commit comments

Comments
 (0)