fix(build): make oRPC/tRPC dist runnable under node ESM (deploy crashloop)

flake.nix only rewrote @/ aliases but left extensionless relative imports
(./router) in compiled dist/. node dist/index.js (how prod runs) cannot
resolve extensionless ESM specifiers -> ERR_MODULE_NOT_FOUND -> backend
crashlooped (444 restarts, port 4001 dead). Extract the fixer into a shared
scripts/fix-imports.mjs that appends .js to extensionless relative imports and
rewrites @/ aliases, and wire it into backend + discord-gateway build phases.

Verified: fresh tsc + fixer -> node dist/index.js boots; oRPC over /trpc
serves both HTTP POST and WebSocket (config/dashboard/voice/moderation/
media/chatbot/analysis) end-to-end against Postgres + Redis. next build
passes with the oRPC client + partysocket.
This commit is contained in:
asepharyana committed 2026-08-16 14:45:02 +07:00
1 parent 2fa1827f17
commit 726a8e116b
27 files changed
+646 -417

No files matched your search

+9 -9
View File
@@ -1,4 +1,4 @@
import { trpc } from "@/lib/trpc/client";
import { orpc } from "@/lib/orpc/client";
import type { AttachmentRecord, MessageRecord } from "@/lib/types";
export const messagesApi = {
@@ -8,7 +8,7 @@ export const messagesApi = {
channelId?: string,
cursor?: string,
) =>
trpc.messages.list.query({
orpc.messages.list({
guildId,
limit,
channelId,
@@ -19,7 +19,7 @@ export const messagesApi = {
}>,
getByChannel: (channelId: string, limit?: number, cursor?: string) =>
trpc.messages.byChannel.query({
orpc.messages.byChannel({
channelId,
query: { channelId, limit, cursor },
}) as unknown as Promise<{
@@ -28,10 +28,10 @@ export const messagesApi = {
}>,
getDetail: (id: string) =>
trpc.messages.detail.query({ id }) as unknown as Promise<MessageRecord>,
orpc.messages.detail({ id }) as unknown as Promise<MessageRecord>,
getImages: (guildId: string, limit?: number) =>
trpc.messages.images.query({ guildId, limit }) as unknown as Promise<{
orpc.messages.images({ guildId, limit }) as unknown as Promise<{
data: MessageRecord[];
nextCursor: string | null;
}>,
@@ -42,7 +42,7 @@ export const messagesApi = {
cursor?: string,
messageId?: string,
) =>
trpc.messages.attachmentsByChannel.query({
orpc.messages.attachmentsByChannel({
channelId,
query: { channelId, limit, cursor, messageId },
}) as unknown as Promise<{
@@ -51,15 +51,15 @@ export const messagesApi = {
}>,
getReview: (limit?: number, channelId?: string) =>
trpc.messages.review.query({ limit, channelId }) as unknown as Promise<{
orpc.messages.review({ limit, channelId }) as unknown as Promise<{
results: MessageRecord[];
limit: number;
cursor: null;
}>,
// Analysis search (formerly /api/analysis/search → tRPC analysis.search)
// Analysis search (formerly /api/analysis/search → oRPC analysis.search)
search: (q: string, limit?: number) =>
trpc.analysis.search.query({ q, limit }) as unknown as Promise<{
orpc.analysis.search({ q, limit }) as unknown as Promise<{
results: MessageRecord[];
}>,
};