Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HMR on Windows #6678

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions babel-preset/configs/hmr.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module.exports = function(options, filename) {
var transform = filename
? './' + path.relative(path.dirname(filename), transformPath) // packager can't handle absolute paths
: hmrTransform;

// Fix the path to use '/' on Windows.
transform = transform.replace(/\\/g, '/');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the transform used to output require('./..\..\...') which of course didn't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should check the path separator first,

if (path.sep === '\\') {
  transform = transform.replace(/\\/g, '/');
}

I think we should move this to a module normalizePath or something, and use it instead of duplicating the code.


return {
plugins: resolvePlugins([
[
Expand Down
7 changes: 3 additions & 4 deletions packager/react-packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,15 @@ class Bundler {
throw new Error('No matching project root for ', path);
}

// Replaces '\' with '/' for Windows paths.
path = path.replace(/\\/g, '/');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the generated URLs had '' in them instead of '/' and caused an error when downloading source maps.


const extensionStart = path.lastIndexOf('.');
let resource = path.substring(
matchingRoot.length,
extensionStart !== -1 ? extensionStart : undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused variable

);

const extension = extensionStart !== -1
? path.substring(extensionStart + 1)
: null;

return (
prefix + resource +
'.' + extensionOverride + '?' +
Expand Down