Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using local packages

Tags:

elm

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?

like image 233
Cactus Avatar asked Jan 23 '15 13:01

Cactus


People also ask

How do I import packages to Go?

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.


3 Answers

In 2017 ( elm 0.18 ) you can do the following:

Overwrite a published package with a local cloned version

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.

Reference a local package

You can reference any elm project locally by adding it to source-directories like this:

"source-directories": [
    ".",
    "src",
    "../elm-css/src"
],

Add the locally referenced package's dependencies to your elm-package.json

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!

like image 171
Joe Avatar answered Nov 23 '22 22:11

Joe


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

like image 24
Apanatshka Avatar answered Nov 23 '22 23:11

Apanatshka


You can track the status of this feature in this enhancement request.

like image 44
thSoft Avatar answered Nov 24 '22 00:11

thSoft