News for hackers. Stuff that matters.
Re:ES modules: A cartoon deep-dive by plopz on Wednesday March 28, 2018 @05:14PM (#16702002)
The problem I find with the current ES modules is a lot of statements like this

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.

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
Re:ES modules: A cartoon deep-dive by mnutt on Wednesday March 28, 2018 @06:10PM (#16702472)
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'`
Re:ES modules: A cartoon deep-dive by danlugo92 on Wednesday March 28, 2018 @07:49PM (#16703198)
RequireJS has this too.
Re:ES modules: A cartoon deep-dive by Touche on Wednesday March 28, 2018 @05:54PM (#16702356)
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.
Re:ES modules: A cartoon deep-dive by reaktivo on Friday March 30, 2018 @11:32AM (#16716910)
You an usually use `NODE_PATH=src` which will make requiring anything inside `src` easy as `import something from 'somewhere';`
Re:ES modules: A cartoon deep-dive by Can_Not on Wednesday March 28, 2018 @06:17PM (#16702533)
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.)