From ad05cbf03cb953cb0a8681e74e19aefe01fea870 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 21 Jan 2026 14:51:46 +0800 Subject: [PATCH 1/3] refactor: remove import meta --- src/runtime/supervisor.ts | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/runtime/supervisor.ts b/src/runtime/supervisor.ts index bf7c7108..ce37634e 100644 --- a/src/runtime/supervisor.ts +++ b/src/runtime/supervisor.ts @@ -56,23 +56,40 @@ export class Supervisor { * Resolve worker script path which works in both ESM and UMD environments */ private resolveWorkerPath(): string { - if (typeof import.meta !== 'undefined' && import.meta.url) { - const currentUrl = new URL(import.meta.url); - // e.g. `.../lib/runtime/supervisor.js` -> `.../lib/worker.js` - const asRoot = currentUrl.href.replace(/\/runtime\/[^/]+\.js$/, '/worker.js'); - if (asRoot !== currentUrl.href) return asRoot; - // Fallback: keep legacy behavior (same directory) - return currentUrl.href.replace(/\/[^/]+\.js$/, '/worker.js'); - } + const scriptUrl = (() => { + if (typeof document === 'undefined') return null; + + const currentScript = document.currentScript as HTMLScriptElement | null; + if (currentScript?.src) return currentScript.src; - if (typeof document !== 'undefined') { const scripts = document.getElementsByTagName('script'); + let fallback: string | null = null; + for (let i = scripts.length - 1; i >= 0; i--) { const src = scripts[i].src; - if (src && (src.includes('index.js') || src.includes('index.min.js'))) { - return src.replace(/index(\.min)?\.js/, 'worker.js'); + if (!src) continue; + if (!fallback) fallback = src; + if (src.includes('index.js') || src.includes('index.min.js')) { + return src; } } + + return fallback; + })(); + + if (scriptUrl) { + if (scriptUrl.includes('index.js') || scriptUrl.includes('index.min.js')) { + const asIndex = scriptUrl.replace(/index(\.min)?\.(m?js)(\?.*)?$/, 'worker.js'); + if (asIndex !== scriptUrl) return asIndex; + } + + // e.g. `.../lib/runtime/supervisor.js` -> `.../lib/worker.js` + const asRoot = scriptUrl.replace(/\/runtime\/[^/]+\.(m?js)(\?.*)?$/, '/worker.js'); + if (asRoot !== scriptUrl) return asRoot; + + // Fallback: keep legacy behavior (same directory) + const asSibling = scriptUrl.replace(/\/[^/]+\.(m?js)(\?.*)?$/, '/worker.js'); + if (asSibling !== scriptUrl) return asSibling; } return './worker.js'; From 3d048206af7aa9f32c3593491b1e84ef78a98253 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 21 Jan 2026 14:52:15 +0800 Subject: [PATCH 2/3] chore: update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce91d76c..4afa85ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/layout", - "version": "2.0.0-beta.1", + "version": "2.0.0-beta.2", "description": "graph layout algorithm", "main": "dist/index.min.js", "module": "lib/index.js", From 7c8a6a5250acfd25b595f2a2f73db5c378dba437 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 21 Jan 2026 15:10:33 +0800 Subject: [PATCH 3/3] fix: fix cr issue --- src/runtime/supervisor.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/runtime/supervisor.ts b/src/runtime/supervisor.ts index ce37634e..3e463bcc 100644 --- a/src/runtime/supervisor.ts +++ b/src/runtime/supervisor.ts @@ -63,18 +63,16 @@ export class Supervisor { if (currentScript?.src) return currentScript.src; const scripts = document.getElementsByTagName('script'); - let fallback: string | null = null; for (let i = scripts.length - 1; i >= 0; i--) { const src = scripts[i].src; if (!src) continue; - if (!fallback) fallback = src; if (src.includes('index.js') || src.includes('index.min.js')) { return src; } } - return fallback; + return null; })(); if (scriptUrl) {