Skip to content

Commit

Permalink
pnpm9 optional packages detection (#1180)
Browse files Browse the repository at this point in the history
* Fix for 1163. Manually track optional packages for pnpm 9

Signed-off-by: Prabhu Subramanian <[email protected]>

* Angular pnpm test

Signed-off-by: Prabhu Subramanian <[email protected]>

* Make tree optional

Signed-off-by: Prabhu Subramanian <[email protected]>

* Make tree optional

Signed-off-by: Prabhu Subramanian <[email protected]>

* Tweaks

Signed-off-by: Prabhu Subramanian <[email protected]>

---------

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Jun 19, 2024
1 parent dfca99a commit 392dca2
Show file tree
Hide file tree
Showing 12 changed files with 22,670 additions and 35 deletions.
2 changes: 1 addition & 1 deletion analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const IGNORE_DIRS = process.env.ASTGEN_IGNORE_DIRS

const IGNORE_FILE_PATTERN = new RegExp(
process.env.ASTGEN_IGNORE_FILE_PATTERN ||
"(conf|config|test|spec|mock|\\.d)\\.(js|ts|tsx)$",
"(conf|config|test|spec|mock|setup-jest|\\.d)\\.(js|ts|tsx)$",
"i",
);

Expand Down
18 changes: 17 additions & 1 deletion bin/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,31 @@ cdxgenRepl.defineCommand("search", {
if (sbom) {
if (searchStr) {
try {
const originalSearchString = searchStr;
let dependenciesSearchStr = searchStr;
if (!searchStr.includes("~>")) {
dependenciesSearchStr = `dependencies[ref ~> /${searchStr}/i or dependsOn ~> /${searchStr}/i or provides ~> /${searchStr}/i]`;
searchStr = `components[group ~> /${searchStr}/i or name ~> /${searchStr}/i or description ~> /${searchStr}/i or publisher ~> /${searchStr}/i or purl ~> /${searchStr}/i]`;
}
const expression = jsonata(searchStr);
const components = await expression.evaluate(sbom);
const dexpression = jsonata(dependenciesSearchStr);
const dependencies = await dexpression.evaluate(sbom);
if (!components) {
console.log("No results found!");
} else {
printTable({ components, dependencies: [] });
printTable(
{ components, dependencies },
undefined,
originalSearchString,
);
if (dependencies?.length) {
printDependencyTree(
{ components, dependencies },
"dependsOn",
originalSearchString,
);
}
}
} catch (e) {
console.log(e);
Expand Down
33 changes: 24 additions & 9 deletions display.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ const SYMBOLS_ANSI = {
};

const MAX_TREE_DEPTH = 6;

export const printTable = (bomJson, filterTypes = undefined) => {
const highlightStr = (s, highlight) => {
if (highlight && s && s.includes(highlight)) {
s = s.replaceAll(highlight, `\x1b[1;33m${highlight}\x1b[0m`);
}
return s;
};
export const printTable = (
bomJson,
filterTypes = undefined,
highlight = undefined,
) => {
if (!bomJson || !bomJson.components) {
return;
}
Expand Down Expand Up @@ -56,8 +65,8 @@ export const printTable = (bomJson, filterTypes = undefined) => {
]);
} else {
stream.write([
comp.group || "",
comp.name,
highlightStr(comp.group || "", highlight),
highlightStr(comp.name, highlight),
`\x1b[1;35m${comp.version || ""}\x1b[0m`,
comp.scope || "",
]);
Expand All @@ -67,9 +76,9 @@ export const printTable = (bomJson, filterTypes = undefined) => {
if (!filterTypes) {
console.log(
"BOM includes",
bomJson.components.length,
bomJson?.components?.length || 0,
"components and",
bomJson.dependencies.length,
bomJson?.dependencies?.length || 0,
"dependencies",
);
} else {
Expand Down Expand Up @@ -215,7 +224,11 @@ export const printCallStack = (bomJson) => {
console.log(table(data, config));
}
};
export const printDependencyTree = (bomJson, mode = "dependsOn") => {
export const printDependencyTree = (
bomJson,
mode = "dependsOn",
highlight = undefined,
) => {
const dependencies = bomJson.dependencies || [];
if (!dependencies.length) {
return;
Expand Down Expand Up @@ -244,9 +257,11 @@ export const printDependencyTree = (bomJson, mode = "dependsOn") => {
content: `${treeType} Tree\nGenerated with \u2665 by cdxgen`,
},
};
console.log(table([[treeGraphics.join("\n")]], config));
console.log(
table([[highlightStr(treeGraphics.join("\n"), highlight)]], config),
);
} else {
console.log(treeGraphics.join("\n"));
console.log(highlightStr(treeGraphics.join("\n"), highlight));
}
};

Expand Down
Loading

0 comments on commit 392dca2

Please sign in to comment.