Skip to content

fix(gradle-plugin): dynamically resolve script filename for JS and Wasm targets - #117

Merged
JSMonk merged 1 commit into
Kotlin:mainfrom
aryapreetam:fix/dynamic-web-script-name
Oct 15, 2026
Merged

JSMonk merged 1 commit into
Kotlin:mainfrom
aryapreetam:fix/dynamic-web-script-name

Conversation

@aryapreetam

@aryapreetam aryapreetam commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The Gradle plugin hardcodes composeApp.js as the script filename in JsSourceGeneratorTask and WasmSourceGeneratorTask. When Storytale is applied to projects using other module names (such as :shared or nested :app:shared), the generated index.html references a non-existent composeApp.js, causing a 404 script loading failure in the browser.

Solution

  1. Configurable Script Filename: Added a scriptFileName: Property<String> property to JsSourceGeneratorTask and WasmSourceGeneratorTask, defaulting to composeApp.js for backwards compatibility.
  2. Dynamic Script Resolution: Added resolveScriptFileName(target) in the Gradle plugin to resolve the script bundle name dynamically:
    • Webpack task mainOutputFileName (if configured)
    • Kotlin Multiplatform target.outputModuleName
    • Project name fallback (${project.name}.js)
  3. Task Grouping: Ensured generated web story run tasks are grouped under storytale.
  4. Unit Tests: Added ResolveScriptFileNameTest verifying resolution across:
    • Root application layout (composeApp -> composeApp.js)
    • Library subproject layout (:shared -> shared.js)
    • Nested subproject hierarchy (:app:shared -> root-app-shared.js)
    • Custom outputModuleName override via KGP DSL
    • Webpack task mainOutputFileName override

Verification

  • ./gradlew spotlessCheck (passes)
  • ./gradlew -p modules/gradle-plugin test (5/5 unit tests pass in ResolveScriptFileNameTest)
  • ./gradlew :examples:wasmJsBrowserStoriesDevelopmentRun (verifies existing :examples app)
  • ./gradlew :shared:wasmJsBrowserStoriesDevelopmentRun -PcmpProfile=1.10 in aryapreetam/storytale-sample (verifies :shared library module)
Visual Verification & Reproduction Steps

1. Internal Application (:examples)

Run the Wasm development server in the repository(./gradlew :examples:wasmJsBrowserStoriesDevelopmentRun):

Screenshot 2026-10-13 at 9 06 14 PM

2. External KMP Project with :shared module (aryapreetam/storytale-sample)

Reproduction Steps:

  1. Publish the updated Gradle plugin locally(from storytale root):
./gradlew publishToMavenLocal
  1. Clone storytale-sample (if not already cloned):
git clone https://github.com/aryapreetam/storytale-sample.git
cd storytale-sample
  1. In shared/build.gradle.kts, apply the local snapshot:
plugins {
  ...
- id("io.github.aryapreetam.storytale") version "0.0.6"
+ id("org.jetbrains.compose.storytale") version "0.0.4-SNAPSHOT"
}
  1. In settings.gradle.kts, set Kotlin to 2.3.10 under profile 1.10 (to match the current compiler plugin baseline):
...
versionCatalogs {
  create("libs") {
    when (profile) {
      "1.10" -> {
-       version("kotlin", "2.3.21")
+       version("kotlin", "2.3.10")
        ...
      }
      ....
    }
  }
}
...

Note: Verified against Kotlin 2.3.10 baseline to match the current compiler plugin registrar. (A separate PR will address IrGenerationExtension compatibility for Kotlin 2.3.20+ / 2.4+).

  1. Launch Wasm stories ./gradlew :shared:wasmJsBrowserStoriesDevelopmentRun -PcmpProfile=1.10:
Screenshot 2026-10-13 at 8 41 00 PM

…sm targets

- Add configurable scriptFileName Property to JsSourceGeneratorTask and WasmSourceGeneratorTask with fallback to SCRIPT_FILE_NAME.
- Dynamically resolve script filename using target webpack configuration, outputModuleName, or project name instead of hardcoded composeApp.js.
- Ensure storytale web run tasks are grouped under StorytaleGradlePlugin.STORYTALE_TASK_GROUP.
- Add unit tests covering standard (composeApp), flat subproject (:shared), nested (:app:shared), custom outputModuleName, and webpack task resolution.
@JSMonk
JSMonk requested review from JSMonk and eymar October 12, 2026 18:45
@JSMonk
JSMonk merged commit 5631d35 into Kotlin:main Oct 15, 2026
2 checks passed
@aryapreetam
aryapreetam deleted the fix/dynamic-web-script-name branch October 15, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants