From 5b660887eca068370cd79ec3af6ae9ea781edb4a Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Wed, 20 Feb 2019 01:34:33 +0200 Subject: [PATCH 1/2] fix(HMR): modulePath on Windows Replace backslashes with forward slashes. --- 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..40225924 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 fromRelativePathToUnix(relativePath) { + return relativePath.replace(/\\/g, "/"); +} + module.exports = { buildEnvData, debuggingEnabled, @@ -99,5 +101,6 @@ module.exports = { getUpdatedEmittedFiles, parseHotUpdateChunkName, addListener, - removeListener + removeListener, + fromRelativePathToUnix }; diff --git a/markup-hot-loader.js b/markup-hot-loader.js index 6d0ffd0a..26d63ac2 100644 --- a/markup-hot-loader.js +++ b/markup-hot-loader.js @@ -1,7 +1,9 @@ const { reload } = require("./hot-loader-helper"); +const { fromRelativePathToUnix } = 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 = fromRelativePathToUnix(moduleRelativePath); return `${source};${reload({ type: typeMarkup, path: modulePath })}`; }; diff --git a/script-hot-loader.js b/script-hot-loader.js index be828359..004a7caa 100644 --- a/script-hot-loader.js +++ b/script-hot-loader.js @@ -1,7 +1,9 @@ const { reload } = require("./hot-loader-helper"); +const { fromRelativePathToUnix } = 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 = fromRelativePathToUnix(moduleRelativePath); return `${source};${reload({ type: typeScript, path: modulePath })}`; }; diff --git a/style-hot-loader.js b/style-hot-loader.js index e581cfbd..79a7e54a 100644 --- a/style-hot-loader.js +++ b/style-hot-loader.js @@ -1,7 +1,9 @@ const { reload } = require("./hot-loader-helper"); +const { fromRelativePathToUnix } = 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 = fromRelativePathToUnix(moduleRelativePath); return `${source};${reload({ type: typeStyle, path: modulePath })}`; }; From e0c49fcc0eeb8cd16821fd13d3074ed010f4bfdc Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Wed, 20 Feb 2019 13:03:38 +0200 Subject: [PATCH 2/2] refactor: rename a method --- lib/utils.js | 4 ++-- markup-hot-loader.js | 4 ++-- script-hot-loader.js | 4 ++-- style-hot-loader.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 40225924..5bb0dea2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -90,7 +90,7 @@ function removeListener(eventEmitter, name) { } } -function fromRelativePathToUnix(relativePath) { +function convertToUnixPath(relativePath) { return relativePath.replace(/\\/g, "/"); } @@ -102,5 +102,5 @@ module.exports = { parseHotUpdateChunkName, addListener, removeListener, - fromRelativePathToUnix + convertToUnixPath }; diff --git a/markup-hot-loader.js b/markup-hot-loader.js index 26d63ac2..e811dd5d 100644 --- a/markup-hot-loader.js +++ b/markup-hot-loader.js @@ -1,9 +1,9 @@ const { reload } = require("./hot-loader-helper"); -const { fromRelativePathToUnix } = require("./lib/utils"); +const { convertToUnixPath } = require("./lib/utils"); module.exports = function (source) { const typeMarkup = "markup"; const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); - const modulePath = fromRelativePathToUnix(moduleRelativePath); + const modulePath = convertToUnixPath(moduleRelativePath); return `${source};${reload({ type: typeMarkup, path: modulePath })}`; }; diff --git a/script-hot-loader.js b/script-hot-loader.js index 004a7caa..b9d07416 100644 --- a/script-hot-loader.js +++ b/script-hot-loader.js @@ -1,9 +1,9 @@ const { reload } = require("./hot-loader-helper"); -const { fromRelativePathToUnix } = require("./lib/utils"); +const { convertToUnixPath } = require("./lib/utils"); module.exports = function (source) { const typeScript = "script"; const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); - const modulePath = fromRelativePathToUnix(moduleRelativePath); + const modulePath = convertToUnixPath(moduleRelativePath); return `${source};${reload({ type: typeScript, path: modulePath })}`; }; diff --git a/style-hot-loader.js b/style-hot-loader.js index 79a7e54a..c4c3822a 100644 --- a/style-hot-loader.js +++ b/style-hot-loader.js @@ -1,9 +1,9 @@ const { reload } = require("./hot-loader-helper"); -const { fromRelativePathToUnix } = require("./lib/utils"); +const { convertToUnixPath } = require("./lib/utils"); module.exports = function (source) { const typeStyle = "style"; const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); - const modulePath = fromRelativePathToUnix(moduleRelativePath); + const modulePath = convertToUnixPath(moduleRelativePath); return `${source};${reload({ type: typeStyle, path: modulePath })}`; };