Skip to content

refactor!: remove builders and formatters re-export#11361

Merged
didinele merged 7 commits intomainfrom
refactor/remove-reexport
Mar 7, 2026
Merged

refactor!: remove builders and formatters re-export#11361
didinele merged 7 commits intomainfrom
refactor/remove-reexport

Conversation

@didinele
Copy link
Member

@didinele didinele commented Dec 12, 2025

people are gonna love me for this one

We've glossed over this briefly in internals, and #11327 also mentioned that this is now possible. The primary argument here is just that there's absolutely no internal dependency on builders anymore (my PR leaves it as a devDep since it is used in tests to ensure things correctly accept JSONEncodables of the right type), and this actually simplifies usage in a sense. There's no real versioning issues anymore, the major of builders you're on (or even implementation? anyone can write a class that implements JSONEncodable, which discord.js will happily accept, it just needs to have a toJSON method) is not significant.

We're also generally somewhat discouraging builders, it should be an option, but it's more of an extension that you can opt into.

"But we still re-export all the other packages" yeah. We critically depend on those for internals and version miss-matches there from a user also installing them can be pretty damaging.

On the topic of formatters, I'm not dying on the hill that we can't re-export them, but I don't necessarily see why we should for the same rationale: it's not a core dependency. We do depend on it to implement certain methods in internals, but that's ok.

Note: Requires discord-api-types bump.

@vercel
Copy link

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
discord-js Skipped Skipped Mar 7, 2026 10:16am
discord-js-guide Skipped Skipped Mar 7, 2026 10:16am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Dec 12, 2025

📝 Walkthrough

Walkthrough

Removed root re-exports of @discordjs/builders and @discordjs/formatters, moved @discordjs/builders to devDependencies, updated TypeScript typings/tests to import builder types directly from @discordjs/builders, and bumped discord-api-types to ^0.38.41 across multiple packages. Also adjusted builder mixin typing to rely on external ApplicationCommandOptionAllowedChannelType.

Changes

Cohort / File(s) Summary
Index export removals
packages/discord.js/src/index.js
Deleted export * re-exports for @discordjs/builders and @discordjs/formatters from the package entry point.
Package manifest (discord.js)
packages/discord.js/package.json
Moved @discordjs/builders from dependencies to devDependencies; bumped discord-api-types to ^0.38.41.
Typings surface
packages/discord.js/typings/index.d.ts
Removed re-exports of @discordjs/builders and @discordjs/formatters; replaced MessageActionRowComponentBuilder usage with JSONEncodable<APIComponentInActionRow> in BaseMessageOptions.components; added ApplicationCommandOptionAllowedChannelType import/usage in channel option types.
Typings tests / imports
packages/discord.js/typings/index.test-d.ts
Replaced previous builder re-exports with direct imports from @discordjs/builders; removed multiple builder symbols from the index export surface.
Builders package typing change
packages/builders/src/.../ApplicationCommandOptionChannelTypesMixin.ts
Removed local exported alias for ApplicationCommandOptionAllowedChannelType, now imports the type from discord-api-types/v10; updated ApplicationCommandOptionAllowedChannelTypes const to use satisfies readonly ApplicationCommandOptionAllowedChannelType[].
Dependency bumps across packages
packages/*/package.json
packages/core/package.json, packages/builders/package.json, packages/formatters/package.json, packages/next/package.json, packages/rest/package.json, packages/structures/package.json, packages/util/package.json, packages/voice/package.json, packages/ws/package.json
Updated discord-api-types dependency from ^0.38.40 to ^0.38.41 in multiple packages; packages/builders/package.json also bumped this dependency. No API surface changes beyond typings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'refactor!: remove builders and formatters re-export' directly and clearly describes the main change: removing the re-export of builders and formatters packages from discord.js.
Description check ✅ Passed The PR description provides detailed context on why builders and formatters re-exports are being removed, explaining the rationale and acknowledging trade-offs with remaining re-exports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/remove-reexport

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@didinele didinele marked this pull request as draft December 12, 2025 08:59
@vercel vercel bot temporarily deployed to Preview – discord-js-guide December 12, 2025 09:03 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js December 12, 2025 09:03 Inactive
@didinele
Copy link
Member Author

I need a hand here, I'm not sure how to deal with this:

import { ApplicationCommandOptionAllowedChannelType } from '@discordjs/builders';

Only usage

export interface ApplicationCommandChannelOptionData extends BaseApplicationCommandOptionsData {
channelTypes?: readonly ApplicationCommandOptionAllowedChannelType[];
channel_types?: readonly ApplicationCommandOptionAllowedChannelType[];
type: CommandOptionChannelResolvableType;
}
export interface ApplicationCommandChannelOption extends BaseApplicationCommandOptionsData {
channelTypes?: readonly ApplicationCommandOptionAllowedChannelType[];
type: ApplicationCommandOptionType.Channel;
}

Do we just move that type to util and call it a day? "Re-implement" it in discord.js? builders has it written like so:

export const ApplicationCommandOptionAllowedChannelTypes = [
ChannelType.GuildText,
ChannelType.GuildVoice,
ChannelType.GuildCategory,
ChannelType.GuildAnnouncement,
ChannelType.AnnouncementThread,
ChannelType.PublicThread,
ChannelType.PrivateThread,
ChannelType.GuildStageVoice,
ChannelType.GuildForum,
ChannelType.GuildMedia,
] as const;
/**
* Allowed channel types used for a channel option.
*/
export type ApplicationCommandOptionAllowedChannelType = (typeof ApplicationCommandOptionAllowedChannelTypes)[number];

@vercel vercel bot temporarily deployed to Preview – discord-js December 12, 2025 09:06 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide December 12, 2025 09:06 Inactive
@didinele
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3adb943 and 39d6f3c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/discord.js/package.json (1 hunks)
  • packages/discord.js/typings/index.d.ts (2 hunks)
  • packages/discord.js/typings/index.test-d.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/discord.js/typings/index.d.ts (1)
packages/util/src/encodables.ts (1)
  • JSONEncodable (8-13)
🔇 Additional comments (3)
packages/discord.js/typings/index.d.ts (1)

6689-6701: BaseMessageOptions.components update matches “any JSONEncodable” direction.

The switch to ActionRowData<JSONEncodable<APIComponentInActionRow> | MessageActionRowComponentData> is consistent with dropping builder-specific component types while still supporting toJSON()-based inputs.

packages/discord.js/typings/index.test-d.ts (2)

4-20: Import paths correctly updated for builders module separation.

The builder imports are now correctly sourced directly from @discordjs/builders rather than through the discord.js package root, which aligns with the PR's objective to remove re-exports. All builder types and classes—including ActionRowBuilder, EmbedBuilder, MessageBuilder, and command builder types—are properly imported from the dedicated module.


826-827: Builder type declarations integrate correctly with test suite.

The declarations of slashCommandBuilder and contextMenuCommandBuilder as types (not instances) are well-positioned and used consistently throughout the test suite (e.g., lines 847–855 for command creation/edit tests). These type declarations maintain the test's ability to validate discord.js's type compatibility with builder instances.

@didinele didinele changed the title refactor: remove builders and formatters re-export refactor!: remove builders and formatters re-export Dec 12, 2025
@didinele didinele force-pushed the refactor/remove-reexport branch from 39d6f3c to aea7f94 Compare March 5, 2026 12:58
@vercel vercel bot temporarily deployed to Preview – discord-js March 5, 2026 12:58 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 5, 2026 12:58 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 5, 2026 14:16 Inactive
@didinele didinele requested review from a team as code owners March 5, 2026 14:28
@didinele
Copy link
Member Author

didinele commented Mar 5, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

1 similar comment
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/discord.js/package.json (1)

83-86: ⚠️ Potential issue | 🔴 Critical

Public typings must not depend on a dev-only package.

Line 85 keeps @discordjs/builders in devDependencies. If packages/discord.js/typings/index.d.ts (or .d.mts) still imports from @discordjs/builders, downstream TS users can fail module resolution.

Suggested fix
   "dependencies": {
+    "@discordjs/builders": "workspace:^",
     "@discordjs/collection": "workspace:^",
     "@discordjs/formatters": "workspace:^",
     "@discordjs/rest": "workspace:^",
     "@discordjs/util": "workspace:^",
     "@discordjs/ws": "workspace:^",
@@
   "devDependencies": {
     "@discordjs/api-extractor": "workspace:^",
-    "@discordjs/builders": "workspace:^",
     "@discordjs/docgen": "workspace:^",
#!/bin/bash
set -euo pipefail

echo "== Check public typings for `@discordjs/builders` references =="
rg -nP '(`@discordjs/builders`)' \
  packages/discord.js/typings/index.d.ts \
  packages/discord.js/typings/index.d.mts || true

echo
echo "== Check where `@discordjs/builders` is declared =="
python - <<'PY'
import json
from pathlib import Path

pkg = json.loads(Path("packages/discord.js/package.json").read_text())
for section in ("dependencies", "peerDependencies", "devDependencies"):
    print(f"{section}: {pkg.get(section, {}).get('@discordjs/builders')}")
PY
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/discord.js/package.json` around lines 83 - 86, The package exposes
typings that import `@discordjs/builders` (see
packages/discord.js/typings/index.d.ts / index.d.mts) but `@discordjs/builders` is
currently only in devDependencies; move `@discordjs/builders` out of
devDependencies into either dependencies or peerDependencies in package.json so
downstream TypeScript resolution succeeds (use peerDependencies if you expect
consumers to provide it, dependencies if you want to bundle it). After updating
package.json, verify there are no remaining references with the provided
ripgrep/python checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/discord.js/package.json`:
- Around line 83-86: The package exposes typings that import `@discordjs/builders`
(see packages/discord.js/typings/index.d.ts / index.d.mts) but
`@discordjs/builders` is currently only in devDependencies; move
`@discordjs/builders` out of devDependencies into either dependencies or
peerDependencies in package.json so downstream TypeScript resolution succeeds
(use peerDependencies if you expect consumers to provide it, dependencies if you
want to bundle it). After updating package.json, verify there are no remaining
references with the provided ripgrep/python checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d2d7e48e-0144-441e-a00b-b19215f91f02

📥 Commits

Reviewing files that changed from the base of the PR and between 39d6f3c and adff2c8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • packages/builders/package.json
  • packages/builders/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.ts
  • packages/core/package.json
  • packages/discord.js/package.json
  • packages/discord.js/src/index.js
  • packages/discord.js/typings/index.d.ts
  • packages/discord.js/typings/index.test-d.ts
  • packages/formatters/package.json
  • packages/next/package.json
  • packages/rest/package.json
  • packages/structures/package.json
  • packages/util/package.json
  • packages/voice/package.json
  • packages/ws/package.json
💤 Files with no reviewable changes (1)
  • packages/discord.js/src/index.js
📜 Review details
🔇 Additional comments (14)
packages/structures/package.json (1)

66-66: LGTM: dependency bump is consistent with the PR scope.

This discord-api-types patch bump is aligned and safe at the manifest level.

packages/core/package.json (1)

73-73: LGTM: clean patch-level dependency update.

No issues identified with this package manifest change.

packages/util/package.json (1)

65-65: LGTM: manifest change looks correct.

The discord-api-types bump is coherent with the rest of the PR.

packages/next/package.json (1)

75-75: LGTM: dependency version bump is appropriate.

No concerns with this isolated change.

packages/rest/package.json (1)

91-91: LGTM: this dependency bump is well-scoped.

No manifest or dependency declaration issues spotted here.

packages/voice/package.json (1)

68-68: LGTM: dependency alignment looks good.

This package.json change is consistent with the PR-wide version bump.

packages/ws/package.json (1)

81-81: LGTM: package manifest update is correct.

No issues found in this dependency version increment.

packages/builders/package.json (1)

69-69: LGTM: dependency bump is consistent and safe.

No additional action needed for this segment.

packages/formatters/package.json (1)

58-58: No actionable feedback for this segment.

packages/discord.js/package.json (1)

76-76: No actionable feedback for this segment.

packages/builders/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.ts (1)

1-5: No actionable feedback for this segment.

Also applies to: 19-19

packages/discord.js/typings/index.d.ts (2)

101-101: Good decoupling of published typings from builders.

Line 101 correctly sources ApplicationCommandOptionAllowedChannelType from discord-api-types/v10, removing the @discordjs/builders typing dependency from this public declaration file.


6748-6748: Typing update matches the “JSONEncodable, builders-optional” direction.

Line 6748 broadens BaseMessageOptions.components to JSONEncodable<APIComponentInActionRow> | MessageActionRowComponentData, which preserves compatibility for builder-like/custom toJSON() implementations without requiring builders re-exports.

packages/discord.js/typings/index.test-d.ts (1)

4-20: Direct builders import alignment looks correct.

This import shift to @discordjs/builders is consistent with the re-export removal objective, and the imported symbols are used coherently throughout the test file.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/discord.js/typings/index.d.ts`:
- Line 6748: The ActionRowData generic currently allows
JSONEncodable<APIComponentInActionRow>, which includes modal-only components;
narrow it to message-only components by replacing
JSONEncodable<APIComponentInActionRow> with a JSONEncodable type limited to
message components (e.g. JSONEncodable<APIButtonComponent |
APISelectMenuComponent> or an existing alias representing message components) so
that the union becomes ActionRowData<JSONEncodable<APIButtonComponent |
APISelectMenuComponent> | MessageActionRowComponentData>; update the type where
BaseMessageOptions.components and the symbol ActionRowData are used and ensure
you reference APIComponentInActionRow, APIButtonComponent,
APISelectMenuComponent, and MessageActionRowComponentData when making the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bf49572a-5cf7-4770-bd1b-1e75f7ec071c

📥 Commits

Reviewing files that changed from the base of the PR and between 39d6f3c and adff2c8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • packages/builders/package.json
  • packages/builders/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.ts
  • packages/core/package.json
  • packages/discord.js/package.json
  • packages/discord.js/src/index.js
  • packages/discord.js/typings/index.d.ts
  • packages/discord.js/typings/index.test-d.ts
  • packages/formatters/package.json
  • packages/next/package.json
  • packages/rest/package.json
  • packages/structures/package.json
  • packages/util/package.json
  • packages/voice/package.json
  • packages/ws/package.json
💤 Files with no reviewable changes (1)
  • packages/discord.js/src/index.js
📜 Review details
🔇 Additional comments (14)
packages/structures/package.json (1)

66-66: Dependency update is aligned and safe in this manifest segment.

Bumping discord-api-types to ^0.38.41 here matches the PR’s package-alignment goal and looks correct.

packages/rest/package.json (1)

91-91: Dependency bump looks correct and scoped.

Line 91 updates discord-api-types to ^0.38.41, which matches the stated PR requirement and keeps this package aligned with the cross-repo API types update.

packages/util/package.json (1)

65-65: Dependency bump is consistent and safe in this manifest segment.

This update aligns with the PR-wide discord-api-types refresh and does not introduce package.json structural issues.

packages/voice/package.json (1)

68-68: LGTM! The patch-level bump to discord-api-types ^0.38.41 is valid and published. This aligns with the coordinated dependency update across the monorepo.

packages/core/package.json (1)

73-73: All discord-api-types declarations across the workspace are consistently set to ^0.38.41. No version skew detected.

packages/next/package.json (1)

75-75: Dependency bump verified; version discord-api-types@0.38.41 exists on npm registry.

No issues found. The version is published and resolvable. Change is safe to merge.

packages/ws/package.json (1)

81-81: Dependency bump is consistent with the coordinated workspace upgrade.

No issues found in this segment.

packages/formatters/package.json (1)

58-58: discord-api-types bump looks correct and aligned with the monorepo update.

No blocking concerns here.

packages/builders/package.json (1)

69-69: Version update is coherent with the rest of the dependency alignment.

This segment looks good.

packages/discord.js/package.json (2)

76-76: discord-api-types bump is consistent with the coordinated package updates.

No issues on this change.


85-85: Keeping @discordjs/builders as a dev dependency is consistent with this PR’s API-surface change.

Given the re-export removal and updated test/import strategy, this placement is coherent.

packages/builders/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.ts (1)

1-5: Type-source and constraint update is clean and type-safe.

The direct type import plus satisfies keeps the runtime list and API channel-type contract in sync.

Also applies to: 19-19

packages/discord.js/typings/index.test-d.ts (1)

4-20: Typings test imports are correctly redirected to @discordjs/builders.

This aligns the test surface with the removed re-exports from discord.js.

packages/discord.js/typings/index.d.ts (1)

101-101: Import decoupling from builders looks correct.

Line 101 now sources ApplicationCommandOptionAllowedChannelType from discord-api-types/v10, which matches the builders re-export removal goal.

Copy link
Member

@Qjuh Qjuh left a comment

Choose a reason for hiding this comment

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

Apart from the nit pointed out by coderabbit LGTM

@vercel vercel bot temporarily deployed to Preview – discord-js March 6, 2026 11:31 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 6, 2026 11:31 Inactive
@github-project-automation github-project-automation bot moved this from Todo to Review Approved in discord.js Mar 7, 2026
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 7, 2026 10:16 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js March 7, 2026 10:16 Inactive
@didinele didinele merged commit 84b85f4 into main Mar 7, 2026
28 checks passed
@didinele didinele deleted the refactor/remove-reexport branch March 7, 2026 10:25
@github-project-automation github-project-automation bot moved this from Review Approved to Done in discord.js Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants