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

fix(hmr): check for hot update should not create new file #1020

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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