-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS-493 Add 'get-telemetry' endpoint on bridge-server #5011
Conversation
create(context) { | ||
return { | ||
CallExpression(node) { | ||
// Necessarily call 'getDependencies' to populate the cache of dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that we would not receive any dependencies in the telemetry in case the analysis never populated the cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a good chance that this happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we will only have dependencies once the analysis populates it. Chance is low. I guess one would have to remove all of the rules that call the package-jsons.ts cache. In that case, we wouldn't populate anything for them. That's a tradeoff. This way, this call is very cheap and doesn't incur an extra time-cost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and could you document this behavior somewhere, preferably in the code base like in the JS doc of the getDependencies() function:
Returns the dependencies of the root package.json file collected in the cache.
As the cache is populated lazily, it could be null in case no rule execution has touched it.
Co-authored-by: Ilia Kebets <ilia.kebets@sonarsource.com>
|
||
export function getAllDependencies(): NamedDependency[] { | ||
const dependencies = [...cache.values()] | ||
.flatMap(dependencies => [...dependencies]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we have duplicates, would it simply overwrite and keep the last one?
return Object.values( | ||
dependencies.reduce( | ||
(result, dependency) => ({ | ||
...result, | ||
[dependency.name]: dependency, | ||
}), | ||
{}, | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this step doing? Since we already have a NemdDependency[] at the previous step.
@@ -46,9 +73,9 @@ export function getDependencies(filename: string, cwd: string) { | |||
const dirname = Path.dirname(toUnixPath(filename)); | |||
const cached = cache.get(dirname); | |||
if (cached) { | |||
return cached; | |||
return new Set([...cached].map(item => item.name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this doing? Just a clone or something more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my few nitpicking comments about documenting in JS doc some things, otherwise, good job!
Quality Gate passedIssues Measures |
JS-493
Added a new endpoint 'get-telemetry'. This is assumed to be called after an analysis has occurred and the dependency cache is filled.
Tested in 2 ways: