Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9893] TiAPI: CommonJS 1.1 compliance

GitHub Issuen/a
TypeStory
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-06-11T15:53:48.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sn/a
ComponentsTiAPI
Labelscore, parity
ReporterStephen Tramer
AssigneeChristopher Williams
Created2012-07-05T16:47:25.000+0000
Updated2018-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/modules

non-MW platforms throw an exception when confronted with async syntax

-> require(["foo"], callbackFunction); There is also the possibility of:

Leading '/' not allowed in module names

Leading '/' always indicates a resource at the root of the project

This should be done for all platforms.

Comments

  1. Ivan Skugor 2012-07-10

    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.
  2. Chris Barber 2012-07-11

    On Mobile Web, require("/some/module") and require("some/module") are the same absolute path.
  3. Stephen Tramer 2012-07-11

    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.
  4. Ivan Skugor 2012-07-12

    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.
  5. Bryan Hughes 2012-07-12

    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.
  6. Chris Barber 2012-07-12

    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?
  7. Stephen Tramer 2012-07-12

    Bryan - Yes, it is an addition. In fact iOS doesn't support it because it had to be added in a recent PR.
  8. Ivan Skugor 2012-07-13

    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.
  9. Chris Barber 2016-08-24

    [~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?
  10. Christopher Williams 2018-06-11

    Marking as closed/fixed as we implemented this behavior as well as node-compatible require in TIMOB-16078 in the 6.0.0 timeframe.

JSON Source