forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirs.ts
33 lines (28 loc) · 1.29 KB
/
dirs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import createDebug from 'debug'
import { fileURLToPath } from 'node:url'
import { dirname, resolve, parse as parsePath } from 'pathe'
import { VUE_I18N_ROUTING_PKG } from './constants'
import { getPackageManagerType, tryResolve } from './utils'
const debug = createDebug('@nuxtjs/i18n:dirs')
export const distDir = dirname(fileURLToPath(import.meta.url))
export const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
const pkgDir = resolve(distDir, '..')
export const pkgModulesDir = resolve(pkgDir, './node_modules')
debug('distDir', distDir)
debug('runtimeDir', runtimeDir)
debug('pkgDir', pkgDir)
debug('pkgModulesDir', pkgModulesDir)
export async function resolveVueI18nRoutingDtsPath(id: string, rootDir: string) {
const pkgMgr = await getPackageManagerType()
const dtsPath = `${VUE_I18N_ROUTING_PKG}/dist/${id}`
const targets = [
// 1st, try to resolve from `node_modules` (hoisted case)
resolve(rootDir, 'node_modules', dtsPath),
// 2nd, try to resolve from `node_modules/@nuxtjs/i18n` (not hoisted case)
resolve(pkgModulesDir, dtsPath)
]
debug(`${VUE_I18N_ROUTING_PKG} resolving from ...`, targets)
const resolved = await tryResolve(VUE_I18N_ROUTING_PKG, targets, pkgMgr, '.d.ts')
const parsed = parsePath(resolved)
return `${parsed.dir}/${parsed.name}`
}