Setting up a VaelJS Project
This guide walks through setting up a new VaelJS TypeScript project from scratch — covering vael.jsonc manifests, monorepo workspaces, .d.ts declaration emission, tsconfig.json, vjs lsp editor integration, vael.lock + .npmrc, and test directory layout.
1. Recommended Project Layout
Section titled “1. Recommended Project Layout”my-service/├── vael.jsonc # Required @scope/name, exports, imports, optional workspaces & db├── vael.lock # Generated canonical v1 lockfile for npm: / package.json deps├── .npmrc # Optional non-secret scoped HTTPS routing (registry= / @scope:registry= only)├── tsconfig.json # Editor / tsc type checking (noEmit + erasableSyntaxOnly)├── migrations/ # Optional SQL migrations managed by `vjs db migrate` / `vael:db/migrate`├── types/ # Generated via `vjs types --out-dir ./types` (gitignored or committed)│ ├── index.d.ts│ ├── globals.d.ts│ ├── vael/│ └── node/├── src/│ ├── main.ts│ └── lib/│ └── config.ts└── tests/ ├── config.test.ts └── http.test.ts2. Create vael.jsonc
Section titled “2. Create vael.jsonc”vjs and vjs-lite discover vael.jsonc upward from the entry file (up to 64 parent directories, max 1 MiB). The JSONC parser is intentionally strict: unknown keys, duplicate keys, "main", "workspace" (singular), "compilerOptions", and explicit null values fail closed rather than being silently ignored.
{ // Required: scoped package name (@scope/name) "name": "@acme/ops-cli", "version": "0.1.0", "description": "Operations CLI and automation toolkit.",
// Explicit ESM entrypoints (no "main" fallback) "exports": { ".": "./src/main.ts", },
// Specifier map applied to local file: modules "imports": { "@lib/": "./src/lib/", "zod": "npm:zod@^3.23.0", "@std/path": "jsr:@std/path@^1.0.0", },}Key manifest rules (see vael.jsonc & Workspaces for full bounds):
vael:*andnode:*cannot be remapped byimports— they always resolve to the runtime’s built-in modules.- Remote targets in
imports(https:,gh:,jsr:) and onlinenpm:packument/tarball fetches still require--allow-remoteorVAELJS_ALLOW_REMOTE=1at runtime. - Pass
--config <path>to target an explicit manifest, or--no-configto disable discovery.
Non-Secret Database & Migration Defaults (db)
Section titled “Non-Secret Database & Migration Defaults (db)”If your project uses vael:db/migrate and vjs db migrate, you can declare non-secret connection and migration settings under "db" in vael.jsonc. Plaintext "password", "url", and ://user:pass@ strings are rejected (SecretInManifest) — reference an environment variable name via "passwordEnv" instead:
{ "name": "@acme/ops-cli", "exports": { ".": "./src/main.ts" }, "db": { "driver": "postgres", "host": "db.internal.example", "port": 5432, "database": "ops", "user": "migrator", "passwordEnv": "VAELJS_DB_PASSWORD", "tlsMode": "verifyFull", "migrationsDir": "./migrations", "table": "_vael_migrations", "schema": "public", "module": "ops" }}See Databases with vael:db for the full vjs db migrate workflow and vael.jsonc Manifest Spec for field bounds.
Monorepo Workspaces
Section titled “Monorepo Workspaces”To link multiple packages in one repository, add "workspaces" to the root vael.jsonc and give each member directory its own vael.jsonc with "name" and "exports":
// Root vael.jsonc{ "name": "@acme/monorepo", "workspaces": ["packages/*"],}{ "name": "@acme/shared", "exports": { ".": "./src/mod.ts", "./format": "./src/format.ts", },}Any file inside a workspace member (or at the workspace root) can then import @acme/shared or @acme/shared/format directly without building or publishing.
3. Generate Declarations (vjs types) & Configure tsconfig.json
Section titled “3. Generate Declarations (vjs types) & Configure tsconfig.json”Both vjs and vjs-lite embed profile-accurate TypeScript declarations (vaeljs-dts). Materialize them into ./types so external tsc checks and editors have exact signatures for Vael, console, vael:*, and node:*:
# Emit the full vjs (V8, 75 modules) declaration tree into ./typesvjs types --out-dir ./types
# Or emit the vjs-lite (QuickJS, 54 modules) profile if targeting portable scriptsvjs types --profile lite --out-dir ./types# Equivalent:vjs-lite types --out-dir ./typesThis writes ./types/index.d.ts, ./types/globals.d.ts, ./types/vael/*.d.ts, and ./types/node/*.d.ts.
Configure tsconfig.json for erasable TypeScript (noEmit: true + erasableSyntaxOnly: true) and point types to [] so Node/browser ambient globals (window, document, Buffer, process) do not leak into type checking:
{ "compilerOptions": { "target": "ESNext", "module": "NodeNext", "moduleResolution": "NodeNext", "allowImportingTsExtensions": true, "noEmit": true, "erasableSyntaxOnly": true, "strict": true, "types": [] }, "include": ["src/**/*.ts", "tests/**/*.ts", "types/index.d.ts"]}4. Editor Support with vjs lsp
Section titled “4. Editor Support with vjs lsp”vjs lsp runs a pure-Rust Language Server Protocol server (vaeljs-lsp) over standard I/O. It shares vaeljs-manifest, vaeljs-module-policy, and vaeljs-dts with the runtime — so hover docs, specifier completion, and diagnostics match runtime resolution 1:1 without booting V8 or executing guest code. Syntax parsing runs in an isolated --parse-worker subprocess so malformed edits cannot crash the LSP session.
# Default V8 profile over stdiovjs lsp --stdio
# Target the vjs-lite (QuickJS) surface and disable node:* completionsvjs lsp --stdio --profile lite --no-node-compat
# Explicit workspace root or manifest pathvjs lsp --stdio --project /path/to/repo --config /path/to/repo/vael.jsoncExample Neovim (nvim-lspconfig / vim.lsp.config) Setup
Section titled “Example Neovim (nvim-lspconfig / vim.lsp.config) Setup”vim.lsp.config("vaeljs", { cmd = { "vjs", "lsp", "--stdio" }, filetypes = { "typescript", "javascript" }, root_markers = { "vael.jsonc", ".git" },})vim.lsp.enable("vaeljs")Example VS Code / Generic LSP Client Command
Section titled “Example VS Code / Generic LSP Client Command”Point your LSP client to:
- Command:
vjs - Args:
["lsp", "--stdio"](or add"--profile", "lite"when authoringvjs-litescripts) - Root patterns:
vael.jsonc
For exact flags (--stdio, --profile, --project, --config, --no-config, --no-node-compat), see Commands & Flags.
5. npm: Dependencies, vael.lock v1 & .npmrc
Section titled “5. npm: Dependencies, vael.lock v1 & .npmrc”VaelJS resolves npm: specifiers and package.json dependencies without creating node_modules or executing install scripts. Packages are verified and stored read-only in the global content-addressed cache ($XDG_CACHE_HOME/vaeljs/packages).
-
First fetch (network opt-in): Run with
--allow-remoteonce to resolve packuments, write/updatevael.lock(version1), and populate the CAS cache:Terminal window vjs --allow-remote src/main.ts -
Reproducible CI & offline runs: Commit
vael.lockto version control and enforce strict lockfile verification:Terminal window # Refuse unpinned packages or integrity mismatches (fetches missing CAS tarballs only if --allow-remote is also passed)vjs --frozen-lockfile src/main.ts# Refuse all network fetches; serve strictly from vael.lock + local CAS cachevjs --offline --frozen-lockfile src/main.ts -
Private scoped registries via
.npmrc&~/.npmrc: VaelJS loads user-level~/.npmrcand discovers project.npmrcupward from the entry directory (max256 KiB,O_NOFOLLOWon Unix). Onlyhttps:registries are permitted:- Project
.npmrc(non-secret routing only): Supportsregistry=and@scope:registry=only. Auth directives (_authToken,_auth,username,_password,always-auth,//host:keys) and${ENV_VAR}expansion are rejected (ProjectAuthNotAllowed) so untrusted repositories cannot exfiltrate host tokens. - User
~/.npmrc(credentials &${ENV_VAR}): Holds auth rules and lazy${ENV_VAR}token expansion for matching hosts.
# Project .npmrc (safe to commit — routing only, no auth or ${ENV_VAR})registry=https://registry.npmjs.org@acme:registry=https://npm.internal.example/# User ~/.npmrc (credentials and ${ENV_VAR} expansion belong here strictly)//npm.internal.example/:_authToken=${ACME_NPM_TOKEN} - Project
6. Running Tests (tests/)
Section titled “6. Running Tests (tests/)”vjs test and vjs-lite test require explicit file paths or shell-style globs — there is no implicit file discovery — and each matched file runs in a fresh isolated runtime:
# Run all tests under tests/ in vjsvjs test "tests/**/*.test.ts"
# Run portable tests in vjs-lite as wellvjs-lite test "tests/config.test.ts"Note that vjs test passes --offline / --frozen-lockfile / --config / --no-node-compat down to every test file’s runtime. See Testing with vael:test & vael:assert for patterns and assertions.
