@@ -213,6 +213,7 @@ await copyBrowserClientFiles();
213213await createBrowserEntryFiles ( ) ;
214214await patchModuleAugmentations ( ) ;
215215await patchChaiTypeReference ( ) ;
216+ await patchMockerHoistedModule ( ) ;
216217const pluginExports = await createPluginExports ( ) ;
217218await mergePackageJson ( pluginExports ) ;
218219await validateExternalDeps ( ) ;
@@ -1906,6 +1907,41 @@ async function patchChaiTypeReference() {
19061907 console . log ( ' Added /// <reference types="chai" /> to @vitest/expect/index.d.ts' ) ;
19071908}
19081909
1910+ /**
1911+ * Patch the vitest mocker to recognize @voidzero-dev packages as valid sources for vi/vitest.
1912+ *
1913+ * The mocker's hoistMocks function checks if `vi` is imported from the 'vitest' module.
1914+ * When users import from '@voidzero-dev/vite-plus/test' instead, the mocker doesn't
1915+ * recognize it and throws "There are some problems in resolving the mocks API".
1916+ *
1917+ * This patch modifies the equality check to also accept our package names:
1918+ * - @voidzero-dev/vite-plus/test
1919+ * - @voidzero-dev/vite-plus-test
1920+ */
1921+ async function patchMockerHoistedModule ( ) {
1922+ console . log ( '\nPatching vitest mocker to recognize @voidzero-dev packages...' ) ;
1923+
1924+ const mockerPath = join ( distDir , '@vitest/mocker/node.js' ) ;
1925+ let content = await readFile ( mockerPath , 'utf-8' ) ;
1926+
1927+ // Find and replace the hoistedModule check
1928+ // Original: if (hoistedModule === source) {
1929+ // New: if (hoistedModule === source || source === "@voidzero-dev/vite-plus/test" || source === "@voidzero-dev/vite-plus-test") {
1930+ const originalCheck = 'if (hoistedModule === source) {' ;
1931+ const newCheck =
1932+ 'if (hoistedModule === source || source === "@voidzero-dev/vite-plus/test" || source === "@voidzero-dev/vite-plus-test") {' ;
1933+
1934+ if ( ! content . includes ( originalCheck ) ) {
1935+ console . log ( ' Warning: Could not find hoistedModule check to patch' ) ;
1936+ return ;
1937+ }
1938+
1939+ content = content . replace ( originalCheck , newCheck ) ;
1940+
1941+ await writeFile ( mockerPath , content , 'utf-8' ) ;
1942+ console . log ( ' Patched hoistMocks to recognize @voidzero-dev packages' ) ;
1943+ }
1944+
19091945/**
19101946 * Create /plugins/* exports for all copied @vitest/* packages.
19111947 * This allows pnpm overrides to redirect @vitest/* imports to our copied versions.
0 commit comments