Replace rollup-plugin-dts with dts-bundle-generator#370
Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 13 commits intoMay 22, 2026
Conversation
Uses a two-pass approach to avoid DOM lib vs @types/node conflicts: - Pass 1: TypeScript API emits .d.ts for all workspace files without DOM lib - Pass 2: dts-bundle-generator bundles against emitted .d.ts files with DOM lib, skipping its own compilation pass (allFilesAreDeclarations shortcut) Includes a Yarn patch for dts-bundle-generator to add a missing null check in TypesUsageEvaluator when getImportExportReferencedSymbol returns undefined (triggered by postcss.d.mts exporting from ./postcss.js in bundler mode). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Emit temp .d.ts files and tsconfigs to os.tmpdir() to avoid cluttering CWD - Symlink project node_modules into the temp dir so TypeScript can resolve external packages from emitted files - Use absolute paths for tsconfig extends since the temp configs live outside the project - Configure inlinedLibraries (@datadog/browser-rum-core, @datadog/browser-core) vs importedLibraries (peer/runtime deps) for dts-bundle-generator - Update LICENSES-3rdparty.csv to swap rollup-plugin-dts for dts-bundle-generator
- Emit temp files inside the project (`.dts-tmp-<pkg>/`) so TypeScript finds node_modules by walking up — drops the symlink hack. - Hoist `dts-bundle-generator` and `typescript` to top-level imports. - Drop the `generated` flag; Rollup calls `closeBundle` once per bundle. - Wrap the whole mkdir → emit → bundle flow in `try/finally` so an error mid-build doesn't leak temp dirs. - Co-locate both tsconfigs inside the temp dir, single cleanup target. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Skip pass 1's tsconfig file write — feed the parsed root config to
`ts.parseJsonConfigFileContent` directly and merge overrides in the
`createProgram` call.
- Drop redundant `emitOnlyDtsFiles=true` (already implied by
`emitDeclarationOnly`) and the explicit `createCompilerHost`
(`createProgram` builds its own).
- Hoist `entrySrcPath` / `entryDtsPath` and drop `|| {}` defensives on
`peerDependencies`/`dependencies` since the typedef declares them.
- Tighten the doc block and inline notes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dts-bundle-generator's default `exportReferencedTypes: true` was
preserving the `export` modifier on every type it inlined from
`@datadog/browser-rum-core` / `@datadog/browser-core`, leaking ~280
internal types (Site, BufferedObservable, Encoder, TraceContextInjection,
…) as part of our public API.
Setting it to `false` keeps the documented surface (`VitePluginOptions`,
`datadogVitePlugin`, `*Types`, `helpers`) exported and demotes everything
else to `declare`, so structural lookups like `RumTypes['RumInitConfiguration']`
still work but `import { Site } from '@datadog/vite-plugin'` no longer
compiles.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move the @dd/* `paths` map from a runtime `buildDdPaths()` fs walk in the rollup config to a declarative block in the root tsconfig.json. Both dts passes already extend the root config, so pass 1 inherits the paths and pass 2 reads them off the parsed root config to compute the .d.ts variant. - Drops ~42 lines of node_modules-walking logic. - Makes the workspace structure visible at a glance. - Aligns paths with what tsc / typecheck already see. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Derives the expected @dd/* `paths` map from each workspace's package.json `exports` and reconciles it with the root tsconfig.json. The check is idempotent — if the existing paths match, the file is not rewritten — and auto-fixes when a workspace is added/renamed/removed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Compare the existing paths block as-is — any out-of-order entry triggers a rewrite so the on-disk file is always alphabetically sorted. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- `toBuild` is now nested under each plugin's `buildPlugin` block, alongside the existing `hideFromRootReadme`. - New `buildPlugin.inlinedLibraries` field lets plugins declare which npm packages should be inlined into the bundled .d.ts. - `getDtsBundlePlugin` collects the union of `inlinedLibraries` from every plugin manifest at build time, replacing the hardcoded list in the rollup config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move `getDtsBundlePlugin` and its `collectInlinedLibraries` / `buildDtsPaths` helpers from `rollupConfig.mjs` into a sibling `dtsBundlePlugin.mjs`. `rollupConfig.mjs` now just imports the plugin factory; the dts-specific deps (`dts-bundle-generator`, `typescript`) only load on the consumer side. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
michaeldfoley
approved these changes
May 19, 2026
1 task
amortemousque
approved these changes
May 20, 2026
Member
Author
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.
What and why?
Replace
rollup-plugin-dtswithdts-bundle-generatorfor bundling the published packages' TypeScript declarations. The previous setup hit DOM-lib vs@types/nodeconflicts when bundling types that pulled in browser APIs (e.g. the RUM Browser SDK types) and was flagged as slow in the rollup config.This unblocks #144 (exposing the RUM plugin in the root README and dropping its
hideFromRootReadmeflag). #144 wants consumers of the published bundler plugins to be able to configure RUM without installing@datadog/browser-rumthemselves — which requiresRumInitConfigurationandRumPublicApito be bundled into the shipped.d.ts. Underrollup-plugin-dtsthe bundle failed on DOM-vs-Node lib conflicts the moment those SDK types entered the graph, so #144 carried a// TODO: Find a way to bundle in types in the plugin.and a fallback path that re-declared the SDK types by hand. With this PR's two-pass +inlinedLibrariessetup, the SDK types are inlined cleanly into the published.d.ts, and #144 can drop the workaround and useAssign<RumInitConfiguration, …>directly.How?
Two-pass bundling (
packages/tools/src/dtsBundlePlugin.mjs).d.tsfor every workspace file reachable from the entry, using the root tsconfig (no DOM lib, so no@types/nodeconflict).dts-bundle-generatorbundles against the emitted.d.tsfiles with DOM lib enabled. Because every reachable file is now a declaration (entry +@dd/*redirected viapaths), dts-bundle-generator hits itsallFilesAreDeclarationsshortcut and skips its own compilation — so the lib conflict never resurfaces..d.ts, the bundle tsconfig) land in<CWD>/.dts-tmp-<package>/so TypeScript resolves external packages via the project'snode_modulesby walking up — no symlink hacks. The wholemkdir → emit → bundle → writeflow is wrapped intry/finally, so a failure cleans up.dts-bundle-generator,typescript) don't leak intorollupConfig.mjs's import graph.Workspace
@dd/*pathstsconfig.json(compilerOptions.paths). Both passes extend the root config and inherit them; pass 2 rewrites them to point at the emitted.d.tsfiles inside the temp dir.yarn cli integritycheck derives the expected mapping from each workspace'spackage.jsonexportsand reconciles it with the root tsconfig — idempotent when correct, auto-fixes drift, always writes alphabetically sorted.Plugin
buildPluginconfigpackage.jsonnow carries its build-time config under a singlebuildPluginblock (alongside the pre-existinghideFromRootReadme):buildPlugin.inlinedLibraries: npm packages whose types should be folded into the bundled.d.tsrather than left as imports (currently@datadog/browser-core+@datadog/browser-rum-core, declared on@dd/rum-plugin).buildPlugin.toBuild: sub-build descriptors that used to live at the top level ofpackage.json.inlinedLibrariesat build time — no shared rollup-config edits when adding a future plugin that needs to inline another library.Library configuration at the dts-bundle-generator call site
inlinedLibraries: union of plugin-declared values.importedLibraries: every peer/runtime dep that isn't inlined — preserved asimportstatements.output.exportReferencedTypes: false— keeps internally-referenced SDK types (Site,BufferedObservable,Encoder, …) asdeclarerather thanexport. Without this, dts-bundle-generator's default behaviour was leaking ~280 internal types as part of our public API surface; the documented surface is now ~10 names (VitePluginOptions,datadogVitePlugin, the per-plugin*Typeslookups,helpers,version).RUM SDK types
packages/plugins/rum/src/browserSdkTypes.tsre-exportsRumPublicApiandRumInitConfigurationfrom@datadog/browser-rum-coredirectly (instead of the top-level@datadog/browser-rum). This matches what's inlined and avoids atypeof datadogRumindirection that confused the bundler.Yarn patch on dts-bundle-generator
TypesUsageEvaluatorfor cases wheregetImportExportReferencedSymbolreturnsundefined(triggered bypostcss.d.mtsre-exporting from./postcss.jsunder bundler-mode resolution).inlinedLibraries: the evaluator walks types fromimportedLibrariesand other transitive sources too, so the bug is reachable throughvite/rolluppeer-dep type graphs.