✨ add @datadog/js-core/runtime sub-path with defineGlobal#4845
Draft
thomas-lebeau wants to merge 2 commits into
Draft
✨ add @datadog/js-core/runtime sub-path with defineGlobal#4845thomas-lebeau wants to merge 2 commits into
thomas-lebeau wants to merge 2 commits into
Conversation
Introduces a new runtime sub-path per the js-core RFC, containing defineGlobal, ported from browser-core's boot/init.ts. Used by openfeature-js-client to expose the DD_FLAGGING global. getGlobalObject was intentionally left out of this sub-path: js-core's util entry already exposes an equivalent globalObject constant that covers the same need, so no new API was added for it. defineGlobal creates its own generic 'Datadog SDK:' display (via @datadog/js-core/util's createDisplay) rather than reusing browser-core's 'Datadog Browser SDK:'-prefixed singleton, since this function is meant for any Datadog SDK, not just the browser one. Wires up the new sub-path: package.json exports + physical runtime/package.json fallback, tsconfig.base.json path mapping, and typedoc.json entry point, per packages/js-core/AGENTS.md.
Adds an optional 'display' parameter to js-core's defineGlobal (defaulting to a generic 'Datadog SDK:'-prefixed one), so browser-core can pass its own 'Datadog Browser SDK:'-prefixed display and preserve the exact console warning text end users already see. This is an additive signature change (new optional trailing param), not a breaking one. browser-core/boot/init.ts's defineGlobal is now a one-line delegation to @datadog/js-core/runtime's defineGlobal, passing browser-core's own display. catchUserErrors is no longer used here (still used elsewhere, e.g. configuration.ts, so tools/catchUserErrors.ts stays). Trims init.spec.ts's defineGlobal tests down to the two behaviors that are actually specific to browser-core's wrapper (delegation works, and the browser-core display is the one used for warnings) since the underlying logic now has full coverage in js-core's own runtime.spec.ts; keeping the exhaustive matrix here would have duplicated test names across files. Adds '@datadog/js-core/runtime' to the disallow-side-effects lint rule's allowlist, alongside the other side-effect-free js-core sub-paths. Downstream packages (browser-logs, browser-rum, browser-rum-slim, browser-debugger) are unaffected: they still import defineGlobal from '@datadog/browser-core', unchanged.
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: bb3c92d | Docs | Datadog PR Page | Give us feedback! |
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
Per the
@datadog/js-coreRFC,openfeature-js-clientneedsdefineGlobal(to expose theDD_FLAGGINGglobal), which requires a new@datadog/js-core/runtimesub-path — previously there was noruntimeentry at all.getGlobalObject(the RFC's otherruntimeTODO) was intentionally not added:@datadog/js-core/utilalready exposes an equivalentglobalObjectconstant (globalThis, already consumed by browser-core's own timer code), so there's nothing new to build for that need.Changes
@datadog/js-core/runtime, exportingdefineGlobal, ported frombrowser-core/boot/init.ts.defineGlobalbuilds its own generic'Datadog SDK:'-prefixed display via@datadog/js-core/util'screateDisplay, instead of reusing browser-core's'Datadog Browser SDK:'-prefixed singleton — this function is meant for any Datadog SDK (electron-sdk, openfeature-js-client, ...), not just the browser one, so hardcoding "Browser SDK" in the warning message would be misleading for those consumers.packages/js-core/AGENTS.md's "adding a new sub-path" checklist:package.jsonexportsfield + physicalruntime/package.jsonfallback (legacy resolvers)tsconfig.base.jsonpath mappingtypedoc.jsonentry pointapi/runtime.api.mdAPI Extractor golden file (auto-generated byyarn api:check --update)Pure additive change (brand new sub-path), no existing behavior changes.
Test instructions
yarn workspace @datadog/js-core build && yarn api:checkpasses.yarn typecheckpasses.yarn test:unit --spec 'packages/js-core/src/**/*.spec.ts'passes (66/66), including a newruntime.spec.tsmirroring browser-core'sdefineGlobaltest coverage, plus additional coverage for the "SDK loaded more than once" warning path.Checklist