♻️ Move time utilities from browser-core to @datadog/js-core#4748
♻️ Move time utilities from browser-core to @datadog/js-core#4748thomas-lebeau wants to merge 7 commits into
Conversation
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 0b205b6 | Docs | Datadog PR Page | Give us feedback! |
71105dc to
fb5c874
Compare
Bundles Sizes Evolution
|
Add all time constants and utilities (`dateNow`, `elapsed`, `relativeNow`, `ONE_SECOND`, `ONE_MINUTE`, etc.) to `packages/js-core/src/time.ts` and delete the original `packages/browser-core/src/tools/utils/timeUtils.ts`.
Migrate all time-related imports (dateNow, ONE_SECOND, ONE_MINUTE, etc.) from browser-core's internal timeUtils to the new @datadog/js-core/time subpath across browser-core, browser-logs, browser-rum-core, browser-rum, browser-rum-react, and browser-debugger packages.
fb5c874 to
f0bd4fe
Compare
…g/js-core Remove the re-export of @datadog/js-core/time from browser-core's public index, and update all consuming packages to import time types and utilities (RelativeTime, TimeStamp, ONE_MINUTE, toTimeStamp, etc.) directly from @datadog/js-core/time. Also add @datadog/js-core as an explicit dependency to framework packages (angular, nextjs, nuxt, vue) that now need it.
…gration - Change `import type` to `import` for values like `Duration`, `relativeNow`, `relativeToClocks` - Move `clocksNow` import to `@datadog/js-core/time` in plugin scenario
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f320c5b6b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export { createIdentityEncoder } from './tools/encoder' | ||
| export * from './tools/utils/urlPolyfill' | ||
| export * from './tools/utils/timeUtils' | ||
| export * from './tools/utils/arrayUtils' |
There was a problem hiding this comment.
Restore the browser-core time exports
issue: Removing the timeUtils barrel export is a backward-incompatible public API change for @datadog/browser-core: customers or plugins importing existing symbols such as Duration, RelativeTime, clocksNow, or ONE_SECOND from @datadog/browser-core will now fail at compile time or module evaluation even though this package is still versioned as a non-major browser SDK release. Please keep a compatibility re-export from @datadog/js-core/time (or otherwise preserve these symbols) while migrating internal imports.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is fine. consuming @datadog/browser-core outside of the browser sdk repo is not uspported
| */ | ||
| export function getTimeOrigin(): TimeStamp { | ||
| if (timeOrigin === undefined) { | ||
| timeOrigin = (performance.timing?.navigationStart ?? performance.timeOrigin) as TimeStamp |
There was a problem hiding this comment.
Keep browser-only timing APIs out of js-core
issue: packages/js-core/AGENTS.md says @datadog/js-core is runtime-agnostic and explicitly forbids DOM APIs such as performance.timing, but this exported helper now reads browser navigation timing directly. This makes the stable @datadog/js-core/time subpath depend on browser-specific globals/semantics for non-browser consumers; keep this origin logic in browser-core or pass in the runtime-specific timing source instead.
Useful? React with 👍 / 👎.
| "dependencies": { | ||
| "@datadog/browser-core": "7.2.0" | ||
| "@datadog/browser-core": "7.2.0", | ||
| "@datadog/js-core": "0.0.1" |
There was a problem hiding this comment.
Bump js-core before depending on new time exports
issue: The browser packages now import many symbols that were just added to @datadog/js-core/time, but this new exact dependency still points at @datadog/js-core 0.0.1 while packages/js-core/package.json also remains 0.0.1. In published installs, package managers can satisfy this with the existing 0.0.1 package that only provided the old API, causing module evaluation to fail on imports like clocksNow/toServerDuration; publish these exports under a new js-core version and depend on that version.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The release script will take care of this
| * @returns The elapsed duration in milliseconds. | ||
| */ | ||
| export function elapsed(start: TimeStamp, end: TimeStamp): Duration | ||
| export function elapsed(start: number, end: number): Duration |
There was a problem hiding this comment.
issue:
export function elapsed(start: number, end: number): Durationshould be:
export function elapsed(start: RelativeTime, end: RelativeTime): DurationMake the overloaded signature of `elapsed` more precise by using the `RelativeTime` branded type instead of the plain `number` type.
|
/to-staging |
|
View all feedbacks in Devflow UI.
Commit 0b205b6a6e will soon be integrated into staging-24.
Commit 0b205b6a6e has been merged into staging-24 in merge commit ce2ab31899. If you need to revert this integration, you can use the following command: |
Integrated commit sha: 0b205b6 Co-authored-by: thomas-lebeau <thomas.lebeau@datadoghq.com>
Motivation
The
@datadog/js-corepackage was introduced to provide runtime-agnostic utilities that can be shared across browser and non-browser environments. Time utilities (dateNow,elapsed,relativeNow,ONE_SECOND,ONE_MINUTE, etc.) are pure, environment-agnostic helpers that are a natural fit for this package.Changes
packages/browser-core/src/tools/utils/timeUtils.tstopackages/js-core/src/time.tsbrowser-core,browser-logs,browser-rum-core,browser-rum,browser-rum-react,browser-debugger) to import time utilities from@datadog/js-coreinstead of@datadog/browser-core@datadog/js-coreas a dependency to affected packagesjs-coreREADME with time utilities documentationTest instructions
yarn typecheckto verify no type errorsyarn test:unitto verify all unit tests passChecklist