-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: update tests and correct type definition #46
Conversation
1a39daf
to
4ea6430
Compare
@kyegupov why |
dep-graph/src/core/create-from-json.ts Line 26 in 1f21cac
dep-graph/test/core/create-from-json.test.ts Lines 762 to 765 in 34da452
|
Just my 2 cents (disregard at will):
|
@darscan the first thing I did was exactly adding missing "depSort". Turned out, it was way more than 2 lines: there also was a bunch of Re two changes in one: I've discovered the "null" problem late, when writing the helper, and I'm not yet sure how to handle it: proceed with nulls or convert them to |
Cool, I'm sold |
Yeh > JSON.stringify({foo: null, bar: undefined})
'{"foo":null}' |
yup, either change is slightly breaking something: types or implementation |
yeh. Out of curiosity.. if you don't change anything.. does anything actually break? |
@darscan the only things that could be broken are: |
src/legacy/index.ts
Outdated
@@ -78,7 +78,7 @@ async function buildGraph( | |||
eventLoopSpinner: EventLoopSpinner, | |||
isRoot = false): Promise<string> { | |||
|
|||
const getNodeId = (name: string, version: string | undefined, hashId: string) => | |||
const getNodeId = (name: string, version: string|null|undefined, hashId: string) => |
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.
should better have spaces around the |
- that's how it appears in the docs: https://www.typescriptlang.org/docs/handbook/advanced-types.html#union-types.
@kyegupov good catch that we actually set it to
|
c94ddaf
to
f56a991
Compare
src/core/create-from-json.ts
Outdated
@@ -22,8 +22,7 @@ export function createFromJSON(depGraphData: DepGraphData): DepGraph { | |||
const pkgNodes: {[pkgId: string]: Set<string>} = {}; | |||
|
|||
for (const { id, info } of depGraphData.pkgs) { | |||
// TODO: avoid this, instead just use `info` as is | |||
pkgs[id] = info.version ? info : { ...info, version: null } as any; | |||
pkgs[id] = info; |
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.
maybe it's better to actually set it to undefined
if it's nullish to make sure it adhers the type?
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.
Yep, why not.
src/core/dep-graph.ts
Outdated
@@ -161,6 +161,10 @@ class DepGraphImpl implements types.DepGraphInternal { | |||
otherDepGraph = createFromJSON(other.toJSON()) as types.DepGraphInternal; | |||
} | |||
|
|||
// In theory, for the graphs created by standard means, `_.isEquals(this._data, otherDepGraph._data)` | |||
// should suffice, since node IDs will be generated in a predictable way. | |||
// However, to support unconventional node IDs, we run our own deep |
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.
not only - it's also to:
- compare across outputs of different (compatible) versions of the lib
- be not sensitive to ordering as the data contains arrays
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.
the array ordering should be fairly deterministic, I believe (but that hinges on the current V8 implementation)
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.
maybe we want to "coalesce" the null-ish versions we get when converting from a depTree
to undefined
? like e.g. in https://github.com/snyk/dep-graph/blob/master/src/legacy/index.ts#L48
f56a991
to
2a7e541
Compare
@michael-go added coalecsion |
🎉 This PR is included in version 1.15.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What does this PR do?
Corrects two mistakes:
.sort()
on aPkgInfo[]
list. Without the comparison function, this sort was doing nothing. The tests were passing just by accident.PkgInfo.version
was set tonull
sometimes and was advertised asnull
-able in the README. This was fixed, now onlyundefined
should be used.Since it introduces a light breakage (correction) of the library interface, this is being submitted as "feat" rather than "fix" or "tests".