chore: revert deprecate as an internal module (#40146)

Revert "chore: restore deprecate as an internal module (#40124)"

This reverts commit 737e3de3fa.
This commit is contained in:
Milan Burda 2023-10-10 17:50:47 +02:00 committed by GitHub
parent 7e312c81ca
commit 2c88626b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 40 additions and 99 deletions

View file

@ -1,7 +1,5 @@
// Common modules, please sort alphabetically
export const commonModuleList: ElectronInternal.ModuleEntry[] = [
{ name: 'nativeImage', loader: () => require('./native-image') },
{ name: 'shell', loader: () => require('./shell') },
// The internal modules, invisible unless you know their names.
{ name: 'deprecate', loader: () => require('./deprecate'), private: true }
{ name: 'shell', loader: () => require('./shell') }
];

View file

@ -9,7 +9,7 @@ export function defineProperties (targetExports: Object, moduleList: ElectronInt
const descriptors: PropertyDescriptorMap = {};
for (const module of moduleList) {
descriptors[module.name] = {
enumerable: !module.private,
enumerable: true,
get: handleESModule(module.loader)
};
}

View file

@ -2,13 +2,13 @@ type DeprecationHandler = (message: string) => void;
let deprecationHandler: DeprecationHandler | null = null;
function warnOnce (oldName: string, newName?: string) {
export 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.`);
}
function warnOnceMessage (msg: string) {
export function warnOnceMessage (msg: string) {
let warned = false;
return () => {
if (!warned && !process.noDeprecation) {
@ -18,21 +18,21 @@ function warnOnceMessage (msg: string) {
};
}
function setHandler (handler: DeprecationHandler | null): void {
export function setHandler (handler: DeprecationHandler | null): void {
deprecationHandler = handler;
}
function getHandler (): DeprecationHandler | null {
export function getHandler (): DeprecationHandler | null {
return deprecationHandler;
}
function warn (oldName: string, newName: string): void {
export function warn (oldName: string, newName: string): void {
if (!process.noDeprecation) {
log(`'${oldName}' is deprecated. Use '${newName}' instead.`);
}
}
function log (message: string): void {
export function log (message: string): void {
if (typeof deprecationHandler === 'function') {
deprecationHandler(message);
} else if (process.throwDeprecation) {
@ -45,7 +45,7 @@ function log (message: string): void {
}
// remove a function with no replacement
function removeFunction<T extends Function> (fn: T, removedName: string): T {
export 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 @@ function removeFunction<T extends Function> (fn: T, removedName: string): T {
}
// change the name of a function
function renameFunction<T extends Function> (fn: T, newName: string): T {
export 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 @@ function renameFunction<T extends Function> (fn: T, newName: string): T {
}
// change the name of an event
function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string, transformer: (...args: any[]) => any[] | undefined = (...args) => args) {
export 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 @@ function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string,
}
// remove a property with no replacement
function removeProperty<T extends Object, K extends (keyof T & string)>(object: T, removedName: K, onlyForValues?: any[]): T {
export 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 @@ function removeProperty<T extends Object, K extends (keyof T & string)>(object:
}
// change the name of a property
function renameProperty<T extends Object, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T {
export 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,27 +137,10 @@ function renameProperty<T extends Object, K extends (keyof T & string)>(object:
});
}
function moveAPI<T extends Function> (fn: T, oldUsage: string, newUsage: string): T {
export 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;