Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

KSXGitHub
Copy link
Contributor

No description provided.

Comment on lines 41 to 45
export function createPackageExtensionsChecksum (packageExtensions: Record<string, PackageExtension> | undefined): PackageExtensionsChecksum {
if (!packageExtensions || isEmpty(packageExtensions)) return undefined
const packageExtensionsChecksum = hash(packageExtensions, withSortingOptions)
return `sha256-${packageExtensionsChecksum}`
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could be more generic, but the name hashObject is already taken. Maybe we should change hashObject to return undefined for empty objects?

@KSXGitHub KSXGitHub marked this pull request as ready for review October 2, 2024 19:12
@KSXGitHub KSXGitHub requested a review from zkochan as a code owner October 2, 2024 19:12
@zkochan
Copy link
Member

zkochan commented Oct 3, 2024

Why is this change needed now? The function is used in a single place.

@KSXGitHub
Copy link
Contributor Author

Why is this change needed now? The function is used in a single place.

The function will be reused. You told me to base createObjectChecksum on the v10 branch.

@zkochan
Copy link
Member

zkochan commented Oct 3, 2024

ok, but in the original PR it was a generic function while here it is specific to package extensions. Which is OK but in this case I don't think it should be part of a generic hashing package. Maybe just keep it in that package that you want to create for checking lockfile settings.

@KSXGitHub
Copy link
Contributor Author

I wonder how many places would hashObject will be used though. Currently, I found it to be used only to calculate packageExtensionsChecksum, which is a waste because this value would never be 00000000000000000 (it will be undefined instead). Should the hash functions return undefined, and when we do need the zero hash, just add ?? DEFAULT_HASH?

@zkochan
Copy link
Member

zkochan commented Oct 3, 2024

Currently, I found it to be used only to calculate packageExtensionsChecksum

no, it is used in multiple places.

you could add a new function like hashObjectNullableWithPrefix.

@KSXGitHub KSXGitHub changed the title refactor: createPackageExtensionsChecksum refactor: hashObjectNullableWithPrefix Oct 3, 2024
@KSXGitHub
Copy link
Contributor Author

you could add a new function like hashObjectNullableWithPrefix.

done.

export const hashObject = (object: unknown): string => hashUnknown(object, withSortingOptions)

export type PrefixedHash = `sha256-${string}`
export function hashObjectNullablePrefix (object: Record<string, unknown> | undefined): PrefixedHash | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function hashObjectNullablePrefix (object: Record<string, unknown> | undefined): PrefixedHash | undefined {
export function hashObjectNullableWithPrefix (object: Record<string, unknown> | undefined): PrefixedHash | undefined {

otherwise it sounds like the prefix is nullable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zkochan zkochan merged commit 2d5f6a7 into v10 Oct 3, 2024
12 checks passed
@zkochan zkochan deleted the refactor-change-object-hasher branch October 3, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants