vp-plugin-config-repro

0
0
0
TypeScript
public

Reproduction: Plugin config hook tasks not recognized by vp run

Problem

When a Vite plugin adds run.tasks via the config hook, vp run does not recognize those tasks. Only tasks defined statically in vite.config.ts or in package.json scripts are visible.

This happens because vp run uses vite_static_config (AST-based static analysis) to extract the run field from vite.config.ts. When the run field is not statically present in the config object, the static analyzer returns None and skips the NAPI fallback (resolveConfig), which means plugin config hooks never execute.

Setup

vp install

Steps to Reproduce

1. Plugin-defined tasks (FAILS)

The default vite.config.ts uses a plugin that adds tasks via the config hook:

function myTaskPlugin() {
  return {
    name: 'my-task-plugin',
    config() {
      return {
        run: {
          tasks: {
            'build:prod': { command: 'echo "build:prod from plugin"' },
            'build:dev': { command: 'echo "build:dev from plugin"' },
          },
        },
      };
    },
  };
}

export default defineConfig({
  plugins: [myTaskPlugin()],
});
vp run
# Expected: build:prod, build:dev, hello, greet
# Actual:   hello, greet (plugin tasks missing)

vp run build:prod
# Expected: executes the task
# Actual:   Task "build:prod" not found.

2. Static config (WORKS)

Rename to use the static config for comparison:

mv vite.config.ts vite.config.plugin.ts
mv vite.config.static.ts vite.config.ts
vp run
# Output: build:prod, hello, greet (all visible)

# Restore
mv vite.config.ts vite.config.static.ts
mv vite.config.plugin.ts vite.config.ts

Environment

  • vite-plus: v0.1.14
  • Node.js: v24.14.1
  • pnpm: v10.33.0
v0.3.3[beta]