Skip to content

Commit c7002cd

Browse files
committed
fix: revert vitePlugins return type to T | undefined
1 parent 245f348 commit c7002cd

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ test('should keep vitest exports stable', () => {
3636
expect(defaultBrowserPort).toBeDefined();
3737
});
3838

39-
test('vitePlugins returns empty array when VP_COMMAND is unset', () => {
39+
test('vitePlugins returns undefined when VP_COMMAND is unset', () => {
4040
delete process.env.VP_COMMAND;
4141
const result = vitePlugins(() => [{ name: 'test' }]);
42-
expect(result).toEqual([]);
42+
expect(result).toBeUndefined();
4343
});
4444

45-
test('vitePlugins returns empty array when VP_COMMAND is empty string', () => {
45+
test('vitePlugins returns undefined when VP_COMMAND is empty string', () => {
4646
process.env.VP_COMMAND = '';
4747
const result = vitePlugins(() => [{ name: 'test' }]);
48-
expect(result).toEqual([]);
48+
expect(result).toBeUndefined();
4949
});
5050

5151
test.each(['dev', 'build', 'test', 'preview'])(
@@ -58,11 +58,11 @@ test.each(['dev', 'build', 'test', 'preview'])(
5858
);
5959

6060
test.each(['lint', 'fmt', 'check', 'pack', 'install', 'run'])(
61-
'vitePlugins returns empty array when VP_COMMAND is %s',
61+
'vitePlugins returns undefined when VP_COMMAND is %s',
6262
(cmd) => {
6363
process.env.VP_COMMAND = cmd;
6464
const result = vitePlugins(() => [{ name: 'my-plugin' }]);
65-
expect(result).toEqual([]);
65+
expect(result).toBeUndefined();
6666
},
6767
);
6868

@@ -76,10 +76,10 @@ test('vitePlugins supports async callback', async () => {
7676
expect(await result).toEqual([{ name: 'async-plugin' }]);
7777
});
7878

79-
test('vitePlugins returns empty array for async callback when skipped', () => {
79+
test('vitePlugins returns undefined for async callback when skipped', () => {
8080
process.env.VP_COMMAND = 'lint';
8181
const result = vitePlugins(async () => {
8282
return [{ name: 'async-plugin' }];
8383
});
84-
expect(result).toEqual([]);
84+
expect(result).toBeUndefined();
8585
});

packages/cli/src/define-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export function defineConfig(config: ViteUserConfigExport): ViteUserConfigExport
4747
return viteDefineConfig(config);
4848
}
4949

50-
export function vitePlugins<T>(cb: () => T): T | [] {
50+
export function vitePlugins<T>(cb: () => T): T | undefined {
5151
const cmd = process.env.VP_COMMAND;
5252
if (cmd === 'dev' || cmd === 'build' || cmd === 'test' || cmd === 'preview') {
5353
return cb();
5454
}
55-
return [];
55+
return undefined;
5656
}

0 commit comments

Comments
 (0)