Skip to content

Commit

Permalink
refactor: standardize export style to named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Dec 2, 2024
1 parent f5445c8 commit 6b99372
Show file tree
Hide file tree
Showing 284 changed files with 1,142 additions and 1,115 deletions.
8 changes: 4 additions & 4 deletions packages/discord.js/scripts/generateRequires.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { readdir, writeFile } from 'node:fs/promises';

async function writeWebsocketHandlerImports() {
const lines = ["'use strict';\n", 'const handlers = Object.fromEntries(['];
const lines = ["'use strict';\n", 'const PacketHandlers = Object.fromEntries(['];

const handlersDirectory = new URL('../src/client/websocket/handlers', import.meta.url);

for (const file of await (await readdir(handlersDirectory)).sort()) {
for (const file of (await readdir(handlersDirectory)).sort()) {
if (file === 'index.js') continue;

lines.push(` ['${file.slice(0, -3)}', require('./${file.slice(0, -3)}')],`);
}

lines.push(']);\n\nmodule.exports = handlers;\n');
lines.push(']);\n\nexports.PacketHandlers = PacketHandlers;\n');

const outputFile = new URL('../src/client/websocket/handlers/index.js', import.meta.url);

Expand Down Expand Up @@ -44,7 +44,7 @@ async function writeClientActionImports() {
lines.push(" this[Action.name.replace(/Action$/, '')] = new Action(this.client);");
lines.push(' }');
lines.push('}\n');
lines.push('module.exports = ActionsManager;\n');
lines.push('exports.ActionsManager = ActionsManager;\n');

const outputFile = new URL('../src/client/actions/ActionsManager.js', import.meta.url);

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/client/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const EventEmitter = require('node:events');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
const Options = require('../util/Options');
const { Options } = require('../util/Options');
const { flatten } = require('../util/Util');

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ class BaseClient extends EventEmitter {
}
}

module.exports = BaseClient;
exports.BaseClient = BaseClient;

/**
* @external REST
Expand Down
48 changes: 24 additions & 24 deletions packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ const { Collection } = require('@discordjs/collection');
const { makeURLSearchParams } = require('@discordjs/rest');
const { WebSocketManager, WebSocketShardEvents, WebSocketShardStatus } = require('@discordjs/ws');
const { GatewayDispatchEvents, GatewayIntentBits, OAuth2Scopes, Routes } = require('discord-api-types/v10');
const BaseClient = require('./BaseClient');
const ActionsManager = require('./actions/ActionsManager');
const ClientVoiceManager = require('./voice/ClientVoiceManager');
const PacketHandlers = require('./websocket/handlers');
const { BaseClient } = require('./BaseClient');
const { ActionsManager } = require('./actions/ActionsManager');
const { ClientVoiceManager } = require('./voice/ClientVoiceManager');
const { PacketHandlers } = require('./websocket/handlers');
const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors');
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
const ChannelManager = require('../managers/ChannelManager');
const GuildManager = require('../managers/GuildManager');
const UserManager = require('../managers/UserManager');
const ShardClientUtil = require('../sharding/ShardClientUtil');
const ClientPresence = require('../structures/ClientPresence');
const GuildPreview = require('../structures/GuildPreview');
const GuildTemplate = require('../structures/GuildTemplate');
const Invite = require('../structures/Invite');
const { BaseGuildEmojiManager } = require('../managers/BaseGuildEmojiManager');
const { ChannelManager } = require('../managers/ChannelManager');
const { GuildManager } = require('../managers/GuildManager');
const { UserManager } = require('../managers/UserManager');
const { ShardClientUtil } = require('../sharding/ShardClientUtil');
const { ClientPresence } = require('../structures/ClientPresence');
const { GuildPreview } = require('../structures/GuildPreview');
const { GuildTemplate } = require('../structures/GuildTemplate');
const { Invite } = require('../structures/Invite');
const { Sticker } = require('../structures/Sticker');
const StickerPack = require('../structures/StickerPack');
const VoiceRegion = require('../structures/VoiceRegion');
const Webhook = require('../structures/Webhook');
const Widget = require('../structures/Widget');
const { StickerPack } = require('../structures/StickerPack');
const { VoiceRegion } = require('../structures/VoiceRegion');
const { Webhook } = require('../structures/Webhook');
const { Widget } = require('../structures/Widget');
const { resolveInviteCode, resolveGuildTemplateCode } = require('../util/DataResolver');
const Events = require('../util/Events');
const IntentsBitField = require('../util/IntentsBitField');
const Options = require('../util/Options');
const PermissionsBitField = require('../util/PermissionsBitField');
const Status = require('../util/Status');
const Sweepers = require('../util/Sweepers');
const { Events } = require('../util/Events');
const { IntentsBitField } = require('../util/IntentsBitField');
const { Options } = require('../util/Options');
const { PermissionsBitField } = require('../util/PermissionsBitField');
const { Status } = require('../util/Status');
const { Sweepers } = require('../util/Sweepers');

const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
const BeforeReadyWhitelist = [
Expand Down Expand Up @@ -732,7 +732,7 @@ class Client extends BaseClient {
}
}

module.exports = Client;
exports.Client = Client;

/**
* @class SnowflakeUtil
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/client/WebhookClient.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const BaseClient = require('./BaseClient');
const { BaseClient } = require('./BaseClient');
const { DiscordjsError, ErrorCodes } = require('../errors');
const Webhook = require('../structures/Webhook');
const { Webhook } = require('../structures/Webhook');
const { parseWebhookURL } = require('../util/Util');

/**
Expand Down Expand Up @@ -100,4 +100,4 @@ class WebhookClient extends BaseClient {

Webhook.applyToClass(WebhookClient);

module.exports = WebhookClient;
exports.WebhookClient = WebhookClient;
6 changes: 3 additions & 3 deletions packages/discord.js/src/client/actions/Action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Partials = require('../../util/Partials');
const { Partials } = require('../../util/Partials');

/*
Expand All @@ -14,7 +14,7 @@ that WebSocket events don't clash with REST methods.
*/

class GenericAction {
class Action {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -117,4 +117,4 @@ class GenericAction {
}
}

module.exports = GenericAction;
exports.Action = Action;
128 changes: 64 additions & 64 deletions packages/discord.js/src/client/actions/ActionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,74 @@ class ActionsManager {
constructor(client) {
this.client = client;

this.register(require('./ApplicationCommandPermissionsUpdate'));
this.register(require('./AutoModerationActionExecution'));
this.register(require('./AutoModerationRuleCreate'));
this.register(require('./AutoModerationRuleDelete'));
this.register(require('./AutoModerationRuleUpdate'));
this.register(require('./ChannelCreate'));
this.register(require('./ChannelDelete'));
this.register(require('./ChannelUpdate'));
this.register(require('./EntitlementCreate'));
this.register(require('./EntitlementDelete'));
this.register(require('./EntitlementUpdate'));
this.register(require('./GuildAuditLogEntryCreate'));
this.register(require('./GuildBanAdd'));
this.register(require('./GuildBanRemove'));
this.register(require('./GuildChannelsPositionUpdate'));
this.register(require('./GuildDelete'));
this.register(require('./GuildEmojiCreate'));
this.register(require('./GuildEmojiDelete'));
this.register(require('./GuildEmojiUpdate'));
this.register(require('./GuildEmojisUpdate'));
this.register(require('./GuildIntegrationsUpdate'));
this.register(require('./GuildMemberRemove'));
this.register(require('./GuildMemberUpdate'));
this.register(require('./GuildRoleCreate'));
this.register(require('./GuildRoleDelete'));
this.register(require('./GuildRoleUpdate'));
this.register(require('./GuildRolesPositionUpdate'));
this.register(require('./GuildScheduledEventCreate'));
this.register(require('./GuildScheduledEventDelete'));
this.register(require('./GuildScheduledEventUpdate'));
this.register(require('./GuildScheduledEventUserAdd'));
this.register(require('./GuildScheduledEventUserRemove'));
this.register(require('./GuildStickerCreate'));
this.register(require('./GuildStickerDelete'));
this.register(require('./GuildStickerUpdate'));
this.register(require('./GuildStickersUpdate'));
this.register(require('./GuildUpdate'));
this.register(require('./InteractionCreate'));
this.register(require('./InviteCreate'));
this.register(require('./InviteDelete'));
this.register(require('./MessageCreate'));
this.register(require('./MessageDelete'));
this.register(require('./MessageDeleteBulk'));
this.register(require('./MessagePollVoteAdd'));
this.register(require('./MessagePollVoteRemove'));
this.register(require('./MessageReactionAdd'));
this.register(require('./MessageReactionRemove'));
this.register(require('./MessageReactionRemoveAll'));
this.register(require('./MessageReactionRemoveEmoji'));
this.register(require('./MessageUpdate'));
this.register(require('./PresenceUpdate'));
this.register(require('./StageInstanceCreate'));
this.register(require('./StageInstanceDelete'));
this.register(require('./StageInstanceUpdate'));
this.register(require('./ThreadCreate'));
this.register(require('./ThreadDelete'));
this.register(require('./ThreadListSync'));
this.register(require('./ThreadMemberUpdate'));
this.register(require('./ThreadMembersUpdate'));
this.register(require('./TypingStart'));
this.register(require('./UserUpdate'));
this.register(require('./VoiceStateUpdate'));
this.register(require('./WebhooksUpdate'));
this.register(require('./ApplicationCommandPermissionsUpdate').ApplicationCommandPermissionsUpdateAction);
this.register(require('./AutoModerationActionExecution').AutoModerationActionExecutionAction);
this.register(require('./AutoModerationRuleCreate').AutoModerationRuleCreateAction);
this.register(require('./AutoModerationRuleDelete').AutoModerationRuleDeleteAction);
this.register(require('./AutoModerationRuleUpdate').AutoModerationRuleUpdateAction);
this.register(require('./ChannelCreate').ChannelCreateAction);
this.register(require('./ChannelDelete').ChannelDeleteAction);
this.register(require('./ChannelUpdate').ChannelUpdateAction);
this.register(require('./EntitlementCreate').EntitlementCreateAction);
this.register(require('./EntitlementDelete').EntitlementDeleteAction);
this.register(require('./EntitlementUpdate').EntitlementUpdateAction);
this.register(require('./GuildAuditLogEntryCreate').GuildAuditLogEntryCreateAction);
this.register(require('./GuildBanAdd').GuildBanAddAction);
this.register(require('./GuildBanRemove').GuildBanRemoveAction);
this.register(require('./GuildChannelsPositionUpdate').GuildChannelsPositionUpdateAction);
this.register(require('./GuildDelete').GuildDeleteAction);
this.register(require('./GuildEmojiCreate').GuildEmojiCreateAction);
this.register(require('./GuildEmojiDelete').GuildEmojiDeleteAction);
this.register(require('./GuildEmojisUpdate').GuildEmojisUpdateAction);
this.register(require('./GuildEmojiUpdate').GuildEmojiUpdateAction);
this.register(require('./GuildIntegrationsUpdate').GuildIntegrationsUpdateAction);
this.register(require('./GuildMemberRemove').GuildMemberRemoveAction);
this.register(require('./GuildMemberUpdate').GuildMemberUpdateAction);
this.register(require('./GuildRoleCreate').GuildRoleCreateAction);
this.register(require('./GuildRoleDelete').GuildRoleDeleteAction);
this.register(require('./GuildRolesPositionUpdate').GuildRolesPositionUpdateAction);
this.register(require('./GuildRoleUpdate').GuildRoleUpdateAction);
this.register(require('./GuildScheduledEventCreate').GuildScheduledEventCreateAction);
this.register(require('./GuildScheduledEventDelete').GuildScheduledEventDeleteAction);
this.register(require('./GuildScheduledEventUpdate').GuildScheduledEventUpdateAction);
this.register(require('./GuildScheduledEventUserAdd').GuildScheduledEventUserAddAction);
this.register(require('./GuildScheduledEventUserRemove').GuildScheduledEventUserRemoveAction);
this.register(require('./GuildStickerCreate').GuildStickerCreateAction);
this.register(require('./GuildStickerDelete').GuildStickerDeleteAction);
this.register(require('./GuildStickersUpdate').GuildStickersUpdateAction);
this.register(require('./GuildStickerUpdate').GuildStickerUpdateAction);
this.register(require('./GuildUpdate').GuildUpdateAction);
this.register(require('./InteractionCreate').InteractionCreateAction);
this.register(require('./InviteCreate').InviteCreateAction);
this.register(require('./InviteDelete').InviteDeleteAction);
this.register(require('./MessageCreate').MessageCreateAction);
this.register(require('./MessageDelete').MessageDeleteAction);
this.register(require('./MessageDeleteBulk').MessageDeleteBulkAction);
this.register(require('./MessagePollVoteAdd').MessagePollVoteAddAction);
this.register(require('./MessagePollVoteRemove').MessagePollVoteRemoveAction);
this.register(require('./MessageReactionAdd').MessageReactionAddAction);
this.register(require('./MessageReactionRemove').MessageReactionRemoveAction);
this.register(require('./MessageReactionRemoveAll').MessageReactionRemoveAllAction);
this.register(require('./MessageReactionRemoveEmoji').MessageReactionRemoveEmojiAction);
this.register(require('./MessageUpdate').MessageUpdateAction);
this.register(require('./PresenceUpdate').PresenceUpdateAction);
this.register(require('./StageInstanceCreate').StageInstanceCreateAction);
this.register(require('./StageInstanceDelete').StageInstanceDeleteAction);
this.register(require('./StageInstanceUpdate').StageInstanceUpdateAction);
this.register(require('./ThreadCreate').ThreadCreateAction);
this.register(require('./ThreadDelete').ThreadDeleteAction);
this.register(require('./ThreadListSync').ThreadListSyncAction);
this.register(require('./ThreadMembersUpdate').ThreadMembersUpdateAction);
this.register(require('./ThreadMemberUpdate').ThreadMemberUpdateAction);
this.register(require('./TypingStart').TypingStartAction);
this.register(require('./UserUpdate').UserUpdateAction);
this.register(require('./VoiceStateUpdate').VoiceStateUpdateAction);
this.register(require('./WebhooksUpdate').WebhooksUpdateAction);
}

register(Action) {
this[Action.name.replace(/Action$/, '')] = new Action(this.client);
}
}

module.exports = ActionsManager;
exports.ActionsManager = ActionsManager;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Action = require('./Action');
const Events = require('../../util/Events');
const { Action } = require('./Action');
const { Events } = require('../../util/Events');

/**
* The data received in the {@link Client#event:applicationCommandPermissionsUpdate} event
Expand Down Expand Up @@ -31,4 +31,4 @@ class ApplicationCommandPermissionsUpdateAction extends Action {
}
}

module.exports = ApplicationCommandPermissionsUpdateAction;
exports.ApplicationCommandPermissionsUpdateAction = ApplicationCommandPermissionsUpdateAction;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const Action = require('./Action');
const AutoModerationActionExecution = require('../../structures/AutoModerationActionExecution');
const Events = require('../../util/Events');
const { Action } = require('./Action');
const { AutoModerationActionExecution } = require('../../structures/AutoModerationActionExecution');
const { Events } = require('../../util/Events');

class AutoModerationActionExecutionAction extends Action {
handle(data) {
Expand All @@ -23,4 +23,4 @@ class AutoModerationActionExecutionAction extends Action {
}
}

module.exports = AutoModerationActionExecutionAction;
exports.AutoModerationActionExecutionAction = AutoModerationActionExecutionAction;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Action = require('./Action');
const Events = require('../../util/Events');
const { Action } = require('./Action');
const { Events } = require('../../util/Events');

class AutoModerationRuleCreateAction extends Action {
handle(data) {
Expand All @@ -24,4 +24,4 @@ class AutoModerationRuleCreateAction extends Action {
}
}

module.exports = AutoModerationRuleCreateAction;
exports.AutoModerationRuleCreateAction = AutoModerationRuleCreateAction;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Action = require('./Action');
const Events = require('../../util/Events');
const { Action } = require('./Action');
const { Events } = require('../../util/Events');

class AutoModerationRuleDeleteAction extends Action {
handle(data) {
Expand All @@ -28,4 +28,4 @@ class AutoModerationRuleDeleteAction extends Action {
}
}

module.exports = AutoModerationRuleDeleteAction;
exports.AutoModerationRuleDeleteAction = AutoModerationRuleDeleteAction;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Action = require('./Action');
const Events = require('../../util/Events');
const { Action } = require('./Action');
const { Events } = require('../../util/Events');

class AutoModerationRuleUpdateAction extends Action {
handle(data) {
Expand All @@ -26,4 +26,4 @@ class AutoModerationRuleUpdateAction extends Action {
}
}

module.exports = AutoModerationRuleUpdateAction;
exports.AutoModerationRuleUpdateAction = AutoModerationRuleUpdateAction;
6 changes: 3 additions & 3 deletions packages/discord.js/src/client/actions/ChannelCreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Action = require('./Action');
const Events = require('../../util/Events');
const { Action } = require('./Action');
const { Events } = require('../../util/Events');

class ChannelCreateAction extends Action {
handle(data) {
Expand All @@ -20,4 +20,4 @@ class ChannelCreateAction extends Action {
}
}

module.exports = ChannelCreateAction;
exports.ChannelCreateAction = ChannelCreateAction;
Loading

0 comments on commit 6b99372

Please sign in to comment.