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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T4W25WLfYD1JNy8icxeLPU
This commit is contained in:
Gergo Magyar 2026-06-24 08:48:01 +00:00
parent 7d8743327a
commit 585d497283
2 changed files with 16 additions and 5 deletions

View file

@ -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 -----------------------------------------------------

View file

@ -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);
});