Skip to content

Commit

Permalink
Merge branch 'master' into gopkg-vcsurl
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Baryshnikov <a.baryshnikov@bi.zone>
  • Loading branch information
CaMoPeZzz committed Dec 23, 2024
2 parents 0ae6ac3 + 5260843 commit 0485787
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 99 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@appthreat/cdx-proto": "npm:@appthreat/cdx-proto@1.0.1",
"@babel/parser": "npm:@babel/parser@^7.26.3",
"@babel/traverse": "npm:@babel/traverse@^7.26.4",
"@npmcli/arborist": "npm:@npmcli/arborist@8.0.0",
"@npmcli/arborist": "npm:@npmcli/arborist@9.0.0",
"ajv": "npm:ajv@^8.16.0",
"ajv-formats": "npm:ajv-formats@^3.0.1",
"cheerio": "npm:cheerio@^1.0.0-rc.12",
Expand Down
12 changes: 6 additions & 6 deletions lib/evinser/evinser.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export async function createSlice(
options = {},
) {
if (!filePath) {
return;
return undefined;
}
const firstLanguage = Array.isArray(purlOrLanguages)
? purlOrLanguages[0]
Expand All @@ -227,7 +227,7 @@ export async function createSlice(
PROJECT_TYPE_ALIASES.swift.includes(language) &&
sliceType !== "semantics"
) {
return;
return undefined;
}

let sliceOutputDir = fs.mkdtempSync(
Expand Down Expand Up @@ -388,7 +388,7 @@ export async function analyzeProject(dbObjMap, options) {
fs.readFileSync(options.reachablesSlicesFile, "utf-8"),
);
} else {
retMap = createSlice(language, dirPath, "reachables", options);
retMap = await createSlice(language, dirPath, "reachables", options);
if (retMap?.slicesFile && fs.existsSync(retMap.slicesFile)) {
reachablesSlicesFile = retMap.slicesFile;
reachablesSlice = JSON.parse(
Expand All @@ -409,7 +409,7 @@ export async function analyzeProject(dbObjMap, options) {
usagesSlicesFile = options.usagesSlicesFile;
} else {
// Generate our own slices
retMap = createSlice(language, dirPath, "usages", options);
retMap = await createSlice(language, dirPath, "usages", options);
if (retMap?.slicesFile && fs.existsSync(retMap.slicesFile)) {
usageSlice = JSON.parse(fs.readFileSync(retMap.slicesFile, "utf-8"));
usagesSlicesFile = retMap.slicesFile;
Expand All @@ -428,7 +428,7 @@ export async function analyzeProject(dbObjMap, options) {
semanticsSlicesFile = options.semanticsSlicesFile;
} else {
// Generate our own slices
retMap = createSlice(language, dirPath, "semantics", options);
retMap = await createSlice(language, dirPath, "semantics", options);
if (retMap?.slicesFile && fs.existsSync(retMap.slicesFile)) {
semanticsSlice = JSON.parse(
fs.readFileSync(retMap.slicesFile, "utf-8"),
Expand Down Expand Up @@ -471,7 +471,7 @@ export async function analyzeProject(dbObjMap, options) {
fs.readFileSync(options.dataFlowSlicesFile, "utf-8"),
);
} else {
retMap = createSlice(language, dirPath, "data-flow", options);
retMap = await createSlice(language, dirPath, "data-flow", options);
if (retMap?.slicesFile && fs.existsSync(retMap.slicesFile)) {
dataFlowSlicesFile = retMap.slicesFile;
dataFlowSlice = JSON.parse(fs.readFileSync(retMap.slicesFile, "utf-8"));
Expand Down
15 changes: 13 additions & 2 deletions lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,13 @@ export function parsePom(pomFile) {
).toString();
}
if (project?.modules?.module) {
modules = project.modules.module.map((m) => m?._);
if (Array.isArray(project.modules.module)) {
// If it's an array, proceed with mapping
modules = project.modules.module.map((m) => m?._);
} else {
// If not an array, handle/convert it accordingly. For instance:
modules = [project.modules.module._];
}
}
if (project?.properties) {
for (const aprop of Object.keys(project.properties)) {
Expand Down Expand Up @@ -12837,15 +12843,20 @@ export function isPartialTree(dependencies, componentsCount = 1) {
if (dependencies?.length <= 1) {
return true;
}
let isCbom = false;
let parentsWithChildsCount = 0;
for (const adep of dependencies) {
if (adep?.dependsOn.length > 0) {
parentsWithChildsCount++;
}
if (!isCbom && adep?.provides?.length > 0) {
isCbom = true;
}
}
return (
!isCbom &&
parentsWithChildsCount <
Math.min(Math.round(componentsCount / 3), componentsCount)
Math.min(Math.round(componentsCount / 3), componentsCount)
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3519,8 +3519,8 @@ test("parsePnpmLock", async () => {
expect(parsedList.dependenciesList).toHaveLength(462);
expect(parsedList.pkgList.filter((pkg) => !pkg.scope)).toHaveLength(3);
parsedList = await parsePnpmLock("./pnpm-lock.yaml");
expect(parsedList.pkgList.length).toEqual(627);
expect(parsedList.dependenciesList.length).toEqual(627);
expect(parsedList.pkgList.length).toEqual(625);
expect(parsedList.dependenciesList.length).toEqual(625);
expect(parsedList.pkgList[0]).toEqual({
group: "@ampproject",
name: "remapping",
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const validateRefs = (bomJson) => {
if (bomJson?.dependencies) {
if (isPartialTree(bomJson.dependencies, bomJson?.components?.length)) {
warningsList.push(
"Dependency tree is partial with multiple empty dependsOn attributes.",
"Dependency tree has multiple empty dependsOn attributes.",
);
}
for (const dep of bomJson.dependencies) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
"bugs": {
"url": "https://github.com/cyclonedx/cdxgen/issues"
},
"packageManager": "pnpm@9.14.4",
"packageManager": "pnpm@9.15.1",
"lint-staged": {
"*": "biome check --fix --no-errors-on-unmatched"
},
"dependencies": {
"@babel/parser": "^7.26.3",
"@babel/traverse": "^7.26.4",
"@npmcli/arborist": "8.0.0",
"@npmcli/arborist": "9.0.0",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"cheerio": "^1.0.0",
Expand Down Expand Up @@ -109,7 +109,7 @@
"@cyclonedx/cdxgen-plugins-bin-ppc64": "1.6.9",
"@cyclonedx/cdxgen-plugins-bin-windows-amd64": "1.6.9",
"@cyclonedx/cdxgen-plugins-bin-windows-arm64": "1.6.9",
"body-parser": "^2.0.1",
"body-parser": "^2.0.2",
"compression": "^1.7.5",
"connect": "^3.7.0",
"jsonata": "^2.0.6",
Expand Down
Loading

0 comments on commit 0485787

Please sign in to comment.