Skip to content

feat: declare env vars in .env.schema with vp dotenv - #1225

Draft
fengmk2 wants to merge 5 commits into
masterfrom
feat/vp-dotenv
Draft

fengmk2 wants to merge 5 commits into
masterfrom
feat/vp-dotenv

Conversation

@fengmk2

@fengmk2 fengmk2 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

A draft that tries the experimental vp dotenv support from a Vite+ preview build (0.0.0-commit.74cb686) on cnpmcore. The runtime does not change: the config files keep their defaults and still read process.env, and production keeps its deployment environment.

Changes

  • .env.schema declares the environment variables that cnpmcore reads (registry and sync, features, Elasticsearch, database, Redis, storage, logs, secrets), plus the Docker Compose variables for Elasticsearch. Each item has a type such as boolean, port, url, or an enum (CNPMCORE_DATABASE_TYPE, CNPMCORE_CONFIG_SYNC_MODE, CNPMCORE_NFS_TYPE). Passwords, cloud keys, CNPMCORE_EGG_KEYS, and GITHUB_TOKEN are @sensitive. Every item is optional, so the defaults in the config files still apply.
  • Local values go to .env.local, which .gitignore now ignores. dev, test:local, cov, their PostgreSQL variants, and the database preparation scripts before them run through vp dotenv exec --, which validates the values and loads the file. start does not change.
  • CI: npm run env:check (vp dotenv check) runs in the typecheck job, and the MySQL and PostgreSQL test steps run egg-bin cov through vp dotenv exec --, so CI validates its CNPMCORE_* values before the tests. The database preparation steps stay as they are, because they start in the background before the install. The pre-commit hook runs vp dotenv scan --staged.
  • DEVELOPER.md describes .env.local, vp dotenv check, print, and explain. .env.example keeps only the variables that Docker Compose reads for Elasticsearch.

Behavior

Case Result
vp dotenv check without .env.local Passes in about 0.13 s: Found no errors in 83 config items (0 have a value)
CNPMCORE_DATABASE_TYPE=Postgres Fails: Current value is not in list of possible values, with the allowed values and the source (process.env)
vp dotenv print Prints only the values that are set; CNPMCORE_DATABASE_PASSWORD shows as 's3▒▒▒▒▒'
vp dotenv explain CNPMCORE_REDIS_PORT Type port, value 6380 as a number, source .env.local
vp dotenv exec -- node -e ... Values from .env.local reach process.env; unset items stay undefined, so config defaults apply
Output of vp dotenv exec into a pipe Sensitive values are masked, so CI logs mask the database password wherever it appears
vp dotenv scan 550 files scanned, no plaintext sensitive values
CI tests through vp dotenv exec All MySQL and PostgreSQL jobs pass (PostgreSQL: 1092 tests passed, 26 skipped)
CI log output POSTGRES_PASSWORD=postgres is sensitive, so vp dotenv exec masks every postgres in the log, for example "dialect":"po▒▒▒▒▒"

Notes for Vite+:

  • Output masking replaces every occurrence of a sensitive value, so a short or common value such as postgres also hides unrelated words in logs.
  • Fixed in this preview: vp dotenv check counted only the values that are set (0 config items without .env.local). It now counts the declared items and the items with a value.
  • Fixed in this preview: vp dotenv init wrote a header for a Vite client app, which marks every variable without a VITE_ prefix sensitive and adds an unused APP_ENV. For a project that does not run Vite, it now keeps @defaultSensitive=false and adds no APP_ENV. It also adapts a header without a # --- divider, which varlock init writes from this .env.example. The schema in this PR stays written by hand.

Before merging

  • The CI workflow sets UTOO_REGISTRY and npm_config_registry to the preview registry (utoo reads only UTOO_REGISTRY), and package.json pins the preview vite-plus and vite-plus-core. Both go back to npm releases before this leaves draft.
  • The Docker image jobs fail on this draft only: the Dockerfiles install from registry.npmjs.org, which does not have the preview build.

🤖 Generated with Claude Code

cnpmcore reads about 80 environment variables, and only the config code
says which ones exist. `.env.schema` now declares each of them with its
type, a short description, and whether it is sensitive. The config files
keep their defaults, so every item is optional, and production still
reads the deployment environment.

For local development, values go to `.env.local`. The dev, test, and
coverage scripts, and the database preparation scripts before them, run
through `vp dotenv exec`, which validates the values and loads the file.
CI checks the schema with `vp dotenv check`, and the pre-commit hook
scans staged files for sensitive values.

This draft uses a Vite+ preview build (0.0.0-commit.a82db6d) and installs
it through the preview registry in CI.

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

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@socket-security

socket-security Bot commented Dec 4, 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
Updatednpm/​vite-plus@​1.9.0 ⏵ 0.0.0-commit.74cb68680819bf3842356f0b927dc5bb3e8929baN/AN/AN/AN/AN/A

View full report

utoo reads UTOO_REGISTRY, not npm_config_registry, so the install still
resolved vite-plus from its default registry and found no preview build.

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

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (273ad74) to head (bfa58c0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1225      +/-   ##
==========================================
- Coverage   94.50%   94.36%   -0.15%     
==========================================
  Files         212      212              
  Lines        9071     9071              
  Branches     1789     1813      +24     
==========================================
- Hits         8573     8560      -13     
- Misses        498      511      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

fengmk2 and others added 3 commits December 4, 2026 21:34
The test jobs call egg-bin and the database scripts directly, not through
the npm scripts, so they skipped `vp dotenv exec`. Run them through it, so
CI validates its CNPMCORE_* values against .env.schema before the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The database step runs in the background right after checkout, before the
install, so node_modules/.bin/vp does not exist yet. Only the test step,
which runs after the install, goes through vp dotenv exec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This preview counts every declared item in `vp dotenv check`, and
`vp dotenv init` keeps a server schema public by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant