Skip to content

Commit

Permalink
refactor: switch es module resolution method
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Nov 2, 2023
1 parent dfaf25f commit b431ecf
Show file tree
Hide file tree
Showing 53 changed files with 118 additions and 134 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"curly": ["error", "all"],
"eqeqeq": ["error", "always", { "null": "ignore" }],
"no-eq-null": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
"import/extensions": ["error", { ".js": "always" }]
"@typescript-eslint/consistent-type-definitions": ["error", "interface"]
}
}
9 changes: 1 addition & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ services:
- ./logs:/usr/modmail/logs
depends_on:
- postgres
command:
[
'node',
'--es-module-specifier-resolution=node',
'--enable-source-maps',
'--no-warnings',
'./packages/bot/dist/index.js',
]
command: ['node', '--enable-source-maps', '--no-warnings', './packages/bot/dist/index.js']

volumes:
postgres-data:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@typescript-eslint/parser": "^6.9.1",
"dotenv-cli": "^7.3.0",
"eslint": "^8.52.0",
"eslint-config-neon": "0.1.56",
"eslint-config-neon": "0.1.54",
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"prettier": "^3.0.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import helmet from 'helmet';
import type { Middleware } from 'polka';
import polka from 'polka';
import { container } from 'tsyringe';
import { Env } from './util/env';
import { logger } from './util/logger';
import { Env } from './util/env.js';
import { logger } from './util/logger.js';

const env = container.resolve(Env);
container.register(PrismaClient, { useValue: new PrismaClient() });
Expand Down Expand Up @@ -57,4 +57,4 @@ for await (const file of files) {

app.listen(env.port, () => logger.info(`Listening to requests on port ${env.port}`));

export * from './routeTypes';
export * from './routeTypes.js';
2 changes: 1 addition & 1 deletion packages/api/src/routeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ export type InferModmailRouteResult<
TMethod extends keyof ModmailRoutes[TPath],
> = InferRouteResult<ModmailRoutes[TPath][TMethod]>;

export * from './util/models';
export * from './util/models.js';
4 changes: 2 additions & 2 deletions packages/api/src/routes/createSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import type {
import { ApplicationCommandOptionType, Routes } from 'discord-api-types/v10';
import type { NextHandler, Response } from 'polka';
import { singleton } from 'tsyringe';
import { Env } from '../util/env';
import { Env } from '../util/env.js';
import type { Snippet } from '../util/models';
import { snowflakeSchema } from '../util/snowflakeSchema';
import { snowflakeSchema } from '../util/snowflakeSchema.js';

const schema = s.object({
name: s.string.lengthGreaterThan(0).lengthLessThanOrEqual(32),
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/routes/deleteSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { s } from '@sapphire/shapeshift';
import { Routes } from 'discord-api-types/v10';
import type { NextHandler, Request, Response } from 'polka';
import { singleton } from 'tsyringe';
import { Env } from '../util/env';
import { Env } from '../util/env.js';
import type { Snippet } from '../util/models';
import { snowflakeSchema } from '../util/snowflakeSchema';
import { snowflakeSchema } from '../util/snowflakeSchema.js';

@singleton()
export default class extends Route<Snippet, never> {
Expand Down
14 changes: 7 additions & 7 deletions packages/api/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as GetSettingsRoute } from './getSettings';
export { default as UpdateSettingsRoute } from './updateSettings';
export { default as GetSnippetsRoute } from './getSnippets';
export { default as GetSnippetRoute } from './getSnippet';
export { default as CreateSnippetRoute } from './createSnippet';
export { default as UpdateSnippetRoute } from './updateSnippet';
export { default as DeleteSnippetRoute } from './deleteSnippet';
export { default as GetSettingsRoute } from './getSettings.js';
export { default as UpdateSettingsRoute } from './updateSettings.js';
export { default as GetSnippetsRoute } from './getSnippets.js';
export { default as GetSnippetRoute } from './getSnippet.js';
export { default as CreateSnippetRoute } from './createSnippet.js';
export { default as UpdateSnippetRoute } from './updateSnippet.js';
export { default as DeleteSnippetRoute } from './deleteSnippet.js';
2 changes: 1 addition & 1 deletion packages/api/src/routes/updateSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { s } from '@sapphire/shapeshift';
import type { Response } from 'polka';
import { singleton } from 'tsyringe';
import type { GuildSettings } from '../util/models';
import { snowflakeSchema } from '../util/snowflakeSchema';
import { snowflakeSchema } from '../util/snowflakeSchema.js';

const schema = s.object({
modmailChannelId: snowflakeSchema.nullish,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/routes/updateSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type { RESTPatchAPIApplicationGuildCommandJSONBody } from 'discord-api-ty
import { Routes } from 'discord-api-types/v10';
import type { NextHandler, Response } from 'polka';
import { singleton } from 'tsyringe';
import { Env } from '../util/env';
import { Env } from '../util/env.js';
import type { Snippet } from '../util/models';
import { snowflakeSchema } from '../util/snowflakeSchema';
import { snowflakeSchema } from '../util/snowflakeSchema.js';

const schema = s.object({
name: s.string.lengthGreaterThan(0).lengthLessThanOrEqual(32).optional,
Expand Down
4 changes: 0 additions & 4 deletions packages/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"private": true,
"version": "1.0.0-dev",
"type": "module",
"imports": {
"#struct/*": "./dist/struct/*.js",
"#util/*": "./dist/util/*.js"
},
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc",
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { PermissionResolvable } from 'discord.js';
import { ApplicationCommandType, type ChatInputCommandInteraction } from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { durationAutoComplete } from '#util/durationAutoComplete';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import { durationAutoComplete } from '../util/durationAutoComplete.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { durationAutoComplete } from '#util/durationAutoComplete';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import { durationAutoComplete } from '../util/durationAutoComplete.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/commands/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { PermissionResolvable, ThreadChannel } from 'discord.js';
import { ApplicationCommandOptionType, ApplicationCommandType, type ChatInputCommandInteraction } from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { closeThread } from '#util/closeThread';
import { durationAutoComplete } from '#util/durationAutoComplete';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import { closeThread } from '../util/closeThread.js';
import { durationAutoComplete } from '../util/durationAutoComplete.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type ChatInputCommandInteraction,
} from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down Expand Up @@ -101,7 +101,7 @@ export default class implements Command<ApplicationCommandType.ChatInput> {

return interaction.reply({
content: stripIndents`
• **modmail channel**: ${configured.modmailChannelId ? `<#${configured.modmailChannelId}>` : 'none'}
• **modmail channel**: ${configured.modmailChannelId ? `<../${configured.modmailChannelId}>` : 'none'}
• **greeting message**: ${configured.greetingMessage ? configured.greetingMessage : 'none'}
• **farewell message**: ${configured.farewellMessage ? configured.farewellMessage : 'none'}
• **simple mode**: ${configured.simpleMode ? 'enabled' : 'disabled'}
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/commands/context-menus/createSnippet.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { MessageContextMenuCommandInteraction, PermissionResolvable } from 'discord.js';
import { ApplicationCommandType } from 'discord.js';
import { singleton } from 'tsyringe';
import type { Command, CommandBody } from '#struct/Command';
import { getLocalizedProp } from '#struct/Command';
import promptSnippetAdd from '../../modals/snippets/add';
import promptSnippetAdd from '../../modals/snippets/add.js';
import type { Command, CommandBody } from '../../struct/Command.js';
import { getLocalizedProp } from '../../struct/Command.js';

@singleton()
export default class implements Command<ApplicationCommandType.Message> {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/commands/context-menus/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MessageContextMenuCommandInteraction, PermissionResolvable } from
import { ApplicationCommandType, Client } from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { getLocalizedProp, type CommandBody, type Command } from '../../struct/Command.js';

@singleton()
export default class implements Command<ApplicationCommandType.Message> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/context-menus/open.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PermissionResolvable } from 'discord.js';
import { ApplicationCommandType, type UserContextMenuCommandInteraction } from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { openThread } from '#util/handleThreadManagement';
import { getLocalizedProp, type CommandBody, type Command } from '../../struct/Command.js';
import { openThread } from '../../util/handleThreadManagement.js';

@singleton()
export default class implements Command<ApplicationCommandType.User> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/context-menus/reply-anon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MessageContextMenuCommandInteraction, PermissionResolvable } from 'discord.js';
import { ApplicationCommandType } from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import ReplyContextMenu from './reply';
import { getLocalizedProp, type CommandBody, type Command } from '../../struct/Command.js';
import ReplyContextMenu from './reply.js';

@singleton()
export default class implements Command<ApplicationCommandType.Message> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/context-menus/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { MessageContextMenuCommandInteraction, PermissionResolvable, Thread
import { ApplicationCommandType } from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { sendStaffThreadMessage } from '#util/sendStaffThreadMessage';
import { getLocalizedProp, type CommandBody, type Command } from '../../struct/Command.js';
import { sendStaffThreadMessage } from '../../util/sendStaffThreadMessage.js';

@singleton()
export default class implements Command<ApplicationCommandType.Message> {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/edit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PermissionResolvable } from 'discord.js';
import { ApplicationCommandOptionType, ApplicationCommandType, type ChatInputCommandInteraction } from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { handleStaffThreadMessage, HandleStaffThreadMessageAction } from '#util/handleStaffThreadMessage';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import { handleStaffThreadMessage, HandleStaffThreadMessageAction } from '../util/handleStaffThreadMessage.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import type { SelectMenuPaginatorConsumers } from '#struct/SelectMenuPaginator';
import { SelectMenuPaginator } from '#struct/SelectMenuPaginator';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import type { SelectMenuPaginatorConsumers } from '../struct/SelectMenuPaginator.js';
import { SelectMenuPaginator } from '../struct/SelectMenuPaginator.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PermissionResolvable } from 'discord.js';
import { ApplicationCommandOptionType, ApplicationCommandType, type ChatInputCommandInteraction } from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { openThread } from '#util/handleThreadManagement';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import { openThread } from '../util/handleThreadManagement.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
type ChatInputCommandInteraction,
} from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { handleStaffThreadMessage, HandleStaffThreadMessageAction } from '#util/handleStaffThreadMessage';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';
import { handleStaffThreadMessage, HandleStaffThreadMessageAction } from '../util/handleStaffThreadMessage.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/snippets/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
PermissionResolvable,
} from 'discord.js';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type Subcommand } from '#struct/Command';
import promptSnippetAdd from '../../modals/snippets/add';
import promptSnippetAdd from '../../modals/snippets/add.js';
import { getLocalizedProp, type Subcommand } from '../../struct/Command.js';

@singleton()
export default class implements Subcommand {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/commands/snippets/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type Subcommand } from '#struct/Command';
import { getLocalizedProp, type Subcommand } from '../../struct/Command.js';

@singleton()
export default class implements Subcommand {
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/commands/snippets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { PrismaClient } from '@prisma/client';
import type { ApplicationCommandType } from 'discord.js';
import { PermissionsBitField, type ApplicationCommandOptionChoiceData, type AutocompleteInteraction } from 'discord.js';
import { singleton } from 'tsyringe';
import type { CommandWithSubcommands } from '#struct/Command';
import { getLocalizedProp, type CommandBody } from '#struct/Command';
import type { CommandWithSubcommands } from '../../struct/Command.js';
import { getLocalizedProp, type CommandBody } from '../../struct/Command.js';

@singleton()
export default class implements CommandWithSubcommands {
Expand Down
6 changes: 3 additions & 3 deletions packages/bot/src/commands/snippets/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type Subcommand } from '#struct/Command';
import { SelectMenuPaginator, type SelectMenuPaginatorConsumers } from '#struct/SelectMenuPaginator';
import { ellipsis } from '#util/ellipsis';
import { getLocalizedProp, type Subcommand } from '../../struct/Command.js';
import { SelectMenuPaginator, type SelectMenuPaginatorConsumers } from '../../struct/SelectMenuPaginator.js';
import { ellipsis } from '../../util/ellipsis.js';

@singleton()
export default class implements Subcommand {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/commands/snippets/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type Subcommand } from '#struct/Command';
import { getLocalizedProp, type Subcommand } from '../../struct/Command.js';

@singleton()
export default class implements Subcommand {
Expand Down
10 changes: 5 additions & 5 deletions packages/bot/src/commands/snippets/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
} from 'discord.js';
import i18next from 'i18next';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type Subcommand } from '#struct/Command';
import { SelectMenuPaginator, type SelectMenuPaginatorConsumers } from '#struct/SelectMenuPaginator';
import { diff } from '#util/diff';
import { ellipsis } from '#util/ellipsis';
import { getLocalizedProp, type Subcommand } from '../../struct/Command.js';
import { SelectMenuPaginator, type SelectMenuPaginatorConsumers } from '../../struct/SelectMenuPaginator.js';
import { diff } from '../../util/diff.js';
import { ellipsis } from '../../util/ellipsis.js';

@singleton()
export default class implements Subcommand {
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class implements Subcommand {
.setFooter({
text: i18next.t('commands.snippets.show.history.embed.footer', {
lng: interaction.locale,
user: updatedBy?.tag ?? 'Unknown User#0000',
user: updatedBy?.tag ?? 'Unknown User../0000',
}),
iconURL: updatedBy?.displayAvatarURL(),
})
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/commands/unblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import i18next from 'i18next';
import { PrismaError } from 'prisma-error-enum';
import { singleton } from 'tsyringe';
import { getLocalizedProp, type CommandBody, type Command } from '#struct/Command';
import { getLocalizedProp, type CommandBody, type Command } from '../struct/Command.js';

@singleton()
export default class implements Command<ApplicationCommandType.ChatInput> {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { container } from 'tsyringe';
import { CommandHandler } from '#struct/CommandHandler';
import { CommandHandler } from './struct/CommandHandler.js';

export async function deploySlashCommands(): Promise<void> {
const commandHandler = container.resolve(CommandHandler);
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/events/error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Events } from 'discord.js';
import { singleton } from 'tsyringe';
import type { Event } from '#struct/Event';
import { logger } from '#util/logger';
import type { Event } from '../struct/Event.js';
import { logger } from '../util/logger.js';

@singleton()
export default class implements Event<typeof Events.Error> {
Expand Down
Loading

0 comments on commit b431ecf

Please sign in to comment.