Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npmInstall ignores npm workspaces in up-to-date detection #304

Open
hosswald opened this issue Feb 14, 2024 · 2 comments
Open

npmInstall ignores npm workspaces in up-to-date detection #304

hosswald opened this issue Feb 14, 2024 · 2 comments

Comments

@hosswald
Copy link

hosswald commented Feb 14, 2024

We have a monorepo with multiple workspaces. The workspaces also reflect the gradle (sub)project structure.
Our project structure looks like this:

build.gradle
package.json
package-lock.json
node_modules/
scripts/
\_ build.gradle
|_ package.json

The root package.json defined scripts/ as a workspace:

  "workspaces": [
    "scripts"
  ]

We apply the gradle-node-plugin in the scripts/build.gradle like this:

node {
    nodeProjectDir = rootProject.projectDir
}

task compile(type: NpmTask) {
    dependsOn = [tasks.npmInstall]
    workingDir = rootProject.projectDir
    args = [
        "run",
        "build",
    ]
}

The problem is that npmInstall only registers changes to the root package.json etc., but not to scripts/package.json etc.
So if I change a dependency in scripts/package.json, npmInstall might not run.
It would be nice if the npmInstall task could check for changes in package.json etc. in all workspaces defined in the root package.json as well.
Currently, we need this workaround:

npmInstall {
    outputs.upToDateWhen {false}
}

I don't think the problem is related to our unusual project structure, but likely affects every situation where NPM workspaces are involved - NpmInstallTask just doesn't seem to consider changes to workspace files / npm files outside of nodeProjectDir at all.

@hosswald hosswald changed the title npmInstall does not detect monorepo changes npmInstall does not detect monorepo workspace changes Feb 14, 2024
@hosswald hosswald changed the title npmInstall does not detect monorepo workspace changes npmInstall ignores npm workspaces in up-to-date detection Feb 14, 2024
@wickkidd
Copy link

Ditto for yarn workspaces. I need to tell gradle-node-plugin to use a subfolder for package.json and root for the lock file.

@brnhffmnn
Copy link

I just changed my module setup and now I am encountering this.
When running a NpxTask in CI I get:

npm error could not determine executable to run

It seems, it is because I have the relevant dependency defined in the parent module.

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

No branches or pull requests

3 participants