-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an option to disable version check
- Loading branch information
Showing
45 changed files
with
364 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
import { MastoConfig } from '../config'; | ||
|
||
interface Target { | ||
readonly config: MastoConfig; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type Fn = (...args: any[]) => any; | ||
|
||
/** | ||
* Decorator that verifies the version of the Mastodon instance | ||
* @param parameters Optional params | ||
*/ | ||
export const deprecated = | ||
(message: string) => | ||
( | ||
_obj: unknown, | ||
_target: Target, | ||
name: string | symbol, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
descriptor: TypedPropertyDescriptor<(...args: any[]) => any>, | ||
descriptor: TypedPropertyDescriptor<Fn>, | ||
) => { | ||
const original = descriptor.value; | ||
|
||
if (!original) { | ||
throw new Error('available can only apply to a method of a class'); | ||
const origin = descriptor.value; | ||
if (!origin) { | ||
throw new Error('deprecated can only apply to a method of a class'); | ||
} | ||
|
||
descriptor.value = function ( | ||
this: unknown, | ||
...args: Parameters<typeof original> | ||
this: Target, | ||
...args: Parameters<typeof origin> | ||
) { | ||
if ( | ||
process.env.NODE_ENV !== 'production' || | ||
!process.env.NODE_IGNORE_MASTO_WARNINGS | ||
!this.config?.disableDeprecatedWarning | ||
) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`#${name.toString()} is deprecated. ${message}`); | ||
} | ||
|
||
return original.apply(this, args); | ||
return origin.apply(this, args); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.