Skip to content

Commit b356a15

Browse files
committed
fix: load plugins by default when VP_COMMAND is unset
When running vitest directly or via the VS Code extension, VP_COMMAND is not set. Default to loading plugins in this case for compatibility. Use a blocklist (NON_VITE_COMMANDS) instead of an allowlist so that unknown or unset commands load plugins by default.
1 parent 7009afb commit b356a15

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/cli/src/__tests__/index.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test.each(['dev', 'build', 'test', 'preview'])(
7272
},
7373
);
7474

75-
test.each(['lint', 'fmt', 'check', 'pack', 'install', 'run'])(
75+
test.each(['lint', 'fmt', 'check', 'pack', 'install'])(
7676
'defineConfig skips plugins factory when VP_COMMAND is %s',
7777
(cmd) => {
7878
process.env.VP_COMMAND = cmd;
@@ -85,14 +85,13 @@ test.each(['lint', 'fmt', 'check', 'pack', 'install', 'run'])(
8585
},
8686
);
8787

88-
test('defineConfig skips plugins factory when VP_COMMAND is unset', () => {
88+
test('defineConfig executes plugins factory when VP_COMMAND is unset', () => {
8989
delete process.env.VP_COMMAND;
90-
const factoryFn = vi.fn(() => [{ name: 'should-not-load' }]);
9190
const config = defineConfig({
92-
plugins: factoryFn,
91+
plugins: () => [{ name: 'no-vp-plugin' }],
9392
});
94-
expect(factoryFn).not.toHaveBeenCalled();
95-
expect(config.plugins?.length).toBe(0);
93+
expect(config.plugins?.length).toBe(1);
94+
expect((config.plugins?.[0] as { name: string })?.name).toBe('no-vp-plugin');
9695
});
9796

9897
test('defineConfig handles function config with plugins factory', () => {

packages/cli/src/define-config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,21 @@ export function defineConfig(config: VPUserConfigExport): VPUserConfigExport {
6868
return viteDefineConfig(config as UserConfig);
6969
}
7070

71-
const VITE_COMMANDS = new Set(['dev', 'build', 'test', 'preview']);
71+
const NON_VITE_COMMANDS = new Set(['lint', 'fmt', 'check', 'pack', 'install']);
7272

73-
function isViteCommand(): boolean {
74-
return VITE_COMMANDS.has(process.env.VP_COMMAND ?? '');
73+
function shouldLoadPlugins(): boolean {
74+
const cmd = process.env.VP_COMMAND;
75+
if (!cmd) {
76+
return true;
77+
}
78+
return !NON_VITE_COMMANDS.has(cmd);
7579
}
7680

7781
function resolvePlugins(plugins: PluginOption[] | PluginsFactory): PluginOption[] {
7882
if (typeof plugins !== 'function') {
7983
return plugins;
8084
}
81-
if (!isViteCommand()) {
85+
if (!shouldLoadPlugins()) {
8286
return [];
8387
}
8488

0 commit comments

Comments
 (0)