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

Need a new Mojo to execute arbitrary node command #996

Open cmarchand opened 2 years ago

cmarchand commented 2 years ago

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.

zacthompson commented 2 years ago

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.

chulkilee commented 2 years ago

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