-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(fslib): handle float timestamps in convertToBigIntStats #6988
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
fix(fslib): handle float timestamps in convertToBigIntStats #6988
Conversation
Fixes RangeError when file timestamps contain fractional milliseconds. Uses Math.floor() to ensure integer conversion before BigInt. The convertToBigIntStats function was failing when stats contained non-integer timestamps (e.g., 1763746784088.47), throwing: 'RangeError: The number X cannot be converted to a BigInt because it is not an integer' This can occur when ZIP file entries have timestamps with floating-point precision, particularly in Yarn 6.0.0-rc.5 when building with Storybook.
arcanis
left a comment
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.
One suggestion
| bigintStats.atimeNs = bigintStats.atimeMs * BigInt(1e6); | ||
| bigintStats.mtimeNs = bigintStats.mtimeMs * BigInt(1e6); | ||
| bigintStats.ctimeNs = bigintStats.ctimeMs * BigInt(1e6); | ||
| bigintStats.birthtimeNs = bigintStats.birthtimeMs * BigInt(1e6); |
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.
These also need to be updated, as otherwise we lose the millisecond precision. Something like this should work, I think:
bigintStats.atimeNs = bigintStats.atimeMs * BigInt(1e6) + BigInt(Math.floor((stats.atimeMs % 1) * 1e3)) * BigInt(1e3);
bigintStats.mtimeNs = bigintStats.mtimeMs * BigInt(1e6) + BigInt(Math.floor((stats.mtimeMs % 1) * 1e3)) * BigInt(1e3);
bigintStats.ctimeNs = bigintStats.ctimeMs * BigInt(1e6) + BigInt(Math.floor((stats.ctimeMs % 1) * 1e3)) * BigInt(1e3);
bigintStats.birthtimeNs = bigintStats.birthtimeMs * BigInt(1e6) + BigInt(Math.floor((stats.birthtimeMs % 1) * 1e3)) * BigInt(1e3);
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.
Updated - great suggestion 👍
Address review feedback from @arcanis to preserve the fractional part of floating-point timestamps when converting to nanoseconds. The fractional milliseconds (e.g., 0.47ms from 1763746784088.47) are now extracted and added as additional nanoseconds: - 0.47ms → 470μs → 470,000ns This ensures no precision is lost during the conversion process.
…lowlist * origin/master: (212 commits) CI: Select node version to run CI against automatically (yarnpkg#7032) Fixes foreach order when --topological isnt set (yarnpkg#6997) fix(fslib): handle float timestamps in convertToBigIntStats (yarnpkg#6988) Fixes the `/<name>/<version>` format (yarnpkg#6993) docs(constraints): add missing @typedef alias for `Context` (yarnpkg#6989) Sync master with the changes from master Releasing 3 new packages Fix JSON Schema (yarnpkg#6973) Implements npm web login support (yarnpkg#6981) fix(git): split `-c` and `core.autocrlf=false` into separate args for `clone` (yarnpkg#6983) Sync master with the changes from master Releasing 8 new packages Allow catalogs to work with descriptors without resolvers (yarnpkg#6930) docs: Clarify additional use-case of npmMinimalAgeGate (yarnpkg#6945) Migrates the "typescript" dependencies to a catalog (yarnpkg#6969) Support escaping template variables in environment values (yarnpkg#6935) Core: Create DURATION settings type (yarnpkg#6942) fix: use correct env var to detect gitlab CI for OIDC (yarnpkg#6938) Update README.md badge link (yarnpkg#6947) fix(publish): use correct workspace name in --json output (yarnpkg#6949) ...
Summary
Fixes RangeError when converting floating-point timestamps to BigInt in the
convertToBigIntStatsfunction.Problem
The
convertToBigIntStats()function fails when file stats contain non-integer timestamps (e.g.,1763746784088.47), throwing:This occurs when ZIP file entries have timestamps with floating-point precision, particularly observed in Yarn 6.0.0-rc.5 when building with Storybook.
Solution
Use
Math.floor()to ensure integer values before BigInt conversion on line 194 ofpackages/yarnpkg-fslib/sources/statUtils.ts.Changes
BigInt(element)toBigInt(Math.floor(element))Testing
Related
This issue was discovered while running
yarn storybook buildwith Yarn 6.0.0-rc.5.