diff --git a/.changeset/empty-lions-rescue.md b/.changeset/empty-lions-rescue.md new file mode 100644 index 000000000..c093a314e --- /dev/null +++ b/.changeset/empty-lions-rescue.md @@ -0,0 +1,5 @@ +--- +'@qiankunjs/shared': patch +--- + +fix: remove inline script source-url diff --git a/packages/shared/src/assets-transpilers/__tests__/script.test.ts b/packages/shared/src/assets-transpilers/__tests__/script.test.ts new file mode 100644 index 000000000..0eabdd8d0 --- /dev/null +++ b/packages/shared/src/assets-transpilers/__tests__/script.test.ts @@ -0,0 +1,23 @@ +import { expect, it, vi } from 'vitest'; +import transpileScript from '../script'; + +it('inline script not include sourceURL', () => { + class MockSandbox { + makeEvaluateFactory(source: string, sourceURL?: string): string { + return ''; + } + } + + const code = 'console.log("hello world")'; + const publicPath = 'http://localhost:8000'; + const scriptElement = document.createElement('script'); + scriptElement.innerHTML = code; + const sandboxInstance = new MockSandbox(); + const makeEvaluateFactorySpy = vi.spyOn(sandboxInstance, 'makeEvaluateFactory'); + transpileScript(scriptElement, publicPath, { + fetch: window.fetch, + rawNode: scriptElement, + sandbox: sandboxInstance, + }); + expect(makeEvaluateFactorySpy).toHaveBeenCalledWith(code); +}); diff --git a/packages/shared/src/assets-transpilers/script.ts b/packages/shared/src/assets-transpilers/script.ts index 12898b6a9..a7ae89571 100644 --- a/packages/shared/src/assets-transpilers/script.ts +++ b/packages/shared/src/assets-transpilers/script.ts @@ -161,7 +161,7 @@ export default function transpileScript( const scriptNode = script.textContent ? script : rawNode.childNodes[0]; const { code } = result; - scriptNode.textContent = sandbox!.makeEvaluateFactory(code, baseURI); + scriptNode.textContent = sandbox!.makeEvaluateFactory(code); // mark the script have consumed script.dataset.consumed = 'true';