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

Commit 20cbf18

Browse files
fix(hmr): check for hot update should not create new file
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.
1 parent 87f5ca7 commit 20cbf18

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Diff for: hmr/hmr-update.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as hot from "../hot";
2-
import { knownFolders } from "tns-core-modules/file-system";
2+
import { knownFolders, path, File } from "tns-core-modules/file-system";
33

44
declare const __webpack_require__: any;
55

66
export function hmrUpdate() {
7-
const applicationFiles = knownFolders.currentApp();
7+
const currentAppFolder = knownFolders.currentApp();
88
const latestHash = __webpack_require__["h"]();
9-
return hot(latestHash, filename => applicationFiles.getFile(filename));
9+
return hot(latestHash, filename => {
10+
const fullFilePath = path.join(currentAppFolder.path, filename);
11+
return File.exists(fullFilePath) ? currentAppFolder.getFile(filename) : null;
12+
});
1013
}

Diff for: hot.js

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ function update(latestHash, options) {
147147

148148
function getNextHash(hash, getFileContent) {
149149
const file = getFileContent(`${hash}.hot-update.json`);
150+
if (!file) {
151+
return Promise.resolve(hash);
152+
}
153+
150154
return file.readText().then(hotUpdateContent => {
151155
if (hotUpdateContent) {
152156
const manifest = JSON.parse(hotUpdateContent);

0 commit comments

Comments
 (0)