How do I import a package from the local filesystem using dub?

336 views Asked by At

I have a project that uses dub. I want to use an external file vendored into my project, as a dependency. How do I do this? I don't want to have it in my project's source/ dir. I don't want to add it as a dub managed dependency, but I do want to be able to just import xxx.

The package is this one: https://github.com/gianm/d-json , it does not use dub or have a dub.json project file.

2

There are 2 answers

1
Adam D. Ruppe On BEST ANSWER

Alternative thing: make a third_party directory, put the file in there, then add that to the sourcePaths in your dub config (you'll probably specify both ["third_party", "source"] since the default source will be overridden if you don't list it too.

0
hraban On
  1. Convert the package to dub by adding a dub.json file in the root, with the following contents: {"name": "jsonx"}. Create a source folder, and move jsonx.d into it.
  2. Put the folder anywhere you want, e.g. top-level next to your own project.
  3. Add the following dependency to your dub.json:
    "dependencies": {
        ...
        "jsonx": {"path": "../jsonx/"}
    }
  1. You can now import the package anywhere using import jsonx;.

In conclusion, if your app is in a dir called app, your tree should look like this:

.
├── app
│   ├── dub.json
│   └── source
│       └── myapp.d
└── jsonx
    ├── dub.json
    └── source
        └── jsonx.d