Anyone else run into an issue where changing the v...
# javascript
a
Anyone else run into an issue where changing the version of an npm dependency (via the Gradle DSL, i.e.
implementation(npm(package, version))
does not invalidate build cache? Kotlin 2.2.0, Gradle 8.12 Running build before and after changing the NPM dependency shows the same build cache key for
compileKotlinJs
. I would expect this to trigger a failed build and prompt the user to run
kotlinUpgradeYarnLock
like normal.
a
@Ilya Goncharov [JB] @Adam Semenenko ^^
e
Never noticed this in 2.1.21. Maybe it's a new bug.
a
Will test in 2.1.21 and report back
gratitude thank you 1
a
iirc npm dependencies are not an input for Kotlin compilation, so changing them won't affect the
compileKotlinJs
task. npm dependencies are an input for other tasks, like Webpack bundling and executing tests.
c
I've looked more into this issue, and it seems like the
jsBrowserProductionWebpack
has the issue with not changing the cache key when changing the version of an npm
implementation(npm(package, version))
. We experienced this being an issue where we updated a dependency and ran
jsBrowserProductionWebpack
on a fresh ci pipeline with remote caching enabled, which resulted in a stale cache. I've fixed it by adding `package.json`and `yarn.lock.bak`to input of my
KotlinWebpack
tasks. So it looks to me that npm dependencies are not inputs for other tasks, and can't find any immediate signs of these (or other versioning) files as inputs in the source code. I'm still quite new with gradle and kotlin, so my assumption and methodologies might be wrong.
a
hi @Christian Holmgaard Lund - the behaviour you're describing is not intended. Can you share your project so we can investigate? The logic around npm dependencies in KGP is rather complex (I'm investigating improving it at the moment), but afaik it is robust. If you have found a bug more details would be appreciated, so we can fix it.
c
I've had the help of claude code create a minimal reproducible example, so it might be a bit verbose. But you can find the repo here: https://github.com/chllund/kotlin-webpack-cache-bug
thank you color 1
And my fix is:
Copy code
tasks.withType<KotlinWebpack>().configureEach {
    inputs.file(layout.buildDirectory.file("tmp/jsPublicPackageJson/package.json"))
        .withPropertyName("npmPackageJson")
        .optional()
    inputs.file(rootProject.file("yarn.lock.bak"))
        .withPropertyName("yarnLockFile")
        .optional()
}
Which makes the cache key depend on these files created by
kotlinNpmInstall
(or similar)
a
@Ilya Goncharov [JB] Should the
jsBrowserProductionWebpack
task re-run if the npm dependencies change?
i
I think it should, because webpack bundles the content of npm dependencies, so if the content is changed, the task should not be up-to-date. Probably lock file as an input for webpack is missed
a
could you report an issue please @Christian Holmgaard Lund https://kotl.in/issue
👍 1
c
thank you color 3