Skip to content

Commit

Permalink
chore(djsdocs): improve debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
almostSouji committed May 16, 2024
1 parent db2902d commit 2729a86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Slash command utilities for the discord.js support server.",
"scripts": {
"build": "rimraf dist && tsc",
"start": "node dist/index.js",
"start": "node --enable-source-maps dist/index.js",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
"prettier": "prettier --write **/*.{ts,js,toml}",
Expand Down
20 changes: 18 additions & 2 deletions src/util/djsdocs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import process from 'node:process';
import { sql } from '@vercel/postgres';
import { container } from 'tsyringe';
import { logger } from './logger.js';

export const kDjsVersions = Symbol('DJS_VERSIONS');

Expand Down Expand Up @@ -48,7 +49,10 @@ export async function fetchDjsVersions(): Promise<DjsVersions> {
packages: [...packages],
versions,
};
} catch {
} catch (error_) {
const error = error_ as Error;
logger.error(error, error.message);

return {
rows: [],
versions: new Map<string, string[]>(),
Expand All @@ -60,9 +64,21 @@ export async function fetchDjsVersions(): Promise<DjsVersions> {
export async function prepareDjsVersions() {
const res = await fetchDjsVersions();
container.register(kDjsVersions, { useValue: res });
logger.debug({ res }, 'Registered container after fetching versions');

return res;
}

export function getDjsVersions() {
return container.resolve<DjsVersions>(kDjsVersions);
const versions = container.resolve<DjsVersions>(kDjsVersions);
logger.debug({ versions }, 'Retrieving versions from container');
if (!versions?.versions) {
return {
rows: [],
versions: new Map<string, string[]>(),
packages: [],
} satisfies DjsVersions;
}

return versions;
}

0 comments on commit 2729a86

Please sign in to comment.