frontend-maven-plugin
frontend-maven-plugin copied to clipboard
Cannot use pnpm inside package.json scripts
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.
A temporary solution is to just use the node executor directly and run build.js
(a file that you write), which then runs webpack.
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.
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)
I proposed a fix for this issue : #1045, it creates a symlink to the pnpm.cjs
executable.