diff --git a/lib/cli/index.js b/lib/cli/index.js index 40b67208d..121049414 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -2537,9 +2537,27 @@ 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"; + 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);