JavaScript, TypeScript and Python
The giz command also runs JavaScript, TypeScript and Python programs. They run on one VM (vm/): an interpreter and
a JIT that both languages share. You need no Node.js and no Python install.
Run a program
giz run main.ts # also .js, .mjs, .cjs and .py
giz main.py ARG... # the short formThe first run builds the VM and caches it, as it caches any program. VM flags, such as --no-jit, go before the
file. The flags are listed in the VM internals.
Build one executable
giz build main.ts -o appThe result is the VM with the files of your project: the folder of the nearest package.json at or above the script,
else the script's folder. The first start unpacks the project into the cache and runs the entry there, so require,
node_modules and file reads find the project as it was built.
JavaScript and TypeScript
- Modules resolve as in Node:
package.jsonmain,exportsandimports,node_modules,.tsfiles, JSON modules, CommonJS and ES modules. evalandnew Functionwork. A syntax error names the file and the line.- Node's own
lib/runs on the VM. It starts at the first built-inrequire, or at the first use of a Node global (process,Buffer,URL,fetch), so a plain script does not pay for it. - A
.tsfile runs with its types removed. Decorators follow TC39 2023.
Add an npm package to a project with its exact version. Installation scripts never run:
giz get . npm:semver@7import semver from "semver";
console.log(semver.satisfies("1.2.3", "^1.0.0"));Python
sys.pathis the script's folder, thenPYTHONPATH, then thesite-packagesof$VIRTUAL_ENVor of the nearest.venvabove the script, then the standard library of CPython 3.15 (fetched once into the cache).- Python source (your program, the standard library and site-packages) runs on the VM. The hot C modules (
sys,math,itertools,_json,_sre,_structand others) are native in the VM. - Any other C module, such as a wheel's
.soor pydantic-core, runs in CPython 3.15 through a bridge. The VM loads it at the first such import.
Speed
Each program runs as a whole process, best of 5. Ratio is the reference time divided by the VM time: above 1, the VM is faster.
| Program | Reference | Ratio |
|---|---|---|
| fib.js, loop.js, obj.js, prop.js, method.js | Bun 1.3.11 | 1.08 to 1.86 |
| fib.py, loop.py, nbody.py, attr.py, method.py | PyPy 7.3.20 | 1.10 to 1.90 |
| An empty program (start and exit) | Bun, PyPy | 2.06 (JS), 6.08 (Python) |
Each program and its number are in the VM internals.