[ALOY-1714] Allow ~/ to be used as a shortcut for WPATH() in xml view attributes

GitHub Issuen/a
TypeNew Feature
Affected Version/sn/a
Fix Version/sn/a
Labelsgriffin-app, widget, wpath
ReporterBrenton House
AssigneeFeon Sua Xin Miao


-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}


  1. Ewan Harris 2020-01-23 [~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]?
  2. Brenton House 2020-01-23 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. Using require('@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
  3. Jan Vennemann 2020-01-23 [~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 the src or asset 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 cumbersome WPATH(). And since this is all just a Webpack alias configuration we can easily add a short version like @w.
  4. Brenton House 2020-01-23 So what would happen if you used @widget/utils and if /my-widget/utils did exist but you wanted to use the correct path of node_modules/@widget/utils ?
  5. Jan Vennemann 2020-01-23 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?

JSON Source