From 7569be07790c33dd69d542f43d3ef0eaedf2b265 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 16 Mar 2026 15:27:35 +0900 Subject: [PATCH] fix(cli): dynamically scan root .d.ts files from @vitest/browser --- packages/test/build.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/test/build.ts b/packages/test/build.ts index 4ed27b0039..9bb4643a79 100644 --- a/packages/test/build.ts +++ b/packages/test/build.ts @@ -619,21 +619,23 @@ async function copyVitestPackages() { totalCopied += copied; console.log(` -> ${copied} files`); - // Copy root type definition files if they exist - // These include context.d.ts (browser providers), matchers.d.ts (expect.element), - // jest-dom.d.ts (matchers), aria-role.d.ts (ARIARole type used by context.d.ts) - // TODO: consider dynamically scanning root .d.ts files instead of hardcoding, - // since upstream @vitest/browser may add new .d.ts files in future versions. - const rootDtsFiles = ['context.d.ts', 'matchers.d.ts', 'jest-dom.d.ts', 'aria-role.d.ts']; - for (const dtsFile of rootDtsFiles) { - const rootDts = resolve(projectDir, `node_modules/${pkg}/${dtsFile}`); + // Copy root .d.ts files from @vitest/browser package directory. + // These are type definitions that live at the package root (not in dist/), + // e.g. context.d.ts, matchers.d.ts, aria-role.d.ts, utils.d.ts. + // Dynamically scan instead of hardcoding to handle future upstream additions. + if (pkg === '@vitest/browser') { + const pkgRoot = resolve(projectDir, `node_modules/${pkg}`); try { - await stat(rootDts); - await copyFile(rootDts, join(destPkgDir, dtsFile)); - console.log(` + copied ${dtsFile}`); - totalCopied++; + const pkgEntries = await readdir(pkgRoot); + for (const entry of pkgEntries) { + if (entry.endsWith('.d.ts')) { + await copyFile(join(pkgRoot, entry), join(destPkgDir, entry)); + console.log(` + copied ${entry}`); + totalCopied++; + } + } } catch { - // File doesn't exist, skip + // Package root not readable, skip } } }