Skip to content

Commit

Permalink
refactor: try to warn in all environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Aug 20, 2023
1 parent 5374fbf commit 02f6def
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/rest/src/lib/CDN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type ImageSize,
type StickerExtension,
} from './utils/constants.js';
import { warn } from './utils/utils.js';

let deprecationEmittedForEmoji = false;

Expand Down Expand Up @@ -179,11 +180,7 @@ export class CDN {

if (typeof options === 'string') {
if (!deprecationEmittedForEmoji) {
process.emitWarning(
'Passing a string for CDN#emoji() is deprecated. Use an object instead.',
'DeprecationWarning',
);

warn('DeprecationWarning: Passing a string for CDN#emoji() is deprecated. Use an object instead.');
deprecationEmittedForEmoji = true;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/rest/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@ export async function sleep(ms: number): Promise<void> {
export function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray {
return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;
}

/**
* Irrespective environment warning.
*
* @internal
*/
export function warn(message: string) {
if (typeof globalThis.process === 'undefined') {
console.warn(message);
} else {
process.emitWarning(message);
}
}

0 comments on commit 02f6def

Please sign in to comment.