Skip to content

Commit

Permalink
fix: cannot resolve message for jit compilation (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Sep 8, 2023
1 parent fc67afb commit 9a24c86
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
VUE_ROUTER_BRIDGE_PKG,
VUE_I18N_ROUTING_PKG,
SHARED_PKG,
MESSAGE_COMPILER_PKG
MESSAGE_COMPILER_PKG,
CORE_BASE_PKG
} from './constants'
import { pkgModulesDir } from './dirs'
import { tryResolve, getLayerRootDirs, getPackageManagerType } from './utils'
Expand All @@ -31,10 +32,16 @@ export async function setupAlias(nuxt: Nuxt, options: NuxtI18nOptions) {
nuxt.options.build.transpile.push(SHARED_PKG)
debug('@intlify/shared alias', nuxt.options.alias[SHARED_PKG])

// resolve @intlify/message-compiler
nuxt.options.alias['@intlify/message-compiler'] = await resolveMessageCompilerAlias(pkgModulesDir, nuxt, pkgMgr)
nuxt.options.build.transpile.push(MESSAGE_COMPILER_PKG)
debug('@intlify/message-compiler alias', nuxt.options.alias[MESSAGE_COMPILER_PKG])

// resolve @intlify/core-base
nuxt.options.alias['@intlify/core-base'] = await resolveCoreBaseAlias(pkgModulesDir, nuxt, pkgMgr)
nuxt.options.build.transpile.push(CORE_BASE_PKG)
debug('@intlify/core-base alias', nuxt.options.alias[CORE_BASE_PKG])

// resolve @intlify/vue-router-bridge
nuxt.options.alias[VUE_ROUTER_BRIDGE_PKG] = await resolveVueRouterBridgeAlias(pkgModulesDir, nuxt, pkgMgr)
nuxt.options.build.transpile.push(VUE_ROUTER_BRIDGE_PKG)
Expand All @@ -59,6 +66,8 @@ export async function setupAlias(nuxt: Nuxt, options: NuxtI18nOptions) {
* - `vue-i18n`
* - `vue-i18n-routing`
* - `@intlify/shared`
* - `@intlify/message-compiler`
* - `@intlify/core-base`
* - `@intlify/vue-i18n-bridge`
* - `@intlify/vue-router-bridge`
*/
Expand Down Expand Up @@ -116,6 +125,24 @@ export async function resolveSharedAlias(pkgModulesDir: string, nuxt: Nuxt, pkgM
return tryResolve(SHARED_PKG, targets, pkgMgr)
}

export async function resolveCoreBaseAlias(pkgModulesDir: string, nuxt: Nuxt, pkgMgr: PackageManager) {
const { rootDir, workspaceDir } = nuxt.options
const modulePath = `${CORE_BASE_PKG}/dist/core-base.mjs` as const
const targets = [
// for Nuxt layer
...getLayerRootDirs(nuxt).map(root => resolve(root, 'node_modules', modulePath)),
// try to resolve from `node_modules/@nuxtjs/i18n` (not hoisted case)
resolve(pkgModulesDir, modulePath),
// try to resolve from `node_modules` (hoisted case)
resolve(rootDir, 'node_modules', modulePath),
// workspace directories
resolve(workspaceDir, 'node_modules', modulePath)
]
debug(`${CORE_BASE_PKG} resolving from ...`, targets)

return tryResolve(CORE_BASE_PKG, targets, pkgMgr)
}

export async function resolveMessageCompilerAlias(pkgModulesDir: string, nuxt: Nuxt, pkgMgr: PackageManager) {
const { rootDir, workspaceDir } = nuxt.options
const modulePath = `${MESSAGE_COMPILER_PKG}/dist/message-compiler.mjs` as const
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const NUXT_I18N_MODULE_ID = '@nuxtjs/i18n' as const
export const VUE_I18N_PKG = 'vue-i18n' as const
export const SHARED_PKG = '@intlify/shared' as const
export const MESSAGE_COMPILER_PKG = '@intlify/message-compiler' as const
export const CORE_BASE_PKG = '@intlify/core-base' as const
export const VUE_I18N_BRIDGE_PKG = '@intlify/vue-i18n-bridge' as const
export const VUE_ROUTER_BRIDGE_PKG = '@intlify/vue-router-bridge' as const
export const VUE_I18N_ROUTING_PKG = 'vue-i18n-routing' as const
Expand Down

0 comments on commit 9a24c86

Please sign in to comment.