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.25k stars 870 forks source link

Node + NPM installation directories inconsistency #204

Open NBardelot opened 9 years ago

NBardelot commented 9 years ago

The project I'm working on requires Maven 2, so I'm using the 0.0.16 version of the plugin.

After Node and NPM are installed, with default properties for the plugin, I end up with directories like this:

./node_modules
./node <-- node binary is here
./node/npm
./node/npm/bin <-- npm bash file is here with npm-cli.js

The npm bash file is:

$ cat npm
#!/bin/sh

basedir=`dirname "$0"`

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node.exe" ]; then
  "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
else
  node "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
fi

This script is incompatible with how NodeAndNPMInstaller handles the installation.

I propose two solutions: Solution 1 : remove this script at the end of the installation, and create an new script at the root of the project (i.e. where pom.xml stands) which will handle things properly. Solution 2 : install NPM in a way that matches this script's behaviour.

Solution 1 has the advantage of being compatible with older versions of the plugin without having to clean up the directories, and requires less code change. But solution 2 is cleaner, and makes life easier for someone who uses other installations of node+NPM.

eirslett commented 9 years ago

The script inside there isn't used at all from the plugin, it's calling npm via the node executable. You might have some luck using the maven clean plugin if you want to hack something together for your particular project?

Den 24. apr. 2015 kl. 17.56 skrev Noël Bardelot notifications@github.com:

The project I'm working on requires Maven 2, so I'm using the 0.0.16 version of the plugin.

After Node and NPM are installed, with default properties for the plugin, I end up with directories like this:

[code] ./node_modules ./node <-- node binary is here ./node/npm ./node/npm/bin <-- npm bash file is here with npm-cli.js [/code]

The npm bash file is:

[code] $ cat npm

!/bin/sh

basedir=dirname "$0"

case uname in CYGWIN) basedir=cygpath -w "$basedir";; esac

if [ -x "$basedir/node.exe" ]; then "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@" else node "$basedir/node_modules/npm/bin/npm-cli.js" "$@" fi [/code]

This script is incompatible with how NodeAndNPMInstaller handles the installation.

I propose two solutions: Solution 1 : remove this script at the end of the installation, and create an new script at the root of the project (i.e. where pom.xml stands) which will handle things properly. Solution 2 : install NPM in a way that matches this script's behaviour.

Solution 1 has the advantage of being compatible with older versions of the plugin without having to clean up the directories, and requires less code change. But solution 2 is cleaner, and makes life easier for someone who uses other installations of node+NPM.

— Reply to this email directly or view it on GitHub.

NBardelot commented 9 years ago

Thanks for this quick response Eirik.

Yourplugin is very nice, because it enables the team to work on a single project:

So I understand what you say, and I have no problem with the inner behaviour of the plugin : a "mvn clean install" works fine for us.

But What's disturbing is that after running the Maven goals the frontend developer will have the node+npm tools installed, but will not be able to use this utility script as-is. You'd be confused if after installing Maven the mvn.bat or mvn shell scripts weren't working, wouldn't you? Well, it's the same here with the npm script. Untill it works our developers must call npm using the full node command line, which works fine but requires to setup the PATH and NODE_PATH and write the full directory structures... It would really help if the npm script worked.

eirslett commented 9 years ago

It does work if you copy some of these helper scripts to your project root directory: https://github.com/eirslett/frontend-maven-plugin/tree/master/frontend-maven-plugin/src/it/example%20project/helper-scripts

NBardelot commented 9 years ago

I saw that while you were writing! Would you consider a pull request that automatically includes the npm helper script at node+npm install time instead of the non-working one?

eirslett commented 9 years ago

I'd rather made it opt-in, since people have to actually put the helper script in their project root and commit it to their repository. (If you put it in the node folder, you get some cross-platform issues)

NBardelot commented 9 years ago

OK, adding a "withNpmHelperScript" boolean flag to the "install-node-and-npm" goal's configuration, with "false" by default will do the trick.

klieber commented 9 years ago

I believe #257 fixed the inconsistency issue described here.