Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias package name to root directory #651

Closed
wants to merge 2 commits into from

Conversation

ccorcos
Copy link

@ccorcos ccorcos commented Sep 14, 2016

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:

mkdir cool-app
cd cool-app
npm init -y
echo "module.exports = { name: 'chet' }" > defs.js
echo "console.log('hello' + require('cool-app/defs').name)" > index.js
node index.js
> hello chet

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

@ghost ghost added the CLA Signed label Sep 14, 2016
@ccorcos
Copy link
Author

ccorcos commented Sep 14, 2016

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

@ccorcos ccorcos mentioned this pull request Sep 14, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 16, 2016

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
Author

ccorcos commented Sep 20, 2016

Awesome. Well you just let me know then!

@gaearon
Copy link
Contributor

gaearon commented Sep 30, 2016

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!

@gaearon gaearon closed this Sep 30, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants