Skip to content
Open
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
11 changes: 10 additions & 1 deletion cli/utils/db.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -34,14 +35,22 @@ 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'))
const paths = tsconfig.compilerOptions?.paths || {}
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 {
Expand Down