♻️ move pure utilities to @datadog/js-core/util - #4994
Draft
BenoitZugmeyer wants to merge 7 commits into
Draft
Conversation
|
BenoitZugmeyer
force-pushed
the
benoit/move-pure-utils-to-js-core
branch
from
August 27, 2026 15:45
8244c7f to
11970f7
Compare
Bundles Sizes Evolution
|
BenoitZugmeyer
force-pushed
the
benoit/move-pure-utils-to-js-core
branch
4 times, most recently
from
August 28, 2026 09:03
66c96ed to
40b080d
Compare
Move `computeBytesCount`, `concatBuffers`, `ONE_KIBI_BYTE`, `ONE_MEBI_BYTE`, and the `Uint8ArrayBuffer` type from `browser-core/src/tools/utils/byteUtils` to `js-core/src/util/byteUtils`. The spec file moves alongside. All consumers (browser-core internals, browser-rum, browser-rum-core, browser-worker) now import directly from `@datadog/js-core/util` instead of going through browser-core re-exports.
Move `Context`, `ContextValue`, and `ContextArray` type definitions from `browser-core/src/tools/serialisation/context` to `js-core/src/util/context`. All consumers (browser-core internals, browser-logs, browser-rum, browser-rum-core, browser-rum-slim, developer-extension, e2e tests) now import directly from `@datadog/js-core/util`.
Move `mockable` and `mockableReplacements` from `browser-core/src/tools/mockable` to `js-core/src/util/mockable`. All consumers (browser-core internals, browser-logs, browser-rum, browser-rum-core, browser-debugger, developer-extension) now import directly from `@datadog/js-core/util`.
Move `jsonStringify`, `detachToJsonMethod`, and the `ObjectWithToJsonMethod` type from `browser-core/src/tools/serialisation/jsonStringify` to `js-core/src/util/jsonStringify`. The spec file moves alongside. The `noop` dependency (previously imported from browser-core's `functionUtils`) is inlined as a private function to avoid pulling browser-specific utilities into js-core. All consumers (browser-core internals, browser-rum-core) now import directly from `@datadog/js-core/util`.
Add TSDoc comments to the utilities moved from browser-core to js-core (byteUtils, Context types, mockable, jsonStringify, detachToJsonMethod, ObjectWithToJsonMethod) so they appear as documented exports in the API Extractor report instead of `(undocumented)`.
BenoitZugmeyer
force-pushed
the
benoit/move-pure-utils-to-js-core
branch
from
August 31, 2026 08:20
40b080d to
060a320
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
@datadog/js-corepackage is meant to hold runtime-agnostic SDK utilities shared across all Datadog JS SDKs. Several pure utilities (byteUtils,Contexttypes,mockable,jsonStringify) lived exclusively in@datadog/browser-core, making them unavailable to non-browser consumers such as the Worker or future server-side SDK targets. This PR moves them to@datadog/js-coreso they can be shared.Changes
byteUtils(computeBytesCount,concatBuffers,ONE_KIBI_BYTE,ONE_MEBI_BYTE,Uint8ArrayBuffer) moved to@datadog/js-core/util; spec moved alongside.Contexttypes (Context,ContextValue,ContextArray) moved to@datadog/js-core/util.mockable(mockable,mockableReplacements) moved to@datadog/js-core/util.jsonStringify(jsonStringify,detachToJsonMethod,ObjectWithToJsonMethod) moved to@datadog/js-core/util; spec moved alongside. Thenoopdependency is inlined to avoid pulling browser-specific utilities into js-core.Uint8ArrayBuffersimplified from a custom interface toUint8Array<ArrayBuffer>.@datadog/js-core/utilinstead of going through browser-core re-exports.@datadog/js-coreadded as a dependency of@datadog/browser-worker.Test instructions
This is a pure refactor with no observable behaviour change. All existing unit tests cover the moved code. To sanity-check the SDK still initialises and sends data correctly:
yarn devand openhttp://localhost:8080.beforeunload/visibilitychange.Checklist