HaxeFoundation / haxelib

The Haxe library manager
https://lib.haxe.org/
MIT License
173 stars 78 forks source link

Run haxelib main relative to classpath #613

Open n0-0b0dy opened 11 months ago

n0-0b0dy commented 11 months ago

When trying to create a runnable library, i noticed that haxelib ignores the classPath at haxelib.json for running the library.

So, if my code is under a src directory, looks like i cannot specify my main class at main property or import this class from a Run.hx or similar.

Consider for example this structure for a project:

I would like to use a haxelib.json similar to the following one in order to run the myproject.Main class:

{
    "name": "myproject",
    "version": "1.2.3",
    "classPath": "src/",
    "main": "myproject.Main",
    "dependencies": {}
}

Inspecting the haxelib code, i draft a possible way to solve the issue (if there isn't already another way that i didn't find out):

haxelib.api.ScriptRunner is responsible for running the projects (at the run method). The run method receives a LibraryRunData. However this data does not contains the classPath info.

So i think that the LibraryRunData could be changed to carry the project classPath (could be set from GlobalScope.runScript method). Then, the classPath would need to be carried out to the generateScript function, problably through Script, which would need to be changed to include that data.

What do you think about the idea to adding this feature?


Note: i know that i can compile run.n (using neko) to solve my problem. But i think would be better and easier if we could directly specify the main class at the haxelib.json.