-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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.
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.