File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ const PackageManager = require('./util/ProjectPackageManager')
21
21
22
22
const { runMigrator } = require ( './migrate' )
23
23
24
+ function clearRequireCache ( ) {
25
+ Object . keys ( require . cache ) . forEach ( key => delete require . cache [ key ] )
26
+ }
27
+
24
28
module . exports = class Upgrader {
25
29
constructor ( context = process . cwd ( ) ) {
26
30
this . context = context
@@ -104,12 +108,16 @@ module.exports = class Upgrader {
104
108
105
109
log ( `Upgrading ${ packageName } from ${ installed } to ${ targetVersion } ` )
106
110
await this . pm . upgrade ( `${ packageName } @~${ targetVersion } ` )
111
+ // as the dependencies have now changed, the require cache must be invalidated
112
+ // otherwise it may affect the behavior of the migrator
113
+ clearRequireCache ( )
107
114
108
115
// The cached `pkg` field won't automatically update after running `this.pm.upgrade`.
109
116
// Also, `npm install pkg@~version` won't replace the original `"pkg": "^version"` field.
110
117
// So we have to manually update `this.pkg` and write to the file system in `runMigrator`
111
118
this . pkg [ depEntry ] [ packageName ] = `~${ targetVersion } `
112
119
const noop = ( ) => { }
120
+
113
121
const pluginMigrator =
114
122
loadModule ( `${ packageName } /migrator` , this . context ) || noop
115
123
You can’t perform that action at this time.
0 commit comments