From c4b4fee029678ba52768e0d249da0d90121e2066 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Wed, 20 Feb 2019 18:34:12 +0200 Subject: [PATCH] fix(HMR): modulePath on Windows to apply changes in app styles at runtime (#807) * fix(HMR): modulePath on Windows Replace backslashes with forward slashes. * refactor: rename a method --- lib/utils.js | 9 ++++++--- markup-hot-loader.js | 4 +++- script-hot-loader.js | 4 +++- style-hot-loader.js | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 36baaf1d..5bb0dea2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,10 +1,8 @@ const os = require("os"); -const path = require("path"); const { getAppPathFromProjectData, getAppResourcesPathFromProjectData, - getProjectDir, isAndroid, } = require("../projectHelpers"); @@ -92,6 +90,10 @@ function removeListener(eventEmitter, name) { } } +function convertToUnixPath(relativePath) { + return relativePath.replace(/\\/g, "/"); +} + module.exports = { buildEnvData, debuggingEnabled, @@ -99,5 +101,6 @@ module.exports = { getUpdatedEmittedFiles, parseHotUpdateChunkName, addListener, - removeListener + removeListener, + convertToUnixPath }; diff --git a/markup-hot-loader.js b/markup-hot-loader.js index 6d0ffd0a..e811dd5d 100644 --- a/markup-hot-loader.js +++ b/markup-hot-loader.js @@ -1,7 +1,9 @@ const { reload } = require("./hot-loader-helper"); +const { convertToUnixPath } = require("./lib/utils"); module.exports = function (source) { const typeMarkup = "markup"; - const modulePath = this.resourcePath.replace(this.rootContext, "."); + const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); + const modulePath = convertToUnixPath(moduleRelativePath); return `${source};${reload({ type: typeMarkup, path: modulePath })}`; }; diff --git a/script-hot-loader.js b/script-hot-loader.js index be828359..b9d07416 100644 --- a/script-hot-loader.js +++ b/script-hot-loader.js @@ -1,7 +1,9 @@ const { reload } = require("./hot-loader-helper"); +const { convertToUnixPath } = require("./lib/utils"); module.exports = function (source) { const typeScript = "script"; - const modulePath = this.resourcePath.replace(this.rootContext, "."); + const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); + const modulePath = convertToUnixPath(moduleRelativePath); return `${source};${reload({ type: typeScript, path: modulePath })}`; }; diff --git a/style-hot-loader.js b/style-hot-loader.js index e581cfbd..c4c3822a 100644 --- a/style-hot-loader.js +++ b/style-hot-loader.js @@ -1,7 +1,9 @@ const { reload } = require("./hot-loader-helper"); +const { convertToUnixPath } = require("./lib/utils"); module.exports = function (source) { const typeStyle = "style"; - const modulePath = this.resourcePath.replace(this.rootContext, "."); + const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); + const modulePath = convertToUnixPath(moduleRelativePath); return `${source};${reload({ type: typeStyle, path: modulePath })}`; };