Skip to content

Commit

Permalink
chore: Use named exports insteadof default exports for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
PartMan7 committed Oct 28, 2024
1 parent 74a9d05 commit c815d11
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/globals/chat-error.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import _chatError from '@/utils/chat-error';
import { ChatError as _chatError } from '@/utils/chat-error';
export as namespace ChatError;
export = _chatError;
2 changes: 1 addition & 1 deletion src/globals/fs-path.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import _fsPath from '@/utils/fs-path';
import { fsPath as _fsPath } from '@/utils/fs-path';
export as namespace fsPath;
export = _fsPath;
4 changes: 2 additions & 2 deletions src/globals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ global.React = React;
import * as Tools from '@/tools';
global.Tools = Tools;

import fsPath from '@/utils/fs-path';
import { fsPath } from '@/utils/fs-path';
global.fsPath = fsPath;
import { log } from '@/utils/logger';
global.log = log;
import { jsxToHTML } from '@/utils/jsx-to-html';
global.jsxToHTML = jsxToHTML;

import ChatError from '@/utils/chat-error';
import { ChatError } from '@/utils/chat-error';
global.ChatError = ChatError;
2 changes: 1 addition & 1 deletion src/ps/handlers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Message } from 'ps-client';
import { HTMLopts } from 'ps-client/classes/common';

Check warning on line 6 in src/ps/handlers/chat.ts

View workflow job for this annotation

GitHub Actions / test (18.18.2, ubuntu-latest)

'HTMLopts' is defined but never used

Check warning on line 6 in src/ps/handlers/chat.ts

View workflow job for this annotation

GitHub Actions / test (18.18.2, macos-latest)

'HTMLopts' is defined but never used

Check warning on line 6 in src/ps/handlers/chat.ts

View workflow job for this annotation

GitHub Actions / test (18.18.2, windows-latest)

'HTMLopts' is defined but never used
import type { PSCommand, PSCommandContext } from '@/types/chat';
import type { Perms } from '@/types/perms';
import ChatError from '@/utils/chat-error';
import { ChatError } from '@/utils/chat-error';

import { ACCESS_DENIED, CMD_NOT_FOUND, INVALID_ALIAS, PM_ONLY_COMMAND, ROOM_ONLY_COMMAND } from '@/text';

Expand Down
2 changes: 1 addition & 1 deletion src/ps/loaders/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PSCommand } from '@/types/chat';

import getSecretCommands from '@/secrets/commands/ps';

import cacheBuster from '@/utils/cachebuster';
import { cacheBuster } from '@/utils/cachebuster';
import { PSAliases, PSCommands } from '@/cache';
import resetCache from '@/cache/reset';

Expand Down
4 changes: 2 additions & 2 deletions src/utils/cachebuster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import emptyObject from '@/utils/empty-object';
import { emptyObject } from '@/utils/empty-object';

export default function cacheBuster(_filepath: string): boolean {
export function cacheBuster(_filepath: string): boolean {
const filepath = _filepath.startsWith('/') ? _filepath : require.resolve(_filepath);
if (!require.cache[filepath]) return false;
emptyObject(require.cache[filepath].exports);
Expand Down
4 changes: 1 addition & 3 deletions src/utils/chat-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class ChatError extends Error {
export class ChatError extends Error {
constructor(args) {
super(args);
this.name = this.constructor.name;
}
}

export default ChatError;
2 changes: 1 addition & 1 deletion src/utils/empty-object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO get this working with 'unknown'
export default function emptyObject<T extends Record<string, any>>(obj: T): Record<string, never> {
export function emptyObject<T extends Record<string, any>>(obj: T): Record<string, never> {
Object.keys(obj).forEach(key => delete obj[key]);
return obj as Record<string, never>;
}
3 changes: 1 addition & 2 deletions src/utils/eval.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// eslint-disable-next-line no-restricted-imports -- eval is at src-level
export * from '../eval';
export * from '@/eval';
2 changes: 1 addition & 1 deletion src/utils/fs-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';

export default function fsPath(...paths: string[]): string {
export function fsPath(...paths: string[]): string {
return path.join(__dirname, '..', ...paths);
}
2 changes: 1 addition & 1 deletion src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import fsSync from 'fs';
import { inspect } from 'util';
import fsPath from '@/utils/fs-path';
import { fsPath } from '@/utils/fs-path';

function dimText(str: string): string {
return `\x1b[2m${str}\x1b[22m`;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/regex-escape.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function escapeRegEx(input: string): string {
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return input.replace(/\W/g, '\\$&');
}

0 comments on commit c815d11

Please sign in to comment.