ESM & npm Resolution
This document captures the resolution contract behind vaeljs-npm and vaeljs-remote in vjs (v0.0.0-alpha.0) and vjs-lite (0.0.0-alpha.1), explaining why VaelJS resolves npm: packages without node_modules, lifecycle scripts, or CommonJS.
Scope & Design Boundaries
Section titled “Scope & Design Boundaries”Three capabilities are kept strictly separate so enabling one does not silently pull in the others:
- ESM
npm:packages (vaeljs-npm): Resolution, verified CAS extraction, and execution of strict ESM package graphs. node:*compatibility (vaeljs-node-core): Separately opt-outable (--no-node-compat) Node.js compatibility modules (39 modules invjs/ 27 synchronous/pure-JS modules invjs-liteinv0.0.0-alpha.3, includingnode:fs,node:child_process,node:crypto,node:buffer,node:os,node:path,node:process,node:url, and more; see Node Compatibility Matrix).- Project
package.json&vael.jsonc: Local projects can consumepackage.jsondependenciesand#importsalongsidevael.jsoncimportsandworkspaces, without creating anode_modulestree.
Deliberate non-goals (fail closed):
- No CommonJS:
.cjs,.cts,require(),createRequire(), and"type": "commonjs".jsfiles are rejected rather than wrapped or auto-converted. - No lifecycle scripts or native addons:
preinstall,install,postinstall, andpreparescripts never run;.node,.dll,.so,.so.*,.dylib,.exe, and.wasmbinaries are excluded from CAS extraction. - No
node_modulesdirectory: Packages live exclusively in the verified content-addressed store.
Resolution Contract
Section titled “Resolution Contract”- Canonical scheme separation:
- Bare names (
"fs","lodash") belong tovael.jsoncimports,package.jsondependencies/#imports, or workspace packages — never tovael:*ornode:*built-ins. - Built-ins require canonical
vael:*ornode:*specifiers. npm:name@range/subpathandnpm:@scope/name@range/subpathresolve via exact versions, npm semver ranges, or dist-tags.
- Bare names (
- Peer-aware graph identity:
- Bare imports inside a package resolve strictly against that package’s declared dependency graph (never a global latest fallback).
- Module instances are keyed by graph-instance identity (including resolved peer bindings) and canonical module path so one package artifact bound to two different peers never shares mutable module state.
- Conditional
exports&#imports:- Active resolution conditions are
["import", "default"]in manifest key order (node,node-addons,require,browser, andtypesare not claimed). - Rejected
exportstargets never fall back tomainor arbitrary deep file paths.
- Active resolution conditions are
- Strict ESM classification:
.mjsis always ESM;.jsinside an npm package requires"type": "module"in its nearestpackage.json;.ts/.mtsuse erasable TypeScript stripping when permitted.
Reproducibility, CAS Cache & Security
Section titled “Reproducibility, CAS Cache & Security”Content-Addressed Store ($XDG_CACHE_HOME/vaeljs/packages)
Section titled “Content-Addressed Store ($XDG_CACHE_HOME/vaeljs/packages)”- On Linux, cached artifacts live under
$XDG_CACHE_HOME/vaeljs/packages(defaulting to$HOME/.cache/vaeljs/packages); Windows uses%USERPROFILE%\.cache\vaeljs\packages. - Tarballs are verified against
sha512SRI digests before atomic extraction into a private temporary directory (rejecting traversal, unsafe links, device files, and native addons). - Extracted files are stored read-only (
0444on Unix) keyed by SHA-256. Every read verifiesO_NOFOLLOW, exact byte length, and in-memory SHA-256 so tampering with extracted cache files is caught before execution even in--offlinemode.
Lockfile (vael.lock v1)
Section titled “Lockfile (vael.lock v1)”- Records requested specifiers (
"pkg@^1.0.0"), resolved package keys ("pkg@1.2.3"), versions,integritydigests, mandatorytreeSha256(fail-closed if missing on a pinned entry),tarballUrl, and dependency edges in canonical sorted JSON (max16 MiB). --frozen-lockfilefails on missing, stale, or mismatched entries without network mutation.--offlineforbids all network I/O and serves strictly fromvael.lockand the verified CAS cache.--no-npmdisablesnpm:andpackage.jsonresolution entirely.
Network & .npmrc Auth Hardening
Section titled “Network & .npmrc Auth Hardening”- Network fetches are off by default in both
vjsandvjs-liteand require--allow-remoteorVAELJS_ALLOW_REMOTE=1(overridable via--no-allow-remote). .npmrcdiscovery is bounded (256 KiB,O_NOFOLLOWon Unix) and HTTPS-only. Project-local.npmrcis restricted to non-secret registry routing (registry=,@scope:registry=) and rejects auth directives (_authToken,_auth,username,_password,always-auth,//host:) and${ENV_VAR}expansion (ProjectAuthNotAllowed); credentials and lazy${ENV_VAR}interpolation belong strictly in user-level~/.npmrc, where tokens are stored withZeroizeOnDrop, redacted as<redacted>, and stripped on cross-origin redirects.--allow-remoteenables network module loading whilevaeljs-remoteenforces SSRF protection (allow_private_ips: falseby default — blocking loopback, RFC 1918, link-local, metadata169.254.169.254, CGNAT, ULA, and IPv4-mapped/NAT64 ranges at URL and DNS resolution levels). Note that--allow-remoteis still not a host allowlist or OS sandbox: loaded modules retain host process capabilities.
Future Registry Evolution
Section titled “Future Registry Evolution”npm:, jsr:, and gh: support in vjs and vjs-lite establishes the CAS + integrity foundation. Future private and self-hosted registry support via Vaelhoard (vael:@, jsr:@, npm:, OCI, and binary release artifacts) is tracked on the Public Roadmap and remains gated on Vaelspire and Vaelguard.
