diff --git a/packages/vue/scripts/switch-cli.js b/packages/vue/scripts/switch-cli.js index 7e4c846b31d..f1f7e0d33b6 100644 --- a/packages/vue/scripts/switch-cli.js +++ b/packages/vue/scripts/switch-cli.js @@ -1,7 +1,5 @@ const { switchVersion } = require('./utils.js') -const { - switchVersion: switchVueDemiVersion, -} = require('vue-demi/scripts/utils.js') +const { exec } = require('child_process') const version = process.argv[2] const vueEntry = process.argv[3] || 'vue' @@ -9,12 +7,12 @@ const vueEntry = process.argv[3] || 'vue' if (version == '2') { switchVersion(2) console.log(`[formily-vue] Switched types for Vue 2`) - switchVueDemiVersion(2, vueEntry) + exec(`npx vue-demi-switch 2 ${vueEntry}`) console.log(`[vue-demi] Switched for Vue 2 (entry: "${vueEntry}")`) } else if (version == '3') { switchVersion(3) console.log(`[formily-vue] Switched types for Vue 3`) - switchVueDemiVersion(3, vueEntry) + exec(`npx vue-demi-switch 3 ${vueEntry}`) console.log(`[vue-demi] Switched for Vue 3 (entry: "${vueEntry}")`) } else { console.warn( diff --git a/packages/vue/scripts/utils.js b/packages/vue/scripts/utils.js index 8a1608d0359..24d86eb5eed 100644 --- a/packages/vue/scripts/utils.js +++ b/packages/vue/scripts/utils.js @@ -1,4 +1,3 @@ -const { loadModule } = require('vue-demi/scripts/utils.js') const fs = require('fs-extra') const path = require('path') @@ -9,5 +8,13 @@ function switchVersion(version) { fs.copySync(`${dir}/v${version}`, `${dir}/cur`) } +function loadModule(name) { + try { + return require(name) + } catch (e) { + return undefined + } +} + module.exports.loadModule = loadModule module.exports.switchVersion = switchVersion