App root module specifiers

PETER Flannery flannery.peter at
Fri Jun 2 16:08:02 UTC 2017

Currently there isn't a way to import a module using an app root module

I.E. `import * as Stuff from 'utils/someUtil.js'`

Relative paths suffices in the simplest applications but not being able to
resolve from the root of the app leads to a complex stack of relative path
entries I.E. `../../..`

One example of where these complex stacks arise is importing source modules from
within test modules where usually tests are defined in a test folder separated
from the source.

Another issue arises when moving a file to another location which then leads to
recalculating the relative path stack.

One idea I have is that each host has a default URL protocol. For now I will
call it **moduleSpecifierDefaultProtocol** that will resolve double front
slashes `//` to the default protocol

In a browser the default protocol already gets resolved and is based on the URL
of the document requested.  I.E.  '//utils/someUtil.js` resolves to
`https://utils/someUtil.js` when `https` is the protocol used in the requesting

Hosts like NodeJS could interpret '**moduleSpecifierDefaultProtocol** to be the
root of the app allowing `import * as Stuff from '//utils/someUtil.js'`.

The other idea I have (and probably needs to be a separate but related solution
proposal) is to have custom alias mappings which would be defined in a place
where the host can find and resolve module specifier aliases I.E. an `.es` file
in the app root containing a json map of aliases. The maps could possibly be
auto generated using build tools when publishing an app.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list