Skip to content

parse npm pack output as JSON - #380

Merged
kriszyp merged 5 commits into
v5.0from
npm-pack-stdout-parsing
Apr 20, 2026
Merged

parse npm pack output as JSON#380
kriszyp merged 5 commits into
v5.0from
npm-pack-stdout-parsing

Conversation

@ldt1996

@ldt1996 ldt1996 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

closes #379

@ldt1996
ldt1996 requested a review from a team as a code owner April 18, 2026 19:38

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, I like this approach.

Comment thread components/Application.ts Outdated
throw new Error(`npm pack produced no JSON output for ${application.packageIdentifier}:\n${stdout}`);
}

const [{ filename }] = JSON.parse(stdout.slice(jsonStart)) as [{ filename: string }];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this return an object or something with an error? (something other than a filename?) is it worth checking for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, added a shape check 6a49434
do you think this would do?

Comment thread components/Application.ts Outdated
throw new Error(`Failed to download package ${application.packageIdentifier}: ${stderr}`);
}

const jsonStart = stdout.indexOf('[');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this? Assuming a success exit code, the output should be only valid JSON.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair, folded it into the slice. still keeping --json tho, lifecycle output can land on stdout before the array

Comment thread components/Application.ts Outdated
throw new Error(`npm pack produced no JSON output for ${application.packageIdentifier}:\n${stdout}`);
}

const packResult = JSON.parse(stdout.slice(jsonStart));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrapping JSON.parse() in a try/catch so we can prepend some context to the error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ldt1996
ldt1996 changed the base branch from main to v5.0 April 20, 2026 19:11
@ldt1996
ldt1996 requested a review from a team as a code owner April 20, 2026 19:11

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you

@kriszyp
kriszyp merged commit cbeb88b into v5.0 Apr 20, 2026
21 of 22 checks passed
@kriszyp
kriszyp deleted the npm-pack-stdout-parsing branch April 20, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deploy_component fails to parse npm pack stdout when lifecycle scripts run

3 participants