Skip to content

refactor: switch to .ts imports for some HidenCloud requirements#21

Merged
calebephrem merged 1 commit into
open-devhub:mainfrom
calebephrem:main
Jun 26, 2026
Merged

refactor: switch to .ts imports for some HidenCloud requirements#21
calebephrem merged 1 commit into
open-devhub:mainfrom
calebephrem:main

Conversation

@calebephrem

Copy link
Copy Markdown
Member

No description provided.

@devhub-bot devhub-bot Bot added the refactor code restructure label Jun 26, 2026
@beetle-ai

beetle-ai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR refactors the entire codebase to use .ts file extensions in import statements instead of .js extensions, aligning with HidenCloud requirements and modern TypeScript best practices. The change affects 40 files across the project, updating import paths throughout commands, utilities, event handlers, and configuration files. Additionally, TypeScript compiler options have been updated to support .ts imports with allowImportingTsExtensions and noEmit flags, and the build output directory (dist/) has been added to .gitignore.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
.gitignore Modified +2/-1 Added dist/ directory to ignore list and fixed missing newline at end of file
tsconfig.json Modified +6/-3 Enabled TypeScript configuration for .ts imports: added allowImportingTsExtensions, noEmit, and configured rootDir/outDir for build output
src/commands/!misc/premium.ts
src/commands/!misc/refreshdb.ts
src/commands/!mod/ban.ts
src/commands/!mod/checkban.ts
src/commands/!mod/unban.ts
Modified +11/-11 Updated imports from .js to .ts extensions for command type definitions and utility functions (cacheDB, firestore, getConfig)
src/commands/!stats/stats.ts Modified +10/-6 Changed imports to .ts extensions and improved type safety with explicit type casting for command statistics and null coalescing for guild IDs
src/commands/code/complexity.ts
src/commands/code/format.ts
src/commands/code/run.ts
src/commands/code/suggest.ts
src/commands/code/whatlang.ts
Modified +10/-10 Updated imports to .ts for code analysis commands, affecting command types and code input parsing utilities
src/commands/docs/mdn.ts
src/commands/docs/wiki.ts
Modified +2/-2 Changed documentation command imports to use .ts extensions
src/commands/github/profile.ts
src/commands/github/repo.ts
Modified +2/-2 Updated GitHub integration command imports to .ts extensions
src/commands/math/math-breakdown.ts Modified +1/-1 Changed math command type imports to .ts extension
src/commands/misc/help.ts
src/commands/misc/ping.ts
Modified +2/-2 Updated miscellaneous command imports to .ts extensions
src/commands/search/npm.ts
src/commands/search/pip.ts
Modified +2/-2 Changed package search command imports to .ts extensions
src/commands/static/github.ts Modified +1/-1 Updated static GitHub command imports to .ts extension
src/commands/support/feature.ts
src/commands/support/report.ts
Modified +4/-4 Changed support command imports to .ts extensions
src/commands/tools/color.ts
src/commands/tools/http.ts
src/commands/tools/id.ts
src/commands/tools/regex.ts
src/commands/tools/scan.ts
src/commands/tools/tree.ts
src/commands/tools/whois.ts
Modified +8/-8 Updated tool command imports to .ts extensions
src/events/clientReady/cacheDB.ts
src/events/guildCreate/isBanned.ts
Modified +2/-2 Changed event handler imports to .ts extensions for database utilities
src/events/messageCreate/handleCommands.ts Modified +5/-5 Updated command handler imports to .ts and improved null safety with null coalescing operator for guild IDs
src/handlers/eventHandler.ts Modified +1/-1 Changed event handler utility imports to .ts extension
src/index.ts Modified +1/-1 Updated main entry point import to .ts extension
src/utils/cacheDB.ts
src/utils/firestore.ts
Modified +3/-3 Changed utility file imports to .ts extensions
src/utils/stats.ts Modified +41/-30 Refactored statistics utility with comprehensive TypeScript type annotations, improved type safety with explicit return types and parameter types, and updated imports to .ts extensions

Total Changes: 40 files changed, +123 additions, -101 deletions

🗺️ Walkthrough:

graph TD
A["Entry Point src/index.ts"] --> B["Event Handler src/handlers/eventHandler.ts"]
B --> C["Client Ready Events src/events/clientReady/"]
B --> D["Message Create Events src/events/messageCreate/"]
B --> E["Guild Create Events src/events/guildCreate/"]
D --> F["Command Handler handleCommands.ts"]
F --> G["Command Categories"]
G --> H["Code Commands format, run, suggest, etc."]
G --> I["Mod Commands ban, unban, checkban"]
G --> J["Tools Commands color, http, regex, etc."]
G --> K["Support Commands feature, report"]
H --> L["Shared Utilities"]
I --> L
J --> L
K --> L
L --> M["cacheDB.ts Database Caching"]
L --> N["firestore.ts Database Operations"]
L --> O["stats.ts Statistics Tracking"]
L --> P["getConfig.ts Configuration"]
N --> Q["Firebase Config src/config/firebase.ts"]
style A fill:#e1f5ff
style L fill:#fff4e1
style Q fill:#ffe1e1
Note1["All imports now use .ts extensions instead of .js for HidenCloud compatibility"]
A -.-> Note1
Loading

🎯 Key Changes:

  • Import Extension Refactor: Systematically replaced all .js import extensions with .ts across 40 files, ensuring consistency with TypeScript source file extensions
  • TypeScript Configuration Enhancement: Added allowImportingTsExtensions and noEmit compiler options to support .ts imports without emitting JavaScript files during type checking
  • Type Safety Improvements: Enhanced stats.ts with comprehensive TypeScript type annotations, explicit return types, and proper type casting for Firestore documents
  • Null Safety Enhancements: Added null coalescing operators (??) in command handlers and statistics tracking to handle potentially undefined guild IDs
  • Build Configuration: Configured rootDir and outDir in tsconfig.json and added dist/ to .gitignore for proper build output management
  • Code Quality: Fixed minor formatting issues (missing newline in .gitignore) and improved type safety throughout the codebase

📊 Impact Assessment:

  • Security: ✅ Neutral Impact - No security-related changes introduced. The refactor maintains existing security patterns and does not expose new attack surfaces. Type safety improvements may help prevent runtime errors that could lead to security issues.
  • Performance: ✅ Neutral to Positive Impact - No runtime performance changes as this is a compile-time refactor. The noEmit flag may slightly improve development build times by skipping JavaScript emission during type checking. Type annotations in stats.ts enable better optimization opportunities for the TypeScript compiler.
  • Maintainability: ✅✅ Significant Positive Impact - Major improvement in code maintainability:
  • Consistent .ts import extensions improve IDE navigation and autocomplete
  • Explicit type annotations in stats.ts make the code self-documenting
  • Better alignment with TypeScript best practices and HidenCloud requirements
  • Reduced cognitive load when working with TypeScript source files
  • Improved refactoring safety with proper type checking
  • Testing: ⚠️ Requires Attention - While no test files are modified in this PR:
  • All existing tests should be run to ensure import path changes don't break functionality
  • Test imports may need similar updates if they reference these files
  • The noEmit flag means the code won't be transpiled during type checking, so runtime testing is essential
  • Verify that the build process correctly handles .ts imports in the deployment pipeline
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

Comment on lines +12 to +15
if (args[0] || message.guildId) {
const serverStats = await getServerStats(
(args[0] || message.guildId) ?? "",
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The conditional logic change introduces a bug that alters the command's behavior. The original code if (args[0]) only fetched server-specific stats when an argument was explicitly provided. The new condition if (args[0] || message.guildId) will almost always evaluate to true in guild contexts (since message.guildId typically exists), causing the command to always fetch server stats even when the user intended to view global stats.
This breaks the command's logic flow: when no argument is provided, the code should skip to line 58 to fetch global stats, but now it will incorrectly enter the server stats branch.

Confidence: 5/5

Suggested Fix
Suggested change
if (args[0] || message.guildId) {
const serverStats = await getServerStats(
(args[0] || message.guildId) ?? "",
);
if (args[0]) {
const serverStats = await getServerStats(
args[0] ?? message.guildId ?? "",
);

Revert the condition to if (args[0]) to preserve the original behavior. If you need to handle null/undefined args[0], use the nullish coalescing operator within the function call to fall back to message.guildId only when args[0] is explicitly provided but happens to be nullish.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/commands/!stats/stats.ts around line 12, the conditional logic was changed from "if (args[0])" to "if (args[0] || message.guildId)" which breaks the command's intended behavior. When no argument is provided, the command should fetch global stats (line 58), but the new condition will almost always be true in guild contexts, causing it to incorrectly fetch server stats instead. Revert the condition to "if (args[0])" and keep the nullish coalescing operator inside the function call for safety: "args[0] ?? message.guildId ?? ''".

📍 This suggestion applies to lines 12-15

@calebephrem calebephrem merged commit 3ec4925 into open-devhub:main Jun 26, 2026
1 of 2 checks passed
Comment thread tsconfig.json
Comment on lines +27 to +28
"allowImportingTsExtensions": true,
"noEmit": true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The combination of allowImportingTsExtensions: true and noEmit: true will prevent TypeScript from generating any JavaScript output files. This configuration is incompatible with standard Node.js execution unless you have an external bundler (like esbuild, webpack, or tsx) configured to handle the transpilation.
Impact: The build process will fail because:

  1. noEmit: true tells TypeScript to skip emitting .js files
  2. Node.js cannot directly execute .ts files with .ts imports
  3. The dist/ directory (configured in outDir) will remain empty
    This will cause runtime failures when trying to run the application unless there's a separate build tool configured that isn't visible in this PR.

Confidence: 5/5

Suggested Fix

If you're using a bundler like esbuild or tsx for runtime execution, this configuration is correct. However, if you're relying on TypeScript's compiler for builds, you need to remove noEmit:

Suggested change
"allowImportingTsExtensions": true,
"noEmit": true,
"allowImportingTsExtensions": true,

Remove the noEmit: true line to allow TypeScript to generate JavaScript output. Alternatively, if you must keep noEmit: true, ensure you have a separate build tool configured (esbuild, webpack, tsx, etc.) and document this requirement in the PR description or README.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In tsconfig.json around line 27-28, the configuration has both "allowImportingTsExtensions: true" and "noEmit: true" which prevents TypeScript from generating any JavaScript output files. This will break the build process unless there's an external bundler configured. If you're using TypeScript's compiler for builds, remove the "noEmit: true" line. If you're using an external bundler like esbuild or tsx, keep this configuration but ensure the bundler is properly configured and document this requirement in the project's build documentation.

📍 This suggestion applies to lines 27-28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor code restructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant