✨ Introduce @datadog/js-core, a runtime-agnostic core package with independent versioning#4727
Conversation
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: fec9f92 | Docs | Datadog PR Page | Give us feedback! |
56e08e9 to
817034d
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 430e745be0
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eff36374e5
ℹ️ 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".
| ### Runtime-agnostic exports only | ||
|
|
||
| Every export must work in both Node.js and browser environments. Do not add: | ||
|
|
||
| - DOM APIs (`document`, `window`, `navigator`, `performance.timing`, etc.) | ||
| - Node.js built-in modules (`fs`, `path`, `process`, etc.) | ||
| - Any API that is not available in both runtimes |
There was a problem hiding this comment.
nitpick: we'll probably have some runtime-related code, like some kind of pageMayExitObservable versions for Browser and Nodejs. Or transport level things.
We'll need to figure whether we want a browser conditional export so we have isomorphic packages, or we export both variants and the consumer uses one or the other.
There was a problem hiding this comment.
true, we probably want to have some integration testing too. but I'd rather think about that in a separate PR.
| ## API | ||
|
|
||
| The package uses sub-path exports. Import only what you need. | ||
|
|
||
| ### `@datadog/js-core/time` | ||
|
|
||
| Time utilities that work in any JavaScript runtime. | ||
|
|
||
| | Export | Description | | ||
| | ----------- | --------------------------------------------------------------------------------------------------------------- | | ||
| | `dateNow()` | Returns the current Unix timestamp in milliseconds. Prefer over `Date.now()` to guard against broken polyfills. | |
There was a problem hiding this comment.
thought: for the future: we should have a API reference doc that is automatically generated. I don't want to maintain the README :D
There was a problem hiding this comment.
I agree, for now I want to keep it simple. Claude can update the readme.
Introduce @datadog/js-core, a stable, runtime-agnostic core package intended for cross-SDK and external usage (electron-sdk, openfeature-js-client). It exposes sub-path exports only (e.g. @datadog/js-core/time) and is versioned independently from the @datadog/browser-* packages. As a first step, move dateNow from @datadog/browser-core into @datadog/js-core/time and update all call sites in browser-core and browser-debugger to import it from the new package.
@datadog/js-core ships in the same release process as the @datadog/browser-* packages but keeps its own version. - prepare-release bumps independently-versioned packages with a minor increment (e.g. 0.0.1 -> 0.1.0) instead of the synced release version, and updates dependents (browser-core, browser-debugger) to reference the new version. - check-release validates that dependents reference the independent package's actual version rather than the synced release version.
The check-packages CI job requires every published package to include a LICENSE file. Add the Apache-2.0 license, matching the other packages.
build:apps installs the SDK packages into each test app as packed .tgz files via resolutions. Now that @datadog/browser-core depends on @datadog/js-core (which is not published), each app that resolves browser-core must also resolve js-core to its local package.tgz, otherwise yarn tries the registry and fails with a 404.
Ship the `time` sub-path two ways so it resolves in both modern and legacy tooling: - the `exports` field for resolvers that support it (encapsulation + import/require/types conditions) - a physical `time/package.json` (relative main/module/types) for resolvers that ignore `exports` (webpack 4, old Node, older Jest) js-core is published transitively to all Browser SDK consumers, so the fallback avoids breaking customers on older bundlers. `exports` takes precedence wherever it is understood.
- Remove the `"exports"` field from `@datadog/js-core/package.json` — legacy resolvers (webpack 4, old Node, older Jest) that predate the `exports` spec would break, and getting native-Node ESM right requires extra packaging the build doesn't emit yet; defer to a future major release - Add `jsCoreCompat.ts` to `@datadog/browser-core` with backward-compat re-exports for symbols that moved to `@datadog/js-core`, so existing consumers importing from `@datadog/browser-core` keep working until the next major - Update `@datadog/js-core` AGENTS.md and README to document the physical sub-path strategy and the deliberate omission of `exports`
- Re-add exports field with ESM/CJS/types conditions for ./time entry point
- Add --esm-type-module flag to build-package script to write {"type":"module"} into esm/ dir for proper ESM resolution
…ategy - AGENTS.md: document that sub-paths are now exposed via both the `exports` field (for modern resolvers) and physical `<name>/package.json` fallbacks (for legacy resolvers); update "adding a new sub-path" steps - README.md: add a note about the dual resolution strategy and the TypeScript moduleResolution requirement for exports-aware sub-paths
Not used outside of filesUtils.ts, no need to export it.
0b98ea7 to
efa367f
Compare
Drop jsCoreCompat.ts and its re-export from browser-core/index.ts now that consumers can import directly from @datadog/js-core.
js-core and similar packages now get a patch increment on each Browser SDK release instead of a minor one, keeping their version progression more conservative.
Motivation
External packages such as
electron-sdkandopenfeature-js-clientcurrently import APIs from@datadog/browser-core, which was never designed as a stable public surface — breaking changes can ship in patch releases, making downstream integrations brittle.This PR introduces
@datadog/js-core, a small, semver-stable, runtime-agnostic core package intended for cross-SDK and external usage, as proposed in the RFC. It is the MVP first step: create the package, move a first utility into it, and wire up the release process.Changes
New package
@datadog/js-coreexportsfield (modern resolvers, native Node ESM/CJS) and physical<name>/directory fallbacks (legacy resolvers — webpack 4, old Node). The build emitsesm/package.jsonwith{"type":"module"}so Node correctly treatsesm/*.jsas ES modules.@datadog/js-core/time).@datadog/browser-*(starts at0.0.1).README.md+AGENTS.mddocumenting the no-breaking-changes, JSDoc, and sub-path rules.dateNowout of@datadog/browser-coreinto@datadog/js-core/timeand updates all call sites inbrowser-coreandbrowser-debuggerto import directly from the new package.@datadog/js-core/timeto thedisallowSideEffectsESLint allowlist and atsconfigpath alias.--esm-type-moduleflag to the sharedbuild-package.tsscript, used by js-core to emitesm/package.jsonpost-build.Release process
@datadog/js-coreis published in the same release pipeline as the browser packages, but keeps its own version.prepare-releasebumps independently-versioned packages with a patch increment (e.g.0.0.1→0.0.2) instead of the synced release version, and updates dependents (browser-core,browser-debugger) to reference the new version.check-releasevalidates that dependents reference the independent package's actual version.Test instructions
yarn build— js-core builds, integrates into the full build, and emitsesm/package.json.yarn typecheck,yarn lint— pass.yarn test:script— 47 pass / 0 fail (validates the release/deploy scripts).prepare-release+check-releaseagainst all package.json files: browser packages bump to the release version, js-core patches0.0.1→0.0.2, andbrowser-core's@datadog/js-coredependency is updated and validated to match.Checklist