node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
603 stars 118 forks source link

yarnSetup is neven UP-TO-DATE in UI multimodule setup #241

Closed dvoloshyn closed 1 year ago

dvoloshyn commented 2 years ago

I have a multimodule yarn UI project when every module is built using yarn and could depend on other modules. It means yarnSetup is executed before every other YarnTask. I noticed that it's almost always reinstalling yarn. The following is printed to console (reduced):

Task '...:yarnSetup' is not up-to-date because:
  Output property 'yarnDir' file '...\yarn-v1.22.19\node_modules\yarn\package.json' has changed.

I checked that file and found that properties "_requiredBy" and "_where" are different.

What could be done to avoid reinstalling yarn all the time?

deepy commented 2 years ago

I made a quick test to see if this happens out of the box and on the bright side, it doesn't. Unfortunately that means I'm not able to reproduce this.

Can you see if you can make a test that triggers it?

I added this to src/test/groovy/com/github/gradle/node/yarn/task/YarnSetupTask_integTest.groovy and ran ./gradlew :test --tests "com.github.gradle.node.yarn.task.YarnSetupTask_integTest"

The two directories are from src/test/resources/fixtures

package com.github.gradle.node.yarn.task

import com.github.gradle.AbstractIntegTest

import static org.gradle.testkit.runner.TaskOutcome.*

class YarnSetupTask_integTest extends AbstractIntegTest {
    def 'execute yarnSetup twice and check up-to-date'() {
        given:
        copyResources("fixtures/yarn")
        copyResources("fixtures/javascript-project")

        when:
        def result1 = build("yarnSetup").task(":yarnSetup").outcome
        def result2 = build("yarnSetup").task(":yarnSetup").outcome

        then:
        result1 == SUCCESS
        result2 == UP_TO_DATE
    }
}