0.3.0 • Published 6 years ago
gjs-require v0.3.0
gjs-require
A require like function for GJS
$ ./gjs-require test/index.js
gjs-require/test/index.js
gjs-require/test/ran/dom.js
random: 0.212101615295042
trueFeatures
- automatically provides
__dirnameand__filenamevariables (top level onyl) - automatically provides
moduleandexports(top level onyl) - simplifies imports through GJS resolving absolutes and relative paths (note: module should start with either
.or/) - usable to also require
GLib,Gio.Fileor any otherginamespace
Usage
You can either use gjs-require as executable, and pass along one or more files, or you can use it as gjs argument itself, and still pass along files to require, giving you the chance to configure gjs flags too.
Last, but not least, you can const {require} = imports.require assuming the gjs-require folder is part of import.searchPath.
Install
# via terminal
curl -LO https://webreflection.github.io/gjs-require
chmod a+x gjs-require
./gjs-require file.js
# via npm
npm i -g gjs-require
gjs-require file.js
# via npx
npx gjs-require file.js
# via gjs itself
const {require} = imports.require;
const module = require('./file.js');