mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 19:25:35 -05:00
Add Deprecation message when loading from latest (#1848)
* add tests to verify if we show an error banner when users load from latest * add deprecation manager to take care of showing a notification in case script src is being loaded from latest * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * make sure deprecation warning also register onWorker * restore tests for banner in worker * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add a wait selector when testing banner since worker seems to take too long to render in CI * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix test_deprecate_loading_scripts_from_latest: I think that the previous failure was because we actually TRIED to execute the js from latest/core.js and it conflicted with our local copy. But to trigger the warning is enough to have a script pointing to pyscript.net/latest, there is no need to execute it: modify it with type="ignore-me" and an URL which doesn't exist. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
This commit is contained in:
27
pyscript.core/src/plugins/deprecations-manager.js
Normal file
27
pyscript.core/src/plugins/deprecations-manager.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// PyScript Derepcations Plugin
|
||||
import { hooks } from "../core.js";
|
||||
import { notify } from "./error.js";
|
||||
|
||||
// react lazily on PyScript bootstrap
|
||||
hooks.main.onReady.add(checkDeprecations);
|
||||
hooks.main.onWorker.add(checkDeprecations);
|
||||
|
||||
/**
|
||||
* Check that there are no scripts loading from pyscript.net/latest
|
||||
*/
|
||||
function checkDeprecations() {
|
||||
const scripts = document.querySelectorAll("script");
|
||||
for (const script of scripts) checkLoadingScriptsFromLatest(script.src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if src being loaded from pyscript.net/latest and display a notification if true
|
||||
* * @param {string} src
|
||||
*/
|
||||
function checkLoadingScriptsFromLatest(src) {
|
||||
if (/\/pyscript\.net\/latest/.test(src)) {
|
||||
notify(
|
||||
"Loading scripts from latest is deprecated and will be removed soon. Please use a specific version instead.",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user