Skip to content

feat(create): set VP_CREATE=1 when running templates and generators #3589

Description

@yuikisaito

Description

Description

Problem

Currently, when running third-party scaffolding CLIs (create-void, create-vue, create-vite, etc.) or custom generators via vp create, there is no official, reliable way for the templates to determine whether they were invoked via vp create or directly on their own (such as via pnpm create <pkg> or npm create <pkg>).

While Vite+ sets several environment variables for child processes, none of them are sufficient for identifying vp create.

  • VP_USER_AGENT=vp/<version> (feat(cli): advertise VP_USER_AGENT to child processes #1958): This is set commonly across all vp / vpr / vpx subcommands and does not include the subcommand name, making it impossible to distinguish between vp create and vp dlx / vp exec / vp run.
  • VP_PACKAGE_MANAGER (packages/cli/src/create/templates/remote.ts): This is an internal implementation detail used to pass the package manager selection to vp dlx, and is not an official contract for detection purposes.
  • VP_CREATE_INTERACTIVE (packages/cli/src/create/discovery.ts): This is only set for local Bingo generators.

As a result, templates are forced to rely on heuristics that depend on internal implementation details, such as checking a combination of VP_USER_AGENT and VP_PACKAGE_MANAGER, which makes them fragile.

Use Cases and Motivation

By providing VP_CREATE=1 as a public contract, templates and initializers can safely optimize behaviors such as:

  1. Default Toolchain Selection:
    In initializers that support multiple toolchains (Vite / Vite+, etc.), when VP_CREATE=1 is present, they can default to Vite+ configurations unless an explicit flag is provided (e.g., --toolchain vite).
  2. Avoiding Redundant Post-Scaffold Processing:
    If VP_CREATE=1 is detected, templates can suppress redundant install executions, writing conflicting package manager configurations, duplicate prompts, and misleading completion messages.
  3. Consistency Across All Template Types:
    A unified execution context determination becomes possible across built-in templates, bundled templates, local generators, and remote (create-*) templates.

If consensus is reached, I would like to submit a pull request to implement this feature.

Suggested solution

Proposed Specification

When vp create executes a template or generator command, it sets the environment variable VP_CREATE=1 for the child process.

  • Target: All template / generator processes launched from vp create (builtin, bundled, generator, and remote)
  • Value: '1' (conforming to the naming and value conventions of existing variables such as VP_FORCE_MIGRATE=1, VP_SKIP_INSTALL=1, and VP_CLI_TEST=1)
  • Even if VP_CREATE is already set in the parent process, it is explicitly set to '1' within the execution context of vp create.

Implementation Direction

Add VP_CREATE: '1' to the base environment variables envs constructed within discoverTemplate() in packages/cli/src/create/discovery.ts.

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Confirm this request is for Vite+ itself and not for Vite, Vitest, tsdown, Rolldown, or Oxc.
  • Check that there isn't already an issue requesting the same feature.

Activity

  1. voidzero-bot commented on Nov 27, 2026

    @voidzero-bot
    Contributor
    • Reproduced: Skipped — this is a feature request (feat(create)), not a bug report, so there is no incorrect behavior to reproduce. The feature's factual premise was nevertheless empirically confirmed: no VP_CREATE variable reaches template child processes on current main.
    • Exploration: Partial — source inspection plus a live probe of a template's environment via vp create confirmed the described gap.
    • Unit Test: No — this stage was reproduction/classification only; no fix was attempted, so no test was added.
    • Priority: Priority P3: minor bug. This is an enhancement request affecting a specific audience (third-party template/generator authors), not a broken core workflow — existing heuristics (e.g. checking VP_USER_AGENT plus VP_PACKAGE_MANAGER) currently work as a fragile workaround, so there is no urgent user-facing breakage.

    vp create never sets VP_CREATE for template/generator child processes in any template type (builtin, bundled, generator, or remote), which matches the issue's analysis exactly. The base environment for all template types is built in one place — discoverTemplate() in packages/cli/src/create/discovery.ts (currently { ...process.env } plus a PATH prepend) — and none of the existing VP_* variables is a reliable vp create-specific signal: VP_USER_AGENT is identical across all vp subcommands, VP_PACKAGE_MANAGER is an internal handoff to vp dlx, VP_CREATE_INTERACTIVE only covers local Bingo generators, and VP_RAW_SUBCOMMAND only exists when the global Rust CLI delegates (it is absent when the local JS CLI runs directly, e.g. via npx vite-plus).

    I wasn't able to find a fix, but I identified some areas that may be relevant. The single envs construction point in discoverTemplate() (packages/cli/src/create/discovery.ts) is exactly where the requested VP_CREATE: '1' would need to be added to cover all four template types, and packages/cli/src/create/templates/remote.ts layers extras (like VP_PACKAGE_MANAGER) on top of those base envs. packages/cli/src/create/__tests__/discovery.spec.ts (which already asserts VP_CREATE_INTERACTIVE) is the natural place for coverage.

    Full Triage Report

    Triage Report — Issue #3589

    Title: feat(create): set VP_CREATE=1 when running templates and generators
    Author: yuikisaito
    Issue type: Feature request (label: pending triage, requested as feat(create))
    Step: reproduce
    Date: 2026-11-27

    1. Issue Summary

    The reporter requests that vp create export VP_CREATE=1 to every template / generator child process (builtin, bundled, generator/bingo, and remote/create-*), so templates can reliably detect that they were invoked through vp create (as opposed to pnpm create, npm create, vp dlx, etc.). They claim that no existing variable serves this purpose today, and propose adding VP_CREATE: '1' to the base envs built in discoverTemplate() in packages/cli/src/create/discovery.ts.

    Expected (requested) behavior: template/generator child processes see VP_CREATE=1 in their environment.

    Actual behavior (claimed): no VP_CREATE variable is set; the available VP_* variables (VP_USER_AGENT, VP_PACKAGE_MANAGER, VP_CREATE_INTERACTIVE) are either common to all vp subcommands, internal implementation details, or only set for local Bingo generators.

    2. Environment

    • Checkout: /home/runner/work/vite-plus/vite-plus (branch triagebot/fix-3589)
    • vp (global Rust CLI on PATH): v1.8.0, local vite-plus v1.8.0 (vite 8.3.8, rolldown 1.2.19, vitest 5.1.1, tsrs 7.1.0-beta.tsrs5)
    • Node.js v24.22.3, pnpm v12.11.2
    • OS: Linux x64 (GitHub Actions runner)

    3. Source Inspection

    • grep -rn "VP_CREATE" over packages/cli/src and crates/: the only VP_CREATE* matches are VP_CREATE_INTERACTIVE (set only for local Bingo generators, packages/cli/src/create/discovery.ts:192). No VP_CREATE is set anywhere.
    • discoverTemplate() (packages/cli/src/create/discovery.ts:95-103) builds the base envs as { ...process.env } plus the download package-manager bin prefix prepended to PATH (prependToPathToEnvs), then returns it unchanged for builtin, bundled, GitHub/degit-remote, local (node-run) and npm-remote template types. Confirms the reporter's implementation analysis: adding the variable there would cover all four types.
    • packages/cli/src/create/templates/remote.ts:88-93: remote create-* templates additionally receive VP_PACKAGE_MANAGER — an internal handoff to vp dlx (not a detection contract, exactly as the issue states).
    • VP_RAW_SUBCOMMAND (crates/vp_global_cli/src/js_executor.rs:389) is set only by the global Rust CLI when delegating to the local JS CLI; it is an internal handoff variable, and it is absent when the local vite-plus JS CLI is invoked directly (package.json scripts / npx vite-plus). So even the observable VP_RAW_SUBCOMMAND=create is not a usable contract for templates.

    4. Reproduction

    Reproduction path: /tmp/vite-plus-triage/gh-3589/repro — a minimal monorepo with a local template package declared via create.templates that dumps all VP_* variables it sees.

    Files:

    • package.json ({ "name": "gh-3589-repro", "private": true })
    • pnpm-workspace.yaml (packages: ["tools/*"])
    • vite.config.ts with create.templates: [{ name: 'env-probe', template: './tools/env-probe', description: 'prints VP_* env vars' }]
    • tools/env-probe/package.json (bin: ./bin/probe.js)
    • tools/env-probe/bin/probe.js — writes the VP_* subset of process.env plus cwd to /tmp/vite-plus-triage/gh-3589/probe-result.json and prints it.

    Commands attempted

    1. vp create env-probe --no-interactive (global vp on PATH delegating to the local JS CLI) — template ran; probe output:

      {
        "cwd": ".../repro/tools",
        "vp": {
          "VP_CLI_BIN": "~/.vite-plus/local-dev-.../bin/vp",
          "VP_PATH_INJECTED_TOOLS": "node",
          "VP_RAW_SUBCOMMAND": "create",
          "VP_USER_AGENT": "vp/1.8.0"
        }
      }

      No VP_CREATE is present. vp create subsequently failed with "Command exited with code 2" because the probe intentionally writes no scaffolded package.json (project-dir detection fails) — expected for this probe and unrelated to the reported gap.

    2. Control 1 — same command through the local JS CLI directly (node $VITE_PLUS_REPO/packages/cli/dist/bin.js create env-probe --no-interactive), i.e. the path taken by package.json scripts / npx vite-plus:

      { "vp": { "VP_USER_AGENT": "vp/1.8.0" } }

      Confirms: VP_USER_AGENT is generic (no subcommand info), and even VP_RAW_SUBCOMMAND disappears without the global CLI — so it cannot serve as a detection contract either.

    3. Control 2 — baseline: node tools/env-probe/bin/probe.js with no vp involved: { "vp": {} } (clean shell has no VP_* variables), ruling out that the observed variables come from the runner shell.

    5. Result

    Not reproducible as a bug / skipped — this is a feature request (not-actionable for the reproduce stage per the triage skill: it is not a bug report but a well-specified new-functionality request).

    That said, the feature's factual premise was empirically confirmed on the current checkout: template/generator child processes launched by vp create receive no VP_CREATE variable in any template type, and none of the existing VP_* variables provides a reliable, documented vp create-specific signal:

    • VP_USER_AGENT is set for all vp subcommands (observed identical for the create run; no subcommand component),
    • VP_RAW_SUBCOMMAND exists only when the global Rust CLI delegates (absent on the direct-JS-CLI path) and is an internal handoff,
    • VP_PACKAGE_MANAGER is an internal vp dlx handoff,
    • VP_CREATE_INTERACTIVE only covers local Bingo generators.

    6. Observations Useful for Diagnosis (no fix proposed here)

    • The single envs construction point for all template types is in discoverTemplate() (packages/cli/src/create/discovery.ts), matching the issue's proposed implementation direction; remote.ts merges extra vars on top of these base envs.
    • Existing nearby tests: packages/cli/src/create/__tests__/discovery.spec.ts (e.g. expect(templateInfo.envs.VP_CREATE_INTERACTIVE).toBe('1')) is the natural place to add coverage for VP_CREATE.
    • Value convention '1' matches VP_SKIP_INSTALL=1 / VP_FORCE_MIGRATE=1 / VP_CLI_TEST=1 as stated in the issue.
    • This feature would live entirely in vite-plus (packages/cli), independent of the global vp CLI.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  2. liangmiQwQ commented on Nov 28, 2026

    @liangmiQwQ
    Collaborator

    @yuikisaito Thanks for this suggestion!

    When adding #1958, we actually have considered about that child processes can't determine whether it is vp dlx or vp create. We eventually assumed that if users already use vp dlx to launch a template CLI, it's also most likely to create a Vite+ project. So we didn't introduce a separate mechanisms here.

    However, your use cases do make sense to me. Personally, I'm also exploring a VP_COMMANDenv var, that makes users know which command is running when loading config. I haven't figured out an exact plan, but it would be great if this could cover your use cases as well.

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

Metadata

Metadata

Fields

Priority

None yet

Start date

None yet

Target date

None yet

Effort

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions