|
@@ -2,13 +2,13 @@ type DeprecationHandler = (message: string) => void;
|
|
|
|
|
|
let deprecationHandler: DeprecationHandler | null = null;
|
|
|
|
|
|
-export function warnOnce (oldName: string, newName?: string) {
|
|
|
+function warnOnce (oldName: string, newName?: string) {
|
|
|
return warnOnceMessage(newName
|
|
|
? `'${oldName}' is deprecated and will be removed. Please use '${newName}' instead.`
|
|
|
: `'${oldName}' is deprecated and will be removed.`);
|
|
|
}
|
|
|
|
|
|
-export function warnOnceMessage (msg: string) {
|
|
|
+function warnOnceMessage (msg: string) {
|
|
|
let warned = false;
|
|
|
return () => {
|
|
|
if (!warned && !process.noDeprecation) {
|
|
@@ -18,21 +18,21 @@ export function warnOnceMessage (msg: string) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-export function setHandler (handler: DeprecationHandler | null): void {
|
|
|
+function setHandler (handler: DeprecationHandler | null): void {
|
|
|
deprecationHandler = handler;
|
|
|
}
|
|
|
|
|
|
-export function getHandler (): DeprecationHandler | null {
|
|
|
+function getHandler (): DeprecationHandler | null {
|
|
|
return deprecationHandler;
|
|
|
}
|
|
|
|
|
|
-export function warn (oldName: string, newName: string): void {
|
|
|
+function warn (oldName: string, newName: string): void {
|
|
|
if (!process.noDeprecation) {
|
|
|
log(`'${oldName}' is deprecated. Use '${newName}' instead.`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function log (message: string): void {
|
|
|
+function log (message: string): void {
|
|
|
if (typeof deprecationHandler === 'function') {
|
|
|
deprecationHandler(message);
|
|
|
} else if (process.throwDeprecation) {
|
|
@@ -45,7 +45,7 @@ export function log (message: string): void {
|
|
|
}
|
|
|
|
|
|
// remove a function with no replacement
|
|
|
-export function removeFunction<T extends Function> (fn: T, removedName: string): T {
|
|
|
+function removeFunction<T extends Function> (fn: T, removedName: string): T {
|
|
|
if (!fn) { throw new Error(`'${removedName} function' is invalid or does not exist.`); }
|
|
|
|
|
|
// wrap the deprecated function to warn user
|
|
@@ -57,7 +57,7 @@ export function removeFunction<T extends Function> (fn: T, removedName: string):
|
|
|
}
|
|
|
|
|
|
// change the name of a function
|
|
|
-export function renameFunction<T extends Function> (fn: T, newName: string): T {
|
|
|
+function renameFunction<T extends Function> (fn: T, newName: string): T {
|
|
|
const warn = warnOnce(`${fn.name} function`, `${newName} function`);
|
|
|
return function (this: any) {
|
|
|
warn();
|
|
@@ -66,7 +66,7 @@ export function renameFunction<T extends Function> (fn: T, newName: string): T {
|
|
|
}
|
|
|
|
|
|
// change the name of an event
|
|
|
-export function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string, transformer: (...args: any[]) => any[] | undefined = (...args) => args) {
|
|
|
+function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string, transformer: (...args: any[]) => any[] | undefined = (...args) => args) {
|
|
|
const warn = newName.startsWith('-') /* internal event */
|
|
|
? warnOnce(`${oldName} event`)
|
|
|
: warnOnce(`${oldName} event`, `${newName} event`);
|
|
@@ -82,7 +82,7 @@ export function event (emitter: NodeJS.EventEmitter, oldName: string, newName: s
|
|
|
}
|
|
|
|
|
|
// remove a property with no replacement
|
|
|
-export function removeProperty<T, K extends (keyof T & string)>(object: T, removedName: K, onlyForValues?: any[]): T {
|
|
|
+function removeProperty<T extends Object, K extends (keyof T & string)>(object: T, removedName: K, onlyForValues?: any[]): T {
|
|
|
// if the property's already been removed, warn about it
|
|
|
// eslint-disable-next-line no-proto
|
|
|
const info = Object.getOwnPropertyDescriptor((object as any).__proto__, removedName);
|
|
@@ -113,7 +113,7 @@ export function removeProperty<T, K extends (keyof T & string)>(object: T, remov
|
|
|
}
|
|
|
|
|
|
// change the name of a property
|
|
|
-export function renameProperty<T extends Object, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T {
|
|
|
+function renameProperty<T extends Object, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T {
|
|
|
const warn = warnOnce(oldName, newName);
|
|
|
|
|
|
// if the new property isn't there yet,
|
|
@@ -137,10 +137,27 @@ export function renameProperty<T extends Object, K extends (keyof T & string)>(o
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-export function moveAPI<T extends Function> (fn: T, oldUsage: string, newUsage: string): T {
|
|
|
+function moveAPI<T extends Function> (fn: T, oldUsage: string, newUsage: string): T {
|
|
|
const warn = warnOnce(oldUsage, newUsage);
|
|
|
return function (this: any) {
|
|
|
warn();
|
|
|
return fn.apply(this, arguments);
|
|
|
} as unknown as typeof fn;
|
|
|
}
|
|
|
+
|
|
|
+const deprecate: ElectronInternal.DeprecationUtil = {
|
|
|
+ warnOnce,
|
|
|
+ warnOnceMessage,
|
|
|
+ setHandler,
|
|
|
+ getHandler,
|
|
|
+ warn,
|
|
|
+ log,
|
|
|
+ removeFunction,
|
|
|
+ renameFunction,
|
|
|
+ event,
|
|
|
+ removeProperty,
|
|
|
+ renameProperty,
|
|
|
+ moveAPI
|
|
|
+};
|
|
|
+
|
|
|
+export default deprecate;
|