Skip to content

Alias package name to root directory - #651

Closed
ccorcos wants to merge 2 commits into
react:masterfrom
ccorcos:alias-root
Closed

Alias package name to root directory#651
ccorcos wants to merge 2 commits into
react:masterfrom
ccorcos:alias-root

Conversation

@ccorcos

@ccorcosccorcos commented Sep 14, 2016

Copy link
Copy Markdown

The benefit of using absolute file paths is it's easier to lookup where a file is being used and its easier to move a file using a find-replace-all on the file's path. I like to use absolute paths for all all of my imports.

As discussed here, it would be great if this feature was supported natively by Node.js. For example:

mkdircool-appcdcool-appnpminit-yecho"module.exports = { name: 'chet' }">defs.jsecho"console.log('hello' + require('cool-app/defs').name)">index.jsnodeindex.js>hellochet

The interesting thing is approach is if you publish a Node.js library with this pattern and another project tries to require this package, all the paths would resolve correctly because the project-name now resolved to the node_module!

Anyways, the first commit is the specific feature I'm interested in. And if you feel like this is a good pattern to encourage, the second commit changes the generated templates to use absolute imports.

P.S. some additional discussion here: #636

@ghostghost added the CLA Signed label Sep 14, 2016
@ccorcos

Copy link
Copy Markdown
Author

Seems a little odd that we're testing the template like this...

@ccorcosccorcos mentioned this pull request Sep 14, 2016
@gaearon

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Let’s let this hang for a while. I’ll come back to make some decision on this later but I definitely want to address the use case in one way or another.

@ccorcos

Copy link
Copy Markdown
Author

Awesome. Well you just let me know then!

@gaearon

Copy link
Copy Markdown
Contributor

I’m going to close because that’s not the route I decided to take, mostly to avoid incompatibilities with wider ecosystem like Node, editors, type checkers, etc. See #741 for the approach I want to take, and the relevant discussion. Please feel free to send a PR implementing it!

@gaearongaearon closed this Sep 30, 2016
@locklockBot locked and limited conversation to collaborators Jan 22, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@ccorcos@gaearon