Skip to content

Commit 5ba0d91

Browse files
authored
fix(vite-node): named export should overwrite export all (#7846)
1 parent 37854a3 commit 5ba0d91

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

packages/vite-node/src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ function exportAll(exports: any, sourceModule: any) {
625625
}
626626

627627
for (const key in sourceModule) {
628-
if (key !== 'default') {
628+
if (key !== 'default' && !(key in exports)) {
629629
try {
630630
defineExport(exports, key, () => sourceModule[key])
631631
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const a = 'dep1-a'
2+
export const b = 'dep1-b'
3+
export const c = 'dep1-c'
4+
export const d = 'dep1-d'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const d = 'dep2-d'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const a = 'main-a'
2+
export * from './dep1.js'
3+
export const c = 'main-c'
4+
export * from './dep2.js'
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect, test } from 'vitest'
2+
// @ts-expect-error no type
3+
import * as lib from './fixtures/named-overwrite-all/main.js'
4+
5+
test('named exports overwrite export all', async () => {
6+
expect(lib).toMatchInlineSnapshot(`
7+
{
8+
"a": "main-a",
9+
"b": "dep1-b",
10+
"c": "main-c",
11+
"d": "dep1-d",
12+
}
13+
`)
14+
})

0 commit comments

Comments
 (0)