From 1a67780308aeac7fac60d822679a73eebd6f3a1d Mon Sep 17 00:00:00 2001 From: Jason Galea Date: Fri, 20 Mar 2026 12:18:40 +1000 Subject: [PATCH] fix(unplugin): prevent file handle leaks in Vitest (#1533) Disable Babel config-file discovery (configFile: false) in runBabelTransform() to stop leaked FILEHANDLE operations during test run, and unref() the setInterval polling timer in configureServer() so it does not block process exit in middleware mode. --- packages/@stylexjs/unplugin/src/core.js | 1 + packages/@stylexjs/unplugin/src/vite.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/@stylexjs/unplugin/src/core.js b/packages/@stylexjs/unplugin/src/core.js index 5e47aac68..29426370e 100644 --- a/packages/@stylexjs/unplugin/src/core.js +++ b/packages/@stylexjs/unplugin/src/core.js @@ -283,6 +283,7 @@ export const unpluginFactory = (userOptions = {}, metaOptions) => { async function runBabelTransform(inputCode, filename, callerName) { const result = await transformAsync(inputCode, { babelrc: false, + configFile: false, filename, presets, plugins: [ diff --git a/packages/@stylexjs/unplugin/src/vite.js b/packages/@stylexjs/unplugin/src/vite.js index 9510369c0..3d0c85494 100644 --- a/packages/@stylexjs/unplugin/src/vite.js +++ b/packages/@stylexjs/unplugin/src/vite.js @@ -87,6 +87,10 @@ function attachViteHooks(plugin) { } catch {} } }, 150); + // Unref the timer so it does not prevent the process from exiting + // (e.g. when Vitest runs the plugin in middleware mode without an + // HTTP server that emits 'close'). + interval.unref(); server.httpServer?.once('close', () => clearInterval(interval)); } },