From 585d4972831865f7d4bdb4f2ac523c1328bccbdc Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Wed, 24 Jun 2026 08:48:01 +0000 Subject: [PATCH] fix(ingestion): treat server/plugins and server/tasks as Nitro runtime isNitroServerRuntimeFile only matched server/api, server/routes, and server/middleware. Nitro also auto-imports server/utils into server/plugins and (since Nitro 2.6) server/tasks, so callers there were misrouted to the client composable map. Extend the prefix set (now a named constant) to cover them. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01T4W25WLfYD1JNy8icxeLPU --- .../languages/typescript/nuxt-auto-imports.ts | 19 ++++++++++++++----- .../typescript/nuxt-auto-imports.test.ts | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gitnexus/src/core/ingestion/languages/typescript/nuxt-auto-imports.ts b/gitnexus/src/core/ingestion/languages/typescript/nuxt-auto-imports.ts index 905ddfe63..f42efdf20 100644 --- a/gitnexus/src/core/ingestion/languages/typescript/nuxt-auto-imports.ts +++ b/gitnexus/src/core/ingestion/languages/typescript/nuxt-auto-imports.ts @@ -132,13 +132,22 @@ export function getNuxtAutoImportEntry( return config.clientByLocalName.get(localName); } +/** + * Directories whose files run in the Nitro server context and so receive + * `server/utils` auto-imports without an explicit import: API routes, server + * routes, middleware, plugins, and (Nitro 2.6+) tasks. + */ +const NITRO_RUNTIME_DIR_PREFIXES = [ + 'server/api/', + 'server/routes/', + 'server/middleware/', + 'server/plugins/', + 'server/tasks/', +] as const; + export function isNitroServerRuntimeFile(filePath: string): boolean { const normalized = filePath.replace(/\\/g, '/'); - return ( - normalized.startsWith('server/api/') || - normalized.startsWith('server/routes/') || - normalized.startsWith('server/middleware/') - ); + return NITRO_RUNTIME_DIR_PREFIXES.some((prefix) => normalized.startsWith(prefix)); } // ---- .nuxt/imports.d.ts ----------------------------------------------------- diff --git a/gitnexus/test/unit/scope-resolution/typescript/nuxt-auto-imports.test.ts b/gitnexus/test/unit/scope-resolution/typescript/nuxt-auto-imports.test.ts index 7fd27b4db..ca31dc76e 100644 --- a/gitnexus/test/unit/scope-resolution/typescript/nuxt-auto-imports.test.ts +++ b/gitnexus/test/unit/scope-resolution/typescript/nuxt-auto-imports.test.ts @@ -157,6 +157,8 @@ describe('isNitroServerRuntimeFile', () => { expect(isNitroServerRuntimeFile('server/api/users.ts')).toBe(true); expect(isNitroServerRuntimeFile('server/routes/feed.ts')).toBe(true); expect(isNitroServerRuntimeFile('server/middleware/auth.ts')).toBe(true); + expect(isNitroServerRuntimeFile('server/plugins/init.ts')).toBe(true); + expect(isNitroServerRuntimeFile('server/tasks/cleanup.ts')).toBe(true); expect(isNitroServerRuntimeFile('server/utils/auth.ts')).toBe(false); expect(isNitroServerRuntimeFile('pages/index.ts')).toBe(false); });