From 2b4d37dc2147ed9080a889f024c8fa95c06f69cc Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 6 Sep 2019 12:08:29 +0800 Subject: [PATCH] fix(upgrade): correctly update version range in package.json --- packages/@vue/cli/__tests__/Upgrader.spec.js | 3 +++ packages/@vue/cli/lib/Upgrader.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/packages/@vue/cli/__tests__/Upgrader.spec.js b/packages/@vue/cli/__tests__/Upgrader.spec.js index 88524138cc..7e3dcfd771 100644 --- a/packages/@vue/cli/__tests__/Upgrader.spec.js +++ b/packages/@vue/cli/__tests__/Upgrader.spec.js @@ -34,6 +34,9 @@ test('upgrade: plugin-babel v3.5', async () => { expect(updatedPkg.dependencies).toHaveProperty('core-js') expect(logs.log.some(([msg]) => msg.match('core-js has been upgraded'))).toBe(true) + + // should have updated the version range in package.json + expect(updatedPkg.devDependencies['@vue/cli-plugin-babel']).not.toMatch('3.5.3') }) test('upgrade: plugin-babel with core-js 2', async () => { diff --git a/packages/@vue/cli/lib/Upgrader.js b/packages/@vue/cli/lib/Upgrader.js index 3c63829966..63392da679 100644 --- a/packages/@vue/cli/lib/Upgrader.js +++ b/packages/@vue/cli/lib/Upgrader.js @@ -101,6 +101,8 @@ module.exports = class Upgrader { log(`Upgrading ${packageName} from ${installed} to ${targetVersion}`) await this.pm.upgrade(`${packageName}@^${targetVersion}`) + // the cached `pkg` field won't automatically update after running `this.pm.upgrade` + this.pkg[depEntry][packageName] = `^${targetVersion}` await this.runMigrator(packageName, { installed }) }