Way to install Haxe dependencies easily?

A lot of tools these days like Node.js’s NPM, and Ruby’s Gems, have easy and quick ways of installing all the thirdparty dependencies needed for a project. I was wondering, is there something similar in Haxe?

For example, in Node.js, you can setup a package.json file, that lists dependency libraries with version numbers. Then you can call npm install and it will look at the dependencies in the package.json file, and install them. Ofcource, this is a little different to haxelib because by default the libraries are installed locally with npm. But they can be installed globally with the -g param.

So is there something like this in Haxe? I know all the haxelibs are in the project.xml file (not sure if it supports version numbers, but haxelib is global anyway, so it might not make sense, also maybe haxelib.json makes more sense for this). It would be great to be able to download a project from github for example, then just run haxelib install, and all the dependencies would magically be installed.

I wrote a bash script recently (works in mingw)

#Install haxelib deps
for lib in $(cat project.xml | grep haxelib | grep source=\"haxelib\" | sed 's/.*name="\([^"]*\)".*/\1/'); do
	haxelib install $lib;
done;

#Instal custom git deps
IFS=$'\n'
#set -f
for lib_and_git in $(cat project.xml | grep haxelib | grep source=\"git | sed 's/.*name="\([^"]*\)"\ source="\([^"]*\)".*/\1 \2/'); do
	eval "haxelib git $lib_and_git"
done;

It’s not great, and relies that dependencies you want to install automatically have a specific format in project.xml:

<haxelib name="dconsole" source="haxelib" />
<haxelib name="tink_core" source="haxelib" />
<haxelib name="thx.core" source="haxelib" />
<haxelib name="mylib" source="[email protected]:me/mylib.git" />

Unfortunately this won’t work with “OpenFL”, so I manually added extra

haxelib install lime
haxelib run lime setup #NOTE you can use 'yes "y" | haxelib run lime setup to automate install on linux/mac. Won't work in MingW
haxelib run lime install openfl

Hope this helps for now, until lime-tools gets some fancy auto-install like npm does.

PS: Vanilla haxe already can do everything automatically with haxeib install build.hxml, but as far as I know, there still isn’t a solution for Lime/OpenFL.

PSS: This is some really bad bash scripting, made very quickly. A good solution would be to actually parse xml. You know what they say about parsing XML with regexp :slight_smile:

1 Like

A bit outdated but now you can do this:
http://www.displayobject.fr/2015/09/04/install-haxe-dependencies-easely/

openfl install or lime install will install dependencies from the project.xml of a library, this does not support individual projects (at the moment) but will support dependencies for haxelibs (such as lime install openfl or openfl upgrade)

If you install tink_macro via haxelib, you’ll notice that it automatically installs (or upgrades) tink_core. This works because of the “dependencies” entry in haxelib.json:

HaxeFlixel and HaxePunk use this feature as well, but for some reason OpenFL does not.

I think the haxelib “dependencies” feature is broken

If you use development libraries, a haxelib upgrade will install release versions anyway. For some projects (like Lime) this can be very large when you only wanted to check for a new format or actuate library :wink:

It includes the library as a source dependency, no matter what. This removes support for “mix-and-match” as you may want, say, HXCPP installed, but not want to include it, source-wise, in every OpenFL build, right?

The openfl install/upgrade behavior respects dev directories, understand GIT checkouts with submodules, and can run through project.xml dependencies without creating a build-time association (“openfl-samples” is another example of a library that shouldn’t be included in every build)

1 Like