Skip to content
VaelJS Blog

npm & Remote Loading

Both vjs (since v0.0.0-alpha.0) and vjs-lite (since v0.0.0-alpha.1) support npm: packages, project package.json dependencies, ancestor vael.jsonc bare import maps, and remote jsr:, gh:/github:, and https: imports—without creating node_modules or running lifecycle scripts. vjs-lite implements remote and registry transport synchronously with zero Tokio or hyper via blocking ureq + rustls (unless built with --no-default-features to omit remote and npm).

Import npm ESM packages directly with npm: specifiers or through the nearest package.json:

import { z } from "npm:zod@^3.23.0";
import { helper } from "@my-org/internal-esm"; // via package.json dependencies

Key architectural guarantees in vjs and vjs-lite (vaeljs-npm):

  • No node_modules directory: Packages are extracted into a shared content-addressed store (CAS) under $XDG_CACHE_HOME/vaeljs/packages (or $HOME/.cache/vaeljs/packages).
  • Content verification: Every tarball is checked against its sha512 SRI digest, extracted files are stored read-only (0444 on Unix) by SHA-256, and reads verify O_NOFOLLOW, file length, and SHA-256 in memory.
  • Zero install scripts or native addons: preinstall, install, postinstall, and prepare scripts are never executed. Native and binary artifacts (.node, .dll, .so, .so.*, .dylib, .exe, .wasm) are excluded from CAS.
  • Strict ESM only: exports and #imports resolve with active conditions ["import", "default"]. CommonJS (.cjs or "type": "commonjs" .js) is rejected.
  • Offline by default: Missing packages or uncached vael.lock entries require --allow-remote (or VAELJS_ALLOW_REMOTE=1) to fetch from the registry.
Flag Effect
--allow-remote Allow fetching missing npm packuments/tarballs from HTTPS registries.
--frozen-lockfile Refuse any resolution not pinned in vael.lock v1 or failing integrity checks.
--offline Forbid all network requests; serve strictly from vael.lock and the verified CAS cache.
--no-npm Disable npm: and package.json resolution completely for the run.

Both vjs and vjs-lite (since 0.0.0-alpha.1) load user-level ~/.npmrc alongside project-local .npmrc discovered upward from the referrer or project directory (max 256 KiB, opened with O_NOFOLLOW on Unix so symlinks fail closed):

# Project .npmrc — non-secret registry routing ONLY
registry=https://registry.npmjs.org
@internal:registry=https://npm.internal.example/
# User ~/.npmrc — credentials and ${ENV_VAR} expansion belong here strictly
//npm.internal.example/:_authToken=${INTERNAL_NPM_TOKEN}
  • Project auth isolation (ProjectAuthNotAllowed): Project-local .npmrc accepts registry= and @scope:registry= routing only. Auth directives (_authToken, _auth, username, _password, always-auth, //host: keys) and ${ENV_VAR} expansion are rejected in project .npmrc so untrusted repositories cannot exfiltrate host tokens; credentials and ${ENV_VAR} belong strictly in ~/.npmrc.
  • HTTPS-only: Only https: registries are accepted for registry= and @scope:registry=.
  • Lazy ${ENV_VAR} interpolation: In ~/.npmrc, tokens are read only from [A-Za-z_][A-Za-z0-9_]* environment variables when a request matches that rule (no shell evaluation).
  • Zero secret leakage: Credentials are stored with ZeroizeOnDrop, print as <redacted> in errors/debug output, and are stripped on cross-origin or out-of-scope redirects.

Remote module loading is disabled by default in both vjs and vjs-lite (since 0.0.0-alpha.1). Enable it explicitly per invocation with --allow-remote or VAELJS_ALLOW_REMOTE=1 (and override it off with --no-allow-remote):

Terminal window
vjs --allow-remote https://example.com/script.ts
vjs --allow-remote gh:owner/repo@v1.2.3/mod.ts
vjs-lite --allow-remote https://example.com/script.ts
vjs-lite --allow-remote jsr:@scope/pkg@^1.0.0
  • jsr:@scope/name[@constraint][/subpath]: Resolves via the public JSR registry (jsr.io), checking every fetched file’s length and SHA-256 against the version manifest before type-stripping and execution.
  • gh:owner/repo@ref/path / github:owner/repo@ref/path: Normalizes to a credential-free https://raw.githubusercontent.com/... URL (the legacy gh:owner/repo/path/@ref form is also accepted). ref must be a single path segment (tag, branch without /, or commit SHA).
  • https://...: Plain http: is always rejected. The HTTPS client sends no ambient credentials and reads no proxy environment variables.