node-gradle / node-gradle/gradle-node-plugin
npmInstall ignores npm workspaces in up-to-date detection
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 677
- Forks
- 120
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main/kotlin/com/github/gradle/node/npm/task/NpmInstallTask.kt and inspect how npmInstall declares inputs for up-to-date detection. Compare those inputs with the root package.json workspace entries and the workspace package files described in the issue. Done means changes in workspace package.json or related npm files cause npmInstall to run, with coverage in the relevant existing task tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, kotlin, nodejs
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100