zJs.assetType
A zJs asset is a JavaScript ES module: a `<name>.zJs/` folder whose `main.js` holds JavaScript source parsed and evaluated by the `zerojs` interpreter. The identity is `<name>` (the `.zJs` suffix strips).
zJs (asset type)
A zJs asset is a JavaScript ES module: a <name>.zJs/ folder whose main.js
holds JavaScript source parsed and evaluated by the zerojs interpreter. The
identity is <name> (the .zJs suffix strips).
Folder shape
main.js— the module body. Required.README.md— instance documentation. Required..metadata— tags sidecar ({"tags": []}). Required.
How to create one
asset.create("zJs", "greeter")
-- Creates /zero/source/greeter.zJs/ with a hello-world main.js.
asset.create("zJs", "greeter", { source = "export const x = 1" })
-- main.js is the given source verbatim.
Static diagnostics
Every write to main.js reparses the module and resolves its import
specifiers against the live asset index. asset.resolve("<name>", "zJs"):check()
returns { ok, diagnostics }: ok is true when the module parses and every
import resolves to another zJs module; each diagnostic carries a severity,
message, line, and col. No JavaScript runs during a check.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/asset-type/v1.zJscontainernoprimary aliasesmain.jsrequired filesmain.js, README.md, .metadatacheck(self: ?) →
Static diagnostics for THIS module's `main.js`: parse errors plus imports that do not resolve to a zJs module. Reads the cache `onChange` maintains, running the parse+resolve pipeline once on a cold reference.
| arg | type | description |
|---|---|---|
| self | ? |
examples
local r = asset.resolve("greeter", "zJs"):check(); if not r.ok then ... endrun(self: ?, opts: { env: { [string]: any }? }?, opts.env: ?) → any
Execute THIS module on a fresh JavaScript VM and marshal the result to Luau. A plain script (no imports or exports) runs as a script and returns its completion value; a module evaluates through the module graph and returns nil, since module evaluation has no completion value. `opts.env` seeds host values as JavaScript globals. Refuses when the module carries diagnostics, naming the first, and directs a script that leaves asynchronous work pending to `runAsync`.
| arg | type | description |
|---|---|---|
| self | ? | |
| opts | { env: { [string]: any }? }? | |
| opts.env | ? | host values injected as JavaScript globals for this run. |
examples
local sum = asset.resolve("calc", "zJs"):run({ env = { base = 10 } })runAsync(self: ?, opts: { env: { [string]: any }?, timeoutMs: number? }?, opts.env: ?, opts.timeoutMs: ?) → any
Execute THIS module's program on a fresh VM under the asynchronous runner, driving armed timers and pending promises to completion. Returns the engine run handle: poll `handle.done`, then read `handle.ok` / `handle.value` / `handle.error`, or call `handle:await()` from a yieldable context. `opts.timeoutMs` bounds a never-settling run. Refuses when the module carries diagnostics, naming the first.
| arg | type | description |
|---|---|---|
| self | ? | |
| opts | { env: { [string]: any }?, timeoutMs: number? }? | |
| opts.env | ? | host values injected as JavaScript globals for this run. |
| opts.timeoutMs | ? | milliseconds after which a never-settling run rejects. |
examples
local h = asset.resolve("job", "zJs"):runAsync({ timeoutMs = 1000 }); h:await()exports(self: ?, opts: { env: { [string]: any }? }?, opts.env: ?) → any
Evaluate THIS module as an ES module on a fresh VM and return its export namespace marshaled to a Luau table: each named export plus `default`. Cross-asset imports resolve through the live asset index, so a JS library built from several `.zJs` assets is consumed as one table. Refuses when the module carries diagnostics, naming the first; a cycle, an unresolved import, or a thrown module body surfaces as a Luau error.
| arg | type | description |
|---|---|---|
| self | ? | |
| opts | { env: { [string]: any }? }? | |
| opts.env | ? | host values injected as JavaScript globals for this evaluation. |
examples
local lib = asset.resolve("mathlib", "zJs"):exports(); print(lib.add(1, 2))onCreate(name: string, opts: CreateOpts, opts.source: ?) →
Generic-creation hook for `asset.create("zJs", name, opts)`. Pure: returns the instance's content file map for the caller to persist. `opts.source`, when given, becomes `main.js` verbatim; otherwise a hello-world module naming the instance is scaffolded from the template.
| arg | type | description |
|---|---|---|
| name | string | zJs module identity (the instance name). |
| opts | CreateOpts | |
| opts.source | ? | JavaScript module source for `main.js`. |
examples
asset.create("zJs", "greeter", { source = "export const x = 1" })onChange(ref: ?, change: ?) → void
Asset-type change callback: recompute this module's static diagnostics whenever its `main.js` is edited or the whole instance is seeded. Convergent: it reads the source and asset index and replaces the ref's cached pipeline result; it never writes to the VFS. Edits to sidecars (`README.md`, `.metadata`) leave the cache untouched.
| arg | type | description |
|---|---|---|
| ref | ? | |
| change | ? |
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.