CommonJS modules are second class citizens, at the moment even we favor JSMs if code needs to be shared. There are also other users who wish to use require (see Bug 1056396) in contexts like frame scripts etc..
before seeing this bug, i wrote up an explanation of my attempt to use our Loader (and thus require) in the child process in bug 1058698 comment 8, though that is somewhat different, and possibly out of scope for this bug, since it requires configuring the Loader with proper options so that it looks like module instances are part of the addon -- for debugging purposes, self stuff, etc..
Duplicate of this bug: 1056396
Attachment #8508385 - Flags: review?(evold) → review+
Assignee: nobody → rFobic
OS: Mac OS X → All
Hardware: x86 → All
Comment on attachment 8512234 [details] [review] override support + tests Nice!
Attachment #8512234 - Flags: review?(evold) → review+
Commit pushed to master at https://github.com/mozilla/addon-sdk https://github.com/mozilla/addon-sdk/commit/21fb4655e732fa6edc863eec7b216d527aeae000 Merge pull request #1687 from Gozala/shared-require-test@1070927 Bug 1070927 - Make shared require use rootURI it's loaded from.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
This possibility was never documented, and I think it should be unless this was meant as a purely internal feature.
It's news to me that you can pass in a full URL - and I don't think this is how people will normally use it (at least not with the built-in modules). It's also a bad idea, I doubt that the resource://gre/modules/commonjs URL is guaranteed to stay unchanged. I think that the examples should be require("sdk/base64") and require("resource://my-extension/main.js") - full URL only if you need to load your own CommonJS modules. Note that in the latter scenario one might be better off creating their own loader as explained on https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/_loader#Usage (should probably be linked).
Thanks Wladimir, that makes sense. I've updated the text. I don't want to refer to extensions here, because I think that in the medium/long term extensions will no longer get access to Cu.import, so encouraging people to acquire a new dependency on it now seems like a bad idea. I'm marking this dev-doc-complete, but please do let me know if you need anything else.
Looks good, thank you.
You need to log in before you can comment on or make changes to this bug.