Skip to content

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

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

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

Conversation

@fengmk2

@fengmk2 fengmk2 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Adds first-class .env support to Vite+ through varlock. A project commits a .env.schema that declares each variable, its type, and whether it is sensitive. Real values stay in git-ignored files such as .env.local. Vite+ bundles varlock and its Vite integration, so the project does not install or register anything.

The feature ships as experimental: the Env Files guide, the dotenv config reference, the varlock migration rules, and the README command lists say so, and commands, options, and the schema setup that vp dotenv init writes may change.

Design: rfcs/varlock-integration.md. User guide: docs/guide/dotenv.md. Config reference: docs/config/dotenv.md.

vp dotenv commands

Command Behavior
vp dotenv init [--no-interactive] Writes .env.schema from the existing .env files and code, adds !.env.schema to .gitignore when needed, and sets up the ENV types without a varlock dependency. A project that serves or builds a client app with Vite gets @defaultSensitive=inferFromPrefix('VITE_'), and a project whose scripts run Vite or Vitest gets an APP_ENV that follows the Vite mode. A server without a client bundle keeps @defaultSensitive=false
vp dotenv check [--mode <name>] [--env <name>] Validates the resolved values without printing them, and prints a pass: line with the number of config items and how many have a value
vp dotenv print [--mode <name>] [--format env|json|shell] [--reveal] Prints the resolved values. Sensitive values are masked unless --reveal is given
vp dotenv explain [KEY] [--mode <name>] Lists every item, or shows the sources and overrides for one key. Sensitive values are masked
vp dotenv scan [--mode <name>] [--staged] [--include-ignored] [paths...] Finds plaintext copies of sensitive values, and exits with a non-zero code on a match
vp dotenv exec [--mode <name>] -- <command> Runs a command with the resolved environment
vp dotenv encrypt [--file <file>] Encrypts a value from stdin or a prompt into varlock("local:...") with a key stored on the device, or the sensitive plaintext values of a file
vp dotenv lock Ends the biometric session of local encryption, so the next decryption asks for Touch ID or another biometric check
vp dotenv keychain [args...] macOS only: manages the Keychain items that keychain() reads. Every argument, --help included, goes to varlock keychain (set, import, fix-access, list)

--mode gives viteMode() the same value as vp build --mode <name>, so CI can check the values of one mode. Every subcommand that loads the config fails when the directory has no .env.schema and no varlock.loadPath, so a check in the wrong directory cannot pass. init, lock, keychain, and encrypt without --file do not load it. vp dotenv is available from both the global and the local CLI, and vp --version lists the bundled varlock version. The global vp env --help points to vp dotenv for project environment variables.

Vite and Vitest integration

When the config root has a .env.schema, defineConfig adds the varlock plugins. Projects without a schema get no new plugins, and their plugin list does not change.

  • vp dev validates before it serves the app and shows varlock's error page when the env is invalid.
  • vp build and vp preview stop with exit code 1 on invalid env. vp test fails before any test runs.
  • ENV from vite-plus/dotenv (or varlock/env) is typed and coerced. Public values are inlined at build time, and sensitive values are never inlined into client code.
  • vite.config.ts can read ENV. The first read loads the schema, and the Vite command uses the same load. An invalid env still stops vp build, and a vp dev restart after an env file change gives the config the new values.
  • The schema can follow the Vite mode. varlock picks .env.[env] files from the @currentEnv variable, and viteMode() from @plugin(vite-plus) returns the mode of vp dev, vp build, vp preview, or vp test (the --mode value, or else the default mode of the command). With APP_ENV=fallback(viteMode(), development), vp build loads .env.production as in Vite, vp build --mode staging loads .env.staging, and vp test loads .env.test. The mode is the lowest-priority source, so APP_ENV from the environment or an env file still wins. This also holds when a vp run task runs the command.
  • Vite+ warns when the mode does not select the varlock environment: for a --mode value, and for the default mode when .env.[mode] exists. The warning names the cause, such as a schema without viteMode() or a value with higher priority.
  • vite-plus/plugin is a varlock plugin. In the schema, @plugin(vite-plus) @generateVitePlusTypes(path=env.d.ts, importMetaEnv=none) writes varlock's TypeScript types and also applies them to ENV from vite-plus/dotenv, so a project needs no direct varlock dependency. vp dotenv init sets this up and leaves package.json unchanged.
  • Vite copies every VITE_* variable from the process environment into import.meta.env. Vite+ removes the keys that varlock treats as sensitive and prints a warning that names them. varlock treats a variable that the schema does not declare as sensitive, so public VITE_* variables must be in the schema.
  • Values that varlock encrypted with a device key (varlock("local:...")), and macOS Keychain references (keychain(...)), resolve in every command that loads the schema. varlock(prompt) asks for a value only through vp dotenv exec, because the other commands do not give varlock a terminal.
  • After a client build, Vite+ runs varlock scan on the output and fails the build if a sensitive value appears there. dotenv.scanBuildOutput: false turns this off.
  • Server builds bundle varlock's runtime, so the server output does not need varlock at run time.
  • Independent Vitest projects (defineProject files and projects with extends: false) use the root config's schema.
  • dotenv.schema: false keeps the file but skips loading. dotenv.schema: true fails when no schema is found.

vp create adds !.env.schema to the default .gitignore.

vp migrate for existing varlock setups

A project that registers @varlock/vite-integration itself would run two integrations after it adopts Vite+. vp migrate detects the integration in package.json or vite.config.*, asks in interactive mode (default yes), and migrates in non-interactive mode. On a project that already uses Vite+, it runs with --full, like the other tool migrations.

  • varlockVitePlugin() without options leaves the Vite config, with its import and an emptied plugins property.
  • @generateTsTypes(...) in .env.schema becomes @plugin(vite-plus) @generateVitePlusTypes(...) with the same options. @defaultSensitive and @currentEnv stay, so the project loads the same values.
  • @varlock/vite-integration is removed. varlock is removed when no source import, script, CI workflow, git hook, varlock plugin, or other schema plugin uses it.
  • A plugin call with options and a dependency that something still uses stay, with a warning. Imports from varlock/env stay, because server code that Vite does not bundle would then need vite-plus at run time.

Dependencies

vite-plus now depends on varlock@1.25.0 and @varlock/vite-integration@1.5.6, kept in lockstep in the catalog. They add about 5.7 MB unpacked (varlock 5.4 MB, the integration 0.24 MB), plus one native helper for the platform (0.5 MB on Windows x64, 1.0 MB on macOS, 1.8 MB on Linux x64).

@varlock/vite-integration@1.5.6 fixes a stale env on the first dev server restart when Vite's root is not the working directory.

Limits

  • One vp process loads one schema. Configs with different .env.schema files in one resolution or one vp test run fail with an error instead of mixing values.
  • Vite+ looks for the schema in the root from vite.config.ts, or else in the working directory. A root given only on the command line (vp dev ./app) is not detected. With dotenv.schema: true, the command fails and names that schema.
  • ENV in vite.config.ts reads the schema in the working directory, not in a root that the config sets. Other commands that run the config file, such as vp lint, then load the schema too.
  • viteMode() comes from the vp command line. mode in vite.config.ts does not change it, and it returns nothing when a script runs vite build directly. Vite+ warns in both cases.
  • A vp run task starts in a clean environment. To give a task the schema environment, run its command through vp dotenv exec.
  • TypeScript code that imports ENV from varlock/env needs a direct varlock dependency at the bundled version. ENV from vite-plus/dotenv does not.
  • varlock ships an agent skill. pnpm 12 asks to approve it ("Agent skills awaiting approval: varlock") only when varlock is a direct dependency, so a project that depends only on vite-plus sees no prompt. This repository and projects that add varlock themselves see it until they approve or deny it (pnpm approve '!varlock').
  • Output redaction in vp dotenv exec replaces every occurrence of a sensitive value, so a short or common value, such as a database password postgres, also masks the same word in unrelated output.
  • vp pack (tsdown) does not load the schema.

🤖 Generated with Claude Code

@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: cb84294

@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 a82db6d

Updated: Dec 4, 2026, 12:42 UTC | Dashboard

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

CLI artifact sizes (cb84294)

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.61 MiB +92.45 KiB (+3.58%)
packages/core/dist Directory total 4.29 MiB 4.29 MiB 0 B (0.00%)
Combined package dist Directory total 6.81 MiB 6.90 MiB +92.45 KiB (+1.33%)
vp (Linux x64) Binary 9.28 MiB 9.28 MiB +4.00 KiB (+0.04%)
vp (Linux x64) gzip -9 4.24 MiB 4.24 MiB -63 B (-0.00%)
NAPI (Linux x64) Binary 37.97 MiB 38.04 MiB +68.00 KiB (+0.17%)
NAPI (Linux x64) gzip -9 15.32 MiB 15.33 MiB +16.05 KiB (+0.10%)
vp (macOS ARM64) Binary 6.11 MiB 6.11 MiB +16 B (+0.00%)
vp (macOS ARM64) gzip -9 3.63 MiB 3.63 MiB +118 B (+0.00%)
NAPI (macOS ARM64) Binary 44.38 MiB 44.43 MiB +48.42 KiB (+0.11%)
NAPI (macOS ARM64) gzip -9 19.42 MiB 19.43 MiB +13.59 KiB (+0.07%)
vp (Windows x64) Binary 7.25 MiB 7.25 MiB +512 B (+0.01%)
vp (Windows x64) gzip -9 3.32 MiB 3.32 MiB +262 B (+0.01%)
NAPI (Windows x64) Binary 33.86 MiB 33.92 MiB +61.00 KiB (+0.18%)
NAPI (Windows x64) gzip -9 14.02 MiB 14.04 MiB +20.50 KiB (+0.14%)
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.69 MiB 4.69 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 Outdated
| Command | Runs | Behavior |
| -------------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `vp dotenv init` | `varlock init`, or `varlock init --agent` with `--no-interactive` | Scaffold `.env.schema` from existing `.env` files and code, add the `.gitignore` exception when needed, pick a type-generation decorator. |
| `vp dotenv check` | `varlock load --format json --agent` | Validate schema plus local values. Discard stdout and print a `pass:` line. varlock reports errors on stderr. This is the CI entry point. Fails, like every subcommand except `init`, when the directory has no schema. |

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.

Does vp check need to include this feature? If a project has a .env.schema file, should vp check also automatically run this check?

Comment thread docs/guide/dotenv.md Outdated

`init` scans your `.env` files and your code, writes `.env.schema` with decorators inferred for each variable, and adds `!.env.schema` to `.gitignore` when the file would otherwise be ignored. Review the schema and mark each secret with `@sensitive`.

`varlock init` also adds `varlock` to the `dependencies` in `package.json`. Keep it, at the version that Vite+ bundles (`vp --version` lists it): TypeScript resolves `varlock/env` from your project to apply the generated `ENV` types, and package managers share one copy when the versions match. `vp dotenv init` prints a reminder with the version when it sees the new dependency.

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.

Need to find a solution that prevents the project from directly depending on varlock.

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?

@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):

Vite feature With a .env.schema
Built-in constants (import.meta.env.MODE, DEV, PROD, SSR, BASE_URL) Vite+ does not change them. Its 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 VITE_* variable that an env file sets without a declaration in the schema as sensitive. Vite+ removes it from import.meta.env and prints a warning that asks for a declaration in the schema.
.env, .env.local, .env.[mode], .env.[mode].local varlock loads the same files. It selects [env] from the @currentEnv variable, which follows the mode through viteMode() (see Modes below).
--mode Selects the varlock environment when the schema uses viteMode(), which vp dotenv init writes. When the mode does not select the environment, Vite+ prints a warning.
envPrefix / public vs. secret vp dotenv init writes @defaultSensitive=inferFromPrefix('VITE_'), so only VITE_* variables are public by default, the same rule as Vite. @public marks an exception.
loadEnv() in vite.config.ts Still works, but it reads the files without the schema. ENV from vite-plus/dotenv also works in vite.config.ts.
TypeScript for import.meta.env Unchanged. The generated types use importMetaEnv=none, so vite/client keeps typing import.meta.env.
envDir Not supported while a schema is active. varlock.loadPath in package.json replaces it.

Modes. varlock selects .env.[env] files from the @currentEnv variable. vp dev, vp build, vp preview, and vp test pass their Vite mode to the schema as viteMode(), which comes from @plugin(vite-plus): the --mode value, or else the default mode of the command. vp dotenv init writes:

# @currentEnv=$APP_ENV
# ---
# @public @type=enum(development, production, test)
APP_ENV=fallback(viteMode(), development)
Command viteMode() Files that load
vp dev development .env.development[.local]
vp build, vp preview production .env.production[.local]
vp test test .env.test[.local]
vp build --mode staging staging .env.staging[.local]

The mode is the lowest-priority source. APP_ENV from the process environment or an env file still wins, so a CI or platform value and a .env.local choice keep working. This also holds when a vp run task runs the command. vp dotenv check --mode production checks the values that vp build uses.

When the mode does not select the environment, Vite+ prints a warning that names the cause: a schema without viteMode(), a value with higher priority, or vite build that runs without vp. For a schema with a fixed APP_ENV=development and a .env.production file, vp build prints:

Vite mode "production" does not select the varlock environment: APP_ENV is "development", so varlock does not load .env.production, and its values override the ones Vite reads from that file. To follow the Vite mode, set `APP_ENV=fallback(viteMode(), development)` in .env.schema, or run `APP_ENV=production vp build`.

ENV in vite.config.ts. The config file runs before Vite+ adds the varlock plugins. The first read of ENV loads the schema, and the Vite command uses the same load:

  • An invalid env still stops vp build with exit code 1, and vp dev still shows the error page.
  • After an env file changes, the vp dev restart gives the config the new values.
  • vp test workers read ENV as in test files without a config read.

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 (a82db6d)

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.11 MiB -16 B (-0.00%)
NAPI (macOS ARM64) 44.35 MiB 44.39 MiB +48.44 KiB (+0.11%)
vp (macOS x64) 7.71 MiB 7.71 MiB +16 B (+0.00%)
NAPI (macOS x64) 49.94 MiB 50.03 MiB +84.09 KiB (+0.16%)
vp (Linux ARM64 GNU) 7.72 MiB 7.72 MiB 0 B (0.00%)
NAPI (Linux ARM64 GNU) 33.66 MiB 33.71 MiB +56.00 KiB (+0.16%)
vp (Linux ARM64 musl) 7.80 MiB 7.80 MiB +672 B (+0.01%)
NAPI (Linux ARM64 musl) 32.87 MiB 32.92 MiB +54.25 KiB (+0.16%)
vp (Linux x64 GNU) 9.28 MiB 9.28 MiB 0 B (0.00%)
NAPI (Linux x64 GNU) 37.89 MiB 37.97 MiB +80.00 KiB (+0.21%)
vp (Linux x64 musl) 9.35 MiB 9.36 MiB +3.34 KiB (+0.03%)
NAPI (Linux x64 musl) 37.08 MiB 37.16 MiB +80.00 KiB (+0.21%)
vp (Windows x64) 7.25 MiB 7.25 MiB -1.50 KiB (-0.02%)
NAPI (Windows x64) 33.49 MiB 33.56 MiB +74.50 KiB (+0.22%)
Trampoline (Windows x64) 13.00 KiB 13.00 KiB 0 B (0.00%)
Installer (Windows x64) 4.70 MiB 4.70 MiB 0 B (0.00%)
vp (Windows ARM64) 6.45 MiB 6.45 MiB +2.00 KiB (+0.03%)
NAPI (Windows ARM64) 29.50 MiB 29.55 MiB +51.00 KiB (+0.17%)
Trampoline (Windows ARM64) 13.00 KiB 13.00 KiB 0 B (0.00%)
Installer (Windows ARM64) 3.87 MiB 3.87 MiB 0 B (0.00%)
gzip -9 sizes
Binary Latest release Preview Change
vp (macOS ARM64) 3.63 MiB 3.63 MiB -747 B (-0.02%)
NAPI (macOS ARM64) 19.40 MiB 19.42 MiB +21.92 KiB (+0.11%)
vp (macOS x64) 3.82 MiB 3.82 MiB -1.98 KiB (-0.05%)
NAPI (macOS x64) 20.75 MiB 20.78 MiB +23.06 KiB (+0.11%)
vp (Linux ARM64 GNU) 4.18 MiB 4.18 MiB +3 B (+0.00%)
NAPI (Linux ARM64 GNU) 14.52 MiB 14.54 MiB +22.69 KiB (+0.15%)
vp (Linux ARM64 musl) 4.21 MiB 4.21 MiB +501 B (+0.01%)
NAPI (Linux ARM64 musl) 14.22 MiB 14.24 MiB +23.93 KiB (+0.16%)
vp (Linux x64 GNU) 4.24 MiB 4.24 MiB -185 B (-0.00%)
NAPI (Linux x64 GNU) 15.27 MiB 15.30 MiB +21.49 KiB (+0.14%)
vp (Linux x64 musl) 4.27 MiB 4.27 MiB -327 B (-0.01%)
NAPI (Linux x64 musl) 14.95 MiB 14.97 MiB +22.84 KiB (+0.15%)
vp (Windows x64) 3.32 MiB 3.32 MiB +566 B (+0.02%)
NAPI (Windows x64) 13.88 MiB 13.91 MiB +23.96 KiB (+0.17%)
Trampoline (Windows x64) 7.14 KiB 7.14 KiB -2 B (-0.03%)
Installer (Windows x64) 2.25 MiB 2.25 MiB -24 B (-0.00%)
vp (Windows ARM64) 3.18 MiB 3.18 MiB +1.77 KiB (+0.05%)
NAPI (Windows ARM64) 13.15 MiB 13.17 MiB +22.74 KiB (+0.17%)
Trampoline (Windows ARM64) 6.93 KiB 6.93 KiB 0 B (0.00%)
Installer (Windows ARM64) 2.15 MiB 2.15 MiB +67 B (+0.00%)

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 (a82db6d)

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.a82db6d743fa458af8136cacda88afb848aff88c
@voidzero-dev/vite-plus-core 0.0.0-commit.a82db6d743fa458af8136cacda88afb848aff88c
create-vite-plus 0.0.0-commit.a82db6d743fa458af8136cacda88afb848aff88c

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

# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/voidzero-dev/vite-plus/a82db6d743fa458af8136cacda88afb848aff88c/packages/cli/install.sh | VP_PR_VERSION=3670 VP_LEGACY_INSTALLER_URL=https://raw.githubusercontent.com/voidzero-dev/vite-plus/a82db6d743fa458af8136cacda88afb848aff88c/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/a82db6d743fa458af8136cacda88afb848aff88c/packages/cli/install-legacy.ps1"; irm https://raw.githubusercontent.com/voidzero-dev/vite-plus/a82db6d743fa458af8136cacda88afb848aff88c/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=a82db6d743fa458af8136cacda88afb848aff88c
  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.a82db6d743fa458af8136cacda88afb848aff88c" --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.a82db6d743fa458af8136cacda88afb848aff88c # or: npm create vite-plus@0.0.0-commit.a82db6d743fa458af8136cacda88afb848aff88c
$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.a82db6d743fa458af8136cacda88afb848aff88c # or: npm create vite-plus@0.0.0-commit.a82db6d743fa458af8136cacda88afb848aff88c

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.a82db6d743fa458af8136cacda88afb848aff88c",
    "vite": "npm:@voidzero-dev/vite-plus-core@0.0.0-commit.a82db6d743fa458af8136cacda88afb848aff88c"
  }
}

@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 234MB
# 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 and others added 12 commits December 4, 2026 12:17
Add an RFC for first-class `.env` support through varlock: a bundled
`vp dotenv` command family (init, check, print, explain, scan, exec),
automatic Vite/Vitest plugin injection when `.env.schema` exists,
create/migrate scaffolding, and opt-in `vp run` task injection.

Add the user guide and config reference that describe the intended
end-user experience, with sidebar entries and cross-links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Phase 1 of rfcs/varlock-integration.md:

- `vp dotenv init|check|print|explain|scan|exec`, parsed by clap in the
  native binding and run through the bundled varlock CLI script.
- Load `@varlock/vite-integration` from `defineConfig` when the project
  root has `.env.schema`, with a resolve plugin for `varlock/*` imports
  and a client build-output scan. The new `dotenv` config key controls it.
- `vite-plus/env` re-exports `varlock/env`.
- Pin varlock and its Vite integration, and report varlock in the
  toolchain and version output.
- Keep `.env.schema` tracked in the `vp create` .gitignore default.
- Align the RFC and docs with varlock's actual CLI and plugin behavior.

Not done yet: pnpm-lock.yaml does not include varlock, the native binding
and global CLI are not compiled, the hand-edited binding index files are
unchecked against napi output, and the affected CLI snapshots are not
re-recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `vp dotenv` waits on SIGINT and forwards SIGTERM and SIGHUP to varlock,
  so `exec` no longer orphans the child under a supervisor.
- `vp dotenv exec` rejects unknown options before the command instead of
  running them as the command.
- Gate every dotenv plugin with `apply`: the first group claims each
  config resolution, so composed configs do not load varlock twice, and
  the merged config's `dotenv` options apply.
- Change PATH and the telemetry default only while the varlock Vite
  integration is imported; the integration keeps its own copy of the env.
- Report a scan spawn error or signal separately from scan findings.
- Skip non-JSON lines before the `varlock load` output, and quote masked
  `env` values with single quotes so `$` is not expanded.
- Add `vp dotenv init --no-interactive` (`varlock init --agent`).
- Reuse `pkgRoot` and resolve varlock from vite-plus's manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Mark varlock as `noExternal` in server environments. Vite resolves an
  externalized dependency again from the importer, which skipped the
  resolve bridge, so SSR dev under pnpm could not load `varlock/env`.
- Resolve `vite-plus/env` to `varlock/env`, so each environment has one
  varlock runtime, the one that the SSR init code initializes.
- Fail every `vp dotenv` subcommand except `init` when the directory has
  no `.env.schema` and no `varlock.loadPath`, so `check` and `scan` cannot
  pass without checking anything.
- Tolerate extra stdout lines after the `varlock load` JSON.
- Document how tasks pass `APP_ENV` and secrets through to varlock, and
  show `--reveal` for `eval` of `vp dotenv print --format shell`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`dotenv.schema: true` without a schema rejected the plugin promise, and
Vite awaits plugin promises before it calls `apply`, so a later
`dotenv.schema: false` from `mergeConfig` could not win. A separate
`vite-plus:dotenv-require-schema` plugin now fails in its `config` hook,
and only when the merged config still sets `true`.

Document in the RFC that the integration's import-time load runs in the
working directory, and that its `config` hook loads again from the Vite
root and clears the earlier error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Stop recommending `vp remove varlock` after `varlock init`. TypeScript
  resolves the generated `varlock/env` augmentation from the project, so
  the direct dependency is needed under pnpm; package managers share one
  copy when it matches the bundled version, which the reminder now names.
- Print masked `vp dotenv print` output through the terminal `log` helper,
  which ignores a closed pipe, instead of a raw stdout write that threw
  EPIPE for `vp dotenv print | head -n 1`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add pnpm-lock.yaml entries for varlock 1.23.0 and
@varlock/vite-integration 1.5.4, including the catalog entries, the
vite-plus importer, and varlock's optional native helper packages, so
frozen installs accept the manifest changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add varlock to the global CLI's `vp --version` tool list, which is
  separate from the JS list, and add the `dotenv` row to the local CLI's
  `vp -h`, so both CLIs show the same commands and tools.
- With `dotenv.schema: true`, fail with an error that names a schema
  found only in a root given on the command line, instead of claiming
  that no schema exists.
- Fix type-aware lint errors in the dotenv module and its tests.
- Add the command_dotenv snapshot fixture (help on both flavors, the
  error paths, and a real schema run with a masked secret), and re-record
  the help, version, toolchain, and create snapshots that the new command,
  tool, and .gitignore entry change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The varlock runtime snapshots process.env when `varlock/env` first loads
and writes the snapshot back on every reload. It first loaded inside the
integration import, while vite-plus's bin directory was on PATH, so a dev
restart or a root that differs from the working directory restored that
PATH for the rest of the process. Load `varlock/env` before changing the
environment, so the snapshot holds the user's own PATH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Fail a Vitest run in `configureVitest` when the env config is invalid.
  Vitest resolves its config with `command: 'serve'`, for which the
  integration only installs a dev error page, so tests ran anyway.
- Apply the integration's plugins only in resolutions with the group's
  first root. An inherited inline Vitest project with its own `root`
  reloaded the integration's module-wide state and dropped the root
  schema's env for every project.
- Add the dotenv entry as a tagged thenable that imports the integration
  only when Vite awaits it, and drop wrapped configs' entries in
  `defineConfig`, so an outer `dotenv.schema: false` never starts the
  first `varlock load`.

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

- Run the Vitest validation guard in `configResolved` instead of
  `configureVitest`. Vitest calls `configureVitest` for runnable projects
  only, so a root config that only lists file-based projects skipped the
  check. The guard detects Vitest through the `__vitest__` environment, so
  `vp dev` keeps the integration's error page.
- Pin the integration to one schema root per process instead of per
  plugin group. The integration and varlock's runtime keep one loaded env
  per process, so a second project config with a different schema mixed
  the two schemas' values. It now fails with an error that names both
  schema roots; inherited projects still keep the root's env.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass `rootDir` to the varlock Vite integration instead of gating its
plugins on the final Vite root. The integration reloads only when
`rootDir ?? config.root` changes, and Vitest changes `root` in ways
`defineConfig` cannot see: it evaluates the parent config again for an
inline project, and sets the root of a file-based project in a config
hook. The root pin wrongly rejected the re-evaluated config, missed the
file-based project's reload, and dropped `ENV` transforms and init code
from inherited browser projects.

Key the one-schema-per-process check on the schema root, so a config
evaluated again for the same schema passes, and run the build-output
scan in the schema root, where `varlock scan` resolves the schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fengmk2 and others added 11 commits December 4, 2026 12:21
- Remove the keys that the schema marks @sensitive from Vite's
  `config.env` in `configResolved`. varlock writes every resolved value
  into `process.env`, and Vite's `loadEnv` copies each `VITE_*` key from
  there into `import.meta.env`, so decrypted or secret-manager values
  reached browser code in `vp dev`. A warning names the removed keys.
- Stop `vp preview` when the env config is invalid. Vite resolves preview
  as `serve`, and the integration's error page lives in
  `configureServer`, which preview never calls. The guard, now
  `vite-plus:dotenv-validation`, covers Vitest and preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Independent Vitest projects (`defineProject` files and inline projects
  with `extends: false` or a config file) get their own Vite server
  without the root plugins. Give each one a follower entry that installs
  the resolver, the varlock transforms, and the client env filter for the
  claimed schema. Validation and the build-output scan stay with the root.
- When merged configs bring two different schema roots into one
  resolution, fail with the conflict error instead of keeping the first
  schema silently.
- Load the schema root right after the integration import. With
  `_VARLOCK_ENV_KEY` preset, the integration skipped its preload and did
  not set the restart flag when the root differed from the working
  directory, so the first dev restart was lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- @varlock/vite-integration 1.5.6 fixes the stale first dev restart when
  the root is not the working directory. Remove
  the early schema-root load that worked around it.
- A dev restart now loads env again only when an env file changed.
  Document that values from a secret manager or `exec()` refresh only
  when the dev server starts again.
- varlock 1.25.0 names the failing keys on the last line of an invalid
  config. Record the new schema snapshot.
- RFC: describe 1.5.6 and mark the restart request as resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Describe `vp dotenv` in the global and local `vp --help` and in the
  READMEs as "Validate and inspect project environment variables using
  .env.schema". "Manage .env files" suggested a file editor.
- Add "For project environment variables, see vp dotenv." to the global
  `vp env --help`, for users who try `vp env` first.
- Start `vp dotenv --help` with "Validate project environment variables
  against .env.schema, including values supplied by CI", so it is clear
  that the check covers the values in effect.
- Record the `help_background_job` snapshot, which was missing the
  `dotenv` row.

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

- Keep the direct `varlock` dependency when TypeScript code reads `ENV`.
  `ENV` gets its keys only from the generated types, which extend
  `varlock/env`, and with pnpm the bundled copy is not visible from the
  project, so every `ENV` property is a type error. Explain why its
  version must match the bundled one, and when it can be removed.
- Use `@generateTsTypes(path='env.d.ts', importMetaEnv=none)` in the
  examples, and tell users to add the option after `vp dotenv init`. By
  default the generated types add every variable to `import.meta.env`,
  sensitive ones included, but Vite exposes only `VITE_*` variables
  there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llow the new lint preset

- `vp dotenv init` pins the `varlock` dependency that `varlock init`
  adds to the bundled version, then runs `vp install`. `varlock init`
  runs `<package manager> add varlock`, which saves the latest release
  with a range.
- Rename the `vite-plus/env` export to `vite-plus/dotenv`. The name
  matches `vp dotenv` and does not suggest a link to `vp env`, which
  manages runtimes.
- Follow the Cloudflare Oxlint preset from #3562: read JSON as
  `JsonObject` instead of `any`, type the lazy plugin entry as a promise,
  and remove unsafe type assertions. Keep `utils/json.ts` out of the
  config graph that `defineConfig` loads, because the CommonJS build
  cannot bundle `jsonc-parser`.
- Add the `varlock` row to the new `cwd_flag` snapshot.
- RFC: record that the generated types can augment `vite-plus/dotenv`
  through the re-export, and link the upstream request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`varlock init` runs `<package manager> add varlock`, which installs the
latest release with a range. Instead of pinning it afterwards with a
second install, `vp dotenv init` writes `varlock` at the bundled version
into `dependencies` before `varlock init` runs. `varlock init` skips its
install when the dependency exists, so `vp dotenv init` runs
`vp install` once. When the init fails or is cancelled (varlock exits
with code 0 on a cancelled prompt), it restores `package.json`.

Remove `hasVarlockDependency`, which nothing uses now, and link the
upstream request for a skip option from the RFC.

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

The generated types augment `varlock/env`, which TypeScript resolves from
the project, so `ENV` needed a direct `varlock` dependency. Ship a varlock
plugin in `vite-plus` (the `./plugin` export that varlock requires) that
registers `@generateVitePlusTypes`. It runs varlock's own TypeScript
generator and adds the same augmentation for `vite-plus/dotenv`, so
varlock writes the final file itself on every load. The plugin is one
CommonJS file: varlock runs `.cjs` plugins with its own
`varlock/plugin-lib`, so it works with the varlock copy that loads it.

`vp dotenv init` now leaves `package.json` unchanged. It writes the
dependency only so that `varlock init` skips its own install, restores
the file, switches the new schema to `@plugin(vite-plus)
@generateVitePlusTypes(..., importMetaEnv=none)`, and runs one load to
write the types. A project that already depends on `varlock`, or has no
`vite-plus` in node_modules, keeps the plain `varlock init` behavior.

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

A config file runs before Vite+ adds the varlock integration, so `ENV`
threw "varlock ENV not initialized" there. Under the `node` export
condition, `vite-plus/dotenv` now loads the integration with `require()`
on the first read. The integration's own load then serves the config file
and the Vite command, the integration copies `process.env` before varlock
injects values into it, and an invalid env still stops `vp build`. After a
failed load, reads return no values with varlock's warning instead of
throwing. Each read checks the env files at most once per synchronous
turn, so a `vp dev` restart gives the config the new values.

varlock picks `.env.[env]` files from `@currentEnv`, not from Vite's mode,
and its values override the ones Vite reads from `.env.[mode]`. `vp dev`,
`vp build`, `vp preview`, and `vp test` now warn when a mode other than
the default mode of the command does not match the `@currentEnv` value,
and name the command to run, such as `APP_ENV=staging vp build`.

`vp dotenv init` also replaces `@defaultSensitive=false` with
`@defaultSensitive=inferFromPrefix('VITE_')`, so that only `VITE_*`
variables are public by default, as in Vite. The client env warning now
says that a variable that the schema does not declare is sensitive too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
varlock selects `.env.[env]` files from `@currentEnv`, and without it only
from its `--env` option, so `vp build` ignored `.env.production`, which
plain Vite loads, and printed no warning.

The local CLI now sets `VP_VITE_MODE` for `vp dev`, `vp build`,
`vp preview`, and `vp test`: the `--mode` value, or else the default mode
of the command. `vp run` passes it to cached tasks, because the arguments
in the cache key decide it. The vite-plus varlock plugin adds
`viteMode()`, so a schema can follow the mode with
`APP_ENV=fallback(viteMode(), development)`. The mode is the
lowest-priority source: the process environment, env files, and earlier
`fallback()` values still win, and `vp build` loads the same files as
`vp build --mode production`.

`vp dotenv init` adds `@currentEnv=$APP_ENV` and that item when the schema
has no `@currentEnv`. `vp dotenv check`, `print`, `explain`, `scan`, and
`exec` take `--mode`. The mode warning now also covers the default mode
when `.env.[mode]` exists, and names why the environment does not follow
the mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Vite+ bundles varlock and its Vite integration and adds them for
`.env.schema`, so a project that registers `varlockVitePlugin()` itself
would run two integrations. `vp migrate` now detects
`@varlock/vite-integration` in package.json or vite.config, asks in
interactive mode (default yes), and migrates in non-interactive mode. On a
project that already uses Vite+, it runs with `--full`, like the other
tool migrations.

The migration removes `varlockVitePlugin()` calls without options and
their import, and an emptied `plugins` property. It switches
`@generateTsTypes(...)` in `.env.schema` to `@plugin(vite-plus)
@generateVitePlusTypes(...)` with the same options, and keeps
`@defaultSensitive` and `@currentEnv`, so the project loads the same
values. It removes `@varlock/vite-integration`, and `varlock` when no
source import, script, CI workflow, git hook, varlock plugin, or other
schema plugin uses it. A call with options and a used dependency stay,
with a warning. Imports from `varlock/env` stay, because server code that
Vite does not bundle would then need `vite-plus` at run time.

The RFC now states when pnpm 12 asks to approve varlock's agent skill:
only for a direct dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2
fengmk2 force-pushed the feat/dotenv-varlock branch from 6b4945c to cc78061 Compare December 4, 2026 04:53
…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>
@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
`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>
@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 and others added 2 commits December 4, 2026 23:15
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>
@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

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.

2 participants