File size: 2,161 Bytes
7d73cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadModule = exports.getVueI18nVersion = exports.checkVueI18nBridgeInstallPackage = exports.checkInstallPackage = void 0;
// eslint-disable-next-line @typescript-eslint/ban-types
function checkInstallPackage(pkg, debug) {
    let installedVueI18n = false;
    try {
        debug(`vue-i18n load path: ${require.resolve('vue-i18n')}`);
        installedVueI18n = true;
    }
    catch (e) {
        debug(`cannot find 'vue-i18n'`, e);
    }
    let installedPetiteVueI18n = false;
    try {
        debug(`petite-vue-i18n load path: ${require.resolve('petite-vue-i18n')}`);
        installedPetiteVueI18n = true;
    }
    catch (e) {
        debug(`cannot find 'petite-vue-i18n'`, e);
    }
    if (installedVueI18n) {
        return 'vue-i18n';
    }
    if (installedPetiteVueI18n) {
        return 'petite-vue-i18n';
    }
    throw new Error(`${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`);
}
exports.checkInstallPackage = checkInstallPackage;
// eslint-disable-next-line @typescript-eslint/ban-types
function checkVueI18nBridgeInstallPackage(debug) {
    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;
}
exports.checkVueI18nBridgeInstallPackage = checkVueI18nBridgeInstallPackage;
function getVueI18nVersion(debug) {
    const VueI18n = loadModule('vue-i18n', debug);
    if (VueI18n == null) {
        return '';
    }
    if (VueI18n.version && VueI18n.version.startsWith('8.')) {
        return '8';
    }
    if (VueI18n.VERSION && VueI18n.VERSION.startsWith('9.')) {
        return '9';
    }
    return 'unknown';
}
exports.getVueI18nVersion = getVueI18nVersion;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function loadModule(moduleName, debug) {
    try {
        return require(moduleName);
    }
    catch (e) {
        debug(`cannot load '${moduleName}'`, e);
        return null;
    }
}
exports.loadModule = loadModule;