Skip to content

Commit 45aeebe

Browse files
committed
fix: handle correctly the situation when the compilation hash is the same as the previous one
Currently CLI considers the hash that is the same as the previous as invalid and this way the application is restarted on device. As that hash is already handled, we should consider it as a valid hash. Steps to reproduce : ``` `tns create ts_proj` - choose ts tabs project npm i tns-core-modules@rc --save --save-exact npm i nativescript-dev-webpack@rc --save-dev --save-exact node_modules/.bin/update-ns-webpack --deps –configs tns run android Change something in app.android.scss - the change is applied, no restart Change something in app.ios.scss - application restarts ```
1 parent 5115f07 commit 45aeebe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/services/webpack/webpack-compiler-service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
260260
// if files will be emitted or not. This way, the first successful compilation after fixing the compilation error generates
261261
// a hash that is not the same as the one expected in the latest emitted hot-update.json file.
262262
// As a result, the hmr chain is broken and the changes are not applied.
263-
const isHashValid = nextHash ? this.expectedHashes[platform] === currentHash : true;
263+
let isHashValid = nextHash ? this.expectedHashes[platform] === currentHash : true;
264+
if (this.expectedHashes[platform] === nextHash) {
265+
isHashValid = true;
266+
}
264267
this.expectedHashes[platform] = nextHash;
265268

266269
const emittedHotUpdatesAndAssets = isHashValid ? _.difference(allEmittedFiles, chunkFiles) : allEmittedFiles;

test/services/webpack/webpack-compiler-service.ts

+7
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,12 @@ describe("WebpackCompilerService", () => {
8686
const androidResult = webpackCompilerService.getUpdatedEmittedFiles(getAllEmittedFiles("hash6"), chunkFiles, "hash8", androidPlatformName);
8787
assert.deepEqual(androidResult.emittedFiles, ["bundle.hash6.hot-update.js", "hash6.hot-update.json"]);
8888
});
89+
it("should return only emitted files when the compilation hash is the same as the previous one", () => {
90+
const initiallyEmittedFiles = ['bundle.js', 'runtime.js', 'vendor.js', 'fonts/FontAwesome.ttf', 'package.json', 'tns-java-classes.js' ];
91+
webpackCompilerService.getUpdatedEmittedFiles(initiallyEmittedFiles, chunkFiles, "hash1", iOSPlatformName);
92+
const result = webpackCompilerService.getUpdatedEmittedFiles(["bundle.js"], chunkFiles, "hash1", iOSPlatformName);
93+
94+
assert.deepEqual(result.emittedFiles, []);
95+
});
8996
});
9097
});

0 commit comments

Comments
 (0)