Skip to content

Commit bf2bbce

Browse files
kazuponfengmk2
andauthored
fix(cli): dynamically scan root .d.ts files from @vitest/browser (#944)
## Summary - Replace hardcoded list of root `.d.ts` files with dynamic `readdir` scan for `@vitest/browser` package - This ensures newly added type definition files (like `aria-role.d.ts`, `utils.d.ts`) are automatically included without requiring manual updates to the build script related #909 in the TODO. ## Test ways - Run `node --import @oxc-node/core/register ./build.ts` in `packages/test` and verify only `@vitest/browser` root `.d.ts` files are copied (aria-role.d.ts, context.d.ts, jest-dom.d.ts, matchers.d.ts, utils.d.ts) - Verify `vp pack` succeeds in a library project that imports `UserConfig` from `vite-plus` Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 2a393e7 commit bf2bbce

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

packages/test/build.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -619,21 +619,23 @@ async function copyVitestPackages() {
619619
totalCopied += copied;
620620
console.log(` -> ${copied} files`);
621621

622-
// Copy root type definition files if they exist
623-
// These include context.d.ts (browser providers), matchers.d.ts (expect.element),
624-
// jest-dom.d.ts (matchers), aria-role.d.ts (ARIARole type used by context.d.ts)
625-
// TODO: consider dynamically scanning root .d.ts files instead of hardcoding,
626-
// since upstream @vitest/browser may add new .d.ts files in future versions.
627-
const rootDtsFiles = ['context.d.ts', 'matchers.d.ts', 'jest-dom.d.ts', 'aria-role.d.ts'];
628-
for (const dtsFile of rootDtsFiles) {
629-
const rootDts = resolve(projectDir, `node_modules/${pkg}/${dtsFile}`);
622+
// Copy root .d.ts files from @vitest/browser package directory.
623+
// These are type definitions that live at the package root (not in dist/),
624+
// e.g. context.d.ts, matchers.d.ts, aria-role.d.ts, utils.d.ts.
625+
// Dynamically scan instead of hardcoding to handle future upstream additions.
626+
if (pkg === '@vitest/browser') {
627+
const pkgRoot = resolve(projectDir, `node_modules/${pkg}`);
630628
try {
631-
await stat(rootDts);
632-
await copyFile(rootDts, join(destPkgDir, dtsFile));
633-
console.log(` + copied ${dtsFile}`);
634-
totalCopied++;
629+
const pkgEntries = await readdir(pkgRoot);
630+
for (const entry of pkgEntries) {
631+
if (entry.endsWith('.d.ts')) {
632+
await copyFile(join(pkgRoot, entry), join(destPkgDir, entry));
633+
console.log(` + copied ${entry}`);
634+
totalCopied++;
635+
}
636+
}
635637
} catch {
636-
// File doesn't exist, skip
638+
// Package root not readable, skip
637639
}
638640
}
639641
}

0 commit comments

Comments
 (0)