A CommonJS Runtime for GJS


Keywords
gjs, require, commonjs, npm, node, gtk, native
License
ISC
Install
npm install cgjs@0.1.32

Documentation

cgjs License: ISC Build Status

A CommonJS Runtime for GJS

Features

Differently from jsgtk, this project has the following goals and features:

  • 100% based on GJS. No wrapping, no runtime transpilation, pure ECMAScript 2015+ via SpiderMonkey 52+
  • Gtk camelCase methods are provided only on demand and if needed. You are free to require('gir').Gtk, which will add camelCase method, or just regular GJS imports.gi.Gtk, suggested to develop core modules too.
  • by default, the core brings in only most basic features to develop CommonJS modules for GJS:
    • a global reference to the shared global GJS object
    • globally available timers such setImmediate(fn, ...args), setInterval(fn, delay, ...args), setTimeout(fn, delay, ...args) with also their clearImmediate/Interval/Timeout(id) counter functions
    • a spec compliant require function with require.cache and a require.resolve implemented via the proper algorithm
  • all other core modules will be made available as soon as available
  • each core module is developed a part:
    • easier to maintain
    • easier to update
    • easier to track changes
    • easier to also contribute 🎉

Core Installation

You need both npm and gjs available on your system.

Once you have both, you can install cgjs either locally, and use it via npx cgjs, or globally.

# global install example
npm install -g cgjs

# see default options
cgjs --help

CommonJS Modules

By default, cgjs includes few core modules, and following you can check their current status:

Basic GJS info

You can install globally the cgjs-about utility and query it as described in the repository.

Together with grep it's a great way to have a quick overview of every namespace.

APIs