[ALOY-1714] Allow ~/ to be used as a shortcut for WPATH() in xml view attributes
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | None |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | griffin-app, widget, wpath |
Reporter | Brenton House |
Assignee | Feon Sua Xin Miao |
Created | 2020-01-23T17:25:35.000+0000 |
Updated | 2020-01-23T23:35:09.000+0000 |
Description
-Currently you have to use WPATH() around everything that refers to a path relative to the widget directory.-
You can do this currently if you are using the PR for this ticket: ALOY-1253 .
I highly recommend merging this PR as well.
{noformat}
{noformat}
I am proposing that ~/ be used as a shortcut for this so that WPATH() is no longer required when using with XML View attributes
{noformat}
{noformat}
[~bhouse] I think that the webpack loader for Alloy is introducing some special syntax for this kinda thing too, so I'd like for us to align between the two rather than have two ways to achieve the same thing. According to [this doc](https://github.com/appcelerator/appcd-plugin-webpack/blob/master/migration.md#code-changes) the widget syntax there will be
@widget
is that right [~jvennemann]?Something like this
require('@widget/utils')
- as an example on the docs is a bad idea. The "@" symbol has a special meaning with node modules and all npm scoped packages begin with this character. Usingrequire('@widget/utils')
would tell the system to require something from the npm package@widget/utils
Plus... it's not much of a shortcut if it is the same or longer than using WPATH[~bhouse], Webpack uses an enhanced resolve mechanism, so things like
@widget/utils
are perfectly valid. The@widget
is just a path alias and Webpack falls back to the default node resolve algorithm using@widget
as the scope if it won't find anything under the alias. Prefixing aliases in Webpack with either@
or~
is common practice. Using those character alone generally is used as an alias to thesrc
orasset
directories of a project. I used the same [alias configuration](https://github.com/appcelerator/appcd-plugin-webpack/blob/9f2f03cc5b88e958abb9ddefad4e19fe36f4b88b/src/config/alloy.js#L39) in our Webpack configs as well. To properly distinguish between the project source alias and the one for widgets i chose@widget
. Although@widget
is not very much of a shortcut, IMHO it's still much easier to write than the cumbersomeWPATH()
. And since this is all just a Webpack alias configuration we can easily add a short version like@w
.So what would happen if you used
@widget/utils
and if/my-widget/utils
did exist but you wanted to use the correct path ofnode_modules/@widget/utils
?It would use the first match (which would be the alias). There are currently no published packages under
@widget
so it wouldn't be an issue anyway. Also I'd say the chances of this every being an issue are pretty low. But we can change it of course just to be safe. However, if possible i would not use~/
since it is very common to use that as the alias to assets in Web projects and i would like to keep it that way in Titanium as well. Any suggestions?