frontend-maven-plugin icon indicating copy to clipboard operation
frontend-maven-plugin copied to clipboard

Cannot use pnpm inside package.json scripts

Open attilapuskas opened this issue 3 years ago • 4 comments

Have a package.json like:

..
"scripts": {
  "build": "pnpm build-a && pnpm build-b",
  "build-a": "webpack --config webpack.config.a.js",
  "build-b": "webpack --config webpack.config.b.js"
}
..

It is not possible to run build with the corresponding pnpm maven goal, because pnpm executables are not added to PATH. Therefore child processes cannot be spawn with the embedded pnpm usage.

Although the PNPMInstaller tries to copy pnpm & pnpm.cmd (copyPnpmScripts), but pnpm has no such predefined files, thus it does not find anything to copy.

A solution can be perhaps to execute cmd-shim if the files are not found. Or another approach can be to install the .tgz files with npm instead of just extracting them, which I assume would add the executables automatically. But of course that would require the npm to be installed in advance.

attilapuskas avatar Apr 26 '21 11:04 attilapuskas

A temporary solution is to just use the node executor directly and run build.js (a file that you write), which then runs webpack.

eirslett avatar Apr 26 '21 13:04 eirslett

Yes, there are possible workarounds certainly, so it is not that critical issue. I mean we could also directly call webpack in the build script instead of referencing build-a and -b. But it would be nice if it can work out-of-the-box.

attilapuskas avatar Apr 26 '21 13:04 attilapuskas

I've solved it that way:

<goals>
  <goal>pnpm</goal>
</goals>
<configuration>
  <environmentVariables>
    <PATH>${env.PATH}:${project.basedir}/node/node_modules/pnpm/bin</PATH>
  </environmentVariables>
  <arguments>run install</arguments>
</configuration>

(looks simple, but took me a while to figure it out)

RiZKiT avatar Nov 04 '21 14:11 RiZKiT

I proposed a fix for this issue : #1045, it creates a symlink to the pnpm.cjs executable.

JulesAaelio avatar Aug 30 '22 13:08 JulesAaelio