Fix HMR on Windows

Summary:Tested HMR on Windows and found 2 small issues related to paths that made it not work. Now it works nicely :)

**Test plan (required)**
Tested HMR in UIExplorer on Windows.
Closes https://github.com/facebook/react-native/pull/6678

Differential Revision: D3138379

fb-gh-sync-id: f27cd2fa21f95954685c8c6916d820f41bc187be
fbshipit-source-id: f27cd2fa21f95954685c8c6916d820f41bc187be
This commit is contained in:
Janic Duplessis 2016-04-05 01:12:13 -07:00 committed by Facebook Github Bot 6
parent bef175af61
commit c61100d0ce
2 changed files with 16 additions and 9 deletions

View File

@ -18,6 +18,12 @@ module.exports = function(options, filename) {
var transform = filename
? './' + path.relative(path.dirname(filename), transformPath) // packager can't handle absolute paths
: hmrTransform;
// Fix the module path to use '/' on Windows.
if (path.sep === '\\') {
transform = transform.replace(/\\/g, '/');
}
return {
plugins: resolvePlugins([
[

View File

@ -189,23 +189,24 @@ class Bundler {
);
}
_hmrURL(prefix, platform, extensionOverride, path) {
const matchingRoot = this._projectRoots.find(root => path.startsWith(root));
_hmrURL(prefix, platform, extensionOverride, filePath) {
const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root));
if (!matchingRoot) {
throw new Error('No matching project root for ', path);
throw new Error('No matching project root for ', filePath);
}
const extensionStart = path.lastIndexOf('.');
let resource = path.substring(
// Replaces '\' with '/' for Windows paths.
if (path.sep === '\\') {
filePath = filePath.replace(/\\/g, '/');
}
const extensionStart = filePath.lastIndexOf('.');
let resource = filePath.substring(
matchingRoot.length,
extensionStart !== -1 ? extensionStart : undefined,
);
const extension = extensionStart !== -1
? path.substring(extensionStart + 1)
: null;
return (
prefix + resource +
'.' + extensionOverride + '?' +