From cecb24c4362d6877ec1bf6d4205ca4e7ceed46a3 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 17 Apr 2025 08:26:22 +0900 Subject: [PATCH 1/2] fix(vite-node): named export should overwrite export all --- packages/vite-node/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite-node/src/client.ts b/packages/vite-node/src/client.ts index b465eb67a8ae..faf1e20e6efa 100644 --- a/packages/vite-node/src/client.ts +++ b/packages/vite-node/src/client.ts @@ -625,7 +625,7 @@ function exportAll(exports: any, sourceModule: any) { } for (const key in sourceModule) { - if (key !== 'default') { + if (key !== 'default' && !(key in exports)) { try { defineExport(exports, key, () => sourceModule[key]) } From a288c1e1820f23ec06947b9b3385a0d21dfb2f60 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 17 Apr 2025 08:42:21 +0900 Subject: [PATCH 2/2] test: add test --- .../core/test/fixtures/named-overwrite-all/dep1.js | 4 ++++ .../core/test/fixtures/named-overwrite-all/dep2.js | 1 + .../core/test/fixtures/named-overwrite-all/main.js | 4 ++++ test/core/test/named-overwrite-all.test.ts | 14 ++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 test/core/test/fixtures/named-overwrite-all/dep1.js create mode 100644 test/core/test/fixtures/named-overwrite-all/dep2.js create mode 100644 test/core/test/fixtures/named-overwrite-all/main.js create mode 100644 test/core/test/named-overwrite-all.test.ts diff --git a/test/core/test/fixtures/named-overwrite-all/dep1.js b/test/core/test/fixtures/named-overwrite-all/dep1.js new file mode 100644 index 000000000000..ccc8eb47f073 --- /dev/null +++ b/test/core/test/fixtures/named-overwrite-all/dep1.js @@ -0,0 +1,4 @@ +export const a = 'dep1-a' +export const b = 'dep1-b' +export const c = 'dep1-c' +export const d = 'dep1-d' diff --git a/test/core/test/fixtures/named-overwrite-all/dep2.js b/test/core/test/fixtures/named-overwrite-all/dep2.js new file mode 100644 index 000000000000..e112aa48c4d2 --- /dev/null +++ b/test/core/test/fixtures/named-overwrite-all/dep2.js @@ -0,0 +1 @@ +export const d = 'dep2-d' diff --git a/test/core/test/fixtures/named-overwrite-all/main.js b/test/core/test/fixtures/named-overwrite-all/main.js new file mode 100644 index 000000000000..860f5fdd95a9 --- /dev/null +++ b/test/core/test/fixtures/named-overwrite-all/main.js @@ -0,0 +1,4 @@ +export const a = 'main-a' +export * from './dep1.js' +export const c = 'main-c' +export * from './dep2.js' diff --git a/test/core/test/named-overwrite-all.test.ts b/test/core/test/named-overwrite-all.test.ts new file mode 100644 index 000000000000..270956704446 --- /dev/null +++ b/test/core/test/named-overwrite-all.test.ts @@ -0,0 +1,14 @@ +import { expect, test } from 'vitest' +// @ts-expect-error no type +import * as lib from './fixtures/named-overwrite-all/main.js' + +test('named exports overwrite export all', async () => { + expect(lib).toMatchInlineSnapshot(` + { + "a": "main-a", + "b": "dep1-b", + "c": "main-c", + "d": "dep1-d", + } + `) +})