diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/wasmCompiler.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/wasmCompiler.kt index 60d7147956716..b340f8a9e2535 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/wasmCompiler.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/wasmCompiler.kt @@ -261,6 +261,7 @@ fun WasmCompiledModuleFragment.generateAsyncJsWrapper( }.sorted() .joinToString("\n") //language=js + val pathJsStringLiteral = wasmFilePath.toJsStringLiteral() return """ export async function instantiate(imports={}, runInitializer=true) { const cachedJsObjects = new WeakMap(); @@ -298,7 +299,7 @@ $jsCodeBodyIndented throw "Supported JS engine not detected"; } - const wasmFilePath = ${wasmFilePath.toJsStringLiteral()}; + const wasmFilePath = $pathJsStringLiteral; const importObject = { js_code, intrinsics: { @@ -334,7 +335,7 @@ $imports } if (isBrowser) { - wasmInstance = (await WebAssembly.instantiateStreaming(fetch(wasmFilePath), importObject)).instance; + wasmInstance = (await WebAssembly.instantiateStreaming(fetch(new URL($pathJsStringLiteral,import.meta.url).href), importObject)).instance; } } catch (e) { if (e instanceof WebAssembly.CompileError) { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt index fb981e2fc9bef..28b99ccf85094 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt @@ -196,9 +196,14 @@ class KotlinWasmGradlePluginIT : KGPBaseTest() { assertTasksExecuted(":compileProductionExecutableKotlinWasmJsOptimize") assertTasksExecuted(":wasmJsBrowserDistribution") - assertFileInProjectExists("build/${Distribution.DIST}/wasmJs/productionExecutable/redefined-wasm-module-name.wasm") assertFileInProjectExists("build/${Distribution.DIST}/wasmJs/productionExecutable/new-mpp-wasm-js.js") assertFileInProjectExists("build/${Distribution.DIST}/wasmJs/productionExecutable/new-mpp-wasm-js.js.map") + + assertTrue("Expected one wasm file") { + projectPath.resolve("build/${Distribution.DIST}/wasmJs/productionExecutable").toFile().listFiles()!! + .filter { it.extension == "wasm" } + .size == 1 + } } } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinBrowserJsIr.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinBrowserJsIr.kt index 5ef564e81d5eb..4af93e32cb6fa 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinBrowserJsIr.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinBrowserJsIr.kt @@ -237,17 +237,6 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) : copy.from(processResourcesTask) copy.from(webpackTask.flatMap { it.outputDirectory }) - if (binary.compilation.platformType == KotlinPlatformType.wasm) { - copy.from( - binary.linkSyncTask.zip(binary.linkTask) { linkSyncTask, linkTask -> - val moduleNameProvider = linkTask.compilerOptions.moduleName - linkSyncTask.destinationDirectory.zip(moduleNameProvider) { destDir, moduleName -> - destDir.resolve("$moduleName.wasm") - } - } - ) - } - copy.into(binary.distribution.outputDirectory) }