I have an Elm package (source + all build artifacts) in a local directory, and I would like to use it from another Elm package, without publishing the library. So my directory setup looks like this:
/
my-lib/
elm-package.json
my-app/
elm-package.json
First of all, running elm-package install
in the library package's directory doesn't seem to do anything more than just building the package; it doesn't get installed in any global directory as far as I can tell.
I've added my-lib
to my-app/elm-package.json
as such:
"dependencies": {
"elm-lang/core": "1.0.0 <= v < 2.0.0",
"my-vendor/my-lib": "0.0.1 <= v <= 0.0.1"
}
So when I run elm-make
in the dependent package's directory, it complains
There are no versions of package
my-vendor/my-lib
on your computer.
elm-package install
complains about the same thing.
The only workaround I've found is to create the following symlinks in my-app
:
/
my-app/
elm-stuff/
packages/
my-vendor/
my-lib/
0.0.1@ -> /my-lib/
build-artifacts/
my-vendor@ -> /my-lib/build-artifacts/my-vendor
I also had to add the following to /my-app/elm-stuff/exact-dependencies.json
:
"my-vendor/elm-lib": "0.0.1"
Clearly, all of the above should be taken care of automatically by elm-package
, if only I could point it at /my-lib/
from /my-app/
. So how do I do that?
To import a package, we use import syntax followed by the package name. 💡 Unlike other programming languages, a package name can also be a subpath like some-dir/greet and Go will automatically resolve the path to the greet package for us as you will see in the nested package topic ahead.
In 2017 ( elm 0.18 ) you can do the following:
If you've got a dependency to a published package that you'd like to make local, remove your dependency e.g:
"dependencies": {
"rtfeldman/elm-css": "8.2.0 <= v < 9.0.0"
}
Then do a elm-make
of your project (this should remove the package from your elm-stuff directory otherwise it will use the cached version of the package. Then you clone and reference the package locally as per steps below.
You can reference any elm project locally by adding it to source-directories
like this:
"source-directories": [
".",
"src",
"../elm-css/src"
],
elm-css has these dependencies:
"rtfeldman/elm-css-util": "1.0.2 <= v < 2.0.0",
"rtfeldman/hex": "1.0.0 <= v < 2.0.0"
So add these to your elm-package.json as well.
You're done!
Easier use of local packages is on the todo list. I'm afraid your current approach is the state of the art. Either do it like your doing it now or copy over the code from the package (or maybe symlink modules folders/.elm files from my-lib/src
in my-app/src
?)
Most recent thread on the mailing list about this issue: https://groups.google.com/d/topic/elm-discuss/i51Bor6Uers/discussion
You can track the status of this feature in this enhancement request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With