From 20cbf1885bc81c68836c96099e518a9e995d5672 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 26 Jul 2019 21:41:33 +0300 Subject: [PATCH] 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. --- hmr/hmr-update.ts | 9 ++++++--- hot.js | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hmr/hmr-update.ts b/hmr/hmr-update.ts index 6ad9b3d1..e4778c33 100644 --- a/hmr/hmr-update.ts +++ b/hmr/hmr-update.ts @@ -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; + }); } \ No newline at end of file diff --git a/hot.js b/hot.js index 84de3b1e..4d9f5c77 100644 --- a/hot.js +++ b/hot.js @@ -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);