feat(loader): rename global load to __apigo_load and add self-cleanup

This commit is contained in:
AI Engineer 2026-06-04 21:04:30 +08:00
parent 70ebb40e4f
commit 042ebe61e3
2 changed files with 53 additions and 46 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@apigo.cc/loader", "name": "@apigo.cc/loader",
"version": "1.0.3", "version": "1.0.4",
"type": "module", "type": "module",
"main": "dist/loader.js", "main": "dist/loader.js",
"module": "dist/loader.js", "module": "dist/loader.js",

View File

@ -17,6 +17,7 @@ const DEFAULT_VERSIONS = {
const Loader = { const Loader = {
load: (...pkgs) => { load: (...pkgs) => {
try {
if (typeof document === 'undefined') return; if (typeof document === 'undefined') return;
const currentScript = document.currentScript; const currentScript = document.currentScript;
@ -71,11 +72,17 @@ const Loader = {
} else { } else {
document.head.appendChild(script); document.head.appendChild(script);
} }
} finally {
// 运行后自动删除,防止全局污染
if (typeof globalThis !== 'undefined' && globalThis.__apigo_load) {
delete globalThis.__apigo_load;
}
}
} }
}; };
// 挂载到全局 // 挂载到全局
globalThis.Loader = Loader; globalThis.__apigo_load = Loader.load;
export { Loader }; export { Loader };
export default Loader; export default Loader;