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')
2121
2222const { runMigrator } = require ( './migrate' )
2323
24+ function clearRequireCache ( ) {
25+ Object . keys ( require . cache ) . forEach ( key => delete require . cache [ key ] )
26+ }
27+
2428module . exports = class Upgrader {
2529 constructor ( context = process . cwd ( ) ) {
2630 this . context = context
@@ -104,12 +108,16 @@ module.exports = class Upgrader {
104108
105109 log ( `Upgrading ${ packageName } from ${ installed } to ${ targetVersion } ` )
106110 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 ( )
107114
108115 // The cached `pkg` field won't automatically update after running `this.pm.upgrade`.
109116 // Also, `npm install pkg@~version` won't replace the original `"pkg": "^version"` field.
110117 // So we have to manually update `this.pkg` and write to the file system in `runMigrator`
111118 this . pkg [ depEntry ] [ packageName ] = `~${ targetVersion } `
112119 const noop = ( ) => { }
120+
113121 const pluginMigrator =
114122 loadModule ( `${ packageName } /migrator` , this . context ) || noop
115123
You can’t perform that action at this time.
0 commit comments