QuickJS-x is QuickJS with a few, additional features patched in:
-
Custom module loader implementing
QJSXPATH(likeNODE_PATH) resolution, to specify additional paths for imports. -
Node.js-style
index.jsresolution for all imports:... from "./module_dir"→... from "./module_dir/index.js" -
Colon-to-slash translation (useful for our Node.js shim):
... from "node:fs"→... from "node/fs" -
We add
import.meta.dirnameandimport.meta.filename. -
We also provide an additional binary
qjsx-node, making a small subset of the Node.js standard library available (e.g. parts ofnode:fs,node:child_process, seeqjsx-nodedirectory).
All original QuickJS features are preserved.
Building QuickJS-x, like QuickJS, should take less than a minute.
git clone --recurse-submodules https://github.com/rmst/quickjs-x.git
cd quickjs-x
make build # Builds ./bin/qjsx, ./bin/qjsx-node, and ./bin/qjsxcBasic JavaScript execution like QuickJS
./bin/qjsx script.jsModule resolution with QJSXPATH
# script.js can import all modules in ./mymodules and ./lib.
QJSXPATH=./my_modules:./lib ./bin/qjsx script.jsThis works like NODE_PATH in Node.js. QJSXPATH enables bare module imports (e.g., import foo from "foo") by specifying search directories.
With Node.js compatibility modules
./bin/qjsx-node script.jsscript.js can use a subset of node:fs, node:child_process, etc (see qjsx-node/node)
qjsxc can be used to compile JavaScript applications into standalone executables with embedded modules.
# Compile an application and embeddes all modules imported by main.js
QJSXPATH=./my_modules ./bin/qjsxc -o my-app main.js
# The resulting binary is a standalone executable
./my-app # (runs your application)Use the -D flag to embed modules that aren't directly imported but should be available to dynamically loaded scripts:
# Embed modules for dynamic loading
QJSXPATH=./libs ./bin/qjsxc -D utils -D config -o runtime bootstrap.js
# External scripts can now import these modules
./runtime external-script.js # Can use import { ... } from "utils"This is how qjsx-node is built - it compiles a minimal bootstrap with all node modules embedded using -D flags, creating a single native executable that can run any script with Node.js compatibility.
The following files are used to compile the qjsx binary:
qjsx.patchis applied toquickjs/qjs.cqjsxc.patchis applied toquickjs/qjsc.cquickjs-libc.patchis applied toquickjs/quickjs-libc.cqjsx-module-resolution.hcontains shared module resolution logic for QJSXPATH support, etc