Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
fix(hmr): check for hot update should not create new file
Browse files Browse the repository at this point in the history
Currently the check for hot update creates a new file in case it does not exist (as the method from tns-core-modules is doing this). This is a problem when trying to install `.ipa` on device and the `.ipa` file contains JavaScript files with HMR enabled.
This may happen in case you run `tns run ios` on device and after command finishes the execution open the project in Xcode and deploy the app from there or uninstall it from device and install the produced `.ipa` manually. The problem in the mentioned scenarios is that the JavaScript file cannot write files in the directory where the `.ipa` is installed.
When `tns run ios` is executed, it livesyncs the files in a different location, so the HMR can create the files there.

To fix the issue check if the hmr file exist before reading its content.
  • Loading branch information
rosen-vladimirov committed Aug 14, 2019
1 parent 8a2e3a3 commit c9656a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hmr/hmr-update.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as hot from "../hot";
import { knownFolders } from "tns-core-modules/file-system";
import { knownFolders, path, File } from "tns-core-modules/file-system";

declare const __webpack_require__: any;

export function hmrUpdate() {
const applicationFiles = knownFolders.currentApp();
const currentAppFolder = knownFolders.currentApp();
const latestHash = __webpack_require__["h"]();
return hot(latestHash, filename => applicationFiles.getFile(filename));
return hot(latestHash, filename => {
const fullFilePath = path.join(currentAppFolder.path, filename);
return File.exists(fullFilePath) ? currentAppFolder.getFile(filename) : null;
});
}
4 changes: 4 additions & 0 deletions hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ function update(latestHash, options) {

function getNextHash(hash, getFileContent) {
const file = getFileContent(`${hash}.hot-update.json`);
if (!file) {
return Promise.resolve(hash);
}

return file.readText().then(hotUpdateContent => {
if (hotUpdateContent) {
const manifest = JSON.parse(hotUpdateContent);
Expand Down

0 comments on commit c9656a9

Please sign in to comment.