Import file in Jsnonnet/libsonnet application using relative path

249 Views Asked by At

I have a libsonnet file in which I want to import another libsonnet file proving relative path

I am able to do it by going backward from current folder For example : import ‘../../../abc.libsonnet’

Is there any way to import same by proving relative path from root folder? Something like below import ‘./appl/example/test/abc.libsonnet

I tried this but facing ‘No match locally’ error during runtime

1

There are 1 best solutions below

0
On BEST ANSWER

As you already found, import paths are resolved from:

  • the current directory
  • the directory of the jsonnet source file importing it

You can add a another directory to the CLI by:

  • Using the -J arg as:
    jsonnet -J <ROOT_DIR> ...
    
  • pre-exporting below env var:
    env JSONNET_PATH=<ROOT_DIR> jsonnet ...
    

In your case, this could be either

  • still relative:
    $ jsonnet -J "${PWD}/../../../" ...
    
  • "resolve" the relative path:
    $ jsonnet -J "$(realpath ../../../)" ...
    

Find more details at: https://www.mankier.com/1/jsonnet#Environment