eirslett / frontend-maven-plugin

"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins." A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.
Apache License 2.0
4.22k stars 868 forks source link

Cannot use pnpm inside package.json scripts #967

Closed attilapuskas closed 1 year ago

attilapuskas commented 3 years ago

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.

eirslett commented 3 years ago

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

attilapuskas commented 3 years ago

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.

RiZKiT commented 2 years ago

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)

JulesAaelio commented 1 year ago

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