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

Support ~ path syntax in require #545

Closed
slavchev opened this issue Aug 3, 2015 · 7 comments
Closed

Support ~ path syntax in require #545

slavchev opened this issue Aug 3, 2015 · 7 comments

Comments

@slavchev
Copy link

slavchev commented Aug 3, 2015

Support ~ path syntax in require. For example

var mymodule = require('~/path1/path2/mymodule');

See:

@slavchev slavchev added this to the 1.3.0 milestone Aug 3, 2015
@jasssonpet
Copy link
Contributor

What do you think of:

var mymodule = global.require('./path1/path2/mymodule');

as an alternative? This is already implemented in the master branch of NativeScript for iOS.

@fealebenpae
Copy link
Contributor

Or there's always require.main.require('./my-top-level-module') which I think is the node.js way to do it. It isn't implemented either but seems more logical to me than some string convention.

@atanasovg
Copy link
Contributor

The string convention seems easier to use to me and is tied with less implicit logic underneath. Additionally, we may provide a property at the file-system module that returns the app root. This will enable a more verbose way to do something like:

var fs = require("file-system");
var appRoot = fs.path.appRoot;
var myModulePath = fs.path.join(appRoot, "my-module");
var myModule = require(myModulePath);

@norfas
Copy link

norfas commented Aug 3, 2015

Tilde (require('/path1/path2/mymodule')) is more logical and clean approach to my taste.
It is also consistent with xml layout, e.g.:
<Image src="
/res/ctlArrangements1.png"/>

@fealebenpae
Copy link
Contributor

@atanasovg: I would advise against tightly coupling the application assets, including any JavaScript files, to a filesystem idiom. Whether we load assets from a filesystem or something like android.res.AssetManager or NSAssetData is an implementation detail, and as we transition towards ES6 modules this rule should hold even more so.

In general I am against this change. I would much rather we reverted to simpler times when absolute paths passed to require resolved to the app folder in the application package, which would in turn obviate the need for the tilde character entirely.

@enchev enchev modified the milestones: 1.4.0, 1.3.0 Sep 11, 2015
@atanasovg atanasovg modified the milestones: 1.4.0 (Under review), 1.4.0 Sep 12, 2015
@atanasovg atanasovg removed this from the 1.4.0 (Under review) milestone Sep 15, 2015
@dspells
Copy link

dspells commented Oct 5, 2015

I tend to agree agree with fealeaenpae.

If the concept of a "root" path is in the system then you should be able to use '/' as the first character to resolve to root.

var mymodule = require('/path1/path2/mymodule');

This is consistent with both the web definition of the "root"

http://www.motive.co.nz/glossary/linking.php?ref

and linux/unix

@enchev enchev closed this as completed Feb 15, 2016
@lock
Copy link

lock bot commented Aug 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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

No branches or pull requests

7 participants