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

Two packages with two the same/different versions occur to unwanted exceptions #77

Open
hozblok opened this issue Oct 29, 2024 · 2 comments

Comments

@hozblok
Copy link

hozblok commented Oct 29, 2024

Sandbox: https://stackblitz.com/edit/stackblitz-starters-nt1w2a?file=package.json

❯ node ./index.js
Hello Node.js v18.20.3!
true false
false true
true
true
Error: Invalid unit _timestamp
    at normalizeComponent (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/utils/utils.js:158:11)
    at normalizeDateComponents (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/utils/utils.js:174:20)
    at getTimestampFromObject (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/dateTime/parse.js:27:58)
    at getTimestamp (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/dateTime/dateTime.js:646:49)
    at dateTime (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/dateTime/dateTime.js:680:14)
    at parseInput (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/parser/parser.js:24:40)
    at dateTimeParse (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/parser/parser.js:43:16)
    at Object.isValid (/home/projects/stackblitz-starters-nt1w2a/node_modules/data-utils-new/build/parser/parser.js:56:42)
    at Object.eval (/home/projects/stackblitz-starters-nt1w2a/index.js:20:20)
    at Object._0x34b746 (https://stackblitzstartersnt1w2a-5cqf.w-credentialless-staticblitz.com/blitz.34c588ed.js:40:792686)

Node.js v18.20.3

We have a complex backoffice project. Different teams are putting together different subprojects using different date-utils. Different people are responsible for updating. All subprojects are integrated into one big one. Periodically, situations arise when in a common big project we have several versions that differ by a patch (e.g. 2.5.3 & 2.5.4). This leads to the breakdown of the entire frontend.

The isValid(...) used in @gravity-ui/date-components : https://github.com/gravity-ui/date-components/blob/1d0f842b521255c31fbd1cd9839fcd1f8ee55e5f/src/components/DateField/hooks/useDateFieldState.ts#L87

IMHO It is not typical for the NPM world to have two different patch packages without backward compatibility. Can this situation be fixed?

@ValeraS
Copy link
Collaborator

ValeraS commented Oct 30, 2024

I see several different issues here:

  • isValid function shouldn't throw on incorrect input.
  • DateTimeImpl doesn't work with inputs of type DateTime that are not DateTimeImpl instances.
  • isDateTime returns false for different version instances.

The first two issues are bugs (fixed here #80) but the last one is not. The library uses the Singleton pattern and this pattern cannot be supported across different versions of the package, even if they have the same version number. It is highly recommended to get rid of multiple versions of a package. This can be done in several ways, such as using overrides in package.json, aliases in bundlers.

IMHO It is not typical for the NPM world to have two different patch packages without backward compatibility. Can this situation be fixed?

There are no backward compatibility issues. The public APIs of these two versions are backward compatible.

@hozblok
Copy link
Author

hozblok commented Nov 2, 2024

I see several different issues here:

  • isValid function shouldn't throw on incorrect input.
  • DateTimeImpl doesn't work with inputs of type DateTime that are not DateTimeImpl instances.
  • isDateTime returns false for different version instances.

The first two issues are bugs (fixed here #80) but the last one is not. The library uses the Singleton pattern and this pattern cannot be supported across different versions of the package, even if they have the same version number. It is highly recommended to get rid of multiple versions of a package. This can be done in several ways, such as using overrides in package.json, aliases in bundlers.

IMHO It is not typical for the NPM world to have two different patch packages without backward compatibility. Can this situation be fixed?

There are no backward compatibility issues. The public APIs of these two versions are backward compatible.

Ok, thanks. So I suggest to close it in favor of gravity-ui/rfc#23

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

No branches or pull requests

2 participants