[TIMOB-9893] TiAPI: CommonJS 1.1 compliance
GitHub Issue | n/a |
---|---|
Type | Story |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-06-11T15:53:48.000+0000 |
Affected Version/s | Release 2.1.0 |
Fix Version/s | n/a |
Components | TiAPI |
Labels | core, parity |
Reporter | Stephen Tramer |
Assignee | Christopher Williams |
Created | 2012-07-05T16:47:25.000+0000 |
Updated | 2018-06-11T15:53:48.000+0000 |
Description
Needs to implement the "minispec" for require() that was decided on by core:
Conform to commonjs spec: http://wiki.commonjs.org/wiki/Modules/1.1
-> Testing to be https://github.com/commonjs/commonjs/tree/master/tests/modulesnon-MW platforms throw an exception when confronted with async syntax
-> require(["foo"], callbackFunction);
There is also the possibility of:
Hello. I'm not sure about second point. The path is relative if it begins with "." or "..", otherwise is absolute. Hope that "require" will work even without leading slash.
On Mobile Web, require("/some/module") and require("some/module") are the same absolute path.
If you have questions about how commonjs will work, read the linked specification. We will be following it exactly except for the root path addition.
I don't have questions regarding CommonJs, but I'm a bit worried about root path addition. If scripts that uses that addition will work in other JS environments that supports CommonJs specification (which is the point of CommonJs), then OK, the problem does not exist. But will they work? I haven't worked much in other CommonJs environments, but for example, in NodeJs "require('console')" works, but "require('/console')" does not work. I don't see the point in having addition (that copies existing functionality) that could cause scripts not to work in other CommonJs environments.
It's not actually an addition. Titanium has supported a forward slash to indicate absolute on Android and iOS for a long time, for better or worse, and changing that behavior now would break a lot of existing apps. Titanium is the only platform I am aware of that supports forward slash in a require.
I'm all for removing support for the '/' in module ids. It's not standard. Mobile Web resisted supporting this for quite a while before we caved. Removing support is 2 small changes. Then any module id that starts with '/' would signify a resource file such as require('/some/file.js'). How about we detect and show a deprecation message if someone tries to use a '/' in a module id?
Bryan - Yes, it is an addition. In fact iOS doesn't support it because it had to be added in a recent PR.
Brake of existing apps shouldn't be big issue because it is not hard task to remove leading slash (everyone should be able to do that within 1 minute). A deprecation message is fine, but IMO unnecessary because leading slash in module id should be considered as a bug and not as a feature.
[~cwilliams] You worked on some of the
require()
behavior, right? Can you say that we have fixed this issue? Do we have correctly load module where the module id begins and does not begin with a '/'? All of the scoping works? Requiring modules with relative paths work correctly?Marking as closed/fixed as we implemented this behavior as well as node-compatible require in TIMOB-16078 in the 6.0.0 timeframe.