fix: dist-redirect.mjs incorrectly rewrites .js→.ts for node_modules paths containing /src/

The resolver guarded on context.parentURL.includes('/src/') to identify
in-repo source files, but @google/gemini-cli-core installs to
node_modules/@google/gemini-cli-core/dist/src/ which also contains '/src/'.
Relative imports from that dist package (e.g. './config/config.js') were
incorrectly rewritten to './config/config.ts', causing ERR_MODULE_NOT_FOUND
on every test that transitively imports the google-gemini provider.

Fix: add !context.parentURL.includes('/node_modules/') guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikael Hugo 2026-04-25 18:04:23 +02:00
parent 2e32c96fa0
commit a30a7692e3

View file

@ -34,7 +34,7 @@ export function resolve(specifier, context, nextResolve) {
// Also handles local imports — skip rewrite for dist/ paths that are real compiled artifacts.
else if (specifier.endsWith('.js') && (specifier.startsWith('./') || specifier.startsWith('../'))) {
if (context.parentURL && context.parentURL.includes('/src/')) {
if (context.parentURL && context.parentURL.includes('/src/') && !context.parentURL.includes('/node_modules/')) {
if (specifier.includes('/dist/')) {
specifier = specifier.replace('/dist/', '/src/').replace(/\.js$/, '.ts');
} else {