Skip to content

Commit

Permalink
fix:GH-1502 name root from package json (#1503)
Browse files Browse the repository at this point in the history
* fix:GH-1502 name root from package json

Signed-off-by: Ivan Alvarez Sabin <[email protected]>

* fix:GH-1502 name root from package json

Signed-off-by: Ivan Alvarez Sabin <[email protected]>

---------

Signed-off-by: Ivan Alvarez Sabin <[email protected]>
  • Loading branch information
ivanasabi authored Dec 23, 2024
1 parent 5260843 commit 50a2d4f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2537,9 +2537,28 @@ export async function createNodejsBom(path, options) {
// Parse package-lock.json if available
const parsedList = await parsePkgLock(f, options);
const dlist = parsedList.pkgList;
const tmpParentComponent = dlist.splice(0, 1)[0] || {};
tmpParentComponent.type = "application";
let tmpParentComponent = dlist.splice(0, 1)[0] || {};
if (!Object.keys(parentComponent).length) {
const basePath = dirname(f);
const packageJsonF = join(basePath, "package.json");
if (existsSync(packageJsonF)) {
const pcs = await parsePkgJson(packageJsonF, true);
if (pcs.length) {
tmpParentComponent = pcs[0];
tmpParentComponent.type = "application";
tmpParentComponent.name = "project-name" in options ? options.projectName : tmpParentComponent.name;
ppurl = new PackageURL(
"npm",
options.projectGroup || tmpParentComponent.group,
"project-name" in options ? options.projectName : tmpParentComponent.name,
options.projectVersion || tmpParentComponent.version,
null,
null,
).toString();
tmpParentComponent["bom-ref"] = decodeURIComponent(ppurl);
tmpParentComponent["purl"] = ppurl;
}
}
parentComponent = tmpParentComponent;
} else {
parentSubComponents.push(tmpParentComponent);
Expand Down

0 comments on commit 50a2d4f

Please sign in to comment.