Re:ES modules: A cartoon deep-dive
by WorldMaker on Wednesday March 28, 2018 @05:45PM
(#16702278)
There are proposals being debated for this. The article mentions specifically this one: https://github.com/domenic/package-name-maps
Ember has a convention to resolve files in its 'app' directory from your project name, and it makes renaming files a lot easier: `import { thing } from 'my-project/thing/in/dir.js'`
RequireJS has this too.
Moving files around is not something you do all that often. Doing so will present a problem in most any programming language.
Re:ES modules: A cartoon deep-dive
by Sophistifunk on Wednesday March 28, 2018 @06:33PM
(#16702644)
This is really not true. Moving files around is trivial in anything with a decent type system and IDE.
Re:ES modules: A cartoon deep-dive
by iamnotlarry on Wednesday March 28, 2018 @08:48PM
(#16703571)
I wrote a very small resolve hook for node that does this. It makes the directory of the initial module / for all imports. Node has made resolver hooks like that dead simple.
You an usually use `NODE_PATH=src` which will make requiring anything inside `src` easy as `import something from 'somewhere';`
You can set a custom alias, for example nuxt uses ~ for project root. I've seen projects use @ also.
Re:ES modules: A cartoon deep-dive
by panopticon on Wednesday March 28, 2018 @07:20PM
(#16702995)
That's not part of the ES module spec. That's something transpilers (like Babel + a plugin) support.
Re:ES modules: A cartoon deep-dive
by underwater on Thursday March 29, 2018 @09:00AM
(#16706600)
Can you also teach systems with their own resolution about the aliases (Jest, Flow, etc.)
import {thing} from '../../../thing/in/dir.js'
and then if I move a file I have to change all of its imports to a different number of parent traversals. It would be really nice to be able to define a path that all imports would be relative from.
I think babel has something like this using @, but I don't use babel right now.