| 1 |
# Creating a haxelib package |
| 2 |
|
| 3 |
Each haxelib package is essentially a zip folder containing source code, supporting files, and a `haxelib.json` file. |
| 4 |
|
| 5 |
### haxelib.json |
| 6 |
|
| 7 |
Each Haxe library requires a `haxelib.json` file in which the following attributes are defined: |
| 8 |
|
| 9 |
* name: The name of the library. It must contain at least 3 characters among the following: `[A-Za-z0-9_-.]`. In particular, no spaces are allowed. |
| 10 |
* url: The URL of the library, i.e. where more information can be found. |
| 11 |
* license: The license under which the library is released. Can be `GPL`, `LGPL`, `BSD`, `Public` (for Public Domain), `MIT`, or `Apache`. |
| 12 |
* tags: An array of tag-strings which are used on the repository website to sort libraries. |
| 13 |
* description: The description of what the library is doing. |
| 14 |
* version: The version string of the library. This is detailed in [Versioning](#versioning). |
| 15 |
* classPath: The path string to the source files. |
| 16 |
* releasenote: The release notes of the current version. |
| 17 |
* contributors: An array of user names which identify contributors to the library that are allowed to upload to haxelib. The first user will be defined as the owner, who is the only one that can change description, url, license, contributors, and ownership (by changing who come first in contributors). |
| 18 |
* dependencies (optional): An object describing the dependencies of the library. This is detailed in [Dependencies](#dependencies). |
| 19 |
* main (optional): A class to run on `haxelib run libraryname` command. Relative to library root. E.g. to run `tools/Main.hx` the value should be `tools.Main`. Default value since Haxe 4: `Run` |
| 20 |
|
| 21 |
The following JSON is a simple example of a haxelib.json: |
| 22 |
|
| 23 |
```haxe |
| 24 |
{ |
| 25 |
"name": "useless_lib", |
| 26 |
"url" : "https://github.com/jasononeil/useless/", |
| 27 |
"license": "MIT", |
| 28 |
"tags": ["cross", "useless"], |
| 29 |
"description": "This library is useless in the same way on every platform.", |
| 30 |
"version": "1.0.0", |
| 31 |
"classPath": "src/", |
| 32 |
"releasenote": "Initial release, everything is working correctly.", |
| 33 |
"contributors": ["Juraj","Jason","Nicolas"], |
| 34 |
"dependencies": { |
| 35 |
"tink_macro": "", |
| 36 |
"nme": "3.5.5" |
| 37 |
}, |
| 38 |
"main": "tools.Main" |
| 39 |
} |
| 40 |
``` |
| 41 |
|
| 42 |
<a name="versioning"></a> |
| 43 |
|
| 44 |
### Versioning |
| 45 |
|
| 46 |
Haxelib uses a simplified version of [SemVer](http://semver.org/). The basic format is this: |
| 47 |
|
| 48 |
``` |
| 49 |
major.minor.patch |
| 50 |
``` |
| 51 |
|
| 52 |
These are the basic rules: |
| 53 |
|
| 54 |
* Major versions are incremented when you break backwards compatibility - so old code will not work with the new version of the library. |
| 55 |
* Minor versions are incremented when new features are added. |
| 56 |
* Patch versions are for small fixes that do not change the public API, so no existing code should break. |
| 57 |
* When a minor version increments, the patch number is reset to 0. When a major version increments, both the minor and patch are reset to 0. |
| 58 |
|
| 59 |
Examples: |
| 60 |
|
| 61 |
* "0.0.1": A first release. Anything with a "0" for the major version is subject to change in the next release - no promises about API stability! |
| 62 |
* "0.1.0": Added a new feature! Increment the minor version, reset the patch version |
| 63 |
* "0.1.1": Realised the new feature was broken. Fixed it now, so increment the patch version |
| 64 |
* "1.0.0": New major version, so increment the major version, reset the minor and patch versions. You promise your users not to break this API until you bump to 2.0.0 |
| 65 |
* "1.0.1": A minor fix |
| 66 |
* "1.1.0": A new feature |
| 67 |
* "1.2.0": Another new feature |
| 68 |
* "2.0.0": A new version, which might break compatibility with 1.0. Users are to upgrade cautiously. |
| 69 |
|
| 70 |
If this release is a preview (Alpha, Beta or Release Candidate), you can also include that, with an optional release number: |
| 71 |
|
| 72 |
``` |
| 73 |
major.minor.patch-(alpha/beta/rc).release |
| 74 |
``` |
| 75 |
|
| 76 |
Examples: |
| 77 |
|
| 78 |
* "1.0.0-alpha": The alpha of 1.0.0 - use with care, things are changing! |
| 79 |
* "1.0.0-alpha.2": The 2nd alpha |
| 80 |
* "1.0.0-beta": Beta - things are settling down, but still subject to change. |
| 81 |
* "1.0.0-rc.1": The 1st release candidate for 1.0.0 - you shouldn't be adding any more features now |
| 82 |
* "1.0.0-rc.2": The 2nd release candidate for 1.0.0 |
| 83 |
* "1.0.0": The final release! |
| 84 |
|
| 85 |
<a name="dependencies"></a> |
| 86 |
|
| 87 |
### Dependencies |
| 88 |
|
| 89 |
As of Haxe 3.1.0, haxelib supports only exact version matching for dependencies. Dependencies are defined as part of the [haxelib.json](haxelib-json.md), with the library name serving as key and the expected version (if required) as value in the format described in [Versioning](#versioning). |
| 90 |
|
| 91 |
We have seen an example of this when introducing haxelib.json: |
| 92 |
|
| 93 |
```haxe |
| 94 |
"dependencies": { |
| 95 |
"tink_macros": "", |
| 96 |
"nme": "3.5.5" |
| 97 |
} |
| 98 |
``` |
| 99 |
|
| 100 |
This adds two dependencies to the given Haxe library: |
| 101 |
|
| 102 |
1. The library "tink_macros" can be used in any version. Haxelib will then always try to use the latest version. |
| 103 |
2. The library "nme" is required in version "3.5.5". Haxelib will make sure that this exact version is used, avoiding potential breaking changes with future versions. |
| 104 |
|
| 105 |
### extraParams.hxml |
| 106 |
|
| 107 |
If you add a file named `extraParams.hxml` to your library root (at the same level as `haxelib.json`), these parameters will be automatically added to the compilation parameters when someone use your library with `-lib`. |
| 108 |
|
| 109 |
### Submission process |
| 110 |
|
| 111 |
* During development: Use `haxelib dev my_test_haxelib /path/to/my_test_haxelib/` to test the library. |
| 112 |
* Ready to test: Zip the current directory, and use `haxelib install my_test_haxelib.zip` to try the final version. |
| 113 |
- Submit: You can run `haxelib submit my_test_haxelib.zip` to submit the zip file to haxelib. Alternatively you can run `haxelib submit` without a zip file to have haxelib zip and submit the current directory. |