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

        There are no Sub-Tasks for this issue.
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

          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
          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.
          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

            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