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

[Packager] Allow imports that are relative to the project root #2035

Conversation

negativetwelve
Copy link
Contributor

This is related to #637.

From that issue to quote @JaapRood:
Browserify and webpack both let you use symlinks in the node_modules folder to reference modules. This is mainly useful for preventing ../../../../ requires.

With a symlink setup from the project root setup like:

ln -s src/app node_modules/app

in any file in the project you can:

var  app = require('app');
var somethingElse  = require('app/lib/something-else');

However, the packager can't resolve them: Requiring unknown module "app".

@ide did some investigation and found that support for symlinks was most likely not going to happen for watchman facebook/watchman#105

To get around this in our app, we've been building a library and keeping it at the project root. With this pull request, we can then find these modules and our import statements are:

import MyLib from "my_lib"
import SomethingElse from "my_lib/very/deep/nested/file/something_else"

from anywhere in our project, not just at the root. This is similar to what resolve.root for those familiar with webpack allows.

Thoughts? I know this isn't a solution to the symlinks problem but it helps alleviate the problem for some use cases and allows us to have clean import statements for our core internal modules.

… symlinks aren't followed, this allows us to have clean import statements.
@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jul 17, 2015
@negativetwelve
Copy link
Contributor Author

I'm investing the test failures now

@negativetwelve
Copy link
Contributor Author

So the test failure happens when we rename a package by changing the name attribute in the package.json from aPackage to bPackage but we leave the filename the same (aPackage).

Is this intended behavior?

@negativetwelve negativetwelve deleted the packager/absolute-imports branch April 11, 2016 06:41
FalseLobster pushed a commit to FalseLobster/react-native that referenced this pull request Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants