From 8cca9db3f580862e79040d4ad718d1d69318cf31 Mon Sep 17 00:00:00 2001 From: PierreDemailly Date: Mon, 5 Aug 2024 23:30:29 +0200 Subject: [PATCH] fix(depWalker): handle scoped packages --- workspaces/scanner/src/depWalker.ts | 13 +++++++++++-- workspaces/scanner/test/depWalker.spec.ts | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/workspaces/scanner/src/depWalker.ts b/workspaces/scanner/src/depWalker.ts index 630d05f..aa2d294 100644 --- a/workspaces/scanner/src/depWalker.ts +++ b/workspaces/scanner/src/depWalker.ts @@ -232,8 +232,17 @@ export async function depWalker( continue; } - const usedBy: Record = Object.create(null); - for (const [name, version] of [...usedDeps].map((name) => name.split("@"))) { + const usedBy: Record = Object.create(null); + for (const [name, version] of [...usedDeps].map((name) => { + const isScoped = name.startsWith("@"); + if (isScoped) { + const [nameChunk, version] = name.slice(1).split("@"); + + return [`@${nameChunk}`, version]; + } + + return name.split("@") + })) { usedBy[name] = version; } Object.assign(verDescriptor.usedBy, usedBy); diff --git a/workspaces/scanner/test/depWalker.spec.ts b/workspaces/scanner/test/depWalker.spec.ts index b71eb58..0283f09 100644 --- a/workspaces/scanner/test/depWalker.spec.ts +++ b/workspaces/scanner/test/depWalker.spec.ts @@ -92,6 +92,12 @@ test("execute depWalker on @slimio/config", async() => { "@iarna/toml", "@slimio/config" ].sort()); + + const ajvDescriptor = resultAsJSON.ajv.versions["6.12.6"]; + const ajvUsedBy = Object.keys(ajvDescriptor.usedBy); + assert.deepEqual(ajvUsedBy, [ + "@slimio/config" + ]); }); test("execute depWalker on pkg.gitdeps", async() => {