From 162fa52468eccfb262630c4e243b58e02bedf526 Mon Sep 17 00:00:00 2001 From: onmax Date: Tue, 30 Jun 2026 07:25:29 +0200 Subject: [PATCH] fix(db): resolve extensions in tsconfig aliases --- cli/utils/db.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cli/utils/db.mjs b/cli/utils/db.mjs index 4f0bbcef2..b95208b74 100644 --- a/cli/utils/db.mjs +++ b/cli/utils/db.mjs @@ -1,4 +1,5 @@ import { readFile } from 'node:fs/promises' +import { existsSync } from 'node:fs' import { join, resolve } from 'pathe' import { createStorage } from 'unstorage' import fsDriver from 'unstorage/drivers/fs' @@ -34,6 +35,14 @@ export async function getNextMigrationNumber() { return (lastSequentialMigrationNumber + 1).toString().padStart(4, '0') } +function resolveWithExtensions(path) { + if (existsSync(path)) return path + for (const ext of ['.mjs', '.js', '.ts', '.mts', '.json']) { + if (existsSync(path + ext)) return path + ext + } + return path +} + export async function getTsconfigAliases(cwd) { try { const tsconfig = JSON.parse(await readFile(join(cwd, '.nuxt/tsconfig.json'), 'utf-8')) @@ -41,7 +50,7 @@ export async function getTsconfigAliases(cwd) { const alias = {} for (const [key, values] of Object.entries(paths)) { const resolvedPath = key.endsWith('/*') ? values[0].replace(/\/\*$/, '') : values[0] - alias[key.replace(/\/\*$/, '')] = resolve(join(cwd, '.nuxt'), resolvedPath) + alias[key.replace(/\/\*$/, '')] = resolveWithExtensions(resolve(join(cwd, '.nuxt'), resolvedPath)) } return alias } catch {