Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
37 changes: 26 additions & 11 deletions src/runtime/supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,38 @@ 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');

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 (src.includes('index.js') || src.includes('index.min.js')) {
return src;
}
}

return null;
})();

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';
Expand Down