node-gradle / gradle-node-plugin

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

Use pnpm in npm rules #324

Closed slatin-esteco closed 1 month ago

slatin-esteco commented 1 month ago

I have in the build.gradle a NpmTask that launch automatically a script in the package.json. My problem is that I am changing npm to pnpm and the plugin when it detects changes in the package.json launch npmInstall but It mustn't do this. Is there a way to override the npmInstall with pnpmInstall, block the npmInstall or set node to absolutely not use npm but use pnpm?

Node settings: image One of the incriminated tasks image The relative script in package.json: image

The node that I install doesn't have pnpm but I don't think it is the real problem

deepy commented 1 month ago

Does changing from npm_run_build to pnpm_run_build work? The <foo>_run_ rules add a dependency to their install equivalent (i.e. npm_run_foo depends on npmInstall and pnpm_run_foo depends on pnpmInstall)

I'm not familiar with how nx works, but if it handles the pnpm install already you might want to register your own PnpmTask that's configured the same as your task above https://github.com/node-gradle/gradle-node-plugin/blob/main/docs/usage.md#executing-npm-commands-via-npx has some examples

slatin-esteco commented 1 month ago

unfortunatly pnpm_run doesn't exist if I am correct (I tried and searched online). To resolve the problem I am changing every task I have by registering tasks with the PnpmTask set like this: image But the old method that invoked automatically the npm scripts was easier to use for me

deepy commented 1 month ago

Having tested it on a clean copy of 7.1.0 the pnpm_ rules behave just like the npm_ rules so a search and replace should work And if you don't need the dependency on pnpmInstall use the pnpm_ rule rather than the pnpm_run_ one

But regardless, I'd still recommend defining the task like you've done above, it's the same amount of lines and only 27 characters more than relying on the rule