Closed
Bug 1161376
Opened 11 years ago
Closed 11 years ago
Add-on SDK environment/version detection
Categories
(Add-on SDK Graveyard :: General, enhancement, P1)
Add-on SDK Graveyard
General
Tracking
(Not tracked)
RESOLVED
WONTFIX
People
(Reporter: rodneyd.teal, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0
Build ID: 20150417180400
Steps to reproduce:
Checked for native support of Add-on SDK environment detection.
Actual results:
None.
Expected results:
toolkit/loader should expose a global variable or property on a global for this purpose.
Usage:
if (jetpack && jetpack.version === '1.17') {}
or similiar to AMD:
if (define && define.jetpack && define.jetpack.version) {}
or pherhaps:
if (require && require.jetpack) {}
Best attempt without the above: https://pastebin.mozilla.org/8832425
Comment 1•11 years ago
|
||
I really don't understand what you're asking for here, can you elaborate?
Flags: needinfo?(rodneyd.teal)
| Reporter | ||
Comment 2•11 years ago
|
||
hmm.. I thought it was clear but I'll state my case anyway. :)
Say, you have a module that supports multiple environments and you need to determine which environment your module is running inside during runtime, having a reliable way of doing so is needed.
See: https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property-
Particularly where it says: Existence of the define.amd property with an object value indicates conformance with this API.
In this case the existence of such a property would allow the fore-mentioned determination.
There are plenty of use cases and I'm surprised that this bug has laid dormant.
Does the toolkit/loader not have a boilerplate for supporting multiple environments? Of course.
It supports: CommonJS, RequireJS, and JSM environments.
Providing a reliable way to at least detect that the module is running in the Add-on SDK environment allows for environment specific features such as taking advantage of the API and providing solid native support where testing for features isn't reliable.
Also view the paste I linked for an example of the hard way around. Lets encourage modular development outside one's own personal library.
| Reporter | ||
Updated•11 years ago
|
Severity: normal → enhancement
Flags: needinfo?(rodneyd.teal)
Priority: -- → P1
Comment 3•11 years ago
|
||
There are many common boilerplates for detecting environment -- so a file can be loaded via CJS, AMD, script tag, node.js, and now jetpacks. We have umd[0] which detect the first three, but it's harder to detect a jetpack loader environemnt. We do this for jsm vs jetpack in some cases[1] but it should be easier and more explicit to cover more cases.
[0] https://github.com/umdjs/umd
[1] https://github.com/mozilla/gecko-dev/blob/634d37ccd0e66e6fb020ff03bc8f3b4bfebd45c9/toolkit/devtools/event-emitter.js#L9-L21
| Reporter | ||
Comment 4•11 years ago
|
||
What I'm implying is trivial to implement whether it is to be done so in toolkit/loader's pseudo Sandbox class: https://github.com/mozilla/addon-sdk/blob/master/lib/toolkit/loader.js#L229 as a default option or whilst bootstrapping an add-on because clearly [the context of which the loader is instantiated is known]. Adding a global symbol at that point(provided that the option to specify globals exists) would be to difficult to support?
quote: but it's harder to detect a jetpack loader environment
reply: not if your the one creating it. ;)
No, detection needs to actually be done here, rather a context dependent conditional statement to add an option to the set of options already being passed to the loader's constructor.
I reiterate that this is trivial in the case of exposing a global. Modifying the loader's require method(that is already being exposed to the sandboxed scope) to add a property is a little different. UMD aside, this hardly a problem that should be labeled as module loading compatibility but rather environment feature compatibility which requires feature testing unless theres a sensible means of determining whether an API is compliant or not. Web Browsers have a UA, The SDK should something similiar.
| Reporter | ||
Comment 5•11 years ago
|
||
Its already being done in a sense: https://github.com/mozilla/addon-sdk/blob/master/lib/toolkit/loader.js#L246
| Reporter | ||
Comment 6•11 years ago
|
||
There are two reasonable ways to introduce this:
1. Here: https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/system/globals.js#L22
Add this line: exports.jetpack = { /* maybe with version */ };
2. Here: https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/addon/runner.js#L67
Add this line: options.loader.globals.jetpack = { /* maybe with version */ };
The first way is the most sensible if sdk/system/globals isn't to be used by anything other than sdk/addon/runner.
I know of no way to determine the sdk version.
Flags: needinfo?(jsantell)
| Reporter | ||
Comment 7•11 years ago
|
||
Also of relevance: https://github.com/iliakan/detect-node#usage
I've reconsider the need for version info as there is only one version of the SDK made available within each version of Mozilla's gecko based apps. After detecting the environment you could rely on sdk/system for version info if necessary.
PR: https://github.com/mozilla/addon-sdk/pull/1961
Flags: needinfo?(jsantell)
Comment 8•11 years ago
|
||
(In reply to rodneyd.teal from comment #0)
> User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101
> Firefox/37.0
> Build ID: 20150417180400
>
> Steps to reproduce:
>
> Checked for native support of Add-on SDK environment detection.
>
>
> Actual results:
>
> None.
>
>
> Expected results:
>
> toolkit/loader should expose a global variable or property on a global for
> this purpose.
>
> Usage:
>
> if (jetpack && jetpack.version === '1.17') {}
>
> or similiar to AMD:
>
> if (define && define.jetpack && define.jetpack.version) {}
>
> or pherhaps:
>
> if (require && require.jetpack) {}
>
> Best attempt without the above: https://pastebin.mozilla.org/8832425
I've made a module which does most of this, adding the version would not be hard.
https://www.npmjs.com/package/engine-details
Comment 9•11 years ago
|
||
If there are any features to add I think we should do so at https://github.com/erikvold/engine-details/issues
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
Comment 10•11 years ago
|
||
Nice! And glad it does differentiate between "jetpack" and "firefox" as the loader is used throughout Firefox code.
You need to log in
before you can comment on or make changes to this bug.
Description
•