Skip to content
VaelJS Blog

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.

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.ts

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.

vael.jsonc
{
// 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:* and node:* cannot be remapped by imports — they always resolve to the runtime’s built-in modules.
  • Remote targets in imports (https:, gh:, jsr:) and online npm: packument/tarball fetches still require --allow-remote or VAELJS_ALLOW_REMOTE=1 at runtime.
  • Pass --config <path> to target an explicit manifest, or --no-config to 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:

vael.jsonc
{
"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.

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/*"],
}
packages/shared/vael.jsonc
{
"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:*:

Terminal window
# Emit the full vjs (V8, 75 modules) declaration tree into ./types
vjs types --out-dir ./types
# Or emit the vjs-lite (QuickJS, 54 modules) profile if targeting portable scripts
vjs types --profile lite --out-dir ./types
# Equivalent:
vjs-lite types --out-dir ./types

This 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"]
}

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.

Terminal window
# Default V8 profile over stdio
vjs lsp --stdio
# Target the vjs-lite (QuickJS) surface and disable node:* completions
vjs lsp --stdio --profile lite --no-node-compat
# Explicit workspace root or manifest path
vjs lsp --stdio --project /path/to/repo --config /path/to/repo/vael.jsonc

Example 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 authoring vjs-lite scripts)
  • 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).

  1. First fetch (network opt-in): Run with --allow-remote once to resolve packuments, write/update vael.lock (version 1), and populate the CAS cache:

    Terminal window
    vjs --allow-remote src/main.ts
  2. Reproducible CI & offline runs: Commit vael.lock to 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 cache
    vjs --offline --frozen-lockfile src/main.ts
  3. Private scoped registries via .npmrc & ~/.npmrc: VaelJS loads user-level ~/.npmrc and discovers project .npmrc upward from the entry directory (max 256 KiB, O_NOFOLLOW on Unix). Only https: registries are permitted:

    • Project .npmrc (non-secret routing only): Supports registry= 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}

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:

Terminal window
# Run all tests under tests/ in vjs
vjs test "tests/**/*.test.ts"
# Run portable tests in vjs-lite as well
vjs-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.