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

Need a new Mojo to execute arbitrary node command

Open cmarchand opened this issue 4 years ago • 2 comments

Some frameworks need to pre-compile some files before making the front app available. See xslt3 for example where we need to pre-compile xslt files with this commande :

node xslt3 -xsl:whatever.xsl -export:whatever.sef.json

Actually, there is no Mojo that directly allows to call node with specific parameters. I need one, with this usage :

<plugin>
  <artifactId>frontend-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>compile-xslt</id>
      <phase>compile</phase>
      <goals>
        <goal>node</goal>
      </goals>
      <configuration>
       <arguments>node_modules/xslt3/xslt3.js -xsl:src/main/xsl/md-to-xhtml.xsl -export:target/classes/xsl/md-to-html.sef.json</arguments>
      </configuration>
    </execution>
  </executions>
</plugin>

I just open the issue to be referenced in the pull request.

cmarchand avatar Aug 30 '21 21:08 cmarchand

There is the npx goal which would probably work almost exactly as you want: <arguments>xslt3 -xsl:...

You might also want to consider https://docs.npmjs.com/cli/v6/using-npm/scripts -- in particular I'm guessing that you want to do this xslt call as part of the preinstall or postinstall of your package or something like that. But even if not, you can add it as its own script and then make the f-e-p goal npm and the arguments run compile-xslt.

zacthompson avatar Aug 31 '21 21:08 zacthompson

FYI npm run of npm 7.x has a strange behaviour

https://docs.npmjs.com/cli/v7/using-npm/scripts#user

When npm is run as root, scripts are always run with the effective uid and gid of the working directory owner.

As a result, it runs as different user from maven... hitting the permission issue 🤦

Right now I'm just using a script to set up PATH with node/npm installed from this plugin.

See https://github.com/npm/cli/issues/3110

chulkilee avatar Sep 17 '21 01:09 chulkilee