Skip to content

Commit ef15316

Browse files
committed
fix: preserve the tilde version range after vue upgrade
1 parent 51a4da7 commit ef15316

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

packages/@vue/cli/lib/Upgrader.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,23 @@ module.exports = class Upgrader {
105105
log(`Upgrading ${packageName} from ${installed} to ${targetVersion}`)
106106
await this.pm.upgrade(`${packageName}@~${targetVersion}`)
107107

108-
// the cached `pkg` field won't automatically update after running `this.pm.upgrade`
108+
// The cached `pkg` field won't automatically update after running `this.pm.upgrade`.
109+
// Also, `npm install pkg@~version` won't replace the original `"pkg": "^version"` field.
110+
// So we have to manually update `this.pkg` and write to the file system in `runMigrator`
109111
this.pkg[depEntry][packageName] = `~${targetVersion}`
110-
const pluginMigrator = loadModule(`${packageName}/migrator`, this.context)
111-
112-
if (pluginMigrator) {
113-
await runMigrator(
114-
this.context,
115-
{
116-
id: packageName,
117-
apply: pluginMigrator,
118-
baseVersion: installed
119-
},
120-
this.pkg
121-
)
122-
}
112+
const noop = () => {}
113+
const pluginMigrator =
114+
loadModule(`${packageName}/migrator`, this.context) || noop
115+
116+
await runMigrator(
117+
this.context,
118+
{
119+
id: packageName,
120+
apply: pluginMigrator,
121+
baseVersion: installed
122+
},
123+
this.pkg
124+
)
123125
}
124126

125127
async getUpgradable (includeNext) {

0 commit comments

Comments
 (0)