Skip to content

Commit

Permalink
fix(depWalker): handle scoped packages
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly committed Aug 5, 2024
1 parent fe6cafe commit 8cca9db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions workspaces/scanner/src/depWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,17 @@ export async function depWalker(
continue;
}

const usedBy: Record<string, string> = Object.create(null);
for (const [name, version] of [...usedDeps].map((name) => name.split("@"))) {
const usedBy: Record<string, string> = 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);
Expand Down
6 changes: 6 additions & 0 deletions workspaces/scanner/test/depWalker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down

0 comments on commit 8cca9db

Please sign in to comment.