@selorax/compiler
v0.1.7
Published
SeloraX TSX compiler (sucrase + AST analyzer + bundler). Build-time only.
Readme
@selorax/compiler
Build-time TSX → CommonJS compiler + static security analyzer for the SeloraX Pages platform.
npm i @selorax/compiler0.1.0 · pre-1.0.
What it is
In SeloraX Pages, a tenant page can be a .tsx file. Before it's stored or rendered, it's compiled: transformed to runnable JS, scanned for what it's allowed to do, and (optionally) bundled with its component imports into one self-contained module. @selorax/compiler is that step — a pure, build-time-only function with no runtime dependencies on the rest of SeloraX.
It powers three call sites: the backend on save (POST /pages), the CLI's local dev render (@selorax/pages-cli's LocalProvider), and selorax-pages build (precompile). You normally get it transitively; install it directly only if you're building tooling on top.
Security boundary. The AST analyzer is what makes it safe to execute tenant-authored TSX. It allowlists imports, rejects dangerous constructs, and classifies each module (server vs. client). Treat its output as the contract: if
compile()returnsok: false, do not run the code.
Usage
const { compile, compileBundle } = require('@selorax/compiler');
// Single file
const res = compile({ source: tsxString, route: '/products/[slug]', isLayout: false });
if (!res.ok) throw new Error(JSON.stringify(res.errors));
// res → { ok: true, moduleKind: 'server' | 'client', compiled, schema, imports, contentHash }
// A page plus its relative component imports → one bundle
const bundle = compileBundle({
source: pageTsx,
route: 'routes/products/[slug]',
isLayout: false,
imports: [{ path: 'components/ProductCard', source: cardTsx }, /* … */],
});compile(...)— transform + analyze one module. Returns the compiled CJS, the extracted@settingsschema, the classified import buckets, themoduleKind, and acontentHash(sha256 of compiled+schema — handy as a cache key).compileBundle(...)— walks a page's relative-import graph (cycle-safe, any depth), analyzes every module, rejects tenant'use client'deps, and assembles one self-contained CJS bundle.
Notes
- Ships TypeScript source. The package is authored in
.tsand self-transpiles viasucrase/register/tsat require time — there's no build step to run. (sucrase+@babel/*are runtime deps for exactly this.) - CommonJS,
require()-only. Build-time use; do not bundle into client code. - Stateless and pure — safe to call concurrently.
Part of SeloraX Pages
@selorax/data · @selorax/runtime · @selorax/platform · @selorax/compiler · @selorax/pages-cli
