Relative Imports

Any import that begins with ./ or ../ is considered a relative import.

Relative imports reference a file located relative to the file that is importing it. This provides a mechanism for modularization (breaking up the logic into multiple files) and code forking (for example, importing different implementations of a function based on the shell interpreter).

Implementation Details

Relative imports are made possible primarily because of the Location and/or Content-Location HTTP headers provided by the server that provides the imported URL.

When a script is imported, the HTTP headers are parsed, and the final Location/Content-Location header is considered the "location" of the script. This final URL gets cached to the filesystem in the locations directory.

Example

Perhaps an example will help illustrate. If you inspect the response headers for the tootallnate/hello, then you can see the Location header is present:

$ curl -sI https://import.pw/tootallnate/hello | grep -i location
location: https://raw.githubusercontent.com/tootallnate/hello/master/hello.sh

import keeps tracks of these URL locations, so that from within the hello.sh script, any relative import, let's say import ./foo.sh, will be normalized to relative of the current URL location.