11const log = console ;
2- const refresh = 'Please refresh the page .' ;
2+ const refresh = 'Please restart the application .' ;
33const hotOptions = {
44 ignoreUnaccepted : true ,
55 ignoreDeclined : true ,
@@ -73,7 +73,7 @@ function check(options) {
7373 . then ( ( modules ) => {
7474 if ( ! modules ) {
7575 log . warn (
76- `Cannot find update. The server may have been restarted. ${ refresh } `
76+ `Cannot find update. ${ refresh } `
7777 ) ;
7878 return null ;
7979 }
@@ -82,8 +82,7 @@ function check(options) {
8282 . apply ( hotOptions )
8383 . then ( ( appliedModules ) => {
8484 if ( ! upToDate ( ) ) {
85- log . warn ( "Hashes don't match. Ignoring second update..." ) ;
86- // check(options);
85+ check ( options ) ;
8786 }
8887
8988 result ( modules , appliedModules ) ;
@@ -122,7 +121,7 @@ if (module.hot) {
122121 console . error ( 'Hot Module Replacement is disabled.' ) ;
123122}
124123
125- module . exports = function update ( currentHash , options ) {
124+ function update ( currentHash , options ) {
126125 lastHash = currentHash ;
127126 if ( ! upToDate ( ) ) {
128127 const status = module . hot . status ( ) ;
@@ -138,3 +137,24 @@ module.exports = function update(currentHash, options) {
138137 }
139138} ;
140139
140+ function getCurrentHash ( currentHash , getFileContent ) {
141+ const file = getFileContent ( `${ currentHash } .hot-update.json` ) ;
142+ return file . readText ( ) . then ( hotUpdateContent => {
143+ if ( hotUpdateContent ) {
144+ const manifest = JSON . parse ( hotUpdateContent ) ;
145+ const newHash = manifest . h ;
146+ return getCurrentHash ( newHash , getFileContent ) ;
147+ } else {
148+ return Promise . resolve ( currentHash ) ;
149+ }
150+ } ) . catch ( error => Promise . reject ( error ) ) ;
151+ }
152+
153+ module . exports = function checkState ( initialHash , getFileContent ) {
154+ getCurrentHash ( initialHash , getFileContent ) . then ( currentHash => {
155+ if ( currentHash != initialHash ) {
156+ update ( currentHash , { } ) ;
157+ }
158+ } )
159+ }
160+
0 commit comments