parse npm pack output as JSON - #380
Conversation
kriszyp
left a comment
There was a problem hiding this comment.
This looks great, I like this approach.
| throw new Error(`npm pack produced no JSON output for ${application.packageIdentifier}:\n${stdout}`); | ||
| } | ||
|
|
||
| const [{ filename }] = JSON.parse(stdout.slice(jsonStart)) as [{ filename: string }]; |
There was a problem hiding this comment.
Can this return an object or something with an error? (something other than a filename?) is it worth checking for that?
There was a problem hiding this comment.
good point, added a shape check 6a49434
do you think this would do?
| throw new Error(`Failed to download package ${application.packageIdentifier}: ${stderr}`); | ||
| } | ||
|
|
||
| const jsonStart = stdout.indexOf('['); |
There was a problem hiding this comment.
Do we need to do this? Assuming a success exit code, the output should be only valid JSON.
There was a problem hiding this comment.
fair, folded it into the slice. still keeping --json tho, lifecycle output can land on stdout before the array
| throw new Error(`npm pack produced no JSON output for ${application.packageIdentifier}:\n${stdout}`); | ||
| } | ||
|
|
||
| const packResult = JSON.parse(stdout.slice(jsonStart)); |
There was a problem hiding this comment.
Consider wrapping JSON.parse() in a try/catch so we can prepend some context to the error message.
closes #379