From e8acd92520b2ed9e8f2ab901c9f0d024d50f4d56 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 22 Jul 2025 19:49:44 +0900 Subject: [PATCH] test(optimizer): add test for cjs interop with namespace imports --- playground/optimize-deps/cjs-dynamic.js | 6 +++++- playground/optimize-deps/cjs.js | 7 ++++++- .../optimize-deps/dep-cjs-compiled-from-cjs/index.js | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/playground/optimize-deps/cjs-dynamic.js b/playground/optimize-deps/cjs-dynamic.js index 616dffae4d6c0c..69c11051692272 100644 --- a/playground/optimize-deps/cjs-dynamic.js +++ b/playground/optimize-deps/cjs-dynamic.js @@ -22,7 +22,11 @@ } const cjsFromCJS = await import('@vitejs/test-dep-cjs-compiled-from-cjs') - if (typeof cjsFromCJS.default === 'function') { + if ( + typeof cjsFromCJS.default === 'function' && + typeof cjsFromCJS !== 'function' && + cjsFromCJS.bar === 'bar' + ) { text('.cjs-dynamic-dep-cjs-compiled-from-cjs', 'ok') } diff --git a/playground/optimize-deps/cjs.js b/playground/optimize-deps/cjs.js index f0201008647889..cd26c373a4765a 100644 --- a/playground/optimize-deps/cjs.js +++ b/playground/optimize-deps/cjs.js @@ -7,6 +7,7 @@ import { Socket } from 'phoenix' import clip from 'clipboard' import cjsFromESM from '@vitejs/test-dep-cjs-compiled-from-esm' import cjsFromCJS from '@vitejs/test-dep-cjs-compiled-from-cjs' +import * as cjsFromCJSNamespace from '@vitejs/test-dep-cjs-compiled-from-cjs' // Test exporting a name that was already imported export { useState } from 'react' @@ -25,7 +26,11 @@ if (typeof cjsFromESM === 'function') { text('.cjs-dep-cjs-compiled-from-esm', 'ok') } -if (typeof cjsFromCJS === 'function') { +if ( + typeof cjsFromCJS === 'function' && + typeof cjsFromCJSNamespace !== 'function' && + cjsFromCJSNamespace.bar === 'bar' +) { text('.cjs-dep-cjs-compiled-from-cjs', 'ok') } diff --git a/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js b/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js index 38d4c85c7c33ce..bb78ebd1f162bd 100644 --- a/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js +++ b/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js @@ -2,4 +2,5 @@ function foo() { return 'foo' } +foo.bar = 'bar' module.exports = foo