Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to improve vitest-pool-workers for the cjs module resolution #6661

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/vitest-pool-workers/src/pool/module-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,23 @@ async function viteResolve(
referrer: string,
isRequire: boolean
): Promise<string> {
// note: using require.resolve doesn't seem to work well on windows, so there we skip this more proper cjs module resolution
if (isRequire && !isWindows) {
try {
// we use the built in require.resolve method to resolve required/cjs modules
return require.resolve(specifier, {
paths: [platformPath.dirname(referrer)],
});
} catch {}
}

// we repurpose pluginContainer.resolveId for the esm module resolution
// when bumping to vite 6 we should instead use the createIdResolver method instead
// (which we can use for both cjs and esm)
const resolved = await vite.pluginContainer.resolveId(specifier, referrer, {
ssr: true,
// https://github.com/vitejs/vite/blob/v5.1.4/packages/vite/src/node/plugins/resolve.ts#L178-L179
custom: { "node-resolve": { isRequire } },
});

if (resolved === null) {
// Vite's resolution algorithm doesn't apply Node resolution to specifiers
// starting with a dot. Unfortunately, the `@prisma/client` package includes
Expand Down
Loading
Loading