[API] Add deprecated warning logging (#967)

Adds a global API to notify devs / users of deprecated features.

- Custom callbacks may be added
- By default, remembers message text and only sends each message once
- Sends to console.warn by default

```ts
// Add a custom notification when a warning is encountered
const warnMessage = (message: string, source?: object) => {
  addToast({ message, detail: object })
}
LiteGraph.onDeprecationWarning.push(warnMessage)
```

```ts
// Debugging flag. Repeats deprecation warnings every time they are reported.
// May impact performance.
LiteGraph.alwaysRepeatWarnings = true
```

Generate a warning
```ts
import { warnDeprecated } from "@/utils/feedback"

warnDeprecated(
  "[DEPRECATED] graph.oldFeature() will be removed from Litegraph. " +
  "Please use graph.newFeature() instead. https://helpful.site/faq",
  objectThatCausedThis
)
```
This commit is contained in:
filtered
2025-04-26 02:16:01 +10:00
committed by GitHub
parent 63407abf3c
commit c10ce1caa1
3 changed files with 43 additions and 0 deletions

View File

@@ -139,6 +139,7 @@ LiteGraphGlobal {
"allow_multi_output_for_events": true,
"allow_scripts": false,
"alt_drag_do_clone_nodes": false,
"alwaysRepeatWarnings": false,
"alwaysSnapToGrid": undefined,
"auto_load_slot_types": false,
"catch_exceptions": true,
@@ -158,6 +159,9 @@ LiteGraphGlobal {
"node_box_coloured_when_on": false,
"node_images_path": "",
"node_types_by_file_extension": {},
"onDeprecationWarning": [
[Function],
],
"overlapBounding": [Function],
"pointerevents_method": "pointer",
"proxy": null,