Skip to content
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

chore: remove datetime package dependencies to lodash #6751

Merged

Conversation

PetrusAsikainen
Copy link
Contributor

@PetrusAsikainen PetrusAsikainen commented Mar 26, 2024

Checklist

  • Includes tests (well, seems to pass existing ones)
  • Update documentation

Changes proposed in this pull request:

I noticed that @blueprintjs/datetime depends on lodash for two extremely trivial use cases. I've changed those as such:

  • getCurrentTimezone, a function without arguments, used memoize.

    I've replaced it with a global variable - while this is a new global let, the previous one was a mutable object stored in a const, so it's essentially the same.

    The function was also declared as () => string, meaning there was no official way to access its lodash cache property either.

  • timezoneUtils used isEmpty on a variable declared as string | null | undefined, out of which null and undefined were already checked for. I replaced this with a simple manual check

Additionally, @blueprintjs/datetime2 depended on @types/lodash without using it for anything, so I've removed it as well.

This effectively means you can build a Blueprint app without depending transitively on lodash.

Reviewers should focus on:

Whether there are edge cases that might break from these changes.

@changelog-app
Copy link

changelog-app bot commented Mar 26, 2024

Generate changelog in packages/datetime/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

chore: remove datetime package dependencies to lodash


Generate changelog in packages/datetime2/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

chore: remove datetime package dependencies to lodash


Check the box to generate changelog(s)

  • Generate changelog entry

Copy link
Contributor

@ericjeney ericjeney left a comment

Choose a reason for hiding this comment

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

Thanks! I agree with removing the dep on lodash, especially since it was so light.

@@ -69,7 +68,7 @@ export function getDateObjectFromIsoString(
if (value === undefined) {
return undefined;
}
if (value === null || isEmpty(value)) {
if (value === null || value === "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (value === null || value === "") {
if (value === null || value === "" || typeof value !== "string") {

Can you add a typeof check here to be extra defensive in the event a non-TypeScript consumer is passing in an incorrect value here (such as a number) and expecting to get null returned?

isEmpty evaluates to true on numbers, so I'd like to preserve that behavior to avoid an accidental break.

Copy link
Contributor Author

@PetrusAsikainen PetrusAsikainen Apr 22, 2024

Choose a reason for hiding this comment

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

Seems reasonable. Interesting that here lodash.isEmpty very much doesn't do what it says on the tin:

Checks if value is an empty object, collection, map, or set.

...which a number clearly isn't - handling for primitives isn't specified.

@PetrusAsikainen PetrusAsikainen requested a review from ericjeney May 17, 2024 19:27
@ericjeney ericjeney merged commit 9dbbda0 into palantir:develop May 21, 2024
12 of 15 checks passed
@PetrusAsikainen PetrusAsikainen deleted the pa/remove-lodash-dependency branch May 22, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants