Skip to content

Commit

Permalink
fix(vue): fix postinstall error (#2684)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisicDemone authored Dec 27, 2021
1 parent 541bd81 commit d4b9133
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 3 additions & 5 deletions packages/vue/scripts/switch-cli.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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'

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(
Expand Down
9 changes: 8 additions & 1 deletion packages/vue/scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { loadModule } = require('vue-demi/scripts/utils.js')
const fs = require('fs-extra')
const path = require('path')

Expand All @@ -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

0 comments on commit d4b9133

Please sign in to comment.