Skip to content

feat: add vp dotenv and schema-validated env files with varlock - #3670

Draft
fengmk2 wants to merge 50 commits into
mainfrom
feat/dotenv-varlock
Draft

fengmk2 wants to merge 50 commits into
mainfrom
feat/dotenv-varlock

Conversation

@fengmk2

@fengmk2 fengmk2 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Adds .env files with a committed schema through varlock. A project commits .env.schema, which declares each variable, its type, and whether it is sensitive. Real values stay in git-ignored files such as .env.local.

The project depends on varlock itself. vite-plus lists it as an optional peer dependency (^1.25.0) and inlines @varlock/vite-integration 1.5.6, whose varlock imports resolve to the project's copy, so the CLI, the integration, and ENV from varlock/env share one varlock. vp dotenv init adds the dependency. Without it, every command that loads the schema fails and suggests vp add varlock@^1.25.0, and a version outside the range prints a warning.

The feature is experimental. Design: rfcs/varlock-integration.md. Guide: docs/guide/dotenv.md. Config: docs/config/dotenv.md.

Command Behavior
vp dotenv init [--no-interactive] Puts varlock in dependencies, runs varlock init, and adapts a new schema to Vite: removes the EXAMPLE_ITEM placeholder, sets importMetaEnv=none for the types and, in a client app, @defaultSensitive=inferFromPrefix('VITE_'), and lists the items that become sensitive. It writes the types with varlock codegen, to env.varlock.d.ts when a new schema would replace the project's own env.d.ts, and once the file exists, adds it to the tsconfig include and to fmt.ignorePatterns, keeping the style of each file. In a workspace package it prints the root-relative pattern for the root config instead. An existing schema stays unchanged: init runs varlock init without its prompts, sets up the types file, leaves a types file of the user and says what to change, and fails with the schema restored when varlock cannot parse it, because varlock init would write a new one over it. With a varlock.loadPath to another path, init fails, because varlock init writes .env.schema in the working directory
vp dotenv check [--env <name>] Validates the values without printing them, names the files it loaded, and warns when --env loaded no file of that environment
vp dotenv print [--env <name>] [--format env|json|shell] [--reveal] Prints the values, with sensitive ones masked unless you pass --reveal
vp dotenv explain [KEY] [--env <name>] Lists every item, or the sources of one
vp dotenv scan [--staged] [--include-ignored] [paths...] Finds plaintext copies of sensitive values
vp dotenv exec -- <command> Runs a command with the resolved environment
vp dotenv encrypt [--file <file>], lock, keychain [args...] Local encryption with a device key, and the macOS Keychain

When the config root has .env.schema, defineConfig adds the varlock integration and three plugins:

  • Validation: vp build and vp test exit with code 1 on an invalid env, vp preview warns and serves the existing build output, and vp dev shows varlock's error page. A config that also adds varlockVitePlugin() gets a warning, because the integration would run twice.
  • A client env filter that removes sensitive VITE_* keys from import.meta.env and names them in a warning.
  • A scan of the client build output that fails the build on a sensitive value (dotenv.scanBuildOutput).

dotenv.schema turns loading off or requires a schema, and dotenv.ssrInjectMode passes the integration's option for built server code. A project without a schema gets no new plugins.

The Vite mode does not select the varlock environment in this PR: vp build loads .env.production only when the variable that @currentEnv reads is production, as in APP_ENV=production vp build with @currentEnv=$APP_ENV. vp dev, vp build, vp preview, and vp test warn when the mode has env files that varlock does not load, and name the variable to set. Passing the mode to varlock as the --env fallback, as its Next.js integration does, is a follow-up (details).

vp migrate (vp migrate --full on a Vite+ project) removes varlockVitePlugin() and the @varlock/vite-integration dependency. A call whose only option is a string ssrInjectMode moves to dotenv.ssrInjectMode. A call with other options stays, with a warning, and so does the dependency. varlock and .env.schema stay, with a warning when the varlock range allows versions that this Vite+ does not support. vp create adds !.env.schema to .gitignore.

Limits:

  • One vp process loads one schema. A second schema in one vp test run fails.
  • A root given only on the command line (vp dev ./app) is not checked for a schema.
  • A vp run task gets the values only through vp dotenv exec --.
  • vp pack does not load the schema.
  • vp dotenv exec redacts every occurrence of a sensitive value in the output, so a common value such as the password postgres also masks that word elsewhere.
  • pnpm 12 asks to approve varlock's agent skill ("Agent skills awaiting approval: varlock"), as for any direct varlock dependency.

@socket-security

socket-security Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​varlock/​vite-integration@​1.5.6991007996100
Addednpm/​varlock@​1.25.0891009796100

View full report

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Staging deployment successful!

Preview: https://viteplus-staging.void.app/
Commit: 1e65e42

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Cloudflare builds and deploys previews for this pull request. Learn more about Cloudflare previews.

Worker Status Deployment Commit
viteplus-dev Deployed Preview 1e65e42

Updated: Dec 5, 2026, 18:14 UTC | Dashboard

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

CLI artifact sizes (1e65e42)

Final release artifacts built by the canonical build-upstream and build-windows-cli actions.
The dist rows use the Linux build. The core total excludes .node files to match the release artifact.

Artifact Format Base PR Change
packages/cli/dist Directory total 2.52 MiB 2.79 MiB +274.89 KiB (+10.64%)
packages/core/dist Directory total 4.29 MiB 4.29 MiB 0 B (0.00%)
Combined package dist Directory total 6.81 MiB 7.08 MiB +274.89 KiB (+3.94%)
vp (Linux x64) Binary 9.31 MiB 9.31 MiB 0 B (0.00%)
vp (Linux x64) gzip -9 4.26 MiB 4.26 MiB -201 B (-0.00%)
NAPI (Linux x64) Binary 37.99 MiB 38.05 MiB +60.00 KiB (+0.15%)
NAPI (Linux x64) gzip -9 15.33 MiB 15.34 MiB +13.94 KiB (+0.09%)
vp (macOS ARM64) Binary 6.12 MiB 6.12 MiB 0 B (0.00%)
vp (macOS ARM64) gzip -9 3.65 MiB 3.65 MiB +266 B (+0.01%)
NAPI (macOS ARM64) Binary 44.39 MiB 44.44 MiB +48.42 KiB (+0.11%)
NAPI (macOS ARM64) gzip -9 19.42 MiB 19.44 MiB +19.77 KiB (+0.10%)
vp (Windows x64) Binary 7.27 MiB 7.27 MiB +512 B (+0.01%)
vp (Windows x64) gzip -9 3.33 MiB 3.33 MiB +436 B (+0.01%)
NAPI (Windows x64) Binary 33.88 MiB 33.93 MiB +51.50 KiB (+0.15%)
NAPI (Windows x64) gzip -9 14.04 MiB 14.05 MiB +10.63 KiB (+0.07%)
Trampoline (Windows x64) Binary 13.50 KiB 13.50 KiB 0 B (0.00%)
Trampoline (Windows x64) gzip -9 7.09 KiB 7.09 KiB 0 B (0.00%)
Installer (Windows x64) Binary 4.70 MiB 4.70 MiB 0 B (0.00%)
Installer (Windows x64) gzip -9 2.25 MiB 2.25 MiB 0 B (0.00%)

@fengmk2 fengmk2 added the preview-build Publish this PR's commits to the registry bridge as preview builds label Dec 3, 2026
Comment thread rfcs/varlock-integration.md Resolved
Comment thread docs/guide/dotenv.md Resolved
Comment thread docs/guide/dotenv.md

1. `.env.schema`: the committed schema and default values
2. `.env`: loaded, but prefer the files below
3. `.env.local`: your machine-only values, git-ignored

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a vp tool reads .env.local and gets cached, the content of .env.local will be fingerprinted even though it's git-gignored. Do we need to do anything about this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be excluded, just make the cache judgment based only on the whitelist of environment variables configured by the user.

@fengmk2
fengmk2 force-pushed the feat/dotenv-varlock branch from ae214b9 to 8293bde Compare December 3, 2026 10:55
@fengmk2

fengmk2 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member Author

How .env.schema works with Vite's env and mode features (https://vite.dev/guide/env-and-mode), updated for the direct varlock dependency (3478f61). An earlier version of this comment described viteMode(), which this PR no longer has: see the design update.

Vite feature With a .env.schema
Built-in constants (import.meta.env.MODE, DEV, PROD, SSR, BASE_URL) Unchanged. The Vite+ filter removes only keys that varlock resolves and treats as sensitive.
VITE_* variables on import.meta.env Still work. Vite reads the values that varlock resolved, because the process environment wins in loadEnv. varlock treats a variable that an env file sets without a declaration in the schema as sensitive, so Vite+ removes such a VITE_* key from import.meta.env and prints a warning that asks for a declaration.
.env, .env.local varlock loads them, after .env.schema.
.env.[mode], .env.[mode].local varlock loads .env.[env] files, where [env] is the value of the @currentEnv variable. It does not read the Vite mode. Vite still reads .env.[mode], but the values that varlock resolves override it, and varlock does not validate it. See Modes below.
--mode Sets the Vite mode only. Vite+ prints a warning when the mode has env files that varlock does not load.
envPrefix / public vs. secret In a project with a client app, vp dotenv init writes @defaultSensitive=inferFromPrefix('VITE_'), so only VITE_* variables are public by default, as in Vite. @public marks an exception.
loadEnv() in vite.config.ts Still works, but it reads the files without the schema: no validation, no type conversion, no @currentEnv. ENV from varlock/env works in the config after import 'varlock/auto-load'.
TypeScript for import.meta.env Unchanged. vp dotenv init adds importMetaEnv=none to @generateTsTypes, so vite/client keeps typing import.meta.env, and the generated file types ENV from varlock/env.
envDir Not supported while a schema is active. varlock.loadPath in package.json replaces it.

Modes. A schema without @currentEnv, which is what vp dotenv init writes, loads no .env.[env] file in vp dev, vp build, vp preview, or vp test. To load the files of one environment, name a variable in the schema and set it for each run:

# @currentEnv=$APP_ENV
# ---
# @public @type=enum(development, staging, production, test)
APP_ENV=development
APP_ENV=production vp build
APP_ENV=test vp test

vp dev, vp build, vp preview, and vp test warn when the Vite mode has env files that varlock does not load. Without @currentEnv, the trigger is a .env.[mode] or .env.[mode].local file. With it, the trigger is a variable value other than the mode while an env file of either one exists. Setting the variable in the environment for the run turns the warning off. For the schema above and a .env.production file, vp build prints:

varlock loads .env.development for Vite mode "production", because APP_ENV is "development". To load .env.production, run `APP_ENV=production vp build`.

In CI, APP_ENV=production vp dotenv check checks the values that APP_ENV=production vp build uses. For a schema without @currentEnv, vp dotenv check --env production loads .env.production. With @currentEnv, --env fails and names the variable to set.

The follow-up passes the Vite mode to varlock as the default environment, as varlock's Next.js integration does. vp build would then load .env.production and vp test .env.test without @currentEnv, and a schema with @currentEnv would keep full control.

ENV in vite.config.ts. Import varlock/auto-load first:

import 'varlock/auto-load';
import { ENV } from 'varlock/env';
import { defineConfig } from 'vite-plus';

export default defineConfig({
  server: { port: ENV.API_PORT },
});

varlock/auto-load loads the schema from the directory where vp runs, and the varlock integration that Vite+ adds reuses that load when the schema is in the same directory. On an invalid env, varlock/auto-load prints the errors and ends the process, so vp dev cannot show them in the browser. Without the import, only application code can read ENV.

Guide sections: Vite modes, Using ENV in vite.config.ts, Sensitive values.

@fengmk2 fengmk2 added test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: create-e2e Run `vp create` e2e tests preview-build Publish this PR's commits to the registry bridge as preview builds and removed preview-build Publish this PR's commits to the registry bridge as preview builds labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Preview binary sizes (1e65e42)

Compared with the latest stable release, v1.9.0. Preview build.
Each row measures one binary. Negative changes mean a smaller preview binary.

Binary Latest release Preview Change
vp (macOS ARM64) 6.11 MiB 6.12 MiB +16.27 KiB (+0.26%)
NAPI (macOS ARM64) 44.35 MiB 44.39 MiB +48.45 KiB (+0.11%)
vp (macOS x64) 7.71 MiB 7.73 MiB +20.20 KiB (+0.26%)
NAPI (macOS x64) 49.94 MiB 50.02 MiB +80.10 KiB (+0.16%)
vp (Linux ARM64 GNU) 7.72 MiB 7.74 MiB +23.98 KiB (+0.30%)
NAPI (Linux ARM64 GNU) 33.66 MiB 33.71 MiB +56.00 KiB (+0.16%)
vp (Linux ARM64 musl) 7.80 MiB 7.83 MiB +25.51 KiB (+0.32%)
NAPI (Linux ARM64 musl) 32.87 MiB 32.93 MiB +58.50 KiB (+0.17%)
vp (Linux x64 GNU) 9.28 MiB 9.31 MiB +27.98 KiB (+0.29%)
NAPI (Linux x64 GNU) 37.89 MiB 37.97 MiB +80.00 KiB (+0.21%)
vp (Linux x64 musl) 9.35 MiB 9.38 MiB +30.51 KiB (+0.32%)
NAPI (Linux x64 musl) 37.08 MiB 37.16 MiB +76.63 KiB (+0.20%)
vp (Windows x64) 7.25 MiB 7.27 MiB +22.00 KiB (+0.30%)
NAPI (Windows x64) 33.49 MiB 33.57 MiB +76.00 KiB (+0.22%)
Trampoline (Windows x64) 13.00 KiB 13.00 KiB 0 B (0.00%)
Installer (Windows x64) 4.70 MiB 4.71 MiB +9.00 KiB (+0.19%)
vp (Windows ARM64) 6.45 MiB 6.47 MiB +22.50 KiB (+0.34%)
NAPI (Windows ARM64) 29.50 MiB 29.55 MiB +55.00 KiB (+0.18%)
Trampoline (Windows ARM64) 13.00 KiB 13.00 KiB 0 B (0.00%)
Installer (Windows ARM64) 3.87 MiB 3.88 MiB +8.00 KiB (+0.20%)
gzip -9 sizes
Binary Latest release Preview Change
vp (macOS ARM64) 3.63 MiB 3.65 MiB +13.75 KiB (+0.37%)
NAPI (macOS ARM64) 19.40 MiB 19.43 MiB +31.87 KiB (+0.16%)
vp (macOS x64) 3.82 MiB 3.84 MiB +13.96 KiB (+0.36%)
NAPI (macOS x64) 20.75 MiB 20.78 MiB +28.83 KiB (+0.14%)
vp (Linux ARM64 GNU) 4.18 MiB 4.19 MiB +12.17 KiB (+0.28%)
NAPI (Linux ARM64 GNU) 14.52 MiB 14.54 MiB +23.00 KiB (+0.15%)
vp (Linux ARM64 musl) 4.21 MiB 4.22 MiB +16.17 KiB (+0.38%)
NAPI (Linux ARM64 musl) 14.22 MiB 14.25 MiB +26.59 KiB (+0.18%)
vp (Linux x64 GNU) 4.24 MiB 4.26 MiB +15.25 KiB (+0.35%)
NAPI (Linux x64 GNU) 15.27 MiB 15.30 MiB +22.68 KiB (+0.15%)
vp (Linux x64 musl) 4.27 MiB 4.29 MiB +16.21 KiB (+0.37%)
NAPI (Linux x64 musl) 14.95 MiB 14.98 MiB +26.22 KiB (+0.17%)
vp (Windows x64) 3.32 MiB 3.33 MiB +11.61 KiB (+0.34%)
NAPI (Windows x64) 13.88 MiB 13.91 MiB +24.07 KiB (+0.17%)
Trampoline (Windows x64) 7.14 KiB 7.14 KiB -1 B (-0.01%)
Installer (Windows x64) 2.25 MiB 2.25 MiB +4.73 KiB (+0.21%)
vp (Windows ARM64) 3.18 MiB 3.19 MiB +14.10 KiB (+0.43%)
NAPI (Windows ARM64) 13.15 MiB 13.18 MiB +25.46 KiB (+0.19%)
Trampoline (Windows ARM64) 6.93 KiB 6.92 KiB -1 B (-0.01%)
Installer (Windows ARM64) 2.15 MiB 2.15 MiB +4.62 KiB (+0.21%)

Raw sizes are uncompressed file sizes. gzip sizes recompress each binary at level 9; they are not package or download archive sizes.
The baseline uses published release files, including NAPI packages from npm at the same version. Build versions and toolchains can affect the difference.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Registry bridge build (1e65e42)

This commit build is published to the registry bridge, which serves these as ordinary npm versions (every other package proxies to npmjs):

Package Version
vite-plus 0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb
@voidzero-dev/vite-plus-core 0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb
create-vite-plus 0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb

Install the Vite+ CLI built from this commit, then migrate a project:

# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/voidzero-dev/vite-plus/1e65e4269a7cea61f0058d0674d64f3b6f5de0fb/packages/cli/install.sh | VP_PR_VERSION=3670 VP_LEGACY_INSTALLER_URL=https://raw.githubusercontent.com/voidzero-dev/vite-plus/1e65e4269a7cea61f0058d0674d64f3b6f5de0fb/packages/cli/install-legacy.sh bash
# Windows (PowerShell)
$env:VP_PR_VERSION="3670"; $env:VP_LEGACY_INSTALLER_URL="https://raw.githubusercontent.com/voidzero-dev/vite-plus/1e65e4269a7cea61f0058d0674d64f3b6f5de0fb/packages/cli/install-legacy.ps1"; irm https://raw.githubusercontent.com/voidzero-dev/vite-plus/1e65e4269a7cea61f0058d0674d64f3b6f5de0fb/packages/cli/install.ps1 | iex

Or install with Homebrew (macOS / glibc Linux):

These commands use the formula and binary from this published commit. Replace brew install with brew reinstall if the tap package is already installed.
If Homebrew Core’s vite-plus is installed, run brew uninstall vite-plus first. This keeps your user data; do not run vp implode to switch installations.

(
  set -eu
  export HOMEBREW_NO_AUTO_UPDATE=1
  export HOMEBREW_VP_PR_VERSION=1e65e4269a7cea61f0058d0674d64f3b6f5de0fb
  brew tap voidzero-dev/vite-plus https://github.com/voidzero-dev/vite-plus
  preview_tap="$(brew --repository voidzero-dev/vite-plus)"
  git -C "$preview_tap" fetch --depth=1 https://github.com/voidzero-dev/vite-plus.git "$HOMEBREW_VP_PR_VERSION"
  git -C "$preview_tap" switch --detach "$HOMEBREW_VP_PR_VERSION"
  brew install voidzero-dev/vite-plus/vp
  brew test voidzero-dev/vite-plus/vp
  "$(brew --prefix)/bin/vp"
)

The tap stays at the tested commit. Return it to main after testing:

git -C "$(brew --repository voidzero-dev/vite-plus)" switch main

Or download the standalone Windows installer built from this commit:

Architecture Installer
x64 vp-setup-x86_64-pc-windows-msvc.exe
Arm64 vp-setup-aarch64-pc-windows-msvc.exe

GitHub requires you to sign in and downloads each installer as a ZIP artifact. Extract vp-setup.exe, then run it against this preview build:

.\vp-setup.exe --version "0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb" --registry "https://registry-bridge.viteplus.dev/"

After installing, upgrade the current project's vite-plus to this test build with:

vp migrate

Or create a new project from this commit without installing the CLI:

export npm_config_registry=https://registry-bridge.viteplus.dev/ pnpm_config_registry=https://registry-bridge.viteplus.dev/
pnpm create vite-plus@0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb # or: npm create vite-plus@0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb
$env:npm_config_registry="https://registry-bridge.viteplus.dev/"; $env:pnpm_config_registry="https://registry-bridge.viteplus.dev/"
pnpm create vite-plus@0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb # or: npm create vite-plus@0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb

pnpm 11+ reads pnpm_config_registry, npm and older pnpm read npm_config_registry. The new project pins this build, so keep the registry set for later installs, or configure it as below.

Or point your package manager at the bridge registry https://registry-bridge.viteplus.dev/:

Package manager Registry config
npm / pnpm / Bun .npmrc: registry=https://registry-bridge.viteplus.dev/
Yarn (v2+) .yarnrc.yml: npmRegistryServer: "https://registry-bridge.viteplus.dev/"

Then pin the build (vite aliases to vite-plus-core; pnpm can use a catalog, npm an overrides entry):

{
  "devDependencies": {
    "vite-plus": "0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb",
    "vite": "npm:@voidzero-dev/vite-plus-core@0.0.0-commit.1e65e4269a7cea61f0058d0674d64f3b6f5de0fb"
  }
}

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🐳 Docker preview image

Built from this PR's registry bridge build:

Image Compressed size
ghcr.io/voidzero-dev/vite-plus:pr-3670 232MB
# remove any stale local copy from a previous run, then pull fresh
docker rmi ghcr.io/voidzero-dev/vite-plus:pr-3670 2>/dev/null; docker pull ghcr.io/voidzero-dev/vite-plus:pr-3670

Quick check:

docker run --rm ghcr.io/voidzero-dev/vite-plus:pr-3670 vp --version

See docs/guide/docker.md for usage.

@fengmk2
fengmk2 force-pushed the feat/dotenv-varlock branch from 6b4945c to cc78061 Compare December 4, 2026 04:53
@fengmk2 fengmk2 added preview-build Publish this PR's commits to the registry bridge as preview builds and removed preview-build Publish this PR's commits to the registry bridge as preview builds labels Dec 4, 2026
@fengmk2 fengmk2 self-assigned this Dec 5, 2026
@fengmk2
fengmk2 force-pushed the feat/dotenv-varlock branch from 4ae3656 to eafdf1f Compare December 5, 2026 03:33

fengmk2 commented Dec 5, 2026 •

Copy link
Copy Markdown
Member Author

Design update: the Vite mode no longer selects the varlock environment in this PR. This moves to a follow-up.

This PR is switching to a direct varlock dependency. A project that uses .env.schema depends on varlock itself, varlock becomes an optional peer dependency of vite-plus, and the schema stays plain varlock with @generateTsTypes. So the schema no longer loads @plugin(vite-plus), and with it go:

  • viteMode();
  • the APP_ENV=fallback(viteMode(), development) item that vp dotenv init writes;
  • VP_VITE_MODE, which the local CLI resolver sets.

The plugin also caused a production problem:

  • A server started with varlock run needs vite-plus installed to load the schema.
  • viteMode() returns nothing there, so APP_ENV falls back to development.

What this PR does instead:

  • vp dotenv init writes no @currentEnv or APP_ENV. A schema without @currentEnv loads .env, .env.local and the schema, and no .env.[mode] file.
  • vp dev, vp build and vp test print a warning when the Vite mode has a .env.[mode] file that varlock does not load. The warning names the file and how to select it, for example @currentEnv=$APP_ENV in the schema, or APP_ENV=production vp build.
  • vp dotenv check|print|explain --env <name> keeps varlock's --env, which selects .env.[name] when the schema has no @currentEnv. It now fails when the schema sets @currentEnv, because varlock would ignore the flag and check the default environment. The --mode option is removed: until the follow-up, vp build --mode staging does not select .env.staging, so a --mode here would imply a match that does not exist.

Follow-up, not in this PR: varlock's Next.js integration already passes the framework environment (next dev / next build) to varlock as the --env fallback, which varlock uses when the schema has no @currentEnv. If @varlock/vite-integration passed Vite's mode the same way:

  • vp build would load .env.production and vp test would load .env.test, as in plain Vite.
  • A schema with @currentEnv would keep full control.
  • Vite+ would need no mode code and the schema no extra items.

We will take this upstream after this PR lands. Until then, the Vite mode does not select the varlock environment.

fengmk2 and others added 27 commits December 5, 2026 18:13
…ntal

varlock encrypts secrets with a key stored on the device (Secure Enclave,
TPM, or a key file) as `varlock("local:...")`, and every command that
loads the schema already decrypts them. Projects without a direct
`varlock` dependency had no command to create those values, though.

`vp dotenv encrypt` runs `varlock encrypt` with the terminal attached: it
reads a value from stdin or a prompt, or encrypts the sensitive plaintext
values of a file with `--file`. `vp dotenv lock` runs `varlock lock`,
which ends the biometric session. Neither needs a schema, except
`encrypt --file`.

The guide gets a local encryption section: which commands decrypt, where
varlock keeps the key, that only the encrypting device can decrypt, and
that `varlock(prompt)` asks only through `vp dotenv exec`. The guide, the
`dotenv` config reference, the varlock migration rules, and the README
command lists now say that `vp dotenv` and the `.env.schema` support are
experimental.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`keychain()` already reads secrets from the macOS Keychain in every
command that loads the schema, but projects without a direct `varlock`
dependency had no command to store or manage those items.

`vp dotenv keychain` passes every argument, `--help` included, to
`varlock keychain` (`set`, `import`, `fix-access`, or `list`) with the
terminal attached. Vite+ does not declare the subcommands and options
again, so it does not have to follow their changes. varlock reports the
platform error outside macOS, and `keychain import` checks for its schema
itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On cnpmcore, a server with about 80 optional variables and none set,
`vp dotenv check` printed `Found no errors in 0 config items`, because it
counted only the values in `load --format json`. It now reads the full
graph (`json-full --agent`, so sensitive values stay redacted) and prints
both numbers: `Found no errors in 80 config items (0 have a value)`.

`vp dotenv init` also assumed a Vite app. `inferFromPrefix('VITE_')`
made every variable of a server sensitive, and the `viteMode()` item had
no Vite command to follow. init now reads the package.json scripts and
`index.html`: only a project that serves or builds a client app with Vite
gets the prefix rule, and only one whose scripts run Vite or Vitest gets
the `APP_ENV` item. A server keeps `@defaultSensitive=false`.

The guide also notes that output redaction in `vp dotenv exec` masks every
occurrence of a sensitive value, so a short value such as `postgres`
masks the same word in unrelated output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
varlock reads the header as the comment blocks before the first item. A
blank line, a divider, or the end of the file ends a block. `varlock init`
writes no divider when `.env.example` starts with a comment block, so
`vp dotenv init` and `vp migrate` left such a schema unchanged. A section
divider below the items also counted as the end of the header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`vp dotenv keychain` added the `keychainArgs` field, which the parser
returns for every subcommand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nal peer

A project with .env.schema now depends on varlock itself. vite-plus
declares varlock as an optional peer (^1.25.0, the peer range of
@varlock/vite-integration) and inlines the integration, whose varlock
imports resolve to the project's copy.

This removes what a vite-plus-only varlock needed:
- the PATH change for the integration's CLI lookup, the dotenv-resolve
  plugin, and noExternal for SSR imports
- the vite-plus/dotenv export and its config-time loader
- the vite-plus varlock plugin (@plugin(vite-plus),
  @generateVitePlusTypes, viteMode()) and VP_VITE_MODE
- varlock in vp --version, vp toolchain, and vite-plus/versions

vp dotenv init adds varlock with `vp add` before varlock init runs, then
adds importMetaEnv=none to a new schema and, in a client app, makes only
VITE_* public by default. A missing varlock fails with the command that
adds it, and a version outside the peer range prints a warning.

The Vite mode no longer selects the varlock environment; vp dev, build,
and test warn when the mode has env files that varlock does not load.
Following the mode is a follow-up. vp dotenv drops --mode, keeps --env
for check, print, and explain, and fails when @currentEnv would ignore
it. dotenv.ssrInjectMode passes the integration's option.

vp migrate removes varlockVitePlugin() and the integration dependency,
keeps varlock and .env.schema, and adds varlock when the project had it
only as the integration's peer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
varlock init checks only `dependencies.varlock` in package.json, and
otherwise runs its own `<package manager> add varlock` without a range.
vp dotenv init added varlock only when it could not resolve it, so a
varlock in devDependencies, or one that only the workspace root has, let
varlock init add it again at the latest version.

vp dotenv init now adds varlock with `vp add` when package.json does not
list it, and moves it from devDependencies or optionalDependencies to
dependencies with its range, then runs `vp install`. bun and Yarn keep an
existing dev dependency in place on `add`, so the move edits package.json.
Built server code imports varlock at run time, so dependencies is also the
right field for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…m issues

The varlock migration and the .gitignore fix ship in Phase 1. The RFC
listed them under Phase 2, next to the schema scaffolding that is still
planned. The pre-commit step now runs `vp dotenv scan --staged`, as the
guide shows, and `vp exec varlock` replaces `vpx varlock` for varlock
commands that `vp dotenv` does not wrap. varlock#1329 and varlock#1330
are closed.

The migrator README no longer describes the schema type generator that
the migration dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…les in check

`vp dotenv init` now finishes the setup that users had to do by hand:

- It removes the unchanged `EXAMPLE_ITEM` placeholder that `varlock init`
  always writes.
- It lists the items that `inferFromPrefix('VITE_')` makes sensitive, so that
  a value such as `HOST=localhost` does not become a secret unnoticed.
- It adds the generated types file to the `include` of `tsconfig.app.json`
  or `tsconfig.json` when that list does not cover it.
- It adds the file to `fmt.ignorePatterns` in the Vite config, because
  varlock rewrites it in its own style on every load and `vp check` would
  report its format. When `fmt` is not an object literal, it warns instead.

The `pass:` line of `vp dotenv check` now names the files that varlock
loaded, so it shows which environment was checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
A `varlockVitePlugin({ ssrInjectMode: '...' })` call stayed in the config
with a warning, because both integrations would run. When `ssrInjectMode`
is its only option and the config does not set `dotenv` yet, migration now
moves the options to `dotenv` and removes the call, with the integration
dependency when nothing else uses it. Other calls with options keep the
warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
The plugin injection had only unit tests with mocks. The new fixture
installs the real varlock, as a project does, and checks that:

- `vp build` inlines a public value and removes a sensitive `VITE_*` value
  from `import.meta.env`, with a warning.
- A sensitive value in the client output fails the build.
- `vp test` does not run the tests while the env config is invalid, and the
  tests read the resolved values once it is valid.

The dotenv warnings now carry a timestamp only in a server, like Vite's own
logs, so build output has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
- The `vp check` step runs only checks that read no values: type
  generation, schema errors, and `varlock audit`. Value validation needs
  secrets, which lint-only CI jobs and cached tasks do not have.
- The git-hook scan becomes opt-in, because it resolves the schema on every
  commit.
- A Follow-ups section lists the known gaps after Phase 1, and the upstream
  asks gain a minimum value length for redaction and scanning and a package
  without source maps.
- The init, check, migration, and fixture descriptions match the code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
The macOS temp dir is a symlink under /private, and module resolution
returns the real path, so the test failed in the macOS CLI E2E job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
- An `env.d.ts` that varlock did not generate stays. The schema writes the
  types to `env.varlock.d.ts` instead, and init says so.
- In a workspace package, the formatter setting belongs to the root config,
  so init prints the root-relative pattern instead of adding a `fmt` block
  to the package config.
- The tsconfig and Vite config edits keep the quotes, indentation,
  semicolons, and single-line arrays of each file, so `vp fmt --check`
  still passes. The config edits share one AST helper.
- init generates the types with `varlock codegen`, which needs no values.
- init reports when a tsconfig may not include the types file, when every
  item is public by default, and which `.env.<mode>` files need
  `@currentEnv`.
- On an existing schema, init still sets up the types file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
- `vp preview` with an invalid env config warns and serves the existing
  build output. Only `vp test` stops, and its error has no stack trace.
- A config that still adds `varlockVitePlugin()` gets a warning, because
  the integration would run twice.
- A failed build output scan suggests `@public` for a value that is not a
  secret.
- `ssrInjectMode` comes from the merged config, so a value set by a
  composed config or a plugin applies.

The fixture reads `ENV` from `varlock/env`, inlines a `@public` port, and
checks the build output when the env config is invalid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…range

- `vp dotenv check --env <name>` warns when varlock loaded no
  `.env.<name>` or `.env.<name>.local` file. varlock accepts any name, so
  a typo passed silently.
- `vp migrate` warns when a `package.json` declares a `varlock` range that
  allows versions this Vite+ does not support, with the command that fixes
  it.
- The migrator adds `dotenv` to the config with the shared AST helper
  instead of the native JSON merge, which dropped semicolons and could not
  edit an arrow function config. The config keeps its layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…commands

- The guide and the RFC describe what `vp dotenv init` keeps and edits,
  the workspace package case, `varlock codegen`, and the notices.
- `vp preview` warns about an invalid env config instead of failing.
- The migration rules mention the `varlock` range warning, and
  `vp dotenv init` for a project that already has a schema.
- The guide lists the costs of `varlock/auto-load`, the `@public` hint for
  a scan match, the `check --env` warning, and `vp exec varlock` for the
  commands that `vp dotenv` does not wrap.
- The RFC follow-ups record the workspace formatter setup, a missing
  varlock in a workspace package, and a user-registered integration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
The `vp dotenv init` snapshots record the text of `varlock init --agent`,
which spells "self-explanitory". The typos check failed the Lint job on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…v init

- On an existing schema whose types path is a file of the user, such as
  the `env.d.ts` of create-vue, init no longer runs `varlock codegen` over
  it. It leaves the file and the project setup, and asks for another path.
  In a client app it also points out a schema with
  `@defaultSensitive=false`. The deprecated `@generateTypes(lang=ts, ...)`
  counts as a types decorator.
- init warns when `varlock codegen` fails, and ends with a line that
  names `vp dotenv check` for an existing schema too.
- Formatter ignore patterns count as `.gitignore` lines: the last match
  decides, a `!` pattern includes the file again, and `./env.d.ts` does
  not cover `env.d.ts`, as in oxfmt.
- Config edits keep comments with the property or pattern they describe,
  and take the quotes of the first string in the file, else double
  quotes, the formatter default.
- The workspace root comes from `findMonorepoRoot`, as for `vp check`.
  When it cannot be found, init asks the user instead of editing the
  package config.
- The `vp migrate` summary names `vp dotenv init`, which sets up the types
  file of a migrated schema.
- The `.env.<mode>` notices say that the `APP_ENV` item goes in the
  schema, not in the header, and `.env.template` and `.env.dist` are not
  environments.

The init fixture gets a case for an existing schema, and the workspace case
starts from a schema, checks the root `vp fmt --check`, and runs init again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…ow-ups

- The guide and the RFC say what `vp dotenv init` does with an existing
  schema and a types file of the user, and that an added entry can need
  `vp fmt` when it makes a line too long.
- The `@generateTsTypes` row says to use a path that no file of the user
  has, since varlock replaces the file.
- `printenv` replaces `install-plugin` among the `vp exec varlock`
  examples: `install-plugin` works only with the standalone binary.
- The RFC follow-ups record the remaining review items: a `vp fmt`
  backstop for init edits, the types setup in `vp migrate`, init and range
  warning edges, and the place of the shared config edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
`varlock init` skips a `.env.schema` that it cannot parse and writes a
new one in its place. `vp dotenv init` now puts the original back and
exits with code 1, and `vp dotenv check` shows the parse error.

- When the types file is a file of the user, the warning says that the
  next `vp dev`, `vp build`, `vp test`, or `vp dotenv check` replaces
  it, names the decorator that the schema uses, and init no longer
  suggests `vp dotenv check` as the next step.
- Set up the tsconfig and the formatter only for a types file that
  `varlock codegen` wrote.
- Read formatter ignore patterns with the `.gitignore` anchors and
  directory patterns, so `/env.d.ts` and `apps/web/` count.
- Keep the comment of an empty `ignorePatterns` array.
- Suggest `env.d.ts` for a schema without types when the file is free,
  and say that only items without `@sensitive` are public.
- Docs and RFC: describe the restored schema, fix the `@currentEnv`
  wording, and record the remaining review items as follow-ups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
An interactive `varlock init` on a schema that it cannot parse writes a
new schema from `.env.example` and the other env files, then offers to
delete the example file and the values that went into the new schema.
`vp dotenv init` puts the original schema back, so accepting those
prompts lost values. With a schema, `vp dotenv init` now always runs
`varlock init --agent`, which asks nothing and deletes nothing, and the
restore error says that varlock's notes are about the discarded schema.

- Restore the schema byte for byte.
- Add no formatter pattern for a types file outside the workspace root:
  the formatter rejects `..` in `ignorePatterns`, so `vp check` failed.
- Read ignore patterns without extglobs, as the formatter does.
- The user-file warning names example commands that replace the file.
- Fix the remaining "every item is public" wording, and record the
  remaining review items in the RFC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
`vp dotenv init` chose `--agent` from one check for `.env.schema` and
armed the restore from a second read, with `vp add` in between. It now
reads the schema once, after the dependency step, and both follow from
that read. `buildVarlockInvocation` takes `hasSchema` without a default.

- The `dotenv_init_existing_schema` case runs `vp dotenv init` without
  `--no-interactive` on a schema that varlock cannot parse, next to an
  `.env.example`. Without `--agent`, varlock waits at a prompt and the
  step times out, so the case guards the fix.
- `isOutsideRoot` takes the path module, so the Windows drive case has
  a test on every platform.
- Reword the restore error, use "prompts" in the guide, say that a
  types file outside the root needs no formatter pattern, fix the RFC
  command table and agent note, and record the remaining review items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…g as varlock and TypeScript do

- The `--env` guard reads the header of the schema that varlock loads,
  `.env.schema` or the entries of `varlock.loadPath`, and names the file.
- `vp dotenv init` fails when `varlock.loadPath` names another path,
  because `varlock init` writes `.env.schema` in the working directory.
- The Vite mode warning reads the schema and env files of a single
  `loadPath` directory.
- The `vp dotenv check` pass line names the loaded files relative to the
  working directory, from the `basePath` of the graph.
- `init` treats only a missing schema as absent, and fails on any other
  read error instead of letting varlock prompt over it.
- As in TypeScript, `*` and `**` in a tsconfig `include` skip hidden files
  and directories, and a tsconfig without `include` gets a request to check
  a types file in a hidden directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
…endencies

`vp dotenv init` cannot tell whether a project loads varlock at run time,
so it keeps `dependencies`. A project that uses varlock only through the
CLI can move it back, and a later init moves it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
- The client env filter removes only sensitive keys with an env prefix,
  so `MODE`, `DEV`, `PROD`, `SSR`, and `BASE_URL` stay in
  `import.meta.env` when the schema declares them.
- `vp dotenv init` marks the items for values that Vite and Node.js set
  (`NODE_ENV`, `MODE`, `DEV`, `PROD`, `SSR`, `BASE_URL`) `@public` in a
  client app.
- `vp dotenv check` fails when varlock loads no file.
- `vp dotenv init` uses varlock's defaults without a terminal or in CI,
  and removes a schema that varlock wrote before it failed.
- The `--env` guard fails when any `varlock.loadPath` entry sets
  `@currentEnv`, because varlock then ignores the flag for every entry.
- The init `loadPath` guard accepts `./.env.schema`, an empty list loads
  the working directory, and its error no longer suggests running init in
  the schema directory.
- Docs, RFC, and BUNDLING.md: a package schema from the workspace root,
  the empty schema follow-up, and the inlined integration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUJ79dF65F7Fo5MhZtHU7a
@fengmk2
fengmk2 force-pushed the feat/dotenv-varlock branch from 97350d0 to 1e65e42 Compare December 5, 2026 18:13
@fengmk2 fengmk2 removed the preview-build Publish this PR's commits to the registry bridge as preview builds label Dec 5, 2026
@fengmk2 fengmk2 added the preview-build Publish this PR's commits to the registry bridge as preview builds label Dec 5, 2026 — with Claude

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview-build Publish this PR's commits to the registry bridge as preview builds test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests test: install-e2e run vite install e2e test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants