Skip to content
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
21 changes: 16 additions & 5 deletions pkg/dependency/parser/nodejs/bun/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,23 @@ func (p *ParsedPackage) UnmarshalJSON(data []byte) error {
return err
}

if len(raw) > 2 {
if err := json.Unmarshal(raw[2], &p.Meta); err != nil {
return err
}
// When package contains only package field [pkg: string]
// cf. https://github.com/oven-sh/bun/blob/61e03a275885b9b48f7a28f6dfbbbe1156eedca6/packages/bun-types/bun.d.ts#L7751
if len(raw) == 1 {
return nil
}

// Meta can be 2 or 3 array elements
// [pkg: string, info: BunLockFilePackageInfo]
// [pkg: string, info: BunLockFilePackageInfo, bunTag: string]
// [pkg: string, info: Pick<BunLockFileBasePackageInfo, "bin" | "binDir">]
// [pkg: string, registry: string, info: BunLockFilePackageInfo, integrity: string]
// cf.https://github.com/oven-sh/bun/blob/61e03a275885b9b48f7a28f6dfbbbe1156eedca6/packages/bun-types/bun.d.ts#L7745-L7755
metaRaw := raw[1]
if len(raw) > 3 {
metaRaw = raw[2]
}
return nil
return json.Unmarshal(metaRaw, &p.Meta)

Choose a reason for hiding this comment

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

note that bun.lock uses JSONC, which means it may have trailing commas and comments in the file. comments are unlikely, but commas are more likely as bun.lock does generate them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @connerlphillippi
Thanks!

We already found that and write unmarshaler for JSONC - #8862

}

func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependency, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/dependency/parser/nodejs/bun/testdata/bun_happy.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-v1DKRfUdyW+jJhZNEI1PYy29S2YRxMV5AOO/x/SjKmW0acCIOqmbj6Haf9eHAhsPmrhlHSxEhv/1WszcLWV4cg=="],

"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-rRjA1T6n7wto4gxhAO/ErZEtOXyEZEmnIHQfl0Dt1QQSB4QV0iP6BZ9/YB5fZaHFQ2dwHFrmPaRQ9GGMX01k9Q=="],
"bun-types": ["[email protected]", { "dependencies": { "@types/node": "*" } }, "sha512-rRjA1T6n7wto4gxhAO/ErZEtOXyEZEmnIHQfl0Dt1QQSB4QV0iP6BZ9/YB5fZaHFQ2dwHFrmPaRQ9GGMX01k9Q=="],

"typescript": ["[email protected]", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],

"undici-types": ["[email protected]", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
"undici-types": ["[email protected]"],

"zod": ["[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-OdqJE9UDRPwWsrHjLN2F8bPxvwJBK22EHLWtanu0LSYr5YqzsaaW3RMgmjwr8Rypg5k+meEJdSPXJZXE/yqOMg=="],
}
Expand Down