diff --git a/packages/unplugin-vue-i18n/package.json b/packages/unplugin-vue-i18n/package.json index 13ca76fa..9d02fe8d 100644 --- a/packages/unplugin-vue-i18n/package.json +++ b/packages/unplugin-vue-i18n/package.json @@ -11,7 +11,8 @@ }, "peerDependencies": { "petite-vue-i18n": "*", - "vue-i18n": "*" + "vue-i18n": "*", + "vue-i18n-bridge": "*" }, "peerDependenciesMeta": { "petite-vue-i18n": { @@ -19,6 +20,9 @@ }, "vue-i18n": { "optional": true + }, + "vue-i18n-bridge": { + "optional": true } }, "dependencies": { diff --git a/packages/unplugin-vue-i18n/src/check.ts b/packages/unplugin-vue-i18n/src/check.ts new file mode 100644 index 00000000..cfddb711 --- /dev/null +++ b/packages/unplugin-vue-i18n/src/check.ts @@ -0,0 +1,11 @@ +// eslint-disable-next-line @typescript-eslint/ban-types +export function checkVueI18nBridgeInstallPackage(debug: Function): boolean { + let ret = false + try { + debug(`vue-i18n-bridge load path: ${require.resolve('vue-i18n-bridge')}`) + ret = true + } catch (e) { + debug(`cannot find 'vue-i18n-bridge'`, e) + } + return ret +} diff --git a/packages/unplugin-vue-i18n/src/index.ts b/packages/unplugin-vue-i18n/src/index.ts index eba8f57f..e0a6c144 100644 --- a/packages/unplugin-vue-i18n/src/index.ts +++ b/packages/unplugin-vue-i18n/src/index.ts @@ -23,6 +23,7 @@ import { parse } from '@vue/compiler-sfc' import { parseVueRequest, VueQuery } from './query' import { createBridgeCodeGenerator } from './legacy' import { getRaw, warn, error, raiseError } from './utils' +import { checkVueI18nBridgeInstallPackage } from './check' import type { UnpluginContextMeta, UnpluginOptions } from 'unplugin' import type { PluginOptions } from './types' @@ -36,6 +37,7 @@ const VIRTUAL_PREFIX = '\0' const debug = createDebug('unplugin-vue-i18n') const installedPkg = checkInstallPackage('@intlify/unplugin-vue-i18n', debug) +const installedVueI18nBridge = checkVueI18nBridgeInstallPackage(debug) export const unplugin = createUnplugin((options = {}, meta) => { debug('plugin options:', options, meta.framework) @@ -93,12 +95,14 @@ export const unplugin = createUnplugin((options = {}, meta) => { } debug('useVueI18nImportName', useVueI18nImportName) + // prettier-ignore const getAliasName = () => - installedPkg === 'petite-vue-i18n' && - isBoolean(useVueI18nImportName) && - useVueI18nImportName - ? 'vue-i18n' - : `${installedPkg}` + installedVueI18nBridge && installedPkg === 'vue-i18n' + ? 'vue-i18n-bridge' + : installedPkg === 'petite-vue-i18n' && isBoolean(useVueI18nImportName) && + useVueI18nImportName + ? 'vue-i18n' + : `${installedPkg}` const esm = isBoolean(options.esm) ? options.esm : true debug('esm', esm) diff --git a/yarn.lock b/yarn.lock index 100b3804..4ef790d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -912,11 +912,14 @@ __metadata: peerDependencies: petite-vue-i18n: "*" vue-i18n: "*" + vue-i18n-bridge: "*" peerDependenciesMeta: petite-vue-i18n: optional: true vue-i18n: optional: true + vue-i18n-bridge: + optional: true languageName: unknown linkType: soft