Skip to content

Commit

Permalink
fix: add additional comments + ignore virtual modules when scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
xenobytezero authored and janbiasi committed May 3, 2024
1 parent 49238e4 commit a38f798
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export async function getCorrespondingPackageFromModuleId(
return Promise.resolve(null);
}

// dirname() will do the equivalent of traversing up the
// directory tree one level when called on a path without
// a file.
const folder = dirname(modulePath);
const potentialPackagePath = join(folder, "./package.json");

Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ export default function rollupPluginSbom(userOptions?: RollupPluginSbomOptions):
* Register only the effectively imported third party modules from `node_modules`
*/
async moduleParsed(moduleInfo) {
const nodeModuleImportedIds = moduleInfo.importedIds.filter((entry) => entry.includes("node_modules"));
// filter out modules that exists in node_modules and
// also are not Rollup virtual modules (starting with \0)
const nodeModuleImportedIds = moduleInfo.importedIds.filter(
(entry) => entry.includes("node_modules") && !entry.startsWith("\0"),
);

const potentialComponents = await Promise.all(
nodeModuleImportedIds.map((moduleId) => {
if (!moduleId.includes("node_modules")) {
Expand Down

0 comments on commit a38f798

Please sign in to comment.