From d4b9133f55a94893c9c281e3e0c300d33e289337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=88=E8=90=BD=E9=9F=B3=E9=98=91?= <424532913@qq.com> Date: Mon, 27 Dec 2021 19:47:48 +0800 Subject: [PATCH] fix(vue): fix postinstall error (#2684) --- packages/vue/scripts/switch-cli.js | 8 +++----- packages/vue/scripts/utils.js | 9 ++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) 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