Skip to content

👷 Add API surface linting for @datadog/js-core via API Extractor#4804

Merged
thomas-lebeau merged 9 commits into
mainfrom
worktree-squishy-churning-salamander
Jun 18, 2026
Merged

👷 Add API surface linting for @datadog/js-core via API Extractor#4804
thomas-lebeau merged 9 commits into
mainfrom
worktree-squishy-churning-salamander

Conversation

@thomas-lebeau

@thomas-lebeau thomas-lebeau commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Motivation

@datadog/js-core is consumed externally by other Datadog SDKs and has a semver stability guarantee. Without an automated API surface check, accidental breaking changes (removed exports, changed signatures) can slip through undetected.

Changes

  • Add @microsoft/api-extractor as a dev dependency
  • Add scripts/check-js-core-api.ts script that runs API Extractor over each sub-path entry point (cjs/entries/*.d.ts) and compares against committed golden files
  • Add golden API report files in packages/js-core/api/ for the three existing sub-paths (monitor, time, util)
  • Add yarn api:check commands
  • Add a check-js-core-api CI job in .gitlab-ci.yml
  • Update packages/js-core/AGENTS.md with documentation on the new workflow

Test instructions

# Build the package first
yarn workspace @datadog/js-core build

# Verify the check passes
yarn api:check

# Simulate an intentional API change: update golden files
yarn api:check --update

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 18, 2026

Copy link
Copy Markdown

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

DataDog/browser-sdk | check-staging-merge   View in Datadog   GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 76.87% (+0.00%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b81442b | Docs | Datadog PR Page | Give us feedback!

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jun 18, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.46 KiB 172.46 KiB 0 B 0.00%
Rum Profiler 8.22 KiB 8.22 KiB 0 B 0.00%
Rum Recorder 21.09 KiB 21.09 KiB 0 B 0.00%
Logs 54.47 KiB 54.47 KiB 0 B 0.00%
Rum Slim 129.97 KiB 129.97 KiB 0 B 0.00%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@thomas-lebeau thomas-lebeau force-pushed the worktree-squishy-churning-salamander branch from ad2dfaa to 30d3ba3 Compare June 18, 2026 08:48
@thomas-lebeau thomas-lebeau marked this pull request as ready for review June 18, 2026 11:16
@thomas-lebeau thomas-lebeau requested a review from a team as a code owner June 18, 2026 11:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c297c05069

ℹ️ 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".

const name = path.basename(entryPoint, '.d.ts')
printLog(`Checking API surface for @datadog/js-core/${name}...`)

const configObject: IConfigFile = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add release tags before enabling CI

When GitLab runs check-js-core-api, this config uses API Extractor's default message reporting with localBuild: false; API Extractor documents ae-missing-release-tag as required by default, and non-local invocations fail when warnings are present. The current js-core declarations have JSDoc but no @public/@internal release tags, so yarn api:check will fail even when the committed reports match; add release tags to the exported API or suppress this message in the generated config before wiring the job into CI. See https://api-extractor.com/pages/messages/ae-missing-release-tag/.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, that does not seem to be the case, the tag are present in the golden reports and the checks passes

Comment thread scripts/check-js-core-api.ts Outdated
})

const packageDir = path.resolve('packages/js-core')
const entryPoints = globSync('cjs/entries/*.d.ts', { cwd: packageDir })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Drive API checks from exported subpaths

Because the script discovers entry points from built cjs/entries/*.d.ts, it does not validate the actual subpaths exposed in packages/js-core/package.json. A change can remove ./monitor from the package exports while leaving src/entries/monitor.ts in place; the build will still emit the same declaration file and this loop will pass, even though modern consumers can no longer import @datadog/js-core/monitor. Use the package exports map (or compare it against the reports) as the source of truth for checked subpaths.

Useful? React with 👍 / 👎.

Comment thread packages/js-core/tsconfig.api.json Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acbdb016a6

ℹ️ 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".

const subpaths = Object.keys(packageJson.exports ?? {}).map((subpath) => subpath.replace('./', ''))

for (const name of subpaths) {
const entryPoint = path.join(packageDir, `cjs/entries/${name}.d.ts`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the exported types target

issue: In package.json exports, the types condition is what TypeScript consumers resolve, but this loop derives only the subpath name and then always checks cjs/entries/${name}.d.ts. If someone changes or drops exports['./monitor'].types while leaving the built entry file in place, yarn api:check still passes even though @datadog/js-core/monitor exposes different or no declarations to node16/bundler users. Fresh evidence: this version now reads export keys, but this line still ignores each export value's types path; use that target and validate it exists as the API Extractor entry point.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine, let's not over do it, we can fix this if it's ever needed

@thomas-lebeau thomas-lebeau force-pushed the worktree-squishy-churning-salamander branch from acbdb01 to b81442b Compare June 18, 2026 14:36
@thomas-lebeau thomas-lebeau merged commit 267b6eb into main Jun 18, 2026
29 of 30 checks passed
@thomas-lebeau thomas-lebeau deleted the worktree-squishy-churning-salamander branch June 18, 2026 15:06
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants