From a38f79817f755df543444ee4f74300da292e38fe Mon Sep 17 00:00:00 2001 From: xenobytezero Date: Wed, 1 May 2024 11:08:28 +0100 Subject: [PATCH] fix: add additional comments + ignore virtual modules when scanning --- src/helpers.ts | 3 +++ src/index.ts | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/helpers.ts b/src/helpers.ts index 7968c95..15bfbcf 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -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"); diff --git a/src/index.ts b/src/index.ts index 698a5a1..ac837ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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")) {