Qt
  1. Qt
  2. QTBUG-22356

Investigate support for 3rd party JS libraries

    Details

      Description

      Research if and how we should support 3rd party javascript libraries from QML.

      JavaScript libraries may attempt to do things not allowed by the QML JS environment. For example:

      Modify native objects:

      Modify the global object:

      Many libraries seem to be looking for either a browser environment or a CommonJS-like environment:

      In some cases, existing libraries can be made to work with code like:

      "import.js"
      var window = {}
      Qt.include("persistence.js")
      

      Possible solutions:

      • Many libraries introspect their JS environment and tweak their code to cater for different environments. We could offer a standard way to identify the QML environment, allowing libraries to tweak themselves to our environment as well
      • We could consider introducing a new pragma, or allowing ".pragma library" imports to do special things (e.g. have their own (private?) editable global object)
      • A pragma that bootstraps some sort of compatibility layer (like Envjs)

      Other notes:

        Issue Links

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

          Michael Brasser (closed Nokia identity) (Inactive) created issue -
          Michael Brasser (closed Nokia identity) (Inactive) made changes -
          Field Original Value New Value
          Link This issue relates to QTBUG-23933 [ QTBUG-23933 ]
          Hide
          Charles Yin (closed Nokia identity) (Inactive) added a comment - - edited

          TO-DO list to support CommonJS

          • Global objects
            • console
            • process
            • Buffer
            • require(), require.resolve(),require.cache
            • __filename, __dirname
            • module
            • exports
            • timers: setTimeout(cb, ms), clearTimeout(t), setInterval(cb, ms),clearInterval(t)
          Show
          Charles Yin (closed Nokia identity) (Inactive) added a comment - - edited TO-DO list to support CommonJS Global objects console process Buffer require(), require.resolve(),require.cache __filename, __dirname module exports timers: setTimeout(cb, ms), clearTimeout(t), setInterval(cb, ms),clearInterval(t) Modules and package managerment http://nodejs.org/api/modules.html console console.log() console.info() console.warn() console.error() console.dir(obj) console.time(label) console.timeEnd(label) console.trace() console.assert() Buffer http://nodejs.org/api/buffer.html Timers (timeout Javascript functions) Process and childprocess http://nodejs.org/api/process.html http://nodejs.org/api/child_process.html Util http://nodejs.org/api/util.html Events http://nodejs.org/api/events.html Stream http://nodejs.org/api/stream.html Crypto http://nodejs.org/api/crypto.html File system http://nodejs.org/api/fs.html Path http://nodejs.org/api/path.html Network protocols: Net/UDP/HTTP/HTTPS/DNS/URL http://nodejs.org/api/net.html http://nodejs.org/api/dgram.html http://nodejs.org/api/http.html http://nodejs.org/api/https.html http://nodejs.org/api/url.html QueryString http://nodejs.org/api/querystring.html ReadLine http://nodejs.org/api/readline.html REPL ? http://nodejs.org/api/repl.html Script class and VM http://nodejs.org/api/vm.html Assert ? QtQuickTest ? http://nodejs.org/api/assert.html TTY? http://nodejs.org/api/tty.html ZLIB ? http://nodejs.org/api/zlib.html OS http://nodejs.org/api/os.html *Debugger ? http://nodejs.org/api/debugger.html Cluster ? http://nodejs.org/api/cluster.html
          Charles Yin (closed Nokia identity) (Inactive) made changes -
          Fix Version/s 5.1.0 [ 12121 ]
          Charles Yin (closed Nokia identity) (Inactive) made changes -
          Link This issue relates to QTBUG-25411 [ QTBUG-25411 ]
          Martin Jones (closed Nokia identity) (Inactive) made changes -
          Priority Not Evaluated [ 6 ] P2: Important [ 3 ]
          Michael Brasser (closed Nokia identity) (Inactive) made changes -
          Description Research if and how we should support 3rd party javascript libraries from QML.

          JavaScript libraries may attempt to do things not allowed by the QML JS environment. For example:

          Modify native objects:
          * http://sugarjs.com/
          * http://www.datejs.com/

          Modify the global object:
          * http://www.diveintojavascript.com/projects/javascript-sprintf
          * http://documentcloud.github.com/underscore/

          Many libraries seem to be looking for either a browser environment or a CommonJS-like environment:
          * https://github.com/willconant/flow-js (CommonJS "exports" or "window" for browser)
          * http://persistencejs.org/ (CommonJS "exports" or "window" for browser)
          * https://github.com/caolan/async (CommonJS "exports" or "this" for browser)
          * https://github.com/michael/data (CommonJS "exports" or "this" for browser)

          In some cases, existing libraries can be made to work with code like:
          {code:title="import.js"}
          var window = {}
          Qt.include("persistence.js")
          {code}

          Possible solutions:
          * Many libraries already tweak their code to cater for different environments. We could offer a standard way for libraries to be tweaked to our environment as well
          * We could consider introducing a new pragma, or allowing ".pragma library" imports to do special things (e.g. have their own (private?) editable global object)

          Other notes:
          * There seem to be a particularly large number of libraries tailored to node's JS environment: https://github.com/joyent/node/wiki/modules, though it isn't immediately clear how many would also be relevant to QML.
          Research if and how we should support 3rd party javascript libraries from QML.

          JavaScript libraries may attempt to do things not allowed by the QML JS environment. For example:

          Modify native objects:
          * http://sugarjs.com/
          * http://www.datejs.com/

          Modify the global object:
          * http://www.diveintojavascript.com/projects/javascript-sprintf
          * http://documentcloud.github.com/underscore/

          Many libraries seem to be looking for either a browser environment or a CommonJS-like environment:
          * https://github.com/willconant/flow-js (CommonJS "exports" or "window" for browser)
          * http://persistencejs.org/ (CommonJS "exports" or "window" for browser)
          * https://github.com/caolan/async (CommonJS "exports" or "this" for browser)
          * https://github.com/michael/data (CommonJS "exports" or "this" for browser)

          In some cases, existing libraries can be made to work with code like:
          {code:title="import.js"}
          var window = {}
          Qt.include("persistence.js")
          {code}

          Possible solutions:
          * Many libraries introspect their JS environment and tweak their code to cater for different environments. We could offer a standard way to identify the QML environment, allowing libraries to tweak themselves to our environment as well
          * We could consider introducing a new pragma, or allowing ".pragma library" imports to do special things (e.g. have their own (private?) editable global object)
          * A pragma that bootstraps some sort of compatibility layer (like Envjs)

          Other notes:
          * There seem to be a particularly large number of libraries tailored to node's JS environment: https://github.com/joyent/node/wiki/modules, though it isn't immediately clear how many would also be relevant to QML.
          Alan Alpert made changes -
          Assignee Martin Jones (closed Nokia identity) [ martjone ]
          Fix Version/s 5.1.0 [ 12121 ]
          Alex Blasche made changes -
          Workflow Qt Bug Tracking [ 281364 ] Qt Bug Tracking v2.0 [ 308686 ]
          Hide
          Dmitriy Kubyshkin added a comment -

          I'm working on a partial implementation that would allow to use npm packages inside QML.

          Progress can be tracked here:
          https://github.com/grassator/qml-commonjs

          Show
          Dmitriy Kubyshkin added a comment - I'm working on a partial implementation that would allow to use npm packages inside QML. Progress can be tracked here: https://github.com/grassator/qml-commonjs
          Hide
          Simon Hausmann added a comment -

          Finally, support for ES6 modules is something desirable for Qml to support out of the box.

          Show
          Simon Hausmann added a comment - Finally, support for ES6 modules is something desirable for Qml to support out of the box.
          Simon Hausmann made changes -
          Status Reported [ 10011 ] Open [ 1 ]
          Simon Hausmann made changes -
          Link This issue replaces QTBUG-40028 [ QTBUG-40028 ]
          Hide
          Michael Spencer added a comment -

          I'm working on a project to support ES6 and emulate a Node.js-like environment in QML. It works using Babel and an additional transpilation step to translate things like require into .import, emulate module.exports and global, etc. It integrates into QML just like regular JS does. It supports npm packages as long as they don't depend on any Node.js features not implemented yet.

          Website is here: ibeliever.github.io/quickly/
          GitHub project is here: https://github.com/quickly/quickly

          Show
          Michael Spencer added a comment - I'm working on a project to support ES6 and emulate a Node.js-like environment in QML. It works using Babel and an additional transpilation step to translate things like require into .import, emulate module.exports and global, etc. It integrates into QML just like regular JS does. It supports npm packages as long as they don't depend on any Node.js features not implemented yet. Website is here: ibeliever.github.io/quickly/ GitHub project is here: https://github.com/quickly/quickly
          Michael Brasser made changes -
          Link This issue is related to QTBUG-47735 [ QTBUG-47735 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Reported Reported Open Open
          1049d 7h 35m 1 Simon Hausmann 09/Sep/14 1:52 PM

            People

            • Assignee:
              Unassigned
              Reporter:
              Michael Brasser (closed Nokia identity) (Inactive)
            • Votes:
              14 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes